Zulip Chat Archive

Stream: lean4

Topic: unfolding earlier fields


Scott Morrison (Oct 06 2022 at 06:03):

In lean3 I could write:

import algebra.group.defs

def bar (a b : nat) : nat := a * b

@[simp]
lemma foo (a b : nat) : bar a b = a * b := rfl

instance : add_semigroup nat :=
{ add := bar,
  add_assoc := λ f g h,
  begin
    simp, -- `+` has changed to `*`
    sorry
  end }

but in lean4:

import Mathlib.Algebra.Group.Basic

def bar (a b : Nat) : Nat := a * b

@[simp]
lemma foo (a b : Nat) : bar a b = a * b := rfl

instance : AddSemigroup Nat :=
{ add := bar,
  add_assoc := fun f g h => by
    simp -- Nothing happens: `foo` doesn't fire
    sorry }

How is one meant to handle this?

Gabriel Ebner (Oct 06 2022 at 23:58):

Ooh, I think that's because + is now HAdd.hAdd so there's the indirection HAdd->Add->AddSemigroup which breaks the unfolding here.

Gabriel Ebner (Oct 06 2022 at 23:59):

I'd do: I wouldn't ever declare an incompatible addition instance for Nat like this:

instance : Add Nat where
  add := bar

theorem Nat.add_def {x y : Nat} : x + y = bar x y := rfl

Last updated: Dec 20 2023 at 11:08 UTC