Skip to content

Commit

Permalink
Add some theorems about dropWhile
Browse files Browse the repository at this point in the history
  • Loading branch information
xrchz committed Dec 15, 2024
1 parent 9c5d06b commit aa170a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/list/src/listScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -4734,6 +4734,16 @@ val EL_LENGTH_dropWhile_REVERSE = Q.store_thm("EL_LENGTH_dropWhile_REVERSE",
>> fs [NOT_EVERY, dropWhile_APPEND_EXISTS, arithmeticTheory.ADD1])
end

Theorem dropWhile_id:
(dropWhile P ls = ls) <=> NULL ls \/ ~P(HD ls)
Proof
Cases_on`ls` \\ rw[dropWhile_def, NULL]
\\ disch_then(mp_tac o Q.AP_TERM`LENGTH`)
\\ Q.MATCH_GOALSUB_RENAME_TAC`dropWhile P l`
\\ Q.SPECL_THEN[`P`,`l`]mp_tac LENGTH_dropWhile_LESS_EQ
\\ simp[]
QED

val IMP_EVERY_LUPDATE = store_thm("IMP_EVERY_LUPDATE",
“!xs h i. P h /\ EVERY P xs ==> EVERY P (LUPDATE h i xs)”,
Induct THEN fs [LUPDATE_def] THEN REPEAT STRIP_TAC
Expand Down
22 changes: 21 additions & 1 deletion src/list/src/rich_listScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open HolKernel Parse boolLib BasicProvers;
open numLib metisLib simpLib combinTheory arithmeticTheory prim_recTheory
pred_setTheory listTheory pairTheory markerLib TotalDefn;

local open listSimps pred_setSimps in end;
local open listSimps pred_setSimps dep_rewrite in end;

val FILTER_APPEND = FILTER_APPEND_DISTRIB
val REVERSE = REVERSE_SNOC_DEF
Expand Down Expand Up @@ -3783,6 +3783,26 @@ Proof
QED
(* END more lemmas of IS_SUFFIX *)

Theorem IS_SUFFIX_dropWhile:
IS_SUFFIX ls (dropWhile P ls)
Proof
Induct_on`ls`
\\ rw[IS_SUFFIX_CONS]
QED

Theorem LENGTH_dropWhile_id:
(LENGTH (dropWhile P ls) = LENGTH ls) <=> (dropWhile P ls = ls)
Proof
rw[EQ_IMP_THM]
\\ rw[dropWhile_id]
\\ Cases_on`ls` \\ fs[]
\\ strip_tac \\ fs[]
\\ `IS_SUFFIX t (dropWhile P t)` by simp[IS_SUFFIX_dropWhile]
\\ fs[IS_SUFFIX_APPEND]
\\ `LENGTH t = LENGTH l + LENGTH (dropWhile P t)` by metis_tac[LENGTH_APPEND]
\\ fs[]
QED

Theorem nub_GENLIST:
nub (GENLIST f n) =
MAP f (FILTER (\i. !j. (i < j) /\ (j < n) ==> f i <> f j) (COUNT_LIST n))
Expand Down

0 comments on commit aa170a5

Please sign in to comment.