@@ -3366,6 +3366,22 @@ Proof
33663366 metis_tac[IS_PREFIX_LENGTH_ANTI]
33673367QED
33683368
3369+ (* lcp2: binary longest common prefix *)
3370+ Definition lcp2_def:
3371+ lcp2 x y = longest_prefix {x;y}
3372+ End
3373+
3374+ Theorem lcp2_thm:
3375+ lcp2 xs ys =
3376+ case xs of
3377+ | x::xs => (case ys of
3378+ | y::ys => if x = y then x :: lcp2 xs ys else []
3379+ | _ => [])
3380+ | _ => []
3381+ Proof
3382+ Cases_on `xs` >> Cases_on `ys` >> rw[lcp2_def, longest_prefix_PAIR]
3383+ QED
3384+
33693385(* lcp: longest common prefix of a list of lists *)
33703386Definition lcp_def:
33713387 lcp ls = longest_prefix (set ls)
@@ -3383,50 +3399,52 @@ Proof
33833399 simp[lcp_def]
33843400QED
33853401
3386- (* Helper: longest_prefix {x;y} is a prefix of both x and y *)
3387- Theorem longest_prefix_PAIR_prefix :
3388- longest_prefix {x;y} <<= x /\ longest_prefix {x;y} <<= y
3402+ (* lcp2 is a prefix of both arguments *)
3403+ Theorem lcp2_prefix :
3404+ lcp2 x y <<= x /\ lcp2 x y <<= y
33893405Proof
3406+ simp[lcp2_def] >>
33903407 MAP_EVERY qid_spec_tac [`y`,`x`] >>
33913408 Induct >> simp[longest_prefix_PAIR] >>
33923409 gen_tac >> Cases >> simp[longest_prefix_PAIR] >> rw[]
33933410QED
33943411
3395- (* Helper: any common prefix of x and y is a prefix of longest_prefix {x;y} *)
3396- Theorem longest_prefix_PAIR_maximal :
3397- p <<= x /\ p <<= y ==> p <<= longest_prefix {x;y}
3412+ (* any common prefix of x and y is a prefix of lcp2 x y *)
3413+ Theorem lcp2_maximal :
3414+ p <<= x /\ p <<= y ==> p <<= lcp2 x y
33983415Proof
3416+ simp[lcp2_def] >>
33993417 MAP_EVERY qid_spec_tac [`y`,`x`,`p`] >>
34003418 Induct >- simp[] >>
34013419 rpt strip_tac >>
34023420 Cases_on `x` >> fs[] >>
34033421 Cases_on `y` >> fs[longest_prefix_PAIR] >> rw[]
34043422QED
34053423
3406- (* Key lemma: replacing {x;y} with {lcp {x;y} } preserves common_prefixes *)
3424+ (* Key lemma: replacing {x;y} with {lcp2 x y } preserves common_prefixes *)
34073425Theorem common_prefixes_INSERT2:
34083426 common_prefixes ({x; y} UNION rest) =
3409- common_prefixes ({longest_prefix {x; y} } UNION rest)
3427+ common_prefixes ({lcp2 x y } UNION rest)
34103428Proof
3411- simp[common_prefixes_def, EXTENSION] >>
3429+ simp[lcp2_def, common_prefixes_def, EXTENSION] >>
34123430 gen_tac >> eq_tac >> rw[] >>
3413- metis_tac[longest_prefix_PAIR_maximal, longest_prefix_PAIR_prefix , IS_PREFIX_TRANS]
3431+ metis_tac[lcp2_def, lcp2_maximal, lcp2_prefix , IS_PREFIX_TRANS]
34143432QED
34153433
3416- (* Key lemma: replacing {x;y} with {lcp {x;y} } preserves longest_prefix *)
3434+ (* Key lemma: replacing {x;y} with {lcp2 x y } preserves longest_prefix *)
34173435Theorem longest_prefix_INSERT2:
3418- longest_prefix ({x; y} UNION rest) = longest_prefix ({longest_prefix {x;y} } UNION rest)
3436+ longest_prefix ({x; y} UNION rest) = longest_prefix ({lcp2 x y } UNION rest)
34193437Proof
3420- `{x; y} UNION rest <> {} /\ {longest_prefix {x;y} } UNION rest <> {}`
3438+ `{x; y} UNION rest <> {} /\ {lcp2 x y } UNION rest <> {}`
34213439 by simp[] >>
3422- simp[longest_prefix_def, common_prefixes_INSERT2]
3440+ simp[longest_prefix_def, lcp2_def, common_prefixes_INSERT2]
34233441QED
34243442
34253443Theorem lcp_cons2:
3426- lcp (x::y::xs) = lcp (longest_prefix {x;y} :: xs)
3444+ lcp (x::y::xs) = lcp (lcp2 x y :: xs)
34273445Proof
3428- simp[lcp_def] >>
3429- metis_tac[longest_prefix_INSERT2, INSERT_UNION_EQ, UNION_EMPTY, INSERT_SING_UNION]
3446+ simp[lcp_def, lcp2_def ] >>
3447+ metis_tac[lcp2_def, longest_prefix_INSERT2, INSERT_UNION_EQ, UNION_EMPTY, INSERT_SING_UNION]
34303448QED
34313449
34323450Theorem lcp_thm:
@@ -3448,33 +3466,17 @@ Proof
34483466 metis_tac[IS_PREFIX_LENGTH, IS_PREFIX_LENGTH_ANTI, LESS_EQUAL_ANTISYM])
34493467QED
34503468
3451- Theorem longest_prefix_assoc:
3452- longest_prefix {longest_prefix {x;y}; z} =
3453- longest_prefix {x; longest_prefix {y;z}}
3469+ Theorem lcp2_assoc:
3470+ lcp2 (lcp2 x y) z = lcp2 x (lcp2 y z)
34543471Proof
3472+ simp[lcp2_def] >>
34553473 MAP_EVERY qid_spec_tac [`z`,`y`,`x`] >>
34563474 Induct >> rw[longest_prefix_PAIR] >>
34573475 Cases_on `y` >> rw[longest_prefix_PAIR] >>
34583476 Cases_on `z` >> rw[longest_prefix_PAIR] >>
34593477 rw[] >> fs[longest_prefix_PAIR]
34603478QED
34613479
3462- (* lcp2: binary longest common prefix for cv_trans *)
3463- Definition lcp2_def:
3464- lcp2 x y = longest_prefix {x;y}
3465- End
3466-
3467- Theorem lcp2_thm:
3468- lcp2 xs ys =
3469- case xs of
3470- | x::xs => (case ys of
3471- | y::ys => if x = y then x :: lcp2 xs ys else []
3472- | _ => [])
3473- | _ => []
3474- Proof
3475- Cases_on `xs` >> Cases_on `ys` >> rw[lcp2_def, longest_prefix_PAIR]
3476- QED
3477-
34783480Theorem lcp_oneline:
34793481 lcp ls =
34803482 case ls of
@@ -3483,15 +3485,15 @@ Theorem lcp_oneline:
34833485 | x::y::xs => lcp (lcp2 x y :: xs)
34843486Proof
34853487 Cases_on `ls` >> rw[lcp_nil, lcp_sing] >>
3486- Cases_on `t` >> rw[lcp_sing, lcp_cons2, lcp2_def ]
3488+ Cases_on `t` >> rw[lcp_sing, lcp_cons2]
34873489QED
34883490
34893491Theorem lcp_CONS:
34903492 lcp (x::xs) = if NULL xs then x else lcp2 x (lcp xs)
34913493Proof
34923494 qid_spec_tac `x` >>
3493- Induct_on `xs` >> rw[lcp_sing, lcp_cons2, lcp2_def ] >>
3494- simp[longest_prefix_assoc ]
3495+ Induct_on `xs` >> rw[lcp_sing, lcp_cons2] >>
3496+ simp[lcp2_def, lcp2_assoc ]
34953497QED
34963498
34973499Theorem lcp2_is_nil:
0 commit comments