Beispiel #1
0
        public BranchingRule <TERM> Compose(int q, BranchingRule <TERM> rule, TERM y1, TERM y2, TERM y, TERM predicate, IContextCore <TERM> solver, Func <int, int, int> stateComposer)
        {
            if (rule is UndefRule <TERM> )
            {
                return(rule);
            }
            if (this.yields.Length == 0)
            {
                int pq        = stateComposer(state, q);
                var register1 = solver.ApplySubstitution(register, y1, solver.MkProj(0, y));
                var register2 = solver.MkProj(1, y);
                var newreg    = solver.MkTuple(register1, register2);
                var res       = new BaseRule <TERM>(Sequence <TERM> .Empty, newreg, pq);
                return(res);
            }
            else
            {
                var y_1 = solver.MkProj(0, y);
                foreach (var o in yields)
                {
                    var o1 = solver.ApplySubstitution(o, y1, y_1);
                    //var rule1 = rule.Subst(solver, y2)
                }
            }

            return(null);
        }
Beispiel #2
0
 private BranchingRule <TERM> EvalB(ConsList <TERM> inputs, int qA, TERM regA, TERM pathCond, int qB, TERM regB, Func <int, int, int> stateComposer, Sequence <TERM> outputFromB, bool isFinal)
 {
     if (inputs == null)
     {
         int qAB = stateComposer(qA, qB);
         if (isFinal)
         {
             var fr = B.GetFinalRuleFrom(qB);
             if (fr.IsNotUndef)
             {
                 return(this.CreateFinalComposedRule(pathCond, qAB, outputFromB, fr, regB));
             }
             else
             {
                 return(UndefRule <TERM> .Default);
             }
         }
         else
         {
             TERM regAB = (regA.Equals(regVar_1) && regB.Equals(regVar_2) ? regVar : JoinRegs(regA, regB));
             var  res   = new BaseRule <TERM>(outputFromB, regAB, qAB);
             return(res);
         }
     }
     else
     {
         return(EvalB_Rule(B.GetRuleFrom(qB), qA, regA, pathCond, inputs, regB, stateComposer, outputFromB, isFinal));
     }
 }
Beispiel #3
0
        private BranchingRule <TERM> CreateFinalComposedRule(TERM pathCond, int qAB, Sequence <TERM> outputFromB, BranchingRule <TERM> ruleB, TERM regB)
        {
            if (ruleB is SwitchRule <TERM> )
            {
                throw new NotImplementedException(ruleB.ToString());
            }

            var br = ruleB as BaseRule <TERM>;

            if (br != null)
            {
                var yields = br.Yields.ConvertAll(z => Simpl(Subst(z, B.RegVar, regB)));
                var outp   = outputFromB.Append(yields);
                var res    = new BaseRule <TERM>(outp, regVar, qAB);
                return(res);
            }
            else
            {
                var ite = ruleB as IteRule <TERM>;
                if (ite != null)
                {
                    var condLifted          = Subst(ite.Condition, B.RegVar, regB);
                    var path_and_condLifted = solver.MkAnd(pathCond, condLifted);
                    if (!solver.IsSatisfiable(path_and_condLifted))
                    {
                        //path ==> !condLifted, the true-branch is unreachable
                        var res = CreateFinalComposedRule(pathCond, qAB, outputFromB, ite.FalseCase, regB);
                        return(res);
                    }
                    else
                    {
                        var path_and_not_condLifted = solver.MkAnd(pathCond, solver.MkNot(condLifted));
                        if (!solver.IsSatisfiable(path_and_not_condLifted))
                        {
                            //path ==> condLifted, the false-branch is unreachable
                            var res = CreateFinalComposedRule(pathCond, qAB, outputFromB, ite.TrueCase, regB);
                            return(res);
                        }
                        else
                        {
                            var f = CreateFinalComposedRule(path_and_not_condLifted, qAB, outputFromB, ite.FalseCase, regB);
                            var t = CreateFinalComposedRule(path_and_condLifted, qAB, outputFromB, ite.TrueCase, regB);
                            if (t is UndefRule <TERM> && f is UndefRule <TERM> )
                            {
                                return(UndefRule <TERM> .Default);
                            }

                            return(new IteRule <TERM>(condLifted, t, f));
                        }
                    }
                }
                else
                {
                    return(UndefRule <TERM> .Default);
                }
            }
        }
Beispiel #4
0
        IEnumerable <TERM> GetBaseRuleNonequivalences(IContextCore <TERM> solver, BaseRule <TERM> a, BaseRule <TERM> b)
        {
            yield return(solver.MkNeq(a.Register, b.Register));

            for (int i = 0; i < a.Yields.Length; ++i)
            {
                yield return(solver.MkNeq(a.Yields[i], b.Yields[i]));
            }
        }
Beispiel #5
0
        internal override BranchingRule <TERM> Concretize1(TERM path, IContextCore <TERM> solver,
                                                           Func <TERM, TERM> fBP, Func <TERM, TERM> fNBP,
                                                           Func <int, TERM, int> stateMap, TERM newReg, TERM inputVar)
        {
            ConsList <TERM> abstr_vals = null; //all possible values for a_tmp
            var             regAbstr   = fBP(register);

            #region collect all possible distinct solutions into abstr_vals
            solver.MainSolver.Push();
            var a = solver.MkFreshConst("a", regAbstr);
            var c = solver.MkFreshConst("c", inputVar);
            var r = solver.MkFreshConst("r", newReg);

            var assertion = solver.ApplySubstitution(solver.MkAnd(path, solver.MkEq(a, regAbstr)), newReg, r, inputVar, c);
            //string tmp = ((IPrettyPrinter<TERM>)solver).PrettyPrint(assertion);
            solver.MainSolver.Assert(assertion);
            var model = solver.MainSolver.GetModel(solver.True, a);
            while (model != null)
            {
                var aVal = model[a].Value;
                abstr_vals = new ConsList <TERM>(aVal, abstr_vals);
                solver.MainSolver.Assert(solver.MkNeq(a, aVal));
                model = solver.MainSolver.GetModel(solver.True, a);
            }
            solver.MainSolver.Pop();
            #endregion

            if (abstr_vals == null) //list cannot be empty because the path is feasible
            {
                throw new AutomataException(AutomataExceptionKind.InternalError);
            }

            //now create corresponding concrete outputs for the cases
            //note that, in case of a boolean abstraction, we need to add additional cases
            //according to the output values that were obtained

            var newRegister           = fNBP(register);
            var newState              = stateMap(state, abstr_vals.First);
            BranchingRule <TERM> rule = new BaseRule <TERM>(yields, newRegister, newState);

            abstr_vals = abstr_vals.Rest;
            while (abstr_vals != null)
            {
                newRegister = fNBP(register);
                newState    = stateMap(state, abstr_vals.First);
                var  brule = new BaseRule <TERM>(yields, newRegister, newState);
                TERM cond  = solver.Simplify(solver.MkEq(abstr_vals.First, regAbstr));
                rule       = new IteRule <TERM>(cond, brule, rule);
                abstr_vals = abstr_vals.Rest;
            }

            return(rule);
        }