← Session 33 — ii′-3b/3c crux + F-D finding; Lagarias letter package
thinking (11294 chars)
Reproduced with `rw [RectangleBorder] at hs` then rcases. The failing equation: `Real.add✝ (↑(2√n)).re (↑T·I).re = s.1`. Now I read it correctly: `Real.add (↑(2√n)) (↑T·I)).re = s.1` — i.e. `re(↑(2√n) + ↑T·I) = s.1` where s.1 is... `s.1` = Prod.fst s?! But s : ℂ... OH WAIT — I bet `s.1` here is `s.re` — no — the equation `Real.add✝ (↑(2 * √↑n)).re (↑T * I).re = s.1`: parsing precedence: `(Real.add✝ (↑(2 * √↑n))).re` — no...
Let me think differently: maybe it's `Real.add✝ (↑(2√n)).re ((↑T * I).re) = s.1`: re(↑(2√n)) + re(↑T·I) = s.1 — and s.1 = s.re (Complex is a structure with field re — s.1 IS s.re via structure projection notation!). And `re(↑(2√n)) + re(↑T·I)` — the add_re of w.re! So the equation is `re(w) = s.re` expanded via add_re to `re(↑(2√n)) + re(↑T·I) = s.re`?? — hmm no wait — w.re = re(↑(2√n) + ↑T·I) — and add_re: re(a+b) = re a + re b — but re(↑(2√n) + ↑T·I) as a TERM is `Complex.add (↑(2√n)) (↑T·I) |>.re` — displaying as `Real.add✝ (↑(2√n)).re (↑T·I).re`?? The `Real.add✝` — hmm, Complex.add vs Real.add confusion: `Real.add✝ (↑(2√n)).re (↑T·I).re` — that's REAL addition of re(2√n) and re(T·I).
So the Eq: re(↑(2√n)) + re(↑T·I) = s.re. Where does this come from? The singleton {w.re} membership gives s.re = w.re. But here it's w.re EXPANDED: re(2√n) + re(T·I) — that's NOT w.re as a term (w.re = re(↑(2√n) + ↑T·I) — the .re OUTSIDE). Unless the elaborator normalized re(a+b) → re a + re b?? No, that's a simp lemma, not defeq... Actually `Complex.add_re : (x + y).re = x.re + y.re` — is it rfl? For ℂ, add is defined componentwise: (a + b).re = a.re + b.re — DEFINITIONALLY rfl! So re(w) = re(↑(2√n)) + re(↑T·I) DEFINITIONALLY. So the singleton Eq s.re = w.re is defeq to s.re = re(↑(2√n)) + re(↑T·I). And re(↑(2√n)) = ↑(2√n) (ofReal_re — defeq? ↑r = ⟨r, 0⟩: re = r definitionally ✓) and re(↑T·I) = re(↑T)·re(I) − im(↑T)·im(I) = T·0 − 0·1 = 0 definitionally? ↑T * I = ⟨T,0⟩·⟨0,1⟩ = ⟨T·0−0·1, T·1+0·0⟩ = ⟨0, T⟩: re = 0 definitionally ✓. So the Eq s.re = re(↑(2√n)) + re(↑T·I) is defeq to s.re = 2√n + 0 = 2√n.
Now — cases on this Eq: `s.re = re(↑(2√n)) + re(↑T·I)` — dependent elimination tries to solve `Eq.refl : re(↑(2√n)) + re(↑T·I) = s.1`?? — hmm the ERROR equation has the sides FLIPPED vs mine: `Real.add... = s.1` — so cases is proving the goal by eliminating the Eq h : s.re = ... hmm — but WHY does cases try to eliminate it at all, rather than keeping it as a hypothesis?
AH — I think I finally get it: `cases`/`subst` on Eq h : a = b: Lean tries `Eq.rec` — it abstracts the motive over b (or a): if b is a VARIABLE, fine; if b is NOT a variable, it tries to generalize the goal over b — and then needs `Eq.refl : b = b'` to typecheck the eliminated goal — wait no. `subst h` requires one side to be a free variable. `cases h` on Eq: it does `Eq.casesOn` — which requires the equation to be provable by refl after unification — i.e., it UNIFIES the two sides (with the equation's LHS/RHS as patterns against themselves)... no — `cases h` on h : @Eq α a b: it elaborates to `Eq.rec` with indices a, b unified: succeeds iff a and b are defeq (with the local context's metavariates assigned). If not defeq: "dependent elimination failed: failed to solve equation a = b at case Eq.refl". So cases on Eq with non-defeq sides ALWAYS fails. rcases on a hypothesis of Eq TYPE attempts cases → fails on non-defeq Eq.
But then WHY did my earlier Scratch test with the singleton {(5:ℝ)} PASS?! `rcases h with h1` on s.re ∈ {5}: the membership s.re = 5 — cases on it: sides s.re vs 5 — NOT defeq — should fail the same way... unless rcases DOESN'T destructure the singleton membership (leaves it as an Eq hypothesis without cases-ing it). And in the border case it DID try to cases it — the difference: in the border case, the Eq is s.re = re(↑(2√n)) + re(↑T·I) — hmm.
Wait — maybe the difference: in my Scratch test, `rcases h with h1` on `s.re ∈ ({(5 : ℝ)} : Set ℝ)` — rcases destructured the SET MEMBERSHIP — Set.singleton membership: is it an Eq? Set.singleton a = {x | x = a}? Set membership in a setOf is defeq to the predicate — s.re = 5 — rcases on an Eq... and it PASSED. So rcases did NOT cases the Eq there. But in the border case it DID cases something. The difference must be that in the border case the Eq has the form `Real.add X Y = s.1` where `s.1` — hmm, `s.1` — s is ℂ, s.1 = s.re — hmm.
OK you know what — let me just look at what the border pieces elaborate to and handle each piece WITHOUT rcases on the union: destruct the union with Set.mem_union.mp manually:
```lean
rw [RectangleBorder] at hs
-- hs : s ∈ A ∪ B ∪ C ∪ D
rcases Set.mem_union _ _ hs with hb | hb3
· rcases Set.mem_union _ _ hb with hb | hb2
· -- bottom: s ∈ [[z.re, w.re]] ×ℂ {z.im}
have him : s.im = z.im := hb.2 -- hb.2 : s.im ∈ {z.im} — defeq to s.im = z.im
...
```
hb.2 : s.im ∈ {z.im} — as a TERM its type displays as s.im ∈ {z.im}, defeq to s.im = z.im. `have him : s.im = z.im := hb.2` — defeq assignment ✓ no cases! And hb.1 : s.re ∈ [[z.re, w.re]] (uIcc membership — keep as is ✓).
So the fix: destructure the union via Set.mem_union.mp (or rcases with hb | hb — which worked in my second Scratch test? no — the second test had rw [RectangleBorder] then rcases with hb | hb | hb | hb and FAILED). Wait — but the FIRST scratch test (no rw) also failed at the rcases. So rcases on the union is what cases-es... no wait — the failing equation is about w.re = s.1 — the RIGHT piece. rcases on the union recurses into everything: the right piece's singleton Eq s.re = w.re gets cases'd → fail. But my isolated right-piece test `rcases hs with ⟨h1, h2⟩` PASSED — there, h1 : s.re ∈ {w.re} is destructured... and it passed?! The difference: in the isolated test, the singleton's element is `(((2 * Real.sqrt n : ℝ) : ℂ) + (T : ℝ) * Complex.I).re` — re OUTSIDE — the Eq s.re = (↑(2√n) + ↑T·I).re — cases on it: RHS = (↑(2√n) + ↑T·I).re — hmm that's also non-defeq vs s.re... but it PASSED. And in the border-union case, the singleton displays as Real.add of the re's — DIFFERENT FORM! In the union case, `Set.mem_union` normalization must have rewritten re(↑(2√n) + ↑T·I) to re(↑(2√n)) + re(↑T·I) (via add_re being defeq?? add_re IS defeq rfl — so the elaborator unfolded it during rcases' whnf). And then cases on `s.re = re(↑(2√n)) + re(↑T·I)`: RHS is an ADD — and `cases` on Eq with an add RHS... hmm still should fail the same way.
Wait wait — maybe the failure is NOT the Eq-cases at all. `s.1` — where does a .1 come from?? s : ℂ. s.1 = s.re. The Eq after add_re expansion: s.re = re(2√n) + re(T·I). cases on Eq: tries Eq.rec — unify `s.re` with `re(2√n) + re(T·I)`: NOT defeq (both proper terms) → fail "Failed to solve equation re(2√n)+re(T·I) = s.1" ✓ consistent.
In the isolated right-piece test: the Eq is s.re = (↑(2√n) + ↑T·I).re: unify s.re with (↑(2√n) + ↑T·I).re: also not defeq → should fail the same way! But it PASSED. WHY?
Hmm — maybe rcases in the isolated test DIDN'T cases the Eq because... ⟨h1, h2⟩ pattern destructures the ×ℂ (And) and LEAVES the components as hypotheses without recursing into them (rcases recurses only with deeper patterns!). ⟨h1, h2⟩ — h1 : s.re ∈ {w.re} — rcases with a SHALLOW pattern ⟨h1, h2⟩ doesn't touch h1's internals ✓ PASSES. But `rcases hs with hb | hb | hb | hb` on the union: after the Or-split, each hb : s ∈ piece — rcases then tries to destructure hb further (default recursion depth) — into ⟨h1, h2⟩ and then into the singleton's Eq → BOOM.
So the fix: control the rcases depth: `rcases hs with hb | hb | hb | hb` where hb remains the full membership — but rcases' default is to keep destructuring... Actually NO — rcases on Or gives exactly hb : s ∈ piece (it doesn't recurse into hb unless the pattern asks). The pattern `hb | hb | hb | hb` names each case's hypothesis hb — shallow ✓. Then INSIDE each case, my code does `Set.mem_singleton_iff.mp hb.2` — hb.2 : s.im ∈ {z.im} — .mp gives s.im = z.im ✓ no cases. But the ERROR is at the rcases line itself (line 9:17 in the rw-test = the rcases)...
Hmm wait — maybe the issue: `rw [RectangleBorder] at hs` — without it, rcases must unfold RectangleBorder itself. In the FIRST scratch test (no rw), the error was the same at the rcases. So rcases destructures the union AND the pieces AND the Eqs recursively by default?! rcases DOES recurse by default: `rcases x with hb | hb | hb | hb` — the PATTERN is flat (4 names), so it shouldn't recurse deeper... but the error occurs at the rcases line. Hmm — unless rcases, when destructuring the union, ALSO destructures the resulting ×ℂ and singleton automatically because Set membership in a setOf is an Eq/And that rcases "sees through"...
rcases DOES see through setOf: `s ∈ {z | p z}` is defeq to `p z` — and rcases destructures `p z` (the And and the Eq). So even with the flat pattern, rcases destructures the whole membership tree: Or → And → Eq — and the Eq cases fails.
FIX: prevent the Eq-cases by hiding the equality behind the iff-lemma at the hypothesis level BEFORE rcases: rewrite the singleton memberships into named implications... no — the Eq is inside the piece structure.
ALTERNATIVE FIX (robust): reformulate the border decomposition as a lemma proved ONCE with the iffs applied:
```lean
lemma border_im_eq_or_re_eq {z w s : ℂ} (hs : s ∈ RectangleBorder z w) :
s.im = z.im ∨ s.re = z.re ∨ s.im = w.im ∨ s.re = w.re := by
rcases hs with hb | hb | hb | hb
· exact Or.inl (Set.mem_singleton_iff.mp hb.2)
· exact Or.inr (Or.inl (Set.mem_singleton_iff.mp hb.1))
· exact Or.inr (Or.inr (Or.inl (Set.mem_singleton_iff.mp hb.2)))
· exact Or.inr (Or.inr (Or.inr (Set.mem_singleton_iff.mp hb.1)))
```
— same rcases problem INSIDE this lemma!
The problem is fundamental: rcases sees through setOf memberships into Eqs and cases them. Solution: don't rcases the union; project manually:
```lean
have hs4 := hs
rw [RectangleBorder, Set.mem_union, Set.mem_union, Set.mem_union] at hs4
-- hs4 : s ∈ A ×ℂ {z.im} ∨ s ∈ {z.re} ×ℂ _ ∨ s ∈ _ ×ℂ {w.im} ∨ s ∈ {w.re} ×ℂ _
rcases hs4 with hb | hb | hb | hb -- STILL recurses into the Eq
```
Hmm — but does it? The Eq is `s.im ∈ {z.im}` — setOf-membership — defeq to `s.im = z.im` — rcases cases-es it?? My isolated test `rcases h with h1` on s.re ∈ {5} PASSED — there rcases did NOT cases the Eq (it kept h1 : s.re = 5 as hypothesis? or did it cases and the sides were defeq?? s.re vs 5 — not defeq — it should have failed. But it PASSED. So rcases does NOT always cases the Eq!
Difference between the passing singleton test and the failing border test: in the passing test, the Eq is `s.re = 5` — RHS a literal. In the failing test, the Eq is `s.re = (↑(2√n) + ↑T·I).re` — after add_re-defeq-unfolding → `s.re = re(↑(2√n)) + re(↑T·I)` — RHS is a SUM (Real.add application). AH — I bet `cases` on Eq with RHS a SUM: Eq.rec's index unification: `s.re` (a projection — "stuck" term) vs `re(2√n) + re(T·I)` (also stuck) — for cases to succeed it needs them defeq — fails. In the passing test: `s.re = 5` — hmm, also stuck vs literal — should fail identically... unless rcases DIDN'T cases it there because it kept it as hypothesis.
Ugh — let me just empirically find what form makes rcases NOT cases the Eq. Test: (a) Eq with literal RHS (passed); (b) Eq with sum RHS; (c) Eq with compound .re RHS.
Isolating exactly when rcases cases-es the Eq.
tool: Bash
input
{
"command": "cd D:/Python/Quantum/research/lean/NguyenRH1 && cat > Scratch.lean << 'EOF'\nimport Mathlib\nopen Complex\nexample (s : \u2102) (h : s.re = (5 : \u211d) + (2 : \u211d)) : True := by\n rcases h with h1\n trivial\nexample (s : \u2102) (h : s.re = ((5 : \u211d) : \u2102).re) : True := by\n rcases h with h1\n trivial\nexample (s : \u2102) (h : s.re = (5 : \u211d)) : True := by\n rcases h with h1\n trivial\nEOF\nexport PATH=\"$HOME/.elan/bin:$PATH\" && lake env lean Scratch.lean 2>&1 | head -12",
"description": "Test Eq forms under rcases",
"timeout": 300000
}
raw content_json (database row)
[{"type":"thinking","thinking":"Reproduced with `rw [RectangleBorder] at hs` then rcases. The failing equation: `Real.add✝ (↑(2√n)).re (↑T·I).re = s.1`. Now I read it correctly: `Real.add (↑(2√n)) (↑T·I)).re = s.1` — i.e. `re(↑(2√n) + ↑T·I) = s.1` where s.1 is... `s.1` = Prod.fst s?! But s : ℂ... OH WAIT — I bet `s.1` here is `s.re` — no — the equation `Real.add✝ (↑(2 * √↑n)).re (↑T * I).re = s.1`: parsing precedence: `(Real.add✝ (↑(2 * √↑n))).re` — no...\n\nLet me think differently: maybe it's `Real.add✝ (↑(2√n)).re ((↑T * I).re) = s.1`: re(↑(2√n)) + re(↑T·I) = s.1 — and s.1 = s.re (Complex is a structure with field re — s.1 IS s.re via structure projection notation!). And `re(↑(2√n)) + re(↑T·I)` — the add_re of w.re! So the equation is `re(w) = s.re` expanded via add_re to `re(↑(2√n)) + re(↑T·I) = s.re`?? — hmm no wait — w.re = re(↑(2√n) + ↑T·I) — and add_re: re(a+b) = re a + re b — but re(↑(2√n) + ↑T·I) as a TERM is `Complex.add (↑(2√n)) (↑T·I) |>.re` — displaying as `Real.add✝ (↑(2√n)).re (↑T·I).re`?? The `Real.add✝` — hmm, Complex.add vs Real.add confusion: `Real.add✝ (↑(2√n)).re (↑T·I).re` — that's REAL addition of re(2√n) and re(T·I).\n\nSo the Eq: re(↑(2√n)) + re(↑T·I) = s.re. Where does this come from? The singleton {w.re} membership gives s.re = w.re. But here it's w.re EXPANDED: re(2√n) + re(T·I) — that's NOT w.re as a term (w.re = re(↑(2√n) + ↑T·I) — the .re OUTSIDE). Unless the elaborator normalized re(a+b) → re a + re b?? No, that's a simp lemma, not defeq... Actually `Complex.add_re : (x + y).re = x.re + y.re` — is it rfl? For ℂ, add is defined componentwise: (a + b).re = a.re + b.re — DEFINITIONALLY rfl! So re(w) = re(↑(2√n)) + re(↑T·I) DEFINITIONALLY. So the singleton Eq s.re = w.re is defeq to s.re = re(↑(2√n)) + re(↑T·I). And re(↑(2√n)) = ↑(2√n) (ofReal_re — defeq? ↑r = ⟨r, 0⟩: re = r definitionally ✓) and re(↑T·I) = re(↑T)·re(I) − im(↑T)·im(I) = T·0 − 0·1 = 0 definitionally? ↑T * I = ⟨T,0⟩·⟨0,1⟩ = ⟨T·0−0·1, T·1+0·0⟩ = ⟨0, T⟩: re = 0 definitionally ✓. So the Eq s.re = re(↑(2√n)) + re(↑T·I) is defeq to s.re = 2√n + 0 = 2√n.\n\nNow — cases on this Eq: `s.re = re(↑(2√n)) + re(↑T·I)` — dependent elimination tries to solve `Eq.refl : re(↑(2√n)) + re(↑T·I) = s.1`?? — hmm the ERROR equation has the sides FLIPPED vs mine: `Real.add... = s.1` — so cases is proving the goal by eliminating the Eq h : s.re = ... hmm — but WHY does cases try to eliminate it at all, rather than keeping it as a hypothesis?\n\nAH — I think I finally get it: `cases`/`subst` on Eq h : a = b: Lean tries `Eq.rec` — it abstracts the motive over b (or a): if b is a VARIABLE, fine; if b is NOT a variable, it tries to generalize the goal over b — and then needs `Eq.refl : b = b'` to typecheck the eliminated goal — wait no. `subst h` requires one side to be a free variable. `cases h` on Eq: it does `Eq.casesOn` — which requires the equation to be provable by refl after unification — i.e., it UNIFIES the two sides (with the equation's LHS/RHS as patterns against themselves)... no — `cases h` on h : @Eq α a b: it elaborates to `Eq.rec` with indices a, b unified: succeeds iff a and b are defeq (with the local context's metavariates assigned). If not defeq: \"dependent elimination failed: failed to solve equation a = b at case Eq.refl\". So cases on Eq with non-defeq sides ALWAYS fails. rcases on a hypothesis of Eq TYPE attempts cases → fails on non-defeq Eq.\n\nBut then WHY did my earlier Scratch test with the singleton {(5:ℝ)} PASS?! `rcases h with h1` on s.re ∈ {5}: the membership s.re = 5 — cases on it: sides s.re vs 5 — NOT defeq — should fail the same way... unless rcases DOESN'T destructure the singleton membership (leaves it as an Eq hypothesis without cases-ing it). And in the border case it DID try to cases it — the difference: in the border case, the Eq is s.re = re(↑(2√n)) + re(↑T·I) — hmm.\n\nWait — maybe the difference: in my Scratch test, `rcases h with h1` on `s.re ∈ ({(5 : ℝ)} : Set ℝ)` — rcases destructured the SET MEMBERSHIP — Set.singleton membership: is it an Eq? Set.singleton a = {x | x = a}? Set membership in a setOf is defeq to the predicate — s.re = 5 — rcases on an Eq... and it PASSED. So rcases did NOT cases the Eq there. But in the border case it DID cases something. The difference must be that in the border case the Eq has the form `Real.add X Y = s.1` where `s.1` — hmm, `s.1` — s is ℂ, s.1 = s.re — hmm.\n\nOK you know what — let me just look at what the border pieces elaborate to and handle each piece WITHOUT rcases on the union: destruct the union with Set.mem_union.mp manually:\n\n```lean\n rw [RectangleBorder] at hs\n -- hs : s ∈ A ∪ B ∪ C ∪ D\n rcases Set.mem_union _ _ hs with hb | hb3\n · rcases Set.mem_union _ _ hb with hb | hb2\n · -- bottom: s ∈ [[z.re, w.re]] ×ℂ {z.im}\n have him : s.im = z.im := hb.2 -- hb.2 : s.im ∈ {z.im} — defeq to s.im = z.im\n ...\n```\nhb.2 : s.im ∈ {z.im} — as a TERM its type displays as s.im ∈ {z.im}, defeq to s.im = z.im. `have him : s.im = z.im := hb.2` — defeq assignment ✓ no cases! And hb.1 : s.re ∈ [[z.re, w.re]] (uIcc membership — keep as is ✓).\n\nSo the fix: destructure the union via Set.mem_union.mp (or rcases with hb | hb — which worked in my second Scratch test? no — the second test had rw [RectangleBorder] then rcases with hb | hb | hb | hb and FAILED). Wait — but the FIRST scratch test (no rw) also failed at the rcases. So rcases on the union is what cases-es... no wait — the failing equation is about w.re = s.1 — the RIGHT piece. rcases on the union recurses into everything: the right piece's singleton Eq s.re = w.re gets cases'd → fail. But my isolated right-piece test `rcases hs with ⟨h1, h2⟩` PASSED — there, h1 : s.re ∈ {w.re} is destructured... and it passed?! The difference: in the isolated test, the singleton's element is `(((2 * Real.sqrt n : ℝ) : ℂ) + (T : ℝ) * Complex.I).re` — re OUTSIDE — the Eq s.re = (↑(2√n) + ↑T·I).re — cases on it: RHS = (↑(2√n) + ↑T·I).re — hmm that's also non-defeq vs s.re... but it PASSED. And in the border-union case, the singleton displays as Real.add of the re's — DIFFERENT FORM! In the union case, `Set.mem_union` normalization must have rewritten re(↑(2√n) + ↑T·I) to re(↑(2√n)) + re(↑T·I) (via add_re being defeq?? add_re IS defeq rfl — so the elaborator unfolded it during rcases' whnf). And then cases on `s.re = re(↑(2√n)) + re(↑T·I)`: RHS is an ADD — and `cases` on Eq with an add RHS... hmm still should fail the same way.\n\nWait wait — maybe the failure is NOT the Eq-cases at all. `s.1` — where does a .1 come from?? s : ℂ. s.1 = s.re. The Eq after add_re expansion: s.re = re(2√n) + re(T·I). cases on Eq: tries Eq.rec — unify `s.re` with `re(2√n) + re(T·I)`: NOT defeq (both proper terms) → fail \"Failed to solve equation re(2√n)+re(T·I) = s.1\" ✓ consistent.\n\nIn the isolated right-piece test: the Eq is s.re = (↑(2√n) + ↑T·I).re: unify s.re with (↑(2√n) + ↑T·I).re: also not defeq → should fail the same way! But it PASSED. WHY?\n\nHmm — maybe rcases in the isolated test DIDN'T cases the Eq because... ⟨h1, h2⟩ pattern destructures the ×ℂ (And) and LEAVES the components as hypotheses without recursing into them (rcases recurses only with deeper patterns!). ⟨h1, h2⟩ — h1 : s.re ∈ {w.re} — rcases with a SHALLOW pattern ⟨h1, h2⟩ doesn't touch h1's internals ✓ PASSES. But `rcases hs with hb | hb | hb | hb` on the union: after the Or-split, each hb : s ∈ piece — rcases then tries to destructure hb further (default recursion depth) — into ⟨h1, h2⟩ and then into the singleton's Eq → BOOM.\n\nSo the fix: control the rcases depth: `rcases hs with hb | hb | hb | hb` where hb remains the full membership — but rcases' default is to keep destructuring... Actually NO — rcases on Or gives exactly hb : s ∈ piece (it doesn't recurse into hb unless the pattern asks). The pattern `hb | hb | hb | hb` names each case's hypothesis hb — shallow ✓. Then INSIDE each case, my code does `Set.mem_singleton_iff.mp hb.2` — hb.2 : s.im ∈ {z.im} — .mp gives s.im = z.im ✓ no cases. But the ERROR is at the rcases line itself (line 9:17 in the rw-test = the rcases)... \n\nHmm wait — maybe the issue: `rw [RectangleBorder] at hs` — without it, rcases must unfold RectangleBorder itself. In the FIRST scratch test (no rw), the error was the same at the rcases. So rcases destructures the union AND the pieces AND the Eqs recursively by default?! rcases DOES recurse by default: `rcases x with hb | hb | hb | hb` — the PATTERN is flat (4 names), so it shouldn't recurse deeper... but the error occurs at the rcases line. Hmm — unless rcases, when destructuring the union, ALSO destructures the resulting ×ℂ and singleton automatically because Set membership in a setOf is an Eq/And that rcases \"sees through\"...\n\nrcases DOES see through setOf: `s ∈ {z | p z}` is defeq to `p z` — and rcases destructures `p z` (the And and the Eq). So even with the flat pattern, rcases destructures the whole membership tree: Or → And → Eq — and the Eq cases fails.\n\nFIX: prevent the Eq-cases by hiding the equality behind the iff-lemma at the hypothesis level BEFORE rcases: rewrite the singleton memberships into named implications... no — the Eq is inside the piece structure.\n\nALTERNATIVE FIX (robust): reformulate the border decomposition as a lemma proved ONCE with the iffs applied:\n\n```lean\nlemma border_im_eq_or_re_eq {z w s : ℂ} (hs : s ∈ RectangleBorder z w) :\n s.im = z.im ∨ s.re = z.re ∨ s.im = w.im ∨ s.re = w.re := by\n rcases hs with hb | hb | hb | hb\n · exact Or.inl (Set.mem_singleton_iff.mp hb.2)\n · exact Or.inr (Or.inl (Set.mem_singleton_iff.mp hb.1))\n · exact Or.inr (Or.inr (Or.inl (Set.mem_singleton_iff.mp hb.2)))\n · exact Or.inr (Or.inr (Or.inr (Set.mem_singleton_iff.mp hb.1)))\n```\n— same rcases problem INSIDE this lemma!\n\nThe problem is fundamental: rcases sees through setOf memberships into Eqs and cases them. Solution: don't rcases the union; project manually:\n\n```lean\n have hs4 := hs\n rw [RectangleBorder, Set.mem_union, Set.mem_union, Set.mem_union] at hs4\n -- hs4 : s ∈ A ×ℂ {z.im} ∨ s ∈ {z.re} ×ℂ _ ∨ s ∈ _ ×ℂ {w.im} ∨ s ∈ {w.re} ×ℂ _\n rcases hs4 with hb | hb | hb | hb -- STILL recurses into the Eq\n```\n\nHmm — but does it? The Eq is `s.im ∈ {z.im}` — setOf-membership — defeq to `s.im = z.im` — rcases cases-es it?? My isolated test `rcases h with h1` on s.re ∈ {5} PASSED — there rcases did NOT cases the Eq (it kept h1 : s.re = 5 as hypothesis? or did it cases and the sides were defeq?? s.re vs 5 — not defeq — it should have failed. But it PASSED. So rcases does NOT always cases the Eq!\n\nDifference between the passing singleton test and the failing border test: in the passing test, the Eq is `s.re = 5` — RHS a literal. In the failing test, the Eq is `s.re = (↑(2√n) + ↑T·I).re` — after add_re-defeq-unfolding → `s.re = re(↑(2√n)) + re(↑T·I)` — RHS is a SUM (Real.add application). AH — I bet `cases` on Eq with RHS a SUM: Eq.rec's index unification: `s.re` (a projection — \"stuck\" term) vs `re(2√n) + re(T·I)` (also stuck) — for cases to succeed it needs them defeq — fails. In the passing test: `s.re = 5` — hmm, also stuck vs literal — should fail identically... unless rcases DIDN'T cases it there because it kept it as hypothesis.\n\nUgh — let me just empirically find what form makes rcases NOT cases the Eq. Test: (a) Eq with literal RHS (passed); (b) Eq with sum RHS; (c) Eq with compound .re RHS.","signature":""},{"type":"text","text":"Isolating exactly when rcases cases-es the Eq."},{"type":"tool_use","id":"Bash_276","name":"Bash","input":{"command":"cd D:/Python/Quantum/research/lean/NguyenRH1 && cat > Scratch.lean << 'EOF'\nimport Mathlib\nopen Complex\nexample (s : ℂ) (h : s.re = (5 : ℝ) + (2 : ℝ)) : True := by\n rcases h with h1\n trivial\nexample (s : ℂ) (h : s.re = ((5 : ℝ) : ℂ).re) : True := by\n rcases h with h1\n trivial\nexample (s : ℂ) (h : s.re = (5 : ℝ)) : True := by\n rcases h with h1\n trivial\nEOF\nexport PATH=\"$HOME/.elan/bin:$PATH\" && lake env lean Scratch.lean 2>&1 | head -12","description":"Test Eq forms under rcases","timeout":300000},"extra_content":null}]