batteries icon indicating copy to clipboard operation
batteries copied to clipboard

Add specialized associative List folds

Open joehendrix opened this issue 1 year ago • 13 comments

This uses the associativity, commutativity and identity classes recently added to Lean core to define folds with simplification lemmas that can move intermediate results outside the fold for better use in tactics.

joehendrix avatar Jan 16 '24 05:01 joehendrix

Note that these classes in mathlib are deprecated and slated for removal; they were in lean 3 core as part of a refactor that never happened, and they are rarely used. I think we should add these on an as-needed basis.

digama0 avatar Jan 16 '24 11:01 digama0

I'm open to other approaches then reviving these classes, but it did seem like a way to get the monoid properties I wanted for writing fold/sum lemmas.

IsSymmOp isn't strictly needed but it seemed to naturally go with the other properties, and the associated Symm tactic is already in Std.

joehendrix avatar Jan 16 '24 19:01 joehendrix

Is the only reason not to use the Lean core classes that these classes are Prop?

fgdorais avatar Jan 16 '24 22:01 fgdorais

The associativity and commutative ones don't have a good reason. Perhaps I should use the Lean core versions. The Identity classes use an out parameter for the identity/neutral element.

joehendrix avatar Jan 16 '24 22:01 joehendrix

Maybe it would be better to add the missing outParam in core? Perhaps also make these classes Prop to avoid diamonds? This kind of PR to core can backfire in interesting ways but that would give more guidance what to do in Std.

Another option is to move ac_rfl to Std. That way we could more freely turn it into something more useful. It doesn't seem to be used in core at a quick glance.

[Edit: This was accidentally posted at the wrong place earlier.] I experimented with deleting ac_rfl from core and nothing seems to break: https://github.com/fgdorais/lean4/tree/ac_rfl

fgdorais avatar Jan 16 '24 23:01 fgdorais

I'm looking into both changing the core axioms and/or moving/removing ac_rfl.

If ac_rfl is removed from core, then technically the classes could live in Std. However, I think it's good for tactics that don't use Std (potentially so they can migrate to Std) to have a common classes for this.

joehendrix avatar Jan 17 '24 16:01 joehendrix

I'll revisit this when leanprover/lean4#3195 is merged.

joehendrix avatar Jan 19 '24 01:01 joehendrix

Let's make sure this has a Mathlib adaptation branch passing CI before we merge!

kim-em avatar Jan 29 '24 13:01 kim-em

I've changed the base of the PR to main, as it is now on v4.6.0-rc1 which includes the upstream changes. I've also set the lean-toolchain to v4.6.0-rc1 to resolve the conflict.

kim-em avatar Feb 05 '24 01:02 kim-em

@semorrison

Let's make sure this has a Mathlib adaptation branch passing CI before we merge!

I've started an adaptation branch here at leanprover-community/mathlib4#10336. It could use some help.

joehendrix avatar Feb 07 '24 17:02 joehendrix

All the prereqs are good now, so this could be merged soon.

fgdorais avatar Feb 16 '24 05:02 fgdorais

Looks like the only issue left is the to_additive problem in Mathlib. We need an expert to deal with that...

fgdorais avatar Feb 17 '24 00:02 fgdorais

This PR was marked will-merge-soon since Februrary 16, I removed that tag on July 20. Presumably something went wrong along the way... What is the current status of this PR?

fgdorais avatar Jul 21 '24 07:07 fgdorais