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

Incrementality causes a weird error #5076

Closed
3 tasks done
BrunoDutertre opened this issue Aug 16, 2024 · 0 comments · Fixed by #5090
Closed
3 tasks done

Incrementality causes a weird error #5076

BrunoDutertre opened this issue Aug 16, 2024 · 0 comments · Fixed by #5090
Labels
bug Something isn't working

Comments

@BrunoDutertre
Copy link

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

In VScode, the kernel complains of an invalid proof term in the example below (I couldn't reduce it more).

(kernel) declaration has metavariables 'PFormula.nnf_of_pos_produces_nnf'

The error disappears on "Restart File" or after any small edit to the file. It reappears when the proof is modified.

inductive PFormula (α: Type): Type where
  | And: Array (PFormula α) → PFormula α
  | Or: Array (PFormula α) → PFormula α
  | Not: (PFormula α) → PFormula α
  | Atom: α → PFormula α

namespace PFormula

/-
Negative normal form
-/
def is_atom (f: PFormula α): Prop :=
  match f with
  | .Atom _ => True
  | _ => False

def is_nnf (f: PFormula α): Prop :=
  match f with
  | .And a | .Or a => all_nnf a
  | .Not g => g.is_atom
  | .Atom _ => True
where
  all_nnf (a: Array (PFormula α)): Prop := ∀ i, (k: i < a.size) → a[i].is_nnf

mutual
-- convert f to negative normal form
def nnf_of_pos (f: PFormula α): PFormula α :=
  match f with
  | .And a => And (a.mapIdx (fun i _ => nnf_of_pos a[i]))
  | .Or a => Or (a.mapIdx (fun i _ => nnf_of_pos a[i]))
  | .Not g => nnf_of_neg g
  | .Atom x => Atom x

-- convert (not f) to negative normal form
def nnf_of_neg (f: PFormula α): PFormula α :=
  match f with
  | .And a => Or (a.mapIdx (fun i _ => nnf_of_neg a[i]))
  | .Or a => And (a.mapIdx (fun i _ => nnf_of_neg a[i]))
  | .Not g => nnf_of_pos g
  | .Atom x => Not (Atom x)
end

theorem nnf_of_pos_produces_nnf {f: PFormula α}: is_nnf (nnf_of_pos f) := by
  induction f using nnf_of_pos.induct (motive2 := fun g => is_nnf (nnf_of_neg g))
  case case1 a ih | case2 a ih =>
    simp [nnf_of_pos, is_nnf, is_nnf.all_nnf]
    intro i h
    exact ih ⟨i, h⟩
  case case3 g ih =>
    simp only [nnf_of_pos]
    exact ih
  case case4 =>
    simp [nnf_of_pos, is_nnf]
  case case5 a ih | case6 a ih =>
    simp [nnf_of_neg, is_nnf, is_nnf.all_nnf]
    intro i h
    exact ih ⟨i, h⟩
  case case7 g  ih =>
    simp only [nnf_of_neg]
    exact ih
  case case8 =>
    simp [nnf_of_neg, is_nnf, is_atom]

end PFormula

Context

Talked with @leodemoura about this and he suspects that this is caused by incrementality.

Steps to Reproduce

It's a bit finicky but this might work

  1. Load the example in vscode
  2. If the error is not there. Comment out the case7 in the proof then put it back in.
  3. Restarting lean on the file should make the error disappear.

Versions

4.10.0

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@BrunoDutertre BrunoDutertre added the bug Something isn't working label Aug 16, 2024
@BrunoDutertre BrunoDutertre changed the title Incrementality causes weird error Incrementality causes a weird error Aug 16, 2024
@Kha Kha linked a pull request Aug 19, 2024 that will close this issue
@Kha Kha closed this as completed in #5090 Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant