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

refactor: port below and brecOn construction to Lean #4517

Merged
merged 12 commits into from
Jun 26, 2024

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Jun 20, 2024

This ports the .below and .brecOn constructions to lean.

I kept them in the same file, as they were in the C code, because they are
highly coupled and the constructions are very analogous.

For validation I developed this in a separate repository at
https://github.com/nomeata/lean-constructions/tree/fad715e
and checked that all declarations found in Lean and Mathlib are
equivalent, up to

def canon (e : Expr) : CoreM Expr := do
  Core.transform (← Core.betaReduce e) (pre := fun
    | .const n ls  => return .done (.const n (ls.map (·.normalize)))
    | .sort l => return .done (.sort l.normalize)
    | _ => return .continue)

It was not feasible to make them completely equal, because the kernel's
type inference code seem to optimize level expressions a bit less
aggressively, and beta-reduces less in inference.

The private helper functions about PProd can later move into their own
file, used by these constructions as well as the structural recursion
module.

nomeata added 2 commits June 20, 2024 16:43
this is the simplest of the constructions to be ported from C++ to Lean,
so I’ll PR this one first.

This begins to put each construction into its own file, as it was the
case with C++.

For validation I developed this in a separate repository at
https://github.com/nomeata/lean-constructions/tree/fad715e
and checked that all `.recOn` declarations found in Lean and Mathlib are
identical (per `==`) to the ones produced by the C code.
this is the simplest of the constructions to be ported from C++ to Lean,
so I’ll PR this one first.

For validation I developed this in a separate repository at
https://github.com/nomeata/lean-constructions/tree/fad715e
and checked that all `.recOn` declarations found in Lean and Mathlib are
equivalent, up to

    def canon (e : Expr) : CoreM Expr := do
      Core.transform (← Core.betaReduce e) (pre := fun
        | .const n ls  => return .done (.const n (ls.map (·.normalize)))
        | .sort l => return .done (.sort l.normalize)
        | _ => return .continue)

It was not feasible to make them completely equal, because the kernel's
type inference code seem to optimize level expressions a bit less
aggressively, and beta-reduces less in inference.

The private helper functions about `PProd` can later move into their own
file, used by these constructions as well as the structural recursion
module.
@nomeata nomeata force-pushed the joachim/constructions-belows branch from bf1073a to a37f0fd Compare June 20, 2024 14:56
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc June 20, 2024 15:11 Inactive
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jun 20, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Jun 20, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 1f732bb3b7fa8e93ca01c1b257668aee14d72d2d --onto 357b52928f905bfb85a3496e411cf12fa20e730c. (2024-06-20 15:27:12)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 378b02921d930ff805b8111a1ece04abc905b963 --onto 24d51b90cc4adbc68386671bba4587d6e47188d6. (2024-06-23 08:14:28)

@nomeata nomeata changed the title refactor: port below construction to Lean refactor: port below and brecOn construction to Lean Jun 23, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc June 23, 2024 08:43 Inactive
@nomeata nomeata marked this pull request as ready for review June 23, 2024 09:04
@nomeata nomeata added the will-merge-soon …unless someone speaks up label Jun 23, 2024
@nomeata nomeata added this pull request to the merge queue Jun 26, 2024
Merged via the queue into master with commit ea22ef4 Jun 26, 2024
15 checks passed
nomeata added a commit that referenced this pull request Jul 4, 2024
I made a mistake in #4517, fixed here, so about time to add a test.

I wonder if this generic level optimization should be move into `mkLevelMax'`, but not today.

fixes #4650
github-merge-queue bot pushed a commit that referenced this pull request Jul 4, 2024
I made a mistake in #4517, fixed here, so about time to add a test.

I wonder if this generic level optimization should be moved into
`mkLevelMax'`, but not today.

fixes #4650
github-actions bot pushed a commit that referenced this pull request Jul 4, 2024
I made a mistake in #4517, fixed here, so about time to add a test.

I wonder if this generic level optimization should be moved into
`mkLevelMax'`, but not today.

fixes #4650

(cherry picked from commit 5ad5c2c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN will-merge-soon …unless someone speaks up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants