Java Code Examples for kodkod.ast.IntExpression#plus()

The following examples show how to use kodkod.ast.IntExpression#plus() . 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: FloatingPoint.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static IntExpression intToFloat(IntExpression intValue) {
	IntExpression abs = intValue.abs();
	IntExpression maxSetBit = maxSetBit(abs);
	Formula shiftRight = maxSetBit.gt(IntConstant.constant(mantissaBits));
	
	IntExpression re = maxSetBit.minus(IntConstant.constant(mantissaBits));
	IntExpression adjustRight = adjustRight(abs, re);
	
	IntExpression le = IntConstant.constant(mantissaBits).minus(maxSetBit);
	IntExpression adjustLeft = abs.shl(le);

	IntExpression mantissa = 
		shiftRight.thenElse(adjustRight, adjustLeft).xor(implicitOne);
		
	IntExpression exponent = maxSetBit.plus(IntConstant.constant(exponentBias));
				
	IntExpression sign = intValue.lt(IntConstant.constant(0))
			.thenElse(IntConstant.constant(1<<(exponentBits+mantissaBits)), zero);

	return intValue.eq(zero)
		.thenElse(zero,
			sign.or(exponent.shl(IntConstant.constant(mantissaBits))).or(mantissa));
}
 
Example 2
Source File: FloatingPoint.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static IntExpression floatMultiply(IntExpression l, IntExpression r) {
	IntExpression le = exponent(l);
	IntExpression re = exponent(r);
	IntExpression e = le.plus(re);
	
	IntExpression lv = mantissa(l);
	IntExpression rv = mantissa(r);
	Pair<IntExpression,IntExpression> p = fullUnsignedIntegerMultiply(lv, rv);
	IntExpression shift = IntConstant.constant(23).minus(maxSetBit(p.snd));
	IntExpression m = adjustRight(p.fst, IntConstant.constant(32).minus(shift)).or(p.snd.shl(shift));
	e = e.plus(IntConstant.constant(9).minus(shift));
	
	// hide implicit one
	m = m.and(IntConstant.constant(mantissaMask));
	
	IntExpression s = sign(l).eq(sign(r)).thenElse(zero, one);
	
	return l.eq(zero).or(r.eq(zero)).thenElse(zero, s.shl(IntConstant.constant(exponentBits+mantissaBits))
		.or(e.plus(IntConstant.constant(exponentBias)).shl(IntConstant.constant(mantissaBits)))
		.or(m));
}
 
Example 3
Source File: Viktor.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the sum of the elements in x (conditional on the non-emptiness of a
 * given a[i]) located at indices [lo..hi]
 *
 * @return the sum of cardinalities of the elements in x (conditional on the
 *         non-emptiness of a given a[i]) located at indices [lo..hi]
 */
private static IntExpression conditionalSum(Expression[] a, Expression[] x, int lo, int hi) {
    if (lo > hi)
        return IntConstant.constant(0);
    else if (lo == hi)
        return a[lo].some().thenElse(x[lo].sum(), IntConstant.constant(0));
    else {
        final int mid = (lo + hi) / 2;
        final IntExpression lsum = conditionalSum(a, x, lo, mid);
        final IntExpression hsum = conditionalSum(a, x, mid + 1, hi);
        return lsum.plus(hsum);
    }
}
 
Example 4
Source File: Viktor.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the sum of the elements in x (conditional on the non-emptiness of a 
 * given a[i]) located at indices [lo..hi]
 * @return the sum of cardinalities of the elements in x (conditional on the non-emptiness of a 
 * given a[i]) located at indices [lo..hi]
 */
private static IntExpression conditionalSum(Expression[] a, Expression[] x, int lo, int hi) {
	if (lo>hi)
		return IntConstant.constant(0);
	else if (lo==hi) 
		return a[lo].some().thenElse(x[lo].sum(), IntConstant.constant(0));
	else {
		final int mid = (lo + hi) / 2;
		final IntExpression lsum = conditionalSum(a, x, lo, mid);
		final IntExpression hsum = conditionalSum(a, x, mid+1, hi);
		return lsum.plus(hsum);
	}
}
 
Example 5
Source File: ExpressionUtil.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
public static IntExpression plus(IntExpression l, IntExpression r) {
	return l.plus(r);
}