//////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////
        public override Expression visit(FAE f)
        {
            context.Push(f.ToString());
            base.visit(f);
            context.Pop();

            Expression result = f;

            bool add = true;

            if (f.arguments.count == 0)
            {
                add = false;
            }
            if (f.arguments.count == 1 && (f.arguments[0] is AtomicExpression))
            {
                add = false;
            }

//            if (BasicFunction.isBinaryLogical(f.function) /*&& (f.arguments[0] is AtomicExpression) && (f.arguments[1] is AtomicExpression)*/)
//                add = false;

//            if (BasicFunction.isUnaryLogical(f.function) /*&& (f.arguments[0] is AtomicExpression)*/)
//                add = false;

            if (add)
            {
                addSubexpression(f, context.Peek());
            }

            return(f);
        }
Esempio n. 2
0
        private void addFunctionInstantiation(FAE e)
        {
            if (ExpressionSymbolCounter.isInterpreted(e.function.name))
            {
                return;
            }
            var f = e.function as BasicFunctionTemplateInstance;

            if (f == null /*|| f.template.mapTypeArguments.Count()==0*/)
            {
                return;
            }
            FunctioneTemplateEntry fti;

            if (!functionTemplateInstantiations.TryGetValue(e.function.name, out fti))
            {
                functionTemplateInstantiations[e.function.name] = fti = new FunctioneTemplateEntry(f.template);
            }
            string s = argumentString(f.typeArguments);

            if (!fti.instances.ContainsKey(s))
            {
                fti.instances[s] = new Dictionary <string, FAE>();
            }
            fti.instances[s][e.ToString()] = e;
            if (f.isGroundInstance())
            {
                fti.groundInstances.Add(s);
            }
        }
Esempio n. 3
0
        ////////////////////////////////////////////////////////////////////////////
        public override Expression visit(FAE e)
        {
            Expression result = e;
            string     oes    = e.ToString();

            result = base.visit(e);

            result = checkReplace(result);
            return(result);
        }
        private Expression makeMapWriteMap(FAE fae)
        {
            Debug.Assert(fae.function is MapWrite);
            Debug.Assert(fae.arguments[0].type is MapType);
            var        mu = fae.function as MapWrite;
            Expression result;

            if (!versionMap.TryGetValue(fae.ToString(), out result))
            {
                var ot = fae.arguments[0].type as MapType;
                Debug.Assert(ot != null);
                var s = new TypeParameterInstantiation(ot.typeParameters, mu.typeArguments.Skip(1).ToArray());
//                var ots = new MapType(new TypeVariable[0], (from m in ot.domain select m.substitute(s)).ToArray(), ot.range.substitute(s));
                Expression   m = fae.arguments[0];
                Expression[] i = fae.arguments.Take(fae.arguments.count - 1).Skip(1).ToArray();

                if (fae.freeVariables.Count > 0)
                {
//m(fv)[i(fv):=x(fv)] ==> v(fv)  (assume v(fv)[i]==x, assume forall fv : forall j : j!=i(fv) ==> v(fv)[j] == m(fv)[j]
                    var    fvt = TypeTuple.make(from fv in fae.freeVariables select fv.type);
                    string fn  = getFreshMUName("mu");
                    var    ft  = new BFunctionTemplate(fn, "", new TypeVariable[0], new BasicFunctionSignature(ot, fvt),
                                                       null);
                    Function f = ft.getInstance();
                    IEnumerable <BasicBoundVariableExpression> fve = from fv in fae.freeVariables
                                                                     select new BasicBoundVariableExpression(fv);
                    result = new BasicFAE(f, new ExpressionList(fve));
                }
                else
                {
                    //m[i:=x] ==> v  (assume v[i]==x, assume forall j : j!=i ==> v[j] == m[j]
                    string nvn = getFreshMUName("mu");
                    var    nv  = new ProgramVariable(nvn, ot, false, false, false, false);
                    procedure.addVariable(nv);
                    result = new BasicProgramVariableExpression(nv);
                }
                Expression[] j =
                    (from e in i select new BasicBoundVariableExpression(makeBoundVariable(e.type))).ToArray();
                //forall j : j!=i ==> v[j]==m[j]
                addConditionalMapEqualityAxiom(i, result, m, mu.typeArguments);
                //v[i]==x;
                Expression x = fae.arguments.Last();
                addEqualityAxiom(ml(result, i, mu.typeArguments.Skip(1).ToArray(), x.type), fae.arguments.Last());
            }
            return(result);
        }