Exemple #1
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));
        }
        private void CheckFullTable(string parse)
        {
            var parser    = StringParser.Create(parse);
            var table     = new SimplifiedTruthTableCreator(parser.GetOperator());
            var processed = new SimplifiedTruthTableCreator(parser.GetOperator().ToNandify());

            var orginal    = table.GetTable();
            var calculated = processed.GetTable();

            for (var i = 0; i < orginal.Length; i++)
            {
                for (var j = 0; j < orginal[i].Length; j++)
                {
                    Assert.True(orginal[i][j] == calculated[i][j]);
                }
            }
        }