Skip to content

WIP: experimenting with HPow as a right action and HSMul as a left action#6852

Closed
kmill wants to merge 18 commits intomasterfrom
kmill_binop2_test
Closed

WIP: experimenting with HPow as a right action and HSMul as a left action#6852
kmill wants to merge 18 commits intomasterfrom
kmill_binop2_test

Conversation

@kmill
Copy link
Copy Markdown
Contributor

@kmill kmill commented Aug 29, 2023

This is experimenting with some changes to the unary/binary operation elaborator that aim to address lean4#2220

It adds two variants of binop%: leftact% and rightact%. Whereas binop% looks at both arguments when doing its coercion computations, leftact% only looks at the right argument and rightact% only looks at the left.

Exponentiation is best thought of as being a right action. For example, in 2 ^ n + x with x : Real and n : Nat, then this should leave n as a Nat but elaborate 2 as a Real (this is the monoid action of Nat on Real).

The main changes to mathlib that are needed are using (a ^ b :) to essentially switch to the local macro_rules solution for the given expression, using ↑(a ^ b) if it's more convenient, or giving type ascriptions to the exponent, like in a ^ (2 : Ordinal).


Open in Gitpod

@kmill kmill added the WIP Work in progress label Aug 29, 2023
open Parser

/-- Left action; the right argument can participate in the operator coercion elaborator. -/
syntax (name := leftact) "leftact% " ident ppSpace term:max ppSpace term:max : term
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to not generate a quot_precheck. If this gets moved to core this shouldn't matter; builtin_term_parser seems to generate one for binop% just fine?


namespace Polynomial

set_option maxHeartbeats 65000 in
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the type ascriptions in this are not actually necessary. My guess is that since binop2.lean is interpreted code instead of compiled code it's consuming a whole lot of heartbeats. The type ascriptions help reduce the number of heartbeats.

@kmill kmill changed the title WIP: experimenting with HPow as a right action WIP: experimenting with HPow as a right action and HSMul as a left action Aug 30, 2023
@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 6, 2023
@YaelDillies
Copy link
Copy Markdown
Contributor

This just saved me a huge amount of manual type-ascription insertions in porting LeanAPAP. How far are we from merging?

@bors bors bot changed the base branch from master to ScottCarnahan/BinomialRing2 September 17, 2023 03:26
@kim-em kim-em changed the base branch from ScottCarnahan/BinomialRing2 to master September 17, 2023 12:11
@kmill
Copy link
Copy Markdown
Contributor Author

kmill commented Nov 18, 2023

The binop changes were merged into Lean and updated versions of these fixes were merged into master, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants