Search in sources :

Example 1 with KBApp

use of catdata.provers.KBExp.KBApp in project fql by CategoricalData.

the class KBHorn method eq.

public static <C, V> KBExp<C, V> eq(KBExp<C, V> e1, KBExp<C, V> e2) {
    List l = new LinkedList();
    l.add(e1);
    l.add(e2);
    return new KBApp<>(_eq, l);
}
Also used : KBApp(catdata.provers.KBExp.KBApp) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 2 with KBApp

use of catdata.provers.KBExp.KBApp in project fql by CategoricalData.

the class ProgramProver method step.

private KBExp<C, V> step(KBExp<C, V> ee) {
    if (Thread.currentThread().isInterrupted()) {
        throw new RuntimeInterruptedException(new InterruptedException());
    }
    if (ee.isVar) {
        return step1(ee);
    } else {
        KBApp<C, V> e = ee.getApp();
        List<KBExp<C, V>> args0 = new LinkedList<>();
        for (KBExp<C, V> arg : e.args) {
            // needs to be step for correctness
            args0.add(step(arg));
        }
        KBApp<C, V> ret = new KBApp<>(e.f, args0);
        return step1(ret);
    }
}
Also used : KBApp(catdata.provers.KBExp.KBApp) RuntimeInterruptedException(catdata.RuntimeInterruptedException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) LinkedList(java.util.LinkedList)

Example 3 with KBApp

use of catdata.provers.KBExp.KBApp in project fql by CategoricalData.

the class KBHorn method not.

public static <C, V> KBExp<C, V> not(KBExp<C, V> e) {
    List l = new LinkedList<>();
    l.add(e);
    return new KBApp<>(_not, l);
}
Also used : KBApp(catdata.provers.KBExp.KBApp) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 4 with KBApp

use of catdata.provers.KBExp.KBApp in project fql by CategoricalData.

the class KBHorn method or.

public static <C, V> KBExp<C, V> or(KBExp<C, V> e1, KBExp<C, V> e2) {
    List l = new LinkedList();
    l.add(e1);
    l.add(e2);
    return new KBApp<>(_or, l);
}
Also used : KBApp(catdata.provers.KBExp.KBApp) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 5 with KBApp

use of catdata.provers.KBExp.KBApp in project fql by CategoricalData.

the class KBOrders method lpogt.

public static <C, V> Function<Pair<KBExp<C, V>, KBExp<C, V>>, Boolean> lpogt(boolean horn, Function<Pair<C, C>, Boolean> gt) {
    // LPO<C,V> check = new LPO<>(gt);
    Function<Pair<KBExp<C, V>, KBExp<C, V>>, Boolean> ret = new Function<Pair<KBExp<C, V>, KBExp<C, V>>, Boolean>() {

        @Override
        public Boolean apply(Pair<KBExp<C, V>, KBExp<C, V>> xxx) {
            KBExp<C, V> s = xxx.first;
            KBExp<C, V> t = xxx.second;
            // for horn clauses
            if (horn) {
                if (KBHorn.isAtom(s) && !KBHorn.isAtom(t)) {
                    return true;
                }
                if (s.equals(KBHorn.fals()) && t.equals(KBHorn.tru())) {
                    return true;
                }
                if (t.equals(KBHorn.fals())) {
                    return true;
                }
            }
            if (!s.isVar && s.getApp().f.equals(new NewConst()) && !t.isVar && t.getApp().f.equals(new NewConst()) || !s.isVar && s.getApp().f.equals(new NewConst())) {
                return false;
            } else if (!t.isVar && t.getApp().f.equals(new NewConst())) {
                return true;
            }
            // LPO1
            if (t.isVar) {
                return !t.equals(s) && s.vars().contains(t.getVar().var);
            }
            if (s.isVar) {
                // }
                return false;
            }
            // LPO2
            KBApp<C, V> s0 = s.getApp();
            KBApp<C, V> t0 = t.getApp();
            C f = s0.f;
            C g = t0.f;
            // LPO2a
            for (KBExp<C, V> si : s0.args) {
                if (apply(new Pair<>(si, t)) || si.equals(t)) {
                    return true;
                }
            }
            // LPO2b
            if (gt.apply(new Pair<>(f, g))) {
                for (KBExp<C, V> ti : t0.args) {
                    if (!apply(new Pair<>(s, ti))) {
                        return false;
                    }
                }
                return true;
            }
            // LPO2c
            if (f.equals(g)) {
                for (KBExp<C, V> ti : t0.args) {
                    if (!apply(new Pair<>(s0, ti))) {
                        return false;
                    }
                }
                int i = 0;
                for (KBExp<C, V> si : s0.args) {
                    if (i > t0.args.size()) {
                        return false;
                    }
                    KBExp<C, V> ti = t0.args.get(i++);
                    if (apply(new Pair<>(si, ti))) {
                        return true;
                    }
                    if (apply(new Pair<>(ti, si))) {
                        return false;
                    }
                    if (si.equals(ti)) {
                        continue;
                    }
                    return false;
                }
            }
            return false;
        }
    };
    return x -> {
        Boolean b1 = ret.apply(x);
        /* if (!b1.equals(b2)) {
				throw new RuntimeException("Internal consistency error, report to Ryan: On " + x + " orig " + b1 + " but now " + b2);
			}  */
        return b1;
    };
}
Also used : KBApp(catdata.provers.KBExp.KBApp) NewConst(catdata.opl.OplKB.NewConst) Function(java.util.function.Function) Pair(catdata.Pair) NewConst(catdata.opl.OplKB.NewConst) Function(java.util.function.Function) Pair(catdata.Pair)

Aggregations

KBApp (catdata.provers.KBExp.KBApp)5 LinkedList (java.util.LinkedList)4 List (java.util.List)3 Pair (catdata.Pair)1 RuntimeInterruptedException (catdata.RuntimeInterruptedException)1 NewConst (catdata.opl.OplKB.NewConst)1 Function (java.util.function.Function)1