Skip to content

Commit c84ca3e

Browse files
Princess: Update Princess to version 2025-06-25 and Ostrich to 2.0
1 parent 71fcd6a commit c84ca3e

File tree

3 files changed

+54
-73
lines changed

3 files changed

+54
-73
lines changed

lib/ivy.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,16 @@ SPDX-License-Identifier: Apache-2.0
170170
<dependency org="de.uni-freiburg.informatik.ultimate" name="smtinterpol" rev="2.5-1242-g5c50fb6d" conf="runtime-smtinterpol->master; contrib->sources"/>
171171

172172
<!-- Princess and Ostrich for our Maven release -->
173-
<dependency org="io.github.uuverifiers" name="princess_2.13" rev="2024-11-08" conf="runtime-princess-with-javacup->default; contrib->sources"/>
174-
<dependency org="io.github.uuverifiers" name="ostrich_2.13" rev="1.4.1" conf="runtime-princess-with-javacup->default; contrib->sources"/>
173+
<dependency org="io.github.uuverifiers" name="princess_2.13" rev="2025-06-25" conf="runtime-princess-with-javacup->default; contrib->sources"/>
174+
<dependency org="io.github.uuverifiers" name="ostrich_2.13" rev="2.0" conf="runtime-princess-with-javacup->default; contrib->sources"/>
175175
<!-- Princess and Ostrich for our Ivy release -->
176-
<dependency org="io.github.uuverifiers" name="princess_2.13" rev="2024-11-08" conf="runtime-princess->default; contrib->sources">
176+
<dependency org="io.github.uuverifiers" name="princess_2.13" rev="2025-06-25" conf="runtime-princess->default; contrib->sources">
177177
<!-- Exclude dependency on java-cup and replace it with java-cup-runtime, which is enough.
178178
We use the JAR that is published by us instead of the one from net.sf.squirrel-sql.thirdparty-non-maven
179179
because the latter does not provide a separate JAR for java-cup-runtime. -->
180180
<exclude org="net.sf.squirrel-sql.thirdparty-non-maven" name="java-cup"/>
181181
</dependency>
182-
<dependency org="io.github.uuverifiers" name="ostrich_2.13" rev="1.4.1" conf="runtime-princess->default; contrib->sources">
182+
<dependency org="io.github.uuverifiers" name="ostrich_2.13" rev="2.0" conf="runtime-princess->default; contrib->sources">
183183
<!-- Exclude dependency on java-cup and replace it with java-cup-runtime, which is enough.
184184
We use the JAR that is published by us instead of the one from net.sf.squirrel-sql.thirdparty-non-maven
185185
because the latter does not provide a separate JAR for java-cup-runtime. -->

src/org/sosy_lab/java_smt/solvers/princess/PrincessFormulaCreator.java

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@
4242
import ap.theories.arrays.ExtArray;
4343
import ap.theories.bitvectors.ModuloArithmetic;
4444
import ap.theories.nia.GroebnerMultiplication$;
45-
import ap.theories.rationals.Fractions;
46-
import ap.theories.rationals.Rationals$;
45+
import ap.theories.rationals.Rationals;
4746
import ap.types.Sort;
4847
import ap.types.Sort$;
4948
import com.google.common.base.Preconditions;
5049
import com.google.common.collect.HashBasedTable;
5150
import com.google.common.collect.ImmutableList;
5251
import com.google.common.collect.ImmutableSet;
5352
import com.google.common.collect.Table;
54-
import java.lang.reflect.InvocationTargetException;
5553
import java.util.HashMap;
5654
import java.util.LinkedHashMap;
5755
import java.util.List;
@@ -108,6 +106,13 @@ class PrincessFormulaCreator
108106
// modmod.bv_xnor()?
109107
// modmod.bv_comp()?
110108

109+
theoryFunctionKind.put(Rationals.addition(), FunctionDeclarationKind.ADD);
110+
theoryFunctionKind.put(Rationals.multiplication(), FunctionDeclarationKind.MUL);
111+
theoryFunctionKind.put(Rationals.multWithFraction(), FunctionDeclarationKind.MUL);
112+
theoryFunctionKind.put(Rationals.multWithRing(), FunctionDeclarationKind.MUL);
113+
theoryFunctionKind.put(Rationals.division(), FunctionDeclarationKind.DIV);
114+
theoryFunctionKind.put(Rationals.RatDivZero(), FunctionDeclarationKind.OTHER);
115+
111116
// casts to integer, sign/zero-extension?
112117

113118
theoryPredKind.put(ModuloArithmetic.bv_ult(), FunctionDeclarationKind.BV_ULT);
@@ -207,30 +212,28 @@ public Object convertValue(IExpression value) {
207212
return ((IIntLit) value).value().bigIntValue();
208213
}
209214
if (value instanceof IFunApp) {
210-
IFunApp fun = (IFunApp) value;
211-
switch (fun.fun().name()) {
215+
IFunApp app = (IFunApp) value;
216+
switch (app.fun().name()) {
212217
case "true":
213-
Preconditions.checkArgument(fun.fun().arity() == 0);
218+
Preconditions.checkArgument(app.fun().arity() == 0);
214219
return true;
215220
case "false":
216-
Preconditions.checkArgument(fun.fun().arity() == 0);
221+
Preconditions.checkArgument(app.fun().arity() == 0);
217222
return false;
218223
case "mod_cast":
219224
// we found a bitvector BV(lower, upper, ctxt), lets extract the last parameter
220-
return ((IIntLit) fun.apply(2)).value().bigIntValue();
221-
case "_int":
222-
case "Rat_int":
223-
Preconditions.checkArgument(fun.fun().arity() == 1);
224-
ITerm term = fun.apply(0);
225+
return ((IIntLit) app.apply(2)).value().bigIntValue();
226+
case "Rat_fromRing":
227+
Preconditions.checkArgument(app.fun().arity() == 1);
228+
ITerm term = app.apply(0);
225229
if (term instanceof IIntLit) {
226230
return ((IIntLit) term).value().bigIntValue();
227231
}
228232
break;
229-
case "_frac":
230233
case "Rat_frac":
231-
Preconditions.checkArgument(fun.fun().arity() == 2);
232-
ITerm term1 = fun.apply(0);
233-
ITerm term2 = fun.apply(1);
234+
Preconditions.checkArgument(app.fun().arity() == 2);
235+
ITerm term1 = app.apply(0);
236+
ITerm term2 = app.apply(1);
234237
if (term1 instanceof IIntLit && term2 instanceof IIntLit) {
235238
Rational ratValue =
236239
Rational.of(
@@ -241,7 +244,7 @@ public Object convertValue(IExpression value) {
241244
break;
242245
case "str_empty":
243246
case "str_cons":
244-
return strToString(fun);
247+
return strToString(app);
245248
default:
246249
}
247250
}
@@ -360,8 +363,11 @@ private String getName(IExpression input) {
360363
}
361364
}
362365

363-
/** Returns true if the expression is a constant number. */
364-
private static boolean isConstant(IFunApp pExpr) {
366+
/** Returns true if the expression is a constant value. */
367+
private static boolean isValue(IFunApp pExpr) {
368+
if (!pExpr.fun().equals(Rationals.frac()) && !pExpr.fun().equals(Rationals.fromRing())) {
369+
return false;
370+
}
365371
for (IExpression sub : asJava(pExpr.args())) {
366372
if (!(sub instanceof IIntLit)) {
367373
return false;
@@ -370,23 +376,6 @@ private static boolean isConstant(IFunApp pExpr) {
370376
return true;
371377
}
372378

373-
/** Returns true if the expression is an integer literal. */
374-
private static boolean isRatInt(IFunApp pExpr) {
375-
// We need to use reflection to get Rationals.int() as `int` can't be a method name in Java
376-
final IFunction ratInt;
377-
try {
378-
ratInt = (IFunction) Fractions.class.getMethod("int").invoke(Rationals$.MODULE$);
379-
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
380-
throw new RuntimeException(ex);
381-
}
382-
return isConstant(pExpr) && pExpr.fun().equals(ratInt);
383-
}
384-
385-
/** Returns true if the expression is a faction literal. */
386-
private static boolean isRatFrac(IFunApp pExpr) {
387-
return isConstant(pExpr) && pExpr.fun().equals(Rationals$.MODULE$.frac());
388-
}
389-
390379
@SuppressWarnings("deprecation")
391380
@Override
392381
public <R> R visit(FormulaVisitor<R> visitor, final Formula f, final IExpression input) {
@@ -398,8 +387,7 @@ public <R> R visit(FormulaVisitor<R> visitor, final Formula f, final IExpression
398387
IBoolLit literal = (IBoolLit) input;
399388
return visitor.visitConstant(f, literal.value());
400389

401-
} else if (input instanceof IFunApp
402-
&& (isRatInt((IFunApp) input) || isRatFrac((IFunApp) input))) {
390+
} else if (input instanceof IFunApp && (isValue((IFunApp) input))) {
403391
return visitor.visitConstant(f, convertValue(input));
404392

405393
} else if (input instanceof IQuantified) {

src/org/sosy_lab/java_smt/solvers/princess/PrincessRationalFormulaManager.java

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ public class PrincessRationalFormulaManager
4040
@Override
4141
protected boolean isNumeral(IExpression value) {
4242
if (value instanceof IFunApp) {
43-
IFunApp fun = (IFunApp) value;
44-
switch (fun.fun().name()) {
45-
case "int":
46-
case "Rat_int":
47-
assert fun.fun().arity() == 1;
48-
return ifmgr.isNumeral(fun.apply(0));
49-
case "frac":
50-
assert fun.fun().arity() == 2;
51-
return ifmgr.isNumeral(fun.apply(0)) && ifmgr.isNumeral(fun.apply(1));
43+
IFunApp app = (IFunApp) value;
44+
switch (app.fun().name()) {
45+
case "Rat_fromRing":
46+
assert app.fun().arity() == 1;
47+
return ifmgr.isNumeral(app.apply(0));
48+
case "Rat_frac":
49+
assert app.fun().arity() == 2;
50+
return ifmgr.isNumeral(app.apply(0)) && ifmgr.isNumeral(app.apply(1));
5251
}
5352
}
5453
return false;
@@ -68,40 +67,34 @@ protected IExpression makeNumberImpl(BigInteger i) {
6867
return fromInteger(ifmgr.makeNumberImpl(i));
6968
}
7069

71-
@Override
72-
protected IExpression makeNumberImpl(Rational pI) {
73-
return divide(makeNumberImpl(pI.getNum()), makeNumberImpl(pI.getDen()));
74-
}
75-
76-
@Override
77-
protected IExpression makeNumberImpl(String i) {
78-
return makeNumberImpl(new BigDecimal(i));
79-
}
80-
8170
@Override
8271
protected IExpression makeNumberImpl(double pNumber) {
8372
return makeNumberImpl(BigDecimal.valueOf(pNumber));
8473
}
8574

8675
@Override
8776
protected IExpression makeNumberImpl(BigDecimal pNumber) {
88-
if (pNumber.stripTrailingZeros().scale() <= 0) {
89-
// We have an integer number
90-
// Return the term for a/1
91-
return PrincessEnvironment.rationalTheory.int2ring(
92-
ifmgr.makeNumberImpl(pNumber.toBigInteger()));
77+
return makeNumberImpl(Rational.ofBigDecimal(pNumber));
78+
}
79+
80+
@Override
81+
protected IExpression makeNumberImpl(Rational pI) {
82+
if (pI.isIntegral()) {
83+
return makeNumberImpl(pI.getNum());
9384
} else {
94-
// We have a fraction a/b
95-
// Convert the numerator and the divisor and then return the fraction
96-
List<ITerm> args =
97-
ImmutableList.of(
98-
ifmgr.makeNumberImpl(pNumber.unscaledValue()),
99-
ifmgr.makeNumberImpl(BigInteger.valueOf(10).pow(pNumber.scale())));
10085
return new IFunApp(
101-
PrincessEnvironment.rationalTheory.frac(), PrincessEnvironment.toSeq(args));
86+
PrincessEnvironment.rationalTheory.frac(),
87+
PrincessEnvironment.toSeq(
88+
ImmutableList.of(
89+
ifmgr.makeNumberImpl(pI.getNum()), ifmgr.makeNumberImpl(pI.getDen()))));
10290
}
10391
}
10492

93+
@Override
94+
protected IExpression makeNumberImpl(String i) {
95+
return makeNumberImpl(new BigDecimal(i));
96+
}
97+
10598
@Override
10699
protected IExpression makeVariableImpl(String varName) {
107100
return getFormulaCreator().makeVariable(PrincessEnvironment.FRACTION_SORT, varName);

0 commit comments

Comments
 (0)