Search in sources :

Example 6 with ITermVar

use of mb.nabl2.terms.ITermVar in project nabl by metaborg.

the class PersistentUnifier method unequalVars.

private boolean unequalVars(final ITermVar left, final ITermVar right, Set<Set2<ITermVar>> stack, final java.util.Map<Set2<ITermVar>, Boolean> visited) {
    final ITermVar leftRep = findRep(left);
    final ITermVar rightRep = findRep(right);
    if (leftRep.equals(rightRep)) {
        return false;
    }
    final Set2<ITermVar> pair = Set2.of(leftRep, rightRep);
    final boolean unequal;
    if (!visited.containsKey(pair)) {
        stack.add(pair);
        visited.put(pair, false);
        final ITerm leftTerm = terms().get(leftRep);
        final ITerm rightTerm = terms().get(rightRep);
        unequal = (leftTerm != null && rightTerm != null) ? unequalTerms(leftTerm, rightTerm, stack, visited) : false;
        visited.put(pair, unequal);
        stack.remove(pair);
    } else if (stack.contains(pair)) {
        unequal = false;
    } else {
        unequal = visited.get(pair);
    }
    return unequal;
}
Also used : ITermVar(mb.nabl2.terms.ITermVar) ITerm(mb.nabl2.terms.ITerm)

Example 7 with ITermVar

use of mb.nabl2.terms.ITermVar in project nabl by metaborg.

the class UnificationPerformanceTest method testCycle.

private static void testCycle() {
    System.out.println("Testing cycle");
    final IUnifier.Transient unifier = PersistentUnifier.Transient.of();
    ITermVar varA = TermBuild.B.newVar("", A);
    ITermVar varB = TermBuild.B.newVar("", B);
    ITermVar varC = TermBuild.B.newVar("", C);
    ITerm termB = TermBuild.B.newTuple(varB, varB);
    ITerm termC = TermBuild.B.newTuple(varC, varC);
    try {
        unifier.unify(varA, termB);
        unifier.unify(varB, termC);
        unifier.unify(varC, termB);
        System.out.println(unifier);
    } catch (UnificationException e) {
        System.out.println("Could not unify");
    }
    System.out.println("ground = " + unifier.isGround(termB));
    System.out.println("cyclic = " + unifier.isCyclic(termB));
    System.out.println("size = " + unifier.size(termB));
    System.out.println("vars = " + unifier.getVars(termB));
    System.out.println("equal = " + unifier.areEqual(termB, termC));
    System.out.println("unequal = " + unifier.areUnequal(termB, termC));
}
Also used : ITermVar(mb.nabl2.terms.ITermVar) ITerm(mb.nabl2.terms.ITerm)

Example 8 with ITermVar

use of mb.nabl2.terms.ITermVar in project nabl by metaborg.

the class VarMultimap method remove.

public boolean remove(ITermVar key, T value, IUnifier unifier) {
    final Set<ITermVar> reps = unifier.getVars(key);
    boolean change = false;
    for (ITermVar rep : reps) {
        change |= map.remove(rep, value);
    }
    return change;
}
Also used : ITermVar(mb.nabl2.terms.ITermVar)

Example 9 with ITermVar

use of mb.nabl2.terms.ITermVar in project nabl by metaborg.

the class VarMultimap method put.

public boolean put(ITermVar key, T value, IUnifier unifier) {
    final Set<ITermVar> reps = unifier.getVars(key);
    boolean change = false;
    for (ITermVar rep : reps) {
        change |= map.put(rep, value);
    }
    return change;
}
Also used : ITermVar(mb.nabl2.terms.ITermVar)

Example 10 with ITermVar

use of mb.nabl2.terms.ITermVar in project nabl by metaborg.

the class CExists method pp.

@Override
public IMessageContent pp() {
    // exists {a b c}. c
    final Builder builder = MessageContent.builder();
    builder.append("exists {");
    boolean first = true;
    for (ITermVar var : getEVars()) {
        if (first) {
            first = false;
        } else {
            builder.append(" ");
        }
        builder.append(var);
    }
    builder.append(": ");
    builder.append(getConstraint().pp());
    builder.append("}");
    return builder.build();
}
Also used : ITermVar(mb.nabl2.terms.ITermVar) Builder(mb.nabl2.constraints.messages.MessageContent.Builder)

Aggregations

ITermVar (mb.nabl2.terms.ITermVar)25 ITerm (mb.nabl2.terms.ITerm)15 Collection (java.util.Collection)3 Occurrence (mb.nabl2.scopegraph.terms.Occurrence)3 SolveResult (mb.nabl2.solver.ISolver.SolveResult)3 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 NaBL2DebugConfig (mb.nabl2.config.NaBL2DebugConfig)2 IConstraint (mb.nabl2.constraints.IConstraint)2 ImmutableTypeVar (mb.nabl2.poly.ImmutableTypeVar)2 TypeVar (mb.nabl2.poly.TypeVar)2 Scope (mb.nabl2.scopegraph.terms.Scope)2 ISolution (mb.nabl2.solver.ISolution)2 SolverException (mb.nabl2.solver.SolverException)2 TypeException (mb.nabl2.solver.TypeException)2 IUnifier (mb.nabl2.terms.unification.IUnifier)2 HashMultiset (com.google.common.collect.HashMultiset)1 Lists (com.google.common.collect.Lists)1