diff --git a/src/api/dotnet/Context.cs b/src/api/dotnet/Context.cs index 69855fc4f..986efc94d 100644 --- a/src/api/dotnet/Context.cs +++ b/src/api/dotnet/Context.cs @@ -3439,65 +3439,118 @@ namespace Microsoft.Z3 #endregion #region Floating-Point Arithmetic + + #region Rounding Modes + #region RoundingMode Sort /// - /// Create a floating point rounding mode sort. + /// Create the floating-point RoundingMode sort. /// - public FPRMSort MkFPRMSort() + public FPRMSort MkFPRoundingModeSort() { Contract.Ensures(Contract.Result() != null); return new FPRMSort(this); } - + #endregion + + #region Numerals /// - /// Create a NearestTiesToEven rounding mode numeral. + /// Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. /// - public FPRMNum MkFPRMNearestTiesToEven() + public FPRMNum MkFPRoundNearestTiesToEven() { Contract.Ensures(Contract.Result() != null); return new FPRMNum(this, Native.Z3_mk_fpa_round_nearest_ties_to_even(nCtx)); } /// - /// Create a NearestTiesToAway rounding mode numeral. + /// Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. /// - public FPRMNum MkFPRMNearestTiesToAway() + public FPRMNum MkFPRNE() + { + Contract.Ensures(Contract.Result() != null); + return new FPRMNum(this, Native.Z3_mk_fpa_rne(nCtx)); + } + + /// + /// Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. + /// + public FPRMNum MkFPRoundNearestTiesToAway() { Contract.Ensures(Contract.Result() != null); return new FPRMNum(this, Native.Z3_mk_fpa_round_nearest_ties_to_away(nCtx)); } /// - /// Create a TowardPositive rounding mode numeral. + /// Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. /// - public FPRMNum MkFPRMTowardPositive() + public FPRMNum MkFPRNA() + { + Contract.Ensures(Contract.Result() != null); + return new FPRMNum(this, Native.Z3_mk_fpa_rna(nCtx)); + } + + /// + /// Create a numeral of RoundingMode sort which represents the RoundTowardPositive rounding mode. + /// + public FPRMNum MkFPRoundTowardPositive() { Contract.Ensures(Contract.Result() != null); return new FPRMNum(this, Native.Z3_mk_fpa_round_toward_positive(nCtx)); } /// - /// Create a TowardNegative rounding mode numeral. + /// Create a numeral of RoundingMode sort which represents the RoundTowardPositive rounding mode. /// - public FPRMNum MkFPRMTowardNegative() + public FPRMNum MkFPRTP() + { + Contract.Ensures(Contract.Result() != null); + return new FPRMNum(this, Native.Z3_mk_fpa_rtp(nCtx)); + } + + /// + /// Create a numeral of RoundingMode sort which represents the RoundTowardNegative rounding mode. + /// + public FPRMNum MkFPRoundTowardNegative() { Contract.Ensures(Contract.Result() != null); return new FPRMNum(this, Native.Z3_mk_fpa_round_toward_negative(nCtx)); } /// - /// Create a TowardZero rounding mode numeral. + /// Create a numeral of RoundingMode sort which represents the RoundTowardNegative rounding mode. /// - public FPRMNum MkFPRMTowardZero() + public FPRMNum MkFPRTN() + { + Contract.Ensures(Contract.Result() != null); + return new FPRMNum(this, Native.Z3_mk_fpa_rtn(nCtx)); + } + + /// + /// Create a numeral of RoundingMode sort which represents the RoundTowardZero rounding mode. + /// + public FPRMNum MkFPRoundTowardZero() { Contract.Ensures(Contract.Result() != null); return new FPRMNum(this, Native.Z3_mk_fpa_round_toward_zero(nCtx)); } /// - /// Create a floating point sort. + /// Create a numeral of RoundingMode sort which represents the RoundTowardZero rounding mode. /// - /// exponent bits in the floating point sort. - /// significand bits in the floating point sort. + public FPRMNum MkFPRTZ() + { + Contract.Ensures(Contract.Result() != null); + return new FPRMNum(this, Native.Z3_mk_fpa_rtz(nCtx)); + } + #endregion + #endregion + + #region FloatingPoint Sorts + /// + /// Create a FloatingPoint sort. + /// + /// exponent bits in the FloatingPoint sort. + /// significand bits in the FloatingPoint sort. public FPSort MkFPSort(uint ebits, uint sbits) { Contract.Ensures(Contract.Result() != null); @@ -3505,9 +3558,83 @@ namespace Microsoft.Z3 } /// - /// Create a floating point NaN numeral. + /// Create the half-precision (16-bit) FloatingPoint sort. + /// + public FPSort MkFPSortHalf() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_half(nCtx)); + } + + /// + /// Create the half-precision (16-bit) FloatingPoint sort. + /// + public FPSort MkFPSort16() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_16(nCtx)); + } + + /// + /// Create the single-precision (32-bit) FloatingPoint sort. + /// + public FPSort MkFPSortSingle() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_single(nCtx)); + } + + /// + /// Create the single-precision (32-bit) FloatingPoint sort. + /// + public FPSort MkFPSort32() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_16(nCtx)); + } + + /// + /// Create the double-precision (64-bit) FloatingPoint sort. + /// + public FPSort MkFPSortDouble() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_double(nCtx)); + } + + /// + /// Create the double-precision (64-bit) FloatingPoint sort. + /// + public FPSort MkFPSort64() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_64(nCtx)); + } + + /// + /// Create the quadruple-precision (128-bit) FloatingPoint sort. + /// + public FPSort MkFPSortQuadruple() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_double(nCtx)); + } + + /// + /// Create the quadruple-precision (128-bit) FloatingPoint sort. + /// + public FPSort MkFPSort128() + { + Contract.Ensures(Contract.Result() != null); + return new FPSort(this, Native.Z3_mk_fpa_sort_128(nCtx)); + } + #endregion + + #region Numerals + /// + /// Create a NaN of sort s. /// - /// floating point sort. + /// FloatingPoint sort. public FPNum MkFPNaN(FPSort s) { Contract.Ensures(Contract.Result() != null); @@ -3515,9 +3642,9 @@ namespace Microsoft.Z3 } /// - /// Create a floating point Inf numeral. + /// Create a floating-point infinity of sort s. /// - /// floating point sort. + /// FloatingPoint sort. /// indicates whether the result should be negative. public FPNum MkFPInf(FPSort s, bool negative) { @@ -3526,20 +3653,141 @@ namespace Microsoft.Z3 } /// - /// Create a floating point numeral. - /// - /// A string representing the value in decimal notation. - /// floating point sort + /// Create a floating-point zero of sort s. + /// + /// FloatingPoint sort. + /// indicates whether the result should be negative. + public FPNum MkFPZero(FPSort s, bool negative) + { + Contract.Ensures(Contract.Result() != null); + return new FPNum(this, Native.Z3_mk_fpa_zero(nCtx, s.NativeObject, negative ? 1 : 0)); + } + + /// + /// Create a numeral of FloatingPoint sort from a float. + /// + /// numeral value. + /// FloatingPoint sort. + public FPNum MkFPNumeral(float v, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPNum(this, Native.Z3_mk_fpa_numeral_float(nCtx, v, s.NativeObject)); + } + + /// + /// Create a numeral of FloatingPoint sort from a float. + /// + /// numeral value. + /// FloatingPoint sort. + public FPNum MkFPNumeral(double v, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPNum(this, Native.Z3_mk_fpa_numeral_double(nCtx, v, s.NativeObject)); + } + + /// + /// Create a numeral of FloatingPoint sort from an int. + /// + /// numeral value. + /// FloatingPoint sort. + public FPNum MkFPNumeral(int v, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPNum(this, Native.Z3_mk_fpa_numeral_int(nCtx, v, s.NativeObject)); + } + + /// + /// Create a numeral of FloatingPoint sort from a sign bit and two integers. + /// + /// the sign. + /// the significand. + /// the exponent. + /// FloatingPoint sort. + public FPNum MkFPNumeral(bool sgn, uint sig, int exp, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPNum(this, Native.Z3_mk_fpa_numeral_uint_int(nCtx, sgn ? 1 : 0, sig, exp, s.NativeObject)); + } + + /// + /// Create a numeral of FloatingPoint sort from a sign bit and two 64-bit integers. + /// + /// the sign. + /// the significand. + /// the exponent. + /// FloatingPoint sort. + public FPNum MkFPNumeral(bool sgn, UInt64 sig, Int64 exp, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPNum(this, Native.Z3_mk_fpa_numeral_uint64_int64(nCtx, sgn ? 1 : 0, sig, exp, s.NativeObject)); + } + + /// + /// Create a numeral of FloatingPoint sort from a float. + /// + /// numeral value. + /// FloatingPoint sort. + public FPNum MkFP(float v, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return MkFPNumeral(v, s); + } + + /// + /// Create a numeral of FloatingPoint sort from a float. + /// + /// numeral value. + /// FloatingPoint sort. public FPNum MkFP(double v, FPSort s) { - Contract.Ensures(Contract.Result() != null); - return new FPNum(this, Native.Z3_mk_fpa_numeral_double(this.nCtx, v, s.NativeObject)); - } + Contract.Ensures(Contract.Result() != null); + return MkFPNumeral(v, s); + } + /// + /// Create a numeral of FloatingPoint sort from an int. + /// + /// numeral value. + /// FloatingPoint sort. + public FPNum MkFP(int v, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return MkFPNumeral(v, s); + } + + /// + /// Create a numeral of FloatingPoint sort from a sign bit and two integers. + /// + /// the sign. + /// the significand. + /// the exponent. + /// FloatingPoint sort. + public FPNum MkFP(bool sgn, uint sig, int exp, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return MkFPNumeral(sgn, sig, exp, s); + } + + /// + /// Create a numeral of FloatingPoint sort from a sign bit and two 64-bit integers. + /// + /// the sign. + /// the significand. + /// the exponent. + /// FloatingPoint sort. + public FPNum MkFP(bool sgn, UInt64 sig, Int64 exp, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return MkFPNumeral(sgn, sig, exp, s); + } + + #endregion + + #region Operators /// /// Floating-point absolute value /// - /// floating point term + /// floating-point term public FPExpr MkFPAbs(FPExpr t) { Contract.Ensures(Contract.Result() != null); @@ -3549,7 +3797,7 @@ namespace Microsoft.Z3 /// /// Floating-point negation /// - /// floating point term + /// floating-point term public FPExpr MkFPNeg(FPExpr t) { Contract.Ensures(Contract.Result() != null); @@ -3560,8 +3808,8 @@ namespace Microsoft.Z3 /// Floating-point addition /// /// rounding mode term - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public FPExpr MkFPAdd(FPRMExpr rm, FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3572,8 +3820,8 @@ namespace Microsoft.Z3 /// Floating-point subtraction /// /// rounding mode term - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public FPExpr MkFPSub(FPRMExpr rm, FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3584,8 +3832,8 @@ namespace Microsoft.Z3 /// Floating-point multiplication /// /// rounding mode term - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public FPExpr MkFPMul(FPRMExpr rm, FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3596,8 +3844,8 @@ namespace Microsoft.Z3 /// Floating-point division /// /// rounding mode term - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public FPExpr MkFPDiv(FPRMExpr rm, FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3611,9 +3859,9 @@ namespace Microsoft.Z3 /// The result is round((t1 * t2) + t3) /// /// rounding mode term - /// floating point term - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term + /// floating-point term public FPExpr MkFPFMA(FPRMExpr rm, FPExpr t1, FPExpr t2, FPExpr t3) { Contract.Ensures(Contract.Result() != null); @@ -3624,7 +3872,7 @@ namespace Microsoft.Z3 /// Floating-point square root /// /// rounding mode term - /// floating point term + /// floating-point term public FPExpr MkFPSqrt(FPRMExpr rm, FPExpr t) { Contract.Ensures(Contract.Result() != null); @@ -3634,33 +3882,53 @@ namespace Microsoft.Z3 /// /// Floating-point remainder /// - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public FPExpr MkFPRem(FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); return new FPExpr(this, Native.Z3_mk_fpa_rem(this.nCtx, t1.NativeObject, t2.NativeObject)); } - + /// - /// Floating-point equality - /// - /// - /// Note that this is IEEE 754 equality (as opposed to standard =). - /// - /// floating point term - /// floating point term - public BoolExpr MkFPEq(FPExpr t1, FPExpr t2) - { - Contract.Ensures(Contract.Result() != null); - return new BoolExpr(this, Native.Z3_mk_fpa_eq(this.nCtx, t1.NativeObject, t2.NativeObject)); - } - - /// - /// Floating-point less than or equal + /// Floating-point roundToIntegral. Rounds a floating-point number to + /// the closest integer, again represented as a floating-point number. /// - /// floating point term - /// floating point term + /// term of RoundingMode sort + /// floating-point term + public FPExpr MkFPRoundToIntegral(FPRMExpr rm, FPExpr t) + { + Contract.Ensures(Contract.Result() != null); + return new FPExpr(this, Native.Z3_mk_fpa_round_to_integral(this.nCtx, rm.NativeObject, t.NativeObject)); + } + + /// + /// Minimum of floating-point numbers. + /// + /// floating-point term + /// floating-point term + public FPExpr MkFPMin(FPExpr t1, FPExpr t2) + { + Contract.Ensures(Contract.Result() != null); + return new FPExpr(this, Native.Z3_mk_fpa_min(this.nCtx, t1.NativeObject, t2.NativeObject)); + } + + /// + /// Maximum of floating-point numbers. + /// + /// floating-point term + /// floating-point term + public FPExpr MkFPMax(FPExpr t1, FPExpr t2) + { + Contract.Ensures(Contract.Result() != null); + return new FPExpr(this, Native.Z3_mk_fpa_max(this.nCtx, t1.NativeObject, t2.NativeObject)); + } + + /// + /// Floating-point less than or equal. + /// + /// floating-point term + /// floating-point term public BoolExpr MkFPLEq(FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3668,10 +3936,10 @@ namespace Microsoft.Z3 } /// - /// Floating-point less than + /// Floating-point less than. /// - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public BoolExpr MkFPLt(FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3679,10 +3947,10 @@ namespace Microsoft.Z3 } /// - /// Floating-point greater than or equal + /// Floating-point greater than or equal. /// - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public BoolExpr MkFPGEq(FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3690,10 +3958,10 @@ namespace Microsoft.Z3 } /// - /// Floating-point greater than + /// Floating-point greater than. /// - /// floating point term - /// floating point term + /// floating-point term + /// floating-point term public BoolExpr MkFPGt(FPExpr t1, FPExpr t2) { Contract.Ensures(Contract.Result() != null); @@ -3701,9 +3969,23 @@ namespace Microsoft.Z3 } /// - /// Predicate indicating whether t is a normal floating point number + /// Floating-point equality. + /// + /// + /// Note that this is IEEE 754 equality (as opposed to standard =). + /// + /// floating-point term + /// floating-point term + public BoolExpr MkFPEq(FPExpr t1, FPExpr t2) + { + Contract.Ensures(Contract.Result() != null); + return new BoolExpr(this, Native.Z3_mk_fpa_eq(this.nCtx, t1.NativeObject, t2.NativeObject)); + } + + /// + /// Predicate indicating whether t is a normal floating-point number. /// - /// floating point term + /// floating-point term public BoolExpr MkFPIsNormal(FPExpr t) { Contract.Ensures(Contract.Result() != null); @@ -3711,9 +3993,9 @@ namespace Microsoft.Z3 } /// - /// Predicate indicating whether t is a subnormal floating point number + /// Predicate indicating whether t is a subnormal floating-point number. /// - /// floating point term + /// floating-point term public BoolExpr MkFPIsSubnormal(FPExpr t) { Contract.Ensures(Contract.Result() != null); @@ -3721,29 +4003,29 @@ namespace Microsoft.Z3 } /// - /// Predicate indicating whether t is a floating point number with zero value, i.e., +0 or -0. + /// Predicate indicating whether t is a floating-point number with zero value, i.e., +0 or -0. /// - /// floating point term - public BoolExpr MkFPIsZero(FPExpr t) - { + /// floating-point term + public BoolExpr MkFPIsZero(FPExpr t) + { Contract.Ensures(Contract.Result() != null); return new BoolExpr(this, Native.Z3_mk_fpa_is_zero(this.nCtx, t.NativeObject)); } /// - /// Predicate indicating whether t is a floating point number representing +Inf or -Inf + /// Predicate indicating whether t is a floating-point number representing +oo or -oo. /// - /// floating point term - public BoolExpr MkFPIsInf(FPExpr t) - { + /// floating-point term + public BoolExpr MkFPIsInfinite(FPExpr t) + { Contract.Ensures(Contract.Result() != null); return new BoolExpr(this, Native.Z3_mk_fpa_is_infinite(this.nCtx, t.NativeObject)); } /// - /// Predicate indicating whether t is a NaN + /// Predicate indicating whether t is a NaN. /// - /// floating point term + /// floating-point term public BoolExpr MkFPIsNaN(FPExpr t) { Contract.Ensures(Contract.Result() != null); @@ -3751,45 +4033,212 @@ namespace Microsoft.Z3 } /// - /// Floating-point minimum + /// Predicate indicating whether t is a negative floating-point number. /// - /// floating point term - /// floating point term - public FPExpr MkFPMin(FPExpr t1, FPExpr t2) + /// floating-point term + public BoolExpr MkFPIsNegative(FPExpr t) { - Contract.Ensures(Contract.Result() != null); - return new FPExpr(this, Native.Z3_mk_fpa_min(this.nCtx, t1.NativeObject, t2.NativeObject)); + Contract.Ensures(Contract.Result() != null); + return new BoolExpr(this, Native.Z3_mk_fpa_is_negative(this.nCtx, t.NativeObject)); } - - /// - /// Floating-point maximium - /// - /// floating point term - /// floating point term - public FPExpr MkFPMax(FPExpr t1, FPExpr t2) - { - Contract.Ensures(Contract.Result() != null); - return new FPExpr(this, Native.Z3_mk_fpa_max(this.nCtx, t1.NativeObject, t2.NativeObject)); - } /// - /// Conversion of a floating point number to another floating-point sort s. + /// Predicate indicating whether t is a positive floating-point number. + /// + /// floating-point term + public BoolExpr MkFPIsPositive(FPExpr t) + { + Contract.Ensures(Contract.Result() != null); + return new BoolExpr(this, Native.Z3_mk_fpa_is_positive(this.nCtx, t.NativeObject)); + } + #endregion + + #region Conversions to FloatingPoint terms + /// + /// Create an expression of FloatingPoint sort from three bit-vector expressions. + /// + /// + /// This is the operator named `fp' in the SMT FP theory definition. + /// Note that sgn is required to be a bit-vector of size 1. Significand and exponent + /// are required to be greater than 1 and 2 respectively. The FloatingPoint sort + /// of the resulting expression is automatically determined from the bit-vector sizes + /// of the arguments. + /// + /// bit-vector term (of size 1) representing the sign. + /// bit-vector term representing the significand. + /// bit-vector term representing the exponent. + public FPExpr MkFP(BitVecExpr sgn, BitVecExpr sig, BitVecExpr exp) + { + Contract.Ensures(Contract.Result() != null); + return new FPExpr(this, Native.Z3_mk_fpa_fp(this.nCtx, sgn.NativeObject, sig.NativeObject, exp.NativeObject)); + } + + /// + /// Conversion of a single IEEE 754-2008 bit-vector into a floating-point number. + /// + /// + /// Produces a term that represents the conversion of a bit-vector term bv to a + /// floating-point term of sort s. The bit-vector size of bv (m) must be equal + /// to ebits+sbits of s. The format of the bit-vector is as defined by the + /// IEEE 754-2008 interchange format. + /// + /// bit-vector value (of size m). + /// FloatingPoint sort (ebits+sbits == m) + public FPExpr MkFPToFP(BitVecExpr bv, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPExpr(this, Native.Z3_mk_fpa_to_fp_bv(this.nCtx, bv.NativeObject, s.NativeObject)); + } + + /// + /// Conversion of a FloatingPoint term into another term of different FloatingPoint sort. + /// + /// + /// Produces a term that represents the conversion of a floating-point term t to a + /// floating-point term of sort s. If necessary, the result will be rounded according + /// to rounding mode rm. + /// + /// RoundingMode term. + /// FloatingPoint term. + /// FloatingPoint sort. + public FPExpr MkFPToFP(FPRMExpr rm, FPExpr t, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPExpr(this, Native.Z3_mk_fpa_to_fp_float(this.nCtx, rm.NativeObject, t.NativeObject, s.NativeObject)); + } + + /// + /// Conversion of a term of real sort into a term of FloatingPoint sort. + /// + /// + /// Produces a term that represents the conversion of term t of real sort into a + /// floating-point term of sort s. If necessary, the result will be rounded according + /// to rounding mode rm. + /// + /// RoundingMode term. + /// term of Real sort. + /// FloatingPoint sort. + public FPExpr MkFPToFP(FPRMExpr rm, RealExpr t, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new FPExpr(this, Native.Z3_mk_fpa_to_fp_real(this.nCtx, rm.NativeObject, t.NativeObject, s.NativeObject)); + } + + /// + /// Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort. + /// + /// + /// Produces a term that represents the conversion of the bit-vector term t into a + /// floating-point term of sort s. The bit-vector t is taken to be in signed + /// 2's complement format (when signed==true, otherwise unsigned). If necessary, the + /// result will be rounded according to rounding mode rm. + /// + /// RoundingMode term. + /// term of bit-vector sort. + /// FloatingPoint sort. + /// flag indicating whether t is interpreted as signed or unsigned bit-vector. + public FPExpr MkFPToFP(FPRMExpr rm, BitVecExpr t, FPSort s, bool signed) + { + Contract.Ensures(Contract.Result() != null); + if (signed) + return new FPExpr(this, Native.Z3_mk_fpa_to_fp_signed(this.nCtx, rm.NativeObject, t.NativeObject, s.NativeObject)); + else + return new FPExpr(this, Native.Z3_mk_fpa_to_fp_unsigned(this.nCtx, rm.NativeObject, t.NativeObject, s.NativeObject)); + } + + /// + /// Conversion of a floating-point number to another FloatingPoint sort s. /// /// /// Produces a term that represents the conversion of a floating-point term t to a different - /// floating point sort s. If necessary, rounding according to rm is applied. + /// FloatingPoint sort s. If necessary, rounding according to rm is applied. /// - /// floating point sort - /// floating point rounding mode term - /// floating point term - public FPExpr MkFPToFP(FPSort s, FPRMExpr rm, FPExpr t) + /// FloatingPoint sort + /// floating-point rounding mode term + /// floating-point term + public FPExpr MkFPToFP(FPSort s, FPRMExpr rm, FPExpr t) { - Contract.Ensures(Contract.Result() != null); + Contract.Ensures(Contract.Result() != null); return new FPExpr(this, Native.Z3_mk_fpa_to_fp_float(this.nCtx, s.NativeObject, rm.NativeObject, t.NativeObject)); } #endregion + #region Conversions from FloatingPoint terms + /// + /// Conversion of a floating-point term into a bit-vector. + /// + /// + /// Produces a term that represents the conversion of the floating-poiunt term t into a + /// bit-vector term of size sz in 2's complement format (signed when signed==true). If necessary, + /// the result will be rounded according to rounding mode rm. + /// + /// RoundingMode term. + /// FloatingPoint term + /// Size of the resulting bit-vector. + /// Indicates whether the result is a signed or unsigned bit-vector. + public BitVecExpr MkFPToBV(FPRMExpr rm, FPExpr t, uint sz, bool signed) + { + Contract.Ensures(Contract.Result() != null); + if (signed) + return new BitVecExpr(this, Native.Z3_mk_fpa_to_sbv(this.nCtx, rm.NativeObject, t.NativeObject, sz)); + else + return new BitVecExpr(this, Native.Z3_mk_fpa_to_ubv(this.nCtx, rm.NativeObject, t.NativeObject, sz)); + } + + /// + /// Conversion of a floating-point term into a real-numbered term. + /// + /// + /// Produces a term that represents the conversion of the floating-poiunt term t into a + /// real number. Note that this type of conversion will often result in non-linear + /// constraints over real terms. + /// + /// FloatingPoint term + public RealExpr MkFPToReal(FPExpr t) + { + Contract.Ensures(Contract.Result() != null); + return new RealExpr(this, Native.Z3_mk_fpa_to_real(this.nCtx, t.NativeObject)); + } + #endregion + + #region Z3-specific extensions + /// + /// Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. + /// + /// + /// The size of the resulting bit-vector is automatically determined. Note that + /// IEEE 754-2008 allows multiple different representations of NaN. This conversion + /// knows only one NaN and it will always produce the same bit-vector represenatation of + /// that NaN. + /// + /// FloatingPoint term. + public BitVecExpr MkFPToIEEEBV(FPExpr t) + { + Contract.Ensures(Contract.Result() != null); + return new BitVecExpr(this, Native.Z3_mk_fpa_to_ieee_bv(this.nCtx, t.NativeObject)); + } + + /// + /// Conversion of a real-sorted significand and an integer-sorted exponent into a term of FloatingPoint sort. + /// + /// + /// Produces a term that represents the conversion of sig * 2^exp into a + /// floating-point term of sort s. If necessary, the result will be rounded + /// according to rounding mode rm. + /// + /// RoundingMode term. + /// Significand term of Real sort. + /// Exponent term of Int sort. + /// FloatingPoint sort. + public BitVecExpr MkFPToFP(FPRMExpr rm, RealExpr sig, IntExpr exp, FPSort s) + { + Contract.Ensures(Contract.Result() != null); + return new BitVecExpr(this, Native.Z3_mk_fpa_to_fp_real_int(this.nCtx, rm.NativeObject, sig.NativeObject, exp.NativeObject, s.NativeObject)); + } + #endregion + #endregion // Floating-point Arithmetic + #region Miscellaneous /// /// Wraps an AST. diff --git a/src/api/dotnet/FPExpr.cs b/src/api/dotnet/FPExpr.cs index 0bb1e4c09..cbba272d1 100644 --- a/src/api/dotnet/FPExpr.cs +++ b/src/api/dotnet/FPExpr.cs @@ -26,7 +26,7 @@ using System.Diagnostics.Contracts; namespace Microsoft.Z3 { /// - /// Floating Point Expressions + /// FloatingPoint Expressions /// public class FPExpr : Expr { diff --git a/src/api/dotnet/FPNum.cs b/src/api/dotnet/FPNum.cs index 044598e58..ab57d57c3 100644 --- a/src/api/dotnet/FPNum.cs +++ b/src/api/dotnet/FPNum.cs @@ -22,7 +22,7 @@ using System.Diagnostics.Contracts; namespace Microsoft.Z3 { /// - /// Floatiung Point Numerals + /// FloatiungPoint Numerals /// [ContractVerification(true)] public class FPNum : FPExpr diff --git a/src/api/dotnet/FPRMExpr.cs b/src/api/dotnet/FPRMExpr.cs index b95816023..92fea1ad4 100644 --- a/src/api/dotnet/FPRMExpr.cs +++ b/src/api/dotnet/FPRMExpr.cs @@ -26,7 +26,7 @@ using System.Diagnostics.Contracts; namespace Microsoft.Z3 { /// - /// Floating Point Expressions + /// FloatingPoint RoundingMode Expressions /// public class FPRMExpr : Expr { diff --git a/src/api/dotnet/FPRMNum.cs b/src/api/dotnet/FPRMNum.cs index eaf105718..7caa56f9f 100644 --- a/src/api/dotnet/FPRMNum.cs +++ b/src/api/dotnet/FPRMNum.cs @@ -22,7 +22,7 @@ using System.Diagnostics.Contracts; namespace Microsoft.Z3 { /// - /// Floatiung Point Rounding Mode Numerals + /// FloatingPoint RoundingMode Numerals /// [ContractVerification(true)] public class FPRMNum : FPRMExpr diff --git a/src/api/dotnet/FPRMSort.cs b/src/api/dotnet/FPRMSort.cs index 23d454a65..1d8334eb5 100644 --- a/src/api/dotnet/FPRMSort.cs +++ b/src/api/dotnet/FPRMSort.cs @@ -7,7 +7,7 @@ Module Name: Abstract: - Z3 Managed API: Floating Point Rounding Mode Sorts + Z3 Managed API: Rounding Mode Sort Author: @@ -23,7 +23,7 @@ using System.Diagnostics.Contracts; namespace Microsoft.Z3 { /// - /// A floating point rounding mode sort + /// The FloatingPoint RoundingMode sort /// public class FPRMSort : Sort { diff --git a/src/api/dotnet/FPSort.cs b/src/api/dotnet/FPSort.cs index a79557ae6..8d8560e53 100644 --- a/src/api/dotnet/FPSort.cs +++ b/src/api/dotnet/FPSort.cs @@ -16,17 +16,26 @@ Author: Notes: --*/ - using System; using System.Diagnostics.Contracts; namespace Microsoft.Z3 { /// - /// A floating point sort + /// FloatingPoint sort /// public class FPSort : Sort { + /// + /// The number of exponent bits. + /// + public uint EBits { get { return Native.Z3_mk_fpa_get_ebits(Context.nCtx, NativeObject); } } + + /// + /// The number of significand bits. + /// + public uint SBits { get { return Native.Z3_mk_fpa_get_ebits(Context.nCtx, NativeObject); } } + #region Internal internal FPSort(Context ctx, IntPtr obj) : base(ctx, obj) @@ -39,5 +48,5 @@ namespace Microsoft.Z3 Contract.Requires(ctx != null); } #endregion - } + } }