Cubic cost of indexed CYK
TheoremExact cost of a membership scan#✓fully proved
Exact charge for a full membership scan, including a failed scan.
theorem member_time (nc : ℕ) (a : N) (xs : List N) :
(member nc a xs).time = 1 + xs.length * (nc + 3)
def member (eqCost : ℕ) (a : N) : List N → TimeM ℕ Bool
| [] => ⟨false, 1⟩
| b :: bs =>
let rest := member eqCost a bs
⟨decide (a = b) || rest.ret, rest.time + eqCost + 3⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:54
Uses 1 · Used by 2
TheoremComputed CYK cell length bounded by the rule count#✓fully proved
Even with duplicates, a cell never exceeds the rule enumeration length.
theorem cell_length (tc nc : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (i len : ℕ)
(rs : List (ContextFreeRule T N)) :
(cell tc nc w tbl i len rs).ret.length ≤ rs.length
def cell (termCost ntCost : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (i len : ℕ) :
List (ContextFreeRule T N) → TimeM ℕ (List N)
| [] => ⟨[], 1⟩
| r :: rs =>
let f := fits termCost ntCost w tbl i len r.output
let rest := cell termCost ntCost w tbl i len rs
⟨if f.ret then r.input :: rest.ret else rest.ret,
f.time + rest.time + 5⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:121
Uses 2 · Used by 1
TheoremEvery CYK table lookup is bounded by the rule count#✓fully proved
All table cells, including invalid/default positions, have bounded membership-scan length. This invariant is proved from construction.
theorem lookup_length (tc nc : ℕ) (w : Array T)
(rs : List (ContextFreeRule T N)) (depth i len : ℕ) :
(lookup (table tc nc w rs depth).ret i len).length ≤ rs.length
def lookup (tbl : Array (Array (List N))) (i len : ℕ) : List N :=
(tbl[len]?.getD #[])[i]?.getD []
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:68
def table (termCost ntCost : ℕ) (w : Array T)
(rs : List (ContextFreeRule T N)) :
ℕ → TimeM ℕ (Array (Array (List N)))
| 0 => ⟨Array.replicate (w.size + 1) #[], w.size + 4⟩
| depth + 1 =>
let prev := table termCost ntCost w rs depth
let next := row termCost ntCost w prev.ret (depth + 1) rs 0
(w.size + 1)
⟨prev.ret.set! (depth + 1) next.ret.toArray,
prev.time + next.time + 2 * (w.size + 1) + 8⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:159
Uses 8 · Used by 2
TheoremCost bound for the CYK split scan#✓fully proved
Each split pays for both indexed cell reads and both membership scans.
theorem splits_time_le (nc : ℕ) (tbl : Array (Array (List N)))
(r : ℕ) (htbl : ∀ i len, (lookup tbl i len).length ≤ r)
(i len : ℕ) (b c : N) (count : ℕ) :
(splits nc tbl i len b c count).time ≤
1 + count * (2 * r * (nc + 3) + 18)
def lookup (tbl : Array (Array (List N))) (i len : ℕ) : List N :=
(tbl[len]?.getD #[])[i]?.getD []
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:68
def splits (eqCost : ℕ) (tbl : Array (Array (List N)))
(i len : ℕ) (b c : N) : ℕ → TimeM ℕ Bool
| 0 => ⟨false, 1⟩
| k + 1 =>
let rest := splits eqCost tbl i len b c k
let left := member eqCost b (lookup tbl i (k + 1))
let right := member eqCost c (lookup tbl (i + (k + 1)) (len - (k + 1)))
⟨rest.ret || (left.ret && right.ret),
rest.time + left.time + right.time + 16⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:74
Uses 4 · Used by 1
TheoremCost bound for the CYK production fit test#✓fully proved
Output inspection is bounded; only binary productions scan splits.
theorem fits_time_le (tc nc : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (r : ℕ)
(htbl : ∀ i len, (lookup tbl i len).length ≤ r)
(i len : ℕ) (out : List (Symbol T N)) :
(fits tc nc w tbl i len out).time ≤
tc + 12 + len * (2 * r * (nc + 3) + 18)
def lookup (tbl : Array (Array (List N))) (i len : ℕ) : List N :=
(tbl[len]?.getD #[])[i]?.getD []
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:68
def fits (termCost ntCost : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (i len : ℕ) :
List (Symbol T N) → TimeM ℕ Bool
| [.terminal a] =>
⟨decide (len = 1) && decide (w[i]? = some a), termCost + 12⟩
| [.nonterminal b, .nonterminal c] =>
let r := splits ntCost tbl i len b c (len - 1)
⟨r.ret, r.time + 8⟩
| _ => ⟨false, 8⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:109
Uses 4 · Used by 1
TheoremCost bound for computing one CYK cell#✓fully proved
A cell charges every rule, its test, and its possible output cons.
theorem cell_time_le (tc nc : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (r : ℕ)
(htbl : ∀ i len, (lookup tbl i len).length ≤ r)
(i len : ℕ) (rs : List (ContextFreeRule T N)) :
(cell tc nc w tbl i len rs).time ≤
1 + rs.length * (tc + 17 + len * (2 * r * (nc + 3) + 18))
def lookup (tbl : Array (Array (List N))) (i len : ℕ) : List N :=
(tbl[len]?.getD #[])[i]?.getD []
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:68
def cell (termCost ntCost : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (i len : ℕ) :
List (ContextFreeRule T N) → TimeM ℕ (List N)
| [] => ⟨[], 1⟩
| r :: rs =>
let f := fits termCost ntCost w tbl i len r.output
let rest := cell termCost ntCost w tbl i len rs
⟨if f.ret then r.input :: rest.ret else rest.ret,
f.time + rest.time + 5⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:121
Uses 4 · Used by 1
TheoremCost bound for building one CYK row#✓fully proved
Row cost counts all starts, not only successful or distinct factors.
theorem row_time_le (tc nc : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (r : ℕ)
(htbl : ∀ i len, (lookup tbl i len).length ≤ r)
(len : ℕ) (rs : List (ContextFreeRule T N)) (i count : ℕ) :
(row tc nc w tbl len rs i count).time ≤
1 + count * (5 + rs.length *
(tc + 17 + len * (2 * r * (nc + 3) + 18)))
def lookup (tbl : Array (Array (List N))) (i len : ℕ) : List N :=
(tbl[len]?.getD #[])[i]?.getD []
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:68
def row (termCost ntCost : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (len : ℕ)
(rs : List (ContextFreeRule T N)) (i : ℕ) :
ℕ → TimeM ℕ (List (List N))
| 0 => ⟨[], 1⟩
| count + 1 =>
let c := cell termCost ntCost w tbl i len rs
let rest := row termCost ntCost w tbl len rs (i + 1) count
⟨c.ret :: rest.ret, c.time + rest.time + 4⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:147
Uses 4 · Used by 1
TheoremCost bound for filling the indexed CYK table#✓fully proved
Table cost includes allocation, every row conversion and every update. The memory-size hypothesis needed for split costs is discharged internally.
theorem table_time_le (tc nc : ℕ) (w : Array T)
(rs : List (ContextFreeRule T N)) (depth : ℕ) (hd : depth ≤ w.size) :
(table tc nc w rs depth).time ≤ w.size + 4 + depth *
(9 + (w.size + 1) * (7 + rs.length *
(tc + 17 + w.size * (2 * rs.length * (nc + 3) + 18))))
def table (termCost ntCost : ℕ) (w : Array T)
(rs : List (ContextFreeRule T N)) :
ℕ → TimeM ℕ (Array (Array (List N)))
| 0 => ⟨Array.replicate (w.size + 1) #[], w.size + 4⟩
| depth + 1 =>
let prev := table termCost ntCost w rs depth
let next := row termCost ntCost w prev.ret (depth + 1) rs 0
(w.size + 1)
⟨prev.ret.set! (depth + 1) next.ret.toArray,
prev.time + next.time + 2 * (w.size + 1) + 8⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:159
Uses 4 · Used by 1
TheoremLength of a computed CYK row#✓fully proved
The linear row-conversion charge uses the actual number of entries.
theorem row_length (tc nc : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (len : ℕ)
(rs : List (ContextFreeRule T N)) (i count : ℕ) :
(row tc nc w tbl len rs i count).ret.length = count
def row (termCost ntCost : ℕ) (w : Array T)
(tbl : Array (Array (List N))) (len : ℕ)
(rs : List (ContextFreeRule T N)) (i : ℕ) :
ℕ → TimeM ℕ (List (List N))
| 0 => ⟨[], 1⟩
| count + 1 =>
let c := cell termCost ntCost w tbl i len rs
let rest := row termCost ntCost w tbl len rs (i + 1) count
⟨c.ret :: rest.ret, c.time + rest.time + 4⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:147
Uses 1
TheoremExact cost of the CYK epsilon scan#✓fully proved
Exact cost of the empty-input production scan.
theorem epsilon_time (nc : ℕ) (start : N)
(rs : List (ContextFreeRule T N)) :
(epsilon nc start rs).time = 1 + rs.length * (nc + 6)
def epsilon (ntCost : ℕ) (start : N) :
List (ContextFreeRule T N) → TimeM ℕ Bool
| [] => ⟨false, 1⟩
| r :: rs =>
let rest := epsilon ntCost start rs
⟨(decide (r.input = start) && r.output.isEmpty) || rest.ret,
rest.time + ntCost + 6⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:171
Uses 1 · Used by 1
TheoremExplicit cubic cost bound for indexed CYK#✓fully proved
Explicit cubic bound, for every word including the empty word. The coefficient depends only on the rule enumeration and equality costs; no semantic or assumed recurrence hypothesis occurs in this cost theorem.
theorem recognizes_time_le (tc nc : ℕ) (start : N)
(rs : List (ContextFreeRule T N)) (w : List T) :
(recognizes tc nc start rs w).time ≤
(rs.length * (tc + nc + 2 * rs.length * (nc + 3) + 38) + 40) *
(w.length + 1) ^ 3
def recognizes (termCost ntCost : ℕ) (start : N)
(rs : List (ContextFreeRule T N)) (w : List T) : TimeM ℕ Bool :=
match w with
| [] =>
let r := epsilon ntCost start rs
⟨r.ret, r.time + 1⟩
| _ :: _ =>
let a := w.toArray
let tbl := table termCost ntCost a rs a.size
let r := member ntCost start (lookup tbl.ret 0 a.size)
⟨r.ret, tbl.time + r.time + 3 * w.length + 12⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:181
Uses 9 · Used by 2
TheoremIndexed CYK costs a constant times \(n^3\) on nonempty words#✓fully proved
In the usual nonempty-input form, the bound is a constant times n³.
theorem recognizes_time_le_cubic (tc nc : ℕ) (start : N)
(rs : List (ContextFreeRule T N)) (w : List T) (hw : w ≠ []) :
(recognizes tc nc start rs w).time ≤
8 * (rs.length *
(tc + nc + 2 * rs.length * (nc + 3) + 38) + 40) * w.length ^ 3
def recognizes (termCost ntCost : ℕ) (start : N)
(rs : List (ContextFreeRule T N)) (w : List T) : TimeM ℕ Bool :=
match w with
| [] =>
let r := epsilon ntCost start rs
⟨r.ret, r.time + 1⟩
| _ :: _ =>
let a := w.toArray
let tbl := table termCost ntCost a rs a.size
let r := member ntCost start (lookup tbl.ret 0 a.size)
⟨r.ret, tbl.time + r.time + 3 * w.length + 12⟩
CSLibExt/Computability/Languages/ContextFree/CYKIndexed.lean:181
Uses 2
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.