You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a nice cu.many() helper for generating collections with a minimum, average, and maximum size. To support local mutation (in generation or shrinking), we arrange this as a sequence of (should_add_element, element) pairs, with a constant probability of adding an element so that the encoding is invariant with respect to the collection index. That in turn gives us a geometric distribution over lengths - before accounting for subtree exhaustion - but anyway, it works nicely. Here's the implementation:
The problem is that this formula for stopping_value, based on the sum of a geometric series, is valid if and only if min_size=0 and max_size=infinity! We should instead compute the stopping_value which gives us our desired average_size over the finite sum of a geometric series between maybe-nonzero min_size and finite-and-maybe-small max_size.
(for implementation reasons max_size is bounded at 4K, typically much less, but such late terms make a negligible contribution to the sum and thus probability anyway)
The text was updated successfully, but these errors were encountered:
which isn't generally solvable for stopping_value for large inputs of max_size - min_size due to being a large polynomial. Therefore I don't think there's a nice general solution.
You still can get an improvement on the status quo by assuming max_size = inf though:
We have a nice
cu.many()
helper for generating collections with a minimum, average, and maximum size. To support local mutation (in generation or shrinking), we arrange this as a sequence of(should_add_element, element)
pairs, with a constant probability of adding an element so that the encoding is invariant with respect to the collection index. That in turn gives us a geometric distribution over lengths - before accounting for subtree exhaustion - but anyway, it works nicely. Here's the implementation:hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/utils.py
Lines 388 to 393 in 377b2ed
The problem is that this formula for
stopping_value
, based on the sum of a geometric series, is valid if and only ifmin_size=0
andmax_size=infinity
! We should instead compute thestopping_value
which gives us our desiredaverage_size
over the finite sum of a geometric series between maybe-nonzero min_size and finite-and-maybe-small max_size.(for implementation reasons max_size is bounded at 4K, typically much less, but such late terms make a negligible contribution to the sum and thus probability anyway)
The text was updated successfully, but these errors were encountered: