Skip to content

Commit 14c59b5

Browse files
Partially prove pathCompressCommute
1 parent d5f5259 commit 14c59b5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

theories/DisjointSetUnionCode.v

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,33 @@ Proof.
485485
{ rewrite nth_lookup, list_lookup_insert_ne; [| exact hs]. rewrite <- nth_lookup. reflexivity. } rewrite step2 in step. rewrite (step hd). reflexivity.
486486
Qed.
487487

488+
Lemma withoutCyclesExtractAncestor (dsu : list Slot) (h2 : withoutCyclesN dsu (length dsu)) (a : nat) (hA : a < length dsu) : exists k, nth (ancestor dsu (length dsu) a) dsu (Ancestor Unit) = Ancestor k.
489+
Proof.
490+
pose proof h2 a hA as step.
491+
destruct (nth (ancestor dsu (length dsu) a) dsu (Ancestor Unit)) as [g | g]. { exfalso. exact step. } exists g. reflexivity.
492+
Qed.
493+
494+
Lemma pathCompressCommute (dsu : list Slot) (h1 : noIllegalIndices dsu) (h2 : withoutCyclesN dsu (length dsu)) (fuel : nat) (a b : nat) (hA : a < length dsu) (hB : b < length dsu) : pathCompress (pathCompress dsu fuel a (ancestor dsu (length dsu) a)) fuel b (ancestor dsu (length dsu) b) = pathCompress (pathCompress dsu fuel b (ancestor dsu (length dsu) b)) fuel a (ancestor dsu (length dsu) a).
495+
Proof.
496+
revert a b dsu h1 h2 hA hB. induction fuel as [| fuel IH]. { easy. }
497+
intros a b dsu h1 h2 hA hB. simpl.
498+
remember (nth a dsu (Ancestor Unit)) as u eqn:hu.
499+
remember (nth b dsu (Ancestor Unit)) as v eqn:hv.
500+
pose proof withoutCyclesExtractAncestor dsu h2 a hA as [ka hka].
501+
pose proof withoutCyclesExtractAncestor dsu h2 b hB as [kb hkb].
502+
destruct u as [u | u]; destruct v as [v | v]; symmetry in hu; symmetry in hv.
503+
- admit.
504+
- rewrite hu.
505+
assert (si : nth b (<[a:=ReferTo (ancestor dsu (length dsu) a)]> dsu) (Ancestor Unit) = Ancestor v).
506+
{ destruct (decide (a = b)) as [hs | hs]; rewrite nth_lookup. { subst a. rewrite hu in hv. easy. } rewrite list_lookup_insert_ne; [| lia]. rewrite <- nth_lookup. assumption. }
507+
rewrite (pathCompressPreservesNth _ _ _ _ _ v); rewrite si; reflexivity.
508+
- rewrite hv.
509+
assert (si : nth a (<[b:=ReferTo (ancestor dsu (length dsu) b)]> dsu) (Ancestor Unit) = Ancestor u).
510+
{ destruct (decide (a = b)) as [hs | hs]; rewrite nth_lookup. { subst a. rewrite hu in hv. easy. } rewrite list_lookup_insert_ne; [| lia]. rewrite <- nth_lookup. assumption. }
511+
rewrite (pathCompressPreservesNth _ _ _ _ _ u); rewrite si; reflexivity.
512+
- rewrite hu. rewrite hv. reflexivity.
513+
Qed.
514+
488515
Definition performMerge (dsu : list Slot) (tree1 tree2 : Tree) (u v : nat) :=
489516
<[u := ReferTo v]> (<[v := Ancestor (Unite tree2 tree1)]> dsu).
490517

0 commit comments

Comments
 (0)