public override bool Equals(object obj)
        {
            PredicateFormula fOther = null;

            if (obj is CompoundFormula)
            {
                Formula fSimplify = ((CompoundFormula)obj).Simplify();
                if (fSimplify is PredicateFormula)
                {
                    fOther = (PredicateFormula)fSimplify;
                }
                else
                {
                    return(false);//might not be accurate - could be not
                }
            }
            else if (obj is PredicateFormula)
            {
                fOther = (PredicateFormula)obj;
            }
            else
            {
                return(false);
            }
            return(Predicate.Equals(fOther.Predicate));
        }
        private Formula ReadFormula(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, bool bParamterized, Domain d)
        {
            bool bPredicate = true;

            //Debug.WriteLine(exp);
            if (d != null && d.IsFunctionExpression(exp.Type))
            {
                Predicate p = ReadFunctionExpression(exp, dParameterNameToType, d);
                return(new PredicateFormula(p));
            }
            else if (IsUniversalQuantifier(exp))
            {
                CompoundExpression eParameter = (CompoundExpression)exp.SubExpressions[0];
                CompoundExpression eBody      = (CompoundExpression)exp.SubExpressions[1];
                string             sParameter = eParameter.Type;
                string             sType      = eParameter.SubExpressions[1].ToString();
                dParameterNameToType[sParameter] = sType;
                ParametrizedFormula cfQuantified = new ParametrizedFormula(exp.Type);
                cfQuantified.Parameters[sParameter] = sType;
                Formula fBody = ReadFormula(eBody, dParameterNameToType, true, d);
                cfQuantified.AddOperand(fBody);
                return(cfQuantified);
            }
            else
            {
                foreach (Expression eSub in exp.SubExpressions)
                {
                    if (eSub is CompoundExpression)
                    {
                        bPredicate = false;
                        break;
                    }
                }
                if (bPredicate)
                {
                    return(ReadPredicate(exp, dParameterNameToType, bParamterized, d));
                }
                else
                {
                    CompoundFormula cf          = new CompoundFormula(exp.Type);
                    int             iExpression = 0;
                    for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
                    {
                        if (exp.SubExpressions[iExpression] is StringExpression)
                        {
                            throw new InvalidDataException();
                        }
                        Formula f = ReadFormula((CompoundExpression)exp.SubExpressions[iExpression], dParameterNameToType, bParamterized, d);
                        cf.SimpleAddOperand(f);
                    }
                    if (cf.Operator == "not" && cf.Operands[0] is PredicateFormula)
                    {
                        PredicateFormula fNegate = new PredicateFormula(((PredicateFormula)cf.Operands[0]).Predicate.Negate());
                        return(fNegate);
                    }
                    return(cf);
                }
            }
        }
        public override Formula GenerateGiven(string sTag, List <string> lAlwaysKnown)
        {
            if (lAlwaysKnown.Contains(Predicate.Name))
            {
                return(this);
            }
            PredicateFormula pfGiven = new PredicateFormula(Predicate.GenerateKnowGiven(sTag));

            return(pfGiven);
        }
        private Formula ReadPredicate(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, bool bParametrized, Domain d)
        {
            Predicate p           = null;
            int       iExpression = 0;
            string    sName       = "";

            if (bParametrized)
            {
                p = new ParametrizedPredicate(exp.Type);
            }
            else
            {
                p = new GroundedPredicate(exp.Type);
            }
            for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                sName = exp.SubExpressions[iExpression].ToString();
                if (bParametrized)
                {
                    Argument a = null;
                    if (sName.StartsWith("?"))
                    {
                        a = new Parameter(dParameterNameToType[sName], sName);
                    }
                    else
                    {
                        a = new Constant(d.ConstantNameToType[sName], sName);
                    }
                    ((ParametrizedPredicate)p).AddParameter(a);
                }
                else
                {
                    Constant c = new Constant(d.ConstantNameToType[sName], sName);
                    ((GroundedPredicate)p).AddConstant(c);
                }
            }
            if (bParametrized)
            {
                if (!MatchParametersToPredicateDeclaration((ParametrizedPredicate)p, d))
                {
                    throw new NotImplementedException();
                }
            }

            PredicateFormula vf = new PredicateFormula(p);

            return(vf);
        }
        public override Formula Clone()
        {
            PredicateFormula f = new PredicateFormula(Predicate);

            return(f);
        }