Skip to content
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

Definition mechanism for tail-recursive functions #1166

Merged
merged 1 commit into from
Nov 27, 2023
Merged

Definition mechanism for tail-recursive functions #1166

merged 1 commit into from
Nov 27, 2023

Conversation

myreen
Copy link
Contributor

@myreen myreen commented Nov 25, 2023

The new automation has two parts: the first part proves that a tail-recursive function exists; the second part uses new_specification to define such a function.

The given equations must have only curried variable arguments left of the equality, e.g.

foo m n = ...

is allowed, but the following is not:

foo (m, n) = ...

This commit also renames:

examples/machine-code/hoare-triple/tailrecLib.{sml,sig}
->
examples/machine-code/hoare-triple/mc_tailrecLib.{sml,sig}

Here's an example use of the new definition mechanism:

val _ = List.map Parse.hide ["foo","bar"];

val foo_def = tailrec_define "foo_def"
  “(foo m n = if m = (n:num) then bar m (SOME 8) else bar 4 NONE) ∧
   (bar k l = case l of
              | NONE => k - 6
              | SOME i =>
                  let (q,r) = ARB i
                  and (t,w,a) = ARB k l in
                    foo (q + r) (t + w + a))”;

The new automation has two parts: the first part proves
that a tail-recursive function exists; the second part
uses new_specification to define such a function.

The given equations must have only curried variable
arguments left of the equality, e.g.

    foo m n = ...

is allowed, but the following is not:

    foo (m, n) = ...

This commit also renames:

    examples/machine-code/hoare-triple/tailrecLib.{sml,sig}
    ->
    examples/machine-code/hoare-triple/mc_tailrecLib.{sml,sig}

Here's an example use of the new definition mechanism:

    val _ = List.map Parse.hide ["foo","bar"];

    val foo_def = tailrec_define "foo_def"
      “(foo m n = if m = (n:num) then bar m (SOME 8) else bar 4 NONE) ∧
       (bar k l = case l of
                  | NONE => k - 6
                  | SOME i =>
                      let (q,r) = ARB i
                      and (t,w,a) = ARB k l in
                        foo (q + r) (t + w + a))”;
@mn200
Copy link
Member

mn200 commented Nov 27, 2023

Thanks for this!

@mn200 mn200 merged commit a1129a6 into develop Nov 27, 2023
2 checks passed
@myreen myreen deleted the tailrec branch November 27, 2023 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants