-
Notifications
You must be signed in to change notification settings - Fork 153
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
Generate function definitions #4727
Comments
Let's leave all function uninterpreted until we run into that issue, so we only handle the simplest cases first, and then leave uninterpreted functions after that. |
So the generation process should be the following:
In both cases:
Implementation will start with all functions uninterpreted, then will be incrementally refined to be able to generate definitions for more and more complex case. |
Found a more general approach, see: |
Depends on: #4726
Suppose we have a function production
The general structure of a function rule is the following:
First, we order rules by priority. This allows the following defintion:
where
foo_pgroup_i
is a function representing all rules in priority groupi
. These helpers are combined using<|>
in increasing order of priority, i.e., if a group with lower priority fails to yield a result, then the next group is tried, etc.In order for the function to be well-defined, within each priority group, for a given concrete input, there must be at most one matching rule. There are three cases.
No
requires
clausesStrictly speaking, this mapping is faithful only if the patterns are non-overlapping, as the order in which patterns are defined matters in Lean. In the presence of overlapping patterns, the K function is only well defined if there's confluence of values, thus it might happen that a non-well-defined K function is translated to a well-defined Lean function.
Only a single pattern on the LHS (modulo alpha renaming)
In this case, it has to be ensured that
requires
clauses are non-overlapping. We can generate atheorem
stub (or multiple ones, for each pair of clauses) to encode the proof obligation. Then the function definition can be implemented usingif-then-else
:The general case
I.e., there are
requires
clasues, and there are various patterns on the left hand sides of rules. Such a function can be well defined (even if the LHS patterns are overlapping), considerGroup rules by LHS pattern. Then generate a helper function as per the previous case for each group. Combine the cases with
<|>
as for priority groups.Similarly to the previous case though, a
theorem
stub (or multiple ones, for each pair of helpers) has to be generated that states well-definedness (i.e. at most one of the helpers returnssome
).The text was updated successfully, but these errors were encountered: