@Override public boolean containsAtLeast(final int n) { if (!_finite || n <= 0) return true; Number sum = 0; for (final IntegerInterval i : _intIntervals) { sum = OWLRealUtils.integerSum(sum, i.size()); if (OWLRealUtils.compare(n, sum) <= 0) return true; } for (final ContinuousRealInterval i : _decimalIntervals) if (!OWLRealUtils.isInteger(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(n, sum) <= 0) return true; } for (final ContinuousRealInterval i : _rationalIntervals) if (!OWLRealUtils.isInteger(i.getLower()) && !OWLRealUtils.isRational(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(n, sum) <= 0) return true; } return false; }
public static Number sum(final Number a, final Number b) { if (isInteger(a) && isInteger(b)) return integerSum(a, b); final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerSum method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (EnumSet.of(ta, tb).contains(Type.RATIONAL)) { final String msg = format("Addition for rational numbers is not supported"); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigDecimal da = (BigDecimal) convertFromTo(a, ta, Type.BIG_DECIMAL); final BigDecimal db = (BigDecimal) convertFromTo(b, tb, Type.BIG_DECIMAL); return getCanonicalObject(da.add(db)); }
@Override protected boolean valid(final Number n) { if (n == null) return true; return OWLRealUtils.acceptable(n.getClass()) && OWLRealUtils.isInteger(n); }
@Override public Number next() { if (_next == null) throw new NoSuchElementException(); final Number n = _next; if (_last != null && OWLRealUtils.compare(_next, _last) == 0) _next = null; else _next = _increment ? OWLRealUtils.integerIncrement(_next) : OWLRealUtils.integerDecrement(_next); return n; }
public Number size() { if (!_finite) throw new IllegalStateException(); else if (_point) return 1; else return integerIncrement(integerDifference(_upper, _lower)); }
final int cmp = OWLRealUtils.compare(lower, upper); if (cmp > 0) if (isInteger(lower)) _lower = lower; else _lower = roundDown(lower); if (isInteger(lower)) _lower = integerIncrement(lower); else _lower = roundDown(lower); _inclusiveLower = true; if (isInteger(upper)) _upper = upper; else _upper = roundDown(upper); if (isInteger(upper)) _upper = integerDecrement(upper); else _upper = roundDown(upper); _inclusiveUpper = true; if (isInteger(lower)) _inclusiveLower = false; else
if (OWLRealUtils.isInteger(cl)) lower = OWLRealUtils.integerIncrement(cl); lower = OWLRealUtils.roundCeiling(cl); if (OWLRealUtils.isInteger(cu)) upper = OWLRealUtils.integerDecrement(cu); upper = OWLRealUtils.roundFloor(cu); if (lower != null && upper != null && OWLRealUtils.compare(lower, upper) > 0) return null; else
if (OWLRealUtils.acceptable(n.getClass())) if (OWLRealUtils.isInteger(n)) if (OWLRealUtils.isDecimal(n)) if (OWLRealUtils.isRational(n)) for (final ContinuousRealInterval i : _rationalIntervals) if (i.contains(n))
if (isInteger(n)) return shrinkBigInteger(bigInteger(n)); else if (Type.RATIONAL.equals(t)) return getCanonicalObject(r.getQuotient()); else return Rational.simplify(r);
@Override public boolean containsAtLeast(final int n) { if (n <= 0) return true; Number sum = _containsNaN ? 1 : 0; for (final FloatingPointInterval<T> i : _intervals) { sum = OWLRealUtils.integerSum(sum, i.size()); if (OWLRealUtils.compare(sum, n) >= 0) return true; } return false; }
public AbstractDerivedIntegerType(final ATermAppl name, final Number lower, final Number upper) { super(name); if (lower != null && !OWLRealUtils.isInteger(lower)) throw new IllegalArgumentException(); if (upper != null && !OWLRealUtils.isInteger(upper)) throw new IllegalArgumentException(); if (lower != null && upper != null && OWLRealUtils.compare(lower, upper) > 0) throw new IllegalArgumentException(); final IntegerInterval i = new IntegerInterval(lower == null ? null : OWLRealUtils.getCanonicalObject(lower), upper == null ? null : OWLRealUtils.getCanonicalObject(upper)); _dataRange = new RestrictedRealDatatype(this, i, null, null); }
public static Number integerDifference(final Number a, final Number b) { final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerDifference method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigInteger ia = bigInteger(a); final BigInteger ib = bigInteger(b); return shrinkBigInteger(ia.subtract(ib)); }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); return OWLRealUtils.getCanonicalObject(fromLexicalForm(lexicalForm)); }
if (as == bs) if (OWLRealUtils.compare(a.getDenominator(), b.getDenominator()) == 0) return OWLRealUtils.compare(a.getNumerator(), b.getNumerator()); else final int qCmp = OWLRealUtils.compare(qa, qb); if (qCmp == 0) final BigInteger aprod = OWLRealUtils.bigInteger(a.getNumerator()).multiply(OWLRealUtils.bigInteger(b.getDenominator())); final BigInteger bprod = OWLRealUtils.bigInteger(b.getNumerator()).multiply(OWLRealUtils.bigInteger(a.getDenominator())); return aprod.compareTo(bprod);
if (!OWLRealUtils.isInteger(numerator)) throw new IllegalArgumentException(); if (OWLRealUtils.signum(denominator) <= 0) throw new IllegalArgumentException(); if (!OWLRealUtils.isInteger(denominator)) throw new IllegalArgumentException(); _denominator = denominator; final BigDecimal n = OWLRealUtils.bigDecimal(numerator); final BigDecimal d = OWLRealUtils.bigDecimal(denominator);
@Override protected boolean equal(final Number a, final Number b) { if (a == null) throw new NullPointerException(); if (b == null) throw new NullPointerException(); return OWLRealUtils.compare(a, b) == 0; }
public boolean contains(final Number n) { if (_type.equals(LineType.INTEGER_ONLY)) { if (!isInteger(n)) return false; } else if (_type.equals(LineType.INTEGER_EXCLUDED)) if (isInteger(n)) return false; int comp; if (boundLower()) { comp = OWLRealUtils.compare(getLower(), n); if (comp > 0) return false; if (comp == 0 && !inclusiveLower()) return false; } if (boundUpper()) { comp = OWLRealUtils.compare(getUpper(), n); if (comp < 0) return false; if (comp == 0 && !inclusiveUpper()) return false; } return true; }
public static Rational valueOf(final String s) throws NumberFormatException { if (s == null) throw new NullPointerException(); final Matcher m = _lexicalPattern.matcher(s); if (!m.matches()) throw new NumberFormatException(s); final String sLex = m.group(1); final String nLex = m.group(2); final String dLex = m.group(3); final Number n = OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(sLex == null ? nLex : sLex + nLex)); final Number d = OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(dLex)); if (OWLRealUtils.signum(d) != 1) throw new NumberFormatException(s); return new Rational(n, d); }
public static Rational simplify(final Rational r) { BigInteger n = OWLRealUtils.bigInteger(r.getNumerator()); BigInteger d = OWLRealUtils.bigInteger(r.getDenominator()); BigInteger gcd = n.gcd(d); while (!gcd.equals(BigInteger.ONE)) { n = n.divide(gcd); d = d.divide(gcd); gcd = n.gcd(d); } final Number canonicalNum = OWLRealUtils.getCanonicalObject(n); final Number canonicalDenom = OWLRealUtils.getCanonicalObject(d); if (canonicalNum.equals(r.getNumerator()) && canonicalDenom.equals(r.getDenominator())) return r; else return new Rational(canonicalNum, canonicalDenom); }