Exemplo n.º 1
0
        public STbRule <TERM> Compose(int q, STbRule <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);
        }
Exemplo n.º 2
0
        STbRule <T> MkSTbRule(IEnumerable <Move <Pair <BDD, T> > > moves, Func <int, int> getState, Func <int, Sequence <T> > getYield, Func <int, T, T> getUpdate)
        {
            List <Tuple <T, BaseRule <T> > > cases = new List <Tuple <T, BaseRule <T> > >();
            var allGuards = solver.CharSetProvider.False;

            foreach (var m in moves)
            {
                cases.Add(new Tuple <T, BaseRule <T> >(ConvertToPredicate(m.Label.First),
                                                       new BaseRule <T>(getYield(m.TargetState), getUpdate(m.TargetState, m.Label.Second), getState(m.TargetState))));
                allGuards = solver.CharSetProvider.MkOr(allGuards, m.Label.First);
            }
            STbRule <T> r = UndefRule <T> .Default;

            if (cases.Count > 0)
            {
                if (allGuards.IsFull)
                {
                    r = cases[0].Item2;
                }
                else
                {
                    r = new IteRule <T>(cases[0].Item1, cases[0].Item2, UndefRule <T> .Default);
                }
                for (int i = 1; i < cases.Count; i++)
                {
                    r = new IteRule <T>(cases[i].Item1, cases[i].Item2, r);
                }
            }
            return(r);
        }
Exemplo n.º 3
0
        STbRule <TERM> Comp(TERM pathCond, STbRule <TERM> ruleA, int qB, Func <int, int, int> stateComposer, bool isFinal)
        {
            if (ruleA is SwitchRule <TERM> )
            {
                throw new NotImplementedException(ruleA.ToString());
            }

            var ite = ruleA as IteRule <TERM>;

            if (ite != null)
            {
                var iteCondLifted = solver.ApplySubstitution(ite.Condition, A.RegVar, regVar_1);
                var pathCond_T    = (pathCond.Equals(solver.True) ? iteCondLifted : solver.MkAnd(pathCond, iteCondLifted));
                var pathCond_F    = (pathCond.Equals(solver.True) ? solver.MkNot(iteCondLifted) : solver.MkAnd(pathCond, solver.MkNot(iteCondLifted)));
                var res_T         = Comp(pathCond_T, ite.TrueCase, qB, stateComposer, isFinal);
                var res_F         = Comp(pathCond_F, ite.FalseCase, qB, stateComposer, isFinal);
                if (res_T is UndefRule <TERM> && res_F is UndefRule <TERM> )
                {
                    return(UndefRule <TERM> .Default);
                }
                var res = new IteRule <TERM>(iteCondLifted, res_T, res_F);
                return(res);
            }
            else
            {
                var br = ruleA as BaseRule <TERM>;
                if (br != null)
                {
                    var yieldsFromALifted = br.Yields.ConvertAll(t => solver.ApplySubstitution(t, A.RegVar, regVar_1));
                    var inputsToB         = ConsList <TERM> .Create(yieldsFromALifted);

                    var regALifted = solver.ApplySubstitution(br.Register, A.RegVar, regVar_1);
                    var res        = this.EvalB(inputsToB, br.State, regALifted, pathCond, qB, regVar_2, stateComposer, Sequence <TERM> .Empty, isFinal);
                    return(res);
                }
                else
                {
                    return(UndefRule <TERM> .Default);
                }
            }
        }
Exemplo n.º 4
0
 public IteRule(TERM condition, STbRule <TERM> trueCase, STbRule <TERM> falseCase)
 {
     this.condition = condition;
     this.trueCase  = trueCase;
     this.falseCase = falseCase;
 }
Exemplo n.º 5
0
 public SwitchRule(TERM input, STbRule <TERM> defaultcase, params KeyValuePair <TERM, STbRule <TERM> >[] cases)
 {
     this.input       = input;
     this.defaultcase = defaultcase;
     this.cases       = cases;
 }
Exemplo n.º 6
0
        private STbRule <TERM> EvalB_Rule(STbRule <TERM> ruleB, int qA, TERM regA, TERM pathCond, ConsList <TERM> inputs, TERM regB, Func <int, int, int> stateComposer, Sequence <TERM> outputFromB, bool isFinal)
        {
            if (ruleB == null)
            {
                return(UndefRule <TERM> .Default);
            }

            if (ruleB is SwitchRule <TERM> )
            {
                var sw  = ruleB as SwitchRule <TERM>;
                var ite = sw.ToIte(solver.MkEq);
                return(EvalB_Rule(ite, qA, regA, pathCond, inputs, regB, stateComposer, outputFromB, isFinal));
            }

            var br = ruleB as BaseRule <TERM>;

            if (br != null)
            {
                var yields = br.Yields.ConvertAll(y => Simpl(Subst(y, B.InputVar, inputs.First, B.RegVar, regB)));
                var reg    = Simpl(Subst(br.Register, B.InputVar, inputs.First, B.RegVar, regB));
                var outp   = outputFromB.Append(yields);
                var res    = EvalB(inputs.Rest, qA, regA, pathCond, br.State, reg, stateComposer, outp, isFinal);
                return(res);
            }
            else
            {
                var ite = ruleB as IteRule <TERM>;
                if (ite != null)
                {
                    var condLifted          = Subst(ite.Condition, B.InputVar, inputs.First, 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 = EvalB_Rule(ite.FalseCase, qA, regA, pathCond, inputs, regB, stateComposer, outputFromB, isFinal);
                        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 = EvalB_Rule(ite.TrueCase, qA, regA, pathCond, inputs, regB, stateComposer, outputFromB, isFinal);
                            return(res);
                        }
                        else
                        {
                            var t = EvalB_Rule(ite.TrueCase, qA, regA, path_and_condLifted, inputs, regB, stateComposer, outputFromB, isFinal);
                            var f = EvalB_Rule(ite.FalseCase, qA, regA, path_and_not_condLifted, inputs, regB, stateComposer, outputFromB, isFinal);
                            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);
                }
            }
        }
Exemplo n.º 7
0
        private STbRule <TERM> CreateFinalComposedRule(TERM pathCond, int qAB, Sequence <TERM> outputFromB, STbRule <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);
                }
            }
        }