2
2
// an API wrapper for a collection of SMT solvers:
3
3
// https://github.com/sosy-lab/java-smt
4
4
//
5
- // SPDX-FileCopyrightText: 2020 Dirk Beyer <https://www.sosy-lab.org>
5
+ // SPDX-FileCopyrightText: 2025 Dirk Beyer <https://www.sosy-lab.org>
6
6
//
7
7
// SPDX-License-Identifier: Apache-2.0
8
8
17
17
import java .math .BigDecimal ;
18
18
import java .math .BigInteger ;
19
19
import java .util .List ;
20
+ import java .util .stream .Collectors ;
20
21
import org .sosy_lab .common .rationals .Rational ;
21
22
import org .sosy_lab .java_smt .api .BooleanFormula ;
22
23
import org .sosy_lab .java_smt .api .Formula ;
@@ -180,7 +181,7 @@ public ResultFormulaType makeVariable(String pVar) {
180
181
@ Override
181
182
public ResultFormulaType negate (ParamFormulaType pNumber ) {
182
183
TFormulaInfo param1 = extractInfo (pNumber );
183
- return wrap (negate (param1 ));
184
+ return wrap (negate (toType ( param1 ) ));
184
185
}
185
186
186
187
protected abstract TFormulaInfo negate (TFormulaInfo pParam1 );
@@ -190,14 +191,19 @@ public ResultFormulaType add(ParamFormulaType pNumber1, ParamFormulaType pNumber
190
191
TFormulaInfo param1 = extractInfo (pNumber1 );
191
192
TFormulaInfo param2 = extractInfo (pNumber2 );
192
193
193
- return wrap (add (param1 , param2 ));
194
+ return wrap (add (toType ( param1 ), toType ( param2 ) ));
194
195
}
195
196
196
197
protected abstract TFormulaInfo add (TFormulaInfo pParam1 , TFormulaInfo pParam2 );
197
198
198
199
@ Override
199
200
public ResultFormulaType sum (List <ParamFormulaType > operands ) {
200
- return wrap (sumImpl (Lists .transform (operands , this ::extractInfo )));
201
+ return wrap (
202
+ sumImpl (
203
+ operands .stream ()
204
+ .map (this ::extractInfo )
205
+ .map (this ::toType )
206
+ .collect (Collectors .toList ())));
201
207
}
202
208
203
209
protected TFormulaInfo sumImpl (List <TFormulaInfo > operands ) {
@@ -213,7 +219,7 @@ public ResultFormulaType subtract(ParamFormulaType pNumber1, ParamFormulaType pN
213
219
TFormulaInfo param1 = extractInfo (pNumber1 );
214
220
TFormulaInfo param2 = extractInfo (pNumber2 );
215
221
216
- return wrap (subtract (param1 , param2 ));
222
+ return wrap (subtract (toType ( param1 ), toType ( param2 ) ));
217
223
}
218
224
219
225
protected abstract TFormulaInfo subtract (TFormulaInfo pParam1 , TFormulaInfo pParam2 );
@@ -231,7 +237,7 @@ public ResultFormulaType divide(ParamFormulaType pNumber1, ParamFormulaType pNum
231
237
result = makeUf (divUfDecl , param1 , param2 );
232
238
} else {
233
239
try {
234
- result = divide (param1 , param2 );
240
+ result = divide (toType ( param1 ), toType ( param2 ) );
235
241
} catch (UnsupportedOperationException e ) {
236
242
if (nonLinearArithmetic == NonLinearArithmetic .APPROXIMATE_FALLBACK ) {
237
243
result = makeUf (divUfDecl , param1 , param2 );
@@ -263,7 +269,7 @@ public ResultFormulaType modulo(ParamFormulaType pNumber1, ParamFormulaType pNum
263
269
result = makeUf (modUfDecl , param1 , param2 );
264
270
} else {
265
271
try {
266
- result = modulo (param1 , param2 );
272
+ result = modulo (toType ( param1 ), toType ( param2 ) );
267
273
} catch (UnsupportedOperationException e ) {
268
274
if (nonLinearArithmetic == NonLinearArithmetic .APPROXIMATE_FALLBACK ) {
269
275
result = makeUf (modUfDecl , param1 , param2 );
@@ -337,7 +343,7 @@ public ResultFormulaType multiply(ParamFormulaType pNumber1, ParamFormulaType pN
337
343
result = makeUf (multUfDecl , param1 , param2 );
338
344
} else {
339
345
try {
340
- result = multiply (param1 , param2 );
346
+ result = multiply (toType ( param1 ), toType ( param2 ) );
341
347
} catch (UnsupportedOperationException e ) {
342
348
if (nonLinearArithmetic == NonLinearArithmetic .APPROXIMATE_FALLBACK ) {
343
349
result = makeUf (multUfDecl , param1 , param2 );
@@ -434,4 +440,9 @@ protected TFormulaInfo floor(TFormulaInfo number) {
434
440
"method should only be called for RationalFormulae, but type is "
435
441
+ getFormulaCreator ().getFormulaType (number ));
436
442
}
443
+
444
+ /** Make sure the value is of correct type (Int vs. Real) and add a cast if necessary. */
445
+ protected TFormulaInfo toType (TFormulaInfo param ) {
446
+ return param ;
447
+ }
437
448
}
0 commit comments