leanprover-community / leanprover-community/lean

(No equational lemmas)/(Mistaken as field notation) when using a `namespace` inside a `section` with universe polymorphism

Open
#613 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
433
Forks
79
PR merge metrics
No merged PRs in 30d

Description

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

Allowing a namespace inside a section can cause compile issues.

Steps to Reproduce
  1. Compile the following code:
    section
      universes u
    
      inductive my_unit : Type u
      | foo
    
      namespace my_unit
        def one : ℕ := 1
      end my_unit
    
      lemma test : my_unit.one = 1 := by refl
    end
    

Expected behavior: Code compiles, in particular, my_unit.one isn't treated as field notation.

Actual behavior: Obtain error message:

invalid field notation, type is not of the form (C ...) where C is a constant
  my_unit
has type
  Type u

Reproduces how often: 100%

Versions
  • Lean (version 3.32.1, commit 35b3a9c4e2d3, Release) on cygwin.
Additional Information

If you rephrase the code, you can also get another issue which I think is related:

section
  universes u

  inductive my_unit : Type u
  | foo

  def my_unit.one (_ : my_unit) : ℕ := 1

  lemma test : my_unit.one my_unit.foo = 1 := by unfold my_unit.one
end

gives:

unfold tactic failed, my_unit.one does not have equational lemmas nor is a projection
state:
⊢ my_unit.foo.one = 1

There some small adjustments I've been able to make to get either example to compile. I think the second and third qualifies as a workaround.

  • Don't use universe polymorphism.
    section
      inductive my_unit : Type
      | foo
    
      namespace my_unit
        def one : ℕ := 1
      end my_unit
    
      lemma test : my_unit.one = 1 := by refl
    end
    
  • Move the namespace out of the section.
    section
      universes u
    
      inductive my_unit : Type u
      | foo
    end
    
    namespace my_unit
      universes u
      def one : ℕ := 1
      -- other code which uses `u`
    end my_unit
    
    section
      universes u
      lemma test : my_unit.one = 1 := by refl
    end
    
  • Use _root_.
    section
      universes u
    
      inductive my_unit : Type u
      | foo
    
      namespace my_unit
        def one : ℕ := 1
      end my_unit
    
      lemma test : _root_.my_unit.one = 1 := by refl
    end
    

Hopefully I haven't made any mistakes or missed an issue/PR, I couldn't find anything related when searching for both "namespace" and "section".

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing both minimal examples with Lean 3.32.1, focusing on the namespace inside a universe-polymorphic section and the resulting field-notation or equational-lemma errors. Compare the listed workarounds, including moving the namespace and using _root_. Done means the original examples compile, my_unit.one resolves as a name, and the second example can be unfolded.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.