-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numeric literals sampling #1389
Draft
rybla
wants to merge
87
commits into
master
Choose a base branch
from
literal-sampling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ampling, literal-sampling-bin-size
Here's a high-level description of the entire sampling algorithm:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current problem with
:check
ing functions that are polymorphic in numeric typesWhen
check
ing a polymorphic function, Cryptol chooses default instantiations of the parametrized type variables that satisfy the function's type constraints. There is a system of rules for choosing default non-numeric type instantiations according to the set of type classes that type variable is constrained by. For numeric type variables, a default instance is found by asking the SMT to try and solve the numeric constraints and then give back a single solving substitution.For testing functions that are polymorphic in numeric types, this method of default instantiation is
unsatisfactory, because the SMT solver only provides a single solution, and that solution is usually trivial (i.e. the smallest literals that satisfy the constraints). For example:
Of course,
clearly_unsatisfied
is clearly unsatisfied, since adding1
to all the elements of a sequence is not the identity. But, since the SMT solver foundn = 0
to be a solution that satisfiesfin n
, it just tests that and finds that[] = []
indeed.New feature: sampling over solution substitutions of the numeric types
This PR implements a new feature that, when turned on, replaces defaulting when getting a concrete type for a function during
:check
ing. It can be turned on viawhere
X
is the number of tests to run for each sampled substitution of literals (the default is 10).The literal sampler algorithm takes into account the constraints over numeric literals in the type signature of the function being
:check
ed, and tries to sample with a certain distribution over the solutions. Only a certain domain of constraints are currently supported. Leta, b, c, ...
be numeric type variables andx, y, z, ...
be constant numeric literals. Then the following subset of the cryptol type constraint syntax is allowed to mention numeric type variables in a function in order to be accepted by the literal sampling algorithm:fin _
_ == _
,_ <= _
,_ >= _
_ + _
,_ - _
a * x
,a % x
,a / x
x * y
,x / y
,x % y
,x ^^ y
If a variable is only bounded above by
inf
, then it is sampled along an exponential distribution up to a maximum value, where higher values are less likely to be sampled. If a variable is bounded above by a constant, then it is sampled on a uniform distribution up to that upper bounded. The order of variable sampling should not affect the distribution (I'm still working out how true this is).Once a solution substitution is sampled, the instantiation of the function type with that substitution is
:check
ed as if it was a normal top-level function, except for onlyliteral-sampling-bin-size
number of tests. Then another solution is sampled and:check
ed, etc, until the the total number of tests performed is at leasttests
.TODO
Things @Riib11 didn't finish before his internship ended.
:check
without any arguments