Open andrey-kuprianov opened 2 years ago
There is an issue with the error message. It should have told you that your set is a bit too large to deal with.
Here is what it gets preprocessed into:
Init_si_0000 ==
Skolem((\E t_a$1 \in SUBSET ({
[denom |-> d$1, amount |-> a$1]:
d$1 \in { "a", "b", "c" },
a$1 \in
0
.. 115792089237316195423570985008687907853269984665640564039457584007913129639935
}):
Skolem((\E t_9$1 \in { "Alice", "Bob", "Carol", "Dave", "Eve" }:
Skolem((\E t_8$1 \in { "Alice", "Bob", "Carol", "Dave", "Eve" }:
action' := [sender |-> t_8$1, receiver |-> t_9$1, coins |-> t_a$1]))))))
So the error message is not very informative, but there is no way we can construct a powerset of the set 0.. 115792089237316195423570985008687907853269984665640564039457584007913129639935
.
If you avoid sets of records, especially the ones with immensely large powersets, then you have better chances.
Classifying it as usability issue, as this is concerned with a suboptimal error message.
re: simplifying selection of action, perhaps something like this?
---- MODULE Ex ----
EXTENDS Apalache, Integers
VARIABLES
\* @typeAlias: COIN = {denom: Str, amount: Int};
\* @typeAlias: ACTION = {sender: Str, receiver: Str, coins: Set(COIN)};
\* @type: ACTION;
action
WALLETS == {"Alice", "Bob", "Carol", "Dave", "Eve"}
MAX_BALANCE == 10
DENOMS == {"a", "b", "c"}
COINS == { [denom |-> d, amount |-> a] : d \in DENOMS, a \in 0 .. MAX_BALANCE }
Actions == [ sender: WALLETS, receiver: WALLETS, coins: SUBSET COINS ]
Init == action \in Actions
Next == \E a \in Actions: action' = a
=====
Right, this works. However, the problem was not with big integers, which we support, but with a..b
over big integers in combination with SUBSET
, which in this case forces us to reason about sets of size up to $2^{256}$. This would require a quantified encoding.
Right, sorry, that was orthoginal to the big ints thing. I was only addressing
Besides that, what I want to achieve, is to express a non-deterministic choice of action. It should be possible to do simpler than in the example; I would be grateful for help on how to express the desired behavior by possibly other means.
Maybe I misunderstood what was being asked, and maybe my suggestion is not really a simplification (it amounts to the same any how). But I took that to be unrelated to the big int issue. I just changed MAX_BALANCE
so the spec would run :)
As has been hinted by @konnov, Value Generators seem to be a better approach here than constructing power sets.
Related to #2139 (cc @danwt, @konnov ); this is what I ended up using to get nice variability wrt. generated actions:
---- MODULE test ----
EXTENDS Apalache, Integers
VARIABLES
\* @typeAlias: COIN = [denom: Str, amount: Int];
\* @typeAlias: ACTION = [sender: Str, receiver: Str, coins: Int -> COIN];
\* @type: ACTION;
action,
\* @type: Int;
step
MAX_BALANCE == 2^256-1
WALLETS == {"Alice", "Bob", "Carol", "Dave", "Eve"}
DENOMS == {"a", "b", "c"}
AMOUNTS == { 0, 1, 2, 3, 10, 20, 30, 100, 200, 300, 2^256-2, 2^256-1, 2^256, 2^256+1, 2^256+2 }
COINS == [ denom : DENOMS, amount: AMOUNTS ]
\* @type: COIN;
GuessCoin ==
LET d == Guess(DENOMS) IN
LET a == Guess(AMOUNTS) IN
[ denom |-> d, amount |-> a ]
\* @type: Int -> COIN;
GuessCoins == [ n \in 1..2 |-> GuessCoin ]
\* @type: (ACTION) => Bool;
NewAction(a) ==
\E sender, receiver \in WALLETS:
a = [ sender |-> sender, receiver |-> receiver, coins |-> GuessCoins ]
Init == NewAction(action) /\ step=0
Next == NewAction(action') /\ step'=step+1
View == action
Inv == step<4
=====
and, e.g. apalache check --inv=Inv --max-error=20 --view=View test.tla
Would be interested to hear opinions on whether this is a good approach or not, and if it can be improved.
Looks like a nice PBT test. You do not need the invariant in this case, you could just run:
apalache-mc simulate --length=4 --max-error=20 --view=View test.tla
You could also write Guess(AMOUNTS \union {Gen(1)})
to add a bit of variability.
Impact
This seems to be a bug, as it tries to fit unbounded integers in the spec into bounded integers in Scala.
Besides that, what I want to achieve, is to express a non-deterministic choice of action. It should be possible to do simpler than in the example; I would be grateful for help on how to express the desired behavior by possibly other means.
Input specification
The command line parameters used to run the tool
Expected behavior
Log files
System information
0.28.0 build 3d945af
Mac OS X
15.0.3
Triage checklist (for maintainers)