Zulip Chat Archive
Stream: lean4
Topic: PANIC at Lean.Expr.appArg! application expected
Floris van Doorn (Aug 07 2024 at 07:45):
When updating the Carleson project to the latest version, I get a few hundred panics, both in CI and locally:
PANIC at Lean.Expr.appArg! Lean.Expr:896:15: application expected
See e.g. the Build Project
step in this run: https://github.com/fpvandoorn/carleson/actions/runs/10279969927/job/28446338121
It seems to be related to docs#Nat.reducePow
Jeremy Tan (Aug 07 2024 at 08:47):
It probably has to do with simps and simpas. Apply the following diff to my PR https://github.com/fpvandoorn/carleson/pull/109 and run lake build Carleson.Defs
; there will be no panic
Jeremy Tan (Aug 07 2024 at 08:47):
diff --git a/Carleson/Defs.lean b/Carleson/Defs.lean
index 320f371..c70e04f 100644
--- a/Carleson/Defs.lean
+++ b/Carleson/Defs.lean
@@ -471,13 +471,13 @@ lemma Θ.finite_and_mk_le_of_le_dist {x₀ : X} {r R : ℝ} {f : Θ X} {k : ℕ}
simp_rw [Cardinal.mk_fintype, Finset.coe_sort_coe, Fintype.card_coe]
norm_cast
classical calc
- _ = ∑ _ ∈ 𝓩, 1 := by simp
+ _ = ∑ _ ∈ 𝓩, 1 := by rw [Finset.sum_const, smul_eq_mul, mul_one]
_ ≤ ∑ u ∈ 𝓩, (g u).card := Finset.sum_le_sum fun z hz ↦ Finset.card_pos.mpr (g_ne z hz)
_ = (𝓩.biUnion g).card := (Finset.card_biUnion (fun z hz z' hz' ↦ g_pd hz hz')).symm
_ ≤ 𝓩'.card := by
refine Finset.card_le_card fun _ h ↦ ?_
rw [Finset.mem_biUnion] at h
- exact Finset.mem_of_subset (by simp [g]) h.choose_spec.2
+ exact Finset.mem_of_subset (by simp only [Finset.filter_subset, g]) h.choose_spec.2
_ ≤ (2 ^ a) ^ k := c𝓩'
_ ≤ _ := by rw [C2_1_1, mul_comm, pow_mul]
@@ -487,4 +487,4 @@ lemma Θ.card_le_of_le_dist {x₀ : X} {r R : ℝ} {f : Θ X} {k : ℕ}
Nat.card 𝓩 ≤ C2_1_1 k a := by
obtain ⟨f𝓩, c𝓩⟩ := finite_and_mk_le_of_le_dist h𝓩 h2𝓩
lift 𝓩 to Finset (Θ X) using f𝓩
- simpa using c𝓩
+ simpa only [Nat.card_eq_fintype_card, Cardinal.mk_fintype, Nat.cast_le] using c𝓩
Jeremy Tan (Aug 07 2024 at 08:48):
But revert any one of the three changes and a panic will appear. Even more tellingly, running simp(a)?
on the three simp(a)
s in question suggests the useless lemma defaultA
in each case
Jeremy Tan (Aug 07 2024 at 08:54):
Attached is the panic obtained by leaving out the first change
panic-out.txt
Sebastian Ullrich (Aug 07 2024 at 09:22):
Is it possible the subterm matching (_ ^ _ : Nat)
is merely defeq to hPow applied to two arguments but not structurally so?
Jeremy Tan (Aug 07 2024 at 09:26):
@Sebastian Ullrich here's the smallest I've got the panic to so far
import Mathlib.Data.Finset.Card
class CompatibleFunctions (X : ℕ) (A : outParam ℕ) where
Θ : Type*
export CompatibleFunctions (Θ)
@[simp] abbrev defaultA (a : ℕ) : ℕ := 2 ^ a
variable {X : ℕ} [CompatibleFunctions X (defaultA 4)]
/-- PANIC -/
lemma Θ.panic {𝓩 : Finset (Θ X)} : 𝓩.card = 𝓩.card * 1 := by simp
Jeremy Tan (Aug 07 2024 at 09:27):
If you change the abbrev
to def
the panic goes away
Jeremy Tan (Aug 07 2024 at 09:29):
Or Finset
to List
(and card
to length
), or ^
to *
Sebastian Ullrich (Aug 07 2024 at 09:35):
Thanks, that matches my hypothesis exactly
Jeremy Tan (Aug 07 2024 at 09:39):
Simpler:
import Mathlib.Data.Multiset.Basic
class G (A : outParam ℕ) where Z : Type*
export G (Z)
@[simp] abbrev f (a : ℕ) : ℕ := 2 ^ a
variable [G (f 1)]
example {s : Multiset Z} : Multiset.card s = Multiset.card s := by simp
Jeremy Tan (Aug 07 2024 at 09:40):
The panic now goes away upon changing 1
to 0
Eric Wieser (Aug 07 2024 at 09:56):
Looks like a missing unless e.isAppOfArity declName arity do return .continue
, which is present on the other binary operator reductions
Henrik Böving (Aug 07 2024 at 10:03):
I guess doing a let_expr
based match would be fine as well.
Jeremy Tan (Aug 07 2024 at 10:22):
Eric Wieser said:
Looks like a missing
unless e.isAppOfArity declName arity do return .continue
, which is present on the other binary operator reductions
but where would that go in the lean4 repo?
Eric Wieser (Aug 07 2024 at 10:25):
On the first line of Nat.reducePow
, to match Nat.reduceBin
Eric Wieser (Aug 07 2024 at 10:27):
Henrik Böving said:
I guess doing a
let_expr
based match would be fine as well.
Or let ~q()
:wink:
Jeremy Tan (Aug 07 2024 at 13:19):
Yeah, I've got an #mwe
universe u
class G (A : outParam Nat) where Z : Type u
export G (Z)
abbrev f (a : Nat) : Nat := 2 ^ a
variable [G (f 0)]
example {s : Z} : s = s := by simp only [Nat.reducePow]
Jeremy Tan (Aug 07 2024 at 14:11):
Filed at https://github.com/leanprover/lean4/issues/4947
Jeremy Tan (Aug 07 2024 at 15:44):
It sure seems to me that this is a regression from lean4#4637
Matthew Ballard (Aug 07 2024 at 15:52):
Eric Wieser said:
Looks like a missing
unless e.isAppOfArity declName arity do return .continue
, which is present on the other binary operator reductions
Indeed this fixes it.
Jeremy Tan (Aug 08 2024 at 09:18):
Matthew Ballard said:
Indeed this fixes it.
I tried fixing it myself. I couldn't find the right line to put that
Matthew Ballard (Aug 08 2024 at 09:19):
Matthew Ballard (Aug 08 2024 at 09:19):
Then you probably want to a make your example into a test that fails before the fix and passes afterwards
Jeremy Tan (Aug 08 2024 at 09:22):
declName
and arity
don't appear in the variables
Matthew Ballard (Aug 08 2024 at 09:25):
You need to specialize them to the existing situation HPow.hPow and 6
Jeremy Tan (Aug 08 2024 at 11:05):
Matthew Ballard said:
You need to specialize them to the existing situation HPow.hPow and 6
I added a file 9999.lean
to lean4/tests/lean
with my example but how do I run it?
Jeremy Tan (Aug 08 2024 at 11:06):
Which directory do I have to be in and what command must I give
Jeremy Tan (Aug 08 2024 at 11:07):
wait...
Kim Morrison (Aug 08 2024 at 23:54):
@Jeremy Tan see https://lean-lang.org/lean4/doc/dev/testing.html for running tests.
Kim Morrison (Aug 08 2024 at 23:55):
(If you find problems in the test docs please let us know!)
Jeremy Tan (Aug 09 2024 at 01:51):
(deleted)
Jeremy Tan (Aug 09 2024 at 02:35):
@Kim Morrison I've got a diff ready. Should I fork and PR or have you accept me into the lean4 org and then PR?
Jeremy Tan (Aug 09 2024 at 02:37):
Jeremy Tan (Aug 09 2024 at 02:57):
how should I title my PR anyway?
Jeremy Tan (Aug 09 2024 at 03:05):
@Kim Morrison https://github.com/leanprover/lean4/pull/4968
Jeremy Tan (Aug 09 2024 at 04:01):
Should I rebase onto nightly-with-mathlib? OK, rebased
Jeremy Tan (Aug 09 2024 at 04:10):
Is there anything I have done wrong with my PR?
Sebastian Ullrich (Aug 09 2024 at 07:15):
@Jeremy Tan Looks good to me. Could you move the test into run/? Then you don't need the empty expected
file
Jeremy Tan (Aug 09 2024 at 09:10):
Sebastian Ullrich said:
Jeremy Tan Looks good to me. Could you move the test into run/? Then you don't need the empty
expected
file
done
Eric Wieser (Aug 09 2024 at 09:25):
Jeremy Tan said:
It sure seems to me that this is a regression from lean4#4637
I left some comments on this PR; it's not clear to me that this is effective at preventing blowups on large powers
Jeremy Tan (Aug 09 2024 at 10:32):
Anyway I tried the rebase command suggested but still no Batteries/mathlib CI
Kim Morrison (Aug 10 2024 at 01:23):
I will try to have a look at the CI next week. My first guess is that we are running into GitHub API rate limits. This has been a known problem (not specific to this step, but all over our infrastructure) for a couple of weeks now.
Jeremy Tan (Aug 10 2024 at 04:50):
@Floris van Doorn For now I have silenced the panics in my https://github.com/fpvandoorn/carleson/pull/109 by adding attribute [-simp] Nat.reducePow
at the start of 9 files
Jeremy Tan (Aug 10 2024 at 04:54):
Eric Wieser said:
I left some comments on this PR; it's not clear to me that this is effective at preventing blowups on large powers
Do you have code where it still blows up on large powers?
Kim Morrison (Aug 12 2024 at 00:46):
@Jeremy Tan, you aren't meant to change the PR target to nightly-with-mathlib
(as you did, and Sebastian changed back), but rather rebase using git rebase -i origin/nightly-with-mathlib
. Could you try this?
Jeremy Tan (Aug 12 2024 at 06:52):
@Kim Morrison I did that, but Leo has already pushed a fix (lean4#4988)
Jeremy Tan (Aug 12 2024 at 07:05):
The tag is still not showing up in mathlib
Kim Morrison (Aug 12 2024 at 11:06):
Jeremy Tan said:
The tag is still not showing up in mathlib
What do you mean?
Jeremy Tan (Aug 13 2024 at 11:07):
@Kim Morrison OK, I think I've got it right with lean4#5011
Jeremy Tan (Aug 13 2024 at 12:31):
then why did I get this out of the blue failure? https://github.com/leanprover/lean4/actions/runs/10368758759/job/28703042712
Joachim Breitner (Aug 13 2024 at 12:32):
This happens ocasionally, haven’t debugged yet when this happens. You can ignore it, not your PR’s fault. Maybe something with github rate limits or so.
Jeremy Tan (Aug 13 2024 at 12:32):
jq: error (at <stdin>:5): Cannot index string with string "body"
Joachim Breitner (Aug 13 2024 at 12:40):
This is from
existing_comment="$(curl -L -s -H "Authorization: token ${{ secrets.MATHLIB4_BOT }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/leanprover/lean4/issues/${{ steps.workflow-info.outputs.pullRequestNumber }}/comments" \
| jq 'first(.[] | select(.body | test("^- . Mathlib") or startswith("Mathlib CI status")) | select(.user.login == "leanprover-community-mathlib4-bot"))')"
existing_comment_id="$(echo "$existing_comment" | jq -r .id)"
existing_comment_body="$(echo "$existing_comment" | jq -r .body)"
and I have been staring at this point wondering how in echo "$existing_comment" | jq -r .body
it can be that jq
receives a string literal (and not either a json object or nothing). :shrug:
Maybe I should add some debugging output there
Eric Wieser (Aug 13 2024 at 12:41):
Maybe rate limits are returned as a single string?
Henrik Böving (Aug 13 2024 at 12:44):
Yeah we've been seeing rate limits on the mathlib4 community bot in a lot of runs recently @Joachim Breitner
Last updated: May 02 2025 at 03:31 UTC