diff --git a/src/anthem/IntegerVariableDetection.cpp b/src/anthem/IntegerVariableDetection.cpp index debf039..49e1d70 100644 --- a/src/anthem/IntegerVariableDetection.cpp +++ b/src/anthem/IntegerVariableDetection.cpp @@ -565,6 +565,39 @@ struct CheckIfQuantifiedFormulaFalseFunctor //////////////////////////////////////////////////////////////////////////////////////////////////// +struct CheckIfCompletedFormulaTrueFunctor +{ + OperationResult operator()(ast::VariableDeclaration &variableDeclaration, + ast::Formula &, ast::Formula &completedFormula, VariableDomainMap &variableDomainMap) + { + if (variableDeclaration.domain != ast::Domain::Unknown) + return OperationResult::Unchanged; + + clearVariableDomainMap(variableDomainMap); + + auto result = evaluate(completedFormula, variableDomainMap); + + if (result == EvaluationResult::Error || result == EvaluationResult::True) + return OperationResult::Unchanged; + + // As a hypothesis, make the parameter’s domain noninteger + variableDomainMap[&variableDeclaration] = ast::Domain::General; + + result = evaluate(completedFormula, variableDomainMap); + + if (result == EvaluationResult::Error || result == EvaluationResult::True) + { + // If making the variable noninteger leads to a false or erroneous result, it’s proven to be integer + variableDeclaration.domain = ast::Domain::Integer; + return OperationResult::Changed; + } + + return OperationResult::Unchanged; + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + // Assumes the completed formulas to be in translated but not simplified form. // That is, completed formulas are either variable-free or universally quantified void detectIntegerVariables(std::vector &completedFormulas) @@ -581,6 +614,9 @@ void detectIntegerVariables(std::vector &completedFormulas) if (completedFormula.accept(ForEachVariableDeclarationVisitor(), variableDomainMap) == OperationResult::Changed) operationResult = OperationResult::Changed; + if (completedFormula.accept(ForEachVariableDeclarationVisitor(), completedFormula, variableDomainMap) == OperationResult::Changed) + operationResult = OperationResult::Changed; + if (!completedFormula.is()) continue;