public static bool check(ArithmeticLanguage language, SymbolicString pumpingString)
        {
            if (pumpingString.GetIntegerVariables().Count() != 1)
            {
                return(false);
            }
            var pumpingLength         = pumpingString.GetIntegerVariables().First();
            var pumpingLengthVariable = PumpingLemma.LinearIntegerExpression
                                        .SingleTerm(1, pumpingLength);
            var additionalConstraint = LogicalExpression.And(
                PumpingLemma.ComparisonExpression.GreaterThan(pumpingLengthVariable, 0),
                LogicalExpression.And(pumpingString.repeats().Select(x => ComparisonExpression.GreaterThanOrEqual(x, 0)))
                );

            // 0. Need to check if pumping string grows unboundedly with p
            var pumpingStringLength = pumpingString.length();

            if (pumpingStringLength.isConstant() || pumpingStringLength.coefficients[pumpingLength] < 0)
            {
                return(false);
            }
            foreach (var r in pumpingString.repeats())
            {
                if (r.coefficients[pumpingLength] < 0)
                {
                    return(false);
                }
            }

            // 1. Check that the pumping string is in the language for all p
            if (!checkContainment(pumpingString, language, additionalConstraint))
            {
                return(false);
            }

            Console.WriteLine("Language is non-regular if all the following splits are good:");
            int i = 0;

            // 2. Check that each split of the pumping string has an valid pumping length
            foreach (var split in pumpingString.ValidSplits(pumpingLengthVariable, additionalConstraint))
            {
                Console.WriteLine("\t" + (i++) + ": " + split + " when " + additionalConstraint);
                if (!splitGood(split, language, additionalConstraint))
                {
                    return(false);
                }
            }

            return(true);
        }
        public static BooleanExpression containmentCondition(SymbolicString s, ArithmeticLanguage l, BooleanExpression additionalConstraints)
        {
            // Console.WriteLine("Checking containment of " + s + " in " + l);
            var goodMatches = Matcher
                              .match(s, l.symbolic_string)
                              .Select(x => x.forceFinish())
                              .Select(x => x.withAdditionalConstraint(l.constraint))
                              .Where(x => x.isFeasible())
            ;

            if (goodMatches.Count() == 0)
            {
                return(LogicalExpression.False());
            }

            var matchCondition = LogicalExpression.False();

            foreach (var match in goodMatches)
            {
                System.Diagnostics.Debug.WriteLine("Got good match: " + match);
                matchCondition = LogicalExpression.Or(matchCondition, match.constraint);
            }
            var condition = LogicalExpression.Implies(additionalConstraints, matchCondition);

            var variables     = condition.GetVariables();
            var pVariables    = s.GetIntegerVariables(); // Most of the times, should be 1
            var nonPVariables = variables.Where(x => !pVariables.Contains(x));

            var eCondition = QuantifiedExpression.Exists(nonPVariables, condition);
            var aCondition = QuantifiedExpression.Forall(pVariables, eCondition);

            return(aCondition);
        }
예제 #3
0
        public HashSet <VariableType> GetIntegerVariables()
        {
            HashSet <VariableType> ret;

            switch (expression_type)
            {
            case SymbolicStringType.Repeat:
                ret = root.GetIntegerVariables();
                foreach (VariableType v in repeat.GetVariables())
                {
                    ret.Add(v);
                }
                break;

            case SymbolicStringType.Concat:
                ret = new HashSet <VariableType>();
                foreach (var sub in sub_strings)
                {
                    foreach (VariableType v in sub.GetIntegerVariables())
                    {
                        ret.Add(v);
                    }
                }
                break;

            case SymbolicStringType.Symbol:
                ret = new HashSet <VariableType>();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(ret);
        }
예제 #4
0
        public static bool check(ArithmeticLanguage language, SymbolicString pumpingString)
        {
            if (pumpingString.GetIntegerVariables().Count() != 1)
                return false;
            var pumpingLength = pumpingString.GetIntegerVariables().First();
            var pumpingLengthVariable = PumpingLemma.LinearIntegerExpression
                .SingleTerm(1, pumpingLength);
            var additionalConstraint = LogicalExpression.And(
                PumpingLemma.ComparisonExpression.GreaterThan(pumpingLengthVariable, 0),
                LogicalExpression.And(pumpingString.repeats().Select(x => ComparisonExpression.GreaterThanOrEqual(x, 0)))
            );

            // 0. Need to check if pumping string grows unboundedly with p
            var pumpingStringLength = pumpingString.length();
            if (pumpingStringLength.isConstant() || pumpingStringLength.coefficients[pumpingLength] < 0)
                return false;
            foreach (var r in pumpingString.repeats())
                if (r.coefficients[pumpingLength] < 0)
                    return false;

            // 1. Check that the pumping string is in the language for all p
            if (!checkContainment(pumpingString, language, additionalConstraint))
                return false;

            Console.WriteLine("Language is non-regular if all the following splits are good:");
            int i = 0;
            // 2. Check that each split of the pumping string has an valid pumping length 
            foreach (var split in pumpingString.ValidSplits(pumpingLengthVariable, additionalConstraint))
            {
                Console.WriteLine("\t" + (i++) + ": " + split + " when " + additionalConstraint);
                if (!splitGood(split, language, additionalConstraint))
                    return false;
            }

            return true;
        }
예제 #5
0
        public static BooleanExpression containmentCondition(SymbolicString s, ArithmeticLanguage l, BooleanExpression additionalConstraints)
        {
            // Console.WriteLine("Checking containment of " + s + " in " + l);
            var goodMatches = Matcher
                .match(s, l.symbolic_string)
                .Select(x => x.forceFinish())
                .Select(x => x.withAdditionalConstraint(l.constraint))
                .Where(x => x.isFeasible())
                ;
            if (goodMatches.Count() == 0)
                return LogicalExpression.False();

            var matchCondition = LogicalExpression.False();
            foreach (var match in goodMatches)
            {
                // Console.WriteLine("Got good match: " + match);
                matchCondition = LogicalExpression.Or(matchCondition, match.constraint);
            }
            var condition = LogicalExpression.Implies(additionalConstraints, matchCondition);

            var variables = condition.GetVariables();
            var pVariables = s.GetIntegerVariables(); // Most of the times, should be 1
            var nonPVariables = variables.Where(x => !pVariables.Contains(x));

            var eCondition = QuantifiedExpression.Exists(nonPVariables, condition);
            var aCondition = QuantifiedExpression.Forall(pVariables, eCondition);

            return aCondition;
        }