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

Functional induction principles should prune parmeters #6320

Closed
nomeata opened this issue Dec 5, 2024 · 1 comment · Fixed by #6330
Closed

Functional induction principles should prune parmeters #6320

nomeata opened this issue Dec 5, 2024 · 1 comment · Fixed by #6330
Labels
bug Something isn't working P-medium We may work on this issue if we find the time

Comments

@nomeata
Copy link
Collaborator

nomeata commented Dec 5, 2024

It can happen that (fixed) function parameters end up completely unused in the function’s induction principle. For example in

/--
info: Array.mapFinIdxM.map.induct.{u, v, w} {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : Array α)
  (f : Fin as.size → α → m β) (motive : (i j : Nat) → i + j = as.size → Array β → Prop)
  (case1 : ∀ (j : Nat) (bs : Array β) (x : 0 + j = as.size), 0 + j = as.size → motive 0 j x bs)
  (case2 :
    ∀ (j : Nat) (bs : Array β) (i : Nat) (inv : i + 1 + j = as.size),
      j < as.size →
        ∀ (this : i + (j + 1) = as.size),
          i.succ + j = as.size →
            (∀ (__do_lift : β), motive i (j + 1) this (bs.push __do_lift)) → motive i.succ j inv bs)
  (i j : Nat) (inv : i + j = as.size) (bs : Array β) : motive i j inv bs
-/
#guard_msgs in #check Array.mapFinIdxM.map.induct

The parameter f is used neither in the theorem statement nor the proof.

I originally left these parameters there, assuming they wouldn’t hurt and would help the user knowing how to instantiate the induction principle.

But in practice they get in the way, for example in this proof, where the function of interest appears under a lambda:

axiom monotone : ∀ {α} {β}, (α → β) → Prop

theorem monotone_mapIdxM
    (m : Type u → Type v) [Monad m]
    {α β : Type u}
    {γ : Type w}
    (xs : Array α)
    (f : γ → Fin xs.size → α → m β) :
    monotone (fun x => xs.mapFinIdxM (fun i y => f x i y)) := by
  -- This shows a limitation of the induction principles:
  -- the parameter `f` isn't strictly needed, and cannot actually be instantiated here
  suffices
    ∀ i j (h : i + j = xs.size) r, monotone (fun x => Array.mapFinIdxM.map xs (fun i y => f x i y) i j h r) by
    apply this
  intros i j h r
  induction i, j, h, r using Array.mapFinIdxM.map.induct (m := m) xs
  case case1 =>
    sorry
  case case2 ih =>
    sorry
  case f i y => exact f sorry i y -- cannot be instantiated

Here I cannot pass any f to the induction principle, but the proof would make perfect sense otherwise.

Version

info: Lean 4.16.0-nightly-2024-12-05

@nomeata nomeata added the bug Something isn't working label Dec 5, 2024
@nomeata
Copy link
Collaborator Author

nomeata commented Dec 5, 2024

Likely just a matter of changing this code:

-- We could pass (usedOnly := true) below, and get nicer induction principles that
-- do not mention odd unused parameters.
-- But the downside is that automatic instantiation of the principle (e.g. in a tactic
-- that derives them from an function application in the goal) is harder, as
-- one would have to infer or keep track of which parameters to pass.
-- So for now lets just keep them around.
let e' ← mkLambdaFVars (binderInfoForMVars := .default) fixedParams e'

@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Dec 6, 2024
nomeata added a commit that referenced this issue Dec 6, 2024
This PR removes unnecessary parameters from the funcion induction
principles. This is a breaking change; broken code can typically be adjusted
simply by passing fewer parameters.

Closes #6320
nomeata added a commit that referenced this issue Dec 7, 2024
This PR removes unnecessary parameters from the funcion induction
principles. This is a breaking change; broken code can typically be adjusted
simply by passing fewer parameters.

Part 1, before stage0 update.

Closes #6320
nomeata added a commit that referenced this issue Dec 7, 2024
This PR removes unnecessary parameters from the funcion induction
principles. This is a breaking change; broken code can typically be adjusted
simply by passing fewer parameters.

Part 2, adjusting after stage0 update.

Closes #6320
nomeata added a commit that referenced this issue Dec 7, 2024
This PR removes unnecessary parameters from the funcion induction
principles. This is a breaking change; broken code can typically be adjusted
simply by passing fewer parameters.

Part 2, adjusting after stage0 update.

Closes #6320
nomeata added a commit that referenced this issue Dec 7, 2024
This PR removes unnecessary parameters from the funcion induction
principles. This is a breaking change; broken code can typically be adjusted
simply by passing fewer parameters.

Part 1, before stage0 update.

Closes #6320
nomeata added a commit that referenced this issue Dec 7, 2024
This PR removes unnecessary parameters from the funcion induction
principles. This is a breaking change; broken code can typically be adjusted
simply by passing fewer parameters.

Part 2, adjusting after stage0 update.

Closes #6320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium We may work on this issue if we find the time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants