public IActionResult Calculate(string formula, string points, double taylorAround, uint taylorN, double startIntegral, double endIntegral)
        {
            if (string.IsNullOrEmpty(formula))
            {
                return(RedirectToAction("Index"));
            }

            var model = new CalculateViewModel();

            model.Original = formula;


            var parser = new StringParser(formula);
            var result = parser.GetOperator();

            model.NiceFormat = (result.DeepSimplyfy().ToMathString());

            model.DerivativeNiceFormat = (result.Derivate().DeepSimplyfy().ToMathString());
            model.DerivativePointJson  =
                JSONHelper.ToJSON(NewtonDerivative.CalculatePoints(result, 0.001d, 0.5d, -3, 3));

            model.IntegralStart = startIntegral;
            model.IntegralEnd   = endIntegral;

            model.IntegralSum = RiemannSum.CalculateSum(result, startIntegral, endIntegral);

            model.TaylorPoloynoomAround     = taylorAround;
            model.TaylorPoloynoomNiceFormat = Taylorpolynomial.CalculateNPolynomial(result, taylorAround, taylorN).ToMathString();

            model.McClairenPoloynoomNiceFormat = Taylorpolynomial.CalculateNPolynomial(result, 0, taylorN).ToMathString();

            model.Request = HttpContext;
            try
            {
                model.GausJordon = GausJordan.GetBaseMathOperatorFromList(GetPoints(points)).DeepSimplyfy()
                                   .ToMathString();
                model.GausJordonFault = false;
            }
            catch (Exception e)
            {
                model.GausJordonFault = true;
            }

            var json = JsonCreator.CreateFromBaseOpeator(result);

            model.JsonData = JsonConvert.SerializeObject(json);

            model.TaylorPossible = model.McClairenPoloynoomNiceFormat.IndexOf("NaN", StringComparison.Ordinal) >= 0 || model.TaylorPoloynoomNiceFormat.IndexOf("NaN", StringComparison.Ordinal) >= 0;

            return(View(model));
        }
Beispiel #2
0
        public IActionResult Calculate(string formula)
        {
            if (string.IsNullOrEmpty(formula))
            {
                return(RedirectToAction("Index"));
            }

            var model = new CalculateViewModel();


            var parser            = StringParser.Create(formula);
            var calculatedFormula = parser.GetOperator();

            model.OriginalFormula = calculatedFormula.ToString();
            model.Logic           = calculatedFormula.ToLogicString();
            model.Nandify         = calculatedFormula.ToNandify().ToString();
            model.HasResult       = calculatedFormula.HasResult();

            var json = JsonCreator.CreateFromBaseOpeator(calculatedFormula);

            model.JsonData = JsonConvert.SerializeObject(json);


            SemanticTableauxParser tableaux;

            if (calculatedFormula.HasResult())
            {
                var stable           = new SimplifiedTruthTableCreator(calculatedFormula);
                var table            = new TruthTableCreator(calculatedFormula);
                var normal           = new DisjunctiveNormalDecorator(table);
                var simplifiedNormal = new DisjunctiveNormalDecorator(stable);
                model.Normalize            = normal.GetOperator().ToString();
                model.NormalizeLogicFormat = normal.GetOperator().ToLogicString();
                model.TruthTable           = table.GetTable();
                model.SimplifiedTruthTable = stable.GetTable();
                model.Arguments            = calculatedFormula.GetArguments();

                model.SimplifiedNormalize            = simplifiedNormal.GetOperator().ToString();
                model.SimplifiedNormalizeLogicFormat = simplifiedNormal.GetOperator().ToLogicString();

                model.Hex = table.ToHex();
            }


            tableaux               = new SemanticTableauxParser(calculatedFormula);
            model.isTautology      = tableaux.IsTautology();
            model.tableauxJsonData =
                JsonConvert.SerializeObject(JsonCreator.CreateFromTableauxStep(tableaux.GetStep()));
            return(View(model));
        }