Overflow when using RandomSubset
See original GitHub issueTLC encounters an overflow error when evaluating the RandomSubset
operator from the Randomization
module with with a record set that is too big. For example, evaluating the following in the TLC REPL:
(tla+) RandomSubset(3, SUBSET [a:1..8, b:1..8])
util.Assert$TLCRuntimeException: Attempted to apply the operator overridden by the Java method
public static tlc2.value.impl.Value tlc2.module.Randomization.RandomSubset(tlc2.value.impl.Value,tlc2.value.impl.Value),
but it produced the following error:
Overflow when computing the number of elements in:
SUBSET { [a |-> 1, b |-> 1],
[a |-> 1, b |-> 2],
[a |-> 1, b |-> 3],
[a |-> 1, b |-> 4],
[a |-> 1, b |-> 5],
[a |-> 1, b |-> 6],
[a |-> 1, b |-> 7],
[a |-> 1, b |-> 8],
[a |-> 2, b |-> 1],
[a |-> 2, b |-> 2],
[a |-> 2, b |-> 3],
[a |-> 2, b |-> 4],
[a |-> 2, b |-> 5],
[a |-> 2, b |-> 6],
[a |-> 2, b |-> 7],
[a |-> 2, b |-> 8],
[a |-> 3, b |-> 1],
[a |-> 3, b |-> 2],
[a |-> 3, b |-> 3],
[a |-> 3, b |-> 4],
[a |-> 3, b |-> 5],
[a |-> 3, b |-> 6],
[a |-> 3, b |-> 7],
[a |-> 3, b |-> 8],
[a |-> 4, b |-> 1],
[a |-> 4, b |-> 2],
[a |-> 4, b |-> 3],
[a |-> 4, b |-> 4],
[a |-> 4, b |-> 5],
[a |-> 4, b |-> 6],
[a |-> 4, b |-> 7],
[a |-> 4, b |-> 8],
[a |-> 5, b |-> 1],
[a |-> 5, b |-> 2],
[a |-> 5, b |-> 3],
[a |-> 5, b |-> 4],
[a |-> 5, b |-> 5],
[a |-> 5, b |-> 6],
[a |-> 5, b |-> 7],
[a |-> 5, b |-> 8],
[a |-> 6, b |-> 1],
[a |-> 6, b |-> 2],
[a |-> 6, b |-> 3],
[a |-> 6, b |-> 4],
[a |-> 6, b |-> 5],
[a |-> 6, b |-> 6],
[a |-> 6, b |-> 7],
[a |-> 6, b |-> 8],
[a |-> 7, b |-> 1],
[a |-> 7, b |-> 2],
[a |-> 7, b |-> 3],
[a |-> 7, b |-> 4],
[a |-> 7, b |-> 5],
[a |-> 7, b |-> 6],
[a |-> 7, b |-> 7],
[a |-> 7, b |-> 8],
[a |-> 8, b |-> 1],
[a |-> 8, b |-> 2],
[a |-> 8, b |-> 3],
[a |-> 8, b |-> 4],
[a |-> 8, b |-> 5],
[a |-> 8, b |-> 6],
[a |-> 8, b |-> 7],
[a |-> 8, b |-> 8] }
at util.Assert.fail(Assert.java:33)
at tlc2.value.impl.MethodValue.apply(MethodValue.java:176)
at tlc2.value.impl.OpValue.eval(OpValue.java:25)
at tlc2.tool.impl.Tool.evalApplImpl(Tool.java:1706)
at tlc2.tool.impl.FastTool.evalAppl(FastTool.java:98)
at tlc2.tool.impl.Tool.evalImpl(Tool.java:1468)
at tlc2.tool.impl.FastTool.eval(FastTool.java:91)
at tlc2.tool.impl.Tool.eval(Tool.java:1364)
at tlc2.REPL.processInput(REPL.java:121)
at tlc2.REPL.runREPL(REPL.java:151)
at tlc2.REPL.main(REPL.java:174)
From some investigation it looks like the error for this specific case arises from the size
call inside SubsetValue.toSetEnum() which is called from EnumerableValue.getRandomSubset() . It looks like the issue manifests when the set size is greater than what can be handled by a 32 bit int e.g. RandomSubset(3, SUBSET [a:1..8, b:1..4])
throws an error but RandomSubset(3, SUBSET [a:1..8, b:1..3])
doesn’t.
Reproduced in TLC revision 4aff6d2.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Sample random rows in dataframe - Stack Overflow
randomly samples 10 rows from the dataframe. It calls sample.int , so really is the same answer with less typing (and simplifies use...
Read more >Is a subset of a random set still random?
1 Answer 1 · if you choose every 3rd element, you'll end up with another random list; · if you pick up all...
Read more >random.sample raises OverflowError - Python Forum
Used for random sampling without replacement. Returns a new list containing elements from the population while leaving the original population ...
Read more >Sufficiently random sample - co.combinatorics - MathOverflow
Let d be an integer ≥2, and let Ω={0,1}d, A⊆{0,1}2 and i,j integers with 1≤i<j≤d. If we select an element (x1,x2,…,xd) in Ω...
Read more >Poisson distribution - Wikipedia
Definitions · Probability mass function. A discrete random variable X is said to have a Poisson distribution, with parameter λ > 0 {\displaystyle...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah. I originally ran into the error when working on a larger spec, and then produced this smaller repro.
Sounds good, thanks.