use of catdata.provers.KBOptions in project fql by CategoricalData.
the class OplToKB method convert.
@SuppressWarnings({ "unchecked", "rawtypes" })
private OplKB<C, V> convert(OplSig<S, C, V> s) {
if (s.prec.keySet().size() != new HashSet<>(s.prec.values()).size()) {
throw new RuntimeException("Cannot duplicate precedence: " + s.prec);
}
// if (!Collections.disjoint(Arrays.asList(KBHorn.reserved), s.symbols.keySet())) {
// throw new RuntimeException("Theory contains reserved symbol, one of " + Arrays.toString(KBHorn.reserved));
// }
Map<C, Pair<List<S>, S>> symbols = new HashMap<>(s.symbols);
List one = new LinkedList();
one.add(new Unit());
List two = new LinkedList();
two.add(new Unit());
two.add(new Unit());
symbols.put((C) KBHorn._eq, new Pair(two, new Unit()));
symbols.put((C) KBHorn._or, new Pair(two, new Unit()));
symbols.put((C) KBHorn._not, new Pair(one, new Unit()));
symbols.put((C) KBHorn._true, new Pair(new LinkedList(), new Unit()));
symbols.put((C) KBHorn._false, new Pair(new LinkedList(), new Unit()));
Function<Pair<C, C>, Boolean> gt = x -> {
Integer l = s.prec.get(x.first);
Integer r = s.prec.get(x.second);
if (l != null && r != null) {
return l > r;
}
if (l == null && r != null) {
return false;
}
if (l != null) {
return true;
}
String lx = x.first.toString();
String rx = x.second.toString();
if (!symbols.containsKey(x.first)) {
throw new RuntimeException("Missing: " + x.first);
}
int la = symbols.get(x.first).first.size();
int ra = symbols.get(x.second).first.size();
if (la == ra) {
if (lx.length() == rx.length()) {
return lx.compareTo(rx) < 0;
}
return lx.length() < rx.length();
}
if (la >= 3 && ra >= 3) {
return la > ra;
}
if (la == 0 && ra > 0) {
return false;
}
if (la == 1 && (ra == 0 || ra == 2)) {
return true;
}
if (la == 1 && ra > 2) {
return false;
}
if (la == 2 && ra == 0) {
return true;
}
if (la == 2 && (ra == 1 || ra > 2)) {
return false;
}
if (la >= 3 || ra >= 3) {
// added Aug 3 16
return la > ra;
}
throw new RuntimeException("Bug in precedence, report to Ryan: la=" + la + ", ra=" + ra + ", l=null r=null");
// function symbols: arity-0 < arity-2 < arity-1 < arity-3 < arity-4
};
Set<Pair<KBExp<C, V>, KBExp<C, V>>> eqs = new HashSet<>();
for (Triple<?, OplTerm<C, V>, OplTerm<C, V>> eq : s.equations) {
eqs.add(new Pair<>(convert(eq.second), convert(eq.third)));
}
Set<Pair<KBExp<C, V>, KBExp<C, V>>> rs = new HashSet<>();
for (Triple<?, List<Pair<OplTerm<C, V>, OplTerm<C, V>>>, List<Pair<OplTerm<C, V>, OplTerm<C, V>>>> impl : s.implications) {
rs.addAll(convert(impl.second, impl.third));
}
KBOptions options = new KBOptions(DefunctGlobalOptions.debug.opl.opl_prover_unfailing, DefunctGlobalOptions.debug.opl.opl_prover_sort, DefunctGlobalOptions.debug.opl.opl_allow_horn && !s.implications.isEmpty(), DefunctGlobalOptions.debug.opl.opl_prover_ac, DefunctGlobalOptions.debug.opl.opl_prover_timeout, DefunctGlobalOptions.debug.opl.opl_prover_reduction_limit, DefunctGlobalOptions.debug.opl.opl_prover_filter_subsumed, /* NEWDEBUG.debug.opl.simplify, */
DefunctGlobalOptions.debug.opl.opl_prover_compose, false);
return new OplKB(eqs, KBOrders.lpogt(DefunctGlobalOptions.debug.opl.opl_allow_horn && !s.implications.isEmpty(), gt), fr, rs, options);
}
Aggregations