Skip to content

Commit b60d0d4

Browse files
committed
Workaround: Duplicate ConstantTermNormalizer
TermParseUtils requires also the fixed ConstantTermNormalizer, otherwise some tests fail. Since it cannot be imported from Library-SmtLibUtils, because of cyclic imports, I copied it as a workaround. But the long term solution should be to fix ConstantTermNormalizer in SMTInterpol, i.e., ultimate-pa/smtinterpol#150 should be revisited and merged.
1 parent d0289a1 commit b60d0d4

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (C) 2024 Matthias Heizmann (matthias.heizmann@iste.uni-stuttgart.de>)
3+
* Copyright (C) 2024 University of Freiburg
4+
*
5+
* This file is part of the ULTIMATE ModelCheckerUtils Library.
6+
*
7+
* The ULTIMATE ModelCheckerUtils Library is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* The ULTIMATE ModelCheckerUtils Library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with the ULTIMATE ModelCheckerUtils Library. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* Additional permission under GNU GPL version 3 section 7:
21+
* If you modify the ULTIMATE ModelCheckerUtils Library, or any covered work, by linking
22+
* or combining it with Eclipse RCP (or a modified version of Eclipse RCP),
23+
* containing parts covered by the terms of the Eclipse Public License, the
24+
* licensors of the ULTIMATE ModelCheckerUtils Library grant you additional permission
25+
* to convey the resulting work.
26+
*/
27+
package de.uni_freiburg.informatik.ultimate.smtsolver.external;
28+
29+
import java.math.BigDecimal;
30+
import java.math.BigInteger;
31+
32+
import de.uni_freiburg.informatik.ultimate.logic.ConstantTerm;
33+
import de.uni_freiburg.informatik.ultimate.logic.Rational;
34+
import de.uni_freiburg.informatik.ultimate.logic.Term;
35+
import de.uni_freiburg.informatik.ultimate.logic.TermTransformer;
36+
37+
/**
38+
* {@link ConstantTerm}s that have numeric sort (Int, Real) can represent their value either as {@link BigInteger},
39+
* {@link BigDecimal}, or {@link Rational}. This class helps us to establish a normal form in which values are always
40+
* represented by {@link Rational}s.
41+
*
42+
* @author Matthias Heizmann (matthias.heizmann@iste.uni-stuttgart.de>)
43+
*
44+
*/
45+
46+
// TODO: This class is just a copy from Library-SmtLibUtils, as it cannot be imported here!
47+
// Instead, this class should be fixed in SMTInterpol and removed from Ultimate.
48+
public class ConstantTermNormalizer extends TermTransformer {
49+
50+
@Override
51+
protected void convert(final Term term) {
52+
if (term instanceof ConstantTerm) {
53+
final Term res;
54+
final ConstantTerm ct = (ConstantTerm) term;
55+
res = convertConstantTerm(term, ct);
56+
setResult(res);
57+
} else {
58+
super.convert(term);
59+
}
60+
}
61+
62+
private static Term convertConstantTerm(final Term term, final ConstantTerm ct) {
63+
if (!ct.getSort().isNumericSort()) {
64+
// do nothing, only applicable to numeric sorts
65+
return ct;
66+
}
67+
if (ct.getValue() instanceof BigInteger) {
68+
final Rational rat = Rational.valueOf((BigInteger) ct.getValue(), BigInteger.ONE);
69+
return rat.toTerm(term.getSort());
70+
} else if (ct.getValue() instanceof BigDecimal) {
71+
final BigDecimal decimal = (BigDecimal) ct.getValue();
72+
Rational rat;
73+
if (decimal.scale() <= 0) {
74+
final BigInteger num = decimal.toBigInteger();
75+
rat = Rational.valueOf(num, BigInteger.ONE);
76+
} else {
77+
final BigInteger num = decimal.unscaledValue();
78+
final BigInteger denom = BigInteger.TEN.pow(decimal.scale());
79+
rat = Rational.valueOf(num, denom);
80+
}
81+
return rat.toTerm(term.getSort());
82+
} else if (ct.getValue() instanceof Rational) {
83+
// do nothing, already in normal form
84+
return ct;
85+
} else {
86+
throw new AssertionError("Value has to be either BigInteger, Decimal, or Rational");
87+
}
88+
}
89+
90+
}

trunk/source/SMTSolverBridge/src/de/uni_freiburg/informatik/ultimate/smtsolver/external/TermParseUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import de.uni_freiburg.informatik.ultimate.logic.Script;
3838
import de.uni_freiburg.informatik.ultimate.logic.Term;
3939
import de.uni_freiburg.informatik.ultimate.logic.TermVariable;
40-
import de.uni_freiburg.informatik.ultimate.smtinterpol.model.ConstantTermNormalizer;
4140

4241
/**
4342
* Class that provides auxiliary methods for transforming Strings into SMT- {@link Term}s.

0 commit comments

Comments
 (0)