AFTD Auto-Formalizing Theoretical Domains

spider_two_leg_one_free_options_eq

theoremverified

The raw zipIdx.flatMap options list of [(1, free), (k, free)] at fuel k + 2 with incoming centre status unfolds to the explicit list [k, k % 2, (k - 1) ^^^ 1, (k - 1) ^^^ 1] concatenated with the flatMap over j ≥ 2 of (k - j) ^^^ spider_gamma (k + 1) incoming [(j - 1, delta), (1, free)].

Statement

theorem spider_two_leg_one_free_options_eq (k : ℕ) (hk : 1 ≤ k) :
    ([(1, SpiderLegEnd.free), (k, SpiderLegEnd.free)].zipIdx.flatMap (fun ⟨⟨h, phi⟩, idx⟩ =>
      let rest := [(1, SpiderLegEnd.free), (k, SpiderLegEnd.free)].eraseIdx idx
      (List.range h).flatMap (fun j_zero =>
        let j := j_zero + 1
        [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
          if j == h ∧ phi ≠ SpiderLegEnd.free ∧ delta ≠ phi then none
          else
            let d := spider_rho (h - j) delta phi
            if j ≥ 2 then
              let new_L := (j - 1, delta) :: rest
              some (d ^^^ spider_gamma (k + 1) CentreStatus.incoming new_L)
            else
              let new_s := spider_update_centre CentreStatus.incoming delta
              some (d ^^^ spider_gamma (k + 1) new_s rest)
        )
      )
    )) =
    [k, k % 2, (k - 1) ^^^ 1, (k - 1) ^^^ 1] ++
    (List.range (k - 1)).flatMap (fun idx =>
      let j := idx + 2
      let d := k - j
      [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>
        d ^^^ spider_gamma (k + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]
      )
    )
Source
step towards spider_two_leg_one_free
Verified
19 Oct 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 5
  • CentreStatusThe status of the central vertex in a spider state: none (no marked arcs incident), incoming (at least one incoming arc), outgoing (at…
  • SpiderLegEndThe end condition of an attached leg in a spider state is either free (no arc on the leg), inward (pointing towards the centre), or…
  • spider_update_centreThe function spider_update_centre updates centre status s given leg transition delta: if delta is inward, none maps to incoming, incoming…
  • spider_rhoThe function spider_rho takes h : ℕ and delta, phi : SpiderLegEnd, returning h if phi = free; if phi = inward, it returns h % 2 when delta…
  • spider_gammaThe function spider_gamma computes a natural number from a fuel parameter fuel : ℕ, a centre status s : CentreStatus, and a list of spider…

The proof, explained

The theorem syntactically evaluates the list of available moves from the two-legged spider graph [(1, free), (k, free)] with incoming centre status. By expressing k as m + 1, the proof separates the options leg by leg: the length-1 leg yields the two values k and k % 2, while the length-k leg splits into its minimal cut j = 1 (producing two copies of (k - 1) ^^^ 1) and the general cuts j ≥ 2 (which retain a shortened leg alongside the length-1 leg). Formal list manipulation rewrites the flatMap into this explicit concatenation.

  1. Write k as m + 1 for some natural number m.

    Since 1 ≤ k, we can write k = m + 1 with m = k - 1, verified by linear arithmetic (`omega`).

    line 28

      obtain ⟨m, rfl⟩ : ∃ m, k = m + 1 := ⟨k - 1, by omega⟩
  2. The moves obtained by cutting the first leg (length 1) evaluate to [m + 1, (m + 1) % 2].

    For the first leg, the only cut length is j = 1. Since j < 2, the cut removes the leg and updates the centre status. An inward cut keeps the status incoming, giving spider_gamma (m + 2) incoming [(m + 1, free)] = m + 1 (via h1); an outward cut changes it to free, giving spider_gamma (m + 2) free [(m + 1, free)] = (m + 1) % 2 (via h2). Since the isolated piece has value d = spider_rho 0 delta free = 0, the XOR sums simplify to m + 1 and (m + 1) % 2 respectively.

    lines 29–47

      have H0 : (let rest := [(m + 1, SpiderLegEnd.free)]
        (List.range 1).flatMap (fun j_zero =>
          let j := j_zero + 1
          [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
            if j == 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none
            else
              let d := spider_rho (1 - j) delta SpiderLegEnd.free
              if j ≥ 2 then
                let new_L := (j - 1, delta) :: rest
                some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)
              else
                let new_s := spider_update_centre CentreStatus.incoming delta
                some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)
          ))) = [m + 1, (m + 1) % 2] := by
        change [0 ^^^ spider_gamma (m + 2) CentreStatus.incoming [(m + 1, SpiderLegEnd.free)],
                0 ^^^ spider_gamma (m + 2) CentreStatus.free [(m + 1, SpiderLegEnd.free)]] = [m + 1, (m + 1) % 2]
        have h1 : spider_gamma (m + 2) CentreStatus.incoming [(m + 1, SpiderLegEnd.free)] = m + 1 := rfl
        have h2 : spider_gamma (m + 2) CentreStatus.free [(m + 1, SpiderLegEnd.free)] = 0 ^^^ ((m + 1) % 2) := rfl
        simp [h1, h2]
  3. The cut of length j = 1 on the second leg (length m + 1) yields the options [m ^^^ 1, m ^^^ 1].

    For j = 1 on the second leg, the cut length is below 2, leaving the first leg [(1, free)]. The detached piece has value d = spider_rho m delta free = m. For both delta = inward and delta = outward, the remaining configuration on [(1, free)] evaluates to 1 (via h1 and h2). Thus both choices yield m ^^^ 1. Filtering out invalid combinations vacuously keeps both moves since phi = free.

    lines 49–70

    uses List.filterMap_nil

      have H1_0 : (let rest := [(1, SpiderLegEnd.free)]
        let j_zero := 0
        let j := j_zero + 1
        [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
          if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none
          else
            let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free
            if j ≥ 2 then
              let new_L := (j - 1, delta) :: rest
              some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)
            else
              let new_s := spider_update_centre CentreStatus.incoming delta
              some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)
        )) = [m ^^^ 1, m ^^^ 1] := by
        dsimp
        simp [List.filterMap_nil]
        have h1 : spider_gamma (m + 2) (spider_update_centre CentreStatus.incoming SpiderLegEnd.inward) [(1, SpiderLegEnd.free)] = 1 := rfl
        have h2 : spider_gamma (m + 2) (spider_update_centre CentreStatus.incoming SpiderLegEnd.outward) [(1, SpiderLegEnd.free)] = 1 := rfl
        have h3 : spider_rho m SpiderLegEnd.inward SpiderLegEnd.free = m := rfl
        have h4 : spider_rho m SpiderLegEnd.outward SpiderLegEnd.free = m := rfl
        rw [h1, h2, h3, h4]
        exact ⟨rfl, rfl⟩
  4. For each cut of length j = idx + 2 ≥ 2 on the second leg, the cut piece remains as a leg of length idx + 1 with orientation delta alongside [(1, free)].

    When j = idx + 2 ≥ 2, the cut leaves a new leg segment (idx + 1, delta) joined to the remaining leg [(1, free)] under incoming centre status. The validity condition phi ≠ free is false because phi = free, so filterMap simplifies directly to mapping over inward and outward orientations.

    lines 72–94

      have H1_succ : ∀ idx, (let rest := [(1, SpiderLegEnd.free)]
        let j_zero := idx + 1
        let j := j_zero + 1
        [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
          if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none
          else
            let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free
            if j ≥ 2 then
              let new_L := (j - 1, delta) :: rest
              some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)
            else
              let new_s := spider_update_centre CentreStatus.incoming delta
              some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)
        )) =
        (let j := idx + 2
         let d := m + 1 - j
         [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>
           d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]
         )) := by
        intro idx
        dsimp
        simp
        exact ⟨rfl, rfl⟩
  5. The original options list decomposes definitionally into the moves on the first leg concatenated with the moves on the second leg.

    Definitially expand the flatMap over the two-element list [(1, free), (m + 1, free)]. It splits into the options on index 0 (leg of length 1) concatenated with the options on index 1 (leg of length m + 1).

    lines 96–123

      change (let rest := [(m + 1, SpiderLegEnd.free)]
        (List.range 1).flatMap (fun j_zero =>
          let j := j_zero + 1
          [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
            if j == 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none
            else
              let d := spider_rho (1 - j) delta SpiderLegEnd.free
              if j ≥ 2 then
                let new_L := (j - 1, delta) :: rest
                some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)
              else
                let new_s := spider_update_centre CentreStatus.incoming delta
                some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)
          ))) ++
        ((let rest := [(1, SpiderLegEnd.free)]
        (List.range (m + 1)).flatMap (fun j_zero =>
          let j := j_zero + 1
          [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
            if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none
            else
              let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free
              if j ≥ 2 then
                let new_L := (j - 1, delta) :: rest
                some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)
              else
                let new_s := spider_update_centre CentreStatus.incoming delta
                some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)
          ))) ++ []) = _
  6. Replace the leg 0 options with [m + 1, (m + 1) % 2] and split the index range for leg 1 into the initial cut j = 1 and successor cuts j ≥ 2.

    Remove the trailing empty list with List.append_nil and substitute H0 for the first leg's options. Then rewrite List.range (m + 1) as 0 :: List.map Nat.succ (List.range m) using List.range_succ_eq_map, and distribute the flatMap using List.flatMap_cons and List.flatMap_map to isolate the j_zero = 0 case from the successor cases.

    lines 124–129

    uses List.append_nil, List.range_succ_eq_map, List.flatMap_cons, List.flatMap_map

      rw [List.append_nil]
      rw [H0]
      have Hrange : List.range (m + 1) = 0 :: List.map Nat.succ (List.range m) := List.range_succ_eq_map
      rw [Hrange]
      rw [List.flatMap_cons]
      rw [List.flatMap_map]
  7. The flatMap over cuts j ≥ 2 on leg 1 matches the desired mapped format.

    Using function extensionality (funext) and H1_succ, rewrite the function on the successor indices so that each cut j = idx + 2 maps directly to the XOR sum of d = m + 1 - j with the recursive spider_gamma value.

    lines 130–173

      have Hmap : (List.range m).flatMap (fun a => (let rest := [(1, SpiderLegEnd.free)]
        let j_zero := a.succ
        let j := j_zero + 1
        [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
          if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none
          else
            let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free
            if j ≥ 2 then
              let new_L := (j - 1, delta) :: rest
              some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)
            else
              let new_s := spider_update_centre CentreStatus.incoming delta
              some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)
        ))) =
        (List.range m).flatMap (fun idx =>
          let j := idx + 2
          let d := m + 1 - j
          [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>
            d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]
          )) := by
        have h_eq : (fun a => (let rest := [(1, SpiderLegEnd.free)]
          let j_zero := a.succ
          let j := j_zero + 1
          [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>
            if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none
            else
              let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free
              if j ≥ 2 then
                let new_L := (j - 1, delta) :: rest
                some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)
              else
                let new_s := spider_update_centre CentreStatus.incoming delta
                some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)
          ))) =
          (fun idx =>
            let j := idx + 2
            let d := m + 1 - j
            [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>
              d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]
            )) := by
          funext idx
          exact H1_succ idx
        rw [h_eq]
      rw [Hmap]
  8. The full options list equals [k, k % 2, (k - 1) ^^^ 1, (k - 1) ^^^ 1] concatenated with the flatMap over cuts j ≥ 2.

    Rewriting with H1_0 replaces the j = 1 cut on the second leg by [m ^^^ 1, m ^^^ 1]. Simplification (simp) associates the list concatenations, simplifying [m + 1, (m + 1) % 2] ++ ([m ^^^ 1, m ^^^ 1] ++ rest) into the desired four-element prefix since k = m + 1 and m = k - 1.

    lines 174–175

      rw [H1_0]
      simp
List.filterMap_nil
Filtering and mapping over an empty list yields an empty list.
List.append_nil
Appending the empty list to any list leaves the list unchanged.
List.range_succ_eq_map
The range of length n + 1 decomposes into 0 followed by the successor of each element in the range of length n.
List.flatMap_cons
Mapping and concatenating over a list x :: xs splits into the function applied to x concatenated with the result on xs.
List.flatMap_map
A flatMap over a mapped list is equal to a single flatMap with the composed function.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

/-- Syntactic unfolding of the options list for [(1, free), (k, free)] at incoming centre status into head options and cuts of the long leg. -/theorem spider_two_leg_one_free_options_eq (k : ℕ) (hk : 1 ≤ k) :    ([(1, SpiderLegEnd.free), (k, SpiderLegEnd.free)].zipIdx.flatMap (fun ⟨⟨h, phi⟩, idx⟩ =>      let rest := [(1, SpiderLegEnd.free), (k, SpiderLegEnd.free)].eraseIdx idx      (List.range h).flatMap (fun j_zero =>        let j := j_zero + 1        [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>          if j == h ∧ phi ≠ SpiderLegEnd.free ∧ delta ≠ phi then none          else            let d := spider_rho (h - j) delta phi            if j ≥ 2 then              let new_L := (j - 1, delta) :: rest              some (d ^^^ spider_gamma (k + 1) CentreStatus.incoming new_L)            else              let new_s := spider_update_centre CentreStatus.incoming delta              some (d ^^^ spider_gamma (k + 1) new_s rest)        )      )    )) =    [k, k % 2, (k - 1) ^^^ 1, (k - 1) ^^^ 1] ++    (List.range (k - 1)).flatMap (fun idx =>      let j := idx + 2      let d := k - j      [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>        d ^^^ spider_gamma (k + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]      )    ) := by  obtain ⟨m, rfl⟩ : ∃ m, k = m + 1 := ⟨k - 1, by omega⟩  have H0 : (let rest := [(m + 1, SpiderLegEnd.free)]    (List.range 1).flatMap (fun j_zero =>      let j := j_zero + 1      [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>        if j == 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none        else          let d := spider_rho (1 - j) delta SpiderLegEnd.free          if j ≥ 2 then            let new_L := (j - 1, delta) :: rest            some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)          else            let new_s := spider_update_centre CentreStatus.incoming delta            some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)      ))) = [m + 1, (m + 1) % 2] := by    change [0 ^^^ spider_gamma (m + 2) CentreStatus.incoming [(m + 1, SpiderLegEnd.free)],            0 ^^^ spider_gamma (m + 2) CentreStatus.free [(m + 1, SpiderLegEnd.free)]] = [m + 1, (m + 1) % 2]    have h1 : spider_gamma (m + 2) CentreStatus.incoming [(m + 1, SpiderLegEnd.free)] = m + 1 := rfl    have h2 : spider_gamma (m + 2) CentreStatus.free [(m + 1, SpiderLegEnd.free)] = 0 ^^^ ((m + 1) % 2) := rfl    simp [h1, h2]  have H1_0 : (let rest := [(1, SpiderLegEnd.free)]    let j_zero := 0    let j := j_zero + 1    [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>      if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none      else        let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free        if j ≥ 2 then          let new_L := (j - 1, delta) :: rest          some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)        else          let new_s := spider_update_centre CentreStatus.incoming delta          some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)    )) = [m ^^^ 1, m ^^^ 1] := by    dsimp    simp [List.filterMap_nil]    have h1 : spider_gamma (m + 2) (spider_update_centre CentreStatus.incoming SpiderLegEnd.inward) [(1, SpiderLegEnd.free)] = 1 := rfl    have h2 : spider_gamma (m + 2) (spider_update_centre CentreStatus.incoming SpiderLegEnd.outward) [(1, SpiderLegEnd.free)] = 1 := rfl    have h3 : spider_rho m SpiderLegEnd.inward SpiderLegEnd.free = m := rfl    have h4 : spider_rho m SpiderLegEnd.outward SpiderLegEnd.free = m := rfl    rw [h1, h2, h3, h4]    exact ⟨rfl, rfl⟩  have H1_succ : ∀ idx, (let rest := [(1, SpiderLegEnd.free)]    let j_zero := idx + 1    let j := j_zero + 1    [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>      if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none      else        let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free        if j ≥ 2 then          let new_L := (j - 1, delta) :: rest          some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)        else          let new_s := spider_update_centre CentreStatus.incoming delta          some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)    )) =    (let j := idx + 2     let d := m + 1 - j     [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>       d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]     )) := by    intro idx    dsimp    simp    exact ⟨rfl, rfl⟩  change (let rest := [(m + 1, SpiderLegEnd.free)]    (List.range 1).flatMap (fun j_zero =>      let j := j_zero + 1      [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>        if j == 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none        else          let d := spider_rho (1 - j) delta SpiderLegEnd.free          if j ≥ 2 then            let new_L := (j - 1, delta) :: rest            some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)          else            let new_s := spider_update_centre CentreStatus.incoming delta            some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)      ))) ++    ((let rest := [(1, SpiderLegEnd.free)]    (List.range (m + 1)).flatMap (fun j_zero =>      let j := j_zero + 1      [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>        if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none        else          let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free          if j ≥ 2 then            let new_L := (j - 1, delta) :: rest            some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)          else            let new_s := spider_update_centre CentreStatus.incoming delta            some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)      ))) ++ []) = _  rw [List.append_nil]  rw [H0]  have Hrange : List.range (m + 1) = 0 :: List.map Nat.succ (List.range m) := List.range_succ_eq_map  rw [Hrange]  rw [List.flatMap_cons]  rw [List.flatMap_map]  have Hmap : (List.range m).flatMap (fun a => (let rest := [(1, SpiderLegEnd.free)]    let j_zero := a.succ    let j := j_zero + 1    [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>      if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none      else        let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free        if j ≥ 2 then          let new_L := (j - 1, delta) :: rest          some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)        else          let new_s := spider_update_centre CentreStatus.incoming delta          some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)    ))) =    (List.range m).flatMap (fun idx =>      let j := idx + 2      let d := m + 1 - j      [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>        d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]      )) := by    have h_eq : (fun a => (let rest := [(1, SpiderLegEnd.free)]      let j_zero := a.succ      let j := j_zero + 1      [SpiderLegEnd.inward, SpiderLegEnd.outward].filterMap (fun delta =>        if j == m + 1 ∧ SpiderLegEnd.free ≠ SpiderLegEnd.free ∧ delta ≠ SpiderLegEnd.free then none        else          let d := spider_rho (m + 1 - j) delta SpiderLegEnd.free          if j ≥ 2 then            let new_L := (j - 1, delta) :: rest            some (d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming new_L)          else            let new_s := spider_update_centre CentreStatus.incoming delta            some (d ^^^ spider_gamma (m + 1 + 1) new_s rest)      ))) =      (fun idx =>        let j := idx + 2        let d := m + 1 - j        [SpiderLegEnd.inward, SpiderLegEnd.outward].map (fun delta =>          d ^^^ spider_gamma (m + 1 + 1) CentreStatus.incoming [(idx + 1, delta), (1, SpiderLegEnd.free)]        )) := by      funext idx      exact H1_succ idx    rw [h_eq]  rw [Hmap]  rw [H1_0]  simp
See it in the graphDiscuss this resultChallenge it