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

Add occurs check at dependent eliminator #1022

Closed
leodemoura opened this issue Feb 18, 2022 · 1 comment
Closed

Add occurs check at dependent eliminator #1022

leodemoura opened this issue Feb 18, 2022 · 1 comment

Comments

@leodemoura
Copy link
Member

The occurs check is missing, and prevents Lean from elaborating the following example

namespace STLC

abbrev Var := Char

inductive type where
  | base  : type
  | arrow : type → type → type

inductive term where
  | var : Var → term
  | lam : Var → type → term → term
  | app : term → term → term

def ctx := List (Var × type)

open type term in
inductive typing : ctx → term → type → Prop where
  | var  : typing ((x, A) :: Γ) (var x) A -- simplified
  | arri : typing ((x, A) :: Γ) M B → typing Γ (lam x A M) (arrow A B)
  | arre : typing Γ M (arrow A B) → typing Γ N A → typing Γ (app M N) B

open type term in
theorem no_δ : ¬ ∃ A B, typing nil (lam x A (app (var x) (var x))) (arrow A B) :=
  fun h => match h with
  | Exists.intro A (Exists.intro B h) => match h with
    | typing.arri h => match h with
      | typing.arre (A := T) h₁ h₂ => match h₂ with
        | typing.var => nomatch h₁ -- Fail here

namespace STLC

The nomatch h₁ fails to detect that arrow A B = A has no solutions.

@digama0
Copy link
Collaborator

digama0 commented Feb 18, 2022

While this would be nice to have, it looks low priority to me. noConfusion style proofs can't handle occurs check reasoning, so you would need a custom inductive proof on the spot. The usual way is to use Nat.lt transitivity with a sizeof function to argue that sizeof A < sizeof (arrow A B), but this has lots of limitations in the dependent type situation and generally goes quite a bit beyond what the equation compiler normally needs to do. Note also that the theorem is false for inductive predicates: if type was a Prop then arrow A B = A would be true. I would not really expect nomatch to be able to do this proof.

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

No branches or pull requests

2 participants