Zulip Chat Archive

Stream: mathlib4

Topic: Noncomputable definitions in !4#3007


Jeremy Tan (Mar 21 2023 at 01:03):

!4#3007 Because FreeAlgebra.lift is noncomputable the instance in this file has to be noncomputable too; because that instance is noncomputable starHom must be too. Should I be worried or not?

Eric Wieser (Mar 21 2023 at 01:06):

FreeAlgebra.lift shouldn't be non-computable

Eric Wieser (Mar 21 2023 at 01:06):

So your PR is fine, but something is up with a previous PR

Jeremy Tan (Mar 21 2023 at 01:07):

!4#2905 to be more precise

Eric Wieser (Mar 21 2023 at 01:09):

Right, the standard fix is to copy what I did with docs4#Nat.rec_eq_recC

Eric Wieser (Mar 21 2023 at 01:09):

But that can be a separate PR

Adam Topaz (Mar 21 2023 at 01:57):

Is this a bug?

Jeremy Tan (Mar 21 2023 at 01:58):

Adam Topaz said:

Is this a bug?

I'm already having an argument with @Eric Wieser on which lemmas should be restored to make the simp in the last declaration work. !4#3008 restored two simp lemmas; I prodded myself and found that a third lemma should be restored, now Eric claims that the third lemma is indeed no longer needed in L4

Eric Wieser (Mar 21 2023 at 01:59):

Adam Topaz said:

Is this a bug?

It's a missing feature, lean4#2049

Adam Topaz (Mar 21 2023 at 02:01):

Ah ok.

Jeremy Tan (Mar 21 2023 at 02:02):

@Eric Wieser I merged your !4#3008 into my !4#3007 and tried it; by simp [star_algebraMap] still doesn't work

Eric Wieser (Mar 21 2023 at 02:03):

What goal does it leave behind?

Jeremy Tan (Mar 21 2023 at 02:04):

r: R
 starRingEquiv.toEquiv ((algebraMap R (FreeAlgebra R X)) r) = { unop := (algebraMap R (FreeAlgebra R X)) r }

Jeremy Tan (Mar 21 2023 at 02:04):

Adding rfl alone closes it, but by rfl itself also works

Eric Wieser (Mar 21 2023 at 02:04):

Did you restart lean after merging?

Eric Wieser (Mar 21 2023 at 02:05):

Does rewriting by my lemma work from that point?

Jeremy Tan (Mar 21 2023 at 02:05):

Yes, I closed VSCode and reopened it, I saw the infoview showing that recompiling was underway

Jeremy Tan (Mar 21 2023 at 02:06):

(Just restarted the server again, I'm still seeing an unsolved goal)

Adam Topaz (Mar 21 2023 at 02:06):

BTW, this works:

def liftFun {A : Type _} [Semiring A] [Algebra R A] (f : X  A) :
    Pre R X  A
  | .of t => f t
  | .mul a b => liftFun f a + liftFun f b
  | .add a b => liftFun f a * liftFun f b
  | .of_scalar c => algebraMap _ _ c

Eric Wieser (Mar 21 2023 at 02:06):

rw [RingEquiv.coe_toEquiv]?

Adam Topaz (Mar 21 2023 at 02:07):

modulo the error I introduced switching ++ and *.

Jeremy Tan (Mar 21 2023 at 02:07):

Eric Wieser said:

rw [RingEquiv.coe_toEquiv]?

doesn't work, even with the simp

Jeremy Tan (Mar 21 2023 at 02:08):

In fact it complains

tactic 'rewrite' failed, did not find instance of the pattern in the target expression

Eric Wieser (Mar 21 2023 at 02:08):

Do you see why I think it should work?

Jeremy Tan (Mar 21 2023 at 02:08):

Yes, because you said so

Eric Wieser (Mar 21 2023 at 02:08):

Take a look at the statement of the lemma and the statement of the goal

Jeremy Tan (Mar 21 2023 at 02:09):

They don't match at all

Eric Wieser (Mar 21 2023 at 02:10):

Both have a term of the form FunLike.coe (RingEquiv.toEquiv f)

Eric Wieser (Mar 21 2023 at 02:10):

You can disable the arrows in printing to make that clearer

Jeremy Tan (Mar 21 2023 at 02:11):

how to disable arrows?

Eric Wieser (Mar 21 2023 at 02:12):

set_option pp.coercions false maybe? I'm afraid I don't know, but autocomplete after pp. might

Eric Wieser (Mar 21 2023 at 02:12):

Or just click on the arrows to find out what they are

Jeremy Tan (Mar 21 2023 at 02:13):

Well after by simp [star_algebraMap] and with coercions not printed the goal is

FunLike.coe starRingEquiv.toEquiv (FunLike.coe (algebraMap R (FreeAlgebra R X)) r) =
  { unop := FunLike.coe (algebraMap R (FreeAlgebra R X)) r }

Jeremy Tan (Mar 21 2023 at 02:14):

Yes, there's FunLike.coe (RingEquiv.toEquiv f) on the LHS, but Lean's not getting it

Eric Wieser (Mar 21 2023 at 02:14):

My guess is that this is lean4#2074

Eric Wieser (Mar 21 2023 at 02:14):

Does set_option synth.etaExperiment true let the proof go through?

Eric Wieser (Mar 21 2023 at 02:16):

To be clear, your refl proof is fine in that PR (and an improvement over the old proof); but it would also be worth understanding the failure here

Jeremy Tan (Mar 21 2023 at 02:17):

No

Jeremy Tan (Mar 21 2023 at 02:17):

(but I'm getting another weird error in which when I do...)

Jeremy Tan (Mar 21 2023 at 02:18):

/-- `star` as an `AlgEquiv` -/
set_option synthInstance.etaExperiment true in
noncomputable def starHom : FreeAlgebra R X ≃ₐ[R] (FreeAlgebra R X)ᵐᵒᵖ :=
  { starRingEquiv with commutes' := fun r => by simp [star_algebraMap] }
#align free_algebra.star_hom FreeAlgebra.starHom

Eric Wieser (Mar 21 2023 at 02:18):

I'll have a look tomorrow

Jeremy Tan (Mar 21 2023 at 02:18):

(... I get expected 'abbrev', 'add_decl_doc', 'alias', 'axiom', 'binder_predicate', 'builtin_initialize', 'class', 'declare_config_elab', 'declare_simp_like_tactic', 'declare_syntax_cat', 'def', 'elab', 'elab_rules', 'example', 'inductive', 'infix', 'infixl', 'infixr', 'initialize', 'instance', 'irreducible_def', 'lemma', 'macro', 'macro_rules', 'notation', 'notation3', 'opaque', 'postfix', 'prefix', 'register_builtin_option', 'register_label_attr', 'register_option', 'register_simp_attr', 'scoped', 'structure', 'syntax', 'theorem' or 'unif_hint')

Jeremy Tan (Mar 21 2023 at 02:19):

Putting the set_option one line higher works though

Eric Wieser (Mar 21 2023 at 02:19):

As in, works completely?

Jeremy Tan (Mar 21 2023 at 02:20):

no, with the set_option one line higher, the original error still remains, but I don't get an error from the set_option

Jeremy Tan (Mar 21 2023 at 02:20):

The two different errors are independent

Jireh Loreaux (Mar 21 2023 at 03:26):

The error you were getting was because of the docstring. Docstring was looking for the def but instead saw set_option

Xavier Roblot (Mar 21 2023 at 07:15):

Eric Wieser said:

FreeAlgebra.lift shouldn't be non-computable

I am the one that ported FreeAlgebra. Last time I encountered a problem with recOn, the easy fix was to mark the definition as noncomputable, but I can see it is not the best option. Sorry about that.
I'll make a new PR today or tomorrow to remove the noncomputable I added in this file.

Reid Barton (Mar 21 2023 at 07:16):

There was some PR that automated the creation of compiled recursors, right? What's the status of that?

Xavier Roblot (Mar 21 2023 at 09:01):

I'll make a new PR today or tomorrow to remove the noncomputable I added in this file.

!4#3011
(Thanks Adam for the correct code!)

Jeremy Tan (Mar 21 2023 at 11:59):

@Eric Wieser I just merged the now-landed !4#3011 into my PR. Now neither rfl or anything described in this thread works. What do I do?

Eric Wieser (Mar 22 2023 at 10:18):

I'm having a look now

Eric Wieser (Mar 22 2023 at 10:19):

It turns out we were missing docs#ring_equiv.to_equiv_eq_coe, which is not a tautology in Lean4 after all (!4#3035)

Eric Wieser (Mar 22 2023 at 10:32):

I think the problem is that the new definition of lift uses brecOn on recOn

Eric Wieser (Mar 22 2023 at 10:34):

Eric Wieser said:

Right, the standard fix is to copy what I did with docs4#Nat.rec_eq_recC

So I think we should probably do this after all, instead of @Adam Topaz's suggestion

Eric Wieser (Mar 22 2023 at 10:58):

I misdiagnosed it; your proof fails because the irreducible attribute (which was previously lost in porting) has been restored

Jeremy Tan (Mar 22 2023 at 11:59):

OK, what now?

Eric Wieser (Mar 22 2023 at 12:27):

star_algebraMap should prove it directly

Eric Wieser (Mar 22 2023 at 12:27):

Or wait for !4#3035 then the original mathlib3 proof will work

Jeremy Tan (Mar 22 2023 at 15:15):

@Eric Wieser Well I've restored the original proof with the added-back simp theorems and it works now, thank you

Eric Wieser (Mar 23 2023 at 10:59):

!4#3035 is now passing CI


Last updated: Dec 20 2023 at 11:08 UTC