public Object visitQuantifiedSentence(QuantifiedSentence sentence,
Object arg)
{
Sentence quantified = sentence.getQuantified();
List<Variable> universalScope = (List<Variable>)arg;
// Skolemize: Skolemization is the process of removing existential
// quantifiers by elimination. This is done by introducing Skolem
// functions. The general rule is that the arguments of the Skolem
// function are all the universally quantified variables in whose
// scope the existential quantifier appears.
if (Quantifiers.isEXISTS(sentence.getQuantifier()))
{
Dictionary<Variable, Term> skolemSubst = new Dictionary<Variable, Term>();
foreach (Variable eVar in sentence.getVariables())
{
if (universalScope.Count > 0)
{
// Replace with a Skolem Function
String skolemFunctionName = parser.getFOLDomain()
.addSkolemFunction();
skolemSubst.Add(eVar, new Function(skolemFunctionName,
new List<Term>(universalScope)));
}
else
{
// Replace with a Skolem Constant
String skolemConstantName = parser.getFOLDomain()
.addSkolemConstant();
skolemSubst.Add(eVar, new Constant(skolemConstantName));
}
}
Sentence skolemized = substVisitor.subst(skolemSubst, quantified);
return skolemized.accept(this, arg);
}
// Drop universal quantifiers.
if (Quantifiers.isFORALL(sentence.getQuantifier()))
{
// Add to the universal scope so that
// existential skolemization may be done correctly
universalScope.AddRange(sentence.getVariables());
Sentence droppedUniversal = (Sentence)quantified.accept(this, arg);
// Enusre my scope is removed before moving back up
// the call stack when returning
foreach (Variable s in sentence.getVariables())
{
universalScope.Remove(s);
}
return droppedUniversal;
}
// Should not reach here as have already
// handled the two quantifiers.
throw new ApplicationException("Unhandled Quantifier:"
+ sentence.getQuantifier());
}
}