Zulip Chat Archive
Stream: general
Topic: norm_num is slow
Kenny Lau (Apr 12 2020 at 08:57):
import tactic set_option profiler true theorem test_norm_num : true := begin have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, have : nat.prime 13 := by norm_num, end
parsing took 1.41s elaboration of test_norm_num took 2.99s
Kenny Lau (Apr 12 2020 at 08:59):
for comparison:
import tactic set_option profiler true theorem test_ring : true := begin have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, have : ∀ n : ℤ, (n+1)^2=n^2+2*n+1 := λ n, by ring, trivial end
parsing took 1.09s elaboration of test_ring took 2.41s
Kenny Lau (Apr 12 2020 at 08:59):
so ok let's say norm_num
is an expensive tactic
Kenny Lau (Apr 12 2020 at 08:59):
but somehow it takes longer to parse than ring
Mario Carneiro (Apr 12 2020 at 08:59):
You can do better if you don't jump in and out of tactic mode so much
Kenny Lau (Apr 12 2020 at 09:00):
oh, I never knew that
Mario Carneiro (Apr 12 2020 at 09:00):
repeating have : nat.prime 13, norm_num,
has much better parsing performance for me
Kenny Lau (Apr 12 2020 at 09:00):
because I sometimes use rw show foo = bar, by norm_num
Mario Carneiro (Apr 12 2020 at 09:01):
It has to create a new context and run the tactic, get the result, and return to the original context
Kevin Buzzard (Apr 12 2020 at 09:01):
Are there some tips here? I do just the same as Kenny
Kenny Lau (Apr 12 2020 at 09:01):
import tactic set_option profiler true theorem test_norm_num : true := begin have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, have : nat.prime 13, norm_num, trivial end
parsing took 1.42s elaboration of test_norm_num took 2.47s
Kenny Lau (Apr 12 2020 at 09:01):
looks like it's the same
Mario Carneiro (Apr 12 2020 at 09:03):
I get a lot more reports with many uses of by
Mario Carneiro (Apr 12 2020 at 09:03):
that might be contributing to the timing
Kenny Lau (Apr 12 2020 at 09:03):
so what should we write instead of rw show foo = bar, by norm_num
?
Mario Carneiro (Apr 12 2020 at 09:05):
have foo = bar, {norm_num}, rw this
Mario Carneiro (Apr 12 2020 at 09:05):
but this seems like hair splitting level optimization
Kenny Lau (Apr 12 2020 at 09:07):
I think we can move on to another thread, because:
Last updated: Dec 20 2023 at 11:08 UTC