Skip to content

rfl not working for pattern matching on indexed inductive types #837

Closed

Description

@imbrem

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

Unless I'm doing something very wrong, rfl does not seem to be working properly for functions defined by pattern matching on indexed inductive types, even for every simple functions

Steps to Reproduce

The following compiles file

inductive RawWk: Type 0 where
  | id: RawWk
  | step: RawWk -> RawWk
  | lift: RawWk -> RawWk

def raw_wk_comp (ρ: RawWk) (σ: RawWk): RawWk :=
  match ρ, σ with
    | RawWk.id, σ => σ
    | RawWk.step ρ, σ => RawWk.step (raw_wk_comp ρ σ)
    | RawWk.lift ρ, RawWk.id => RawWk.lift ρ
    | RawWk.lift ρ, RawWk.step σ => RawWk.step (raw_wk_comp ρ σ)
    | RawWk.lift ρ, RawWk.lift σ => RawWk.lift (raw_wk_comp ρ σ)

theorem raw_wk_comp_id_id {ρ: RawWk}: raw_wk_comp RawWk.id ρ = ρ := rfl

but, when indexing the inductive type as follows

inductive Wk: Nat -> Nat -> Type 0 where
  | id: Wk n n
  | step: Wk m n -> Wk (Nat.succ m) n
  | lift: Wk m n -> Wk (Nat.succ m) (Nat.succ n)

def wk_comp {n m l: Nat} (ρ: Wk n m) (σ: Wk m l): Wk n l :=
  match n, m, l, ρ, σ with
    | _, _, _, Wk.id, σ => σ
    | _, _, _, Wk.step ρ, σ => Wk.step (wk_comp ρ σ)
    | _, _, _, Wk.lift ρ, Wk.id => Wk.lift ρ
    | _, _, _, Wk.lift ρ, Wk.step σ => Wk.step (wk_comp ρ σ)
    | _, _, _, Wk.lift ρ, Wk.lift σ => Wk.lift (wk_comp ρ σ)

theorem wk_comp_id_id {ρ: Wk m n}: wk_comp Wk.id ρ = ρ := rfl

I get an error

Expected behavior: this should type-check (it works in Agda)

Actual behavior: I get the error

(kernel) declaration type mismatch, 'wk_comp_id_id' has type
  ∀ {m n : Nat} {ρ : Wk m n}, wk_comp Wk.id ρ = wk_comp Wk.id ρ
but it is expected to have type
  ∀ {m n : Nat} {ρ : Wk m n}, wk_comp Wk.id ρ = ρ

Reproduces how often: Always

Versions

Lean (version 4.0.0-nightly-2021-12-01, commit 4aab42f, Release)
on Ubuntu 20.04

Additional Information

N/A

Activity

  1. kmill commented on Dec 1, 2021

    @kmill
    Collaborator

    Here's a smaller example with the same error:

    inductive Wk: Nat -> Nat -> Type 0 where
      | id: Wk n n
      | step: Wk m n -> Wk (Nat.succ m) n
    
    def wk_comp : Wk n m → Wk m l → Wk n l
      | Wk.id, σ => σ
      | Wk.step ρ, σ => Wk.step (wk_comp ρ σ)
    
    theorem wk_comp_id_id {ρ: Wk m n}: wk_comp Wk.id ρ = ρ := rfl
    
    /-
    (kernel) declaration type mismatch, 'wk_comp_id_id' has type
      ∀ {m n : Nat} {ρ : Wk m n}, wk_comp Wk.id ρ = wk_comp Wk.id ρ
    but it is expected to have type
      ∀ {m n : Nat} {ρ : Wk m n}, wk_comp Wk.id ρ = ρ
    -/
  2. arthurpaulino commented on Dec 1, 2021

    @arthurpaulino
    Contributor

    For some reason this is accepted:

    inductive Wk: Nat -> Nat -> Type 0 where
      | id: Wk n n
      | step: Wk m n -> Wk m n -- (Nat.succ m) n
    
    def wk_comp : Wk n m → Wk m l → Wk n l
      | Wk.id, σ => σ
      | Wk.step ρ, σ => Wk.step (wk_comp ρ σ)
    
    theorem wk_comp_id_id {ρ: Wk m n}: wk_comp Wk.id ρ = ρ := rfl
  3. leodemoura commented on Dec 2, 2021

    @leodemoura
    Member

    Thanks for all the useful feedback. It helped to diagnose and fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions