Zulip Chat Archive

Stream: lean4

Topic: mkSimpAttr


Simon Hudon (Dec 27 2021 at 17:26):

In Lean 3, we have a meta function to create a customized simp attribute. Does that exist in Lean 4 already?

Gabriel Ebner (Dec 27 2021 at 17:26):

registerSimpAttr

Simon Hudon (Dec 27 2021 at 17:28):

Thanks!

Simon Hudon (Dec 27 2021 at 17:29):

Follow-up: I noticed something called preprocess and postprocess with simp. Does that mean that we can create our own pre / postprocessing functions, a bit like reassoc in mathlib / category theory?

Gabriel Ebner (Dec 27 2021 at 17:32):

rg -i postprocess src doesn't return anything, can you be more specific?

Gabriel Ebner (Dec 27 2021 at 17:33):

Big-picture wise nothing has changed. We still don't have simpprocs.

Gabriel Ebner (Dec 27 2021 at 17:33):

You can still write your own simplifiers, with blackjack and simpprocs.

Simon Hudon (Dec 27 2021 at 17:34):

What are blackjack and simpprocs?

Gabriel Ebner (Dec 27 2021 at 17:36):

Blackjack is a form of gambling. Simpprocs are a feature in the Isabelle simplifier, which allows you to register -- in the same way as simp lemmas -- functions that are executed during simplification.

Gabriel Ebner (Dec 27 2021 at 17:36):

The combination just means "with whatever features you want".

Patrick Massot (Dec 27 2021 at 17:37):

Standard link: https://github.com/leanprover/lean/wiki/Simplifier-Features

Johan Commelin (Dec 27 2021 at 17:39):

Standard link: https://en.wikipedia.org/wiki/Blackjack

Simon Hudon (Dec 27 2021 at 17:48):

Specifically, what I was referring to are ↑ ↓ in the syntax of simp attributes

Gabriel Ebner (Dec 27 2021 at 18:30):

Ah those. To be honest, today is the first time I've seen them. They allow you to specify if a simp lemma is applied before recursing into the arguments, or afterwards. (Default is post, for pre-lemmas you need to be super super careful not to run into confluence issues.) The pre/post-flag can't be used for anything like reassoc.

Simon Hudon (Dec 27 2021 at 18:36):

:+1:

Simon Hudon (Dec 27 2021 at 18:42):

I'm thinking about how reassoc could be redesigned so that we don't have to mark lemmas as reassoc. What I'm thinking of is that I'd create an additional simp attribute to use with a customized simp tactic. In that cache, I'd put all the simp lemmas but also their reassoc version as well. The reassoc versions would be created when the cache is updated and for the lemmas that you list as arguments to simp. Does that seem like a reasonable design to you?

Gabriel Ebner (Dec 27 2021 at 18:55):

I don't think a custom simp tactic is a good idea. The whole point of reassoc is to automate writing simp lemmas for the default simp tactic, not to add yet another tactic.

Gabriel Ebner (Dec 27 2021 at 18:56):

BTW, if you add @[simp] to a lemma like foo : a ↔ b, then Lean 4 will declare a helper lemma foo_aux : a = b and add that to the simp extension instead. So I think it's perfectly fine to have reassoc add helper lemmas as well.

Simon Hudon (Dec 27 2021 at 19:05):

The idea is that reassoc is not the only feature that needs to create buddy lemmas. In mathlib, there's also higher_order which creates point-free formulations which are very useful when working with Functor, Foldable and Traversable. I'd like to be able to declare once that reassoc lemmas are useful, point-free lemmas are useful and so on if necessary rather than going around tagging every possible lemma with both attributes. I think with a custom version of simp, you can create a scoped macro and have the same syntax as simp (down to the name) and the whole device can be made invisible

Simon Hudon (Dec 27 2021 at 19:06):

Gabriel Ebner said:

BTW, if you add @[simp] to a lemma like foo : a ↔ b, then Lean 4 will declare a helper lemma foo_aux : a = b and add that to the simp extension instead. So I think it's perfectly fine to have reassoc add helper lemmas as well.

Do you think the same machinery could be highjacked to create our own companion lemmas?


Last updated: Dec 20 2023 at 11:08 UTC