Zulip Chat Archive

Stream: mathlib4

Topic: Subgroup definition yields "metavariables" error


thielema (Jan 18 2025 at 10:08):

The following simplified code causes the Lean kernel to emit suspicious errors:

import Mathlib
import Lean

def is_primitive_root [Monoid α] (n : Nat) (z : α)
  :=  k:, if n  k then z^k = 1 else z^k  1

def subgroup_of_primitive_root [Monoid α] {n : Nat} [NeZero n]
  {z : α} (primitive_root : is_primitive_root n z)
  : Subgroup (Units α) where
  carrier := {x |  k, x = z^k}
  mul_mem' {x y} | k,z_k, j,z_j => k+j, by simp [pow_add, z_k, z_j]
  one_mem' := by use 0; simp [pow_zero]
  inv_mem' {x}
    | k,z_k => by
      use (n-1)*k
      sorry

I get the error message:

(kernel) declaration has metavariables 'subgroup_of_primitive_root'

I think this is not intended?

Edward van de Meent (Jan 18 2025 at 10:11):

i'm not getting this error on the playground...

Edward van de Meent (Jan 18 2025 at 10:31):

ah, it seems that i do get the error when i specify mathlib stable on the playground...

Etienne Marion (Jan 18 2025 at 10:39):

This solves the issue. I'm not sure what the problem is exactly but this metavariable message often occurs because of a weird pattern matching (though it seems to be fixed in the latest version in this case).

import Mathlib

set_option autoImplicit false

variable {α : Type*}

def is_primitive_root [Monoid α] (n : Nat) (z : α)
  :=  k:, if n  k then z^k = 1 else z^k  1

def subgroup_of_primitive_root [Monoid α] {n : Nat} [NeZero n]
  {z : α} (primitive_root : is_primitive_root n z)
  : Subgroup (Units α) where
  carrier := {x |  k, x = z^k}
  mul_mem' := by
    rintro x y k, z_k j, z_j
    exact k+j, by simp [pow_add, z_k, z_j]
  one_mem' := by use 0; simp [pow_zero]
  inv_mem' := by
      rintro x k, z_k
      use (n-1)*k
      sorry

thielema (Jan 19 2025 at 15:20):

Problem occured in 4.14. I confirm it has gone in 4.15.

thielema (Jan 19 2025 at 15:21):

No sorry, still occurs in 4.15.

Etienne Marion (Jan 19 2025 at 15:48):

The latest version is 4.16.0-rc2, but it is not a stable release.

thielema (Jan 19 2025 at 21:16):

Nice, with 4.16.0-rc2 the problem disappears.

Kyle Miller (Jan 19 2025 at 21:22):

I think it might have been lean4#6414


Last updated: May 02 2025 at 03:31 UTC