public BDD varRange(BigInteger lo, BigInteger hi) { if (lo.signum() < 0 || hi.compareTo(size()) >= 0 || lo.compareTo(hi) > 0) { throw new BDDException("range <"+lo+", "+hi+"> is invalid"); }  BDDFactory factory = getFactory(); BDD result = factory.zero(); int[] ivar = this.vars(); while (lo.compareTo(hi) <= 0) { BDD v = factory.one(); for (int n = ivar.length - 1; ; n--) { if (lo.testBit(n)) { v.andWith(factory.ithVar(ivar[n])); } else { v.andWith(factory.nithVar(ivar[n])); } BigInteger mask = BigInteger.ONE.shiftLeft(n).subtract(BigInteger.ONE); if (!lo.testBit(n) && lo.or(mask).compareTo(hi) <= 0) { lo = lo.or(mask).add(BigInteger.ONE); break; } } result.orWith(v); } return result;
public BDD varRange(long lo, long hi) { return varRange(BigInteger.valueOf(lo), BigInteger.valueOf(hi));
    public BDD varRange(BigInteger lo, BigInteger hi) {        if (lo.signum() < 0 || hi.compareTo(size()) >= 0 || lo.compareTo(hi) > 0) {            throw new BDDException("range <"+lo+", "+hi+"> is invalid");        }        BDDFactory factory = getFactory();        BDD result = factory.zero();        int[] ivar = this.vars();        while (lo.compareTo(hi) <= 0) {            BDD v = factory.one();            for (int n = ivar.length - 1; ; n--) {                if (lo.testBit(n)) {                    v.andWith(factory.ithVar(ivar[n]));                } else {                    v.andWith(factory.nithVar(ivar[n]));                }                BigInteger mask = BigInteger.ONE.shiftLeft(n).subtract(BigInteger.ONE);                if (!lo.testBit(n) && lo.or(mask).compareTo(hi) <= 0) {                    lo = lo.or(mask).add(BigInteger.ONE);                    break;                }            }            result.orWith(v);        }        return result;    }