kodkod.ast.NotFormula Java Examples
The following examples show how to use
kodkod.ast.NotFormula.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormulaFlattener.java From kodkod with MIT License | 6 votes |
/** * Calls nf.formula.accept(this) after flipping the negation flag. * @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.NotFormula) */ public final void visit(NotFormula nf) { if (visited(nf)) return; final Map<Formula, Node> oldConjuncts = conjuncts; conjuncts = new LinkedHashMap<Formula, Node>(); negated = !negated; nf.formula().accept(this); negated = !negated; if (conjuncts.size()>1) { // was broken down further oldConjuncts.putAll(conjuncts); conjuncts = oldConjuncts; } else { // wasn't broken down further conjuncts = oldConjuncts; conjuncts.put(negated ? nf.formula() : nf, nf); } }
Example #2
Source File: FullNegationPropagator.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Calls nf.formula.accept(this) after flipping the negation flag. * * @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.NotFormula) */ @Override public final void visit(NotFormula nf) { if (visited(nf)) return; FullNegationPropagator fne = new FullNegationPropagator(shared, annotations); fne.negated = !negated; nf.formula().accept(fne); if (fne.hasChanged) { addConjunct(Formula.and(fne.conjuncts), false, nf); hasChanged = true; } else { addConjunct(nf); } }
Example #3
Source File: PartialCannonicalizer.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret!=null) return ret; final Formula child = not.formula().accept(this); ret = simplify(child); if (ret==null) { final int hash = hash(NotFormula.class, child); for(Iterator<PartialCannonicalizer.Holder<Formula>> itr = formulas.get(hash); itr.hasNext(); ) { final Formula next = itr.next().obj; if (next.getClass()==NotFormula.class) { if (((NotFormula)next).formula()==child) return cache(not, next); } } ret = child==not.formula() ? not : child.not(); formulas.add(new PartialCannonicalizer.Holder<Formula>(ret, hash)); } return cache(not,ret); }
Example #4
Source File: FormulaFlattener.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Calls nf.formula.accept(this) after flipping the negation flag. * * @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.NotFormula) */ @Override public final void visit(NotFormula nf) { if (visited(nf)) return; final Map<Formula,Node> oldConjuncts = conjuncts; conjuncts = new LinkedHashMap<Formula,Node>(); negated = !negated; nf.formula().accept(this); negated = !negated; if (conjuncts.size() > 1) { // was broken down further oldConjuncts.putAll(conjuncts); conjuncts = oldConjuncts; } else { // wasn't broken down further conjuncts = oldConjuncts; conjuncts.put(negated ? nf.formula() : nf, nf); } }
Example #5
Source File: PrettyPrinter.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * @ensures appends the given op and child to this.tokens; the child is * parenthesized if it's not an instance of not formula, constant * formula, or relation predicate. **/ @Override public void visit(NotFormula node) { append("!"); final boolean pchild = parenthesize(node.formula()); indent += pchild ? 2 : 1; visitChild(node.formula(), parenthesize(node.formula())); indent -= pchild ? 2 : 1; }
Example #6
Source File: AnnotatedNode.java From kodkod with MIT License | 5 votes |
/** * Visits the children of the child of the child formula, with * the negation of the current value of the negated flag, * if it has not already been visited * with the current value of this.negated; otherwise does nothing. */ public void visit(NotFormula not) { if (visited(not)) return; negated = !negated; not.formula().accept(this); negated = !negated; }
Example #7
Source File: PrettyPrinter.java From kodkod with MIT License | 5 votes |
/** @ensures appends the given op and child to this.tokens; the child is * parenthesized if it's not an instance of not formula, constant formula, or * relation predicate. **/ public void visit(NotFormula node) { append("!"); final boolean pchild = parenthesize(node.formula()); indent += pchild ? 2 : 1; visitChild(node.formula(), parenthesize(node.formula())); indent -= pchild ? 2 : 1; }
Example #8
Source File: Propagator.java From quetzal with Eclipse Public License 2.0 | 5 votes |
/** * Constructs a new propagator. */ private Propagator(Set<Formula> conjuncts, SparseSequence<Expression> empties, SparseSequence<IntConstant> constants) { super(empties, constants); this.conjuncts = conjuncts; this.negs = new LinkedHashSet<Formula>(); for(Formula f: conjuncts) { if (f instanceof NotFormula) negs.add(((NotFormula)f).formula()); } }
Example #9
Source File: Skolemizer.java From kodkod with MIT License | 5 votes |
/** * Calls not.formula.accept(this) after flipping the negation flag and returns the result. * @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.NotFormula) **/ public final Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret!=null) return ret; negated = !negated; // flip the negation flag final Formula retChild = not.formula().accept(this); negated = !negated; return retChild==not.formula() ? cache(not,not) : source(cache(not, retChild.not()), not); }
Example #10
Source File: Propagator.java From quetzal with Eclipse Public License 2.0 | 5 votes |
final boolean isFalse(Formula formula) { if (formula==Formula.FALSE) return true; else if (!conjuncts.contains(formula)) { if (formula.getClass()==NotFormula.class) { return conjuncts.contains(((NotFormula)formula).formula()); } else { return negs.contains(formula); } } return false; }
Example #11
Source File: AbstractCollector.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(not) and returns the cached value, if any. * If no cached value exists, visits the child, caches its return value and returns it. * @return let x = lookup(not) | * x != null => x, * cache(not, not.formula.accept(this)) */ public Set<T> visit(NotFormula not) { Set<T> ret = lookup(not); if (ret!=null) return ret; ret = newSet(); ret.addAll(not.formula().accept(this)); return cache(not, ret); }
Example #12
Source File: AbstractReplacer.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(binFormula) and returns the cached value, if any. * If a replacement has not been cached, visits the formula's * child. If nothing changes, the argument is cached and * returned, otherwise a replacement formula is cached and returned. * @return { n: NotFormula | n.child = not.child.accept(this) } */ public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret!=null) return ret; final Formula child = not.formula().accept(this); ret = (child==not.formula()) ? not : child.not(); return cache(not,ret); }
Example #13
Source File: TranslateKodkodToJava.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void visit(NotFormula x) { String newname = makename(x); if (newname == null) return; String sub = make(x.formula()); file.printf("Formula %s=%s.not();%n", newname, sub); }
Example #14
Source File: AnnotatedNode.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Visits the children of the child of the child formula, with the negation of * the current value of the negated flag, if it has not already been visited * with the current value of this.negated; otherwise does nothing. */ @Override public void visit(NotFormula not) { if (visited(not)) return; negated = !negated; not.formula().accept(this); negated = !negated; }
Example #15
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 5 votes |
/** @effects appends the given op and child to this.tokens; the child is * parenthesized if it's not an instance of not formula, constant formula, or * relation predicate. **/ public void visit(NotFormula node) { if (displayed(node)) return; negated = !negated; append("!"); final boolean pchild = parenthesize(node.formula()); indent += pchild ? 2 : 1; visitChild(node.formula(), parenthesize(node.formula())); indent -= pchild ? 2 : 1; negated = !negated; }
Example #16
Source File: Simplifier.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret!=null) return ret; final Formula child = not.formula().accept(this); ret = simplify(child); if (ret==null) { ret = child==not.formula() ? not : child.not(); } return cache(not,ret); }
Example #17
Source File: AbstractReplacer.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls lookup(binFormula) and returns the cached value, if any. If a * replacement has not been cached, visits the formula's child. If nothing * changes, the argument is cached and returned, otherwise a replacement formula * is cached and returned. * * @return { n: NotFormula | n.child = not.child.accept(delegate) } */ @Override public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret != null) return ret; final Formula child = not.formula().accept(delegate); ret = (child == not.formula()) ? not : child.not(); return cache(not, ret); }
Example #18
Source File: PrenexNFConverter.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
@Override public Formula visit(NotFormula not) { Formula sub = not.formula().accept(this); Pair p = new Pair(sub, null); Formula ans; if (p.hasNoQuant() && sub == not.formula()) ans = not; else if (p.hasNoQuant()) ans = sub.not(); else ans = pushNegation(p.leftQF); return saveMapping(ans, not); }
Example #19
Source File: AbstractVoidVisitor.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Visits the subformula if this.visited(not) returns false. Otherwise does * nothing. * * @ensures not.formula.accept(this) */ @Override public void visit(NotFormula not) { if (visited(not)) return; not.formula().accept(this); }
Example #20
Source File: FOL2BoolTranslator.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls lookup(not) and returns the cached value, if any. If a translation has * not been cached, translates the formula, calls cache(...) on it and returns * it. * * @return let t = lookup(not) | some t => t, cache(not, * !not.formula.accept(this)) */ @Override public final BooleanValue visit(NotFormula not) { BooleanValue ret = lookup(not); if (ret != null) return ret; env.negate(); ret = cache(not, interpreter.factory().not(not.formula().accept(this))); env.negate(); return ret; }
Example #21
Source File: Skolemizer.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls not.formula.accept(this) after flipping the negation flag and returns * the result. * * @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.NotFormula) **/ @Override public final Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret != null) return ret; negated = !negated; // flip the negation flag final Formula retChild = not.formula().accept(this); negated = !negated; return retChild == not.formula() ? cache(not, not) : source(cache(not, retChild.not()), not); }
Example #22
Source File: AbstractCollector.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls lookup(not) and returns the cached value, if any. If no cached value * exists, visits the child, caches its return value and returns it. * * @return let x = lookup(not) | x != null => x, cache(not, * not.formula.accept(this)) */ @Override public Set<T> visit(NotFormula not) { Set<T> ret = lookup(not); if (ret != null) return ret; ret = newSet(); ret.addAll(not.formula().accept(this)); return cache(not, ret); }
Example #23
Source File: TrivialProof.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * If the argument node has been been visited, adds it to this.relevant and * visits its child. */ @Override public void visit(NotFormula not) { if (visited(not)) return; relevant.add(not); not.formula().accept(this); }
Example #24
Source File: Simplifier.java From quetzal with Eclipse Public License 2.0 | 5 votes |
/** @return a simplification of !child, if possible, or null otherwise. */ final Formula simplify(Formula child) { // can only simplify in the case of not with constants for the Propagator to work correctly if (child==Formula.TRUE) return Formula.FALSE; else if (child==Formula.FALSE) return Formula.TRUE; else if (child.getClass()==NotFormula.class) return ((NotFormula)child).formula(); else return null; }
Example #25
Source File: FullNegationPropagator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
private Formula not(Formula f) { return f instanceof NotFormula ? ((NotFormula) f).formula() : f.not(); }
Example #26
Source File: PrettyPrinter.java From kodkod with MIT License | 4 votes |
/** @return true if the given formula should be parenthesized when a * child of a compound parent */ private boolean parenthesize(Formula child) { return !(child instanceof NotFormula || child instanceof ConstantFormula || child instanceof RelationPredicate); }
Example #27
Source File: Simplifier.java From quetzal with Eclipse Public License 2.0 | 4 votes |
/** @return true if left is a NotFormula with right as its child or vice versa */ final boolean areInverses(Formula left, Formula right) { return ((left.getClass() == NotFormula.class) && ((NotFormula)left).formula()==right) || ((right.getClass() == NotFormula.class) && ((NotFormula)right).formula()==left); }
Example #28
Source File: TrivialProof.java From kodkod with MIT License | 4 votes |
/** * If the argument node has been been visited, adds it to this.relevant and visits its child. */ public void visit(NotFormula not) { if (visited(not)) return; relevant.add(not); not.formula().accept(this); }
Example #29
Source File: HOLTranslator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
private void assertNNF(NotFormula not) { Formula f = not.formula(); if (f instanceof BinaryFormula || f instanceof NaryFormula || f instanceof QuantifiedFormula) throw new IllegalStateException("Expected formula to be in NNF; got: " + not); }
Example #30
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 4 votes |
/** @return true if the given formula should be parenthesized when a * child of a compound parent */ private boolean parenthesize(Formula child) { return !(child instanceof NotFormula || child instanceof ConstantFormula || child instanceof RelationPredicate); }