Example #1
0
        public TreeNode <string> ExtractUnSATProgram(UnSatCore unSATCore, Grammar grammarGround, Context context)
        {
            var minIndex  = unSATCore.Min(x => x.index.ToInt());
            var rootCores = unSATCore.Where(x => x.index.ToInt() == minIndex).ToList();

            if (rootCores.Count(x => !x.exprInterVars.Args.First().ToString().Contains(Symbols.outputArg)) != 0)
            {
                return(null);
            }
            var result = unSATCore.GroupBy(x => x.index).Select(grp => grp.First()).OrderBy(x => x.index.ToInt()).ToList();

            var rule = grammarGround.productions.Where(x => x.component == rootCores.First().name).First();

            var rootOfUnSATCoreProgram = new TreeNode <string>();

            rootOfUnSATCoreProgram.FillHole(rule.component, rule, context, grammarGround, minIndex);

            foreach (var node in result.Skip(1))
            {
                rule = grammarGround.productions.Where(x => x.component == node.name).First();
                var temp = grammarGround.DFS(rootOfUnSATCoreProgram, x => x.index == node.index.ToInt()).Pop();
                temp.FillHole(rule.component, rule, context, grammarGround);
            }

            return(rootOfUnSATCoreProgram);
        }
Example #2
0
        public Lemma AnalyzeConflict(UnSatCore unSATCore, List <Z3ComponentSpecs> z3ComponentsSpecs, Context context, TreeNode <string> root, Grammar grammar)
        {
            var lemma = new Lemma();

            foreach (var clause in unSATCore)
            {
                //var rule = programRoot.GetAtIndex(Int32.Parse(clause.index)).rule;
                var rule = grammar.DFS(root, (x) => x.index == Int32.Parse(clause.index)).Pop().rule;
                var componentsToCheck = grammar.productions.Where(x => x.leftHandSide == rule.leftHandSide)
                                        .Select(x => x.rightHandSide.First()).ToList();

                var lemmaClause = new LemmaClause();

                lemmaClause.Add(context.MkNot(clause.expression));

                if (clause.spec != null && z3ComponentsSpecs.Any(x => x.key == clause.name && x.type != ComponentType.Parameter))
                {
                    foreach (var component in componentsToCheck)
                    {
                        var componentSpec = z3ComponentsSpecs.Where(x => x.key == component).FirstOrDefault();
                        if (componentSpec != null)
                        {
                            var z3ComponentSpec = context.MkAnd(ComponentSpecsBuilder.GetComponentSpec(componentSpec));

                            var check         = context.MkNot(context.MkImplies(z3ComponentSpec, clause.spec));
                            var lightEncoding = unSATCore.Where(x => x != clause);
                            if (SMTSolver.CheckIfUnSAT(context, check))
                            {
                                lemmaClause.Add(context.MkNot(context.MkBoolConst($"C_{clause.index}_{component}")));
                            }
                        }
                    }
                }
                //lemma.lemmaLength = unSATCores.SelectMany(x => x).Max(x => x.index).ToInt();
                lemma.Add(lemmaClause);
            }
            return(lemma);
        }