Package kodkod.ast

Examples of kodkod.ast.Decls


   * @requires this.skolemDepth < 0
   * @return { d: Decls | d.size = decls.size &&
   *                      all i: [0..d.size) | d.declarations[i] = decls.declarations[i].accept(this) }
   */
  public final  Decls visit(Decls decls) {
    Decls ret = lookup(decls);
    if (ret==null) {
      Decls visitedDecls = null;
      boolean allSame = true;
      for(Decl decl : decls) {
        Decls newDecl = visit(decl);
        if (newDecl != decl)
          allSame = false;
        visitedDecls = (visitedDecls==null) ? newDecl : visitedDecls.and(newDecl);
        repEnv = repEnv.extend(decl.variable(), decl.variable());
      }
View Full Code Here


  @Override
  public final Expression visit(Comprehension expr) {
    Expression ret = lookup(expr);
    if (ret!=null) return ret;
    final Environment<Expression> oldRepEnv = repEnv; // skolemDepth < 0 at this point
    final Decls decls = visit((Decls)expr.decls());
    final Formula formula = expr.formula().accept(this);
    ret = (decls==expr.decls() && formula==expr.formula()) ? expr : formula.comprehension(decls);
    repEnv = oldRepEnv;   
    return cache(expr,ret);
  }
View Full Code Here

  @Override
  public final IntExpression visit(SumExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret!=null) return ret; 
    final Environment<Expression> oldRepEnv = repEnv; // skolemDepth < 0 at this point
    final Decls decls  = visit((Decls)intExpr.decls());
    final IntExpression expr = intExpr.intExpr().accept(this);
    ret =  (decls==intExpr.decls() && expr==intExpr.intExpr()) ? intExpr : expr.sum(decls);
    repEnv = oldRepEnv;
    return cache(intExpr,ret);
  }
View Full Code Here

   * @requires !nonSkolems.isEmpty()
   * @return a formula that properly constrains the given skolem's domain.
   */
  private Formula domainConstraint(Decl skolemDecl, Relation skolem) {
    final Iterator<DeclInfo> itr = nonSkolems.iterator();
    Decls rangeDecls = itr.next().decl;
    while(itr.hasNext()) {
      rangeDecls = rangeDecls.and(itr.next().decl);
    }
//    System.out.println(skolemDecl.expression());
    Expression skolemDomain = skolem;
    for(int i = 0, max = skolemDecl.variable().arity(); i < max; i++) {
      skolemDomain = skolemDomain.join(Expression.UNIV);
View Full Code Here

    Formula ret = lookup(qf);
    if (ret!=null) return ret;
   
    final Environment<Expression> oldRepEnv = repEnv; 
    final Quantifier quant = qf.quantifier();
    final Decls decls = qf.decls();
   
    if (skolemDepth>=0 && (negated && quant==ALL || !negated && quant==SOME)) { // skolemizable formula
      final List<Formula> rangeConstraints = new LinkedList<Formula>();
      final List<Formula> domConstraints = new LinkedList<Formula>();
     
      for(Decl decl : decls) { 
        final Decl skolemDecl = visit(decl);
       
        final Relation skolem = Relation.nary("$"+ skolemDecl.variable().name(), nonSkolems.size() + skolemDecl.variable().arity());
        reporter.skolemizing(decl, skolem, nonSkolemsView);
       
        final Expression skolemExpr = skolemExpr(skolemDecl, skolem);
       
        final Multiplicity mult = decl.multiplicity();
        rangeConstraints.add(source(skolemExpr.in(skolemDecl.expression()), decl));
        if (mult!=Multiplicity.SET) {
          rangeConstraints.add(source(skolemExpr.apply(mult), decl));
        }

        if (!nonSkolems.isEmpty())
          domConstraints.add(source(domainConstraint(skolemDecl, skolem), decl));
       
        repEnv = repEnv.extend(decl.variable(), skolemExpr);
      }
   
      ret = source(Formula.and(rangeConstraints), decls).compose(negated ? IMPLIES : AND, qf.formula().accept(this));
     
      if (!domConstraints.isEmpty())
        topSkolemConstraints.add(source(Formula.and(domConstraints), decls));
     
    } else { // non-skolemizable formula
   
      final Decls newDecls = visit((Decls)qf.decls());
      if (skolemDepth>=nonSkolems.size()+newDecls.size()) { // could skolemize below
        for(Decl d: newDecls) { nonSkolems.add(new DeclInfo(d)); }
        final Formula formula = qf.formula().accept(this);
        ret = ((newDecls==decls && formula==qf.formula()) ? qf : formula.quantify(quant, newDecls));
        for(int i = newDecls.size(); i > 0; i--) { nonSkolems.remove(nonSkolems.size()-1); }
      } else { // can't skolemize below
        final int oldDepth = skolemDepth;
        skolemDepth = -1;
        final Formula formula = qf.formula().accept(this);
        ret = ((newDecls==decls && formula==qf.formula()) ? qf : formula.quantify(quant, newDecls));
View Full Code Here

      if ((!negated && quant==ALL) || (negated && quant==SOME)) { // may break down further
        final Map<Formula, Node> oldConjuncts = conjuncts;
        conjuncts = new LinkedHashMap<Formula, Node>();
        qf.formula().accept(this);
        if (conjuncts.size()>1) { // was broken down further
          final Decls decls = qf.decls();
          for(Map.Entry<Formula, Node> entry : conjuncts.entrySet()) {
            oldConjuncts.put(entry.getKey().forAll(decls), entry.getValue());
          }
          conjuncts = oldConjuncts;
          return;
View Full Code Here

    private Formula size(Sig sig, int n, boolean exact) {
        Expression a = sol.a2k(sig);
        if (n<=0) return a.no();
        if (n==1) return exact ? a.one() : a.lone();
        Formula f = exact ? Formula.TRUE : null;
        Decls d = null;
        Expression sum = null;
        while(n>0) {
           n--;
           Variable v = Variable.unary("");
           kodkod.ast.Decl dd = v.oneOf(a);
View Full Code Here

   * returned, otherwise a replacement Decls object is cached and returned.
   * @return { d: Decls | d.size = decls.size &&
   *                      all i: [0..d.size) | d.declarations[i] = decls.declarations[i].accept(this) }
   */
  public Decls visit(Decls decls) {
    Decls ret = lookup(decls);
    if (ret!=null) return ret;
   
    Decls visitedDecls = null;
    boolean allSame = true;
    for(Decl decl : decls) {
      Decls newDecl = visit(decl);
      if (newDecl != decl)
        allSame = false;
      visitedDecls = (visitedDecls==null) ? newDecl : visitedDecls.and(newDecl);
    }
    ret = allSame ? decls : visitedDecls;
View Full Code Here

   */
  public Expression visit(Comprehension comprehension) {
    Expression ret = lookup(comprehension);
    if (ret!=null) return ret;
   
    final Decls decls = (Decls)comprehension.decls().accept(this);
    final Formula formula = comprehension.formula().accept(this);
    ret = (decls==comprehension.decls() && formula==comprehension.formula()) ?
        comprehension : formula.comprehension(decls);
    return cache(comprehension,ret);
  }
View Full Code Here

   */
    public IntExpression visit(SumExpression intExpr) {
    IntExpression ret = lookup(intExpr);
    if (ret!=null) return ret;
 
    final Decls decls  = intExpr.decls().accept(this);
    final IntExpression expr = intExpr.intExpr().accept(this);
    ret =  (decls==intExpr.decls() && expr==intExpr.intExpr()) ?
        intExpr : expr.sum(decls);
    return cache(intExpr,ret);
    }
View Full Code Here

TOP

Related Classes of kodkod.ast.Decls

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.