Zulip Chat Archive
Stream: mathlib4
Topic: olympiad problems with mathlib4
David Renshaw (Dec 06 2022 at 23:28):
I think we're at the point where we can try some simple olympiad problems with mathlib4, so I'm going to try that right now on stream: https://www.twitch.tv/dwrensha
Eric Wieser (Dec 06 2022 at 23:33):
Can mathport not translate this stuff for you?
David Renshaw (Dec 06 2022 at 23:34):
yeah, but that's less fun
Jason Rute (Dec 06 2022 at 23:54):
But can LeanAid (#lean4 > LeanAide translation: Natural language to Lean 4) translate it for you. That sounds fun!
David Renshaw (Dec 07 2022 at 00:24):
First problem: done!
https://github.com/dwrensha/math-puzzles-in-lean4/blob/5e87d4a793f9ec04846b63bdbbdd4ebe5c73f949/MathPuzzles/russia1998_q42.lean
David Renshaw (Dec 07 2022 at 00:26):
I at first had
variable (R : Type) [CommRing R] [NeZero (2:R)] [CancelMonoidWithZero R]
and that didn't work due to an error
application type mismatch
Iff.mp (mul_right_inj' ?m.7061) h2
argument
h2
has type
@HMul.hMul R R R (@instHMul R NonUnitalNonAssocRing.toMul) 2 x = 2 * a : Prop
but is expected to have type
@HMul.hMul R R R (@instHMul R MulZeroClass.toMul) 2 x = 2 * a : Prop
David Renshaw (Dec 07 2022 at 00:26):
but then when I did
class RealLike (R : Type) extends
CommRing R, NeZero (2:R), CancelMonoidWithZero R
variable (R : Type) [CommRing R] [NeZero (2:R)] [CancelMonoidWithZero R]
it worked.
David Renshaw (Dec 07 2022 at 00:27):
(I don't think this is a Lean 3 / Lean 4 difference, just something that I stumbled on when trying to mock out the real numbers)
David Renshaw (Jan 11 2023 at 00:01):
Tonight I'm going to try formalizing some MiniF2F problems with Mathlib4. https://www.twitch.tv/dwrensha
Heather Macbeth (Jan 11 2023 at 00:02):
Good luck! But I imagine mathlib4#1102 and mathlib4#1189 will be major obstacles ...
David Renshaw (Jan 11 2023 at 00:09):
yeah, I'm probably going to mostly stick to ints and nats
David Renshaw (Jan 11 2023 at 01:23):
We found a bug in one of the problems! https://github.com/openai/miniF2F/issues/125
Eric Wieser (Jan 11 2023 at 01:37):
miniF2F has many such problems, there was a thread about that elsewhere. Facebook's version fixes a small fraction of those.
David Renshaw (Jan 11 2023 at 01:39):
fwiw, this particular bug is not fixed on the Facebook fork: https://github.com/facebookresearch/miniF2F/blob/5271ddec788677c815cf818a06f368ef6498a106/lean/src/valid.lean#L57-L66
David Renshaw (Jan 25 2023 at 23:34):
Last night on twitch, I formalized another IMO problem with mathlib4, and today I cut the recording of the 2-hour session into a fast(er) paced 11-minute video: https://youtu.be/9d2nicgd68Q
David Renshaw (Jan 25 2023 at 23:35):
One interesting outcome was that I ran into this bug: https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/weird.20interaction.20between.20.60mod_cases.60.20and.20.60induction.60/near/323603044
Johan Commelin (Jan 26 2023 at 07:31):
Thanks! I enjoyed watching the video.
Sebastian Ullrich (Jan 26 2023 at 09:18):
Very nice. Would the obtain \<n, h\> := ...; cases n
pattern be covered by cases h : n
?
Sebastian Ullrich (Jan 26 2023 at 09:19):
(The obtain
by itself should be docs4#Lean.Parser.Tactic.generalize)
David Renshaw (Jan 26 2023 at 13:09):
Sebastian Ullrich said:
Very nice. Would the
obtain \<n, h\> := ...; cases n
pattern be covered bycases h : n
?
Yep, thanks! I was hoping someone might teach me the right way to do that.
Anand Rao (Jan 30 2023 at 17:03):
I enjoyed watching the video. With a slight rephrasing of the problem statement, I managed to golf the proof down to four lines. (I wonder if the n + 3
case can be golfed further to a single line using aesop
?)
import Mathlib.Data.Nat.Basic
import Mathlib.Algebra.GroupPower.Basic
theorem imo_1964_q1b : ∀ (n : ℕ), (2 ^ n + 1) % 7 ≠ 0
| 0 | 1 | 2 => by decide
| n + 3 => by
rw [pow_add, Nat.add_mod, Nat.mul_mod, show 2 ^ 3 % 7 = 1 from by rfl]
simp [imo_1964_q1b n]
Jannis Limperg (Jan 30 2023 at 17:06):
Probably not; Aesop is no better at equations than simp
. You can golf it by putting a semicolon between rw
and simp
. ;)
Kevin Buzzard (Jan 30 2023 at 17:12):
This is the canonical easy IMO problem :-) Even the AIs can solve tuff one! Although they take far more lines to do so :-)
David Renshaw (Jan 30 2023 at 17:32):
Anand Rao said:
I enjoyed watching the video. With a slight rephrasing of the problem statement, I managed to golf the proof down to four lines.
Cool! Care to submit a pull request? https://github.com/dwrensha/math-puzzles-in-lean4
Siddhartha Gadgil (Jan 31 2023 at 03:14):
@Jannis Limperg Since we are on this topic, @Anand Rao and I were discussing this: how do we add rw [blah]
as a tactic in an Aesop call/rule-set?
Anand Rao (Jan 31 2023 at 03:54):
David Renshaw said:
Anand Rao said:
I enjoyed watching the video. With a slight rephrasing of the problem statement, I managed to golf the proof down to four lines.
Cool! Care to submit a pull request? https://github.com/dwrensha/math-puzzles-in-lean4
Done: https://github.com/dwrensha/math-puzzles-in-lean4/pull/1.
Jannis Limperg (Jan 31 2023 at 11:42):
Siddhartha Gadgil said:
Jannis Limperg Since we are on this topic, Anand Rao and I were discussing this: how do we add
rw [blah]
as a tactic in an Aesop call/rule-set?
If you don't want the rewrite to be a simp
rule, this is currently the only way:
open Lean.Elab.Tactic in
@[aesop safe]
def myTactic : TacticM Unit := do
evalTactic $ ← `(tactic| rw [blah])
Admittedly not great. I'll try to come up with a better syntax for adding tactics.
Siddhartha Gadgil (Jan 31 2023 at 12:23):
Jannis Limperg said:
Siddhartha Gadgil said:
Jannis Limperg Since we are on this topic, Anand Rao and I were discussing this: how do we add
rw [blah]
as a tactic in an Aesop call/rule-set?If you don't want the rewrite to be a
simp
rule, this is currently the only way:open Lean.Elab.Tactic in @[aesop safe] def myTactic : TacticM Unit := do evalTactic $ ← `(tactic| rw [blah])
Admittedly not great. I'll try to come up with a better syntax for adding tactics.
Thanks. So I take it for now it should be a single named tactic, not one with parameters.
Jannis Limperg (Jan 31 2023 at 12:34):
The rw [blah]
from my example works if blah
is a defined constant. It could also work for hypotheses if Aesop had some syntax to support it. If you mean adding just rw
and letting it figure out that it should rewrite with each hypothesis or something along those lines, that's probably not going to be supported.
Siddhartha Gadgil (Jan 31 2023 at 12:54):
Our goal is to call Aesop programmatically with a bunch of rules, some of which are specific instances of rw. So an API is fine
Siddhartha Gadgil (Jan 31 2023 at 12:59):
Essentially do a search with Aesop with a large number of rules which the indexing makes cheap and a small number of more carefully chosen tactics, mainly insurances of rw with specified parameters
Jannis Limperg (Jan 31 2023 at 17:34):
In that case you probably want to be going through the MetaM
-level API. The entrypoint is search
and you'd want to pass a custom rule set. There's not much documentation (and not much thought has gone into this use case) but I'll be happy to help.
David Renshaw (Feb 03 2023 at 05:12):
This week I formalized IMO 1964 Q4, a combinatorics problem: https://www.youtube.com/watch?v=TOzS4aC_K1g
Kevin Buzzard (Feb 03 2023 at 06:58):
Are you doing these things at a regular weekly time?
David Renshaw (Feb 03 2023 at 12:35):
I've been doing ~7pm Pittsburgh local time on Tuesdays.
David Renshaw (Feb 03 2023 at 12:35):
Admittedly not a very Europe-friendly time.
Last updated: Dec 20 2023 at 11:08 UTC