Example #1
0
        /// <summary>
        ///     Return lookup lemmas for each element in the old relation as well as the definition of the old relation, which
        ///     is defined via an association list
        /// </summary>
        private static StateRelationData OldRelation(
            ISet <Variable> oldGlobalVars,
            IVariableTranslation <Variable> variableTranslation,
            out IList <OuterDecl> oldRelDecls)
        {
            //assume that passive version representing old variable of "g" is "g" itself
            var oldRelTuples     = new List <Term>();
            var varList          = new List <Variable>();
            var varToLookupLemma = new Dictionary <Variable, LemmaDecl>();
            var uniqueNamer      = new IsaUniqueNamer();

            foreach (var v in oldGlobalVars)
            {
                if (variableTranslation.TryTranslateVariableId(v, out var varTermId, out _))
                {
                    oldRelTuples.Add(new TermTuple(varTermId, IsaCommonTerms.Inl(varTermId)));
                    var lemma = new LemmaDecl(
                        "lookup_old_rel" + uniqueNamer.GetName(v, v.Name),
                        TermBinary.Eq(new TermApp(oldRel, varTermId),
                                      IsaCommonTerms.SomeOption(IsaCommonTerms.Inl(varTermId))),
                        new Proof(new List <string>
                    {
                        "unfolding " + oldRelListName + "_def " + oldRelName + "_def",
                        "by simp"
                    })
                        );
                    varToLookupLemma.Add(v, lemma);
                    varList.Add(v);
                }
        //must be called in a topological backwards order
        public Tuple <LemmaDecl, LemmaDecl> GenerateBlockLemma(Block block, string localLemmaName,
                                                               Func <Block, string> cfgLemmaNameFunc)
        {
            var  cmdsDefName = programAccessor.BlockInfo().CmdsQualifiedName(block);
            Term cmds        = IsaCommonTerms.TermIdentFromName(cmdsDefName);

            var  passiveBlock       = origToPassiveBlock[block];
            var  passiveCmdsDefName = passiveProgramAccessor.BlockInfo().CmdsQualifiedName(passiveBlock);
            Term passiveCmds        = IsaCommonTerms.TermIdentFromName(passiveCmdsDefName);

            #region compute variable relation update  information

            var successors    = cfg.GetSuccessorBlocks(block);
            var varRelUpdates = _relationGen.GenerateVariableRelUpdates(block, out _);

            var constrainedPassiveVars = new List <Term>();
            var modifiedVarRelTerm     = new List <Term>();
            var lookupTyUpdatesLemmas  = new List <Tuple <string, string> >();

            foreach (var tuple in varRelUpdates)
            {
                var origVar = tuple.Item1;
                if (varTranslation.TryTranslateVariableId(origVar, out var origVarTerm, out _))
                {
                    if (tuple.Item2 is IdentifierExpr ie)
                    {
                        var passiveVar = ie.Decl;
                        if (passiveVarTranslation.TryTranslateVariableId(passiveVar, out var passiveVarTerm, out _))
                        {
                            modifiedVarRelTerm.Add(new TermTuple(origVarTerm, IsaCommonTerms.Inl(passiveVarTerm)));

                            /* don't add variable to newly constrained variables if update is associated with constant propagation
                             * in which case the variable is not newly constrained */
                            if (!tuple.Item3)
                            {
                                constrainedPassiveVars.Add(passiveVarTerm);
                            }
                            lookupTyUpdatesLemmas.Add(
                                Tuple.Create(programAccessor.LookupVarTyLemma(origVar),
                                             passiveProgramAccessor.LookupVarTyLemma(passiveVar))
                                );
                        }
                        else
                        {
                            throw new ProofGenUnexpectedStateException(GetType(), "Could not translate variables.");
                        }
                    }
 public static Term CFGConfigNode(Term node, Term state)
 {
     return(CFGConfig(IsaCommonTerms.Inl(node), state));
 }