-
Notifications
You must be signed in to change notification settings - Fork 835
feat(Positivity): add support for positivity [h₁, h₂]
syntax
#30388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HugLycan
wants to merge
17
commits into
leanprover-community:master
Choose a base branch
from
HugLycan:feat/positivity-with-hyps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+22
−2
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d0f4c1e
feat: add support for `positivity [h₁, h₂]` syntax
HugLycan 79df7ee
Merge branch 'master' into feat/positivity-with-hyps
HugLycan 7026c48
Merge branch 'leanprover-community:master' into feat/positivity-with-…
HugLycan 0e2adb3
Merge branch 'leanprover-community:master' into feat/positivity-with-…
HugLycan a68f22c
add doc-strings to `positivity [_,,]`
HugLycan 7c36ff8
Merge branch 'feat/positivity-with-hyps' of https://github.com/HugLyc…
HugLycan 1c67d0f
Merge branch 'master' into feat/positivity-with-hyps
HugLycan eb0e068
Merge branch 'master' into feat/positivity-with-hyps
HugLycan 12a540e
just make it nicer
HugLycan e30f668
Merge branch 'feat/positivity-with-hyps' of https://github.com/HugLyc…
HugLycan 4a78394
Merge branch 'master' into feat/positivity-with-hyps
HugLycan b81ce6a
Update MathlibTest/positivity.lean
HugLycan c293b26
Update Core.lean
HugLycan 71bf2ed
Update Mathlib/Tactic/Positivity/Core.lean
HugLycan 3b8b131
Merge branch 'master' into feat/positivity-with-hyps
HugLycan 30532c2
update `positivity []`
HugLycan 1387869
Merge branch 'master' into feat/positivity-with-hyps
HugLycan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -491,18 +491,30 @@ according to the syntax of the expression `x`, if the atoms composing the expres | |||||||||||||||
numeric lower bounds which can be proved positive/nonnegative/nonzero by `norm_num`. This tactic | ||||||||||||||||
either closes the goal or fails. | ||||||||||||||||
`positivity [t₁, …, tₙ]` first executes `have := t₁; …; have := tₙ` in the current goal, | ||||||||||||||||
then runs `positivity`. This is useful when `positivity` needs derived premises such as `0 < y` | ||||||||||||||||
for division/reciprocal, or `0 ≤ x` for real powers. | ||||||||||||||||
Examples: | ||||||||||||||||
``` | ||||||||||||||||
example {a : ℤ} (ha : 3 < a) : 0 ≤ a ^ 3 + a := by positivity | ||||||||||||||||
example {a : ℤ} (ha : 1 < a) : 0 < |(3:ℤ) + a| := by positivity | ||||||||||||||||
example {b : ℤ} : 0 ≤ max (-3) (b ^ 2) := by positivity | ||||||||||||||||
example {a b c d : ℝ} (hab : 0 < a * b) (hb : 0 ≤ b) (hcd : c < d) : | ||||||||||||||||
0 < a ^ c + 1 / (d - c) := by | ||||||||||||||||
positivity [sub_pos_of_lt hcd, pos_of_mul_pos_left hab hb] | ||||||||||||||||
``` | ||||||||||||||||
-/ | ||||||||||||||||
elab (name := positivity) "positivity" : tactic => do | ||||||||||||||||
liftMetaTactic fun g => do Meta.Positivity.positivity g; pure [] | ||||||||||||||||
syntax (name := positivity) "positivity" (" [" term,* "]")? : tactic | ||||||||||||||||
|
||||||||||||||||
elab_rules : tactic | ||||||||||||||||
| `(tactic| positivity $[[]]?) => liftMetaTactic fun g => do Meta.Positivity.positivity g; pure [] | ||||||||||||||||
|
||||||||||||||||
macro_rules | ||||||||||||||||
| `(tactic| positivity [$h,*]) => `(tactic| · ($[have := $h];*); positivity) | ||||||||||||||||
end Positivity | ||||||||||||||||
Comment on lines
+516
to
518
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies, github ate this newline. :)
Suggested change
|
||||||||||||||||
|
||||||||||||||||
end Mathlib.Tactic | ||||||||||||||||
|
fpvandoorn marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad, I should have been less ambiguous: I only meant to test the behavior of
positivity []
in the test file, not test for the case of[]
in this syntax! :) (And I see you've added that test, so thanks!)So, we are indeed okay with
The reason why this is okay after the earlier suggestion to use
· ($[have := $h];*); positivity
instead of· $[have := $h];*; positivity
is indeed unintuitive; I'll explain it in a bit more depth here. :)Writing
· (); positivity
directly in source, e.g.example : 0 ≤ 0 := by · (); positivity
is indeed not parsed as we'd want it to be. This is due to how tactic sequences are parsed, and the parser avoids parsing an empty tactic sequence in this context.But macro_rules take
Syntax
toSyntax
(the result of parsing). We're defining the outcome of our macro rule using syntax quotations (`()
), which do their parsing at elaboration time, i.e. in this file, before themacro_rule
is even registered and sent off to be used.So the parsing of
`(tactic| · ($[have := $h];*); positivity)
intoSyntax
is already complete before the rule is recorded, and this syntax is sufficiently structured to know that a tactic sequence is what will end up inside()
. When we apply this macro rule later, it will happily insert the tactic sequence$[have := $h];*
inside the abstract syntax for()
—even if that sequence is empty.Parsing into
Syntax
was what was preventing the source code version of· (); positivity
from working, but we've gotten through that step by the time we apply a macro_rule. :)(It's very verbose, but you could write
to see the definition it creates—not to read the individual parts, but just to see that the rule we've actually recorded is really a bunch of
Syntax
, not source code.)Also, for some peace of mind that this is what's going on, you can write
and see that even when matching
[]
in theelab_rules
, we loggot none
(instead ofgot some []
). The macro gets there first. :)This is a bit of a crash course, so I've rushed through some things. Feel free to tag or DM me (Thomas Murrills) on Zulip if you have any more questions; as might be apparent, I really enjoy talking about metaprogramming, so I'd be happy to answer them. :)