Z3
ArithExpr.cs
Go to the documentation of this file.
1/*++
2Copyright (<c>) 2012 Microsoft Corporation
3
4Module Name:
5
6 ArithExpr.cs
7
8Abstract:
9
10 Z3 Managed API: Arith Expressions
11
12Author:
13
14 Christoph Wintersteiger (cwinter) 2012-11-23
15
16Notes:
17
18--*/
19using System.Diagnostics;
20using System;
21using System.Collections.Generic;
22using System.Linq;
23using System.Text;
24
25namespace Microsoft.Z3
26{
30 public class ArithExpr : Expr
31 {
32 #region Internal
34 internal ArithExpr(Context ctx, IntPtr obj)
35 : base(ctx, obj)
36 {
37 Debug.Assert(ctx != null);
38 }
39 #endregion
40
41 #region Operators
42
43 private static ArithExpr MkNum(ArithExpr e, int i)
44 {
45 using var sort = e.Context.MkIntSort();
46 return (ArithExpr)e.Context.MkNumeral(i, sort);
47 }
48
49 private static ArithExpr MkNum(ArithExpr e, double d)
50 {
51 using var sort = e.Context.MkRealSort();
52 return (ArithExpr)e.Context.MkNumeral(d.ToString(), sort);
53 }
54
56 public static ArithExpr operator /(ArithExpr a, ArithExpr b) { return a.Context.MkDiv(a, b); }
57
59 public static ArithExpr operator /(ArithExpr a, int b)
60 {
61 using var denominator = MkNum(a, b);
62 return a / denominator;
63 }
64
66 public static ArithExpr operator /(ArithExpr a, double b)
67 {
68 using var denominator = MkNum(a, b);
69 return a / denominator;
70 }
71
73 public static ArithExpr operator /(int a, ArithExpr b)
74 {
75 using var numerator = MkNum(b, a);
76 return numerator / b;
77 }
78
80 public static ArithExpr operator /(double a, ArithExpr b)
81 {
82 using var numerator = MkNum(b, a);
83 return numerator / b;
84 }
85
87 public static ArithExpr operator -(ArithExpr a) { return a.Context.MkUnaryMinus(a); }
88
90 public static ArithExpr operator -(ArithExpr a, ArithExpr b) { return a.Context.MkSub(a, b); }
91
93 public static ArithExpr operator -(ArithExpr a, int b)
94 {
95 using var rhs = MkNum(a, b);
96 return a - rhs;
97 }
98
100 public static ArithExpr operator -(ArithExpr a, double b)
101 {
102 using var rhs = MkNum(a, b);
103 return a - rhs;
104 }
105
107 public static ArithExpr operator -(int a, ArithExpr b)
108 {
109 using var lhs = MkNum(b, a);
110 return lhs - b;
111 }
112
114 public static ArithExpr operator -(double a, ArithExpr b)
115 {
116 using var lhs = MkNum(b, a);
117 return lhs - b;
118 }
119
121 public static ArithExpr operator +(ArithExpr a, ArithExpr b) { return a.Context.MkAdd(a, b); }
122
124 public static ArithExpr operator +(ArithExpr a, int b)
125 {
126 using var rhs = MkNum(a, b);
127 return a + rhs;
128 }
129
131 public static ArithExpr operator +(ArithExpr a, double b)
132 {
133 using var rhs = MkNum(a, b);
134 return a + rhs;
135 }
136
138 public static ArithExpr operator +(int a, ArithExpr b)
139 {
140 using var lhs = MkNum(b, a);
141 return lhs + b;
142 }
143
145 public static ArithExpr operator +(double a, ArithExpr b)
146 {
147 using var lhs = MkNum(b, a);
148 return lhs + b;
149 }
150
152 public static ArithExpr operator *(ArithExpr a, ArithExpr b) { return a.Context.MkMul(a, b); }
153
155 public static ArithExpr operator *(ArithExpr a, int b)
156 {
157 using var rhs = MkNum(a, b);
158 return a * rhs;
159 }
160
162 public static ArithExpr operator *(ArithExpr a, double b)
163 {
164 using var rhs = MkNum(a, b);
165 return a * rhs;
166 }
167
169 public static ArithExpr operator *(int a, ArithExpr b)
170 {
171 using var lhs = MkNum(b, a);
172 return lhs * b;
173 }
174
176 public static ArithExpr operator *(double a, ArithExpr b)
177 {
178 using var lhs = MkNum(b, a);
179 return lhs * b;
180 }
181
183 public static BoolExpr operator <=(ArithExpr a, ArithExpr b) { return a.Context.MkLe(a, b); }
184
186 public static BoolExpr operator <=(ArithExpr a, int b)
187 {
188 using var rhs = MkNum(a, b);
189 return a <= rhs;
190 }
191
193 public static BoolExpr operator <=(ArithExpr a, double b)
194 {
195 using var rhs = MkNum(a, b);
196 return a <= rhs;
197 }
198
200 public static BoolExpr operator <=(int a, ArithExpr b)
201 {
202 using var lhs = MkNum(b, a);
203 return lhs <= b;
204 }
205
207 public static BoolExpr operator <=(double a, ArithExpr b)
208 {
209 using var lhs = MkNum(b, a);
210 return lhs <= b;
211 }
212
214 public static BoolExpr operator <(ArithExpr a, ArithExpr b) { return a.Context.MkLt(a, b); }
215
217 public static BoolExpr operator <(ArithExpr a, int b)
218 {
219 using var rhs = MkNum(a, b);
220 return a < rhs;
221 }
222
224 public static BoolExpr operator <(ArithExpr a, double b)
225 {
226 using var rhs = MkNum(a, b);
227 return a < rhs;
228 }
229
231 public static BoolExpr operator <(int a, ArithExpr b)
232 {
233 using var lhs = MkNum(b, a);
234 return lhs < b;
235 }
236
238 public static BoolExpr operator <(double a, ArithExpr b)
239 {
240 using var lhs = MkNum(b, a);
241 return lhs < b;
242 }
243
245 public static BoolExpr operator >(ArithExpr a, ArithExpr b) { return a.Context.MkGt(a, b); }
246
248 public static BoolExpr operator >(ArithExpr a, int b)
249 {
250 using var rhs = MkNum(a, b);
251 return a > rhs;
252 }
253
255 public static BoolExpr operator >(ArithExpr a, double b)
256 {
257 using var rhs = MkNum(a, b);
258 return a > rhs;
259 }
260
262 public static BoolExpr operator >(int a, ArithExpr b)
263 {
264 using var lhs = MkNum(b, a);
265 return lhs > b;
266 }
267
269 public static BoolExpr operator >(double a, ArithExpr b)
270 {
271 using var lhs = MkNum(b, a);
272 return lhs > b;
273 }
274
276 public static BoolExpr operator >=(ArithExpr a, ArithExpr b) { return a.Context.MkGe(a, b); }
277
279 public static BoolExpr operator >=(ArithExpr a, int b)
280 {
281 using var rhs = MkNum(a, b);
282 return a >= rhs;
283 }
284
286 public static BoolExpr operator >=(ArithExpr a, double b)
287 {
288 using var rhs = MkNum(a, b);
289 return a >= rhs;
290 }
291
293 public static BoolExpr operator >=(int a, ArithExpr b)
294 {
295 using var lhs = MkNum(b, a);
296 return lhs >= b;
297 }
298
300 public static BoolExpr operator >=(double a, ArithExpr b)
301 {
302 using var lhs = MkNum(b, a);
303 return lhs >= b;
304 }
305
306 #endregion
307 }
308}
Arithmetic expressions (int/real)
Definition: ArithExpr.cs:31
static BoolExpr operator>(ArithExpr a, ArithExpr b)
Operator overloading for arithmetical operator
Definition: ArithExpr.cs:245
static ArithExpr operator*(ArithExpr a, ArithExpr b)
Operator overloading for arithmetical operator
Definition: ArithExpr.cs:152
static BoolExpr operator>=(ArithExpr a, ArithExpr b)
Operator overloading for arithmetical operator
Definition: ArithExpr.cs:276
static ArithExpr operator+(ArithExpr a, ArithExpr b)
Operator overloading for arithmetical operator
Definition: ArithExpr.cs:121
static BoolExpr operator<(ArithExpr a, ArithExpr b)
Operator overloading for arithmetical operator
Definition: ArithExpr.cs:214
static ArithExpr operator-(ArithExpr a)
Operator overloading for arithmetical operator
Definition: ArithExpr.cs:87
static ArithExpr operator/(ArithExpr a, ArithExpr b)
Operator overloading for arithmetical division operator (over reals)
Definition: ArithExpr.cs:56
static BoolExpr operator<=(ArithExpr a, ArithExpr b)
Operator overloading for arithmetical operator
Definition: ArithExpr.cs:183
Boolean expressions
Definition: BoolExpr.cs:32
The main interaction with Z3 happens via the Context.
Definition: Context.cs:34
BoolExpr MkLe(ArithExpr t1, ArithExpr t2)
Create an expression representing t1 <= t2
Definition: Context.cs:1231
ArithExpr MkUnaryMinus(ArithExpr t)
Create an expression representing -t.
Definition: Context.cs:1153
ArithExpr MkSub(params ArithExpr[] t)
Create an expression representing t[0] - t[1] - ....
Definition: Context.cs:1141
BoolExpr MkLt(ArithExpr t1, ArithExpr t2)
Create an expression representing t1 < t2
Definition: Context.cs:1218
BoolExpr MkGe(ArithExpr t1, ArithExpr t2)
Create an expression representing t1 >= t2
Definition: Context.cs:1257
ArithExpr MkMul(params ArithExpr[] t)
Create an expression representing t[0] * t[1] * ....
Definition: Context.cs:1115
ArithExpr MkAdd(params ArithExpr[] t)
Create an expression representing t[0] + t[1] + ....
Definition: Context.cs:1090
RealSort MkRealSort()
Create a real sort.
Definition: Context.cs:240
ArithExpr MkDiv(ArithExpr t1, ArithExpr t2)
Create an expression representing t1 / t2.
Definition: Context.cs:1164
IntSort MkIntSort()
Create a new integer sort.
Definition: Context.cs:231
Expr MkNumeral(string v, Sort ty)
Create a Term of a given sort.
Definition: Context.cs:2913
BoolExpr MkGt(ArithExpr t1, ArithExpr t2)
Create an expression representing t1 > t2
Definition: Context.cs:1244
Expressions are terms.
Definition: Expr.cs:31
Context Context
Access Context object
Definition: Z3Object.cs:120