-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathats-anairiats-bignums.patch
More file actions
287 lines (259 loc) · 6.81 KB
/
Copy pathats-anairiats-bignums.patch
File metadata and controls
287 lines (259 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
diff --git a/src/ats_solver_fm.cats b/src/ats_solver_fm.cats
index b1f71bb..d264314 100644
--- a/src/ats_solver_fm.cats
+++ b/src/ats_solver_fm.cats
@@ -48,16 +48,26 @@
/* ****** ****** */
+typedef ats_mpz_ptr_type i0nt;
+
+/* ****** ****** */
+
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_i0nt_of_int
- (ats_int_type i) { return (i) ; }
+ (ats_int_type i)
+{
+ ats_ptr_type p = atspre_ptr_alloc_tsz (sizeof (ats_mpz_viewt0ype));
+ atslib_mpz_init_set_int (p, i);
+ return p;
+}
// end of [atsopt_solver_fm_i0nt_of_int]
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_i0nt_of_intinf
- (ats_mpz_ptr_type i) { return atsopt_get_int (i) ; }
+ (ats_mpz_ptr_type i)
+{ return i ; }
// end of [atsopt_solver_fm_i0nt_of_intinf]
/* ****** ****** */
@@ -65,48 +75,48 @@ atsopt_solver_fm_i0nt_of_intinf
ATSinline()
ats_bool_type
atsopt_solver_fm_gt_i0nt_int
- (ats_int_type i0, ats_int_type i) {
- return (i0 > i ? ats_true_bool : ats_false_bool) ;
+ (i0nt i0, ats_int_type i) {
+ return atsopt_gt_intinf_int (i0, i) ;
} // end of [atsopt_solver_fm_gt_i0nt_int]
ATSinline()
ats_bool_type
atsopt_solver_fm_gte_i0nt_int (
- ats_int_type i0, ats_int_type i
+ i0nt i0, ats_int_type i
) {
- return (i0 >= i ? ats_true_bool : ats_false_bool) ;
+ return atsopt_gte_intinf_int (i0, i) ;
} // end of [atsopt_solver_fm_gte_i0nt_int]
ATSinline()
ats_bool_type
atsopt_solver_fm_lt_i0nt_int (
- ats_int_type i0, ats_int_type i
+ i0nt i0, ats_int_type i
) {
- return (i0 < i ? ats_true_bool : ats_false_bool) ;
+ return atsopt_lt_intinf_int (i0, i) ;
} // end of [atsopt_solver_fm_lt_i0nt_int]
ATSinline()
ats_bool_type
atsopt_solver_fm_lte_i0nt_int (
- ats_int_type i0, ats_int_type i
+ i0nt i0, ats_int_type i
) {
- return (i0 <= i ? ats_true_bool : ats_false_bool) ;
+ return atsopt_lte_intinf_int (i0, i) ;
} // end of [atsopt_solver_fm_lte_i0nt_int]
ATSinline()
ats_bool_type
atsopt_solver_fm_eq_i0nt_int (
- ats_int_type i0, ats_int_type i
+ i0nt i0, ats_int_type i
) {
- return (i0 == i ? ats_true_bool : ats_false_bool) ;
+ return atsopt_eq_intinf_int (i0, i) ;
} // end of [atsopt_solver_fm_eq_i0nt_int]
ATSinline()
ats_bool_type
atsopt_solver_fm_neq_i0nt_int (
- ats_int_type i0, ats_int_type i
+ i0nt i0, ats_int_type i
) {
- return (i0 != i ? ats_true_bool : ats_false_bool) ;
+ return atsopt_neq_intinf_int (i0, i) ;
} // end of [atsopt_solver_fm_neq_i0nt_int]
//
@@ -114,93 +124,114 @@ atsopt_solver_fm_neq_i0nt_int (
ATSinline()
ats_bool_type
atsopt_solver_fm_gt_i0nt_i0nt (
- ats_int_type i1, ats_int_type i2
+ i0nt i1, i0nt i2
) {
- return (i1 > i2 ? ats_true_bool : ats_false_bool) ;
+ return atsopt_gt_intinf_intinf (i1, i2) ;
} // end of [atsopt_solver_fm_gt_i0nt_i0nt]
ATSinline()
ats_bool_type
atsopt_solver_fm_lt_i0nt_i0nt (
- ats_int_type i1, ats_int_type i2
+ i0nt i1, i0nt i2
) {
- return (i1 < i2 ? ats_true_bool : ats_false_bool) ;
+ return atsopt_lt_intinf_intinf (i1, i2) ;
} // end of [atsopt_solver_fm_lt_i0nt_i0nt]
//
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_neg_i0nt
- (ats_int_type i) { return (-i) ; }
+ (i0nt i) { return atsopt_neg_intinf (i) ; }
// end of [atsopt_solver_fm_neg_i0nt]
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_add_i0nt_i0nt (
- ats_int_type i1, ats_int_type i2
+ i0nt i1, i0nt i2
) {
- return (i1 + i2) ;
+ return atsopt_add_intinf_intinf (i1, i2) ;
} // end of [atsopt_solver_fm_add_i0nt_i0nt]
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_sub_i0nt_i0nt (
- ats_int_type i1, ats_int_type i2
+ i0nt i1, i0nt i2
) {
- return (i1 - i2) ;
+ return atsopt_sub_intinf_intinf (i1, i2) ;
} // end of [atsopt_solver_fm_sub_i0nt_i0nt]
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_mul_i0nt_i0nt (
- ats_int_type i1, ats_int_type i2
+ i0nt i1, i0nt i2
) {
- return (i1 * i2) ;
+ return atsopt_mul_intinf_intinf (i1, i2) ;
} // end of [atsopt_solver_fm_mul_i0nt_i0nt]
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_div_i0nt_i0nt (
- ats_int_type i1, ats_int_type i2
+ i0nt i1, i0nt i2
) {
- return (i1 / i2) ;
+ mpz_ptr ans = ATS_MALLOC (sizeof(ats_mpz_viewt0ype)) ;
+ mpz_init (ans) ;
+ mpz_tdiv_q (ans, i1, i2) ;
+ return ans ;
} // end of [atsopt_solver_fm_div_i0nt_i0nt]
//
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_succ_i0nt
- (ats_int_type i) { return (i + 1) ; }
+ (i0nt i) {
+ mpz_ptr ans = ATS_MALLOC (sizeof(ats_mpz_viewt0ype)) ;
+ mpz_init (ans) ;
+ mpz_add_ui (ans, i, 1) ;
+ return ans ;
+}
// end of [atsopt_solver_fm_succ_i0nt]
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_pred_i0nt
- (ats_int_type i) { return (i - 1) ; }
+ (i0nt i) {
+ mpz_ptr ans = ATS_MALLOC (sizeof(ats_mpz_viewt0ype)) ;
+ mpz_init (ans) ;
+ mpz_sub_ui (ans, i, 1) ;
+ return ans ;
+}
// end of [atsopt_solver_fm_pred_i0nt]
//
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_mod_i0nt_i0nt
- (ats_int_type i1, ats_int_type i2) {
- return (i1 % i2) ;
+ (i0nt i1, i0nt i2) {
+ mpz_ptr ans = ATS_MALLOC (sizeof(ats_mpz_viewt0ype)) ;
+ mpz_init (ans);
+ mpz_tdiv_r (ans, i1, i2) ;
+ return ans ;
} // end of [atsopt_solver_fm_mod_i0nt_i0nt]
ATSinline()
-ats_int_type
+i0nt
atsopt_solver_fm_gcd_i0nt_i0nt (
- ats_int_type i1, ats_int_type i2
+ i0nt i1, i0nt i2
) {
- int tmp ;
- if (i1 < 0) i1 = -i1 ;
- if (i2 < 0) i2 = -i2 ;
-
+ if (atsopt_lt_intinf_int (i1, 0)) {
+ i1 = atsopt_neg_intinf (i1) ;
+ }
+ if (atsopt_lt_intinf_int (i2, 0)) {
+ i2 = atsopt_neg_intinf (i2) ;
+ }
while (1) {
- if (i2 == 0) return i1; tmp = i1 % i2 ; i1 = i2 ; i2 = tmp ;
+ if (atsopt_eq_intinf_int (i2, 0)) return i1;
+ i0nt tmp = atsopt_solver_fm_mod_i0nt_i0nt (i1, i2) ;
+ i1 = i2;
+ i2 = tmp;
}
return 0 ; /* deadcode */
} // end of [atsopt_solver_fm_gcd_i0nt_i0nt]
@@ -210,8 +241,8 @@ atsopt_solver_fm_gcd_i0nt_i0nt (
ATSinline()
ats_void_type
atsopt_solver_fm_fprint_i0nt
- (ats_ptr_type out, ats_int_type i) {
- fprintf ((FILE *)out, "%i", i) ; return ;
+ (ats_ptr_type out, i0nt i) {
+ atslib_fprint_mpz (out, i) ;
} // end of [atsopt_solver_fm_fprint_i0nt]
/* ****** ****** */
@@ -234,10 +265,16 @@ ATSinline()
ats_ptr_type
atsopt_solver_fm_intvec_ptr_make
(ats_int_type n) {
- int *p ;
- int nbytes = n * sizeof(ats_int_type) ;
+ i0nt zero = ATS_MALLOC (sizeof(ats_mpz_viewt0ype)) ;
+ mpz_init_set_si (zero, 0) ;
+ i0nt *p ;
+ int i ;
+ int nbytes = n * sizeof(i0nt) ;
p = ATS_MALLOC (nbytes) ;
- return memset (p, 0, nbytes) ;
+ for (i=0; i<n; ++i) {
+ p[i] = zero ;
+ }
+ return p ;
} // end of [atsopt_solver_fm_intvec_ptr_make]
/* ****** ****** */
diff --git a/src/ats_solver_fm.sats b/src/ats_solver_fm.sats
index 7b76040..62ffd7e 100644
--- a/src/ats_solver_fm.sats
+++ b/src/ats_solver_fm.sats
@@ -46,7 +46,7 @@ staload IntInf = "ats_intinf.sats"
(* ****** ****** *)
-abst@ype i0nt = int
+abstype i0nt
val i0nt_0 : i0nt
val i0nt_1 : i0nt