private ParsingResult parseLeaf(Node leaf, int timeIndex, int intervalDuration) { string leafExpression = leaf.getExpression(); string result = leafExpression; double number; if (!double.TryParse(result, out number)) { string timeVariable = timeIndex == 0 ? "time" : string.Format("t{0}", timeIndex); if (intervalDuration > 0) { timeVariable = string.Format("(+ {0} {1})", timeVariable, intervalDuration); } List <string> expressions = new List <string> { timeVariable }; ICollection <string> functionInputs = PropositionParser.extractParameters(leafExpression); string functionName = PropositionParser.extractName(leafExpression); foreach (string fInput in functionInputs) { expressions.Add(fInput); } result = SMTConstructsInstantiator.instantiateNaryOperator(functionName, expressions.ToArray()); } return(new ParsingResult(result)); }
private ParsingResult parseAFPathOperator(InternalNode afOperator, int lastTimeIndex, int intervalDuration) { string operatorString = afOperator.getExpression(); int myTimeIndex = lastTimeIndex + 1; bool isBounded = operatorString.Contains("<"); string result = ""; string quantifiedVariable = myTimeIndex < 1 ? "time" : string.Format("t{0}", myTimeIndex); string lowerBoundTimeVariable = ""; if (myTimeIndex == 1) { lowerBoundTimeVariable = "time"; } if (myTimeIndex > 1) { lowerBoundTimeVariable = string.Format("t{0}", myTimeIndex - 1); } List <string> afExpressions = new List <string>(); string innerExpression = parseNode(afOperator.getRightHandSide(), myTimeIndex, intervalDuration).SmtExpression; string lowerBound = ""; if (myTimeIndex > 0) { lowerBound = SMTConstructsInstantiator.instantiateBinaryOperator(">", quantifiedVariable, lowerBoundTimeVariable); } /*afExpressions[afExpressions.Length] = innerExpression; * afExpressions[afExpressions.Length] = lowerBound; */ afExpressions.Add(innerExpression); afExpressions.Add(lowerBound); if (isBounded) { string upperBound = SMTConstructsInstantiator.instantiateBinaryOperator("<", quantifiedVariable, SMTConstructsInstantiator.instantiateBinaryOperator("+", lowerBoundTimeVariable, extractUpperBound(operatorString).ToString())); afExpressions.Add(upperBound); //afExpressions[afExpressions.Length] = upperBound; } result = SMTConstructsInstantiator.instantiateQuantifier("exists", SMTConstructsInstantiator.instantiateUnaryOperator(quantifiedVariable, "Real"), SMTConstructsInstantiator.instantiateNaryOperator("and", afExpressions.ToArray())); return(new ParsingResult(result, intervalDuration)); }
private ParsingResult parseUPathOperator(InternalNode uOperator, int timeIndex, int intervalDuration) { string operatorString = uOperator.getExpression().Trim(); bool isBounded = operatorString.Contains("<"); string result = ""; /* Unitl operator encoded as SMT-LIB assertion * AG(p -> A(q U r)) * (exists ((t1 Real)) (and (> t1 t) (< t1 (+ t k)) * (r t1) * (not (exists ((t2 Real)) (and (>= t2 t) (< t2 t1) (not (q t2))))))) */ string baseTimeVariable = timeIndex <= 0 ? "time" : string.Format("t{0}", timeIndex); string outerQuantifiedTimeVariable = string.Format("t{0}", (timeIndex) + 1); string innerQuantifiedTimeVariable = string.Format("t{0}", (timeIndex) + 2); string outerQLowerBound = SMTConstructsInstantiator.instantiateBinaryOperator(">", outerQuantifiedTimeVariable, intervalDuration <= 0 ? baseTimeVariable : SMTConstructsInstantiator.instantiateBinaryOperator("+", baseTimeVariable, intervalDuration.ToString())); string outerQUpperBound = ""; if (isBounded) { outerQUpperBound = SMTConstructsInstantiator.instantiateBinaryOperator("<", outerQuantifiedTimeVariable, SMTConstructsInstantiator.instantiateBinaryOperator("+", intervalDuration <= 0 ? baseTimeVariable : SMTConstructsInstantiator .instantiateBinaryOperator("+", baseTimeVariable, intervalDuration.ToString()), extractUpperBound(operatorString).ToString())); } string innerQLowerBound = SMTConstructsInstantiator.instantiateBinaryOperator(">", innerQuantifiedTimeVariable, intervalDuration <= 0 ? baseTimeVariable : SMTConstructsInstantiator.instantiateBinaryOperator("+", baseTimeVariable, intervalDuration.ToString())); string innerQUpperBound = SMTConstructsInstantiator.instantiateBinaryOperator("<", innerQuantifiedTimeVariable, outerQuantifiedTimeVariable); //string[] innerExistsExpressions = new string[] { }; List <string> innerExistsExpressions = new List <string>(); string innerExpression = SMTConstructsInstantiator.instantiateUnaryOperator("not", parseNode(uOperator.getLeftHandSide(), timeIndex + 2, 0).SmtExpression); innerExistsExpressions.Add(innerExpression); innerExistsExpressions.Add(innerQLowerBound); innerExistsExpressions.Add(innerQUpperBound); string innerExsists = SMTConstructsInstantiator.instantiateUnaryOperator("not", SMTConstructsInstantiator.instantiateQuantifier("exists", SMTConstructsInstantiator.instantiateUnaryOperator(innerQuantifiedTimeVariable, "Real"), SMTConstructsInstantiator.instantiateNaryOperator("and", innerExistsExpressions.ToArray()))); //string[] outerExistsExpressions = new string[] { }; List <string> outerExistsExpressions = new List <string>(); /*outerExistsExpressions[outerExistsExpressions.Length] = innerExsists; * outerExistsExpressions[outerExistsExpressions.Length] = outerQLowerBound;*/ outerExistsExpressions.Add(innerExsists); Node rhsNode = uOperator.getRightHandSide(); string rightHandSide = parseNode(uOperator.getRightHandSide(), timeIndex + 1, 0).SmtExpression; outerExistsExpressions.Add(rightHandSide); outerExistsExpressions.Add(outerQLowerBound); outerExistsExpressions.Add(outerQUpperBound); result = SMTConstructsInstantiator.instantiateQuantifier("exists", SMTConstructsInstantiator.instantiateUnaryOperator(outerQuantifiedTimeVariable, "Real"), SMTConstructsInstantiator.instantiateNaryOperator("and", outerExistsExpressions.ToArray()) ); if (timeIndex < 0) { result = SMTConstructsInstantiator.instantiateQuantifier("forall", SMTConstructsInstantiator.instantiateUnaryOperator("time", "Real"), result); } return(new ParsingResult(result)); }
private ParsingResult parseAGPathOperator(InternalNode agOperator, int lastUsedTimeIndex, int intervalDuration) { string operatorString = agOperator.getExpression(); int myTimeIndex = lastUsedTimeIndex + 1; string result = ""; bool isBounded = operatorString.Contains("<"); string quantifiedVariable = myTimeIndex <= 0 ? "time" : string.Format("t{0}", myTimeIndex); /*special case only for the outmost AG (if any)*/ if (myTimeIndex < 1 && !isBounded) { ParsingResult innerParsingResult = parseNode(agOperator.getRightHandSide(), myTimeIndex, intervalDuration); intervalDuration = innerParsingResult.IntervalDuration; result = SMTConstructsInstantiator .instantiateQuantifier("forall", SMTConstructsInstantiator.instantiateUnaryOperator(quantifiedVariable, "Real"), innerParsingResult.SmtExpression); } else { ParsingResult innerExpressionParsingResult = parseNode(agOperator.getRightHandSide(), myTimeIndex, intervalDuration); string inmostExpression = innerExpressionParsingResult.SmtExpression; intervalDuration = innerExpressionParsingResult.IntervalDuration; string negation = SMTConstructsInstantiator.instantiateUnaryOperator("not", inmostExpression); if (isBounded) { if (intervalDuration == 0) { intervalDuration = extractUpperBound(operatorString); } List <string> agExpressions = new List <string>(); string lowerBoundVariable = ""; if (myTimeIndex <= 1) { lowerBoundVariable = "time"; } if (myTimeIndex > 1) { lowerBoundVariable = string.Format("t{0}", lastUsedTimeIndex); } string upperBound = SMTConstructsInstantiator.instantiateBinaryOperator("<", quantifiedVariable, SMTConstructsInstantiator.instantiateBinaryOperator("+", lowerBoundVariable, extractUpperBound(operatorString).ToString())); string lowerBound = SMTConstructsInstantiator.instantiateBinaryOperator(">", quantifiedVariable, lowerBoundVariable); agExpressions.Add(lowerBound); agExpressions.Add(upperBound); agExpressions.Add(negation); result = SMTConstructsInstantiator.instantiateUnaryOperator("not", SMTConstructsInstantiator.instantiateQuantifier("exists", SMTConstructsInstantiator.instantiateUnaryOperator(quantifiedVariable, "Real"), SMTConstructsInstantiator.instantiateNaryOperator("and", agExpressions.ToArray()) ) ); //lowerBound, upperBound, newTimeIndex, negation)); /*SMTConstructsInstantiator.instantiateUnaryOperator("not", * SMTConstructsInstantiator.instantiateBoundedQuantifier("exists", lowerBound, upperBound, newTimeIndex, negation));*/ } else { if (intervalDuration <= 0 && innerExpressionParsingResult.IntervalDuration > 0) { intervalDuration = 0; } result = SMTConstructsInstantiator.instantiateUnaryOperator("not", SMTConstructsInstantiator.instantiateQuantifier("exists", SMTConstructsInstantiator.instantiateUnaryOperator(quantifiedVariable, "Real"), negation)); //SMTConstructsInstantiator.instantiateUnboundedQuantifier("exists", newTimeIndex, negation)); } } return(new ParsingResult(result, intervalDuration)); }