fact
stringlengths
9
20.3k
type
stringclasses
2 values
library
stringclasses
116 values
imports
listlengths
0
239
filename
stringlengths
21
103
symbolic_name
stringlengths
1
92
docstring
null
FDOM_update : ∀xs root n q. FDOM (update xs root n k q) = FDOM q ∪ (set (MAP FST xs) DIFF FDOM k)
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
FDOM_update
null
has_path_exists_known : ∀edges root l n. has_path edges root l n ∧ root ∈ FDOM known ∧ n ∉ FDOM (known: num |-> res_info) ⇒ ∃m1 m2 l1 l2 l3. has_path edges root l1 m1 ∧ m1 ∈ FDOM known ∧ has_edge edges m1 l2 m2 ∧ m2 ∉ FDOM known ∧ l1 + l2 ≤ l
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
has_path_exists_known
null
FLOOKUP_update_neq : ∀i ns n d k q j v. i ≠ j ⇒ FLOOKUP (update ns n d k (q |+ (j,v))) i = FLOOKUP (update ns n d k q) i
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
FLOOKUP_update_neq
null
FLOOKUP_update_cons_neq : ∀i ns n d k q j v m. i ≠ j ⇒ FLOOKUP (update ((j,m)::ns) n d k q) i = FLOOKUP (update ns n d k q) i
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
FLOOKUP_update_cons_neq
null
pull_if : (f (if b then x else y) = if b then f x else f y) ∧ ((if b then g1 else g2) z = if b then g1 z else g2 z)
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
pull_if
null
FLOOKUP_update_pass : ∀i k ns h n d h1 q. (∀l. MEM (i,l) ns ⇒ h ≤ l) ⇒ FLOOKUP (update ns n d k (q |+ (i,<|prev_node := n; dist_from_root := d + h|>))) i = SOME <|prev_node := n; dist_from_root := d + h|>
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
FLOOKUP_update_pass
null
FLOOKUP_update_skip : ∀i k ns h n d h1 q l. FLOOKUP k i = NONE ∧ MEM (i,l) ns ∧ l < h ∧ (∀x. FLOOKUP q i = SOME x ⇒ d + h < x.dist_from_root) ⇒ FLOOKUP (update ns n d k (q |+ (i,<|prev_node := n; dist_from_root := d + h|>))) i = FLOOKUP (update ns n d k q) i
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
FLOOKUP_update_skip
null
FLOOKUP_update_MEM : ∀i k ns h n d h1 q. FLOOKUP k i = NONE ∧ (∀x. FLOOKUP q i = SOME x ⇒ d + h < x.dist_from_root) ⇒ FLOOKUP (update ns n d k (q |+ (i,<|prev_node := n; dist_from_root := d + h|>))) i = if ∃l. MEM (i,l) ns ∧ l < h then FLOOKUP (update ns n d k q) i else SOME <|prev_node := n; dist_from_root := d + h|>
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
FLOOKUP_update_MEM
null
update_thm : ∀i ns n d k q v. FLOOKUP (update ns n d k q) i = SOME v ∧ i ∉ FDOM k ⇒ (* the original value in q survived *) (FLOOKUP q i = SOME v ∧ (* all matching pairs in ns must have been ignored *) ∀len. MEM (i,len) ns ∧ FLOOKUP k i = NONE ⇒ v.dist_from_root ≤ d + len) ∨ (* mem in ns has been picked *) ∃len. MEM (i,len) ns ∧ v.dist_from_root = d + len ∧ v.prev_node = n ∧ (∀len2. MEM (i,len2) ns ⇒ len ≤ len2) ∧ (* any mapping in q must have been larger *) ∀w. FLOOKUP q i = SOME w ⇒ d + len ≤ w.dist_from_root
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
update_thm
null
FLOOKUP_update_k : ∀ns q. i ∈ FDOM k ⇒ FLOOKUP (update ns n d k q) i = FLOOKUP q i
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
FLOOKUP_update_k
null
update_not_eq : ∀ns n d k q i v. FLOOKUP (update ns n d k q) i = SOME v ∧ v.prev_node ≠ n ⇒ FLOOKUP q i = SOME v ∧ ∀len1. MEM (i,len1) ns ∧ i ∉ FDOM k ⇒ v.dist_from_root ≤ len1 + d
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
update_not_eq
null
update_eq : ∀ns d k q i v. FLOOKUP (update ns v.prev_node d k q) i = SOME v ∧ (∀w. FLOOKUP q i = SOME w ⇒ w ≠ v) ⇒ ∃len. i ∉ FDOM k ∧ MEM (i,len) ns ∧ v.dist_from_root = len + d ∧ (∀len1. MEM (i,len1) ns ⇒ len ≤ len1) ∧ (∀x. FLOOKUP q i = SOME x ⇒ d + len ≤ x.dist_from_root)
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
update_eq
null
dijkstra_thm : ∀root known queue edges res. calc known queue edges res ⇒ FLOOKUP known root = SOME (root_node root) ⇒ DISJOINT (FDOM known) (FDOM queue) ∧ (* content in known is shortest *) correct_result edges root known ∧ (* all neighbours of known are in known or queue *) (∀n len i. n ∈ FDOM known ∧ has_edge edges n len i ⇒ i ∈ FDOM known ∨ i ∈ FDOM queue) ∧ (* each queue points at shortest node in known *) (∀n v. FLOOKUP queue n = SOME v ⇒ ∃x len. FLOOKUP known v.prev_node = SOME x ∧ has_edge edges v.prev_node len n ∧ v.dist_from_root = x.dist_from_root + len ∧ ∀other y len1. FLOOKUP known other = SOME y ∧ has_edge edges other len1 n ⇒ v.dist_from_root ≤ y.dist_from_root + len1) ⇒ correct_result edges root res ∧ complete_result edges root res
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
dijkstra_thm
null
dijkstra_imp_correct_result : dijkstra root edges result ⇒ correct_result edges root result ∧ complete_result edges root result
theorem
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
dijkstra_imp_correct_result
null
min_elem_def = min_elem (n:num) v queue ⇔ FLOOKUP queue n = SOME v ∧ ∀m w. FLOOKUP queue m = SOME w ⇒ v.dist_from_root ≤ w.dist_from_root
definition
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
min_elem_def
null
update_def = update [] n d k q = q ∧ update ((i,len)::es) n d k q = case FLOOKUP k i of | SOME _ => update es n d k q | NONE => case FLOOKUP q i of | NONE => update es n d k (q |+ (i,<| prev_node := n ; dist_from_root := d + len |>)) | SOME j => if j.dist_from_root ≤ d + len then update es n d k q else update es n d k (q |+ (i,<| prev_node := n ; dist_from_root := d + len |>))
definition
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
update_def
null
root_node_def = root_node r = <| prev_node := r; dist_from_root := 0 |>
definition
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
root_node_def
null
dijkstra_def = dijkstra root edges result ⇔ calc FEMPTY (FEMPTY |+ (root, root_node root)) edges result
definition
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
dijkstra_def
null
correct_result_def = correct_result edges root known ⇔ (∀n v. FLOOKUP known n = SOME v ⇒ has_path edges root v.dist_from_root n ∧ (∀l. l < v.dist_from_root ⇒ ~ has_path edges root l n) ∧ (n = root ⇒ v.prev_node = root) ∧ (n ≠ root ⇒ ∃w l. FLOOKUP known v.prev_node = SOME w ∧ has_edge edges v.prev_node l n ∧ v.dist_from_root = l + w.dist_from_root))
definition
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
correct_result_def
null
complete_result_def = complete_result edges root known ⇔ (∀n len. has_path edges root len n ⇒ n ∈ FDOM known)
definition
examples/algorithms
[]
examples/algorithms/dijkstraScript.sml
complete_result_def
null
domain_spt_fold_union : ! tree y. domain (spt_fold union y tree) = domain y UNION {n | ?k aSet. lookup k tree = SOME aSet /\ n IN domain aSet}
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
domain_spt_fold_union
null
num_set_tree_union_empty : ! t1 t2 . isEmpty (num_set_tree_union t1 t2) <=> isEmpty t1 /\ isEmpty t2
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
num_set_tree_union_empty
null
wf_num_set_tree_union : ! t1 t2 result . wf t1 /\ wf t2 ==> wf (num_set_tree_union t1 t2)
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
wf_num_set_tree_union
null
domain_num_set_tree_union : ! t1 t2 . domain (num_set_tree_union t1 t2) = domain t1 UNION domain t2
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
domain_num_set_tree_union
null
num_set_tree_union_sym : ! t1 t2 . num_set_tree_union t1 t2 = num_set_tree_union t2 t1
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
num_set_tree_union_sym
null
lookup_num_set_tree_union : !t1 t2 n. lookup n (num_set_tree_union t1 t2) = case lookup n t1 of SOME x => ( case lookup n t2 of SOME y => SOME (union x y) | NONE => SOME x) | NONE => lookup n t2
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
lookup_num_set_tree_union
null
wf_spt_fold_union : ! tree y. (! n x . (lookup n tree = SOME x) ==> wf x) /\ wf y ==> wf (spt_fold union y tree)
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
wf_spt_fold_union
null
wf_closure_spt : ! reachable tree. wf reachable /\ (! n x . lookup n tree = SOME x ==> wf x) ==> wf (closure_spt reachable tree)
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
wf_closure_spt
null
adjacent_domain : ! tree x y . is_adjacent tree x y ==> x IN domain tree
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
adjacent_domain
null
reachable_domain : ! tree x y . is_reachable tree x y ==> (x = y \/ x IN domain tree)
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
reachable_domain
null
reachable_LHS_NOTIN : !tree n x. is_reachable tree n x /\ n NOTIN domain tree ==> n = x
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
reachable_LHS_NOTIN
null
rtc_is_adjacent : (! k . k IN t ==> ! n . (is_adjacent fullTree k n ==> n IN t)) ==> ! x y . RTC (is_adjacent fullTree) x y ==> x IN t ==> y IN t
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
rtc_is_adjacent
null
is_adjacent_num_set_tree_union : ! t1 t2 n m . is_adjacent t1 n m ==> is_adjacent (num_set_tree_union t1 t2) n m
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
is_adjacent_num_set_tree_union
null
is_reachable_num_set_tree_union : ! t1 t2 n m . is_reachable t1 n m ==> is_reachable (num_set_tree_union t1 t2) n m
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
is_reachable_num_set_tree_union
null
closure_spt_lemma : ! reachable tree closure (roots : num set). closure_spt reachable tree = closure /\ roots ⊆ domain reachable /\ (!k. k IN domain reachable ==> ?n. n IN roots /\ is_reachable tree n k) ==> domain closure = {a | ?n. n IN roots /\ is_reachable tree n a}
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
closure_spt_lemma
null
closure_spt_thm : ! tree start. domain (closure_spt start tree) = {a | ?n. n IN domain start /\ is_reachable tree n a}
theorem
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
closure_spt_thm
null
num_set_tree_union_def = (num_set_tree_union LN t2 = t2 : num_set num_map) /\ (num_set_tree_union (LS a) t = case t of | LN => LS a | LS b => LS (union a b) | BN t1 t2 => BS t1 a t2 | BS t1 b t2 => BS t1 (union a b) t2) /\ (num_set_tree_union (BN t1 t2) t = case t of | LN => BN t1 t2 | LS a => BS t1 a t2 | BN t1' t2' => BN (num_set_tree_union t1 t1') (num_set_tree_union t2 t2') | BS t1' a t2' => BS (num_set_tree_union t1 t1') a (num_set_tree_union t2 t2')) /\ (num_set_tree_union (BS t1 a t2) t = case t of | LN => BS t1 a t2 | LS b => BS t1 (union a b) t2 | BN t1' t2' => BS (num_set_tree_union t1 t1') a (num_set_tree_union t2 t2') | BS t1' b t2' => BS (num_set_tree_union t1 t1') (union a b) (num_set_tree_union t2 t2'))
definition
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
num_set_tree_union_def
null
closure_spt_def = closure_spt (reachable: num_set) tree = let sets = inter tree reachable in let nodes = spt_fold union LN sets in if subspt nodes reachable then reachable else closure_spt (union reachable nodes) tree Termination WF_REL_TAC `measure (\ (r,t). size (difference (spt_fold union LN t) r))` >> rw[] >> gvs[subspt_domain, SUBSET_DEF] >> irule size_diff_less >> gvs[domain_union, domain_spt_fold_union, lookup_inter] >> EVERY_CASE_TAC >> gvs[] >> simp[PULL_EXISTS, GSYM CONJ_ASSOC] >> goal_assum drule >> goal_assum drule >> simp[] >> goal_assum (drule_at Any) >> qexists_tac `k` >> simp[]
definition
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
closure_spt_def
null
is_adjacent_def = is_adjacent tree x y = ? aSetx. ( lookup x tree = SOME aSetx ) /\ ( lookup y aSetx = SOME () )
definition
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
is_adjacent_def
null
is_reachable_def = is_reachable tree = RTC (is_adjacent tree)
definition
examples/algorithms
[]
examples/algorithms/spt_closureScript.sml
is_reachable_def
null
partition_LENGTH : !ks n reach xs ys zs xs1 ys1 zs1. partition n ks reach (xs,ys,zs) = (xs1,ys1,zs1) ==> LENGTH xs1 <= LENGTH xs + LENGTH ks /\ LENGTH ys1 <= LENGTH ys + LENGTH ks /\ LENGTH zs1 <= LENGTH zs + LENGTH ks
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
partition_LENGTH
null
top_sort_example : top_sort [(0,fromAList[]); (* 0 has no deps *) (1,fromAList[(2,());(0,())]); (* 1 depens on 2 and 0 *) (2,fromAList[(1,())]); (* 2 depends on 1 *) (3,fromAList[(1,())])] (* 3 depends on 1 *) = [[0]; [1; 2]; [3]] (* 0 defined first, 1 and 2 are mutual, 3 is last *)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_example
null
top_sort_any_example : top_sort_any [("A",[]); (* A has no deps *) ("B",["C";"A"]); (* B depens on C and A *) ("C",["B";"X"]); (* C depends on B and X -- X is intentionally not defined here *) ("D",["B"])] (* D depends on B *) = [["A"]; ["B"; "C"]; ["D"]] (* A defined first, B and C are mutual, D is last *)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_any_example
null
needs_eq_is_adjacent : !x y tree. needs x y tree <=> is_adjacent tree x y
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
needs_eq_is_adjacent
null
partition_lemma : !n ks reach acc xas ybs zcs as bs cs. partition n ks reach acc = (xas,ybs,zcs) /\ acc = (as,bs,cs) ==> ?xs ys zs. xas = xs ++ as /\ ybs = ys ++ bs /\ zcs = zs ++ cs /\ (set (xs ++ ys ++ zs) = set ks) /\ (!x. MEM x ks ==> (MEM x xs <=> ¬ needs x n reach)) /\ (!y. MEM y ks ==> (MEM y ys <=> needs y n reach /\ needs n y reach)) /\ (!z. MEM z ks ==> (MEM z zs <=> needs z n reach /\ ¬ needs n z reach))
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
partition_lemma
null
partition_thm : !n ks reach as bs cs res. partition n ks reach (as, bs, cs) = res ==> ?xs ys zs. res = (xs ++ as, ys ++ bs, zs ++ cs) /\ (set (xs ++ ys ++ zs) = set ks) /\ (!x. MEM x ks ==> (MEM x xs <=> ¬ needs x n reach)) /\ (!y. MEM y ks ==> (MEM y ys <=> needs y n reach /\ needs n y reach)) /\ (!z. MEM z ks ==> (MEM z zs <=> needs z n reach /\ ¬ needs n z reach))
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
partition_thm
null
ALL_DISTINCT_APPEND_SWAP : !l1 l2. ALL_DISTINCT (l1 ++ l2) <=> ALL_DISTINCT (l2 ++ l1)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
ALL_DISTINCT_APPEND_SWAP
null
partition_ALL_DISTINCT : !n ks reach acc xs ys zs as bs cs. partition n ks reach acc = (xs,ys,zs) /\ acc = (as,bs,cs) /\ ALL_DISTINCT (ks ++ as ++ bs ++ cs) ==> ALL_DISTINCT (xs ++ ys ++ zs)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
partition_ALL_DISTINCT
null
top_sort_aux_correct : !ns reach acc resacc. top_sort_aux ns reach acc = resacc /\ (!n m. TC (\a b. needs a b reach) n m ==> needs n m reach) /\ ALL_DISTINCT ns ==> ?res. resacc = res ++ acc /\ ALL_DISTINCT (FLAT res) /\ set (FLAT res) = set ns /\ !xss ys zss y. (* for any element ys in the result res, for any y in that ys: *) res = xss ++ [ys] ++ zss /\ MEM y ys ==> (* for any defined dependencies of y *) !dep. needs y dep reach /\ MEM dep ns ==> (* mutual dependencies must by in ys, all others in xss *) (¬ needs dep y reach <=> MEM dep (FLAT xss)) /\ ( needs dep y reach <=> MEM dep ys)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_aux_correct
null
domain_lookup_num_set : !t k. k IN domain t <=> lookup k t = SOME ()
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
domain_lookup_num_set
null
trans_clos_correct : !nexts n m. needs n m (trans_clos nexts) \/ n = m <=> is_reachable nexts n m
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
trans_clos_correct
null
trans_clos_correct_imp : !nexts n m. (TC (\x y. needs x y nexts)) n m ==> needs n m (trans_clos nexts)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
trans_clos_correct_imp
null
trans_clos_TC_closed : !t n m. TC (\a b. needs a b (trans_clos t)) n m ==> needs n m (trans_clos t)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
trans_clos_TC_closed
null
top_sort_correct_weak : !lets res. ALL_DISTINCT (MAP FST lets) /\ res = top_sort lets ==> ALL_DISTINCT (FLAT res) /\ set (FLAT res) = set (MAP FST lets) /\ !xss ys zss y. (* for any element ys in the result res, for any y in that ys: *) res = xss ++ [ys] ++ zss /\ MEM y ys ==> (* all dependencies of y must be defined in ys or earlier, i.e. xss *) ?deps. ALOOKUP lets y = SOME deps /\ !d. d IN domain deps /\ MEM d (MAP FST lets) ==> MEM d (FLAT xss ++ ys)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_correct_weak
null
top_sort_correct : !lets res. ALL_DISTINCT (MAP FST lets) /\ res = top_sort lets ==> ALL_DISTINCT (FLAT res) /\ set (FLAT res) = set (MAP FST lets) /\ !xss ys zss y. (* for any element ys in the result res, for any y in that ys: *) res = xss ++ [ys] ++ zss /\ MEM y ys ==> (* for any defined dependencies of y *) !dep. is_reachable (fromAList lets) y dep /\ MEM dep (MAP FST lets) ==> (¬ is_reachable (fromAList lets) dep y <=> MEM dep (FLAT xss)) /\ ( is_reachable (fromAList lets) dep y <=> MEM dep ys)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_correct
null
top_sort_aux_same_partition : ∀ns reach acc xs. MEM xs (top_sort_aux ns reach acc) ⇒ ∀x y nexts. (∀n m. TC (λa b. needs a b reach) n m ⇒ needs n m reach) ∧ (∀as x y. MEM as acc ∧ x ≠ y ∧ MEM x as ∧ MEM y as ⇒ needs x y reach) ∧ x ≠ y ∧ MEM x xs ∧ MEM y xs ⇒ needs x y reach
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_aux_same_partition
null
top_sort_same_partition : MEM xs (top_sort graph) ∧ x ≠ y ∧ MEM x xs ∧ MEM y xs ⇒ needs x y (trans_clos $ fromAList graph)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_same_partition
null
SCC_REFL : SCC E x x
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
SCC_REFL
null
SCC_SYM : SCC E x y ⇔ SCC E y x
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
SCC_SYM
null
SCC_TRANS : SCC E x y ∧ SCC E y z ⇒ SCC E x z
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
SCC_TRANS
null
SCC_EQUIV : EQUIV (SCC E)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
SCC_EQUIV
null
is_reachable_IMP_MEM : ALL_DISTINCT (MAP FST graph) ⇒ x ≠ y ⇒ is_reachable (fromAList graph) x y ⇒ MEM x (MAP FST graph)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
is_reachable_IMP_MEM
null
top_sort_SCC : ALL_DISTINCT (MAP FST graph) ∧ MEM x l ∧ MEM l (top_sort graph) ⇒ SCC (is_adjacent (fromAList graph)) x = set l
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_SCC
null
to_nums_correct : !xs b res. to_nums b xs = res /\ ALL_DISTINCT (MAP FST b) ==> domain res = {c | ?d. MEM d xs /\ ALOOKUP b d = SOME c}
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
to_nums_correct
null
ALL_DISTINCT_MAPi_ID : !l. ALL_DISTINCT (MAPi (\i _. i) l)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
ALL_DISTINCT_MAPi_ID
null
ALL_DISTINCT_FLAT : ∀l. ALL_DISTINCT (FLAT l) ⇔ (∀l0. MEM l0 l ⇒ ALL_DISTINCT l0) ∧ (∀i j. i < j ∧ j < LENGTH l ⇒ ∀e. MEM e (EL i l) ⇒ ¬MEM e (EL j l))
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
ALL_DISTINCT_FLAT
null
ALOOKUP_MAPi_ID : !l k. ALOOKUP (MAPi (\i n. (i,n)) l) k = if k < LENGTH l then SOME (EL k l) else NONE
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
ALOOKUP_MAPi_ID
null
ALOOKUP_MAPi_ID_f : !l k. ALOOKUP (MAPi (\i n. (i,f n)) l) k = if k < LENGTH l then SOME (f (EL k l)) else NONE
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
ALOOKUP_MAPi_ID_f
null
MAPi_MAP : !l. MAPi (\i n. f n) l = MAP f l
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
MAPi_MAP
null
MEM_ALOOKUP : !l k v. ALL_DISTINCT (MAP FST l) ==> (MEM (k,v) l <=> ALOOKUP l k = SOME v)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
MEM_ALOOKUP
null
top_sort_any_correct_weak : !lets res. ALL_DISTINCT (MAP FST lets) /\ res = top_sort_any lets ==> ALL_DISTINCT (FLAT res) /\ set (FLAT res) = set (MAP FST lets) /\ !xss ys zss y. (* for any element ys in the result res, for any y in that ys: *) res = xss ++ [ys] ++ zss /\ MEM y ys ==> (* all dependencies of y must be defined in ys or earlier, i.e. xss *) ?deps. ALOOKUP lets y = SOME deps /\ !d. MEM d deps /\ MEM d (MAP FST lets) ==> MEM d (FLAT xss ++ ys)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_any_correct_weak
null
depends_on : depends_on alist = RTC (depends_on1 alist)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
depends_on
null
top_sort_any_depends_on_weak : !lets res. (!xss ys zss y. res = xss ++ [ys] ++ zss /\ MEM y ys ==> ?deps. ALOOKUP lets y = SOME deps /\ !d. MEM d deps /\ MEM d (MAP FST lets) ==> MEM d (FLAT xss ++ ys)) ==> !a b. depends_on lets a b ==> !xss ys zss y. res = xss ++ [ys] ++ zss /\ MEM a ys ==> MEM b (FLAT xss ++ ys)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_any_depends_on_weak
null
top_sort_any_correct : !lets res. ALL_DISTINCT (MAP FST lets) /\ res = top_sort_any lets ==> ALL_DISTINCT (FLAT res) /\ set (FLAT res) = set (MAP FST lets) /\ !xss ys zss y. (* for any element ys in the result res, for any y in that ys: *) res = xss ++ [ys] ++ zss /\ MEM y ys ==> (* all dependencies of y must be defined in ys or earlier, i.e. xss *) !dep. depends_on lets y dep ==> MEM dep (FLAT xss ++ ys) /\ (depends_on lets dep y ==> MEM dep ys)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_any_correct
null
MEM_MEM_top_sort : ALL_DISTINCT (MAP FST l) ∧ MEM xs $ top_sort l ∧ MEM n xs ⇒ MEM n (MAP FST l)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
MEM_MEM_top_sort
null
ALL_DISTINCT_enc_graph : ALL_DISTINCT (MAPi ($o FST o (λi (n,ns). (i,to_nums (MAPi (λi n. (n,i)) (MAP FST graph)) ns))) graph)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
ALL_DISTINCT_enc_graph
null
RTC_ALOOKUP_enc_graph_IMP_depends_on : ALL_DISTINCT (MAP FST graph) ⇒ ∀n n'. RTC (λx y. ∃aSetx. ALOOKUP (MAPi (λi (n,ns). (i,to_nums (MAPi (λi n. (n,i)) (MAP FST graph)) ns)) graph) x = SOME aSetx ∧ lookup y aSetx = SOME ()) n n' ⇒ depends_on graph (EL n (MAP FST graph)) (EL n' (MAP FST graph))
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
RTC_ALOOKUP_enc_graph_IMP_depends_on
null
top_sort_any_same_partition : ALL_DISTINCT (MAP FST graph) ∧ MEM xs (top_sort_any graph) ∧ MEM x xs ∧ MEM y xs ⇒ depends_on graph x y
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_any_same_partition
null
top_sort_any_SCC : ALL_DISTINCT (MAP FST graph) ∧ MEM x l ∧ MEM l (top_sort_any graph) ⇒ SCC (depends_on1 graph) x = set l
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_any_SCC
null
cycle_CASES_lem : ∀x z. TC R x z ⇒ x = z ⇒ (R x z ∨ (∃y. x ≠ y ∧ TC R x y ∧ TC R y z))
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
cycle_CASES_lem
null
cycle_CASES : TC R x x ⇔ (R x x ∨ (∃y. x ≠ y ∧ TC R x y ∧ TC R y x))
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
cycle_CASES
null
depends_on_IMP_MEM : ∀x y. depends_on graph x y ⇒ x ≠ y ⇒ MEM y (MAP FST graph)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
depends_on_IMP_MEM
null
TC_depends_on_SCC : x ≠ y ⇒ SCC (depends_on1 graph) x y = (TC_depends_on graph x y ∧ TC_depends_on graph y x)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
TC_depends_on_SCC
null
ONE_LT_LENGTH_ALL_DISTINCT_IMP : 1 < LENGTH l ∧ ALL_DISTINCT l ⇒ ∃x y. MEM x l ∧ MEM y l ∧ x ≠ y
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
ONE_LT_LENGTH_ALL_DISTINCT_IMP
null
DISTINCT_IMP_ONE_LT_LENGTH : MEM x l ∧ MEM y l ∧ x ≠ y ⇒ 1 < LENGTH l
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
DISTINCT_IMP_ONE_LT_LENGTH
null
has_cycle_correct : ALL_DISTINCT (MAP FST graph) ⇒ (has_cycle graph ⇔ ∃x. TC_depends_on graph x x)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
has_cycle_correct
null
TC_depends_on_weak_IMP_MEM : ∀x y. TC_depends_on_weak graph x y ⇒ MEM x (MAP FST graph)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
TC_depends_on_weak_IMP_MEM
null
TC_depends_on_weak_IMP_TC_depends_on : ∀x y. TC_depends_on_weak graph x y ⇒ MEM y (MAP FST graph) ⇒ TC_depends_on graph x y
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
TC_depends_on_weak_IMP_TC_depends_on
null
TC_depends_on_TC_depends_on_weak_thm : ∀x y. TC_depends_on graph x y = (TC_depends_on_weak graph x y ∧ MEM y (MAP FST graph))
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
TC_depends_on_TC_depends_on_weak_thm
null
TC_depends_on_weak_cycle_thm : TC_depends_on_weak graph x x = TC_depends_on graph x x
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
TC_depends_on_weak_cycle_thm
null
has_cycle_correct2 : ALL_DISTINCT (MAP FST graph) ⇒ (has_cycle graph ⇔ ∃x. TC_depends_on_weak graph x x)
theorem
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
has_cycle_correct2
null
needs_def = needs n m (reach:num_set num_map) = case lookup n reach of | NONE => F (* cannot happen *) | SOME s => IS_SOME (lookup m s)
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
needs_def
null
partition_def = partition n [] reach acc = acc /\ partition n (k::ks) reach (xs,ys,zs) = if needs k n reach then if needs n k reach then partition n ks reach (xs,k::ys,zs) else partition n ks reach (xs,ys,k::zs) else partition n ks reach (k::xs,ys,zs)
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
partition_def
null
top_sort_aux_def = top_sort_aux [] reach acc = acc /\ top_sort_aux (n::ns) reach acc = let (xs,ys,zs) = partition n ns reach ([],[],[]) in top_sort_aux xs reach ((n::ys) :: top_sort_aux zs reach acc) Termination WF_REL_TAC `measure (LENGTH o FST)` \\ rw [] \\ pop_assum (assume_tac o GSYM) \\ imp_res_tac partition_LENGTH \\ fs []
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_aux_def
null
trans_clos_def = (* computes the transitive closure for each node given nexts *) trans_clos nexts = map (\x. closure_spt x nexts) nexts
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
trans_clos_def
null
top_sort_def = top_sort (let_bindings : (num (* name *) # num_set (* free vars *)) list) = let roots = MAP FST let_bindings in let nexts = fromAList let_bindings in let reach = trans_clos nexts in top_sort_aux roots reach []
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_def
null
to_nums_def = to_nums b [] = LN /\ to_nums b (x::xs) = case ALOOKUP b x of | NONE => to_nums b xs | SOME n => insert n () (to_nums b xs)
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
to_nums_def
null
top_sort_any_def = top_sort_any (lets : ('a # 'a list) list) = if NULL lets (* so that HD names, below, is well defined *) then [] else let names = MAP FST lets in let to_num = MAPi (\i n. (n,i)) names in let from_num = fromAList (MAPi (\i n. (i,n)) names) in let nesting = top_sort (MAPi (\i (n,ns). (i,to_nums to_num ns)) lets) in MAP (MAP (\n. case lookup n from_num of SOME m => m | _ => HD (names))) nesting
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
top_sort_any_def
null
has_cycle_def = has_cycle graph = ((EXISTS (λl. 1 < LENGTH l) $ top_sort_any graph) ∨ EXISTS (λ(v,l). MEM v l) graph)
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
has_cycle_def
null
SCC_def = SCC E x y ⇔ RTC E x y ∧ RTC E y x
definition
examples/algorithms
[]
examples/algorithms/topological_sortScript.sml
SCC_def
null