コード例 #1
0
        public void CheckDifferenceTest()
        {
            var bddBuilder = new CharSetSolver(BitWidth.BV7);
            var converter  = bddBuilder;

            string[] regexes = SampleRegexes.regexes; // File.ReadAllLines(sampleDir + "icst.txt");

            int i = 1;
            int j = 2;

            string regexA = regexes[i];
            string regexB = regexes[j];

            var A = converter.Convert(regexA, System.Text.RegularExpressions.RegexOptions.None);
            //ShowAsGraph(converter, A, "A.dgml");

            var B = converter.Convert(regexB, System.Text.RegularExpressions.RegexOptions.None);
            //ShowAsGraph(converter, B, "B.dgml");

            List <BDD> witness;
            var        res = Automaton <BDD> .CheckDifference(A, B, 0, out witness);

            //ShowAsGraph(converter, C, "C.dgml");

            Console.Write(":");
            foreach (BDD cur in witness)
            {
                Console.Write(".");
            }
            Console.WriteLine(":");


            Assert.IsTrue(res == true, @"A-B must be nonempty");
        }
コード例 #2
0
        /// <summary>
        /// Returns true if the language of the current SFA is a subset of L(A)
        /// </summary>
        /// <param name="A">superset automaton</param>
        /// <returns>true if L(this) is subset of L(A)</returns>
        public bool IsSubsetOf(SFA <FUNC, TERM, SORT> A)
        {
            if (A == null)
            {
                throw new ArgumentNullException("A");
            }

            CheckCompatibiltyWith(A);

            List <TERM> w;
            bool        res = Automaton <TERM> .CheckDifference(this.automaton, A.automaton, 0, out w);

            return(!res);
        }
コード例 #3
0
        private static void LDiffExperimentZ3(BitWidth encoding)
        {
            List <string> regexes = new List <string>(SampleRegexes.regexes);

            regexes.RemoveRange(2, regexes.Count - 2);                                    //just consider the first 5 cases

            long timeout = 5 * Microsoft.Automata.Internal.Utilities.HighTimer.Frequency; //5 sec

            for (int i = 0; i < regexes.Count; i++)
            {
                for (int j = 0; j < regexes.Count; j++)
                {
                    string regexA = regexes[i];
                    string regexB = regexes[j];

                    var z3p = new Z3Provider(encoding);

                    z3p.MainSolver.Push();

                    var A = z3p.RegexConverter.Convert(regexA, System.Text.RegularExpressions.RegexOptions.None);
                    var B = z3p.RegexConverter.Convert(regexB, System.Text.RegularExpressions.RegexOptions.None);
                    //A.ShowGraph();
                    try
                    {
                        List <Expr> witness;
                        var         AmB = Automaton <Expr> .MkDifference(A, B, (int)timeout).Determinize().Minimize();

                        //AmB.ShowGraph();
                        bool isNonempty = Automaton <Expr> .CheckDifference(A, B, (int)timeout, out witness);

                        if (isNonempty)
                        {
                            string s = new String(Array.ConvertAll(witness.ToArray(), c => z3p.GetCharValue(z3p.MainSolver.FindOneMember(c).Value)));
                            Assert.IsTrue(Regex.IsMatch(s, regexA), s + " must match " + regexA);
                            Assert.IsFalse(Regex.IsMatch(s, regexB), s + " must not match " + regexB);
                        }
                    }
                    catch (TimeoutException)
                    {
                        Console.WriteLine("Timeout {0},{1}", i, j);
                    }

                    z3p.MainSolver.Pop();
                }
            }
        }
コード例 #4
0
        private static void LDiffExperimentBDD(BitWidth encoding)
        {
            var solver    = new CharSetSolver(encoding);
            var converter = solver;

            string[] regexes = SampleRegexes.regexes;

            long timeout = 60 * Microsoft.Automata.Internal.Utilities.HighTimer.Frequency; //1 minute

            int nonemptyCnt = 0;

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    string regexA = regexes[i];
                    string regexB = regexes[j];

                    long start = Microsoft.Automata.Internal.Utilities.HighTimer.Now;

                    var A = converter.Convert(regexA, System.Text.RegularExpressions.RegexOptions.None);
                    var B = converter.Convert(regexB, System.Text.RegularExpressions.RegexOptions.None);
                    try
                    {
                        List <BDD> witness;
                        bool       isNonempty;
                        isNonempty = Automaton <BDD> .CheckDifference(A, B, (int)timeout, out witness);

                        if (isNonempty)
                        {
                            nonemptyCnt += 1;
                            string s = solver.ChooseString(witness);
                            Assert.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(s, regexA), s + " must be a member of " + regexA);
                            Assert.IsFalse(System.Text.RegularExpressions.Regex.IsMatch(s, regexB), s + " must not be a member of " + regexB);
                        }
                    }
                    catch (TimeoutException)
                    {
                        Console.WriteLine("Timeout {0},{1}", i, j);
                    }
                }
            }
            Assert.AreEqual <int>(30, nonemptyCnt, "unexpected number of nonempty differences");
        }
コード例 #5
0
ファイル: AST.cs プロジェクト: wellsoftware/Automata
        internal override void RunQuery(EvaluationContext ec)
        {
            var         aut1 = subexpressions[0].GetSFA(ec);
            var         aut2 = subexpressions[1].GetSFA(ec);
            List <Expr> witness;
            bool        diff = Automaton <Expr> .CheckDifference(aut1.Automaton, aut2.Automaton, -1,
                                                                 out witness);

            if (diff)
            {
                char[] s = Array.ConvertAll(witness.ToArray(), e => GetChar(ec, e));
                ec.tw.WriteLine("Result: Subset relation is False");
                ec.tw.WriteLine("Counterexample: LHS-RHS contains {0}", Automata.StringUtility.Escape(new String(s)));
            }
            else
            {
                ec.tw.WriteLine("Result: Subset relation is True");
            }
        }
コード例 #6
0
        /*
         * IsYieldTypeSafe :
         * 2.1 Input parameters :
         * 2.1.1 Automaton<BvSet> implTypeCheckAutomaton : This input Automaton is generated for a phase of YTS checking of an impl.
         * 2.2 Return value : returns true if input automaton is subset of YTS property autoamaton.
         * 2.3 Action : Subset checking for a phase of an implementation. f L(YTSI) is subset of L(YTSP) {TRUE} else {FALSE}
         */
        public static bool IsYieldTypeSafe(Automaton <BvSet> implTypeCheckAutomaton, Implementation impl, MoverTypeChecker moverTypeChecker, int phaseNum)
        {
            List <BvSet> witnessSet;

            var isNonEmpty = Automaton <BvSet> .CheckDifference(
                implTypeCheckAutomaton,
                yieldTypeCheckerAutomaton,
                0,
                yieldTypeCheckerAutomatonSolver,
                out witnessSet);

#if DEBUG && !DEBUG_DETAIL
            var    diffAutomaton          = implTypeCheckAutomaton.Minus(yieldTypeCheckerAutomaton, yieldTypeCheckerAutomatonSolver);
            string diffAutomatonGraphName = "diffAutomaton" + impl.Proc.Name + phaseNum.ToString();
            yieldTypeCheckerAutomatonSolver.ShowGraph(diffAutomaton, diffAutomatonGraphName + ".dgml");
#endif

#if DEBUG && !DEBUG_DETAIL
            string s = yieldTypeCheckerAutomatonSolver.GenerateMember(implTypeCheckAutomaton);
            Console.WriteLine("\n member " + s + " \n");
            if (!yieldTypeCheckerAutomatonSolver.Accepts(yieldTypeCheckerAutomaton, s))
            {
                Console.WriteLine("Property Automaton accepts a random member of impl_automaton " + s);
            }
            else
            {
                Console.WriteLine("Property Automaton does not accept a random member of impl_automaton " + s);
            }
#endif
            if (isNonEmpty)
            {
                var witness = new String(Array.ConvertAll(witnessSet.ToArray(), bvset => (char)yieldTypeCheckerAutomatonSolver.Choose(bvset)));
                moverTypeChecker.Error(impl, "\n Body of " + impl.Proc.Name + " has invalid trace of actions " + witness + "\n");
                return(false);
            }

            return(true);
        }
コード例 #7
0
ファイル: SSA.cs プロジェクト: matejchalk/ARMC
 /// <summary>
 /// Checks if L(this) is a subset of L(M). If not, produces witness.
 /// </summary>
 public bool IsSubsetOf(SSA <SYMBOL> m, out List <Predicate <SYMBOL> > witness)
 {
     return(!(Automaton <Predicate <SYMBOL> > .CheckDifference(this.automaton, m.automaton, 0, out witness)));
 }