コード例 #1
0
        public LogicExpression nextNotEqual(LogicExpression exp, int maxVarsNumber)
        {
            LogicExpression result;

            do
            {
                result = next(maxVarsNumber);
            } while (result.Equals(exp));
            return(result);
        }
コード例 #2
0
        public LogicExpression nextNotEqual(LogicExpression exp)
        {
            LogicExpression result;

            do
            {
                result = next();
            } while (result.Equals(exp));
            return(result);
        }
コード例 #3
0
        public override bool Equals(object obj)
        {
            if (!(obj is LogicExpression))
            {
                return(false);
            }
            //Declare LogicExpression
            LogicExpression x = new LogicExpression(this, (LogicExpression)obj, new EOperation(LogicSymbols.EQU));

            x.makeRPolishRecord();
            x.generateTruthTable();
            return(x.truthTable.isTautology());
        }
コード例 #4
0
        public LogicExpression(LogicExpression leftExpr, LogicExpression rightExpr, EOperation op)
        {
            //Creating new "body" sequence with two existing sequences separated with EQU operation
            List <ExpressionPart> inputLeft   = new List <ExpressionPart>(leftExpr.body);
            List <EOperand>       newOperands = new List <EOperand>(leftExpr.operands);

            inputLeft[inputLeft.Count - 1] = new EBrackets(")");
            inputLeft.Insert(1, new EBrackets("("));

            inputLeft.Add(op);

            List <ExpressionPart> inputRight    = new List <ExpressionPart>(rightExpr.body);
            List <EOperand>       rightOperands = new List <EOperand>(rightExpr.operands);

            inputRight[0] = new EBrackets("(");
            inputRight.Insert(inputRight.Count - 1, new EBrackets(")"));

            inputLeft.AddRange(inputRight);
            newOperands.AddRange(rightOperands);

            //Removing vars repeating
            for (int i = 0; i < newOperands.Count; i++)
            {
                for (int j = i + 1; j < newOperands.Count; j++)
                {
                    if (newOperands[i].Equals(newOperands[j]))
                    {
                        newOperands.RemoveAt(j);
                    }
                }
            }

            //Recovering reference connection between .body and .operands
            for (int i = 0; i < inputLeft.Count; i++)
            {
                if (!(inputLeft[i] is EOperand))
                {
                    continue;
                }
                for (int j = 0; j < newOperands.Count; j++)
                {
                    if (inputLeft[i].Equals(newOperands[j]) && !Object.ReferenceEquals(inputLeft, newOperands))
                    {
                        inputLeft[i] = newOperands[j];
                    }
                }
            }

            this.body     = new Queue <ExpressionPart>(inputLeft);
            this.operands = newOperands;
        }