From 7e9faf7bcfbbc55084543bc2cb79d954a2f6f9e4 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Sun, 17 Mar 2024 07:12:44 +0000 Subject: [PATCH] Added a basic implementation of BDDs as a HOL derived rule, in the new file Library/bdd.ml, together with some examples of usage in the other new file Examples/bdd_examples.ml The style of implementation follows Brace, Rudell and Bryant's paper "Efficient implementation of a BDD package" (DAC 1990). This implementation is distantly descended from the hol90 implementation in "Binary Decision Diagrams as a HOL Derived Rule", but greatly simplified since HOL Light handles pointer-eq subterms more efficiently and so we can avoid introducing any additional variables. Also added an extra utility function "atoms" for returning the set of propositional atomic formulas in a Boolean term. Made a number of explicit type variable choices in theorems (and occasionally fixed up or added quantifiers), just so things look tidier with the new default print_types_of_subterms=1. Added miscelleneous theorems, in particular quite a few connected with the concept of "square-free": CARD_IMAGE_LE2 CARD_IMAGE_LT2 FORALL_PRIME_INDEX IMAGE_EQ ISOMORPHIC_PROD_INTEGER_MOD_RING RING_CARRIER_INTEGER_MOD_RING RING_HOMOMORPHISM_PROD_INTEGER_MOD_RING RING_ISOMORPHISM_PROD_INTEGER_MOD_RING RING_OF_INT_PROD_RING RING_OF_NUM_PROD_RING SQUAREFREE,SQUAREFREE_ALT SQUAREFREE_DIVEXP SQUAREFREE_DIVEXP_EQ SQUAREFREE_DIVIDES SQUAREFREE_GCD SQUAREFREE_GCD_SQUARE VNREGULAR_INTEGER_MOD_RING --- 100/polyhedron.ml | 4 +- CHANGES | 133 ++++++ Examples/bdd_examples.ml | 423 +++++++++++++++++ Help/atoms.hlp | 32 ++ Help/frees.hlp | 2 +- Library/bdd.ml | 417 +++++++++++++++++ Library/grouptheory.ml | 20 +- Library/pocklington.ml | 57 +++ Library/prime.ml | 9 + Library/ringtheory.ml | 102 +++- Minisat/minisat_prove.ml | 15 +- Multivariate/cauchy.ml | 3 +- Multivariate/complex_database.ml | 21 + Multivariate/convex.ml | 4 +- Multivariate/homology.ml | 4 +- Multivariate/measure.ml | 6 +- Multivariate/metric.ml | 14 +- Multivariate/misc.ml | 3 +- Multivariate/multivariate_database.ml | 21 + Multivariate/paths.ml | 6 +- Multivariate/topology.ml | 9 +- Multivariate/vectors.ml | 4 +- basics.ml | 17 + cart.ml | 70 +-- class.ml | 2 +- database.ml | 7 + holtest | 2 + holtest.mk | 2 + ind_types.ml | 4 +- int.ml | 4 +- iterate.ml | 413 +++++++++-------- lists.ml | 181 ++++---- pair.ml | 40 +- sets.ml | 644 +++++++++++++++----------- theorems.ml | 4 +- wf.ml | 6 +- 36 files changed, 2022 insertions(+), 683 deletions(-) create mode 100644 Examples/bdd_examples.ml create mode 100644 Help/atoms.hlp create mode 100644 Library/bdd.ml mode change 100644 => 100755 Minisat/minisat_prove.ml mode change 100644 => 100755 basics.ml mode change 100644 => 100755 class.ml mode change 100644 => 100755 ind_types.ml mode change 100644 => 100755 pair.ml mode change 100644 => 100755 theorems.ml diff --git a/100/polyhedron.ml b/100/polyhedron.ml index 8471f42c..0d52a06e 100644 --- a/100/polyhedron.ml +++ b/100/polyhedron.ml @@ -1364,9 +1364,7 @@ let EULER_POLYHEDRAL_CONE = prove {{x | (fa:(real^N->bool)->real^N) h dot x <= &0} | h IN J}` SUBST1_TAC THENL [ONCE_REWRITE_TAC[SIMPLE_IMAGE] THEN - REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC IMAGE_EQ THEN GEN_TAC THEN DISCH_TAC THEN REWRITE_TAC[] THEN MATCH_MP_TAC CLOSURE_HALFSPACE_LT THEN ASM SET_TAC[]; ALL_TAC] THEN diff --git a/CHANGES b/CHANGES index 5bf381cf..ce2ad450 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,138 @@ * page: https://github.com/jrh13/hol-light/commits/master * * ***************************************************************** +Fri 15th Mar 2024 Library/bdd.ml [new file], Examples/bdd_examples.ml [new file] + +Added a new file giving a basic implementation (as a HOL derived rule) of +ordered binary decision diagrams with complement edges, a canonical form for +Boolean formulas. The style of implementation follows Brace, Rudell and +Bryant's paper "Efficient implementation of a BDD package" (DAC 1990). This +implementation is distantly descended from the hol90 implementation in "Binary +Decision Diagrams as a HOL Derived Rule", but greatly simplified since HOL +Light handles pointer-eq subterms more efficiently and so we can avoid +introducing any additional variables. + +The two top-level functions are BDD_TAUT just taking a formula and BDD_DEFTAUT +taking both a list of variables determining the BDD variable order (allowed to +be empty in which case the default is used) and a formula that is also allowed +to contain "definitions". The examples in Examples/bdd_examples.ml give an idea +how to use these options. + +Fri 15th Mar 2024 passim + +Made a number of explicit type variable choices in theorems (and occasionally +fixed up or added quantifiers), just so things look tidier. + +Thu 14th Mar 2024 Makefile, README, .github/workflows/main.yml, .gitignore [new file], hol_4.14.sh [new file], hol_4.sh [new file] + +Added an update from June Lee that automatically creates (as part of +the default "make" target) a shell script "hol.sh" to run HOL Light +directly. + +Wed 13th Mar 2024 Library/ringtheory.ml + +Added a few more ring theory lemmas, mainly basic machinery including the +usual "Chinese remainder theorem" facts about Z_{m*n}, and also the simple +but rather obscure fact that Z_n is a von Neumann regular ring iff n is +squarefree: + + ISOMORPHIC_PROD_INTEGER_MOD_RING = + |- !m n. + integer_mod_ring (m * n) isomorphic_ring + prod_ring (integer_mod_ring m) (integer_mod_ring n) <=> + coprime(m,n) + + RING_CARRIER_INTEGER_MOD_RING = + |- !n. ring_carrier (integer_mod_ring n) = IMAGE (\x. x rem &n) (:int) + + RING_HOMOMORPHISM_PROD_INTEGER_MOD_RING = + |- !m n. + ring_homomorphism + (integer_mod_ring (m * n), + prod_ring (integer_mod_ring m) (integer_mod_ring n)) + (\a. a rem &m,a rem &n) + + RING_ISOMORPHISM_PROD_INTEGER_MOD_RING = + |- !m n. + ring_isomorphism + (integer_mod_ring (m * n), + prod_ring (integer_mod_ring m) (integer_mod_ring n)) + (\a. a rem &m,a rem &n) <=> + coprime(m,n) + + RING_OF_INT_PROD_RING = + |- !r s n. ring_of_int (prod_ring r s) n = ring_of_int r n,ring_of_int s n + + RING_OF_NUM_PROD_RING = + |- !r s n. ring_of_num (prod_ring r s) n = ring_of_num r n,ring_of_num s n + + VNREGULAR_INTEGER_MOD_RING = + |- !n. vnregular_ring (integer_mod_ring n) <=> squarefree n + +Wed 13th Mar 2024 Library/prime.ml, Library/pocklington.ml + +Added a few more number theory lemmas, mainly involving "squarefree": + + FORALL_PRIME_INDEX = + |- (!p. prime p ==> (!P. (!x. P (index p x)) <=> (!k. P k))) /\ + (!p. prime p ==> (!P. (!x. ~(x = 0) ==> P (index p x)) <=> (!k. P k))) + + SQUAREFREE = + |- !n. squarefree n <=> + ~(n = 0) /\ (!m k. n divides m EXP k ==> n divides m) + + SQUAREFREE_ALT = + |- !n. squarefree n <=> ~(n = 0) /\ (!m. n divides m EXP 2 ==> n divides m) + + SQUAREFREE_DIVEXP = + |- !n q x. squarefree q /\ q divides x EXP n ==> q divides x + + SQUAREFREE_DIVEXP_EQ = + |- !n q x. squarefree q /\ ~(n = 0) ==> (q divides x EXP n <=> q divides x) + + SQUAREFREE_DIVIDES = + |- !q n. + squarefree q + ==> (q divides n <=> (!p. prime p /\ p divides q ==> p divides n)) + + SQUAREFREE_GCD = + |- !m n. squarefree m \/ squarefree n ==> squarefree (gcd (m,n)) + + SQUAREFREE_GCD_SQUARE = + |- !n. squarefree n <=> (!x. gcd (x EXP 2,n) divides x) + +Tue 12th Mar 2024 sets.ml, passim + +Added one basic lemma that was previously regenerated many times via +SET_RULE + + IMAGE_EQ = + |- !f g s. (!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s + +as well as a couple of elaborations of "image of a set is <= the set" +using two different imaging functions: + + CARD_IMAGE_LE2 = + |- !f g s. + FINITE s /\ (!x y. x IN s /\ y IN s /\ g x = g y ==> f x = f y) + ==> CARD(IMAGE f s) <= CARD(IMAGE g s) + + CARD_IMAGE_LT2 = + |- !f g s. + FINITE s /\ + (!x y. x IN s /\ y IN s /\ g x = g y ==> f x = f y) /\ + ~(!x y. x IN s /\ y IN s /\ f x = f y ==> g x = g y) + ==> CARD(IMAGE f s) < CARD(IMAGE g s) + +Mon 11th Mar 2024 basics.ml, Minisat/minisat_prove.ml + +Added a function "atoms" to return the set (as a list with no repetitions +but arbitrary order) of atomic formulas in a term, considering it as a +propositional formula and any non-propositional subterms as atomic: + + # atoms `x < 1 \/ x > 1 ==> ~(x = 1)`;; + val it : term list = [`x < 1`; `x > 1`; `x = 1`] + Fri 1st Mar 2024 Library/words.ml Added a few more miscellaneous word lemmas: @@ -86,6 +218,7 @@ atomic formulas are arbitrary. Also made a few modernizations to the two README files to better reflect the current experience with MiniSat and zchaff. + Wed 21st Feb 2024 EC/jacobian.ml Added some alternative definitions of Jacobian-coordinate elliptic curve diff --git a/Examples/bdd_examples.ml b/Examples/bdd_examples.ml new file mode 100644 index 00000000..dc5bc04b --- /dev/null +++ b/Examples/bdd_examples.ml @@ -0,0 +1,423 @@ +(* ========================================================================= *) +(* A few simple examples of using the BDD library to prove tautologies. *) +(* ========================================================================= *) + +needs "Library/bdd.ml";; + +(* ------------------------------------------------------------------------- *) +(* First a few basic tautologies with BDD_TAUT *) +(* ------------------------------------------------------------------------- *) + +BDD_TAUT + `((p <=> q) <=> r) <=> (p <=> (q <=> r))`;; + +let syn323_1 = + `~((v0 \/ v1) /\ (~v0 \/ v1) /\ (~v1 \/ v0) /\ (~v0 \/ ~v1))` in +BDD_TAUT syn323_1;; + +let gra001_1 = +`~((~v1 \/ v0) /\ + (~v0 \/ v1) /\ + (~v4 \/ ~v2 \/ ~v0) /\ + (~v4 \/ v2 \/ v0) /\ + (~v2 \/ v4 \/ v0) /\ + (~v0 \/ v4 \/ v2) /\ + (~v3 \/ ~v2 \/ ~v1) /\ + (~v3 \/ v2 \/ v1) /\ + (~v2 \/ v3 \/ v1) /\ + (~v1 \/ v3 \/ v2) /\ + (~v3 \/ ~v4) /\ + (v3 \/ v4))` in +BDD_TAUT gra001_1;; + +(* ------------------------------------------------------------------------- *) +(* The same formula considered ithout and with definitions. *) +(* ------------------------------------------------------------------------- *) + +let rip02_be = + `(car1 <=> (a1 /\ b1)) /\ + (cout <=> ((a2 \/ b2) /\ car1 \/ a2 /\ b2)) /\ + (som2 <=> ~(a2 <=> ~(b2 <=> car1))) /\ + (som1 <=> ~(a1 <=> b1)) /\ + (cout1 <=> (b1 /\ a1)) + ==> (som1 <=> ~(~a1 /\ ~b1 \/ a1 /\ b1)) /\ + (som2 <=> + ~((~a2 /\ ~b2 \/ a2 /\ b2) /\ ~cout1 \/ + cout1 /\ ~(~a2 /\ ~b2 \/ a2 /\ b2))) /\ + (cout <=> (a2 /\ cout1 \/ b2 /\ cout1 \/ a2 /\ b2))`;; + +BDD_TAUT rip02_be;; +BDD_DEFTAUT [] rip02_be;; + +(* ------------------------------------------------------------------------- *) +(* With a specific variable order. *) +(* ------------------------------------------------------------------------- *) + +let add4_be = + `(n3 <=> a_0_) /\ + (n4 <=> a_2_) /\ + (n5 <=> a_4_) /\ + (n6 <=> a_5_) /\ + (n7 <=> a_6_) /\ + (n8 <=> a_8_) /\ + (n9 <=> a_3_) /\ + (n10 <=> a_7_) /\ + (n11 <=> a_9_) /\ + (n12 <=> a_11_) /\ + (n13 <=> a_1_) /\ + (n14 <=> a_10_) /\ + (n15 <=> anda) /\ + (n16 <=> exora) /\ + (n17 <=> b_3_) /\ + (n18 <=> b_4_) /\ + (n19 <=> b_6_) /\ + (n20 <=> b_1_) /\ + (n21 <=> b_7_) /\ + (n22 <=> b_9_) /\ + (n23 <=> b_2_) /\ + (n24 <=> b_5_) /\ + (n25 <=> b_8_) /\ + (n26 <=> b_10_) /\ + (n27 <=> b_11_) /\ + (n28 <=> b_0_) /\ + (n29 <=> andb) /\ + (n30 <=> exorb) /\ + (n31 <=> carryin) /\ + (n98 <=> ~n29) /\ + (n104 <=> ~n30) /\ + (n97 <=> ~n15) /\ + (n103 <=> ~n16) /\ + (n102 <=> ~n31) /\ + (n105 <=> ~n102) /\ + (n243 <=> ~n14 \/ ~n97) /\ + (n235 <=> ~n103) /\ + (n244 <=> ~n26 \/ ~n98) /\ + (n236 <=> ~n104) /\ + (n224 <=> ~n22 \/ ~n98) /\ + (n232 <=> ~n104) /\ + (n223 <=> ~n11 \/ ~n97) /\ + (n231 <=> ~n103) /\ + (n217 <=> ~n8 \/ ~n97) /\ + (n209 <=> ~n103) /\ + (n218 <=> ~n25 \/ ~n98) /\ + (n210 <=> ~n104) /\ + (n197 <=> ~n21 \/ ~n98) /\ + (n206 <=> ~n104) /\ + (n196 <=> ~n10 \/ ~n97) /\ + (n205 <=> ~n103) /\ + (n190 <=> ~n19 \/ ~n98) /\ + (n182 <=> ~n104) /\ + (n189 <=> ~n7 \/ ~n97) /\ + (n181 <=> ~n103) /\ + (n251 <=> ~n27 \/ ~n98) /\ + (n259 <=> ~n104) /\ + (n250 <=> ~n12 \/ ~n97) /\ + (n258 <=> ~n103) /\ + (n163 <=> ~n18 \/ ~n98) /\ + (n155 <=> ~n104) /\ + (n162 <=> ~n5 \/ ~n97) /\ + (n154 <=> ~n103) /\ + (n170 <=> ~n24 \/ ~n98) /\ + (n178 <=> ~n104) /\ + (n169 <=> ~n6 \/ ~n97) /\ + (n177 <=> ~n103) /\ + (n136 <=> ~n23 \/ ~n98) /\ + (n128 <=> ~n104) /\ + (n135 <=> ~n4 \/ ~n97) /\ + (n127 <=> ~n103) /\ + (n116 <=> ~n20 \/ ~n98) /\ + (n124 <=> ~n104) /\ + (n115 <=> ~n13 \/ ~n97) /\ + (n123 <=> ~n103) /\ + (n110 <=> ~n28 \/ ~n98) /\ + (n100 <=> ~n104) /\ + (n109 <=> ~n3 \/ ~n97) /\ + (n99 <=> ~n103) /\ + (n142 <=> ~n17 \/ ~n98) /\ + (n150 <=> ~n104) /\ + (n141 <=> ~n9 \/ ~n97) /\ + (n149 <=> ~n103) /\ + (n87 <=> ~n243) /\ + (n89 <=> ~n244) /\ + (n83 <=> ~n224) /\ + (n85 <=> ~n223) /\ + (n79 <=> ~n217) /\ + (n81 <=> ~n218) /\ + (n75 <=> ~n197) /\ + (n77 <=> ~n196) /\ + (n73 <=> ~n190) /\ + (n71 <=> ~n189) /\ + (n91 <=> ~n251) /\ + (n93 <=> ~n250) /\ + (n65 <=> ~n163) /\ + (n63 <=> ~n162) /\ + (n67 <=> ~n170) /\ + (n69 <=> ~n169) /\ + (n57 <=> ~n136) /\ + (n55 <=> ~n135) /\ + (n51 <=> ~n116) /\ + (n53 <=> ~n115) /\ + (n49 <=> ~n110) /\ + (n47 <=> ~n109) /\ + (n59 <=> ~n142) /\ + (n61 <=> ~n141) /\ + (n241 <=> n87 /\ n103 \/ ~n87 /\ ~n103) /\ + (n242 <=> n89 /\ n104 \/ ~n89 /\ ~n104) /\ + (n227 <=> n83 /\ n104 \/ ~n83 /\ ~n104) /\ + (n226 <=> n85 /\ n103 \/ ~n85 /\ ~n103) /\ + (n215 <=> n79 /\ n103 \/ ~n79 /\ ~n103) /\ + (n216 <=> n81 /\ n104 \/ ~n81 /\ ~n104) /\ + (n200 <=> n75 /\ n104 \/ ~n75 /\ ~n104) /\ + (n199 <=> n77 /\ n103 \/ ~n77 /\ ~n103) /\ + (n188 <=> n73 /\ n104 \/ ~n73 /\ ~n104) /\ + (n187 <=> n71 /\ n103 \/ ~n71 /\ ~n103) /\ + (n254 <=> n91 /\ n104 \/ ~n91 /\ ~n104) /\ + (n253 <=> n93 /\ n103 \/ ~n93 /\ ~n103) /\ + (n160 <=> n65 /\ n104 \/ ~n65 /\ ~n104) /\ + (n159 <=> n63 /\ n103 \/ ~n63 /\ ~n103) /\ + (n173 <=> n67 /\ n104 \/ ~n67 /\ ~n104) /\ + (n172 <=> n69 /\ n103 \/ ~n69 /\ ~n103) /\ + (n134 <=> n57 /\ n104 \/ ~n57 /\ ~n104) /\ + (n133 <=> n55 /\ n103 \/ ~n55 /\ ~n103) /\ + (n119 <=> n51 /\ n104 \/ ~n51 /\ ~n104) /\ + (n118 <=> n53 /\ n103 \/ ~n53 /\ ~n103) /\ + (n108 <=> n49 /\ n104 \/ ~n49 /\ ~n104) /\ + (n107 <=> n47 /\ n103 \/ ~n47 /\ ~n103) /\ + (n145 <=> n59 /\ n104 \/ ~n59 /\ ~n104) /\ + (n144 <=> n61 /\ n103 \/ ~n61 /\ ~n103) /\ + (n88 <=> ~n241) /\ + (n90 <=> ~n242) /\ + (n84 <=> ~n227) /\ + (n86 <=> ~n226) /\ + (n80 <=> ~n215) /\ + (n82 <=> ~n216) /\ + (n76 <=> ~n200) /\ + (n78 <=> ~n199) /\ + (n74 <=> ~n188) /\ + (n72 <=> ~n187) /\ + (n92 <=> ~n254) /\ + (n94 <=> ~n253) /\ + (n66 <=> ~n160) /\ + (n64 <=> ~n159) /\ + (n68 <=> ~n173) /\ + (n70 <=> ~n172) /\ + (n58 <=> ~n134) /\ + (n56 <=> ~n133) /\ + (n52 <=> ~n119) /\ + (n54 <=> ~n118) /\ + (n50 <=> ~n108) /\ + (n48 <=> ~n107) /\ + (n60 <=> ~n145) /\ + (n62 <=> ~n144) /\ + (n234 <=> ~n88) /\ + (n230 <=> ~n86) /\ + (n208 <=> ~n80) /\ + (n204 <=> ~n78) /\ + (n180 <=> ~n72) /\ + (n257 <=> ~n94) /\ + (n152 <=> ~n64) /\ + (n176 <=> ~n70) /\ + (n126 <=> ~n56) /\ + (n122 <=> ~n54) /\ + (n96 <=> ~n48) /\ + (n148 <=> ~n62) /\ + (n237 <=> n90 /\ n88 \/ ~n90 /\ ~n88) /\ + (n229 <=> n84 /\ n86 \/ ~n84 /\ ~n86) /\ + (n211 <=> n82 /\ n80 \/ ~n82 /\ ~n80) /\ + (n203 <=> n76 /\ n78 \/ ~n76 /\ ~n78) /\ + (n183 <=> n74 /\ n72 \/ ~n74 /\ ~n72) /\ + (n256 <=> n92 /\ n94 \/ ~n92 /\ ~n94) /\ + (n156 <=> n66 /\ n64 \/ ~n66 /\ ~n64) /\ + (n175 <=> n68 /\ n70 \/ ~n68 /\ ~n70) /\ + (n129 <=> n58 /\ n56 \/ ~n58 /\ ~n56) /\ + (n121 <=> n52 /\ n54 \/ ~n52 /\ ~n54) /\ + (n101 <=> n50 /\ n48 \/ ~n50 /\ ~n48) /\ + (n147 <=> n60 /\ n62 \/ ~n60 /\ ~n62) /\ + (n233 <=> ~n237) /\ + (n221 <=> ~n229) /\ + (n207 <=> ~n211) /\ + (n193 <=> ~n203) /\ + (n179 <=> ~n183) /\ + (n248 <=> ~n256) /\ + (n151 <=> ~n156) /\ + (n166 <=> ~n175) /\ + (n125 <=> ~n129) /\ + (n113 <=> ~n121) /\ + (n95 <=> ~n101) /\ + (n139 <=> ~n147) /\ + (n245 <=> ~n233) /\ + (n228 <=> ~n221) /\ + (n219 <=> ~n207) /\ + (n167 <=> ~n166 \/ ~n151 \/ ~n179 \/ ~n193) /\ + (n202 <=> ~n193) /\ + (n191 <=> ~n179) /\ + (n255 <=> ~n248) /\ + (n164 <=> ~n151) /\ + (n174 <=> ~n166) /\ + (n137 <=> ~n125) /\ + (n120 <=> ~n113) /\ + (n111 <=> ~n95) /\ + (n146 <=> ~n139) /\ + (n106 <=> n105 /\ ~n95 \/ ~n105 /\ n95) /\ + (n161 <=> ~n167) /\ + (n112 <=> ~n95 /\ ~n48 \/ ~n111 /\ ~n102) /\ + (n114 <=> ~n112) /\ + (n39 <=> ~n106) /\ + (n130 <=> ~n120 /\ ~n112 \/ ~n122 /\ ~n113) /\ + (n117 <=> n114 /\ n113 \/ ~n114 /\ ~n113) /\ + (n131 <=> ~n130) /\ + (n138 <=> ~n125 /\ ~n56 \/ ~n137 /\ ~n130) /\ + (n32 <=> ~n117) /\ + (n132 <=> n131 /\ ~n125 \/ ~n131 /\ n125) /\ + (n153 <=> ~n146 /\ ~n138 \/ ~n148 /\ ~n139) /\ + (n140 <=> ~n138) /\ + (n37 <=> ~n132) /\ + (n157 <=> ~n153) /\ + (n165 <=> ~n151 /\ ~n64 \/ ~n164 /\ ~n153) /\ + (n143 <=> n140 /\ n139 \/ ~n140 /\ ~n139) /\ + (n158 <=> n157 /\ ~n151 \/ ~n157 /\ n151) /\ + (n184 <=> ~n174 /\ ~n165 \/ ~n176 /\ ~n166) /\ + (n168 <=> ~n165) /\ + (n33 <=> ~n143) /\ + (n43 <=> ~n158) /\ + (n185 <=> ~n184) /\ + (n192 <=> ~n179 /\ ~n72 \/ ~n191 /\ ~n184) /\ + (n171 <=> n168 /\ n166 \/ ~n168 /\ ~n166) /\ + (n195 <=> ~n192) /\ + (n186 <=> n185 /\ ~n179 \/ ~n185 /\ n179) /\ + (n201 <=> ~n202 /\ ~n192 \/ ~n204 /\ ~n193) /\ + (n34 <=> ~n171) /\ + (n198 <=> n195 /\ n193 \/ ~n195 /\ ~n193) /\ + (n35 <=> ~n186) /\ + (n194 <=> ~n167 /\ ~n153 \/ ~n161 /\ ~n201) /\ + (n36 <=> ~n198) /\ + (n212 <=> ~n194) /\ + (n213 <=> ~n212) /\ + (n220 <=> ~n207 /\ ~n80 \/ ~n219 /\ ~n212) /\ + (n214 <=> n213 /\ ~n207 \/ ~n213 /\ n207) /\ + (n222 <=> ~n220) /\ + (n238 <=> ~n228 /\ ~n220 \/ ~n230 /\ ~n221) /\ + (n38 <=> ~n214) /\ + (n225 <=> n222 /\ n221 \/ ~n222 /\ ~n221) /\ + (n239 <=> ~n238) /\ + (n246 <=> ~n233 /\ ~n88 \/ ~n245 /\ ~n238) /\ + (n40 <=> ~n225) /\ + (n240 <=> n239 /\ ~n233 \/ ~n239 /\ n233) /\ + (n261 <=> ~n255 /\ ~n246 \/ ~n257 /\ ~n248) /\ + (n249 <=> ~n246) /\ + (n262 <=> n261 /\ n246 \/ ~n261 /\ ~n246) /\ + (n41 <=> ~n240) /\ + (n44 <=> ~n261) /\ + (n252 <=> n249 /\ n248 \/ ~n249 /\ ~n248) /\ + (n45 <=> ~n262) /\ + (n42 <=> ~n252) /\ + (n46 <=> ~n42) /\ + (o_4_ <=> n43) /\ + (o_11_ <=> n42) /\ + (o_10_ <=> n41) /\ + (o_9_ <=> n40) /\ + (o_0_ <=> n39) /\ + (o_8_ <=> n38) /\ + (o_2_ <=> n37) /\ + (o_7_ <=> n36) /\ + (o_6_ <=> n35) /\ + (o_5_ <=> n34) /\ + (o_3_ <=> n33) /\ + (o_1_ <=> n32) /\ + (aftbuf1 <=> ~anda) /\ + (aftbuf2 <=> ~andb) /\ + (aftbuf3 <=> ~exora) /\ + (aftbuf4 <=> ~exorb) /\ + (aftbuf5 <=> ~carryin) /\ + (n1_0_ <=> aftbuf1 /\ a_0_) /\ + (n1_1_ <=> aftbuf1 /\ a_1_) /\ + (n1_2_ <=> aftbuf1 /\ a_2_) /\ + (n1_3_ <=> aftbuf1 /\ a_3_) /\ + (n1_4_ <=> aftbuf1 /\ a_4_) /\ + (n1_5_ <=> aftbuf1 /\ a_5_) /\ + (n1_6_ <=> aftbuf1 /\ a_6_) /\ + (n1_7_ <=> aftbuf1 /\ a_7_) /\ + (n1_8_ <=> aftbuf1 /\ a_8_) /\ + (n1_9_ <=> aftbuf1 /\ a_9_) /\ + (n1_10_ <=> aftbuf1 /\ a_10_) /\ + (n1_11_ <=> aftbuf1 /\ a_11_) /\ + (n3_0_ <=> aftbuf2 /\ b_0_) /\ + (n3_1_ <=> aftbuf2 /\ b_1_) /\ + (n3_2_ <=> aftbuf2 /\ b_2_) /\ + (n3_3_ <=> aftbuf2 /\ b_3_) /\ + (n3_4_ <=> aftbuf2 /\ b_4_) /\ + (n3_5_ <=> aftbuf2 /\ b_5_) /\ + (n3_6_ <=> aftbuf2 /\ b_6_) /\ + (n3_7_ <=> aftbuf2 /\ b_7_) /\ + (n3_8_ <=> aftbuf2 /\ b_8_) /\ + (n3_9_ <=> aftbuf2 /\ b_9_) /\ + (n3_10_ <=> aftbuf2 /\ b_10_) /\ + (n3_11_ <=> aftbuf2 /\ b_11_) /\ + (n2_0_ <=> aftbuf3 /\ ~n1_0_ \/ ~aftbuf3 /\ n1_0_) /\ + (n2_1_ <=> aftbuf3 /\ ~n1_1_ \/ ~aftbuf3 /\ n1_1_) /\ + (n2_2_ <=> aftbuf3 /\ ~n1_2_ \/ ~aftbuf3 /\ n1_2_) /\ + (n2_3_ <=> aftbuf3 /\ ~n1_3_ \/ ~aftbuf3 /\ n1_3_) /\ + (n2_4_ <=> aftbuf3 /\ ~n1_4_ \/ ~aftbuf3 /\ n1_4_) /\ + (n2_5_ <=> aftbuf3 /\ ~n1_5_ \/ ~aftbuf3 /\ n1_5_) /\ + (n2_6_ <=> aftbuf3 /\ ~n1_6_ \/ ~aftbuf3 /\ n1_6_) /\ + (n2_7_ <=> aftbuf3 /\ ~n1_7_ \/ ~aftbuf3 /\ n1_7_) /\ + (n2_8_ <=> aftbuf3 /\ ~n1_8_ \/ ~aftbuf3 /\ n1_8_) /\ + (n2_9_ <=> aftbuf3 /\ ~n1_9_ \/ ~aftbuf3 /\ n1_9_) /\ + (n2_10_ <=> aftbuf3 /\ ~n1_10_ \/ ~aftbuf3 /\ n1_10_) /\ + (n2_11_ <=> aftbuf3 /\ ~n1_11_ \/ ~aftbuf3 /\ n1_11_) /\ + (n4_0_ <=> aftbuf4 /\ ~n3_0_ \/ ~aftbuf4 /\ n3_0_) /\ + (n4_1_ <=> aftbuf4 /\ ~n3_1_ \/ ~aftbuf4 /\ n3_1_) /\ + (n4_2_ <=> aftbuf4 /\ ~n3_2_ \/ ~aftbuf4 /\ n3_2_) /\ + (n4_3_ <=> aftbuf4 /\ ~n3_3_ \/ ~aftbuf4 /\ n3_3_) /\ + (n4_4_ <=> aftbuf4 /\ ~n3_4_ \/ ~aftbuf4 /\ n3_4_) /\ + (n4_5_ <=> aftbuf4 /\ ~n3_5_ \/ ~aftbuf4 /\ n3_5_) /\ + (n4_6_ <=> aftbuf4 /\ ~n3_6_ \/ ~aftbuf4 /\ n3_6_) /\ + (n4_7_ <=> aftbuf4 /\ ~n3_7_ \/ ~aftbuf4 /\ n3_7_) /\ + (n4_8_ <=> aftbuf4 /\ ~n3_8_ \/ ~aftbuf4 /\ n3_8_) /\ + (n4_9_ <=> aftbuf4 /\ ~n3_9_ \/ ~aftbuf4 /\ n3_9_) /\ + (n4_10_ <=> aftbuf4 /\ ~n3_10_ \/ ~aftbuf4 /\ n3_10_) /\ + (n4_11_ <=> aftbuf4 /\ ~n3_11_ \/ ~aftbuf4 /\ n3_11_) /\ + (cout1 <=> aftbuf5 /\ n4_0_ \/ aftbuf5 /\ n2_0_ \/ n4_0_ /\ n2_0_) /\ + (cout2 <=> cout1 /\ n4_1_ \/ cout1 /\ n2_1_ \/ n4_1_ /\ n2_1_) /\ + (cout3 <=> cout2 /\ n4_2_ \/ cout2 /\ n2_2_ \/ n4_2_ /\ n2_2_) /\ + (cout4 <=> cout3 /\ n4_3_ \/ cout3 /\ n2_3_ \/ n4_3_ /\ n2_3_) /\ + (cout5 <=> cout4 /\ n4_4_ \/ cout4 /\ n2_4_ \/ n4_4_ /\ n2_4_) /\ + (cout6 <=> cout5 /\ n4_5_ \/ cout5 /\ n2_5_ \/ n4_5_ /\ n2_5_) /\ + (cout7 <=> cout6 /\ n4_6_ \/ cout6 /\ n2_6_ \/ n4_6_ /\ n2_6_) /\ + (cout8 <=> cout7 /\ n4_7_ \/ cout7 /\ n2_7_ \/ n4_7_ /\ n2_7_) /\ + (cout9 <=> cout8 /\ n4_8_ \/ cout8 /\ n2_8_ \/ n4_8_ /\ n2_8_) /\ + (cout10 <=> cout9 /\ n4_9_ \/ cout9 /\ n2_9_ \/ n4_9_ /\ n2_9_) /\ + (cout11 <=> cout10 /\ n4_10_ \/ cout10 /\ n2_10_ \/ n4_10_ /\ n2_10_) /\ + (hulp0 <=> ~(n2_0_ <=> ~(n4_0_ <=> aftbuf5))) /\ + (hulp1 <=> ~(n2_1_ <=> ~(n4_1_ <=> cout1))) /\ + (hulp2 <=> ~(n2_2_ <=> ~(n4_2_ <=> cout2))) /\ + (hulp3 <=> ~(n2_3_ <=> ~(n4_3_ <=> cout3))) /\ + (hulp4 <=> ~(n2_4_ <=> ~(n4_4_ <=> cout4))) /\ + (hulp5 <=> ~(n2_5_ <=> ~(n4_5_ <=> cout5))) /\ + (hulp6 <=> ~(n2_6_ <=> ~(n4_6_ <=> cout6))) /\ + (hulp7 <=> ~(n2_7_ <=> ~(n4_7_ <=> cout7))) /\ + (hulp8 <=> ~(n2_8_ <=> ~(n4_8_ <=> cout8))) /\ + (hulp9 <=> ~(n2_9_ <=> ~(n4_9_ <=> cout9))) /\ + (hulp10 <=> ~(n2_10_ <=> ~(n4_10_ <=> cout10))) /\ + (hulp11 <=> ~(n2_11_ <=> ~(n4_11_ <=> cout11))) /\ + (hulp12 <=> cout11 /\ n4_11_ \/ cout11 /\ n2_11_ \/ n4_11_ /\ n2_11_) + ==> (o_0_ <=> hulp0) /\ + (o_1_ <=> hulp1) /\ + (o_2_ <=> hulp2) /\ + (o_3_ <=> hulp3) /\ + (o_4_ <=> hulp4) /\ + (o_5_ <=> hulp5) /\ + (o_6_ <=> hulp6) /\ + (o_7_ <=> hulp7) /\ + (o_8_ <=> hulp8) /\ + (o_9_ <=> hulp9) /\ + (o_10_ <=> hulp10) /\ + (o_11_ <=> hulp11)` +and vars = map (C (curry mk_var) bool_ty) + ["carryin";"anda";"andb";"exora";"exorb"; + "a_0_";"b_0_";"a_1_";"b_1_";"a_2_"; + "b_2_";"a_3_";"b_3_";"a_4_";"b_4_"; + "a_5_";"b_5_";"a_6_";"b_6_";"a_7_"; + "b_7_";"a_8_";"b_8_";"a_9_";"b_9_"; + "a_10_";"b_10_";"a_11_";"b_11_"] in +BDD_DEFTAUT vars add4_be;; diff --git a/Help/atoms.hlp b/Help/atoms.hlp new file mode 100644 index 00000000..02cdc488 --- /dev/null +++ b/Help/atoms.hlp @@ -0,0 +1,32 @@ +\DOC atoms + +\TYPE {atoms : term -> term list} + +\SYNOPSIS +Returns a list of the atomic propositions in a Boolean term + +\DESCRIBE +When applied to a term of Boolean type, {atoms} returns a list of the atomic +fomulas, considering the term as a propositional formula built up recursively +with negation, conjunction, disjunction, implication and logical equivalence, +treating all other subterms (e.g. quantified ones) as atomic. + +\FAILURE +Fails if the term does not have type {:bool}. + +\EXAMPLE +Here the atomic formulas are simply variables: +{ + # atoms `p \/ q ==> r`;; + val it : term list = [`r`; `p`; `q`] +} +\noindent while here the atomic formulas are composite: +{ + # atoms `x < 1 \/ x > 1 ==> ~(x = 1)`;; + val it : term list = [`x < 1`; `x > 1`; `x = 1`] +} + +\SEEALSO +frees, freesl, free_in, thm_frees, variables. + +\ENDDOC diff --git a/Help/frees.hlp b/Help/frees.hlp index 7f38d502..64df5385 100644 --- a/Help/frees.hlp +++ b/Help/frees.hlp @@ -21,6 +21,6 @@ Clearly in the following term, {x} and {y} are free, whereas {z} is bound: } \SEEALSO -freesl, free_in, thm_frees, variables. +atoms, freesl, free_in, thm_frees, variables. \ENDDOC diff --git a/Library/bdd.ml b/Library/bdd.ml new file mode 100644 index 00000000..2829de3e --- /dev/null +++ b/Library/bdd.ml @@ -0,0 +1,417 @@ +(* ========================================================================= *) +(* Binary decision diagrams with complement edges, as a HOL derived rule. *) +(* *) +(* The style of implementation follows Brace, Rudell and Bryant's paper *) +(* "Efficient implementation of a BDD package" (DAC 1990). It's based on the *) +(* hol90 implementation in "Binary Decision Diagrams as a HOL Derived Rule", *) +(* but greatly simplified since HOL Light handles pointer-eq subterms more *) +(* efficiently and so we can avoid introducing any additional variables. *) +(* ========================================================================= *) + +let tfst (a,b,c) = a;; +let tsnd (a,b,c) = b;; + +(* ------------------------------------------------------------------------- *) +(* Handling of variable tables. *) +(* ------------------------------------------------------------------------- *) + +let var_of_num varray n = Array.get varray n;; + +let num_of_var (varray,vnext,vhash) v = + try Hashtbl.find vhash v + with Not_Found -> + let n = !vnext in + (vnext := n + 1; Array.set varray n v; Hashtbl.add vhash v n; n);; + +let mk_vtable n = + (Array.make (n+1) `T`, + ref 1, + (Hashtbl.create (n+1) :(term,int)Hashtbl.t));; + +(* ------------------------------------------------------------------------- *) +(* Handling of unique table. *) +(* ------------------------------------------------------------------------- *) + +let USIZE = 100000;; +let UHASH = 1024;; + +let BDD_1 = USIZE + 1;; +let BDD_0 = -BDD_1;; + +let btm_of_int = + let true_tm = `T` in + let rec btm_of_int uarray n = + if n < 0 then mk_neg(btm_of_int uarray (-n)) else + if n = BDD_1 then true_tm else + rand(rator(concl(snd(Array.get uarray n)))) in + btm_of_int;; + +let lookup_triple varray (uarray,unext,uhash) ((v,y,n) as tr) = + try Hashtbl.find uhash tr with Not_Found -> + let ytm = btm_of_int uarray y + and ntm = btm_of_int uarray n + and vtm = Array.get varray v + and m = !unext in + let ltm = mk_cond(vtm,ytm,ntm) in + let dth = REFL ltm in + (unext := m + 1; + Array.set uarray m (tr,dth); + Hashtbl.add uhash tr m; + m);; + +let bdd_expand uarray b = + if b < 0 then + let (v,l,r) = fst(Array.get uarray (-b)) in + (v,-l,-r) + else fst(Array.get uarray b);; + +let BDD_EXPAND = + let pth1 = TAUT + `~(if v then b1 else b2) <=> (if v then ~b1 else ~b2)` + and pth2 = TAUT + `~(if v then b1 else ~b2) <=> (if v then ~b1 else b2)` + and pth3 = TAUT + `~(if v then ~b1 else b2) <=> (if v then b1 else ~b2)` + and pth4 = TAUT + `~(if v then ~b1 else ~b2) <=> (if v then b1 else b2)` + and neg_tm = `~` + and v_tm = `v:bool` + and b1_tm = `b1:bool` + and b2_tm = `b2:bool` in + let rec BDD_EXPAND uarray b = + if b < 0 then + let def = snd(Array.get uarray (-b)) in + let (v,(y,n)) = dest_cond(rand(concl def)) in + let pth = + if is_neg y then + if is_neg n then INST [v,v_tm; rand y,b1_tm; rand n,b2_tm] pth4 + else INST [v,v_tm; rand y,b1_tm; n,b2_tm] pth3 + else + if is_neg n then INST [v,v_tm; y,b1_tm; rand n,b2_tm] pth2 + else INST [v,v_tm; y,b1_tm; n,b2_tm] pth1 in + TRANS (AP_TERM neg_tm def) pth + else snd(Array.get uarray b) in + BDD_EXPAND;; + +let BDD_LOOKUP = + let pth1 = TAUT `b <=> (if v then b else b)` + and pth2 = TAUT + `(b <=> (if v then l else r)) + ==> (~b <=> (if v then ~l else ~r))` + and pth3 = TAUT + `(b <=> (if v then l else ~r)) + ==> (~b <=> (if v then ~l else r))` + and b_tm = `b:bool` + and v_tm = `v:bool` + and l_tm = `l:bool` + and r_tm = `r:bool` in + let rec BDD_LOOKUP varray utable (v,l,r) = + if l = r then + (INST [var_of_num varray v,v_tm;btm_of_int (tfst utable) l,b_tm] pth1, + l,0) + else if l < 0 then + let i = lookup_triple varray utable (v,-l,-r) in + let dth = snd(Array.get (tfst utable) i) in + let (ctm,(vtm,(ltm,rtm))) = (I F_F dest_cond) (dest_eq(concl dth)) in + if r < 0 then + (MP (INST [ctm,b_tm;vtm,v_tm;ltm,l_tm;rtm,r_tm] pth2) dth,-i,i) + else + (MP (INST [ctm,b_tm;vtm,v_tm;ltm,l_tm;rand rtm,r_tm] pth3) dth,-i,i) + else let i = lookup_triple varray utable (v,l,r) in + let dth = snd(Array.get (tfst utable) i) in + (dth,i,i) in + BDD_LOOKUP;; + +let mk_utable() = + (Array.make USIZE ((0,0,0),TRUTH), + ref 1, + (Hashtbl.create UHASH :(int*int*int,int)Hashtbl.t));; + +(* ------------------------------------------------------------------------- *) +(* Handling of computed table. *) +(* ------------------------------------------------------------------------- *) + +let CSIZE = 200000;; +let CHASH = 1024;; + +let bdd_and = + let pth1 = TAUT `~T /\ r1 <=> ~T` + and pth2 = TAUT `l1 /\ T <=> l1` + and pth3 = TAUT `l1 /\ l1 <=> l1` + and pth4 = TAUT `~r1 /\ r1 <=> ~T` + and pth5 = TAUT + `(b1 <=> (if v then l1 else r1)) + ==> (b2 <=> (if v then l2 else r2)) + ==> (b3 <=> (if v then l3 else r3)) + ==> (l1 /\ l2 <=> l3) ==> (r1 /\ r2 <=> r3) ==> (b1 /\ b2 <=> b3)` + and pth6 = TAUT + `(b1 <=> (if v then l1 else r1)) + ==> (b3 <=> (if v then l3 else r3)) + ==> (l1 /\ b2 <=> l3) ==> (r1 /\ b2 <=> r3) ==> (b1 /\ b2 <=> b3)` + and pth7 = TAUT + `(b2 <=> (if v then l2 else r2)) + ==> (b3 <=> (if v then l3 else r3)) + ==> (b1 /\ l2 <=> l3) ==> (b1 /\ r2 <=> r3) ==> (b1 /\ b2 <=> b3)` + and pth8 = TAUT `l1 /\ r1 <=> r1 /\ l1` + and b1_tm = `b1:bool` + and b2_tm = `b2:bool` + and b3_tm = `b3:bool` + and l1_tm = `l1:bool` + and l2_tm = `l2:bool` + and l3_tm = `l3:bool` + and r1_tm = `r1:bool` + and r2_tm = `r2:bool` + and r3_tm = `r3:bool` + and v_tm = `v:bool` + and lookup_pair (carray,cnext,chash) (l,r) = + try let i = Hashtbl.find chash (l,r) in (fst(Array.get carray i),i) + with Not_Found -> failwith "lookup_pair" in + let rec bdd_and (varray,utable,((carray,cnext,chash) as ctable)) (l,r) = + try lookup_pair ctable (l,r) with Failure _ -> + let (ans,thm,uargs,cargs) = + if l = BDD_0 then + (BDD_0,INST [btm_of_int (tfst utable) r,r1_tm] pth1,[],[]) + else if r = BDD_1 then + (l,INST [btm_of_int (tfst utable) l,l1_tm] pth2,[],[]) + else if l = r then + (l,INST [btm_of_int (tfst utable) l,l1_tm] pth3,[],[]) + else if l = -r then + (BDD_0,INST [btm_of_int (tfst utable) r,r1_tm] pth4,[],[]) + else + let (lv,ly,ln) = bdd_expand (tfst utable) l + and (rv,ry,rn) = bdd_expand (tfst utable) r in + if lv = rv then + let (thy,cy,jy) = bdd_ands (varray,utable,ctable) (ly,ry) in + let (thn,cn,jn) = bdd_ands (varray,utable,ctable) (ln,rn) in + let thl = BDD_EXPAND (tfst utable) l in + let thr = BDD_EXPAND (tfst utable) r in + let (thc,c,jc) = BDD_LOOKUP varray utable (lv,cy,cn) in + let (b1,(v1,(l1,r1))) = (I F_F dest_cond) (dest_eq(concl thl)) in + let (b2,(v2,(l2,r2))) = (I F_F dest_cond) (dest_eq(concl thr)) in + let (b3,(v3,(l3,r3))) = (I F_F dest_cond) (dest_eq(concl thc)) in + let ith = INST [(b1,b1_tm);(b2,b2_tm);(b3,b3_tm); + (l1,l1_tm);(l2,l2_tm);(l3,l3_tm); + (r1,r1_tm);(r2,r2_tm);(r3,r3_tm);(v3,v_tm)] pth5 in + let lis = [thl; thr; thc; thy; thn] in + let xth = rev_itlist (C MP) lis ith in + (c,xth,[abs(l);abs(r);jc],[jy;jn]) + else if lv > rv then + let (thy,cy,jy) = bdd_ands (varray,utable,ctable) (ly,r) in + let (thn,cn,jn) = bdd_ands (varray,utable,ctable) (ln,r) in + let thl = BDD_EXPAND (tfst utable) l in + let (thc,c,jc) = BDD_LOOKUP varray utable (lv,cy,cn) in + let (b1,(v1,(l1,r1))) = (I F_F dest_cond) (dest_eq(concl thl)) in + let (b3,(v3,(l3,r3))) = (I F_F dest_cond) (dest_eq(concl thc)) in + let b2 = rand(rand(rator(concl thy))) in + let ith = INST [(b1,b1_tm);(b2,b2_tm);(b3,b3_tm); + (l1,l1_tm);(l3,l3_tm); + (r1,r1_tm);(r3,r3_tm);(v3,v_tm)] pth6 in + let lis = [thl; thc; thy; thn] in + let xth = rev_itlist (C MP) lis ith in + (c,xth,[abs(l);jc],[jy;jn]) + else + let (thy,cy,jy) = bdd_ands (varray,utable,ctable) (l,ry) in + let (thn,cn,jn) = bdd_ands (varray,utable,ctable) (l,rn) in + let thr = BDD_EXPAND (tfst utable) r in + let (thc,c,jc) = BDD_LOOKUP varray utable (rv,cy,cn) in + let (b2,(v2,(l2,r2))) = (I F_F dest_cond) (dest_eq(concl thr)) in + let (b3,(v3,(l3,r3))) = (I F_F dest_cond) (dest_eq(concl thc)) in + let b1 = rand(rator(rand(rator(concl thy)))) in + let ith = INST [(b1,b1_tm);(b2,b2_tm);(b3,b3_tm); + (l2,l2_tm);(l3,l3_tm); + (r2,r2_tm);(r3,r3_tm);(v3,v_tm)] pth7 in + let lis = [thr; thc; thy; thn] in + let xth = rev_itlist (C MP) lis ith in + (c,xth,[abs(r);jc],[jy;jn]) in + let m = !cnext in + (cnext := m + 1; + Array.set carray m ((ans,(thm,uargs,cargs))); + Hashtbl.add chash (l,r) m; + (ans,m)) + + and bdd_ands (varray,utable,ctable) (l,r) = + if (l:int) <= r then + let (ans,i) = bdd_and (varray,utable,ctable) (l,r) in + let th = tfst(snd(Array.get (tfst ctable) i)) in + (th,ans,i) + else + let (ans,i) = bdd_and (varray,utable,ctable) (r,l) in + let th = tfst(snd(Array.get (tfst ctable) i)) in + let ((ltm,rtm),ctm) = (dest_conj F_F I) (dest_eq(concl th)) in + let eth = INST [rtm,l1_tm; ltm,r1_tm] pth8 in + (TRANS eth th,ans,i) in + bdd_and;; + +let mk_ctable() = + (Array.make CSIZE (0,(TRUTH,([]:int list),([]:int list))), + ref 0, + (Hashtbl.create CHASH :(int*int,int)Hashtbl.t));; + +(* ------------------------------------------------------------------------- *) +(* Basic BDD-constructing operations for the logical connectives. *) +(* ------------------------------------------------------------------------- *) + +let BDD_TRUE = (BDD_1,REFL `T`);; + +let BDD_FALSE = (BDD_0,TAUT `F <=> ~T`);; + +let BDD_VAR = + let pth = TAUT `(x <=> (if v then T else ~T)) ==> v = x` + and x_tm = `x:bool` + and v_tm = `v:bool` in + fun (vtable,utable,ctable) tm -> + let v = num_of_var vtable tm in + let u = lookup_triple (tfst vtable) utable (v,BDD_1,BDD_0) in + let ltm = btm_of_int (tfst utable) u in + let sth = INST [ltm,x_tm; tm,v_tm] pth in + let th = snd(Array.get (tfst utable) u) in + (u,MP sth th);; + +let BDD_NEG = + let neg_tm = `~` + and x_tm = `x:bool` + and pth = TAUT `~ ~ x <=> x` in + fun (vtable,utable,ctable) (i,fth) -> + if i < 0 then + let utm = btm_of_int (tfst utable) (-i) in + let th = INST [utm,x_tm] pth in + (-i,TRANS (AP_TERM neg_tm fth) th) + else + (-i,AP_TERM neg_tm fth);; + +let BDD_AND = + let and_tm = `/\` + and t1_tm = `t1:bool` + and t2_tm = `t2:bool` in + let pth = SPECL [t1_tm; t2_tm] CONJ_SYM in + fun (vtable,utable,ctable) ((i1,th1),(i2,th2)) -> + if i2 < i1 then + let (i3,j) = bdd_and (tfst vtable,utable,ctable) (i2,i1) in + let sth = INST [btm_of_int (tfst utable) i1,t1_tm; + btm_of_int (tfst utable) i2,t2_tm] pth + and th = tfst(snd(Array.get (tfst ctable) j)) in + (i3,TRANS (MK_COMB(AP_TERM and_tm th1,th2)) + (TRANS sth th)) + else + let (i3,j) = bdd_and (tfst vtable,utable,ctable) (i1,i2) in + let th = tfst(snd(Array.get (tfst ctable) j)) in + (i3,TRANS (MK_COMB(AP_TERM and_tm th1,th2)) th);; + +let BDD_OR = + let pth = TAUT `~(~a /\ ~b) <=> a \/ b` in + let rew = REWR_CONV pth in + let rewl = LAND_CONV rew in + let rule = CONV_RULE rewl in + fun tt (b1,b2) -> + let (i,fth) = BDD_NEG tt (BDD_AND tt (BDD_NEG tt b1,BDD_NEG tt b2)) in + (i,rule fth);; + +let BDD_IMP = + let pth = TAUT `~(a /\ ~b) <=> a ==> b` in + let rew = REWR_CONV pth in + let rewl = LAND_CONV rew in + let rule = CONV_RULE rewl in + fun tt (b1,b2) -> + let (i,fth) = BDD_NEG tt (BDD_AND tt (b1,BDD_NEG tt b2)) in + (i,rule fth);; + +let BDD_IFF = + let pth = TAUT `~(a /\ ~b) /\ ~(~a /\ b) <=> (a <=> b)` in + let rew = REWR_CONV pth in + let rewl = LAND_CONV rew in + let rule = CONV_RULE rewl in + fun tt (b1,b2) -> + let (i,fth) = BDD_AND tt (BDD_NEG tt (BDD_AND tt (b1,BDD_NEG tt b2)), + BDD_NEG tt (BDD_AND tt (BDD_NEG tt b1,b2))) in + (i,rule fth);; + +let rec BDD_OF_TERM defs tt tm = + match tm with + Const("T",_) -> BDD_TRUE + | Const("F",_) -> BDD_FALSE + | Comb(Comb(Const("/\\",_),l),r) -> + BDD_AND tt (BDD_OF_TERM defs tt l,BDD_OF_TERM defs tt r) + | Comb(Comb(Const("\\/",_),l),r) -> + BDD_OR tt (BDD_OF_TERM defs tt l,BDD_OF_TERM defs tt r) + | Comb(Comb(Const("==>",_),l),r) -> + BDD_IMP tt (BDD_OF_TERM defs tt l,BDD_OF_TERM defs tt r) + | Comb(Comb(Const("=",Tyapp("fun",[Tyapp("bool",[]);_])),l),r) -> + BDD_IFF tt (BDD_OF_TERM defs tt l,BDD_OF_TERM defs tt r) + | Comb(Const("~",_),l) -> + BDD_NEG tt (BDD_OF_TERM defs tt (rand tm)) + | _ -> (try apply defs tm with Failure _ -> BDD_VAR tt tm);; + +(* ------------------------------------------------------------------------- *) +(* Provide some information on output when verbose = 1 *) +(* ------------------------------------------------------------------------- *) + +let bdd_stats nd (vt,ct,ut) = + let d = if nd = 0 then "" else string_of_int nd^" definitions, " in + remark + ("BDD with "^d^ + string_of_int(!(tsnd vt)) ^ " variables, " ^ + string_of_int(!(tsnd ut)) ^ " nodes and " ^ + string_of_int(!(tsnd ct)) ^ " cached results");; + +(* ------------------------------------------------------------------------- *) +(* Basic tautology prover *) +(* ------------------------------------------------------------------------- *) + +let BDD_TAUT tm = + let vt = mk_vtable(length(atoms tm)) + and ut = mk_utable() and ct = mk_ctable() in + let b = BDD_OF_TERM undefined (vt,ut,ct) tm in + let _ = bdd_stats 0 (vt,ct,ut) in + EQT_ELIM (snd b);; + +(* ------------------------------------------------------------------------- *) +(* A version that treats an input p ==> q specially, considering p *) +(* as a list of "definitions" (required to be left-to-right acyclic) *) +(* ------------------------------------------------------------------------- *) + +let BDD_DEFTAUT = + let bdd_def th = + let rule = TRANS th in + fun (i,fth) -> (i,rule fth) in + let rec bdd_of_defs defs tt ths = + match ths with + [] -> defs + | th::oths -> + let lv,rt = dest_eq(concl th) in + let br = BDD_OF_TERM defs tt rt in + let bl = bdd_def th br in + bdd_of_defs ((lv |-> bl) defs) tt oths in + let is_atomic tm = + not(is_neg tm || is_conj tm || is_disj tm || is_imp tm || is_iff tm) in + let is_literal tm = + (is_neg tm && is_atomic(rand tm)) || is_atomic tm in + let valid_definition tm = + (is_iff tm && is_literal(lhand tm)) || is_literal tm in + let ADJUST_DEF th = + let tm = concl th in + if is_neg tm then EQF_INTRO th + else if is_iff tm then th + else EQT_INTRO th in + let rec acyclic oks tms = + match tms with + [] -> true + | tm::otms -> not (exists (free_in (lhs tm)) (rand tm::oks)) && + acyclic (tm::oks) otms in + let valid_definitions tm = + let tms = map (concl o ADJUST_DEF o ASSUME) (conjuncts tm) in + forall valid_definition tms && acyclic [] tms in + fun ivars tm -> + let vars = ivars @ subtract (atoms tm) ivars in + let vt = mk_vtable (length vars) + and ut = mk_utable() and ct = mk_ctable() in + let _ = do_list (ignore o BDD_VAR (vt,ut,ct)) ivars in + if is_imp tm && valid_definitions (lhand tm) then + let ths = map ADJUST_DEF (CONJUNCTS(ASSUME(lhand tm))) in + let defs = bdd_of_defs undefined (vt,ut,ct) ths in + let b = BDD_OF_TERM defs (vt,ut,ct) (rand tm) in + let _ = bdd_stats (length(dom defs)) (vt,ct,ut) in + DISCH (lhand tm) (EQT_ELIM(snd b)) + else + let b = BDD_OF_TERM undefined (vt,ut,ct) tm in + let _ = bdd_stats 0 (vt,ct,ut) in + EQT_ELIM(snd b);; diff --git a/Library/grouptheory.ml b/Library/grouptheory.ml index 3c788de1..1936a4b9 100644 --- a/Library/grouptheory.ml +++ b/Library/grouptheory.ml @@ -1877,8 +1877,8 @@ let IMAGE_GROUP_CONJUGATION_BY_MUL = prove s SUBSET group_carrier G ==> IMAGE (group_conjugation G (group_mul G a b)) s = IMAGE (group_conjugation G a) (IMAGE (group_conjugation G b) s)`, - REPEAT STRIP_TAC THEN REWRITE_TAC[GSYM IMAGE_o] THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + REPEAT STRIP_TAC THEN REWRITE_TAC[GSYM IMAGE_o] THEN + MATCH_MP_TAC IMAGE_EQ THEN ASM_MESON_TAC[GROUP_CONJUGATION_CONJUGATION; o_THM; SUBSET]);; let IMAGE_GROUP_CONJUGATION_BY_INV = prove @@ -5855,8 +5855,7 @@ let LEFT_COSET_LEFT_COSET = prove left_coset G (group_mul G x y) h`, REWRITE_TAC[SUBSET] THEN REPEAT STRIP_TAC THEN REWRITE_TAC[LEFT_COSET_AS_IMAGE; GSYM IMAGE_o; o_DEF] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + MATCH_MP_TAC IMAGE_EQ THEN ASM_SIMP_TAC[GROUP_MUL_ASSOC; SUBSET]);; let RIGHT_COSET_RIGHT_COSET = prove @@ -6218,9 +6217,7 @@ let GROUP_ACTION_LEFT_COSET_MULTIPLICATION = prove X_GEN_TAC `a:A` THEN DISCH_TAC THEN X_GEN_TAC `b:A` THEN DISCH_TAC THEN REWRITE_TAC[IN_ELIM_THM; GSYM IMAGE_o; o_DEF] THEN EXISTS_TAC `group_mul G a b:A` THEN ASM_SIMP_TAC[GROUP_MUL] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN - ASM_MESON_TAC[GROUP_MUL_ASSOC; SUBSET]);; + MATCH_MP_TAC IMAGE_EQ THEN ASM_MESON_TAC[GROUP_MUL_ASSOC; SUBSET]);; let GROUP_ORBIT_LEFT_COSET_MULTIPLICATION = prove (`!G h a:A. @@ -6861,9 +6858,8 @@ let GROUP_SETINV_RIGHT_COSET = prove [REWRITE_TAC[group_setinv; group_setmul; SET_RULE `{f x y | P x /\ y IN {a}} = {f x a | P x}`; SET_RULE `{f x y | x IN {a} /\ P y} = {f a y | P y}`] THEN - REWRITE_TAC[SIMPLE_IMAGE; GSYM IMAGE_o] THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN - RULE_ASSUM_TAC(REWRITE_RULE[SUBSET]) THEN + REWRITE_TAC[SIMPLE_IMAGE; GSYM IMAGE_o] THEN + MATCH_MP_TAC IMAGE_EQ THEN RULE_ASSUM_TAC(REWRITE_RULE[SUBSET]) THEN ASM_SIMP_TAC[GROUP_INV_MUL; o_DEF]; ASM_SIMP_TAC[GROUP_SETINV_SUBGROUP; GROUP_INV]]);; @@ -13953,9 +13949,7 @@ let CARRIER_SUBGROUP_GENERATED_UNIONS_ALT = prove `{y | y IN {f x | P x} /\ Q y} = IMAGE f {x | P x /\ Q(f x)}`] THEN ONCE_REWRITE_TAC[TAUT `p /\ ~q <=> ~(p ==> q)`] THEN SIMP_TAC[RESTRICTION] THEN REWRITE_TAC[NOT_IMP; GSYM IMAGE_o; o_DEF] THEN - GEN_REWRITE_TAC RAND_CONV [SIMPLE_IMAGE_GEN] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + GEN_REWRITE_TAC RAND_CONV [SIMPLE_IMAGE_GEN] THEN MATCH_MP_TAC IMAGE_EQ THEN REWRITE_TAC[FORALL_IN_GSPEC] THEN REPEAT STRIP_TAC THEN MATCH_MP_TAC GROUP_SUM_EQ THEN SIMP_TAC[RESTRICTION]);; diff --git a/Library/pocklington.ml b/Library/pocklington.ml index e556e7e1..5607a11e 100755 --- a/Library/pocklington.ml +++ b/Library/pocklington.ml @@ -971,6 +971,63 @@ let SQUAREFREE_EXP = prove ASM_REWRITE_TAC[] THEN MATCH_MP_TAC DIVIDES_EXP_LE_IMP THEN ASM_ARITH_TAC);; +let SQUAREFREE_DIVIDES = prove + (`!q n. squarefree q + ==> (q divides n <=> !p. prime p /\ p divides q ==> p divides n)`, + REWRITE_TAC[SQUAREFREE_PRIME_INDEX] THEN REPEAT STRIP_TAC THEN + ASM_SIMP_TAC[IMP_CONJ; DIVIDES_INDEX; PRIME_IMP_NZ] THEN + ASM_CASES_TAC `n = 0` THEN ASM_SIMP_TAC[INDEX_PRIME] THEN + AP_TERM_TAC THEN GEN_REWRITE_TAC I [FUN_EQ_THM] THEN + X_GEN_TAC `p:num` THEN FIRST_X_ASSUM(MP_TAC o SPEC `p:num`) THEN + ASM_CASES_TAC `prime p` THEN ASM_REWRITE_TAC[MESON[LE_0] + `(if p then 1 else 0) <= x <=> p ==> 1 <= x`] THEN + ONCE_REWRITE_TAC[TAUT `p ==> q ==> r <=> q ==> p ==> r`] THEN + ASM_REWRITE_TAC[FORALL_UNWIND_THM1] THEN ARITH_TAC);; + +let SQUAREFREE_DIVEXP = prove + (`!n q x. squarefree q /\ q divides x EXP n ==> q divides x`, + SIMP_TAC[IMP_CONJ; SQUAREFREE_DIVIDES; PRIME_DIVEXP_EQ]);; + +let SQUAREFREE_DIVEXP_EQ = prove + (`!n q x. squarefree q /\ ~(n = 0) ==> (q divides x EXP n <=> q divides x)`, + MESON_TAC[DIVIDES_REXP; SQUAREFREE_DIVEXP]);; + +let SQUAREFREE,SQUAREFREE_ALT = (CONJ_PAIR o prove) + (`(!n. squarefree n <=> ~(n = 0) /\ !m k. n divides m EXP k ==> n divides m) /\ + (!n. squarefree n <=> ~(n = 0) /\ !m. n divides m EXP 2 ==> n divides m)`, + REWRITE_TAC[AND_FORALL_THM] THEN GEN_TAC THEN MATCH_MP_TAC(TAUT + `((p ==> q) /\ (q ==> r)) /\ (r ==> p) ==> (p <=> q) /\ (p <=> r)`) THEN + CONJ_TAC THENL [MESON_TAC[SQUAREFREE_DIVEXP; SQUAREFREE_0]; STRIP_TAC] THEN + REWRITE_TAC[SQUAREFREE_PRIME] THEN + X_GEN_TAC `p:num` THEN REPEAT STRIP_TAC THEN + FIRST_X_ASSUM(X_CHOOSE_THEN `r:num` SUBST_ALL_TAC o + GEN_REWRITE_RULE I [divides]) THEN + FIRST_X_ASSUM(MP_TAC o SPEC `p * r:num`) THEN RULE_ASSUM_TAC + (REWRITE_RULE[MULT_EQ_0; EXP_EQ_0; ARITH_EQ; DE_MORGAN_THM]) THEN + ASM_SIMP_TAC[EXP_2; GSYM MULT_ASSOC; DIVIDES_LMUL2_EQ; NOT_IMP] THEN + CONJ_TAC THENL [CONV_TAC NUMBER_RULE; ALL_TAC] THEN + GEN_REWRITE_TAC (RAND_CONV o RAND_CONV) [ARITH_RULE `r = 1 * r`] THEN + ASM_SIMP_TAC[DIVIDES_RMUL2_EQ; DIVIDES_ONE] THEN ASM_MESON_TAC[PRIME_1]);; + +let SQUAREFREE_GCD = prove + (`!m n. squarefree m \/ squarefree n ==> squarefree(gcd(m,n))`, + MESON_TAC[SQUAREFREE_DIVISOR; GCD]);; + +let SQUAREFREE_GCD_SQUARE = prove + (`!n. squarefree n <=> !x. gcd(x EXP 2,n) divides x`, + GEN_TAC THEN ASM_CASES_TAC `n = 0` THENL + [ASM_REWRITE_TAC[SQUAREFREE_0; GCD_0] THEN + DISCH_THEN(MP_TAC o SPEC `2`) THEN REWRITE_TAC[DIVIDES_MOD] THEN ARITH_TAC; + ASM_REWRITE_TAC[DIVIDES_INDEX; SQUAREFREE_PRIME_INDEX]] THEN + ASM_SIMP_TAC[GCD_ZERO; INDEX_GCD; INDEX_EXP; EXP_EQ_0; + RIGHT_IMP_FORALL_THM; TAUT `p \/ q <=> ~p ==> q`] THEN + SIMP_TAC[GCD_ZERO; EXP_EQ_0; TAUT `p \/ q <=> ~p ==> q`] THEN + ONCE_REWRITE_TAC[SWAP_FORALL_THM] THEN AP_TERM_TAC THEN + GEN_REWRITE_TAC I [FUN_EQ_THM] THEN X_GEN_TAC `p:num` THEN + ASM_CASES_TAC `prime p` THEN ASM_REWRITE_TAC[] THEN + EQ_TAC THENL [ARITH_TAC; DISCH_THEN(MP_TAC o SPEC `p:num`)] THEN + ASM_SIMP_TAC[INDEX_PRIME; PRIME_IMP_NZ] THEN ARITH_TAC);; + let SQUAREFREE_NPRODUCT = prove (`!s. FINITE s ==> (squarefree(nproduct s (\n. n)) <=> diff --git a/Library/prime.ml b/Library/prime.ml index 031c4cf6..a8231a42 100755 --- a/Library/prime.ml +++ b/Library/prime.ml @@ -1640,6 +1640,15 @@ let INDEX_GCD = prove REWRITE_TAC[ARITH_RULE `k <= m /\ k <= n <=> k <= MIN m n`] THEN MESON_TAC[LE_REFL; LE_ANTISYM; LE_TRANS]);; +let FORALL_PRIME_INDEX = prove + (`(!p. prime p ==> !P. ((!x. P(index p x)) <=> !k. P k)) /\ + (!p. prime p ==> !P. ((!x. ~(x = 0) ==> P(index p x)) <=> !k. P k))`, + REPEAT STRIP_TAC THEN EQ_TAC THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN + X_GEN_TAC `k:num` THEN FIRST_X_ASSUM(MP_TAC o SPEC `p EXP k`) THEN + ASM_SIMP_TAC[INDEX_EXP; INDEX_REFL; EXP_EQ_0; PRIME_IMP_NZ] THEN + MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN + FIRST_X_ASSUM(MP_TAC o MATCH_MP PRIME_GE_2) THEN ARITH_TAC);; + let INDEX_FACT_PRIME_MULT = prove (`!p n. prime p ==> index p (FACT(p * n)) = n + index p (FACT n)`, REPEAT STRIP_TAC THEN ASM_CASES_TAC `n = 0` THEN diff --git a/Library/ringtheory.ml b/Library/ringtheory.ml index 8dc242a5..ee931344 100644 --- a/Library/ringtheory.ml +++ b/Library/ringtheory.ml @@ -917,7 +917,7 @@ let RING_SUM_CLAUSES = prove REWRITE_TAC[ring_sum; SET_RULE `{x | x IN {} /\ P x} = {}`] THEN REWRITE_TAC[INSERT_RESTRICT] THEN REPEAT STRIP_TAC THEN TRY COND_CASES_TAC THEN - ASM_SIMP_TAC[MATCH_MP ITERATE_CLAUSES (ISPEC `r:A ring` MONOIDAL_RING_ADD); + ASM_SIMP_TAC[ITERATE_CLAUSES; MONOIDAL_RING_ADD; NOT_IN_EMPTY; EMPTY_GSPEC; FINITE_RESTRICT] THEN ASM_REWRITE_TAC[NEUTRAL_RING_ADD; GSYM ring_sum; IN_ELIM_THM; RING_SUM]);; @@ -1417,10 +1417,10 @@ let RING_PRODUCT_CLAUSES = prove REWRITE_TAC[ring_product; SET_RULE `{x | x IN {} /\ P x} = {}`] THEN REWRITE_TAC[INSERT_RESTRICT] THEN REPEAT STRIP_TAC THEN TRY COND_CASES_TAC THEN - ASM_SIMP_TAC[MATCH_MP ITERATE_CLAUSES (ISPEC `r:A ring` MONOIDAL_RING_MUL); + ASM_SIMP_TAC[ITERATE_CLAUSES; MONOIDAL_RING_MUL; NOT_IN_EMPTY; EMPTY_GSPEC; FINITE_RESTRICT] THEN ASM_REWRITE_TAC[NEUTRAL_RING_MUL; GSYM ring_product; - IN_ELIM_THM; RING_PRODUCT]);; + IN_ELIM_THM; RING_PRODUCT]);; let RING_PRODUCT_SING = prove (`!r (f:K->A) a. @@ -6757,6 +6757,18 @@ let RING_DIVIDES_PROD_RING = prove REWRITE_TAC[ring_divides; EXISTS_PAIR_THM; PROD_RING; IN_CROSS; PAIR_EQ] THEN MESON_TAC[]);; +let RING_OF_NUM_PROD_RING = prove + (`!(r:A ring) (s:B ring) n. + ring_of_num (prod_ring r s) n = (ring_of_num r n,ring_of_num s n)`, + GEN_TAC THEN GEN_TAC THEN + INDUCT_TAC THEN ASM_REWRITE_TAC[ring_of_num; PROD_RING]);; + +let RING_OF_INT_PROD_RING = prove + (`!(r:A ring) (s:B ring) n. + ring_of_int (prod_ring r s) n = (ring_of_int r n,ring_of_int s n)`, + REWRITE_TAC[FORALL_INT_CASES; RING_OF_INT_CASES] THEN + REWRITE_TAC[RING_OF_NUM_PROD_RING; PROD_RING]);; + let RING_ASSOCIATES_PROD_RING = prove (`!r1 r2 (a:A) (b:B) c d. ring_associates (prod_ring r1 r2) (a,b) (c,d) <=> @@ -13971,6 +13983,16 @@ let IN_INTEGER_MOD_RING_CARRIER = prove ASM_REWRITE_TAC[CONJUNCT1 INTEGER_MOD_RING; IN_UNIV; INT_OF_NUM_EQ] THEN ASM_SIMP_TAC[INTEGER_MOD_RING; LE_1; IN_ELIM_THM]);; +let RING_CARRIER_INTEGER_MOD_RING = prove + (`!n. ring_carrier (integer_mod_ring n) = IMAGE (\x. x rem &n) (:int)`, + GEN_TAC THEN ASM_CASES_TAC `n = 0` THEN + ASM_SIMP_TAC[INTEGER_MOD_RING; INT_REM_0; IMAGE_ID; LE_1] THEN + MATCH_MP_TAC(SET_RULE + `(!x. x IN s ==> f x = x) /\ (!x. f x IN s) ==> s = IMAGE f UNIV`) THEN + SIMP_TAC[IN_ELIM_THM; INT_REM_LT] THEN + REWRITE_TAC[INT_REM_POS_EQ; INT_LT_REM_EQ] THEN + ASM_SIMP_TAC[INT_OF_NUM_EQ; INT_OF_NUM_LT; LE_1]);; + let INTEGER_MOD_RING_CARRIER_REM = prove (`!n x. x rem &n IN ring_carrier(integer_mod_ring n)`, REPEAT GEN_TAC THEN ASM_CASES_TAC `n = 0` THEN @@ -14196,6 +14218,80 @@ let RING_MONOMORPHISM_FROM_INTEGER_MOD_RING = prove DISCH_TAC THEN EXISTS_TAC `ring_of_int (r:A ring)` THEN ASM_REWRITE_TAC[RING_MONOMORPHISM_INTEGER_MOD_RING_OF_INT]]);; +let RING_HOMOMORPHISM_PROD_INTEGER_MOD_RING = prove + (`!m n. + ring_homomorphism + (integer_mod_ring (m * n), + prod_ring (integer_mod_ring m) (integer_mod_ring n)) + (\a. (a rem &m),(a rem &n))`, + REPEAT GEN_TAC THEN REWRITE_TAC[RING_HOMOMORPHISM] THEN + SIMP_TAC[PROD_RING; SUBSET; FORALL_IN_IMAGE; IN_CROSS; PAIR_EQ] THEN + SIMP_TAC[INTEGER_MOD_RING; GSYM INT_OF_NUM_MUL; INT_REM_REM_MUL] THEN + CONV_TAC INT_REM_DOWN_CONV THEN + REWRITE_TAC[INTEGER_MOD_RING_CARRIER_REM]);; + +let RING_ISOMORPHISM_PROD_INTEGER_MOD_RING = prove + (`!m n. ring_isomorphism + (integer_mod_ring (m * n), + prod_ring (integer_mod_ring m) (integer_mod_ring n)) + (\a. (a rem &m),(a rem &n)) <=> + coprime(m,n)`, + REPEAT GEN_TAC THEN + REWRITE_TAC[RING_ISOMORPHISM_SUBSET] THEN + REWRITE_TAC[RING_HOMOMORPHISM_PROD_INTEGER_MOD_RING] THEN + REWRITE_TAC[RING_CARRIER_INTEGER_MOD_RING; GSYM IMAGE_o] THEN + REWRITE_TAC[SET_RULE + `s SUBSET IMAGE f UNIV <=> !y. y IN s ==> ?x. f x = y`] THEN + REWRITE_TAC[PROD_RING; FORALL_IN_CROSS] THEN + REWRITE_TAC[RING_CARRIER_INTEGER_MOD_RING] THEN + REWRITE_TAC[FORALL_IN_IMAGE; RIGHT_FORALL_IMP_THM; IMP_CONJ] THEN + REWRITE_TAC[IN_UNIV; PAIR_EQ; GSYM INT_OF_NUM_CLAUSES; o_THM] THEN + REWRITE_TAC[INT_REM_REM_MUL] THEN REWRITE_TAC[INT_REM_EQ; num_coprime] THEN + EQ_TAC THENL [ALL_TAC; INTEGER_TAC] THEN + ASM_CASES_TAC `m = 0` THENL + [DISCH_THEN(MP_TAC o SPECL [`&1:int`; `&0:int`] o CONJUNCT1) THEN + ASM_REWRITE_TAC[] THEN CONV_TAC INTEGER_RULE; + ALL_TAC] THEN + ASM_CASES_TAC `n = 0` THENL + [DISCH_THEN(MP_TAC o SPECL [`&1:int`; `&0:int`] o CONJUNCT1) THEN + ASM_REWRITE_TAC[] THEN CONV_TAC INTEGER_RULE; + ALL_TAC] THEN + DISCH_THEN(MP_TAC o SPEC `&0:int` o CONJUNCT2) THEN + REWRITE_TAC[INTEGER_RULE `(&0:int == x) (mod n) <=> n divides x`] THEN + DISCH_THEN(MP_TAC o SPEC `lcm(&m,&n):int`) THEN + REWRITE_TAC[GSYM NUM_LCM; GSYM num_divides; GSYM num_coprime; + INT_OF_NUM_CLAUSES; LCM] THEN + REWRITE_TAC[DIVIDES_LCM_GCD] THEN + REPEAT(POP_ASSUM MP_TAC) THEN NUMBER_TAC);; + +let ISOMORPHIC_PROD_INTEGER_MOD_RING = prove + (`!m n. integer_mod_ring(m * n) isomorphic_ring + prod_ring (integer_mod_ring m) (integer_mod_ring n) <=> + coprime(m,n)`, + REPEAT GEN_TAC THEN REWRITE_TAC[isomorphic_ring] THEN + REWRITE_TAC[GSYM RING_ISOMORPHISM_PROD_INTEGER_MOD_RING] THEN + MATCH_MP_TAC(MESON[] `(!f. P f ==> P g) ==> ((?f. P f) <=> P g)`) THEN + REPEAT STRIP_TAC THEN FIRST_ASSUM(MATCH_MP_TAC o MATCH_MP + (REWRITE_RULE[IMP_CONJ] RING_ISOMORPHISM_EQ)) THEN + FIRST_ASSUM(MP_TAC o MATCH_MP RING_HOMOMORPHISM_RING_OF_INT o + MATCH_MP RING_ISOMORPHISM_IMP_HOMOMORPHISM) THEN + REWRITE_TAC[INTEGER_MOD_RING_OF_INT; RING_OF_INT_PROD_RING] THEN + SIMP_TAC[RING_CARRIER_INTEGER_MOD_RING; FORALL_IN_IMAGE; IN_UNIV] THEN + REWRITE_TAC[GSYM INT_OF_NUM_MUL; INT_REM_REM_MUL]);; + +let VNREGULAR_INTEGER_MOD_RING = prove + (`!n. vnregular_ring(integer_mod_ring n) <=> squarefree n`, + GEN_TAC THEN REWRITE_TAC[vnregular_ring; INTEGER_MOD_RING_CLAUSES] THEN + REWRITE_TAC[RING_CARRIER_INTEGER_MOD_RING] THEN + REWRITE_TAC[FORALL_IN_IMAGE; EXISTS_IN_IMAGE; IN_UNIV] THEN + CONV_TAC INT_REM_DOWN_CONV THEN + REWRITE_TAC[INT_REM_EQ; INTEGER_RULE + `(?x:int. (a * x * a == a) (mod n)) <=> gcd(a pow 2,n) divides a`] THEN + ONCE_REWRITE_TAC[GSYM INT_DIVIDES_RABS] THEN + ONCE_REWRITE_TAC[GSYM INT_POW2_ABS] THEN + REWRITE_TAC[GSYM INT_FORALL_ABS; INT_OF_NUM_CLAUSES; GSYM NUM_GCD] THEN + REWRITE_TAC[GSYM num_divides; GSYM SQUAREFREE_GCD_SQUARE]);; + (* ------------------------------------------------------------------------- *) (* Conversion for explicit calculation over integer_mod_ring n (nonzero n) *) (* ------------------------------------------------------------------------- *) diff --git a/Minisat/minisat_prove.ml b/Minisat/minisat_prove.ml old mode 100644 new mode 100755 index 20c86de8..d18ddec1 --- a/Minisat/minisat_prove.ml +++ b/Minisat/minisat_prove.ml @@ -210,19 +210,6 @@ let GEN_SAT_PROVE solver solvername = let triv_rule p th = EQ_MP(INST [p,p_tm] pth_triv) th and main_rule p q sth th = itlist PROVE_HYP [sth; DISCH_ALL th] (INST [p,p_tm; q,q_tm] pth_main) in - let rec compoundprops tm = - match tm with - Comb(Comb(Const("/\\",_),l),r) -> - union (compoundprops l) (compoundprops r) - | Comb(Comb(Const("\\/",_),l),r) -> - union (compoundprops l) (compoundprops r) - | Comb(Comb(Const("==>",_),l),r) -> - union (compoundprops l) (compoundprops r) - | Comb(Comb(Const("=",Tyapp("fun",[Tyapp("bool",[]);_])),l),r) -> - union (compoundprops l) (compoundprops r) - | Comb(Const("~",_),l) -> compoundprops l - | Var(_,_) -> [] - | _ -> [tm] in let invoke_minisat lfn mcth stm t rcv vc = let nr = Array.length rcv in let res = match invokeSat solver None t (Some vc) with @@ -270,7 +257,7 @@ let GEN_SAT_PROVE solver solvername = else main_rule tm stm sth th) in fun tm -> if type_of tm <> bool_ty then failwith "GEN_SAT_PROVE" else - let pats = compoundprops tm in + let pats = filter (not o is_var) (atoms tm) in let bvs = map (genvar o type_of) pats in let tm' = subst (zip bvs pats) tm in try let th' = PROP_PROVE tm' in diff --git a/Multivariate/cauchy.ml b/Multivariate/cauchy.ml index 651f998d..71b63e50 100644 --- a/Multivariate/cauchy.ml +++ b/Multivariate/cauchy.ml @@ -21653,8 +21653,7 @@ let TORHORST_CONFORMAL_EXTENSION_THEOREM = prove ANTS_TAC THENL [ASM_MESON_TAC[REAL_LT_REFL]; ALL_TAC] THEN ASM_SIMP_TAC[SEGMENT_1; REAL_LT_IMP_LE] THEN DISCH_THEN SUBST1_TAC THEN REWRITE_TAC[GSYM IMAGE_o] THEN - EXPAND_TAC "q" THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + EXPAND_TAC "q" THEN MATCH_MP_TAC IMAGE_EQ THEN X_GEN_TAC `t:real^1` THEN STRIP_TAC THEN REWRITE_TAC[partcirclepath] THEN REWRITE_TAC[LINEPATH_CX; o_DEF] THEN REPLICATE_TAC 5 AP_TERM_TAC THEN REWRITE_TAC[DROP_ADD; DROP_SUB; DROP_CMUL] THEN REAL_ARITH_TAC; diff --git a/Multivariate/complex_database.ml b/Multivariate/complex_database.ml index c9f17cd6..9d1f9582 100644 --- a/Multivariate/complex_database.ml +++ b/Multivariate/complex_database.ml @@ -1636,6 +1636,8 @@ theorems := "CARD_IMAGE_INJ",CARD_IMAGE_INJ; "CARD_IMAGE_INJ_EQ",CARD_IMAGE_INJ_EQ; "CARD_IMAGE_LE",CARD_IMAGE_LE; +"CARD_IMAGE_LE2",CARD_IMAGE_LE2; +"CARD_IMAGE_LT2",CARD_IMAGE_LT2; "CARD_INFINITE_CONG",CARD_INFINITE_CONG; "CARD_INTSEG_INT",CARD_INTSEG_INT; "CARD_LDISTRIB",CARD_LDISTRIB; @@ -5533,6 +5535,8 @@ theorems := "DIV_0",DIV_0; "DIV_1",DIV_1; "DIV_ADD",DIV_ADD; +"DIV_ADD_EQ",DIV_ADD_EQ; +"DIV_ADD_EQ_EQ",DIV_ADD_EQ_EQ; "DIV_ADD_MOD",DIV_ADD_MOD; "DIV_BY_DIV",DIV_BY_DIV; "DIV_DIV",DIV_DIV; @@ -6626,6 +6630,7 @@ theorems := "FORALL_POS_MONO_1",FORALL_POS_MONO_1; "FORALL_POS_MONO_1_EQ",FORALL_POS_MONO_1_EQ; "FORALL_POS_MONO_EQ",FORALL_POS_MONO_EQ; +"FORALL_PRIME_INDEX",FORALL_PRIME_INDEX; "FORALL_REAL",FORALL_REAL; "FORALL_REAL_ONE",FORALL_REAL_ONE; "FORALL_RELATIVE_TO",FORALL_RELATIVE_TO; @@ -7334,6 +7339,7 @@ theorems := "GROUP_INV_INV",GROUP_INV_INV; "GROUP_INV_MUL",GROUP_INV_MUL; "GROUP_INV_POW",GROUP_INV_POW; +"GROUP_INV_SUBGROUP",GROUP_INV_SUBGROUP; "GROUP_INV_ZPOW",GROUP_INV_ZPOW; "GROUP_ISOMORPHISM",GROUP_ISOMORPHISM; "GROUP_ISOMORPHISMS",GROUP_ISOMORPHISMS; @@ -7462,6 +7468,7 @@ theorems := "GROUP_MUL_RCANCEL_IMP",GROUP_MUL_RCANCEL_IMP; "GROUP_MUL_RID",GROUP_MUL_RID; "GROUP_MUL_RINV",GROUP_MUL_RINV; +"GROUP_MUL_SUBGROUP",GROUP_MUL_SUBGROUP; "GROUP_MUL_ZPOW",GROUP_MUL_ZPOW; "GROUP_NEG",GROUP_NEG; "GROUP_NEG_ADD",GROUP_NEG_ADD; @@ -9285,6 +9292,7 @@ theorems := "IMAGE_DROPOUT_CLOSED_INTERVAL",IMAGE_DROPOUT_CLOSED_INTERVAL; "IMAGE_DROP_INTERVAL",IMAGE_DROP_INTERVAL; "IMAGE_DROP_UNIV",IMAGE_DROP_UNIV; +"IMAGE_EQ",IMAGE_EQ; "IMAGE_EQ_EMPTY",IMAGE_EQ_EMPTY; "IMAGE_FSTCART_PCROSS",IMAGE_FSTCART_PCROSS; "IMAGE_FST_CROSS",IMAGE_FST_CROSS; @@ -10377,10 +10385,14 @@ theorems := "INT_REM_1",INT_REM_1; "INT_REM_2_CASES",INT_REM_2_CASES; "INT_REM_2_DIVIDES",INT_REM_2_DIVIDES; +"INT_REM_2_EXPAND",INT_REM_2_EXPAND; +"INT_REM_2_NEG",INT_REM_2_NEG; "INT_REM_DIV",INT_REM_DIV; "INT_REM_EQ",INT_REM_EQ; "INT_REM_EQ_0",INT_REM_EQ_0; "INT_REM_EQ_SELF",INT_REM_EQ_SELF; +"INT_REM_LE",INT_REM_LE; +"INT_REM_LE_EQ",INT_REM_LE_EQ; "INT_REM_LNEG",INT_REM_LNEG; "INT_REM_LT",INT_REM_LT; "INT_REM_MOD_SELF",INT_REM_MOD_SELF; @@ -10393,7 +10405,9 @@ theorems := "INT_REM_RABS",INT_REM_RABS; "INT_REM_REFL",INT_REM_REFL; "INT_REM_REM",INT_REM_REM; +"INT_REM_REM_LE",INT_REM_REM_LE; "INT_REM_REM_MUL",INT_REM_REM_MUL; +"INT_REM_REM_POW_MIN",INT_REM_REM_POW_MIN; "INT_REM_RNEG",INT_REM_RNEG; "INT_REM_UNIQ",INT_REM_UNIQ; "INT_REM_UNIQUE",INT_REM_UNIQUE; @@ -12810,6 +12824,8 @@ theorems := "MOD_1",MOD_1; "MOD_2_CASES",MOD_2_CASES; "MOD_ADD_CASES",MOD_ADD_CASES; +"MOD_ADD_EQ",MOD_ADD_EQ; +"MOD_ADD_EQ_EQ",MOD_ADD_EQ_EQ; "MOD_ADD_MOD",MOD_ADD_MOD; "MOD_CASES",MOD_CASES; "MOD_DIV_EQ_0",MOD_DIV_EQ_0; @@ -13561,6 +13577,7 @@ theorems := "NUMSEG_LE",NUMSEG_LE; "NUMSEG_LREC",NUMSEG_LREC; "NUMSEG_LT",NUMSEG_LT; +"NUMSEG_LT_DIMINDEX",NUMSEG_LT_DIMINDEX; "NUMSEG_OFFSET_IMAGE",NUMSEG_OFFSET_IMAGE; "NUMSEG_REC",NUMSEG_REC; "NUMSEG_RREC",NUMSEG_RREC; @@ -14907,6 +14924,7 @@ theorems := "PRIME_GE_2",PRIME_GE_2; "PRIME_IMP_NZ",PRIME_IMP_NZ; "PRIME_INDEX_MAXIMAL_PROPER_SUBGROUP",PRIME_INDEX_MAXIMAL_PROPER_SUBGROUP; +"PRIME_INT_DIVPROD_EQ",PRIME_INT_DIVPROD_EQ; "PRIME_IRREDUCIBLE",PRIME_IRREDUCIBLE; "PRIME_ODD",PRIME_ODD; "PRIME_ORDER_EQ_NO_PROPER_SUBGROUPS",PRIME_ORDER_EQ_NO_PROPER_SUBGROUPS; @@ -16384,6 +16402,7 @@ theorems := "REAL_NOT_EQ",REAL_NOT_EQ; "REAL_NOT_LE",REAL_NOT_LE; "REAL_NOT_LT",REAL_NOT_LT; +"REAL_OF_INT_CLAUSES",REAL_OF_INT_CLAUSES; "REAL_OF_INT_OF_REAL",REAL_OF_INT_OF_REAL; "REAL_OF_NUM_ADD",REAL_OF_NUM_ADD; "REAL_OF_NUM_BINOM",REAL_OF_NUM_BINOM; @@ -18043,7 +18062,9 @@ theorems := "SUBGROUP_EPIMORPHISM_GROUP_SUM_EQ",SUBGROUP_EPIMORPHISM_GROUP_SUM_EQ; "SUBGROUP_EPIMORPHISM_GROUP_SUM_GEN",SUBGROUP_EPIMORPHISM_GROUP_SUM_GEN; "SUBGROUP_GENERATED",SUBGROUP_GENERATED; +"SUBGROUP_GENERATED_BY_EPIMORPHIC_IMAGE",SUBGROUP_GENERATED_BY_EPIMORPHIC_IMAGE; "SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE",SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE; +"SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE_EQ",SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE_EQ; "SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED",SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED; "SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED_IDEMPOT",SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED_IDEMPOT; "SUBGROUP_GENERATED_ELEMENT_ORDER",SUBGROUP_GENERATED_ELEMENT_ORDER; diff --git a/Multivariate/convex.ml b/Multivariate/convex.ml index f5f77c78..0f967c9a 100644 --- a/Multivariate/convex.ml +++ b/Multivariate/convex.ml @@ -15174,9 +15174,7 @@ let STARLIKE_COMPACT_PROJECTIVE = prove REWRITE_TAC[RELATIVE_INTERIOR_SUBSET] THEN FIRST_X_ASSUM(MP_TAC o GEN_REWRITE_RULE I [homeomorphism]) THEN DISCH_THEN(SUBST1_TAC o SYM o el 4 o CONJUNCTS) THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN - MAP_EVERY EXPAND_TAC ["usph"; "proj"] THEN + MATCH_MP_TAC IMAGE_EQ THEN MAP_EVERY EXPAND_TAC ["usph"; "proj"] THEN SIMP_TAC[IN_ELIM_THM; REAL_INV_1; REAL_MUL_LID; VECTOR_MUL_LID]]; ALL_TAC] THEN MATCH_MP_TAC HOMEOMORPHISM_COMPACT THEN diff --git a/Multivariate/homology.ml b/Multivariate/homology.ml index 58831043..efce240a 100644 --- a/Multivariate/homology.ml +++ b/Multivariate/homology.ml @@ -10210,9 +10210,7 @@ let ISOMORPHIC_RELATIVE_HOMOLOGY_GROUPS_EUCLIDEAN_COMPLEMENTS = prove REPEAT(FIRST_X_ASSUM(MP_TAC o MATCH_MP CLOSED_IN_SUBSET)) THEN ASM SET_TAC[]; ALL_TAC] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN - EXPAND_TAC "g'" THEN REWRITE_TAC[o_THM] THEN + MATCH_MP_TAC IMAGE_EQ THEN EXPAND_TAC "g'" THEN REWRITE_TAC[o_THM] THEN MATCH_MP_TAC(SET_RULE `(!x. x IN s ==> k(h(f x)) = f x) /\ (!x. x IN s ==> g(h x) = h(f x)) diff --git a/Multivariate/measure.ml b/Multivariate/measure.ml index 7d64aace..22b28216 100644 --- a/Multivariate/measure.ml +++ b/Multivariate/measure.ml @@ -26043,8 +26043,7 @@ let NEGLIGIBLE_ABSOLUTELY_CONTINUOUS_IMAGE, dd)` SUBST1_TAC THENL [REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> g x = f x) ==> IMAGE f s = IMAGE g s`) THEN + CONV_TAC SYM_CONV THEN MATCH_MP_TAC IMAGE_EQ THEN SIMP_TAC[INTERVAL_LOWERBOUND_1; INTERVAL_UPPERBOUND_1; LIFT_DROP; REAL_ARITH `min a b <= max a b`] THEN X_GEN_TAC `k:real^1->bool` THEN DISCH_TAC THEN @@ -26857,8 +26856,7 @@ let NEGLIGIBLE_IMAGE_INDEFINITE_INTEGRAL = prove ASM_SIMP_TAC[] THEN ANTS_TAC THENL [UNDISCH_TAC `(f:real^1->real^1) integrable_on interval[a,b]` THEN MATCH_MP_TAC INTEGRABLE_SPIKE; - MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> g x = f x) ==> IMAGE g s = IMAGE f s`) THEN + MATCH_MP_TAC EQ_IMP THEN AP_TERM_TAC THEN MATCH_MP_TAC IMAGE_EQ THEN X_GEN_TAC `x:real^1` THEN DISCH_TAC THEN REWRITE_TAC[] THEN MATCH_MP_TAC INTEGRAL_SPIKE] THEN EXISTS_TAC `s:real^1->bool` THEN ASM SET_TAC[]] THEN diff --git a/Multivariate/metric.ml b/Multivariate/metric.ml index 72afcf18..2cca33f8 100644 --- a/Multivariate/metric.ml +++ b/Multivariate/metric.ml @@ -5804,10 +5804,7 @@ let EMBEDDING_MAP_EQ = prove (!x. x IN topspace top ==> f x = g x) /\ embedding_map (top,top') f ==> embedding_map (top,top') g`, REPEAT GEN_TAC THEN REWRITE_TAC[embedding_map] THEN - DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC) THEN - FIRST_ASSUM(SUBST1_TAC o MATCH_MP (SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`)) THEN - ASM_MESON_TAC[HOMEOMORPHIC_MAP_EQ]);; + MESON_TAC[IMAGE_EQ; HOMEOMORPHIC_MAP_EQ]);; let EMBEDDING_MAP_COMPOSE = prove (`!top top' top'' (f:A->B) (g:B->C). @@ -14203,8 +14200,7 @@ let HOMEOMORPHIC_MAP_CONNECTED_COMPONENTS_OF = prove REPEAT STRIP_TAC THEN REWRITE_TAC[connected_components_of; SIMPLE_IMAGE] THEN FIRST_ASSUM(SUBST1_TAC o SYM o MATCH_MP HOMEOMORPHIC_IMP_SURJECTIVE_MAP) THEN - REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC IMAGE_EQ THEN REWRITE_TAC[] THEN ASM_MESON_TAC[HOMEOMORPHIC_MAP_CONNECTED_COMPONENT_OF]);; let CONNECTED_COMPONENT_OF_PAIR = prove @@ -21624,8 +21620,7 @@ let HOMEOMORPHIC_MAP_PATH_COMPONENTS_OF = prove REPEAT STRIP_TAC THEN REWRITE_TAC[path_components_of; SIMPLE_IMAGE] THEN FIRST_ASSUM(SUBST1_TAC o SYM o MATCH_MP HOMEOMORPHIC_IMP_SURJECTIVE_MAP) THEN - REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC IMAGE_EQ THEN REWRITE_TAC[] THEN ASM_MESON_TAC[HOMEOMORPHIC_MAP_PATH_COMPONENT_OF]);; let PATH_COMPONENT_OF_PAIR = prove @@ -25514,8 +25509,7 @@ let HOMEOMORPHIC_MAP_QUASI_COMPONENTS_OF = prove REPEAT STRIP_TAC THEN REWRITE_TAC[quasi_components_of; SIMPLE_IMAGE] THEN FIRST_ASSUM(SUBST1_TAC o SYM o MATCH_MP HOMEOMORPHIC_IMP_SURJECTIVE_MAP) THEN - REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC IMAGE_EQ THEN REWRITE_TAC[] THEN ASM_MESON_TAC[HOMEOMORPHIC_MAP_QUASI_COMPONENT_OF]);; let OPEN_IN_QUASI_COMPONENT_OF_LOCALLY_CONNECTED_SPACE = prove diff --git a/Multivariate/misc.ml b/Multivariate/misc.ml index 1618ef45..a0b1de1a 100644 --- a/Multivariate/misc.ml +++ b/Multivariate/misc.ml @@ -1946,8 +1946,7 @@ let BACK_AND_FORTH = prove ALL_TAC] THEN SUBGOAL_THEN `IMAGE (f:A->B) s' = t'` ASSUME_TAC THENL [MAP_EVERY EXPAND_TAC ["s'"; "t'"] THEN REWRITE_TAC[GSYM IMAGE_o] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + MATCH_MP_TAC IMAGE_EQ THEN REWRITE_TAC[FORALL_PAIR_THM; o_THM] THEN ASM_MESON_TAC[]; ASM_REWRITE_TAC[]] THEN ANTS_TAC THENL diff --git a/Multivariate/multivariate_database.ml b/Multivariate/multivariate_database.ml index e468c260..94779a45 100644 --- a/Multivariate/multivariate_database.ml +++ b/Multivariate/multivariate_database.ml @@ -1362,6 +1362,8 @@ theorems := "CARD_IMAGE_INJ",CARD_IMAGE_INJ; "CARD_IMAGE_INJ_EQ",CARD_IMAGE_INJ_EQ; "CARD_IMAGE_LE",CARD_IMAGE_LE; +"CARD_IMAGE_LE2",CARD_IMAGE_LE2; +"CARD_IMAGE_LT2",CARD_IMAGE_LT2; "CARD_INFINITE_CONG",CARD_INFINITE_CONG; "CARD_INTSEG_INT",CARD_INTSEG_INT; "CARD_LDISTRIB",CARD_LDISTRIB; @@ -4560,6 +4562,8 @@ theorems := "DIV_0",DIV_0; "DIV_1",DIV_1; "DIV_ADD",DIV_ADD; +"DIV_ADD_EQ",DIV_ADD_EQ; +"DIV_ADD_EQ_EQ",DIV_ADD_EQ_EQ; "DIV_ADD_MOD",DIV_ADD_MOD; "DIV_BY_DIV",DIV_BY_DIV; "DIV_DIV",DIV_DIV; @@ -5617,6 +5621,7 @@ theorems := "FORALL_POS_MONO_1",FORALL_POS_MONO_1; "FORALL_POS_MONO_1_EQ",FORALL_POS_MONO_1_EQ; "FORALL_POS_MONO_EQ",FORALL_POS_MONO_EQ; +"FORALL_PRIME_INDEX",FORALL_PRIME_INDEX; "FORALL_REAL_ONE",FORALL_REAL_ONE; "FORALL_RELATIVE_TO",FORALL_RELATIVE_TO; "FORALL_SETCODE",FORALL_SETCODE; @@ -6307,6 +6312,7 @@ theorems := "GROUP_INV_INV",GROUP_INV_INV; "GROUP_INV_MUL",GROUP_INV_MUL; "GROUP_INV_POW",GROUP_INV_POW; +"GROUP_INV_SUBGROUP",GROUP_INV_SUBGROUP; "GROUP_INV_ZPOW",GROUP_INV_ZPOW; "GROUP_ISOMORPHISM",GROUP_ISOMORPHISM; "GROUP_ISOMORPHISMS",GROUP_ISOMORPHISMS; @@ -6435,6 +6441,7 @@ theorems := "GROUP_MUL_RCANCEL_IMP",GROUP_MUL_RCANCEL_IMP; "GROUP_MUL_RID",GROUP_MUL_RID; "GROUP_MUL_RINV",GROUP_MUL_RINV; +"GROUP_MUL_SUBGROUP",GROUP_MUL_SUBGROUP; "GROUP_MUL_ZPOW",GROUP_MUL_ZPOW; "GROUP_NEG",GROUP_NEG; "GROUP_NEG_ADD",GROUP_NEG_ADD; @@ -7772,6 +7779,7 @@ theorems := "IMAGE_DROPOUT_CLOSED_INTERVAL",IMAGE_DROPOUT_CLOSED_INTERVAL; "IMAGE_DROP_INTERVAL",IMAGE_DROP_INTERVAL; "IMAGE_DROP_UNIV",IMAGE_DROP_UNIV; +"IMAGE_EQ",IMAGE_EQ; "IMAGE_EQ_EMPTY",IMAGE_EQ_EMPTY; "IMAGE_FSTCART_PCROSS",IMAGE_FSTCART_PCROSS; "IMAGE_FST_CROSS",IMAGE_FST_CROSS; @@ -8801,10 +8809,14 @@ theorems := "INT_REM_1",INT_REM_1; "INT_REM_2_CASES",INT_REM_2_CASES; "INT_REM_2_DIVIDES",INT_REM_2_DIVIDES; +"INT_REM_2_EXPAND",INT_REM_2_EXPAND; +"INT_REM_2_NEG",INT_REM_2_NEG; "INT_REM_DIV",INT_REM_DIV; "INT_REM_EQ",INT_REM_EQ; "INT_REM_EQ_0",INT_REM_EQ_0; "INT_REM_EQ_SELF",INT_REM_EQ_SELF; +"INT_REM_LE",INT_REM_LE; +"INT_REM_LE_EQ",INT_REM_LE_EQ; "INT_REM_LNEG",INT_REM_LNEG; "INT_REM_LT",INT_REM_LT; "INT_REM_MOD_SELF",INT_REM_MOD_SELF; @@ -8817,7 +8829,9 @@ theorems := "INT_REM_RABS",INT_REM_RABS; "INT_REM_REFL",INT_REM_REFL; "INT_REM_REM",INT_REM_REM; +"INT_REM_REM_LE",INT_REM_REM_LE; "INT_REM_REM_MUL",INT_REM_REM_MUL; +"INT_REM_REM_POW_MIN",INT_REM_REM_POW_MIN; "INT_REM_RNEG",INT_REM_RNEG; "INT_REM_UNIQ",INT_REM_UNIQ; "INT_REM_UNIQUE",INT_REM_UNIQUE; @@ -11041,6 +11055,8 @@ theorems := "MOD_1",MOD_1; "MOD_2_CASES",MOD_2_CASES; "MOD_ADD_CASES",MOD_ADD_CASES; +"MOD_ADD_EQ",MOD_ADD_EQ; +"MOD_ADD_EQ_EQ",MOD_ADD_EQ_EQ; "MOD_ADD_MOD",MOD_ADD_MOD; "MOD_CASES",MOD_CASES; "MOD_DIV_EQ_0",MOD_DIV_EQ_0; @@ -11749,6 +11765,7 @@ theorems := "NUMSEG_LE",NUMSEG_LE; "NUMSEG_LREC",NUMSEG_LREC; "NUMSEG_LT",NUMSEG_LT; +"NUMSEG_LT_DIMINDEX",NUMSEG_LT_DIMINDEX; "NUMSEG_OFFSET_IMAGE",NUMSEG_OFFSET_IMAGE; "NUMSEG_REC",NUMSEG_REC; "NUMSEG_RREC",NUMSEG_RREC; @@ -12964,6 +12981,7 @@ theorems := "PRIME_GE_2",PRIME_GE_2; "PRIME_IMP_NZ",PRIME_IMP_NZ; "PRIME_INDEX_MAXIMAL_PROPER_SUBGROUP",PRIME_INDEX_MAXIMAL_PROPER_SUBGROUP; +"PRIME_INT_DIVPROD_EQ",PRIME_INT_DIVPROD_EQ; "PRIME_IRREDUCIBLE",PRIME_IRREDUCIBLE; "PRIME_ODD",PRIME_ODD; "PRIME_ORDER_EQ_NO_PROPER_SUBGROUPS",PRIME_ORDER_EQ_NO_PROPER_SUBGROUPS; @@ -13687,6 +13705,7 @@ theorems := "REAL_NOT_EQ",REAL_NOT_EQ; "REAL_NOT_LE",REAL_NOT_LE; "REAL_NOT_LT",REAL_NOT_LT; +"REAL_OF_INT_CLAUSES",REAL_OF_INT_CLAUSES; "REAL_OF_INT_OF_REAL",REAL_OF_INT_OF_REAL; "REAL_OF_NUM_ADD",REAL_OF_NUM_ADD; "REAL_OF_NUM_CLAUSES",REAL_OF_NUM_CLAUSES; @@ -14896,7 +14915,9 @@ theorems := "SUBGROUP_EPIMORPHISM_GROUP_SUM_EQ",SUBGROUP_EPIMORPHISM_GROUP_SUM_EQ; "SUBGROUP_EPIMORPHISM_GROUP_SUM_GEN",SUBGROUP_EPIMORPHISM_GROUP_SUM_GEN; "SUBGROUP_GENERATED",SUBGROUP_GENERATED; +"SUBGROUP_GENERATED_BY_EPIMORPHIC_IMAGE",SUBGROUP_GENERATED_BY_EPIMORPHIC_IMAGE; "SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE",SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE; +"SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE_EQ",SUBGROUP_GENERATED_BY_HOMOMORPHIC_IMAGE_EQ; "SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED",SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED; "SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED_IDEMPOT",SUBGROUP_GENERATED_BY_SUBGROUP_GENERATED_IDEMPOT; "SUBGROUP_GENERATED_ELEMENT_ORDER",SUBGROUP_GENERATED_ELEMENT_ORDER; diff --git a/Multivariate/paths.ml b/Multivariate/paths.ml index 941e7072..ba8fac96 100644 --- a/Multivariate/paths.ml +++ b/Multivariate/paths.ml @@ -15390,8 +15390,7 @@ let HOMEOMORPHISM_GROUPING_POINTS_EXISTS = prove ASM_REAL_ARITH_TAC; REWRITE_TAC[IMAGE_UNION] THEN BINOP_TAC THEN FIRST_X_ASSUM(fun th -> GEN_REWRITE_TAC RAND_CONV [SYM th]) THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + MATCH_MP_TAC IMAGE_EQ THEN SIMP_TAC[IN_INTERVAL_1; REAL_ARITH `b <= c ==> (c <= b <=> c = b)`] THEN ASM_MESON_TAC[DROP_EQ]]; @@ -15958,8 +15957,7 @@ let HOMEOMORPHISM_MOVING_DENSE_COUNTABLE_SUBSETS_EXISTS = prove COND_CASES_TAC THEN ASM_SIMP_TAC[LIFT_DROP] THEN REWRITE_TAC[GSYM LIFT_EQ; LIFT_DROP] THEN RULE_ASSUM_TAC(REWRITE_RULE[IN_NUMSEG]) THEN ASM_SIMP_TAC[]; - EXPAND_TAC "t" THEN MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + EXPAND_TAC "t" THEN MATCH_MP_TAC IMAGE_EQ THEN ASM_SIMP_TAC[CART_EQ; LAMBDA_BETA; IN_NUMSEG] THEN X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN X_GEN_TAC `i:num` THEN STRIP_TAC THEN diff --git a/Multivariate/topology.ml b/Multivariate/topology.ml index 64c4e9cc..fbb203ce 100644 --- a/Multivariate/topology.ml +++ b/Multivariate/topology.ml @@ -11865,8 +11865,7 @@ let COMPONENTS_SEPARATED_UNION = prove ==> components(s UNION t) = components(s) UNION components(t)`, REPEAT STRIP_TAC THEN REWRITE_TAC[components] THEN REWRITE_TAC[SIMPLE_IMAGE; IMAGE_UNION] THEN BINOP_TAC THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + MATCH_MP_TAC IMAGE_EQ THEN X_GEN_TAC `x:real^N` THEN REWRITE_TAC[GSYM SUBSET_ANTISYM] THENL [ALL_TAC; ONCE_REWRITE_TAC[UNION_COMM]] THEN ASM_SIMP_TAC[CONNECTED_COMPONENT_SEPARATED_UNION]);; @@ -17863,8 +17862,7 @@ let CONNECTED_CARD_LT_IFF_TRIVIAL = prove let SMALL_IMP_TOTALLY_DISCONNECTED = prove (`!s:real^N->bool. s <_c (:real) ==> components s = IMAGE (\x. {x}) s`, REPEAT STRIP_TAC THEN REWRITE_TAC[components; SIMPLE_IMAGE] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + MATCH_MP_TAC IMAGE_EQ THEN X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN REWRITE_TAC[] THEN MATCH_MP_TAC(SET_RULE `s x /\ (?a. s SUBSET {a}) ==> s = {x}`) THEN ASM_REWRITE_TAC[CONNECTED_COMPONENT_REFL_EQ] THEN @@ -35515,8 +35513,7 @@ let ANALYTIC_CONTINUOUS_IMAGE = prove SUBSET_UNIV]; REWRITE_TAC[IMAGE_UNIONS]] THEN REWRITE_TAC[SIMPLE_IMAGE; GSYM IMAGE_o] THEN AP_TERM_TAC THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + MATCH_MP_TAC IMAGE_EQ THEN X_GEN_TAC `s:num->num` THEN REWRITE_TAC[o_THM; IN_UNIV] THEN W(MP_TAC o PART_MATCH (lhand o rand) CONTINUOUS_IMAGE_NESTED_INTERS_GEN o lhand o snd) THEN diff --git a/Multivariate/vectors.ml b/Multivariate/vectors.ml index cc3278ab..b9027213 100644 --- a/Multivariate/vectors.ml +++ b/Multivariate/vectors.ml @@ -6917,9 +6917,7 @@ let COLUMNS_IMAGE_BASIS = prove columns A = IMAGE (\x. A ** x) {basis i | 1 <= i /\ i <= dimindex(:M)}`, GEN_TAC THEN REWRITE_TAC[columns] THEN ONCE_REWRITE_TAC[SIMPLE_IMAGE_GEN] THEN - REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN - MATCH_MP_TAC(SET_RULE - `(!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`) THEN + REWRITE_TAC[GSYM IMAGE_o; o_DEF] THEN MATCH_MP_TAC IMAGE_EQ THEN SIMP_TAC[IN_ELIM_THM; MATRIX_VECTOR_MUL_BASIS]);; let RANK_DIM_IM = prove diff --git a/basics.ml b/basics.ml old mode 100644 new mode 100755 index 3e13f6d9..aa03c299 --- a/basics.ml +++ b/basics.ml @@ -446,3 +446,20 @@ let follow_path = | "r"::t -> follow_path t (rand tm) | _::t -> follow_path t (body tm) in fun s tm -> follow_path (explode s) tm;; + +(* ------------------------------------------------------------------------- *) +(* Considering a term as a propositional formula and returning atoms. *) +(* ------------------------------------------------------------------------- *) + +let atoms = + let rec atoms acc tm = + match tm with + Comb(Comb(Const("/\\",_),l),r) + | Comb(Comb(Const("\\/",_),l),r) + | Comb(Comb(Const("==>",_),l),r) + | Comb(Comb(Const("=",Tyapp("fun",[Tyapp("bool",[]);_])),l),r) -> + atoms (atoms acc l) r + | Comb(Const("~",_),l) -> atoms acc l + | _ -> (tm |-> ()) acc in + fun tm -> if type_of tm <> bool_ty then failwith "atoms: not Boolean" + else foldl (fun a x y -> x::a) [] (atoms undefined tm);; diff --git a/cart.ml b/cart.ml index 7ecf0f8d..913f77d3 100644 --- a/cart.ml +++ b/cart.ml @@ -115,7 +115,7 @@ let cart_tybij = parse_as_infix("$",(25,"left"));; let finite_index = new_definition - `x$i = dest_cart x (finite_index i)`;; + `(x:A^N)$i = dest_cart x (finite_index i)`;; let CART_EQ = prove (`!x:A^B y. @@ -147,7 +147,7 @@ let LAMBDA_UNIQUE = prove SIMP_TAC[CART_EQ; LAMBDA_BETA] THEN MESON_TAC[]);; let LAMBDA_ETA = prove - (`!g. (lambda i. g$i) = g`, + (`!g. (lambda i. g$i):A^B = g`, REWRITE_TAC[CART_EQ; LAMBDA_BETA]);; (* ------------------------------------------------------------------------- *) @@ -225,7 +225,7 @@ let SNDCART_PASTECART = prove ASM_SIMP_TAC[ADD_SUB; ARITH_RULE `1 <= i ==> ~(i + a <= a)`]]);; let PASTECART_FST_SND = prove - (`!z. pastecart (fstcart z) (sndcart z) = z`, + (`!z. pastecart (fstcart z) (sndcart z):A^(M,N)finite_sum = z`, SIMP_TAC[pastecart; fstcart; sndcart; CART_EQ; LAMBDA_BETA] THEN REPEAT GEN_TAC THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[] THEN ASM_SIMP_TAC[DIMINDEX_FINITE_SUM; LAMBDA_BETA; @@ -234,15 +234,16 @@ let PASTECART_FST_SND = prove ARITH_RULE `~(i <= a) ==> ((i - a) + a = i)`]);; let PASTECART_EQ = prove - (`!x y. (x = y) <=> (fstcart x = fstcart y) /\ (sndcart x = sndcart y)`, + (`!x y:A^(M,N)finite_sum. + x = y <=> fstcart x = fstcart y /\ sndcart x = sndcart y`, MESON_TAC[PASTECART_FST_SND]);; let FORALL_PASTECART = prove - (`(!p. P p) <=> !x y. P (pastecart x y)`, + (`(!p:A^(M,N)finite_sum. P p) <=> !x y. P (pastecart x y)`, MESON_TAC[PASTECART_FST_SND; FSTCART_PASTECART; SNDCART_PASTECART]);; let EXISTS_PASTECART = prove - (`(?p. P p) <=> ?x y. P (pastecart x y)`, + (`(?p:A^(M,N)finite_sum. P p) <=> ?x y. P (pastecart x y)`, MESON_TAC[PASTECART_FST_SND; FSTCART_PASTECART; SNDCART_PASTECART]);; let PASTECART_INJ = prove @@ -558,7 +559,7 @@ let vector = new_definition (* ------------------------------------------------------------------------- *) let IN_ELIM_PASTECART_THM = prove - (`!P a b. pastecart a b IN {pastecart x y | P x y} <=> P a b`, + (`!P (a:A^M) (b:A^N). pastecart a b IN {pastecart x y | P x y} <=> P a b`, REWRITE_TAC[IN_ELIM_THM; PASTECART_EQ; FSTCART_PASTECART; SNDCART_PASTECART] THEN MESON_TAC[]);; @@ -573,40 +574,43 @@ let PCROSS = new_definition `s PCROSS t = {pastecart (x:A^M) (y:A^N) | x IN s /\ y IN t}`;; let FORALL_IN_PCROSS = prove - (`(!z. z IN s PCROSS t ==> P z) <=> + (`(!z:A^(M,N)finite_sum. z IN s PCROSS t ==> P z) <=> (!x y. x IN s /\ y IN t ==> P(pastecart x y))`, REWRITE_TAC[PCROSS; FORALL_IN_GSPEC]);; let EXISTS_IN_PCROSS = prove - (`(?z. z IN s PCROSS t /\ P z) <=> + (`(?z:A^(M,N)finite_sum. z IN s PCROSS t /\ P z) <=> (?x y. x IN s /\ y IN t /\ P(pastecart x y))`, REWRITE_TAC[PCROSS; EXISTS_IN_GSPEC; CONJ_ASSOC]);; let PASTECART_IN_PCROSS = prove - (`!s t x y. (pastecart x y) IN (s PCROSS t) <=> x IN s /\ y IN t`, + (`!s t (x:A^M) (y:A^N). (pastecart x y) IN (s PCROSS t) <=> x IN s /\ y IN t`, REWRITE_TAC[PCROSS; IN_ELIM_PASTECART_THM]);; let PCROSS_EQ_EMPTY = prove - (`!s t. s PCROSS t = {} <=> s = {} \/ t = {}`, + (`!(s:A^M->bool) (t:A^N->bool). s PCROSS t = {} <=> s = {} \/ t = {}`, REWRITE_TAC[PCROSS] THEN SET_TAC[]);; let PCROSS_EMPTY = prove - (`(!s. s PCROSS {} = {}) /\ (!t. {} PCROSS t = {})`, + (`(!s. (s PCROSS {}) :A^(M,N)finite_sum->bool = {}) /\ + (!t. ({} PCROSS t) :A^(M,N)finite_sum->bool = {})`, REWRITE_TAC[PCROSS_EQ_EMPTY]);; let PCROSS_SING = prove - (`!x y:A^N. {x} PCROSS {y} = {pastecart x y}`, + (`!(x:A^M) (y:A^N). {x} PCROSS {y} = {pastecart x y}`, REWRITE_TAC[EXTENSION; FORALL_PASTECART; IN_SING; PASTECART_IN_PCROSS; PASTECART_INJ]);; let SUBSET_PCROSS = prove - (`!s t s' t'. s PCROSS t SUBSET s' PCROSS t' <=> - s = {} \/ t = {} \/ s SUBSET s' /\ t SUBSET t'`, + (`!(s:A^M->bool) (t:A^N->bool) s' t'. + s PCROSS t SUBSET s' PCROSS t' <=> + s = {} \/ t = {} \/ s SUBSET s' /\ t SUBSET t'`, SIMP_TAC[PCROSS; EXTENSION; IN_ELIM_PASTECART_THM; SUBSET; FORALL_PASTECART; PASTECART_IN_PCROSS; NOT_IN_EMPTY] THEN MESON_TAC[]);; let PCROSS_MONO = prove - (`!s t s' t'. s SUBSET s' /\ t SUBSET t' ==> s PCROSS t SUBSET s' PCROSS t'`, + (`!(s:A^M->bool) (t:A^N->bool) s' t'. + s SUBSET s' /\ t SUBSET t' ==> s PCROSS t SUBSET s' PCROSS t'`, SIMP_TAC[SUBSET_PCROSS]);; let PCROSS_EQ = prove @@ -668,46 +672,54 @@ let IMAGE_SNDCART_PCROSS = prove REWRITE_TAC[EXISTS_IN_PCROSS; SNDCART_PASTECART] THEN ASM SET_TAC[]);; let PCROSS_INTER = prove - (`(!s t u. s PCROSS (t INTER u) = (s PCROSS t) INTER (s PCROSS u)) /\ - (!s t u. (s INTER t) PCROSS u = (s PCROSS u) INTER (t PCROSS u))`, + (`(!(s:A^M->bool) (t:A^N->bool) u. + s PCROSS (t INTER u) = (s PCROSS t) INTER (s PCROSS u)) /\ + (!(s:A^M->bool) t (u:A^N->bool). + (s INTER t) PCROSS u = (s PCROSS u) INTER (t PCROSS u))`, REWRITE_TAC[EXTENSION; FORALL_PASTECART; IN_INTER; PASTECART_IN_PCROSS] THEN REPEAT STRIP_TAC THEN CONV_TAC TAUT);; let PCROSS_UNION = prove - (`(!s t u. s PCROSS (t UNION u) = (s PCROSS t) UNION (s PCROSS u)) /\ - (!s t u. (s UNION t) PCROSS u = (s PCROSS u) UNION (t PCROSS u))`, + (`(!(s:A^M->bool) (t:A^N->bool) u. + s PCROSS (t UNION u) = (s PCROSS t) UNION (s PCROSS u)) /\ + (!(s:A^M->bool) t (u:A^N->bool). + (s UNION t) PCROSS u = (s PCROSS u) UNION (t PCROSS u))`, REWRITE_TAC[EXTENSION; FORALL_PASTECART; IN_UNION; PASTECART_IN_PCROSS] THEN REPEAT STRIP_TAC THEN CONV_TAC TAUT);; let PCROSS_DIFF = prove - (`(!s t u. s PCROSS (t DIFF u) = (s PCROSS t) DIFF (s PCROSS u)) /\ - (!s t u. (s DIFF t) PCROSS u = (s PCROSS u) DIFF (t PCROSS u))`, + (`(!(s:A^M->bool) (t:A^N->bool) u. + s PCROSS (t DIFF u) = (s PCROSS t) DIFF (s PCROSS u)) /\ + (!(s:A^M->bool) t (u:A^N->bool). + (s DIFF t) PCROSS u = (s PCROSS u) DIFF (t PCROSS u))`, REWRITE_TAC[EXTENSION; FORALL_PASTECART; IN_DIFF; PASTECART_IN_PCROSS] THEN REPEAT STRIP_TAC THEN CONV_TAC TAUT);; let INTER_PCROSS = prove - (`!s s' t t'. + (`!(s:A^M->bool) s' (t:A^N->bool) t'. (s PCROSS t) INTER (s' PCROSS t') = (s INTER s') PCROSS (t INTER t')`, REWRITE_TAC[EXTENSION; IN_INTER; FORALL_PASTECART; PASTECART_IN_PCROSS] THEN CONV_TAC TAUT);; let PCROSS_UNIONS_UNIONS,PCROSS_UNIONS = (CONJ_PAIR o prove) - (`(!f g. (UNIONS f) PCROSS (UNIONS g) = + (`(!f g. ((UNIONS f) PCROSS (UNIONS g)) :A^(M,N)finite_sum->bool = UNIONS {s PCROSS t | s IN f /\ t IN g}) /\ - (!s f. s PCROSS (UNIONS f) = UNIONS {s PCROSS t | t IN f}) /\ - (!f t. (UNIONS f) PCROSS t = UNIONS {s PCROSS t | s IN f})`, + (!s f. (s PCROSS (UNIONS f)) :A^(M,N)finite_sum->bool = + UNIONS {s PCROSS t | t IN f}) /\ + (!f t. ((UNIONS f) PCROSS t) :A^(M,N)finite_sum->bool = + UNIONS {s PCROSS t | s IN f})`, REWRITE_TAC[UNIONS_GSPEC; EXTENSION; FORALL_PASTECART; IN_ELIM_THM; PASTECART_IN_PCROSS] THEN SET_TAC[]);; let PCROSS_INTERS_INTERS,PCROSS_INTERS = (CONJ_PAIR o prove) - (`(!f g. (INTERS f) PCROSS (INTERS g) = + (`(!f g. ((INTERS f) PCROSS (INTERS g)) :A^(M,N)finite_sum->bool = if f = {} then INTERS {UNIV PCROSS t | t IN g} else if g = {} then INTERS {s PCROSS UNIV | s IN f} else INTERS {s PCROSS t | s IN f /\ t IN g}) /\ - (!s f. s PCROSS (INTERS f) = + (!s f. (s PCROSS (INTERS f)) :A^(M,N)finite_sum->bool = if f = {} then s PCROSS UNIV else INTERS {s PCROSS t | t IN f}) /\ - (!f t. (INTERS f) PCROSS t = + (!f t. ((INTERS f) PCROSS t) :A^(M,N)finite_sum->bool = if f = {} then UNIV PCROSS t else INTERS {s PCROSS t | s IN f})`, REPEAT STRIP_TAC THEN REPEAT (COND_CASES_TAC THEN REWRITE_TAC[]) THEN ASM_REWRITE_TAC[INTERS_GSPEC; EXTENSION; FORALL_PASTECART; IN_ELIM_THM; diff --git a/class.ml b/class.ml old mode 100644 new mode 100755 index 37149123..6aaa9ff3 --- a/class.ml +++ b/class.ml @@ -424,7 +424,7 @@ let SKOLEM_THM = prove POP_ASSUM MATCH_ACCEPT_TAC);; let SKOLEM_THM_GEN = prove - (`!P R. (!x. P x ==> ?y. R x y) <=> (?f. !x. P x ==> R x (f x))`, + (`!P R. (!x:A. P x ==> ?y:B. R x y) <=> (?f. !x. P x ==> R x (f x))`, REWRITE_TAC[RIGHT_IMP_EXISTS_THM; SKOLEM_THM]);; (* ------------------------------------------------------------------------- *) diff --git a/database.ml b/database.ml index ee590b2e..f109775d 100644 --- a/database.ml +++ b/database.ml @@ -148,6 +148,8 @@ theorems := "CARD_IMAGE_INJ",CARD_IMAGE_INJ; "CARD_IMAGE_INJ_EQ",CARD_IMAGE_INJ_EQ; "CARD_IMAGE_LE",CARD_IMAGE_LE; +"CARD_IMAGE_LE2",CARD_IMAGE_LE2; +"CARD_IMAGE_LT2",CARD_IMAGE_LT2; "CARD_LE_1",CARD_LE_1; "CARD_LE_INJ",CARD_LE_INJ; "CARD_LE_UNIONS_CHAIN",CARD_LE_UNIONS_CHAIN; @@ -347,6 +349,8 @@ theorems := "DIV_0",DIV_0; "DIV_1",DIV_1; "DIV_ADD",DIV_ADD; +"DIV_ADD_EQ",DIV_ADD_EQ; +"DIV_ADD_EQ_EQ",DIV_ADD_EQ_EQ; "DIV_ADD_MOD",DIV_ADD_MOD; "DIV_BY_DIV",DIV_BY_DIV; "DIV_DIV",DIV_DIV; @@ -761,6 +765,7 @@ theorems := "IMAGE_DELETE_INJ_ALT",IMAGE_DELETE_INJ_ALT; "IMAGE_DIFF_INJ",IMAGE_DIFF_INJ; "IMAGE_DIFF_INJ_ALT",IMAGE_DIFF_INJ_ALT; +"IMAGE_EQ",IMAGE_EQ; "IMAGE_EQ_EMPTY",IMAGE_EQ_EMPTY; "IMAGE_FSTCART_PCROSS",IMAGE_FSTCART_PCROSS; "IMAGE_FST_CROSS",IMAGE_FST_CROSS; @@ -1533,6 +1538,8 @@ theorems := "MOD_1",MOD_1; "MOD_2_CASES",MOD_2_CASES; "MOD_ADD_CASES",MOD_ADD_CASES; +"MOD_ADD_EQ",MOD_ADD_EQ; +"MOD_ADD_EQ_EQ",MOD_ADD_EQ_EQ; "MOD_ADD_MOD",MOD_ADD_MOD; "MOD_CASES",MOD_CASES; "MOD_DIV_EQ_0",MOD_DIV_EQ_0; diff --git a/holtest b/holtest index e6b620c4..548d48cd 100755 --- a/holtest +++ b/holtest @@ -31,6 +31,8 @@ fi # Standalone examples echo '### Loading Library/agm.ml'; echo 'loadt "Library/agm.ml";;' | (time $hollight) +echo '### Loading Library/bdd.ml, Examples/bdd_examples.ml'; +(echo 'loadt "Library/bdd.ml";;'; echo 'loadt "Examples/bdd_examples.ml";;') | (time $hollight) echo '### Loading Library/binary.ml'; echo 'loadt "Library/binary.ml";;' | (time $hollight) echo '### Loading Library/binomial.ml'; echo 'loadt "Library/binomial.ml";;' | (time $hollight) echo '### Loading Library/bitmatch.ml'; echo 'loadt "Library/bitmatch.ml";;' | (time $hollight) diff --git a/holtest.mk b/holtest.mk index 9fefb5b7..12a5f200 100644 --- a/holtest.mk +++ b/holtest.mk @@ -2,6 +2,8 @@ HOLLIGHT:=ocaml -init hol.ml STANDALONE_EXAMPLES:=\ Library/agm \ + Library/bdd \ + Examples/bdd_examples \ Library/binary \ Library/binomial \ Library/bitmatch \ diff --git a/ind_types.ml b/ind_types.ml old mode 100644 new mode 100755 index 7876965c..457410ab --- a/ind_types.ml +++ b/ind_types.ml @@ -887,7 +887,7 @@ let list_INDUCT,list_RECURSION = (parse_inductive_type_specification "list = NIL | CONS A list");; let FORALL_OPTION_THM = prove - (`!P. (!x. P x) <=> P NONE /\ !a. P(SOME a)`, + (`!P:A option->bool. (!x. P x) <=> P NONE /\ !a. P(SOME a)`, GEN_TAC THEN EQ_TAC THEN REWRITE_TAC[option_INDUCT] THEN SIMP_TAC[]);; let EXISTS_OPTION_THM = prove @@ -1074,7 +1074,7 @@ let ISO_USAGE = prove (`ISO f g ==> (!P. (!x. P x) <=> (!x. P(g x))) /\ (!P. (?x. P x) <=> (?x. P(g x))) /\ - (!a b. (a = g b) <=> (f a = b))`, + (!(a:A) (b:B). (a = g b) <=> (f a = b))`, REWRITE_TAC[ISO; FUN_EQ_THM] THEN MESON_TAC[]);; (* ------------------------------------------------------------------------- *) diff --git a/int.ml b/int.ml index 0018bc39..661e9a64 100755 --- a/int.ml +++ b/int.ml @@ -1180,7 +1180,7 @@ parse_as_infix("divides",(12,"right"));; overload_interface("divides",`int_divides:int->int->bool`);; let int_divides = new_definition - `a divides b <=> ?x. b = a * x`;; + `a divides b <=> ?x:int. b = a * x`;; let INT_DIVIDES_LE = prove (`!x y:int. x divides y ==> abs(x) <= abs(y) \/ y = &0`, @@ -2334,7 +2334,7 @@ let CONG_DIV2 = prove SIMP_TAC[CONG; DIV_MOD]);; let divides = prove - (`a divides b <=> ?x. b = a * x`, + (`a divides b <=> ?x:num. b = a * x`, REWRITE_TAC[num_divides; int_divides] THEN EQ_TAC THENL [ALL_TAC; MESON_TAC[INT_OF_NUM_MUL; INT_OF_NUM_EQ]] THEN DISCH_THEN(X_CHOOSE_TAC `x:int`) THEN EXISTS_TAC `num_of_int(abs x)` THEN diff --git a/iterate.ml b/iterate.ml index 88b68990..90cfacb5 100644 --- a/iterate.ml +++ b/iterate.ml @@ -279,7 +279,7 @@ let FINITE_INT_SEG = prove (* ------------------------------------------------------------------------- *) let neutral = new_definition - `neutral op = @x. !y. (op x y = y) /\ (op y x = y)`;; + `neutral op = @x:A. !y. (op x y = y) /\ (op y x = y)`;; let monoidal = new_definition `monoidal op <=> (!x y. op x y = op y x) /\ @@ -288,7 +288,7 @@ let monoidal = new_definition let MONOIDAL_AC = prove (`!op. monoidal op - ==> (!a. op (neutral op) a = a) /\ + ==> (!a:A. op (neutral op) a = a) /\ (!a. op a (neutral op) = a) /\ (!a b. op a b = op b a) /\ (!a b c. op (op a b) c = op a (op b c)) /\ @@ -299,58 +299,61 @@ let support = new_definition `support op (f:A->B) s = {x | x IN s /\ ~(f x = neutral op)}`;; let iterate = new_definition - `iterate op (s:A->bool) f = + `iterate op s (f:A->B) = if FINITE(support op f s) then ITSET (\x a. op (f x) a) (support op f s) (neutral op) else neutral op`;; let IN_SUPPORT = prove - (`!op f x s. x IN (support op f s) <=> x IN s /\ ~(f x = neutral op)`, + (`!op (f:A->B) x s. x IN (support op f s) <=> x IN s /\ ~(f x = neutral op)`, REWRITE_TAC[support; IN_ELIM_THM]);; let SUPPORT_SUPPORT = prove - (`!op f s. support op f (support op f s) = support op f s`, + (`!op (f:A->B) s. support op f (support op f s) = support op f s`, REWRITE_TAC[support; IN_ELIM_THM; EXTENSION] THEN REWRITE_TAC[CONJ_ACI]);; let SUPPORT_EMPTY = prove - (`!op f s. (!x. x IN s ==> (f(x) = neutral op)) <=> (support op f s = {})`, + (`!op (f:A->B) s. (!x. x IN s ==> f(x) = neutral op) <=> support op f s = {}`, REWRITE_TAC[IN_SUPPORT; EXTENSION; IN_ELIM_THM; NOT_IN_EMPTY] THEN MESON_TAC[]);; let SUPPORT_SUBSET = prove - (`!op f s. (support op f s) SUBSET s`, + (`!op (f:A->B) s. (support op f s) SUBSET s`, SIMP_TAC[SUBSET; IN_SUPPORT]);; let FINITE_SUPPORT = prove - (`!op f s. FINITE s ==> FINITE(support op f s)`, + (`!op (f:A->B) s. FINITE s ==> FINITE(support op f s)`, MESON_TAC[SUPPORT_SUBSET; FINITE_SUBSET]);; let SUPPORT_CLAUSES = prove - (`(!f. support op f {} = {}) /\ - (!f x s. support op f (x INSERT s) = - if f(x) = neutral op then support op f s - else x INSERT (support op f s)) /\ - (!f x s. support op f (s DELETE x) = (support op f s) DELETE x) /\ - (!f s t. support op f (s UNION t) = - (support op f s) UNION (support op f t)) /\ - (!f s t. support op f (s INTER t) = - (support op f s) INTER (support op f t)) /\ - (!f s t. support op f (s DIFF t) = - (support op f s) DIFF (support op f t)) /\ - (!f g s. support op g (IMAGE f s) = IMAGE f (support op (g o f) s))`, + (`(!(f:A->C). support op f {} = {}) /\ + (!(f:A->C) x s. support op f (x INSERT s) = + if f(x) = neutral op then support op f s + else x INSERT (support op f s)) /\ + (!(f:A->C) x s. support op f (s DELETE x) = (support op f s) DELETE x) /\ + (!(f:A->C) s t. support op f (s UNION t) = + (support op f s) UNION (support op f t)) /\ + (!(f:A->C) s t. support op f (s INTER t) = + (support op f s) INTER (support op f t)) /\ + (!(f:A->C) s t. support op f (s DIFF t) = + (support op f s) DIFF (support op f t)) /\ + (!(f:A->B) (g:B->C) s. + support op g (IMAGE f s) = IMAGE f (support op (g o f) s))`, REWRITE_TAC[support; EXTENSION; IN_ELIM_THM; IN_INSERT; IN_DELETE; o_THM; IN_IMAGE; NOT_IN_EMPTY; IN_UNION; IN_INTER; IN_DIFF; COND_RAND] THEN REPEAT STRIP_TAC THEN TRY COND_CASES_TAC THEN ASM_MESON_TAC[]);; let SUPPORT_DELTA = prove - (`!op s f a. support op (\x. if x = a then f(x) else neutral op) s = - if a IN s then support op f {a} else {}`, + (`!op s (f:A->B) a. + support op (\x. if x = a then f(x) else neutral op) s = + if a IN s then support op f {a} else {}`, REWRITE_TAC[EXTENSION; support; IN_ELIM_THM; IN_SING] THEN REPEAT GEN_TAC THEN REPEAT COND_CASES_TAC THEN ASM_REWRITE_TAC[IN_ELIM_THM; NOT_IN_EMPTY]);; let FINITE_SUPPORT_DELTA = prove - (`!op f a. FINITE(support op (\x. if x = a then f(x) else neutral op) s)`, + (`!op (f:A->B) a. + FINITE(support op (\x. if x = a then f(x) else neutral op) s)`, REWRITE_TAC[SUPPORT_DELTA] THEN REPEAT GEN_TAC THEN COND_CASES_TAC THEN SIMP_TAC[FINITE_RULES; FINITE_SUPPORT]);; @@ -359,13 +362,14 @@ let FINITE_SUPPORT_DELTA = prove (* ------------------------------------------------------------------------- *) let ITERATE_SUPPORT = prove - (`!op f s. iterate op (support op f s) f = iterate op s f`, + (`!op (f:A->B) s. iterate op (support op f s) f = iterate op s f`, SIMP_TAC[iterate; SUPPORT_SUPPORT]);; let ITERATE_EXPAND_CASES = prove - (`!op f s. iterate op s f = - if FINITE(support op f s) then iterate op (support op f s) f - else neutral op`, + (`!op (f:A->B) s. + iterate op s f = + if FINITE(support op f s) then iterate op (support op f s) f + else neutral op`, SIMP_TAC[iterate; SUPPORT_SUPPORT]);; let ITERATE_CLAUSES_GEN = prove @@ -389,18 +393,20 @@ let ITERATE_CLAUSES_GEN = prove let ITERATE_CLAUSES = prove (`!op. monoidal op - ==> (!f. iterate op {} f = neutral op) /\ - (!f x s. FINITE(s) - ==> (iterate op (x INSERT s) f = - if x IN s then iterate op s f - else op (f x) (iterate op s f)))`, + ==> (!(f:A->C). iterate op {} f = neutral op) /\ + (!(f:B->C) x s. + FINITE(s) + ==> (iterate op (x INSERT s) f = + if x IN s then iterate op s f + else op (f x) (iterate op s f)))`, SIMP_TAC[ITERATE_CLAUSES_GEN; FINITE_SUPPORT]);; let ITERATE_UNION = prove (`!op. monoidal op - ==> !f s t. FINITE s /\ FINITE t /\ DISJOINT s t - ==> (iterate op (s UNION t) f = - op (iterate op s f) (iterate op t f))`, + ==> !(f:A->B) s t. + FINITE s /\ FINITE t /\ DISJOINT s t + ==> (iterate op (s UNION t) f = + op (iterate op s f) (iterate op t f))`, let lemma = prove (`(s UNION (x INSERT t) = x INSERT (s UNION t)) /\ (DISJOINT s (x INSERT t) <=> ~(x IN s) /\ DISJOINT s t)`, @@ -423,9 +429,10 @@ let ITERATE_UNION_GEN = prove let ITERATE_DIFF = prove (`!op. monoidal op - ==> !f s t. FINITE s /\ t SUBSET s - ==> (op (iterate op (s DIFF t) f) (iterate op t f) = - iterate op s f)`, + ==> !(f:A->B) s t. + FINITE s /\ t SUBSET s + ==> (op (iterate op (s DIFF t) f) (iterate op t f) = + iterate op s f)`, let lemma = prove (`t SUBSET s ==> (s = (s DIFF t) UNION t) /\ DISJOINT (s DIFF t) t`, SET_TAC[]) in @@ -442,10 +449,11 @@ let ITERATE_DIFF_GEN = prove let ITERATE_INCL_EXCL = prove (`!op. monoidal op - ==> !s t f. FINITE s /\ FINITE t - ==> op (iterate op s f) (iterate op t f) = - op (iterate op (s UNION t) f) - (iterate op (s INTER t) f)`, + ==> !s t (f:A->B). + FINITE s /\ FINITE t + ==> op (iterate op s f) (iterate op t f) = + op (iterate op (s UNION t) f) + (iterate op (s INTER t) f)`, REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[SET_RULE `a UNION b = ((a DIFF b) UNION (b DIFF a)) UNION (a INTER b)`] THEN @@ -537,8 +545,9 @@ let ITERATE_DELETE = prove let ITERATE_DELTA = prove (`!op. monoidal op - ==> !f a s. iterate op s (\x. if x = a then f(x) else neutral op) = - if a IN s then f(a) else neutral op`, + ==> !(f:A->B) a s. + iterate op s (\x. if x = a then f(x) else neutral op) = + if a IN s then f(a) else neutral op`, GEN_TAC THEN DISCH_TAC THEN ONCE_REWRITE_TAC[GSYM ITERATE_SUPPORT] THEN REWRITE_TAC[SUPPORT_DELTA] THEN REPEAT GEN_TAC THEN COND_CASES_TAC THEN ASM_SIMP_TAC[ITERATE_CLAUSES] THEN REWRITE_TAC[SUPPORT_CLAUSES] THEN @@ -693,9 +702,10 @@ let ITERATE_UNION_NONZERO = prove let ITERATE_OP = prove (`!op. monoidal op - ==> !f g s. FINITE s - ==> iterate op s (\x. op (f x) (g x)) = - op (iterate op s f) (iterate op s g)`, + ==> !(f:A->B) g s. + FINITE s + ==> iterate op s (\x. op (f x) (g x)) = + op (iterate op s f) (iterate op s g)`, GEN_TAC THEN DISCH_TAC THEN GEN_TAC THEN GEN_TAC THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN ASM_SIMP_TAC[ITERATE_CLAUSES; MONOIDAL_AC]);; @@ -809,9 +819,9 @@ let ITERATE_OP_GEN = prove let ITERATE_CLAUSES_NUMSEG = prove (`!op. monoidal op ==> (!m. iterate op (m..0) f = if m = 0 then f(0) else neutral op) /\ - (!m n. iterate op (m..SUC n) f = - if m <= SUC n then op (iterate op (m..n) f) (f(SUC n)) - else iterate op (m..n) f)`, + (!m n. iterate op (m..SUC n) f :A = + if m <= SUC n then op (iterate op (m..n) f) (f(SUC n)) + else iterate op (m..n) f)`, REWRITE_TAC[NUMSEG_CLAUSES] THEN REPEAT STRIP_TAC THEN COND_CASES_TAC THEN ASM_SIMP_TAC[ITERATE_CLAUSES; FINITE_NUMSEG; IN_NUMSEG; FINITE_EMPTY] THEN @@ -820,7 +830,7 @@ let ITERATE_CLAUSES_NUMSEG = prove let ITERATE_CLAUSES_NUMSEG_LT = prove (`!op. monoidal op - ==> iterate op {i | i < 0} f = neutral op /\ + ==> iterate op {i | i < 0} f :A = neutral op /\ (!k. iterate op {i | i < SUC k} f = op (iterate op {i | i < k} f) (f k))`, SIMP_TAC[NUMSEG_CLAUSES_LT; ITERATE_CLAUSES; FINITE_NUMSEG_LT] THEN @@ -828,7 +838,7 @@ let ITERATE_CLAUSES_NUMSEG_LT = prove let ITERATE_CLAUSES_NUMSEG_LE = prove (`!op. monoidal op - ==> iterate op {i | i <= 0} f = f 0 /\ + ==> iterate op {i | i <= 0} f :A = f 0 /\ (!k. iterate op {i | i <= SUC k} f = op (iterate op {i | i <= k} f) (f(SUC k)))`, SIMP_TAC[NUMSEG_CLAUSES_LE; ITERATE_CLAUSES; @@ -838,7 +848,7 @@ let ITERATE_CLAUSES_NUMSEG_LE = prove let ITERATE_PAIR = prove (`!op. monoidal op - ==> !f m n. iterate op (2*m..2*n+1) f = + ==> !f m n. iterate op (2*m..2*n+1) f :A = iterate op (m..n) (\i. op (f(2*i)) (f(2*i+1)))`, GEN_TAC THEN DISCH_TAC THEN GEN_TAC THEN GEN_TAC THEN INDUCT_TAC THEN CONV_TAC NUM_REDUCE_CONV THENL @@ -1182,7 +1192,7 @@ let ITERATO_CLAUSES_NUMSEG_LEFT = prove (* ------------------------------------------------------------------------- *) let nproduct = new_definition - `nproduct = iterate(( * ):num->num->num)`;; + `nproduct:(A->bool)->(A->num)->num = iterate(( * ):num->num->num)`;; let NEUTRAL_MUL = prove (`neutral(( * ):num->num->num) = 1`, @@ -1194,16 +1204,17 @@ let MONOIDAL_MUL = prove REWRITE_TAC[monoidal; NEUTRAL_MUL] THEN ARITH_TAC);; let NPRODUCT_CLAUSES = prove - (`(!f. nproduct {} f = 1) /\ - (!x f s. FINITE(s) - ==> (nproduct (x INSERT s) f = - if x IN s then nproduct s f else f(x) * nproduct s f))`, + (`(!f:A->num. nproduct {} f = 1) /\ + (!x (f:B->num) s. + FINITE(s) + ==> (nproduct (x INSERT s) f = + if x IN s then nproduct s f else f(x) * nproduct s f))`, REWRITE_TAC[nproduct; GSYM NEUTRAL_MUL] THEN ONCE_REWRITE_TAC[SWAP_FORALL_THM] THEN MATCH_MP_TAC ITERATE_CLAUSES THEN REWRITE_TAC[MONOIDAL_MUL]);; let iproduct = new_definition - `iproduct = iterate (( * ):int->int->int)`;; + `iproduct:(A->bool)->(A->int)->int = iterate (( * ):int->int->int)`;; let NEUTRAL_INT_MUL = prove (`neutral(( * ):int->int->int) = &1`, @@ -1215,16 +1226,17 @@ let MONOIDAL_INT_MUL = prove REWRITE_TAC[monoidal; NEUTRAL_INT_MUL] THEN INT_ARITH_TAC);; let IPRODUCT_CLAUSES = prove - (`(!f. iproduct {} f = &1) /\ - (!x f s. FINITE(s) - ==> (iproduct (x INSERT s) f = - if x IN s then iproduct s f else f(x) * iproduct s f))`, + (`(!f:A->int. iproduct {} f = &1) /\ + (!x (f:B->int) s. + FINITE(s) + ==> (iproduct (x INSERT s) f = + if x IN s then iproduct s f else f(x) * iproduct s f))`, REWRITE_TAC[iproduct; GSYM NEUTRAL_INT_MUL] THEN ONCE_REWRITE_TAC[SWAP_FORALL_THM] THEN MATCH_MP_TAC ITERATE_CLAUSES THEN REWRITE_TAC[MONOIDAL_INT_MUL]);; let product = new_definition - `product = iterate (( * ):real->real->real)`;; + `product:(A->bool)->(A->real)->real = iterate (( * ):real->real->real)`;; let NEUTRAL_REAL_MUL = prove (`neutral(( * ):real->real->real) = &1`, @@ -1236,16 +1248,17 @@ let MONOIDAL_REAL_MUL = prove REWRITE_TAC[monoidal; NEUTRAL_REAL_MUL] THEN REAL_ARITH_TAC);; let PRODUCT_CLAUSES = prove - (`(!f. product {} f = &1) /\ - (!x f s. FINITE(s) - ==> (product (x INSERT s) f = - if x IN s then product s f else f(x) * product s f))`, + (`(!f:A->real. product {} f = &1) /\ + (!x (f:B->real) s. + FINITE(s) + ==> (product (x INSERT s) f = + if x IN s then product s f else f(x) * product s f))`, REWRITE_TAC[product; GSYM NEUTRAL_REAL_MUL] THEN ONCE_REWRITE_TAC[SWAP_FORALL_THM] THEN MATCH_MP_TAC ITERATE_CLAUSES THEN REWRITE_TAC[MONOIDAL_REAL_MUL]);; let isum = new_definition - `isum = iterate((+):int->int->int)`;; + `isum:(A->bool)->(A->int)->int = iterate((+):int->int->int)`;; let NEUTRAL_INT_ADD = prove (`neutral((+):int->int->int) = &0`, @@ -1257,10 +1270,11 @@ let MONOIDAL_INT_ADD = prove REWRITE_TAC[monoidal; NEUTRAL_INT_ADD] THEN INT_ARITH_TAC);; let ISUM_CLAUSES = prove - (`(!f. isum {} f = &0) /\ - (!x f s. FINITE(s) - ==> (isum (x INSERT s) f = - if x IN s then isum s f else f(x) + isum s f))`, + (`(!f:A->int. isum {} f = &0) /\ + (!x (f:B->int) s. + FINITE(s) + ==> (isum (x INSERT s) f = + if x IN s then isum s f else f(x) + isum s f))`, REWRITE_TAC[isum; GSYM NEUTRAL_INT_ADD] THEN ONCE_REWRITE_TAC[SWAP_FORALL_THM] THEN MATCH_MP_TAC ITERATE_CLAUSES THEN REWRITE_TAC[MONOIDAL_INT_ADD]);; @@ -1272,7 +1286,7 @@ let ISUM_CLAUSES = prove prioritize_num();; let nsum = new_definition - `nsum = iterate (+)`;; + `nsum:(A->bool)->(A->num)->num = iterate (+)`;; let NEUTRAL_ADD = prove (`neutral((+):num->num->num) = 0`, @@ -1284,27 +1298,30 @@ let MONOIDAL_ADD = prove REWRITE_TAC[monoidal; NEUTRAL_ADD] THEN ARITH_TAC);; let NSUM_DEGENERATE = prove - (`!f s. ~(FINITE {x | x IN s /\ ~(f x = 0)}) ==> nsum s f = 0`, + (`!f s:A->bool. ~(FINITE {x | x IN s /\ ~(f x = 0)}) ==> nsum s f = 0`, REPEAT GEN_TAC THEN REWRITE_TAC[nsum] THEN SIMP_TAC[iterate; support; NEUTRAL_ADD]);; let NSUM_CLAUSES = prove - (`(!f. nsum {} f = 0) /\ - (!x f s. FINITE(s) - ==> (nsum (x INSERT s) f = - if x IN s then nsum s f else f(x) + nsum s f))`, + (`(!f:A->num. nsum {} f = 0) /\ + (!x (f:B->num) s. + FINITE(s) + ==> (nsum (x INSERT s) f = + if x IN s then nsum s f else f(x) + nsum s f))`, REWRITE_TAC[nsum; GSYM NEUTRAL_ADD] THEN ONCE_REWRITE_TAC[SWAP_FORALL_THM] THEN MATCH_MP_TAC ITERATE_CLAUSES THEN REWRITE_TAC[MONOIDAL_ADD]);; let NSUM_UNION = prove - (`!f s t. FINITE s /\ FINITE t /\ DISJOINT s t - ==> (nsum (s UNION t) f = nsum s f + nsum t f)`, + (`!f s t:A->bool. + FINITE s /\ FINITE t /\ DISJOINT s t + ==> nsum (s UNION t) f = nsum s f + nsum t f`, SIMP_TAC[nsum; ITERATE_UNION; MONOIDAL_ADD]);; let NSUM_DIFF = prove - (`!f s t. FINITE s /\ t SUBSET s - ==> (nsum (s DIFF t) f = nsum s f - nsum t f)`, + (`!f s t:A->bool. + FINITE s /\ t SUBSET s + ==> nsum (s DIFF t) f = nsum s f - nsum t f`, REPEAT STRIP_TAC THEN MATCH_MP_TAC(ARITH_RULE `(x + z = y:num) ==> (x = y - z)`) THEN ASM_SIMP_TAC[nsum; ITERATE_DIFF; MONOIDAL_ADD]);; @@ -1317,22 +1334,23 @@ let NSUM_INCL_EXCL = prove MATCH_MP_TAC ITERATE_INCL_EXCL THEN REWRITE_TAC[MONOIDAL_ADD]);; let NSUM_SUPPORT = prove - (`!f s. nsum (support (+) f s) f = nsum s f`, + (`!f s:A->bool. nsum (support (+) f s) f = nsum s f`, SIMP_TAC[nsum; iterate; SUPPORT_SUPPORT]);; let NSUM_ADD = prove - (`!f g s. FINITE s ==> (nsum s (\x. f(x) + g(x)) = nsum s f + nsum s g)`, + (`!f g s:A->bool. + FINITE s ==> (nsum s (\x. f(x) + g(x)) = nsum s f + nsum s g)`, SIMP_TAC[nsum; ITERATE_OP; MONOIDAL_ADD]);; let NSUM_ADD_GEN = prove - (`!f g s. - FINITE {x | x IN s /\ ~(f x = 0)} /\ FINITE {x | x IN s /\ ~(g x = 0)} - ==> nsum s (\x. f x + g x) = nsum s f + nsum s g`, + (`!f g s:A->bool. + FINITE {x | x IN s /\ ~(f x = 0)} /\ FINITE {x | x IN s /\ ~(g x = 0)} + ==> nsum s (\x. f x + g x) = nsum s f + nsum s g`, REWRITE_TAC[GSYM NEUTRAL_ADD; GSYM support; nsum] THEN MATCH_MP_TAC ITERATE_OP_GEN THEN ACCEPT_TAC MONOIDAL_ADD);; let NSUM_EQ_0 = prove - (`!f s. (!x:A. x IN s ==> (f(x) = 0)) ==> (nsum s f = 0)`, + (`!f s:A->bool. (!x. x IN s ==> f(x) = 0) ==> nsum s f = 0`, REWRITE_TAC[nsum; GSYM NEUTRAL_ADD] THEN SIMP_TAC[ITERATE_EQ_NEUTRAL; MONOIDAL_ADD]);; @@ -1358,16 +1376,17 @@ let NSUM_RMUL = prove ONCE_REWRITE_TAC[MULT_SYM] THEN REWRITE_TAC[NSUM_LMUL]);; let NSUM_LE = prove - (`!f g s. FINITE(s) /\ (!x. x IN s ==> f(x) <= g(x)) - ==> nsum s f <= nsum s g`, + (`!f g s:A->bool. + FINITE(s) /\ (!x. x IN s ==> f(x) <= g(x)) + ==> nsum s f <= nsum s g`, ONCE_REWRITE_TAC[IMP_CONJ] THEN GEN_TAC THEN GEN_TAC THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[NSUM_CLAUSES; LE_REFL; LE_ADD2; IN_INSERT]);; let NSUM_LT = prove (`!f g s:A->bool. - FINITE(s) /\ (!x. x IN s ==> f(x) <= g(x)) /\ - (?x. x IN s /\ f(x) < g(x)) + FINITE(s) /\ (!x. x IN s ==> f(x) <= g(x)) /\ + (?x. x IN s /\ f(x) < g(x)) ==> nsum s f < nsum s g`, REPEAT GEN_TAC THEN REPEAT(DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC MP_TAC)) THEN @@ -1378,23 +1397,24 @@ let NSUM_LT = prove ASM_SIMP_TAC[LTE_ADD2; NSUM_LE; IN_DELETE; FINITE_DELETE]);; let NSUM_LT_ALL = prove - (`!f g s. FINITE s /\ ~(s = {}) /\ (!x. x IN s ==> f(x) < g(x)) - ==> nsum s f < nsum s g`, + (`!f g s:A->bool. + FINITE s /\ ~(s = {}) /\ (!x. x IN s ==> f(x) < g(x)) + ==> nsum s f < nsum s g`, MESON_TAC[MEMBER_NOT_EMPTY; LT_IMP_LE; NSUM_LT]);; let NSUM_EQ = prove - (`!f g s. (!x. x IN s ==> (f x = g x)) ==> (nsum s f = nsum s g)`, + (`!f g s:A->bool. (!x. x IN s ==> f x = g x) ==> nsum s f = nsum s g`, REWRITE_TAC[nsum] THEN MATCH_MP_TAC ITERATE_EQ THEN REWRITE_TAC[MONOIDAL_ADD]);; let NSUM_CONST = prove - (`!c s. FINITE s ==> (nsum s (\n. c) = (CARD s) * c)`, + (`!c s:A->bool. FINITE s ==> (nsum s (\n. c) = (CARD s) * c)`, GEN_TAC THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[NSUM_CLAUSES; CARD_CLAUSES] THEN REPEAT STRIP_TAC THEN ARITH_TAC);; let NSUM_POS_BOUND = prove - (`!f b s. FINITE s /\ nsum s f <= b ==> !x:A. x IN s ==> f x <= b`, + (`!f b s:A->bool. FINITE s /\ nsum s f <= b ==> !x:A. x IN s ==> f x <= b`, GEN_TAC THEN GEN_TAC THEN REWRITE_TAC[IMP_CONJ] THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[NSUM_CLAUSES; NOT_IN_EMPTY; IN_INSERT] THEN @@ -1402,7 +1422,7 @@ let NSUM_POS_BOUND = prove `0 <= x /\ 0 <= y /\ x + y <= b ==> x <= b /\ y <= b`]);; let NSUM_EQ_0_IFF = prove - (`!s. FINITE s ==> (nsum s f = 0 <=> !x. x IN s ==> f x = 0)`, + (`!s:A->bool. FINITE s ==> (nsum s f = 0 <=> !x. x IN s ==> f x = 0)`, REPEAT STRIP_TAC THEN EQ_TAC THEN ASM_SIMP_TAC[NSUM_EQ_0] THEN ASM_MESON_TAC[ARITH_RULE `n = 0 <=> n <= 0`; NSUM_POS_BOUND]);; @@ -1419,11 +1439,11 @@ let NSUM_POS_LT_ALL = prove ASM_MESON_TAC[MEMBER_NOT_EMPTY; REAL_LT_IMP_LE]);; let NSUM_DELETE = prove - (`!f s a. FINITE s /\ a IN s ==> f(a) + nsum(s DELETE a) f = nsum s f`, + (`!f s a:A. FINITE s /\ a IN s ==> f(a) + nsum(s DELETE a) f = nsum s f`, SIMP_TAC[nsum; ITERATE_DELETE; MONOIDAL_ADD]);; let NSUM_SING = prove - (`!f x. nsum {x} f = f(x)`, + (`!f x:A. nsum {x} f = f(x)`, SIMP_TAC[NSUM_CLAUSES; FINITE_RULES; NOT_IN_EMPTY; ADD_CLAUSES]);; let NSUM_DELTA = prove @@ -1440,8 +1460,9 @@ let NSUM_SWAP = prove SIMP_TAC[NSUM_CLAUSES; NSUM_0; NSUM_ADD; ETA_AX]);; let NSUM_IMAGE = prove - (`!f g s. (!x y. x IN s /\ y IN s /\ (f x = f y) ==> (x = y)) - ==> (nsum (IMAGE f s) g = nsum s (g o f))`, + (`!(f:A->B) g s. + (!x y. x IN s /\ y IN s /\ (f x = f y) ==> (x = y)) + ==> (nsum (IMAGE f s) g = nsum s (g o f))`, REWRITE_TAC[nsum; GSYM NEUTRAL_ADD] THEN MATCH_MP_TAC ITERATE_IMAGE THEN REWRITE_TAC[MONOIDAL_ADD]);; @@ -1456,19 +1477,10 @@ let NSUM_UNIV = prove REWRITE_TAC[nsum] THEN MATCH_MP_TAC ITERATE_UNIV THEN REWRITE_TAC[MONOIDAL_ADD]);; -let ITERATE_UNIV = prove - (`!op. monoidal op - ==> !f s. support op f UNIV SUBSET s - ==> iterate op s f = iterate op UNIV f`, - REWRITE_TAC[support; SUBSET; IN_ELIM_THM] THEN - REPEAT STRIP_TAC THEN CONV_TAC SYM_CONV THEN - FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP ITERATE_SUPERSET) THEN - ASM SET_TAC[]);; - let NSUM_UNION_RZERO = prove (`!f:A->num u v. FINITE u /\ (!x. x IN v /\ ~(x IN u) ==> (f(x) = 0)) - ==> (nsum (u UNION v) f = nsum u f)`, + ==> nsum (u UNION v) f = nsum u f`, let lemma = prove(`u UNION v = u UNION (v DIFF u)`,SET_TAC[]) in REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[lemma] THEN MATCH_MP_TAC NSUM_SUPERSET THEN ASM_MESON_TAC[IN_UNION; IN_DIFF; SUBSET]);; @@ -1476,11 +1488,12 @@ let NSUM_UNION_RZERO = prove let NSUM_UNION_LZERO = prove (`!f:A->num u v. FINITE v /\ (!x. x IN u /\ ~(x IN v) ==> (f(x) = 0)) - ==> (nsum (u UNION v) f = nsum v f)`, + ==> nsum (u UNION v) f = nsum v f`, MESON_TAC[NSUM_UNION_RZERO; UNION_COMM]);; let NSUM_RESTRICT = prove - (`!f s. FINITE s ==> (nsum s (\x. if x IN s then f(x) else 0) = nsum s f)`, + (`!f s:A->bool. + FINITE s ==> nsum s (\x. if x IN s then f(x) else 0) = nsum s f`, REPEAT STRIP_TAC THEN MATCH_MP_TAC NSUM_EQ THEN ASM_SIMP_TAC[]);; let NSUM_BOUND = prove @@ -1505,8 +1518,8 @@ let NSUM_BOUND_LT = prove ASM_SIMP_TAC[NSUM_CONST; LE_REFL]]);; let NSUM_BOUND_LT_ALL = prove - (`!s f b. FINITE s /\ ~(s = {}) /\ (!x. x IN s ==> f(x) < b) - ==> nsum s f < (CARD s) * b`, + (`!s f b. FINITE s /\ ~(s = {}) /\ (!x:A. x IN s ==> f(x) < b) + ==> nsum s f < (CARD s) * b`, MESON_TAC[MEMBER_NOT_EMPTY; LT_IMP_LE; NSUM_BOUND_LT]);; let NSUM_BOUND_LT_GEN = prove @@ -1519,8 +1532,9 @@ let NSUM_BOUND_LT_GEN = prove ASM_REWRITE_TAC[ARITH_RULE `a + 1 <= b <=> a < b`]]);; let NSUM_UNION_EQ = prove - (`!s t u. FINITE u /\ (s INTER t = {}) /\ (s UNION t = u) - ==> (nsum s f + nsum t f = nsum u f)`, + (`!s t u:A->bool. + FINITE u /\ (s INTER t = {}) /\ (s UNION t = u) + ==> nsum s f + nsum t f = nsum u f`, MESON_TAC[NSUM_UNION; DISJOINT; FINITE_SUBSET; SUBSET_UNION]);; let NSUM_EQ_SUPERSET = prove @@ -1537,7 +1551,7 @@ let NSUM_RESTRICT_SET = prove MATCH_MP_TAC ITERATE_RESTRICT_SET THEN REWRITE_TAC[MONOIDAL_ADD]);; let NSUM_NSUM_RESTRICT = prove - (`!R f s t. + (`!(R:A->B->bool) f s t. FINITE s /\ FINITE t ==> (nsum s (\x. nsum {y | y IN t /\ R x y} (\y. f x y)) = nsum t (\y. nsum {x | x IN s /\ R x y} (\x. f x y)))`, @@ -1545,7 +1559,7 @@ let NSUM_NSUM_RESTRICT = prove DISCH_THEN(fun th -> REWRITE_TAC[MATCH_MP NSUM_SWAP th]));; let CARD_EQ_NSUM = prove - (`!s. FINITE s ==> ((CARD s) = nsum s (\x. 1))`, + (`!s:A->bool. FINITE s ==> ((CARD s) = nsum s (\x. 1))`, SIMP_TAC[NSUM_CONST; MULT_CLAUSES]);; let NSUM_MULTICOUNT_GEN = prove @@ -1621,7 +1635,7 @@ let NSUM_SUBSET = prove ASM_SIMP_TAC[NSUM_EQ_0] THEN ARITH_TAC);; let NSUM_SUBSET_SIMPLE = prove - (`!u v f. FINITE v /\ u SUBSET v ==> nsum u f <= nsum v f`, + (`!u v f:A->num. FINITE v /\ u SUBSET v ==> nsum u f <= nsum v f`, REPEAT STRIP_TAC THEN MATCH_MP_TAC NSUM_SUBSET THEN ASM_MESON_TAC[IN_DIFF; SUBSET; FINITE_SUBSET]);; @@ -1661,9 +1675,9 @@ let NSUM_IMAGE_NONZERO = prove let NSUM_BIJECTION = prove (`!f p s:A->bool. - (!x. x IN s ==> p(x) IN s) /\ - (!y. y IN s ==> ?!x. x IN s /\ p(x) = y) - ==> nsum s f = nsum s (f o p)`, + (!x. x IN s ==> p(x) IN s) /\ + (!y. y IN s ==> ?!x. x IN s /\ p(x) = y) + ==> nsum s f = nsum s (f o p)`, REWRITE_TAC[nsum] THEN MATCH_MP_TAC ITERATE_BIJECTION THEN REWRITE_TAC[MONOIDAL_ADD]);; @@ -1692,16 +1706,18 @@ let NSUM_EQ_GENERAL_INVERSES = prove REWRITE_TAC[MONOIDAL_ADD]);; let NSUM_INJECTION = prove - (`!f p s. FINITE s /\ - (!x. x IN s ==> p x IN s) /\ - (!x y. x IN s /\ y IN s /\ p x = p y ==> x = y) - ==> nsum s (f o p) = nsum s f`, + (`!f p s:A->bool. + FINITE s /\ + (!x. x IN s ==> p x IN s) /\ + (!x y. x IN s /\ y IN s /\ p x = p y ==> x = y) + ==> nsum s (f o p) = nsum s f`, REWRITE_TAC[nsum] THEN MATCH_MP_TAC ITERATE_INJECTION THEN REWRITE_TAC[MONOIDAL_ADD]);; let NSUM_UNION_NONZERO = prove - (`!f s t. FINITE s /\ FINITE t /\ (!x. x IN s INTER t ==> f(x) = 0) - ==> nsum (s UNION t) f = nsum s f + nsum t f`, + (`!f s t:A->bool. + FINITE s /\ FINITE t /\ (!x. x IN s INTER t ==> f(x) = 0) + ==> nsum (s UNION t) f = nsum s f + nsum t f`, REWRITE_TAC[nsum; GSYM NEUTRAL_ADD] THEN MATCH_MP_TAC ITERATE_UNION_NONZERO THEN REWRITE_TAC[MONOIDAL_ADD]);; @@ -1889,12 +1905,13 @@ let CONG_NSUM = prove CONV_TAC NUMBER_RULE);; let th = prove - (`(!f g s. (!x. x IN s ==> f(x) = g(x)) - ==> nsum s (\i. f(i)) = nsum s g) /\ + (`(!f g s:A->bool. + (!x. x IN s ==> f(x) = g(x)) + ==> nsum s (\i. f(i)) = nsum s g) /\ (!f g a b. (!i. a <= i /\ i <= b ==> f(i) = g(i)) ==> nsum(a..b) (\i. f(i)) = nsum(a..b) g) /\ - (!f g p. (!x. p x ==> f x = g x) - ==> nsum {y | p y} (\i. f(i)) = nsum {y | p y} g)`, + (!f g p. (!x. p x ==> f x = g x) + ==> nsum {y | p y} (\i. f(i)) = nsum {y | p y} g)`, REPEAT STRIP_TAC THEN MATCH_MP_TAC NSUM_EQ THEN ASM_SIMP_TAC[IN_ELIM_THM; IN_NUMSEG]) in extend_basic_congs (map SPEC_ALL (CONJUNCTS th));; @@ -1958,7 +1975,7 @@ let EXPAND_NSUM_CONV = prioritize_real();; let sum = new_definition - `sum = iterate (+)`;; + `sum:(A->bool)->(A->real)->real = iterate (+)`;; let NEUTRAL_REAL_ADD = prove (`neutral((+):real->real->real) = &0`, @@ -1970,26 +1987,28 @@ let MONOIDAL_REAL_ADD = prove REWRITE_TAC[monoidal; NEUTRAL_REAL_ADD] THEN REAL_ARITH_TAC);; let SUM_DEGENERATE = prove - (`!f s. ~(FINITE {x | x IN s /\ ~(f x = &0)}) ==> sum s f = &0`, + (`!f s:A->bool. ~(FINITE {x | x IN s /\ ~(f x = &0)}) ==> sum s f = &0`, REPEAT GEN_TAC THEN REWRITE_TAC[sum] THEN SIMP_TAC[iterate; support; NEUTRAL_REAL_ADD]);; let SUM_CLAUSES = prove - (`(!f. sum {} f = &0) /\ - (!x f s. FINITE(s) - ==> (sum (x INSERT s) f = - if x IN s then sum s f else f(x) + sum s f))`, + (`(!f:A->real. sum {} f = &0) /\ + (!x (f:B->real) s. + FINITE(s) + ==> (sum (x INSERT s) f = + if x IN s then sum s f else f(x) + sum s f))`, REWRITE_TAC[sum; GSYM NEUTRAL_REAL_ADD] THEN ONCE_REWRITE_TAC[SWAP_FORALL_THM] THEN MATCH_MP_TAC ITERATE_CLAUSES THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; let SUM_UNION = prove - (`!f s t. FINITE s /\ FINITE t /\ DISJOINT s t - ==> (sum (s UNION t) f = sum s f + sum t f)`, + (`!f s t:A->bool. + FINITE s /\ FINITE t /\ DISJOINT s t + ==> sum (s UNION t) f = sum s f + sum t f`, SIMP_TAC[sum; ITERATE_UNION; MONOIDAL_REAL_ADD]);; let SUM_DIFF = prove - (`!f s t. FINITE s /\ t SUBSET s ==> (sum (s DIFF t) f = sum s f - sum t f)`, + (`!f s t:A->bool. FINITE s /\ t SUBSET s ==> (sum (s DIFF t) f = sum s f - sum t f)`, SIMP_TAC[REAL_EQ_SUB_LADD; sum; ITERATE_DIFF; MONOIDAL_REAL_ADD]);; let SUM_INCL_EXCL = prove @@ -2000,15 +2019,15 @@ let SUM_INCL_EXCL = prove MATCH_MP_TAC ITERATE_INCL_EXCL THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; let SUM_SUPPORT = prove - (`!f s. sum (support (+) f s) f = sum s f`, + (`!f s:A->bool. sum (support (+) f s) f = sum s f`, SIMP_TAC[sum; iterate; SUPPORT_SUPPORT]);; let SUM_ADD = prove - (`!f g s. FINITE s ==> (sum s (\x. f(x) + g(x)) = sum s f + sum s g)`, + (`!f g s:A->bool. FINITE s ==> (sum s (\x. f(x) + g(x)) = sum s f + sum s g)`, SIMP_TAC[sum; ITERATE_OP; MONOIDAL_REAL_ADD]);; let SUM_ADD_GEN = prove - (`!f g s. + (`!f g s:A->bool. FINITE {x | x IN s /\ ~(f x = &0)} /\ FINITE {x | x IN s /\ ~(g x = &0)} ==> sum s (\x. f x + g x) = sum s f + sum s g`, REWRITE_TAC[GSYM NEUTRAL_REAL_ADD; GSYM support; sum] THEN @@ -2042,16 +2061,17 @@ let SUM_RMUL = prove ONCE_REWRITE_TAC[REAL_MUL_SYM] THEN REWRITE_TAC[SUM_LMUL]);; let SUM_NEG = prove - (`!f s. sum s (\x. --(f(x))) = --(sum s f)`, + (`!f s:A->bool. sum s (\x. --(f(x))) = --(sum s f)`, ONCE_REWRITE_TAC[REAL_ARITH `--x = --(&1) * x`] THEN SIMP_TAC[SUM_LMUL]);; let SUM_SUB = prove - (`!f g s. FINITE s ==> (sum s (\x. f(x) - g(x)) = sum s f - sum s g)`, + (`!f g s:A->bool. FINITE s ==> sum s (\x. f(x) - g(x)) = sum s f - sum s g`, ONCE_REWRITE_TAC[real_sub] THEN SIMP_TAC[SUM_NEG; SUM_ADD]);; let SUM_LE = prove - (`!f g s. FINITE(s) /\ (!x. x IN s ==> f(x) <= g(x)) ==> sum s f <= sum s g`, + (`!f g s:A->bool. + FINITE(s) /\ (!x. x IN s ==> f(x) <= g(x)) ==> sum s f <= sum s g`, ONCE_REWRITE_TAC[IMP_CONJ] THEN GEN_TAC THEN GEN_TAC THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[SUM_CLAUSES; REAL_LE_REFL; REAL_LE_ADD2; IN_INSERT]);; @@ -2070,8 +2090,9 @@ let SUM_LT = prove ASM_SIMP_TAC[REAL_LTE_ADD2; SUM_LE; IN_DELETE; FINITE_DELETE]);; let SUM_LT_ALL = prove - (`!f g s. FINITE s /\ ~(s = {}) /\ (!x. x IN s ==> f(x) < g(x)) - ==> sum s f < sum s g`, + (`!f g s:A->bool. + FINITE s /\ ~(s = {}) /\ (!x. x IN s ==> f(x) < g(x)) + ==> sum s f < sum s g`, MESON_TAC[MEMBER_NOT_EMPTY; REAL_LT_IMP_LE; SUM_LT]);; let SUM_POS_LT = prove @@ -2093,18 +2114,18 @@ let SUM_POS_LT_ALL = prove ASM_MESON_TAC[MEMBER_NOT_EMPTY; REAL_LT_IMP_LE]);; let SUM_EQ = prove - (`!f g s. (!x. x IN s ==> (f x = g x)) ==> (sum s f = sum s g)`, + (`!f g s:A->bool. (!x. x IN s ==> (f x = g x)) ==> (sum s f = sum s g)`, REWRITE_TAC[sum] THEN MATCH_MP_TAC ITERATE_EQ THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; let SUM_ABS = prove - (`!f s. FINITE(s) ==> abs(sum s f) <= sum s (\x. abs(f x))`, + (`!f s:A->bool. FINITE(s) ==> abs(sum s f) <= sum s (\x. abs(f x))`, GEN_TAC THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[SUM_CLAUSES; REAL_ABS_NUM; REAL_LE_REFL; REAL_ARITH `abs(a) <= b ==> abs(x + a) <= abs(x) + b`]);; let SUM_ABS_LE = prove - (`!f:A->real g s. + (`!f:A->real g s:A->bool. FINITE s /\ (!x. x IN s ==> abs(f x) <= g x) ==> abs(sum s f) <= sum s g`, REPEAT STRIP_TAC THEN MATCH_MP_TAC REAL_LE_TRANS THEN @@ -2113,7 +2134,7 @@ let SUM_ABS_LE = prove ASM_REWRITE_TAC[]);; let SUM_CONST = prove - (`!c s. FINITE s ==> (sum s (\n. c) = &(CARD s) * c)`, + (`!c s:A->bool. FINITE s ==> (sum s (\n. c) = &(CARD s) * c)`, GEN_TAC THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[SUM_CLAUSES; CARD_CLAUSES; GSYM REAL_OF_NUM_SUC] THEN REPEAT STRIP_TAC THEN REAL_ARITH_TAC);; @@ -2130,8 +2151,9 @@ let SUM_POS_LE = prove ASM_SIMP_TAC[SUM_0; IN_ELIM_THM]);; let SUM_POS_BOUND = prove - (`!f b s. FINITE s /\ (!x. x IN s ==> &0 <= f x) /\ sum s f <= b - ==> !x:A. x IN s ==> f x <= b`, + (`!f b s:A->bool. + FINITE s /\ (!x. x IN s ==> &0 <= f x) /\ sum s f <= b + ==> !x:A. x IN s ==> f x <= b`, GEN_TAC THEN GEN_TAC THEN REWRITE_TAC[IMP_CONJ] THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[SUM_CLAUSES; NOT_IN_EMPTY; IN_INSERT] THEN @@ -2139,8 +2161,9 @@ let SUM_POS_BOUND = prove REAL_ARITH `&0 <= x /\ &0 <= y /\ x + y <= b ==> x <= b /\ y <= b`]);; let SUM_POS_EQ_0 = prove - (`!f s. FINITE s /\ (!x. x IN s ==> &0 <= f x) /\ (sum s f = &0) - ==> !x. x IN s ==> f x = &0`, + (`!f s:A->bool. + FINITE s /\ (!x. x IN s ==> &0 <= f x) /\ (sum s f = &0) + ==> !x. x IN s ==> f x = &0`, REWRITE_TAC[GSYM REAL_LE_ANTISYM] THEN MESON_TAC[SUM_POS_BOUND; SUM_POS_LE]);; @@ -2158,19 +2181,19 @@ let SUM_ZERO_EXISTS = prove MATCH_MP_TAC SUM_POS_EQ_0 THEN ASM_REWRITE_TAC[SUM_NEG; REAL_NEG_0]);; let SUM_DELETE = prove - (`!f s a. FINITE s /\ a IN s ==> sum (s DELETE a) f = sum s f - f(a)`, + (`!f s a:A. FINITE s /\ a IN s ==> sum (s DELETE a) f = sum s f - f(a)`, SIMP_TAC[REAL_ARITH `y = z - x <=> x + y = z:real`; sum; ITERATE_DELETE; MONOIDAL_REAL_ADD]);; let SUM_DELETE_CASES = prove - (`!f s a. FINITE s - ==> sum (s DELETE a) f = if a IN s then sum s f - f(a) - else sum s f`, + (`!f s a:A. FINITE s + ==> sum (s DELETE a) f = if a IN s then sum s f - f(a) + else sum s f`, REPEAT STRIP_TAC THEN COND_CASES_TAC THEN ASM_SIMP_TAC[SET_RULE `~(a IN s) ==> (s DELETE a = s)`; SUM_DELETE]);; let SUM_SING = prove - (`!f x. sum {x} f = f(x)`, + (`!f x:A. sum {x} f = f(x)`, SIMP_TAC[SUM_CLAUSES; FINITE_RULES; NOT_IN_EMPTY; REAL_ADD_RID]);; let SUM_DELTA = prove @@ -2187,8 +2210,9 @@ let SUM_SWAP = prove SIMP_TAC[SUM_CLAUSES; SUM_0; SUM_ADD; ETA_AX]);; let SUM_IMAGE = prove - (`!f g s. (!x y. x IN s /\ y IN s /\ (f x = f y) ==> (x = y)) - ==> (sum (IMAGE f s) g = sum s (g o f))`, + (`!(f:A->B) g s. + (!x y. x IN s /\ y IN s /\ f x = f y ==> x = y) + ==> sum (IMAGE f s) g = sum s (g o f)`, REWRITE_TAC[sum; GSYM NEUTRAL_REAL_ADD] THEN MATCH_MP_TAC ITERATE_IMAGE THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; @@ -2206,7 +2230,7 @@ let SUM_UNIV = prove let SUM_UNION_RZERO = prove (`!f:A->real u v. FINITE u /\ (!x. x IN v /\ ~(x IN u) ==> (f(x) = &0)) - ==> (sum (u UNION v) f = sum u f)`, + ==> sum (u UNION v) f = sum u f`, let lemma = prove(`u UNION v = u UNION (v DIFF u)`,SET_TAC[]) in REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[lemma] THEN MATCH_MP_TAC SUM_SUPERSET THEN @@ -2215,11 +2239,12 @@ let SUM_UNION_RZERO = prove let SUM_UNION_LZERO = prove (`!f:A->real u v. FINITE v /\ (!x. x IN u /\ ~(x IN v) ==> (f(x) = &0)) - ==> (sum (u UNION v) f = sum v f)`, + ==> sum (u UNION v) f = sum v f`, MESON_TAC[SUM_UNION_RZERO; UNION_COMM]);; let SUM_RESTRICT = prove - (`!f s. FINITE s ==> (sum s (\x. if x IN s then f(x) else &0) = sum s f)`, + (`!f s:A->bool. + FINITE s ==> sum s (\x. if x IN s then f(x) else &0) = sum s f`, REPEAT STRIP_TAC THEN MATCH_MP_TAC SUM_EQ THEN ASM_SIMP_TAC[]);; let SUM_BOUND = prove @@ -2249,7 +2274,7 @@ let SUM_BOUND_LT = prove ASM_SIMP_TAC[SUM_CONST; REAL_LE_REFL]]);; let SUM_BOUND_LT_ALL = prove - (`!s f b. FINITE s /\ ~(s = {}) /\ (!x. x IN s ==> f(x) < b) + (`!s f b. FINITE s /\ ~(s = {}) /\ (!x:A. x IN s ==> f(x) < b) ==> sum s f < &(CARD s) * b`, MESON_TAC[MEMBER_NOT_EMPTY; REAL_LT_IMP_LE; SUM_BOUND_LT]);; @@ -2260,8 +2285,9 @@ let SUM_BOUND_LT_GEN = prove HAS_SIZE]);; let SUM_UNION_EQ = prove - (`!s t u. FINITE u /\ (s INTER t = {}) /\ (s UNION t = u) - ==> (sum s f + sum t f = sum u f)`, + (`!s t u:A->bool. + FINITE u /\ s INTER t = {} /\ s UNION t = u + ==> sum s f + sum t f = sum u f`, MESON_TAC[SUM_UNION; DISJOINT; FINITE_SUBSET; SUBSET_UNION]);; let SUM_EQ_SUPERSET = prove @@ -2273,12 +2299,12 @@ let SUM_EQ_SUPERSET = prove MESON_TAC[SUM_SUPERSET; SUM_EQ]);; let SUM_RESTRICT_SET = prove - (`!P s f. sum {x | x IN s /\ P x} f = sum s (\x. if P x then f x else &0)`, + (`!P s f. sum {x:A | x IN s /\ P x} f = sum s (\x. if P x then f x else &0)`, REWRITE_TAC[sum; GSYM NEUTRAL_REAL_ADD] THEN MATCH_MP_TAC ITERATE_RESTRICT_SET THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; let SUM_SUM_RESTRICT = prove - (`!R f s t. + (`!(R:A->B->bool) f s t. FINITE s /\ FINITE t ==> (sum s (\x. sum {y | y IN t /\ R x y} (\y. f x y)) = sum t (\y. sum {x | x IN s /\ R x y} (\x. f x y)))`, @@ -2286,7 +2312,7 @@ let SUM_SUM_RESTRICT = prove DISCH_THEN(fun th -> REWRITE_TAC[MATCH_MP SUM_SWAP th]));; let CARD_EQ_SUM = prove - (`!s. FINITE s ==> (&(CARD s) = sum s (\x. &1))`, + (`!s:A->bool. FINITE s ==> (&(CARD s) = sum s (\x. &1))`, SIMP_TAC[SUM_CONST; REAL_MUL_RID]);; let SUM_MULTICOUNT_GEN = prove @@ -2351,7 +2377,7 @@ let SUM_GROUP_RELATION = prove AP_THM_TAC THEN AP_TERM_TAC THEN ASM SET_TAC[]);; let REAL_OF_NUM_SUM = prove - (`!f s. FINITE s ==> (&(nsum s f) = sum s (\x. &(f x)))`, + (`!f s:A->bool. FINITE s ==> (&(nsum s f) = sum s (\x. &(f x)))`, GEN_TAC THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[SUM_CLAUSES; NSUM_CLAUSES; GSYM REAL_OF_NUM_ADD]);; @@ -2374,9 +2400,9 @@ let SUM_SUBSET = prove ASM_SIMP_TAC[FINITE_DIFF; REAL_LE_RNEG; REAL_ADD_LID]);; let SUM_SUBSET_SIMPLE = prove - (`!u v f. FINITE v /\ u SUBSET v /\ (!x:A. x IN (v DIFF u) ==> &0 <= f(x)) - - ==> sum u f <= sum v f`, + (`!u v f. + FINITE v /\ u SUBSET v /\ (!x:A. x IN (v DIFF u) ==> &0 <= f(x)) + ==> sum u f <= sum v f`, REPEAT STRIP_TAC THEN MATCH_MP_TAC SUM_SUBSET THEN ASM_MESON_TAC[IN_DIFF; SUBSET; FINITE_SUBSET]);; @@ -2401,9 +2427,9 @@ let SUM_IMAGE_NONZERO = prove let SUM_BIJECTION = prove (`!f p s:A->bool. - (!x. x IN s ==> p(x) IN s) /\ - (!y. y IN s ==> ?!x. x IN s /\ p(x) = y) - ==> sum s f = sum s (f o p)`, + (!x. x IN s ==> p(x) IN s) /\ + (!y. y IN s ==> ?!x. x IN s /\ p(x) = y) + ==> sum s f = sum s (f o p)`, REWRITE_TAC[sum] THEN MATCH_MP_TAC ITERATE_BIJECTION THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; @@ -2432,7 +2458,8 @@ let SUM_EQ_GENERAL_INVERSES = prove REWRITE_TAC[MONOIDAL_REAL_ADD]);; let SUM_INJECTION = prove - (`!f p s. FINITE s /\ + (`!f p s:A->bool. + FINITE s /\ (!x. x IN s ==> p x IN s) /\ (!x y. x IN s /\ y IN s /\ p x = p y ==> x = y) ==> sum s (f o p) = sum s f`, @@ -2440,8 +2467,9 @@ let SUM_INJECTION = prove REWRITE_TAC[MONOIDAL_REAL_ADD]);; let SUM_UNION_NONZERO = prove - (`!f s t. FINITE s /\ FINITE t /\ (!x. x IN s INTER t ==> f(x) = &0) - ==> sum (s UNION t) f = sum s f + sum t f`, + (`!f s t:A->bool. + FINITE s /\ FINITE t /\ (!x. x IN s INTER t ==> f(x) = &0) + ==> sum (s UNION t) f = sum s f + sum t f`, REWRITE_TAC[sum; GSYM NEUTRAL_REAL_ADD] THEN MATCH_MP_TAC ITERATE_UNION_NONZERO THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; @@ -2468,8 +2496,8 @@ let SUM_CASES = prove MATCH_MP_TAC ITERATE_CASES THEN REWRITE_TAC[MONOIDAL_REAL_ADD]);; let SUM_CASES_1 = prove - (`!s a. FINITE s /\ a IN s - ==> sum s (\x. if x = a then y else f(x)) = sum s f + (y - f a)`, + (`!s a:A. FINITE s /\ a IN s + ==> sum s (\x. if x = a then y else f(x)) = sum s f + (y - f a)`, REPEAT STRIP_TAC THEN ASM_SIMP_TAC[SUM_CASES] THEN ASM_SIMP_TAC[GSYM DELETE; SUM_DELETE] THEN ASM_SIMP_TAC[SET_RULE `a IN s ==> {x | x IN s /\ x = a} = {a}`] THEN @@ -2746,12 +2774,13 @@ let SUM_COMBINE_L = prove (* ------------------------------------------------------------------------- *) let th = prove - (`(!f g s. (!x. x IN s ==> f(x) = g(x)) - ==> sum s (\i. f(i)) = sum s g) /\ + (`(!f g s:A->bool. + (!x. x IN s ==> f(x) = g(x)) + ==> sum s (\i. f(i)) = sum s g) /\ (!f g a b. (!i. a <= i /\ i <= b ==> f(i) = g(i)) ==> sum(a..b) (\i. f(i)) = sum(a..b) g) /\ - (!f g p. (!x. p x ==> f x = g x) - ==> sum {y | p y} (\i. f(i)) = sum {y | p y} g)`, + (!f g p. (!x. p x ==> f x = g x) + ==> sum {y | p y} (\i. f(i)) = sum {y | p y} g)`, REPEAT STRIP_TAC THEN MATCH_MP_TAC SUM_EQ THEN ASM_SIMP_TAC[IN_ELIM_THM; IN_NUMSEG]) in extend_basic_congs (map SPEC_ALL (CONJUNCTS th));; diff --git a/lists.ml b/lists.ml index a09e01ec..1a6180f2 100644 --- a/lists.ml +++ b/lists.ml @@ -52,85 +52,85 @@ let LAST = new_recursive_definition list_RECURSION let BUTLAST = new_recursive_definition list_RECURSION `(BUTLAST [] = []) /\ - (BUTLAST (CONS h t) = if t = [] then [] else CONS h (BUTLAST t))`;; + (BUTLAST (CONS (h:A) t) = if t = [] then [] else CONS h (BUTLAST t))`;; let REPLICATE = new_recursive_definition num_RECURSION - `(REPLICATE 0 x = []) /\ + `(REPLICATE 0 (x:A) = []) /\ (REPLICATE (SUC n) x = CONS x (REPLICATE n x))`;; let NULL = new_recursive_definition list_RECURSION `(NULL [] = T) /\ - (NULL (CONS h t) = F)`;; + (NULL (CONS (h:A) t) = F)`;; let ALL = new_recursive_definition list_RECURSION `(ALL P [] = T) /\ - (ALL P (CONS h t) <=> P h /\ ALL P t)`;; + (ALL P (CONS (h:A) t) <=> P h /\ ALL P t)`;; let EX = new_recursive_definition list_RECURSION `(EX P [] = F) /\ - (EX P (CONS h t) <=> P h \/ EX P t)`;; + (EX P (CONS (h:A) t) <=> P h \/ EX P t)`;; let ITLIST = new_recursive_definition list_RECURSION - `(ITLIST f [] b = b) /\ + `(ITLIST (f:A->B->B) [] b = b) /\ (ITLIST f (CONS h t) b = f h (ITLIST f t b))`;; let MEM = new_recursive_definition list_RECURSION - `(MEM x [] <=> F) /\ + `(MEM (x:A) [] <=> F) /\ (MEM x (CONS h t) <=> (x = h) \/ MEM x t)`;; let ALL2_DEF = new_recursive_definition list_RECURSION - `(ALL2 P [] l2 <=> (l2 = [])) /\ + `(ALL2 (P:A->B->bool) [] l2 <=> (l2 = [])) /\ (ALL2 P (CONS h1 t1) l2 <=> if l2 = [] then F else P h1 (HD l2) /\ ALL2 P t1 (TL l2))`;; let ALL2 = prove - (`(ALL2 P [] [] <=> T) /\ + (`(ALL2 (P:A->B->bool) [] [] <=> T) /\ (ALL2 P (CONS h1 t1) [] <=> F) /\ (ALL2 P [] (CONS h2 t2) <=> F) /\ (ALL2 P (CONS h1 t1) (CONS h2 t2) <=> P h1 h2 /\ ALL2 P t1 t2)`, REWRITE_TAC[distinctness "list"; ALL2_DEF; HD; TL]);; let MAP2_DEF = new_recursive_definition list_RECURSION - `(MAP2 f [] l = []) /\ + `(MAP2 (f:A->B->C) [] l = []) /\ (MAP2 f (CONS h1 t1) l = CONS (f h1 (HD l)) (MAP2 f t1 (TL l)))`;; let MAP2 = prove - (`(MAP2 f [] [] = []) /\ + (`(MAP2 (f:A->B->C) [] [] = []) /\ (MAP2 f (CONS h1 t1) (CONS h2 t2) = CONS (f h1 h2) (MAP2 f t1 t2))`, REWRITE_TAC[MAP2_DEF; HD; TL]);; let EL = new_recursive_definition num_RECURSION - `(EL 0 l = HD l) /\ + `(EL 0 l :A = HD l) /\ (EL (SUC n) l = EL n (TL l))`;; let FILTER = new_recursive_definition list_RECURSION - `(FILTER P [] = []) /\ + `(FILTER (P:A->bool) [] = []) /\ (FILTER P (CONS h t) = if P h then CONS h (FILTER P t) else FILTER P t)`;; let ASSOC = new_recursive_definition list_RECURSION - `ASSOC a (CONS h t) = if FST h = a then SND h else ASSOC a t`;; + `ASSOC a (CONS (h:A#B) t) = if FST h = a then SND h else ASSOC a t`;; let ITLIST2_DEF = new_recursive_definition list_RECURSION - `(ITLIST2 f [] l2 b = b) /\ + `(ITLIST2 (f:A->B->C->C) [] l2 b = b) /\ (ITLIST2 f (CONS h1 t1) l2 b = f h1 (HD l2) (ITLIST2 f t1 (TL l2) b))`;; let ITLIST2 = prove - (`(ITLIST2 f [] [] b = b) /\ + (`(ITLIST2 (f:A->B->C->C) [] [] b = b) /\ (ITLIST2 f (CONS h1 t1) (CONS h2 t2) b = f h1 h2 (ITLIST2 f t1 t2 b))`, REWRITE_TAC[ITLIST2_DEF; HD; TL]);; let ZIP_DEF = new_recursive_definition list_RECURSION - `(ZIP [] l2 = []) /\ - (ZIP (CONS h1 t1) l2 = CONS (h1,HD l2) (ZIP t1 (TL l2)))`;; + `(ZIP [] l2 :(A#B)list = []) /\ + (ZIP (CONS h1 t1) l2:(A#B)list = CONS (h1,HD l2) (ZIP t1 (TL l2)))`;; let ZIP = prove - (`(ZIP [] [] = []) /\ - (ZIP (CONS h1 t1) (CONS h2 t2) = CONS (h1,h2) (ZIP t1 t2))`, + (`(ZIP [] [] :(A#B)list = []) /\ + (ZIP (CONS h1 t1) (CONS h2 t2) :(A#B)list = CONS (h1,h2) (ZIP t1 t2))`, REWRITE_TAC[ZIP_DEF; HD; TL]);; let ALLPAIRS = new_recursive_definition list_RECURSION - `(ALLPAIRS f [] l <=> T) /\ + `(ALLPAIRS (f:A->B->bool) [] l <=> T) /\ (ALLPAIRS f (CONS h t) l <=> ALL (f h) l /\ ALLPAIRS f t l)`;; let PAIRWISE = new_recursive_definition list_RECURSION @@ -212,7 +212,7 @@ let LENGTH_EQ_NIL = prove LIST_INDUCT_TAC THEN REWRITE_TAC[LENGTH; NOT_CONS_NIL; NOT_SUC]);; let LENGTH_EQ_CONS = prove - (`!l n. (LENGTH l = SUC n) <=> ?h t. (l = CONS h t) /\ (LENGTH t = n)`, + (`!(l:A list) n. LENGTH l = SUC n <=> ?h t. (l = CONS h t) /\ (LENGTH t = n)`, LIST_INDUCT_TAC THEN REWRITE_TAC[LENGTH; NOT_SUC; NOT_CONS_NIL] THEN ASM_REWRITE_TAC[SUC_INJ; CONS_11] THEN MESON_TAC[]);; @@ -228,94 +228,96 @@ let MAP_o = prove ASM_REWRITE_TAC[MAP; o_THM]);; let MAP_EQ = prove - (`!f g l. ALL (\x. f x = g x) l ==> (MAP f l = MAP g l)`, + (`!(f:A->B) g l. ALL (\x. f x = g x) l ==> (MAP f l = MAP g l)`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[MAP; ALL] THEN ASM_MESON_TAC[]);; let ALL_IMP = prove - (`!P Q l. (!x. MEM x l /\ P x ==> Q x) /\ ALL P l ==> ALL Q l`, + (`!P Q l:A list. (!x. MEM x l /\ P x ==> Q x) /\ ALL P l ==> ALL Q l`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[MEM; ALL] THEN ASM_MESON_TAC[]);; let NOT_EX = prove - (`!P l. ~(EX P l) <=> ALL (\x. ~(P x)) l`, + (`!P l:A list. ~(EX P l) <=> ALL (\x. ~(P x)) l`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[EX; ALL; DE_MORGAN_THM]);; let NOT_ALL = prove - (`!P l. ~(ALL P l) <=> EX (\x. ~(P x)) l`, + (`!P l:A list. ~(ALL P l) <=> EX (\x. ~(P x)) l`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[EX; ALL; DE_MORGAN_THM]);; let ALL_MAP = prove - (`!P f l. ALL P (MAP f l) <=> ALL (P o f) l`, + (`!P (f:A->B) l. ALL P (MAP f l) <=> ALL (P o f) l`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL; MAP; o_THM]);; let ALL_EQ = prove - (`!l. ALL R l /\ (!x. R x ==> (P x <=> Q x)) - ==> (ALL P l <=> ALL Q l)`, + (`!l:A list. + ALL R l /\ (!x. R x ==> (P x <=> Q x)) ==> (ALL P l <=> ALL Q l)`, LIST_INDUCT_TAC THEN REWRITE_TAC[ALL] THEN STRIP_TAC THEN BINOP_TAC THEN FIRST_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]);; let ALL_T = prove - (`!l. ALL (\x. T) l`, + (`!l:A list. ALL (\x. T) l`, LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL]);; let MAP_EQ_ALL2 = prove - (`!l m. ALL2 (\x y. f x = f y) l m ==> (MAP f l = MAP f m)`, + (`!(f:A->B) l m. ALL2 (\x y. f x = f y) l m ==> MAP f l = MAP f m`, + GEN_TAC THEN REPEAT LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MAP; ALL2; CONS_11] THEN ASM_MESON_TAC[]);; let ALL2_MAP = prove - (`!P f l. ALL2 P (MAP f l) l <=> ALL (\a. P (f a) a) l`, + (`!P (f:A->B) l. ALL2 P (MAP f l) l <=> ALL (\a. P (f a) a) l`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL2; MAP; ALL]);; let MAP_EQ_DEGEN = prove - (`!l f. ALL (\x. f(x) = x) l ==> (MAP f l = l)`, + (`!l (f:A->A). ALL (\x. f(x) = x) l ==> (MAP f l = l)`, LIST_INDUCT_TAC THEN REWRITE_TAC[ALL; MAP; CONS_11] THEN REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THEN FIRST_ASSUM MATCH_MP_TAC THEN ASM_REWRITE_TAC[]);; let ALL2_AND_RIGHT = prove - (`!l m P Q. ALL2 (\x y. P x /\ Q x y) l m <=> ALL P l /\ ALL2 Q l m`, + (`!l m P Q. ALL2 (\(x:A) (y:B). P x /\ Q x y) l m <=> ALL P l /\ ALL2 Q l m`, LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL; ALL2] THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL; ALL2] THEN REWRITE_TAC[CONJ_ACI]);; let ITLIST_APPEND = prove - (`!f a l1 l2. ITLIST f (APPEND l1 l2) a = ITLIST f l1 (ITLIST f l2 a)`, + (`!(f:A->B->B) a l1 l2. + ITLIST f (APPEND l1 l2) a = ITLIST f l1 (ITLIST f l2 a)`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ITLIST; APPEND]);; let ITLIST_EXTRA = prove - (`!l. ITLIST f (APPEND l [a]) b = ITLIST f l (f a b)`, + (`!(f:A->B->B) l. ITLIST f (APPEND l [a]) b = ITLIST f l (f a b)`, REWRITE_TAC[ITLIST_APPEND; ITLIST]);; let ALL_MP = prove - (`!P Q l. ALL (\x. P x ==> Q x) l /\ ALL P l ==> ALL Q l`, + (`!P Q (l:A list). ALL (\x. P x ==> Q x) l /\ ALL P l ==> ALL Q l`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[ALL] THEN ASM_MESON_TAC[]);; let AND_ALL = prove - (`!l. ALL P l /\ ALL Q l <=> ALL (\x. P x /\ Q x) l`, + (`!l:A list. ALL P l /\ ALL Q l <=> ALL (\x. P x /\ Q x) l`, CONV_TAC(ONCE_DEPTH_CONV SYM_CONV) THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL; CONJ_ACI]);; let EX_IMP = prove - (`!P Q l. (!x. MEM x l /\ P x ==> Q x) /\ EX P l ==> EX Q l`, + (`!P Q (l:A list). (!x. MEM x l /\ P x ==> Q x) /\ EX P l ==> EX Q l`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[MEM; EX] THEN ASM_MESON_TAC[]);; let ALL_MEM = prove - (`!P l. (!x. MEM x l ==> P x) <=> ALL P l`, + (`!P (l:A list). (!x. MEM x l ==> P x) <=> ALL P l`, GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[ALL; MEM] THEN ASM_MESON_TAC[]);; let LENGTH_REPLICATE = prove - (`!n x. LENGTH(REPLICATE n x) = n`, + (`!n x:A. LENGTH(REPLICATE n x) = n`, INDUCT_TAC THEN ASM_REWRITE_TAC[LENGTH; REPLICATE]);; let MEM_REPLICATE = prove @@ -324,118 +326,127 @@ let MEM_REPLICATE = prove MESON_TAC[]);; let EX_MAP = prove - (`!P f l. EX P (MAP f l) <=> EX (P o f) l`, + (`!P (f:A->B) l. EX P (MAP f l) <=> EX (P o f) l`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MAP; EX; o_THM]);; let EXISTS_EX = prove - (`!P l. (?x. EX (P x) l) <=> EX (\s. ?x. P x s) l`, + (`!(P:A->B->bool) l. (?x. EX (P x) l) <=> EX (\s. ?x. P x s) l`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[EX] THEN ASM_MESON_TAC[]);; let FORALL_ALL = prove - (`!P l. (!x. ALL (P x) l) <=> ALL (\s. !x. P x s) l`, + (`!(P:A->B->bool) l. (!x. ALL (P x) l) <=> ALL (\s. !x. P x s) l`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL] THEN ASM_MESON_TAC[]);; let MEM_APPEND = prove - (`!x l1 l2. MEM x (APPEND l1 l2) <=> MEM x l1 \/ MEM x l2`, + (`!(x:A) l1 l2. MEM x (APPEND l1 l2) <=> MEM x l1 \/ MEM x l2`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MEM; APPEND; DISJ_ACI]);; let MEM_MAP = prove - (`!f y l. MEM y (MAP f l) <=> ?x. MEM x l /\ (y = f x)`, + (`!(f:A->B) y l. MEM y (MAP f l) <=> ?x. MEM x l /\ (y = f x)`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MEM; MAP] THEN MESON_TAC[]);; let FILTER_APPEND = prove - (`!P l1 l2. FILTER P (APPEND l1 l2) = APPEND (FILTER P l1) (FILTER P l2)`, + (`!(P:A->bool) l1 l2. + FILTER P (APPEND l1 l2) = APPEND (FILTER P l1) (FILTER P l2)`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[FILTER; APPEND] THEN GEN_TAC THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[APPEND]);; let FILTER_MAP = prove - (`!P f l. FILTER P (MAP f l) = MAP f (FILTER (P o f) l)`, + (`!P (f:A->B) l. FILTER P (MAP f l) = MAP f (FILTER (P o f) l)`, GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MAP; FILTER; o_THM] THEN COND_CASES_TAC THEN REWRITE_TAC[MAP]);; let MEM_FILTER = prove - (`!P l x. MEM x (FILTER P l) <=> P x /\ MEM x l`, + (`!P l (x:A). MEM x (FILTER P l) <=> P x /\ MEM x l`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MEM; FILTER] THEN GEN_TAC THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[MEM] THEN ASM_MESON_TAC[]);; let EX_MEM = prove - (`!P l. (?x. P x /\ MEM x l) <=> EX P l`, + (`!P (l:A list). (?x. P x /\ MEM x l) <=> EX P l`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[EX; MEM] THEN ASM_MESON_TAC[]);; let MAP_FST_ZIP = prove - (`!l1 l2. (LENGTH l1 = LENGTH l2) ==> (MAP FST (ZIP l1 l2) = l1)`, + (`!(l1:A list) (l2:B list). + LENGTH l1 = LENGTH l2 ==> MAP FST (ZIP l1 l2) = l1`, LIST_INDUCT_TAC THEN LIST_INDUCT_TAC THEN ASM_SIMP_TAC[LENGTH; SUC_INJ; MAP; FST; ZIP; NOT_SUC]);; let MAP_SND_ZIP = prove - (`!l1 l2. (LENGTH l1 = LENGTH l2) ==> (MAP SND (ZIP l1 l2) = l2)`, + (`!(l1:A list) (l2:B list). + LENGTH l1 = LENGTH l2 ==> MAP SND (ZIP l1 l2) = l2`, LIST_INDUCT_TAC THEN LIST_INDUCT_TAC THEN ASM_SIMP_TAC[LENGTH; SUC_INJ; MAP; FST; ZIP; NOT_SUC]);; let LENGTH_ZIP = prove - (`!l1 l2. LENGTH l1 = LENGTH l2 ==> LENGTH(ZIP l1 l2) = LENGTH l2`, + (`!(l1:A list) (l2:B list). + LENGTH l1 = LENGTH l2 ==> LENGTH(ZIP l1 l2) = LENGTH l2`, REPEAT(LIST_INDUCT_TAC ORELSE GEN_TAC) THEN ASM_SIMP_TAC[LENGTH; NOT_SUC; ZIP; SUC_INJ]);; let MEM_ASSOC = prove - (`!l x. MEM (x,ASSOC x l) l <=> MEM x (MAP FST l)`, + (`!(l:(A#B)list) x. MEM (x,ASSOC x l) l <=> MEM x (MAP FST l)`, LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MEM; MAP; ASSOC] THEN GEN_TAC THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[] THEN ASM_MESON_TAC[PAIR; FST]);; let ALL_APPEND = prove - (`!P l1 l2. ALL P (APPEND l1 l2) <=> ALL P l1 /\ ALL P l2`, + (`!P l1 l2:A list. ALL P (APPEND l1 l2) <=> ALL P l1 /\ ALL P l2`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL; APPEND; GSYM CONJ_ASSOC]);; let MEM_EL = prove - (`!l n. n < LENGTH l ==> MEM (EL n l) l`, + (`!(l:A list) n. n < LENGTH l ==> MEM (EL n l) l`, LIST_INDUCT_TAC THEN REWRITE_TAC[MEM; CONJUNCT1 LT; LENGTH] THEN INDUCT_TAC THEN ASM_SIMP_TAC[EL; HD; LT_SUC; TL]);; let MEM_EXISTS_EL = prove - (`!l x. MEM x l <=> ?i. i < LENGTH l /\ x = EL i l`, + (`!(l:A list) x. MEM x l <=> ?i. i < LENGTH l /\ x = EL i l`, LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[LENGTH; EL; MEM; CONJUNCT1 LT] THEN GEN_TAC THEN GEN_REWRITE_TAC RAND_CONV [MESON[num_CASES] `(?i. P i) <=> P 0 \/ (?i. P(SUC i))`] THEN REWRITE_TAC[LT_SUC; LT_0; EL; HD; TL]);; let ALL_EL = prove - (`!P l. (!i. i < LENGTH l ==> P (EL i l)) <=> ALL P l`, + (`!P (l:A list). (!i. i < LENGTH l ==> P (EL i l)) <=> ALL P l`, REWRITE_TAC[GSYM ALL_MEM; MEM_EXISTS_EL] THEN MESON_TAC[]);; let ALL2_MAP2 = prove - (`!l m. ALL2 P (MAP f l) (MAP g m) = ALL2 (\x y. P (f x) (g y)) l m`, + (`!(f:A->B) (g:C->D) l m. + ALL2 P (MAP f l) (MAP g m) = ALL2 (\x y. P (f x) (g y)) l m`, + GEN_TAC THEN GEN_TAC THEN LIST_INDUCT_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL2; MAP]);; let AND_ALL2 = prove - (`!P Q l m. ALL2 P l m /\ ALL2 Q l m <=> ALL2 (\x y. P x y /\ Q x y) l m`, + (`!(P:A->B->bool) Q l m. + ALL2 P l m /\ ALL2 Q l m <=> ALL2 (\x y. P x y /\ Q x y) l m`, GEN_TAC THEN GEN_TAC THEN CONV_TAC(ONCE_DEPTH_CONV SYM_CONV) THEN LIST_INDUCT_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL2] THEN REWRITE_TAC[CONJ_ACI]);; let ALLPAIRS_SYM = prove - (`!P l m. ALLPAIRS P l m <=> ALLPAIRS (\x y. P y x) m l`, + (`!(P:A->B->bool) l m. ALLPAIRS P l m <=> ALLPAIRS (\x y. P y x) m l`, GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[ALLPAIRS] THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALLPAIRS; ALL] THEN ASM_MESON_TAC[]);; let ALLPAIRS_MEM = prove - (`!P l m. (!x y. MEM x l /\ MEM y m ==> P x y) <=> ALLPAIRS P l m`, + (`!(P:A->B->bool) l m. + (!x y. MEM x l /\ MEM y m ==> P x y) <=> ALLPAIRS P l m`, GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[ALLPAIRS; GSYM ALL_MEM; MEM] THEN ASM_MESON_TAC[]);; let ALLPAIRS_MAP = prove - (`!P l m. ALLPAIRS P (MAP f l) (MAP g m) <=> - ALLPAIRS (\x y. P (f x) (g y)) l m`, + (`!P (f:A->B) (g:C->D) l m. + ALLPAIRS P (MAP f l) (MAP g m) <=> + ALLPAIRS (\x y. P (f x) (g y)) l m`, REWRITE_TAC[GSYM ALLPAIRS_MEM; MEM_MAP] THEN MESON_TAC[]);; let ALLPAIRS_EQ = prove @@ -445,12 +456,12 @@ let ALLPAIRS_EQ = prove REWRITE_TAC[GSYM ALLPAIRS_MEM; GSYM ALL_MEM] THEN MESON_TAC[]);; let ALL2_ALL = prove - (`!P l. ALL2 P l l <=> ALL (\x. P x x) l`, + (`!P (l:A list). ALL2 P l l <=> ALL (\x. P x x) l`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[ALL2; ALL]);; let APPEND_EQ_NIL = prove - (`!l m. (APPEND l m = []) <=> (l = []) /\ (m = [])`, + (`!l m:A list. (APPEND l m = []) <=> (l = []) /\ (m = [])`, REWRITE_TAC[GSYM LENGTH_EQ_NIL; LENGTH_APPEND; ADD_EQ_0]);; let APPEND_LCANCEL = prove @@ -464,19 +475,20 @@ let APPEND_RCANCEL = prove REWRITE_TAC[REVERSE_APPEND; APPEND_LCANCEL]);; let LENGTH_MAP2 = prove - (`!f l m. LENGTH l = LENGTH m ==> LENGTH(MAP2 f l m) = LENGTH m`, + (`!(f:A->B->C) l m. LENGTH l = LENGTH m ==> LENGTH(MAP2 f l m) = LENGTH m`, GEN_TAC THEN LIST_INDUCT_TAC THEN LIST_INDUCT_TAC THEN ASM_SIMP_TAC[LENGTH; NOT_CONS_NIL; NOT_SUC; MAP2; SUC_INJ]);; let EL_MAP2 = prove - (`!f l m k. k < LENGTH l /\ k < LENGTH m - ==> EL k (MAP2 f l m) = f (EL k l) (EL k m)`, + (`!(f:A->B->C) l m k. + k < LENGTH l /\ k < LENGTH m + ==> EL k (MAP2 f l m) = f (EL k l) (EL k m)`, GEN_TAC THEN LIST_INDUCT_TAC THEN LIST_INDUCT_TAC THEN ASM_SIMP_TAC[LENGTH; CONJUNCT1 LT] THEN INDUCT_TAC THEN ASM_SIMP_TAC[LENGTH; MAP2; EL; HD; TL; LT_SUC]);; let MAP_EQ_NIL = prove - (`!f l. MAP f l = [] <=> l = []`, + (`!(f:A->B) l. MAP f l = [] <=> l = []`, GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[MAP; NOT_CONS_NIL]);; let INJECTIVE_MAP = prove @@ -499,11 +511,11 @@ let SURJECTIVE_MAP = prove ASM_MESON_TAC[MAP]);; let MAP_ID = prove - (`!l. MAP (\x. x) l = l`, + (`!l. MAP (\x:A. x) l = l`, LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MAP]);; let MAP_I = prove - (`MAP I = I`, + (`MAP (I:A->A) = I`, REWRITE_TAC[FUN_EQ_THM; I_DEF; MAP_ID]);; let BUTLAST_CLAUSES = prove @@ -520,17 +532,17 @@ let BUTLAST_APPEND = prove LIST_INDUCT_TAC THEN ASM_SIMP_TAC[APPEND; BUTLAST; APPEND_EQ_NIL]);; let APPEND_BUTLAST_LAST = prove - (`!l. ~(l = []) ==> APPEND (BUTLAST l) [LAST l] = l`, + (`!l:A list. ~(l = []) ==> APPEND (BUTLAST l) [LAST l] = l`, LIST_INDUCT_TAC THEN REWRITE_TAC[LAST; BUTLAST; NOT_CONS_NIL] THEN COND_CASES_TAC THEN ASM_SIMP_TAC[APPEND]);; let LAST_APPEND = prove - (`!p q. LAST(APPEND p q) = if q = [] then LAST p else LAST q`, + (`!p q:A list. LAST(APPEND p q) = if q = [] then LAST p else LAST q`, LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[APPEND; LAST; APPEND_EQ_NIL] THEN MESON_TAC[]);; let LENGTH_TL = prove - (`!l. ~(l = []) ==> LENGTH(TL l) = LENGTH l - 1`, + (`!l:A list. ~(l = []) ==> LENGTH(TL l) = LENGTH l - 1`, LIST_INDUCT_TAC THEN REWRITE_TAC[LENGTH; TL; ARITH; SUC_SUB1]);; let LAST_REVERSE = prove @@ -543,23 +555,24 @@ let HD_REVERSE = prove MESON_TAC[LAST_REVERSE; REVERSE_REVERSE; REVERSE_EQ_EMPTY]);; let EL_APPEND = prove - (`!k l m. EL k (APPEND l m) = if k < LENGTH l then EL k l - else EL (k - LENGTH l) m`, + (`!k l m:A list. + EL k (APPEND l m) = if k < LENGTH l then EL k l + else EL (k - LENGTH l) m`, INDUCT_TAC THEN REWRITE_TAC[EL] THEN LIST_INDUCT_TAC THEN REWRITE_TAC[HD; APPEND; LENGTH; SUB_0; EL; LT_0; CONJUNCT1 LT] THEN ASM_REWRITE_TAC[TL; LT_SUC; SUB_SUC]);; let EL_TL = prove - (`!n. EL n (TL l) = EL (n + 1) l`, + (`!n. EL n (TL l):A = EL (n + 1) l`, REWRITE_TAC[GSYM ADD1; EL]);; let EL_CONS = prove - (`!n h t. EL n (CONS h t) = if n = 0 then h else EL (n - 1) t`, + (`!n (h:A) t. EL n (CONS h t) = if n = 0 then h else EL (n - 1) t`, INDUCT_TAC THEN REWRITE_TAC[EL; HD; TL; NOT_SUC; SUC_SUB1]);; let LAST_EL = prove - (`!l. ~(l = []) ==> LAST l = EL (LENGTH l - 1) l`, + (`!l:A list. ~(l = []) ==> LAST l = EL (LENGTH l - 1) l`, LIST_INDUCT_TAC THEN REWRITE_TAC[LAST; LENGTH; SUC_SUB1] THEN DISCH_TAC THEN COND_CASES_TAC THEN ASM_SIMP_TAC[LENGTH; EL; HD; EL_CONS; LENGTH_EQ_NIL]);; @@ -569,16 +582,16 @@ let HD_APPEND = prove LIST_INDUCT_TAC THEN REWRITE_TAC[HD; APPEND; NOT_CONS_NIL]);; let CONS_HD_TL = prove - (`!l. ~(l = []) ==> l = CONS (HD l) (TL l)`, + (`!l:A list. ~(l = []) ==> l = CONS (HD l) (TL l)`, LIST_INDUCT_TAC THEN REWRITE_TAC[NOT_CONS_NIL;HD;TL]);; let EL_MAP = prove - (`!f n l. n < LENGTH l ==> EL n (MAP f l) = f(EL n l)`, + (`!(f:A->B) n l. n < LENGTH l ==> EL n (MAP f l) = f(EL n l)`, GEN_TAC THEN INDUCT_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[LENGTH; CONJUNCT1 LT; LT_0; EL; HD; TL; MAP; LT_SUC]);; let MAP_REVERSE = prove - (`!f l. REVERSE(MAP f l) = MAP f (REVERSE l)`, + (`!(f:A->B) l. REVERSE(MAP f l) = MAP f (REVERSE l)`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[MAP; REVERSE; MAP_APPEND]);; @@ -589,7 +602,7 @@ let ALL_FILTER = prove COND_CASES_TAC THEN ASM_REWRITE_TAC[ALL]);; let APPEND_SING = prove - (`!h t. APPEND [h] t = CONS h t`, + (`!(h:A) t. APPEND [h] t = CONS h t`, REWRITE_TAC[APPEND]);; let MEM_APPEND_DECOMPOSE_LEFT = prove diff --git a/pair.ml b/pair.ml old mode 100644 new mode 100755 index ce8cb019..b3504f09 --- a/pair.ml +++ b/pair.ml @@ -27,7 +27,7 @@ let GEQ_DEF = new_definition `GEQ a b = (a:A = b)`;; let _SEQPATTERN = new_definition - `_SEQPATTERN = \r s x. if ?y. r x y then r x else s x`;; + `_SEQPATTERN = \(r:A->B->bool) s x. if ?y. r x y then r x else s x`;; let _UNGUARDED_PATTERN = new_definition `_UNGUARDED_PATTERN = \p r. p /\ r`;; @@ -36,10 +36,10 @@ let _GUARDED_PATTERN = new_definition `_GUARDED_PATTERN = \p g r. p /\ g /\ r`;; let _MATCH = new_definition - `_MATCH = \e r. if (?!) (r e) then (@) (r e) else @z. F`;; + `_MATCH = \e (r:A->B->bool). if (?!) (r e) then (@) (r e) else @z. F`;; let _FUNCTION = new_definition - `_FUNCTION = \r x. if (?!) (r x) then (@) (r x) else @z. F`;; + `_FUNCTION = \(r:A->B->bool) x. if (?!) (r x) then (@) (r x) else @z. F`;; (* ------------------------------------------------------------------------- *) (* Pair type. *) @@ -113,7 +113,7 @@ let PAIR = prove REWRITE_TAC[FST; SND]);; let pair_INDUCT = prove - (`!P. (!x y. P (x,y)) ==> !p. P p`, + (`!P:A#B->bool. (!x y. P (x,y)) ==> !p. P p`, REPEAT STRIP_TAC THEN GEN_REWRITE_TAC RAND_CONV [GSYM PAIR] THEN FIRST_ASSUM MATCH_ACCEPT_TAC);; @@ -293,15 +293,15 @@ inductive_type_store := (* ------------------------------------------------------------------------- *) let FORALL_PAIR_THM = prove - (`!P. (!p. P p) <=> (!p1 p2. P(p1,p2))`, + (`!P:A#B->bool. (!p. P p) <=> (!p1 p2. P(p1,p2))`, MESON_TAC[PAIR]);; let EXISTS_PAIR_THM = prove - (`!P. (?p. P p) <=> ?p1 p2. P(p1,p2)`, + (`!P:A#B->bool. (?p. P p) <=> ?p1 p2. P(p1,p2)`, MESON_TAC[PAIR]);; let LAMBDA_PAIR_THM = prove - (`!t. (\p. t p) = (\(x,y). t(x,y))`, + (`!t:A#B->C. (\p. t p) = (\(x,y). t(x,y))`, REWRITE_TAC[FORALL_PAIR_THM; FUN_EQ_THM]);; let LAMBDA_PAIR = prove @@ -318,9 +318,9 @@ let LAMBDA_TRIPLE = prove REWRITE_TAC[LAMBDA_TRIPLE_THM]);; let PAIRED_ETA_THM = prove - (`(!f. (\(x,y). f (x,y)) = f) /\ - (!f. (\(x,y,z). f (x,y,z)) = f) /\ - (!f. (\(w,x,y,z). f (w,x,y,z)) = f)`, + (`(!f:A#B->C. (\(x,y). f (x,y)) = f) /\ + (!f:A#B#C->D. (\(x,y,z). f (x,y,z)) = f) /\ + (!f:A#B#C#D->E. (\(w,x,y,z). f (w,x,y,z)) = f)`, REPEAT STRIP_TAC THEN REWRITE_TAC[FUN_EQ_THM; FORALL_PAIR_THM]);; let FORALL_UNCURRY = prove @@ -335,19 +335,19 @@ let EXISTS_UNCURRY = prove REWRITE_TAC[FORALL_UNCURRY]);; let EXISTS_CURRY = prove - (`!P. (?f. P f) <=> (?f. P (\(a,b). f a b))`, + (`!P:(A#B->C)->bool. (?f. P f) <=> (?f. P (\(a,b). f a b))`, REWRITE_TAC[EXISTS_UNCURRY; PAIRED_ETA_THM]);; let FORALL_CURRY = prove - (`!P. (!f. P f) <=> (!f. P (\(a,b). f a b))`, + (`!P:(A#B->C)->bool. (!f. P f) <=> (!f. P (\(a,b). f a b))`, REWRITE_TAC[FORALL_UNCURRY; PAIRED_ETA_THM]);; let FORALL_UNPAIR_THM = prove - (`!P. (!x y. P x y) <=> !z. P (FST z) (SND z)`, + (`!P:A->B->bool. (!x y. P x y) <=> !z. P (FST z) (SND z)`, REWRITE_TAC[FORALL_PAIR_THM; FST; SND] THEN MESON_TAC[]);; let EXISTS_UNPAIR_THM = prove - (`!P. (?x y. P x y) <=> ?z. P (FST z) (SND z)`, + (`!P:A->B->bool. (?x y. P x y) <=> ?z. P (FST z) (SND z)`, REWRITE_TAC[EXISTS_PAIR_THM; FST; SND] THEN MESON_TAC[]);; let FORALL_PAIR_FUN_THM = prove @@ -362,11 +362,11 @@ let EXISTS_PAIR_FUN_THM = prove REWRITE_TAC[FORALL_PAIR_FUN_THM]);; let FORALL_UNPAIR_FUN_THM = prove - (`!P. (!f g. P f g) <=> (!h. P (FST o h) (SND o h))`, + (`!P:(A->B)->(A->C)->bool. (!f g. P f g) <=> (!h. P (FST o h) (SND o h))`, REWRITE_TAC[FORALL_PAIR_FUN_THM; o_DEF; ETA_AX]);; let EXISTS_UNPAIR_FUN_THM = prove - (`!P. (?f g. P f g) <=> (?h. P (FST o h) (SND o h))`, + (`!P:(A->B)->(A->C)->bool. (?f g. P f g) <=> (?h. P (FST o h) (SND o h))`, REWRITE_TAC[EXISTS_PAIR_FUN_THM; o_DEF; ETA_AX]);; let EXISTS_SWAP_FUN_THM = prove @@ -383,12 +383,12 @@ let EXISTS_SWAP_FUN_THM = prove (* ------------------------------------------------------------------------- *) let FORALL_PAIRED_THM = prove - (`!P. (!(x,y). P x y) <=> (!x y. P x y)`, + (`!P:A->B->bool. (!(x,y). P x y) <=> (!x y. P x y)`, GEN_TAC THEN GEN_REWRITE_TAC (LAND_CONV o RATOR_CONV) [FORALL_DEF] THEN REWRITE_TAC[FUN_EQ_THM; FORALL_PAIR_THM]);; let EXISTS_PAIRED_THM = prove - (`!P. (?(x,y). P x y) <=> (?x y. P x y)`, + (`!P:A->B->bool. (?(x,y). P x y) <=> (?x y. P x y)`, GEN_TAC THEN MATCH_MP_TAC(TAUT `(~p <=> ~q) ==> (p <=> q)`) THEN REWRITE_TAC[REWRITE_RULE[ETA_AX] NOT_EXISTS_THM; FORALL_PAIR_THM]);; @@ -397,12 +397,12 @@ let EXISTS_PAIRED_THM = prove (* ------------------------------------------------------------------------- *) let FORALL_TRIPLED_THM = prove - (`!P. (!(x,y,z). P x y z) <=> (!x y z. P x y z)`, + (`!P:A->B->C->bool. (!(x,y,z). P x y z) <=> (!x y z. P x y z)`, GEN_TAC THEN GEN_REWRITE_TAC (LAND_CONV o RATOR_CONV) [FORALL_DEF] THEN REWRITE_TAC[FUN_EQ_THM; FORALL_PAIR_THM]);; let EXISTS_TRIPLED_THM = prove - (`!P. (?(x,y,z). P x y z) <=> (?x y z. P x y z)`, + (`!P:A->B->C->bool. (?(x,y,z). P x y z) <=> (?x y z. P x y z)`, GEN_TAC THEN MATCH_MP_TAC(TAUT `(~p <=> ~q) ==> (p <=> q)`) THEN REWRITE_TAC[REWRITE_RULE[ETA_AX] NOT_EXISTS_THM; FORALL_PAIR_THM]);; diff --git a/sets.ml b/sets.ml index 731883f7..e6b8b8b7 100644 --- a/sets.ml +++ b/sets.ml @@ -54,18 +54,18 @@ let GSPEC = new_definition `GSPEC (p:A->bool) = p`;; let SETSPEC = new_definition - `SETSPEC v P t <=> P /\ (v = t)`;; + `SETSPEC (v:A) P t <=> P /\ (v = t)`;; (* ------------------------------------------------------------------------- *) (* Rewrite rule for eliminating set-comprehension membership assertions. *) (* ------------------------------------------------------------------------- *) let IN_ELIM_THM = prove - (`(!P x. x IN GSPEC (\v. P (SETSPEC v)) <=> P (\p t. p /\ (x = t))) /\ - (!p x. x IN GSPEC (\v. ?y. SETSPEC v (p y) y) <=> p x) /\ - (!P x. GSPEC (\v. P (SETSPEC v)) x <=> P (\p t. p /\ (x = t))) /\ - (!p x. GSPEC (\v. ?y. SETSPEC v (p y) y) x <=> p x) /\ - (!p x. x IN (\y. p y) <=> p x)`, + (`(!P x:A. x IN GSPEC (\v. P (SETSPEC v)) <=> P (\p t. p /\ (x = t))) /\ + (!p x:A. x IN GSPEC (\v. ?y. SETSPEC v (p y) y) <=> p x) /\ + (!P x:A. GSPEC (\v. P (SETSPEC v)) x <=> P (\p t. p /\ (x = t))) /\ + (!p x:A. GSPEC (\v. ?y. SETSPEC v (p y) y) x <=> p x) /\ + (!p x:A. x IN (\y. p y) <=> p x)`, REPEAT STRIP_TAC THEN REWRITE_TAC[IN; GSPEC] THEN TRY(AP_TERM_TAC THEN REWRITE_TAC[FUN_EQ_THM]) THEN REWRITE_TAC[SETSPEC] THEN MESON_TAC[]);; @@ -220,11 +220,11 @@ let IN_REST = prove REWRITE_TAC[REST; IN_DELETE]);; let FORALL_IN_INSERT = prove - (`!P a s. (!x. x IN (a INSERT s) ==> P x) <=> P a /\ (!x. x IN s ==> P x)`, + (`!P a s. (!x:A. x IN (a INSERT s) ==> P x) <=> P a /\ (!x. x IN s ==> P x)`, REWRITE_TAC[IN_INSERT] THEN MESON_TAC[]);; let EXISTS_IN_INSERT = prove - (`!P a s. (?x. x IN (a INSERT s) /\ P x) <=> P a \/ ?x. x IN s /\ P x`, + (`!P a s. (?x:A. x IN (a INSERT s) /\ P x) <=> P a \/ ?x. x IN s /\ P x`, REWRITE_TAC[IN_INSERT] THEN MESON_TAC[]);; let FORALL_IN_UNION = prove @@ -340,11 +340,11 @@ let UNIV_SUBSET = prove SET_TAC[]);; let SING_SUBSET = prove - (`!s x. {x} SUBSET s <=> x IN s`, + (`!s x:A. {x} SUBSET s <=> x IN s`, SET_TAC[]);; let SUBSET_RESTRICT = prove - (`!s P. {x | x IN s /\ P x} SUBSET s`, + (`!s P. {x:A | x IN s /\ P x} SUBSET s`, SIMP_TAC[SUBSET; IN_ELIM_THM]);; (* ------------------------------------------------------------------------- *) @@ -423,11 +423,11 @@ let EMPTY_UNION = prove SET_TAC[]);; let UNION_SUBSET = prove - (`!s t u. (s UNION t) SUBSET u <=> s SUBSET u /\ t SUBSET u`, + (`!s t u:A->bool. (s UNION t) SUBSET u <=> s SUBSET u /\ t SUBSET u`, SET_TAC[]);; let UNION_RESTRICT = prove - (`!P s t. + (`!P s t:A->bool. {x | x IN (s UNION t) /\ P x} = {x | x IN s /\ P x} UNION {x | x IN t /\ P x}`, SET_TAC[]);; @@ -501,11 +501,11 @@ let INTER_UNIV = prove SET_TAC[]);; let SUBSET_INTER = prove - (`!s t u. s SUBSET (t INTER u) <=> s SUBSET t /\ s SUBSET u`, + (`!s t u:A->bool. s SUBSET (t INTER u) <=> s SUBSET t /\ s SUBSET u`, SET_TAC[]);; let INTER_RESTRICT = prove - (`!P s t. + (`!P s (t:A->bool). {x | x IN (s INTER t) /\ P x} = {x | x IN s /\ P x} INTER {x | x IN t /\ P x}`, SET_TAC[]);; @@ -576,7 +576,7 @@ let DIFF_EQ_EMPTY = prove SET_TAC[]);; let SUBSET_DIFF = prove - (`!s t. (s DIFF t) SUBSET s`, + (`!s t:A->bool. (s DIFF t) SUBSET s`, SET_TAC[]);; let COMPL_COMPL = prove @@ -584,7 +584,7 @@ let COMPL_COMPL = prove SET_TAC[]);; let DIFF_RESTRICT = prove - (`!P s t. + (`!P s (t:A->bool). {x | x IN (s DIFF t) /\ P x} = {x | x IN s /\ P x} DIFF {x | x IN t /\ P x}`, SET_TAC[]);; @@ -666,12 +666,12 @@ let INSERT_DIFF = prove POP_ASSUM MP_TAC THEN SET_TAC[]);; let INSERT_AC = prove - (`(x INSERT (y INSERT s) = y INSERT (x INSERT s)) /\ - (x INSERT (x INSERT s) = x INSERT s)`, + (`(x:A) INSERT (y INSERT s) = y INSERT (x INSERT s) /\ + x INSERT (x INSERT s) = x INSERT s`, REWRITE_TAC[INSERT_COMM; INSERT_INSERT]);; let INTER_ACI = prove - (`(p INTER q = q INTER p) /\ + (`((p:A->bool) INTER q = q INTER p) /\ ((p INTER q) INTER r = p INTER q INTER r) /\ (p INTER q INTER r = q INTER p INTER r) /\ (p INTER p = p) /\ @@ -679,7 +679,7 @@ let INTER_ACI = prove SET_TAC[]);; let UNION_ACI = prove - (`(p UNION q = q UNION p) /\ + (`((p:A->bool) UNION q = q UNION p) /\ ((p UNION q) UNION r = p UNION q UNION r) /\ (p UNION q UNION r = q UNION p UNION r) /\ (p UNION p = p) /\ @@ -751,63 +751,65 @@ let DISJOINT_DELETE_SYM = prove (* ------------------------------------------------------------------------- *) let UNIONS_0 = prove - (`UNIONS {} = {}`, + (`UNIONS {}:A->bool = {}`, SET_TAC[]);; let UNIONS_1 = prove - (`UNIONS {s} = s`, + (`!s:A->bool. UNIONS {s} = s`, SET_TAC[]);; let UNIONS_2 = prove - (`UNIONS {s,t} = s UNION t`, + (`!s (t:A->bool). UNIONS {s,t} = s UNION t`, SET_TAC[]);; let UNIONS_INSERT = prove - (`UNIONS (s INSERT u) = s UNION (UNIONS u)`, + (`!(s:A->bool) u. UNIONS (s INSERT u) = s UNION (UNIONS u)`, SET_TAC[]);; let FORALL_IN_UNIONS = prove - (`!P s. (!x. x IN UNIONS s ==> P x) <=> !t x. t IN s /\ x IN t ==> P x`, + (`!P s. (!x:A. x IN UNIONS s ==> P x) <=> !t x. t IN s /\ x IN t ==> P x`, SET_TAC[]);; let EXISTS_IN_UNIONS = prove - (`!P s. (?x. x IN UNIONS s /\ P x) <=> (?t x. t IN s /\ x IN t /\ P x)`, + (`!P s. (?x:A. x IN UNIONS s /\ P x) <=> (?t x. t IN s /\ x IN t /\ P x)`, SET_TAC[]);; let EMPTY_UNIONS = prove - (`!s. (UNIONS s = {}) <=> !t. t IN s ==> t = {}`, + (`!s. (UNIONS s = {}) <=> !t:A->bool. t IN s ==> t = {}`, SET_TAC[]);; let INTER_UNIONS = prove - (`(!s t. UNIONS s INTER t = UNIONS {x INTER t | x IN s}) /\ - (!s t. t INTER UNIONS s = UNIONS {t INTER x | x IN s})`, + (`(!s (t:A->bool). UNIONS s INTER t = UNIONS {x INTER t | x IN s}) /\ + (!s (t:A->bool). t INTER UNIONS s = UNIONS {t INTER x | x IN s})`, ONCE_REWRITE_TAC[EXTENSION] THEN REWRITE_TAC[IN_UNIONS; IN_ELIM_THM; IN_INTER] THEN MESON_TAC[IN_INTER]);; let UNIONS_SUBSET = prove - (`!f t. UNIONS f SUBSET t <=> !s. s IN f ==> s SUBSET t`, + (`!f (t:A->bool). UNIONS f SUBSET t <=> !s. s IN f ==> s SUBSET t`, SET_TAC[]);; let SUBSET_UNIONS = prove - (`!f g. f SUBSET g ==> UNIONS f SUBSET UNIONS g`, + (`!(f:(A->bool)->bool) g. f SUBSET g ==> UNIONS f SUBSET UNIONS g`, SET_TAC[]);; let UNIONS_UNION = prove - (`!s t. UNIONS(s UNION t) = (UNIONS s) UNION (UNIONS t)`, + (`!s t:(A->bool)->bool. UNIONS(s UNION t) = (UNIONS s) UNION (UNIONS t)`, SET_TAC[]);; let INTERS_UNION = prove - (`!s t. INTERS (s UNION t) = INTERS s INTER INTERS t`, + (`!s t:(A->bool)->bool. INTERS (s UNION t) = INTERS s INTER INTERS t`, SET_TAC[]);; let UNIONS_MONO = prove - (`(!x. x IN s ==> ?y. y IN t /\ x SUBSET y) ==> UNIONS s SUBSET UNIONS t`, + (`!s t:(A->bool)->bool. + (!x. x IN s ==> ?y. y IN t /\ x SUBSET y) ==> UNIONS s SUBSET UNIONS t`, SET_TAC[]);; let UNIONS_MONO_IMAGE = prove - (`(!x. x IN s ==> f x SUBSET g x) - ==> UNIONS(IMAGE f s) SUBSET UNIONS(IMAGE g s)`, + (`!(f:A->B->bool) g s. + (!x. x IN s ==> f x SUBSET g x) + ==> UNIONS(IMAGE f s) SUBSET UNIONS(IMAGE g s)`, SET_TAC[]);; let UNIONS_UNIV = prove @@ -816,12 +818,12 @@ let UNIONS_UNIV = prove MESON_TAC[IN_SING]);; let UNIONS_INSERT_EMPTY = prove - (`!s. UNIONS({} INSERT s) = UNIONS s`, + (`!s:(A->bool)->bool. UNIONS({} INSERT s) = UNIONS s`, ONCE_REWRITE_TAC[EXTENSION] THEN REWRITE_TAC[IN_UNIONS; IN_INSERT] THEN MESON_TAC[NOT_IN_EMPTY]);; let UNIONS_DELETE_EMPTY = prove - (`!s. UNIONS(s DELETE {}) = UNIONS s`, + (`!s:(A->bool)->bool. UNIONS(s DELETE {}) = UNIONS s`, ONCE_REWRITE_TAC[EXTENSION] THEN REWRITE_TAC[IN_UNIONS; IN_DELETE] THEN MESON_TAC[NOT_IN_EMPTY]);; @@ -834,19 +836,19 @@ let INTERS_0 = prove SET_TAC[]);; let INTERS_1 = prove - (`INTERS {s} = s`, + (`!s:A->bool. INTERS {s} = s`, SET_TAC[]);; let INTERS_2 = prove - (`INTERS {s,t} = s INTER t`, + (`!s (t:A->bool). INTERS {s,t} = s INTER t`, SET_TAC[]);; let INTERS_INSERT = prove - (`INTERS (s INSERT u) = s INTER (INTERS u)`, + (`!(s:A->bool) u. INTERS (s INSERT u) = s INTER (INTERS u)`, SET_TAC[]);; let SUBSET_INTERS = prove - (`!s f. s SUBSET INTERS f <=> (!t. t IN f ==> s SUBSET t)`, + (`!(s:A->bool) f. s SUBSET INTERS f <=> (!t. t IN f ==> s SUBSET t)`, SET_TAC[]);; let INTERS_SUBSET = prove @@ -859,7 +861,7 @@ let INTERS_SUBSET_STRONG = prove SET_TAC[]);; let INTERS_ANTIMONO = prove - (`!f g. g SUBSET f ==> INTERS f SUBSET INTERS g`, + (`!(f:(A->bool)->bool) g. g SUBSET f ==> INTERS f SUBSET INTERS g`, SET_TAC[]);; let INTERS_EQ_UNIV = prove @@ -867,8 +869,9 @@ let INTERS_EQ_UNIV = prove SET_TAC[]);; let INTERS_ANTIMONO_GEN = prove - (`!s t. (!y. y IN t ==> ?x. x IN s /\ x SUBSET y) - ==> INTERS s SUBSET INTERS t`, + (`!s (t:(A->bool)->bool). + (!y. y IN t ==> ?x. x IN s /\ x SUBSET y) + ==> INTERS s SUBSET INTERS t`, SET_TAC[]);; (* ------------------------------------------------------------------------- *) @@ -876,34 +879,35 @@ let INTERS_ANTIMONO_GEN = prove (* ------------------------------------------------------------------------- *) let IMAGE_CLAUSES = prove - (`(IMAGE f {} = {}) /\ + (`(IMAGE (f:A->B) {} = {}) /\ (IMAGE f (x INSERT s) = (f x) INSERT (IMAGE f s))`, REWRITE_TAC[IMAGE; IN_ELIM_THM; NOT_IN_EMPTY; IN_INSERT; EXTENSION] THEN MESON_TAC[]);; let IMAGE_UNION = prove - (`!f s t. IMAGE f (s UNION t) = (IMAGE f s) UNION (IMAGE f t)`, + (`!(f:A->B) s t. IMAGE f (s UNION t) = (IMAGE f s) UNION (IMAGE f t)`, REWRITE_TAC[EXTENSION; IN_IMAGE; IN_UNION] THEN MESON_TAC[]);; let IMAGE_ID = prove - (`!s. IMAGE (\x. x) s = s`, + (`!s:A->bool. IMAGE (\x. x) s = s`, REWRITE_TAC[EXTENSION; IN_IMAGE; UNWIND_THM1]);; let IMAGE_I = prove - (`!s. IMAGE I s = s`, + (`!s:A->bool. IMAGE I s = s`, REWRITE_TAC[I_DEF; IMAGE_ID]);; let IMAGE_o = prove - (`!f g s. IMAGE (f o g) s = IMAGE f (IMAGE g s)`, + (`!(f:B->C) (g:A->B) s. IMAGE (f o g) s = IMAGE f (IMAGE g s)`, REWRITE_TAC[EXTENSION; IN_IMAGE; o_THM] THEN MESON_TAC[]);; let IMAGE_SUBSET = prove - (`!f s t. s SUBSET t ==> (IMAGE f s) SUBSET (IMAGE f t)`, + (`!(f:A->B) s t. s SUBSET t ==> (IMAGE f s) SUBSET (IMAGE f t)`, REWRITE_TAC[SUBSET; IN_IMAGE] THEN MESON_TAC[]);; let IMAGE_INTER_INJ = prove - (`!f s t. (!x y. (f(x) = f(y)) ==> (x = y)) - ==> (IMAGE f (s INTER t) = (IMAGE f s) INTER (IMAGE f t))`, + (`!(f:A->B) s t. + (!x y. f(x) = f(y) ==> x = y) + ==> (IMAGE f (s INTER t) = (IMAGE f s) INTER (IMAGE f t))`, REWRITE_TAC[EXTENSION; IN_IMAGE; IN_INTER] THEN MESON_TAC[]);; let IMAGE_DIFF_INJ = prove @@ -931,39 +935,39 @@ let IMAGE_DELETE_INJ_ALT = prove SET_TAC[]);; let IMAGE_EQ_EMPTY = prove - (`!f s. (IMAGE f s = {}) <=> (s = {})`, + (`!(f:A->B) s. (IMAGE f s = {}) <=> (s = {})`, REWRITE_TAC[EXTENSION; NOT_IN_EMPTY; IN_IMAGE] THEN MESON_TAC[]);; let FORALL_IN_IMAGE = prove - (`!f s. (!y. y IN IMAGE f s ==> P y) <=> (!x. x IN s ==> P(f x))`, + (`!(f:A->B) s. (!y. y IN IMAGE f s ==> P y) <=> (!x. x IN s ==> P(f x))`, REWRITE_TAC[IN_IMAGE] THEN MESON_TAC[]);; let EXISTS_IN_IMAGE = prove - (`!f s. (?y. y IN IMAGE f s /\ P y) <=> ?x. x IN s /\ P(f x)`, + (`!(f:A->B) s. (?y. y IN IMAGE f s /\ P y) <=> ?x. x IN s /\ P(f x)`, REWRITE_TAC[IN_IMAGE] THEN MESON_TAC[]);; let FORALL_IN_IMAGE_2 = prove - (`!f P s. (!x y. x IN IMAGE f s /\ y IN IMAGE f s ==> P x y) <=> - (!x y. x IN s /\ y IN s ==> P (f x) (f y))`, + (`!(f:A->B) P s. (!x y. x IN IMAGE f s /\ y IN IMAGE f s ==> P x y) <=> + (!x y. x IN s /\ y IN s ==> P (f x) (f y))`, SET_TAC[]);; let IMAGE_CONST = prove - (`!s c. IMAGE (\x. c) s = if s = {} then {} else {c}`, + (`!(s:A->bool) (c:B). IMAGE (\x. c) s = if s = {} then {} else {c}`, REPEAT GEN_TAC THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[IMAGE_CLAUSES] THEN REWRITE_TAC[EXTENSION; IN_IMAGE; IN_SING] THEN ASM_MESON_TAC[MEMBER_NOT_EMPTY]);; let SIMPLE_IMAGE = prove - (`!f s. {f x | x IN s} = IMAGE f s`, + (`!(f:A->B) s. {f x | x IN s} = IMAGE f s`, REWRITE_TAC[EXTENSION; IN_ELIM_THM; IN_IMAGE] THEN MESON_TAC[]);; let SIMPLE_IMAGE_GEN = prove - (`!f P. {f x | P x} = IMAGE f {x | P x}`, + (`!(f:A->B) P. {f x | P x} = IMAGE f {x | P x}`, SET_TAC[]);; let IMAGE_UNIONS = prove - (`!f s. IMAGE f (UNIONS s) = UNIONS (IMAGE (IMAGE f) s)`, + (`!(f:A->B) s. IMAGE f (UNIONS s) = UNIONS (IMAGE (IMAGE f) s)`, ONCE_REWRITE_TAC[EXTENSION] THEN REWRITE_TAC[IN_UNIONS; IN_IMAGE] THEN REWRITE_TAC[LEFT_AND_EXISTS_THM] THEN ONCE_REWRITE_TAC[SWAP_EXISTS_THM] THEN @@ -971,12 +975,17 @@ let IMAGE_UNIONS = prove MESON_TAC[]);; let FUN_IN_IMAGE = prove - (`!f s x. x IN s ==> f(x) IN IMAGE f s`, + (`!(f:A->B) s x. x IN s ==> f(x) IN IMAGE f s`, SET_TAC[]);; let SURJECTIVE_IMAGE_EQ = prove - (`!s t. (!y. y IN t ==> ?x. f x = y) /\ (!x. (f x) IN t <=> x IN s) - ==> IMAGE f s = t`, + (`!(f:A->B) s t. + (!y. y IN t ==> ?x. f x = y) /\ (!x. (f x) IN t <=> x IN s) + ==> IMAGE f s = t`, + SET_TAC[]);; + +let IMAGE_EQ = prove + (`!(f:A->B) g s. (!x. x IN s ==> f x = g x) ==> IMAGE f s = IMAGE g s`, SET_TAC[]);; (* ------------------------------------------------------------------------- *) @@ -984,16 +993,16 @@ let SURJECTIVE_IMAGE_EQ = prove (* ------------------------------------------------------------------------- *) let EMPTY_GSPEC = prove - (`{x | F} = {}`, + (`{x:A | F} = {}`, SET_TAC[]);; let UNIV_GSPEC = prove - (`{x | T} = UNIV`, + (`{x | T} = (:A)`, SET_TAC[]);; let SING_GSPEC = prove - (`(!a. {x | x = a} = {a}) /\ - (!a. {x | a = x} = {a})`, + (`(!a:A. {x | x = a} = {a}) /\ + (!a:A. {x | a = x} = {a})`, SET_TAC[]);; let IN_GSPEC = prove @@ -1001,42 +1010,51 @@ let IN_GSPEC = prove SET_TAC[]);; let IN_ELIM_PAIR_THM = prove - (`!P a b. (a,b) IN {(x,y) | P x y} <=> P a b`, + (`!(P:A->B->bool) a b. (a,b) IN {(x,y) | P x y} <=> P a b`, REWRITE_TAC[IN_ELIM_THM] THEN MESON_TAC[PAIR_EQ]);; let IN_ELIM_TRIPLE_THM = prove - (`(!P a b c. (a,b,c) IN {(x,y,z) | P x y z} <=> P a b c) /\ - (!P a b c. ((a,b),c) IN {((x,y),z) | P x y z} <=> P a b c)`, + (`(!(P:A->B->C->bool) a b c. (a,b,c) IN {(x,y,z) | P x y z} <=> P a b c) /\ + (!(P:A->B->C->bool) a b c. ((a,b),c) IN {((x,y),z) | P x y z} <=> P a b c)`, REWRITE_TAC[IN_ELIM_THM; PAIR_EQ] THEN MESON_TAC[]);; let IN_ELIM_QUAD_THM = prove - (`(!P a b c d. (a,b,c,d) IN {w,x,y,z | P w x y z} <=> P a b c d) /\ - (!P a b c d. ((a,b),(c,d)) IN {(w,x),(y,z) | P w x y z} <=> P a b c d) /\ - (!P a b c d. (((a,b),c),d) IN {(((w,x),y),z) | P w x y z} <=> P a b c d)`, + (`(!(P:A->B->C->D->bool) a b c d. + (a,b,c,d) IN {w,x,y,z | P w x y z} <=> P a b c d) /\ + (!(P:A->B->C->D->bool) a b c d. + ((a,b),(c,d)) IN {(w,x),(y,z) | P w x y z} <=> P a b c d) /\ + (!(P:A->B->C->D->bool) a b c d. + (((a,b),c),d) IN {(((w,x),y),z) | P w x y z} <=> P a b c d)`, REWRITE_TAC[IN_ELIM_THM; PAIR_EQ] THEN MESON_TAC[]);; let SET_PAIR_THM = prove - (`!P. {p | P p} = {(a,b) | P(a,b)}`, + (`!(P:A#B->bool). {p | P p} = {(a,b) | P(a,b)}`, REWRITE_TAC[EXTENSION; FORALL_PAIR_THM; IN_ELIM_THM; IN_ELIM_PAIR_THM]);; let FORALL_IN_GSPEC = prove - (`(!P f. (!z. z IN {f x | P x} ==> Q z) <=> (!x. P x ==> Q(f x))) /\ - (!P f. (!z. z IN {f x y | P x y} ==> Q z) <=> - (!x y. P x y ==> Q(f x y))) /\ - (!P f. (!z. z IN {f w x y | P w x y} ==> Q z) <=> - (!w x y. P w x y ==> Q(f w x y))) /\ - (!P f. (!z. z IN {f v w x y | P v w x y} ==> Q z) <=> - (!v w x y. P v w x y ==> Q(f v w x y)))`, + (`(!P Q (f:A->B). (!z. z IN {f x | P x} ==> Q z) <=> (!x. P x ==> Q(f x))) /\ + (!P Q (f:A->B->C). + (!z. z IN {f x y | P x y} ==> Q z) <=> + (!x y. P x y ==> Q(f x y))) /\ + (!P Q (f:A->B->C->D). + (!z. z IN {f w x y | P w x y} ==> Q z) <=> + (!w x y. P w x y ==> Q(f w x y))) /\ + (!P Q (f:A->B->C->D->E). + (!z. z IN {f v w x y | P v w x y} ==> Q z) <=> + (!v w x y. P v w x y ==> Q(f v w x y)))`, SET_TAC[]);; let EXISTS_IN_GSPEC = prove - (`(!P f. (?z. z IN {f x | P x} /\ Q z) <=> (?x. P x /\ Q(f x))) /\ - (!P f. (?z. z IN {f x y | P x y} /\ Q z) <=> - (?x y. P x y /\ Q(f x y))) /\ - (!P f. (?z. z IN {f w x y | P w x y} /\ Q z) <=> - (?w x y. P w x y /\ Q(f w x y))) /\ - (!P f. (?z. z IN {f v w x y | P v w x y} /\ Q z) <=> - (?v w x y. P v w x y /\ Q(f v w x y)))`, + (`(!P Q (f:A->B). (?z. z IN {f x | P x} /\ Q z) <=> (?x. P x /\ Q(f x))) /\ + (!P Q (f:A->B->C). + (?z. z IN {f x y | P x y} /\ Q z) <=> + (?x y. P x y /\ Q(f x y))) /\ + (!P Q (f:A->B->C->D). + (?z. z IN {f w x y | P w x y} /\ Q z) <=> + (?w x y. P w x y /\ Q(f w x y))) /\ + (!P Q (f:A->B->C->D->E). + (?z. z IN {f v w x y | P v w x y} /\ Q z) <=> + (?v w x y. P v w x y /\ Q(f v w x y)))`, SET_TAC[]);; let SET_PROVE_CASES = prove @@ -1046,28 +1064,34 @@ let SET_PROVE_CASES = prove MESON_TAC[SET_CASES]);; let UNIONS_IMAGE = prove - (`!f s. UNIONS (IMAGE f s) = {y | ?x. x IN s /\ y IN f x}`, + (`!(f:A->B->bool) s. UNIONS (IMAGE f s) = {y | ?x. x IN s /\ y IN f x}`, REPEAT GEN_TAC THEN GEN_REWRITE_TAC I [EXTENSION] THEN REWRITE_TAC[IN_UNIONS; IN_IMAGE; IN_ELIM_THM] THEN MESON_TAC[]);; let INTERS_IMAGE = prove - (`!f s. INTERS (IMAGE f s) = {y | !x. x IN s ==> y IN f x}`, + (`!(f:A->B->bool) s. INTERS (IMAGE f s) = {y | !x. x IN s ==> y IN f x}`, REPEAT GEN_TAC THEN GEN_REWRITE_TAC I [EXTENSION] THEN REWRITE_TAC[IN_INTERS; IN_IMAGE; IN_ELIM_THM] THEN MESON_TAC[]);; let UNIONS_GSPEC = prove - (`(!P f. UNIONS {f x | P x} = {a | ?x. P x /\ a IN (f x)}) /\ - (!P f. UNIONS {f x y | P x y} = {a | ?x y. P x y /\ a IN (f x y)}) /\ - (!P f. UNIONS {f x y z | P x y z} = - {a | ?x y z. P x y z /\ a IN (f x y z)})`, + (`(!P (f:A->B->bool). + UNIONS {f x | P x} = {a | ?x. P x /\ a IN (f x)}) /\ + (!P (f:A->B->C->bool). + UNIONS {f x y | P x y} = {a | ?x y. P x y /\ a IN (f x y)}) /\ + (!P (f:A->B->C->D->bool). + UNIONS {f x y z | P x y z} = + {a | ?x y z. P x y z /\ a IN (f x y z)})`, REPEAT STRIP_TAC THEN GEN_REWRITE_TAC I [EXTENSION] THEN REWRITE_TAC[IN_UNIONS; IN_ELIM_THM] THEN MESON_TAC[]);; let INTERS_GSPEC = prove - (`(!P f. INTERS {f x | P x} = {a | !x. P x ==> a IN (f x)}) /\ - (!P f. INTERS {f x y | P x y} = {a | !x y. P x y ==> a IN (f x y)}) /\ - (!P f. INTERS {f x y z | P x y z} = - {a | !x y z. P x y z ==> a IN (f x y z)})`, + (`(!P (f:A->B->bool). + INTERS {f x | P x} = {a | !x. P x ==> a IN (f x)}) /\ + (!P (f:A->B->C->bool). + INTERS {f x y | P x y} = {a | !x y. P x y ==> a IN (f x y)}) /\ + (!P (f:A->B->C->D->bool). + INTERS {f x y z | P x y z} = + {a | !x y z. P x y z ==> a IN (f x y z)})`, REPEAT STRIP_TAC THEN GEN_REWRITE_TAC I [EXTENSION] THEN REWRITE_TAC[IN_INTERS; IN_ELIM_THM] THEN MESON_TAC[]);; @@ -1080,35 +1104,36 @@ let UNIONS_SINGS = prove REWRITE_TAC[UNIONS_GSPEC] THEN SET_TAC[]);; let IMAGE_INTERS = prove - (`!f s. ~(s = {}) /\ - (!x y. x IN UNIONS s /\ y IN UNIONS s /\ f x = f y ==> x = y) - ==> IMAGE f (INTERS s) = INTERS(IMAGE (IMAGE f) s)`, + (`!(f:A->B) s. + ~(s = {}) /\ + (!x y. x IN UNIONS s /\ y IN UNIONS s /\ f x = f y ==> x = y) + ==> IMAGE f (INTERS s) = INTERS(IMAGE (IMAGE f) s)`, REWRITE_TAC[INTERS_IMAGE] THEN SET_TAC[]);; let DIFF_INTERS = prove - (`!u s. u DIFF INTERS s = UNIONS {u DIFF t | t IN s}`, + (`!(u:A->bool) s. u DIFF INTERS s = UNIONS {u DIFF t | t IN s}`, REWRITE_TAC[UNIONS_GSPEC] THEN SET_TAC[]);; let INTERS_UNIONS = prove - (`!s. INTERS s = UNIV DIFF (UNIONS {UNIV DIFF t | t IN s})`, + (`!s. INTERS s = UNIV DIFF (UNIONS {(:A) DIFF t | t IN s})`, REWRITE_TAC[GSYM DIFF_INTERS] THEN SET_TAC[]);; let UNIONS_INTERS = prove - (`!s. UNIONS s = UNIV DIFF (INTERS {UNIV DIFF t | t IN s})`, + (`!s. UNIONS s = UNIV DIFF (INTERS {(:A) DIFF t | t IN s})`, GEN_TAC THEN GEN_REWRITE_TAC I [EXTENSION] THEN REWRITE_TAC[IN_UNIONS; IN_UNIV; IN_DIFF; INTERS_GSPEC; IN_ELIM_THM] THEN MESON_TAC[]);; let UNIONS_DIFF = prove - (`!s t. UNIONS s DIFF t = UNIONS {x DIFF t | x IN s}`, + (`!s t:A->bool. UNIONS s DIFF t = UNIONS {x DIFF t | x IN s}`, REWRITE_TAC[UNIONS_GSPEC] THEN SET_TAC[]);; let DIFF_UNIONS = prove - (`!u s. u DIFF UNIONS s = u INTER INTERS {u DIFF t | t IN s}`, + (`!(u:A->bool) s. u DIFF UNIONS s = u INTER INTERS {u DIFF t | t IN s}`, REWRITE_TAC[INTERS_GSPEC] THEN SET_TAC[]);; let DIFF_UNIONS_NONEMPTY = prove - (`!u s. ~(s = {}) ==> u DIFF UNIONS s = INTERS {u DIFF t | t IN s}`, + (`!(u:A->bool) s. ~(s = {}) ==> u DIFF UNIONS s = INTERS {u DIFF t | t IN s}`, REWRITE_TAC[INTERS_GSPEC] THEN SET_TAC[]);; let INTERS_OVER_UNIONS = prove @@ -1122,10 +1147,12 @@ let INTERS_OVER_UNIONS = prove MESON_TAC[]);; let INTER_INTERS = prove - (`(!f s:A->bool. s INTER INTERS f = - if f = {} then s else INTERS {s INTER t | t IN f}) /\ - (!f s:A->bool. INTERS f INTER s = - if f = {} then s else INTERS {t INTER s | t IN f})`, + (`(!f s:A->bool. + s INTER INTERS f = + if f = {} then s else INTERS {s INTER t | t IN f}) /\ + (!f s:A->bool. + INTERS f INTER s = + if f = {} then s else INTERS {t INTER s | t IN f})`, REPEAT STRIP_TAC THEN COND_CASES_TAC THEN ASM_REWRITE_TAC[INTERS_0; INTER_UNIV; INTERS_GSPEC] THEN ASM SET_TAC[]);; @@ -1146,7 +1173,7 @@ let IMAGE_INTERS_SUBSET = prove REWRITE_TAC[INTERS_IMAGE] THEN SET_TAC[]);; let IMAGE_INTER_SUBSET = prove - (`!f s t. IMAGE f (s INTER t) SUBSET IMAGE f s INTER IMAGE f t`, + (`!(f:A->B) s t. IMAGE f (s INTER t) SUBSET IMAGE f s INTER IMAGE f t`, SET_TAC[]);; let IMAGE_INTER_SATURATED_GEN = prove @@ -1226,29 +1253,31 @@ let FINITE_INDUCT_STRONG = prove (* ------------------------------------------------------------------------- *) let INJECTIVE_ON_ALT = prove - (`!P f. (!x y. P x /\ P y /\ f x = f y ==> x = y) <=> - (!x y. P x /\ P y ==> (f x = f y <=> x = y))`, + (`!P f:A->B. + (!x y. P x /\ P y /\ f x = f y ==> x = y) <=> + (!x y. P x /\ P y ==> (f x = f y <=> x = y))`, MESON_TAC[]);; let INJECTIVE_ALT = prove - (`!f. (!x y. f x = f y ==> x = y) <=> (!x y. f x = f y <=> x = y)`, + (`!f:A->B. (!x y. f x = f y ==> x = y) <=> (!x y. f x = f y <=> x = y)`, MESON_TAC[]);; let SURJECTIVE_ON_RIGHT_INVERSE = prove - (`!f t. (!y. y IN t ==> ?x. x IN s /\ (f(x) = y)) <=> - (?g. !y. y IN t ==> g(y) IN s /\ (f(g(y)) = y))`, + (`!(f:A->B) t. + (!y. y IN t ==> ?x. x IN s /\ (f(x) = y)) <=> + (?g. !y. y IN t ==> g(y) IN s /\ (f(g(y)) = y))`, REWRITE_TAC[RIGHT_IMP_EXISTS_THM; SKOLEM_THM]);; let INJECTIVE_ON_LEFT_INVERSE = prove - (`!f s. (!x y. x IN s /\ y IN s /\ (f x = f y) ==> (x = y)) <=> + (`!(f:A->B) s. (!x y. x IN s /\ y IN s /\ (f x = f y) ==> (x = y)) <=> (?g. !x. x IN s ==> (g(f(x)) = x))`, let lemma = MESON[] `(!x. x IN s ==> (g(f(x)) = x)) <=> - (!y x. x IN s /\ (y = f x) ==> (g y = x))` in + (!y x. x IN s /\ (y = (f:A->B) x) ==> (g y = x))` in REWRITE_TAC[lemma; GSYM SKOLEM_THM] THEN MESON_TAC[]);; let BIJECTIVE_ON_LEFT_RIGHT_INVERSE = prove - (`!f s t. + (`!(f:A->B) s t. (!x. x IN s ==> f(x) IN t) ==> ((!x y. x IN s /\ y IN s /\ f(x) = f(y) ==> x = y) /\ (!y. y IN t ==> ?x. x IN s /\ f x = y) <=> @@ -1261,11 +1290,11 @@ let BIJECTIVE_ON_LEFT_RIGHT_INVERSE = prove EQ_TAC THEN ASM_MESON_TAC[]);; let SURJECTIVE_RIGHT_INVERSE = prove - (`(!y. ?x. f(x) = y) <=> (?g. !y. f(g(y)) = y)`, + (`!f:A->B. (!y. ?x. f(x) = y) <=> (?g. !y. f(g(y)) = y)`, MESON_TAC[SURJECTIVE_ON_RIGHT_INVERSE; IN_UNIV]);; let INJECTIVE_LEFT_INVERSE = prove - (`(!x y. (f x = f y) ==> (x = y)) <=> (?g. !x. g(f(x)) = x)`, + (`!f:A->B. (!x y. f x = f y ==> x = y) <=> (?g. !x. g(f(x)) = x)`, let th = REWRITE_RULE[IN_UNIV] (ISPECL [`f:A->B`; `UNIV:A->bool`] INJECTIVE_ON_LEFT_INVERSE) in REWRITE_TAC[th]);; @@ -1279,24 +1308,26 @@ let BIJECTIVE_LEFT_RIGHT_INVERSE = prove REWRITE_TAC[IN_UNIV]);; let FUNCTION_FACTORS_LEFT_GEN = prove - (`!P f g. (!x y. P x /\ P y /\ g x = g y ==> f x = f y) <=> - (?h. !x. P x ==> f(x) = h(g x))`, + (`!P (f:A->B) (g:A->C). + (!x y. P x /\ P y /\ g x = g y ==> f x = f y) <=> + (?h. !x. P x ==> f(x) = h(g x))`, ONCE_REWRITE_TAC[MESON[] `(!x. P x ==> f(x) = g(k x)) <=> (!y x. P x /\ y = k x ==> f x = g y)`] THEN REWRITE_TAC[GSYM SKOLEM_THM] THEN MESON_TAC[]);; let FUNCTION_FACTORS_LEFT = prove - (`!f g. (!x y. (g x = g y) ==> (f x = f y)) <=> ?h. f = h o g`, + (`!(f:A->B) (g:A->C). (!x y. g x = g y ==> f x = f y) <=> ?h. f = h o g`, REWRITE_TAC[FUN_EQ_THM; o_THM; GSYM(REWRITE_RULE[] (ISPEC `\x. T` FUNCTION_FACTORS_LEFT_GEN))]);; let FUNCTION_FACTORS_RIGHT_GEN = prove - (`!P f g. (!x. P x ==> ?y. g(y) = f(x)) <=> - (?h. !x. P x ==> f(x) = g(h x))`, + (`!P (f:A->C) (g:B->C). + (!x. P x ==> ?y. g(y) = f(x)) <=> + (?h. !x. P x ==> f(x) = g(h x))`, REWRITE_TAC[GSYM SKOLEM_THM] THEN MESON_TAC[]);; let FUNCTION_FACTORS_RIGHT = prove - (`!f g. (!x. ?y. g(y) = f(x)) <=> ?h. f = g o h`, + (`!(f:A->C) (g:B->C). (!x. ?y. g(y) = f(x)) <=> ?h. f = g o h`, REWRITE_TAC[FUN_EQ_THM; o_THM; GSYM SKOLEM_THM] THEN MESON_TAC[]);; let SURJECTIVE_FORALL_THM = prove @@ -1332,7 +1363,7 @@ let IMAGE_INJECTIVE_IMAGE_OF_SUBSET = prove (* ------------------------------------------------------------------------- *) let FINITE_EMPTY = prove - (`FINITE {}`, + (`FINITE ({}:A->bool)`, REWRITE_TAC[FINITE_RULES]);; let FINITE_SUBSET = prove @@ -1387,7 +1418,7 @@ let FINITE_INSERT = prove ASM_REWRITE_TAC[]]);; let FINITE_SING = prove - (`!a. FINITE {a}`, + (`!a:A. FINITE {a}`, REWRITE_TAC[FINITE_INSERT; FINITE_RULES]);; let FINITE_DELETE_IMP = prove @@ -1406,7 +1437,8 @@ let FINITE_DELETE = prove POP_ASSUM MP_TAC THEN SET_TAC[]]);; let FINITE_FINITE_UNIONS = prove - (`!s. FINITE(s) ==> (FINITE(UNIONS s) <=> (!t. t IN s ==> FINITE(t)))`, + (`!s:(A->bool)->bool. + FINITE(s) ==> (FINITE(UNIONS s) <=> (!t. t IN s ==> FINITE(t)))`, MATCH_MP_TAC FINITE_INDUCT THEN REWRITE_TAC[IN_INSERT; NOT_IN_EMPTY; UNIONS_0; UNIONS_INSERT] THEN REWRITE_TAC[FINITE_UNION; FINITE_RULES] THEN MESON_TAC[]);; @@ -1505,7 +1537,7 @@ let INFINITE_IMAGE_INJ = prove MESON_TAC[INFINITE_IMAGE]);; let INFINITE_NONEMPTY = prove - (`!s. INFINITE(s) ==> ~(s = EMPTY)`, + (`!s:A->bool. INFINITE(s) ==> ~(s = EMPTY)`, MESON_TAC[INFINITE; FINITE_RULES]);; let INFINITE_DIFF_FINITE = prove @@ -1536,17 +1568,18 @@ let SUBSET_IMAGE = prove REWRITE_TAC[SUBSET_IMAGE_INJ] THEN MATCH_MP_TAC MONO_EXISTS THEN SET_TAC[]);; let EXISTS_SUBSET_IMAGE = prove - (`!P f s. + (`!P (f:A->B) s. (?t. t SUBSET IMAGE f s /\ P t) <=> (?t. t SUBSET s /\ P (IMAGE f t))`, REWRITE_TAC[SUBSET_IMAGE] THEN MESON_TAC[]);; let FORALL_SUBSET_IMAGE = prove - (`!P f s. (!t. t SUBSET IMAGE f s ==> P t) <=> - (!t. t SUBSET s ==> P(IMAGE f t))`, + (`!P (f:A->B) s. + (!t. t SUBSET IMAGE f s ==> P t) <=> + (!t. t SUBSET s ==> P(IMAGE f t))`, REWRITE_TAC[SUBSET_IMAGE] THEN MESON_TAC[]);; let EXISTS_SUBSET_IMAGE_INJ = prove - (`!P f s. + (`!P (f:A->B) s. (?t. t SUBSET IMAGE f s /\ P t) <=> (?t. t SUBSET s /\ (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) /\ @@ -1554,16 +1587,17 @@ let EXISTS_SUBSET_IMAGE_INJ = prove REWRITE_TAC[SUBSET_IMAGE_INJ] THEN MESON_TAC[]);; let FORALL_SUBSET_IMAGE_INJ = prove - (`!P f s. (!t. t SUBSET IMAGE f s ==> P t) <=> - (!t. t SUBSET s /\ - (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) - ==> P(IMAGE f t))`, + (`!P (f:A->B) s. + (!t. t SUBSET IMAGE f s ==> P t) <=> + (!t. t SUBSET s /\ + (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) + ==> P(IMAGE f t))`, REPEAT GEN_TAC THEN ONCE_REWRITE_TAC[MESON[] `(!t. p t) <=> ~(?t. ~p t)`] THEN REWRITE_TAC[NOT_IMP; EXISTS_SUBSET_IMAGE_INJ; GSYM CONJ_ASSOC]);; let EXISTS_FINITE_SUBSET_IMAGE_INJ = prove - (`!P f s. + (`!P (f:A->B) s. (?t. FINITE t /\ t SUBSET IMAGE f s /\ P t) <=> (?t. FINITE t /\ t SUBSET s /\ (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) /\ @@ -1573,16 +1607,17 @@ let EXISTS_FINITE_SUBSET_IMAGE_INJ = prove AP_TERM_TAC THEN ABS_TAC THEN MESON_TAC[FINITE_IMAGE_INJ_EQ]);; let FORALL_FINITE_SUBSET_IMAGE_INJ = prove - (`!P f s. (!t. FINITE t /\ t SUBSET IMAGE f s ==> P t) <=> - (!t. FINITE t /\ t SUBSET s /\ - (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) - ==> P(IMAGE f t))`, + (`!P (f:A->B) s. + (!t. FINITE t /\ t SUBSET IMAGE f s ==> P t) <=> + (!t. FINITE t /\ t SUBSET s /\ + (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) + ==> P(IMAGE f t))`, REPEAT GEN_TAC THEN ONCE_REWRITE_TAC[MESON[] `(!t. p t) <=> ~(?t. ~p t)`] THEN REWRITE_TAC[NOT_IMP; EXISTS_FINITE_SUBSET_IMAGE_INJ; GSYM CONJ_ASSOC]);; let EXISTS_FINITE_SUBSET_IMAGE = prove - (`!P f s. + (`!P (f:A->B) s. (?t. FINITE t /\ t SUBSET IMAGE f s /\ P t) <=> (?t. FINITE t /\ t SUBSET s /\ P (IMAGE f t))`, REPEAT GEN_TAC THEN EQ_TAC THENL @@ -1590,8 +1625,9 @@ let EXISTS_FINITE_SUBSET_IMAGE = prove MESON_TAC[FINITE_IMAGE; IMAGE_SUBSET]]);; let FORALL_FINITE_SUBSET_IMAGE = prove - (`!P f s. (!t. FINITE t /\ t SUBSET IMAGE f s ==> P t) <=> - (!t. FINITE t /\ t SUBSET s ==> P(IMAGE f t))`, + (`!P (f:A->B) s. + (!t. FINITE t /\ t SUBSET IMAGE f s ==> P t) <=> + (!t. FINITE t /\ t SUBSET s ==> P(IMAGE f t))`, REPEAT GEN_TAC THEN ONCE_REWRITE_TAC[MESON[] `(!x. P x) <=> ~(?x. ~P x)`] THEN REWRITE_TAC[NOT_IMP; GSYM CONJ_ASSOC; EXISTS_FINITE_SUBSET_IMAGE]);; @@ -1628,11 +1664,11 @@ let FINITE_IMAGE_EQ_INJ = prove ASM_METIS_TAC[FINITE_IMAGE_INJ_EQ]);; let FINITE_DIFF = prove - (`!s t. FINITE s ==> FINITE(s DIFF t)`, + (`!s t:A->bool. FINITE s ==> FINITE(s DIFF t)`, MESON_TAC[FINITE_SUBSET; SUBSET_DIFF]);; let INFINITE_SUPERSET = prove - (`!s t. INFINITE s /\ s SUBSET t ==> INFINITE t`, + (`!s t:A->bool. INFINITE s /\ s SUBSET t ==> INFINITE t`, REWRITE_TAC[INFINITE] THEN MESON_TAC[FINITE_SUBSET]);; let FINITE_TRANSITIVITY_CHAIN = prove @@ -1738,7 +1774,7 @@ let FINREC = new_recursive_definition num_RECURSION (a = f x c))`;; let FINREC_1_LEMMA = prove - (`!f b s a. FINREC f b s a (SUC 0) <=> ?x. (s = {x}) /\ (a = f x b)`, + (`!(f:A->B->B) b s a. FINREC f b s a (SUC 0) <=> ?x. s = {x} /\ a = f x b`, REWRITE_TAC[FINREC] THEN REPEAT GEN_TAC THEN AP_TERM_TAC THEN ABS_TAC THEN SET_TAC[]);; @@ -1867,7 +1903,7 @@ let SET_RECURSION_LEMMA = prove REPEAT AP_TERM_TAC THEN UNDISCH_TAC `~(x:A IN s)` THEN SET_TAC[]]]);; let ITSET = new_definition - `ITSET f s b = + `ITSET (f:A->B->B) s b = (@g. (g {} = b) /\ !x s. FINITE s ==> (g (x INSERT s) = if x IN s then g s else f x (g s))) @@ -1905,10 +1941,11 @@ let FINITE_RECURSION_DELETE = prove UNDISCH_TAC `~(x:A IN s)` THEN SET_TAC[]]);; let ITSET_EQ = prove - (`!s f g b. FINITE(s) /\ (!x. x IN s ==> (f x = g x)) /\ - (!x y s. ~(x = y) ==> (f x (f y s) = f y (f x s))) /\ - (!x y s. ~(x = y) ==> (g x (g y s) = g y (g x s))) - ==> (ITSET f s b = ITSET g s b)`, + (`!s (f:A->B->B) g b. + FINITE(s) /\ (!x. x IN s ==> (f x = g x)) /\ + (!x y s. ~(x = y) ==> (f x (f y s) = f y (f x s))) /\ + (!x y s. ~(x = y) ==> (g x (g y s) = g y (g x s))) + ==> (ITSET f s b = ITSET g s b)`, ONCE_REWRITE_TAC[IMP_CONJ] THEN REWRITE_TAC[RIGHT_FORALL_IMP_THM] THEN MATCH_MP_TAC FINITE_INDUCT_STRONG THEN @@ -1922,7 +1959,7 @@ let ITSET_EQ = prove (* ------------------------------------------------------------------------- *) let CARD = new_definition - `CARD s = ITSET (\x n. SUC n) s 0`;; + `CARD (s:A->bool) = ITSET (\x n. SUC n) s 0`;; let CARD_CLAUSES = prove (`(CARD ({}:A->bool) = 0) /\ @@ -1969,18 +2006,19 @@ let CARD_DELETE = prove AP_TERM_TAC THEN UNDISCH_TAC `~(x:A IN s)` THEN SET_TAC[]]);; let CARD_UNION_EQ = prove - (`!s t u. FINITE u /\ (s INTER t = {}) /\ (s UNION t = u) - ==> (CARD s + CARD t = CARD u)`, + (`!s t u:A->bool. + FINITE u /\ s INTER t = {} /\ s UNION t = u + ==> (CARD s + CARD t = CARD u)`, MESON_TAC[CARD_UNION; FINITE_SUBSET; SUBSET_UNION]);; let CARD_DIFF = prove - (`!s t. FINITE s /\ t SUBSET s ==> CARD(s DIFF t) = CARD s - CARD t`, + (`!s t:A->bool. FINITE s /\ t SUBSET s ==> CARD(s DIFF t) = CARD s - CARD t`, REPEAT STRIP_TAC THEN MATCH_MP_TAC(ARITH_RULE `a + b:num = c ==> a = c - b`) THEN MATCH_MP_TAC CARD_UNION_EQ THEN ASM_SIMP_TAC[] THEN ASM SET_TAC[]);; let CARD_EQ_0 = prove - (`!s. FINITE s ==> ((CARD s = 0) <=> (s = {}))`, + (`!s:A->bool. FINITE s ==> ((CARD s = 0) <=> (s = {}))`, MATCH_MP_TAC FINITE_INDUCT_STRONG THEN SIMP_TAC[CARD_CLAUSES; NOT_INSERT_EMPTY; NOT_SUC]);; @@ -2011,10 +2049,10 @@ let FINITE_INDUCT_DELETE = prove (* ------------------------------------------------------------------------- *) let HAS_SIZE = new_definition - `s HAS_SIZE n <=> FINITE s /\ (CARD s = n)`;; + `(s:A->bool) HAS_SIZE n <=> FINITE s /\ CARD s = n`;; let HAS_SIZE_CARD = prove - (`!s n. s HAS_SIZE n ==> (CARD s = n)`, + (`!(s:A->bool) n. s HAS_SIZE n ==> CARD s = n`, SIMP_TAC[HAS_SIZE]);; let HAS_SIZE_0 = prove @@ -2055,13 +2093,15 @@ let HAS_SIZE_SUC = prove ASM_MESON_TAC[]]]);; let HAS_SIZE_UNION = prove - (`!s t m n. s HAS_SIZE m /\ t HAS_SIZE n /\ DISJOINT s t - ==> (s UNION t) HAS_SIZE (m + n)`, + (`!(s:A->bool) t m n. + s HAS_SIZE m /\ t HAS_SIZE n /\ DISJOINT s t + ==> (s UNION t) HAS_SIZE (m + n)`, SIMP_TAC[HAS_SIZE; FINITE_UNION; DISJOINT; CARD_UNION]);; let HAS_SIZE_DIFF = prove - (`!s t m n. s HAS_SIZE m /\ t HAS_SIZE n /\ t SUBSET s - ==> (s DIFF t) HAS_SIZE (m - n)`, + (`!(s:A->bool) t m n. + s HAS_SIZE m /\ t HAS_SIZE n /\ t SUBSET s + ==> (s DIFF t) HAS_SIZE (m - n)`, SIMP_TAC[HAS_SIZE; FINITE_DIFF; CARD_DIFF]);; let HAS_SIZE_UNIONS = prove @@ -2093,7 +2133,7 @@ let HAS_SIZE_UNIONS = prove ASM_MESON_TAC[IN_INSERT]);; let FINITE_HAS_SIZE = prove - (`!s. FINITE s <=> s HAS_SIZE CARD s`, + (`!s:A->bool. FINITE s <=> s HAS_SIZE CARD s`, REWRITE_TAC[HAS_SIZE]);; (* ------------------------------------------------------------------------- *) @@ -2101,9 +2141,9 @@ let FINITE_HAS_SIZE = prove (* ------------------------------------------------------------------------- *) let HAS_SIZE_CLAUSES = prove - (`(s HAS_SIZE 0 <=> (s = {})) /\ + (`(s HAS_SIZE 0 <=> s = {}) /\ (s HAS_SIZE (SUC n) <=> - ?a t. t HAS_SIZE n /\ ~(a IN t) /\ (s = a INSERT t))`, + ?(a:A) t. t HAS_SIZE n /\ ~(a IN t) /\ (s = a INSERT t))`, let lemma = SET_RULE `a IN s ==> (s = a INSERT (s DELETE a))` in REWRITE_TAC[HAS_SIZE_0] THEN REPEAT STRIP_TAC THEN EQ_TAC THENL [REWRITE_TAC[HAS_SIZE_SUC; GSYM MEMBER_NOT_EMPTY] THEN @@ -2116,14 +2156,14 @@ let HAS_SIZE_CLAUSES = prove let HAS_SIZE_CONV = let pth = prove - (`(~(a IN {}) /\ P <=> P) /\ + (`(~((a:A) IN {}) /\ P <=> P) /\ (~(a IN {b}) /\ P <=> ~(a = b) /\ P) /\ (~(a IN (b INSERT cs)) /\ P <=> ~(a = b) /\ ~(a IN cs) /\ P)`, SET_TAC[]) and qth = prove (`((?s. s HAS_SIZE 0 /\ P s) <=> P {}) /\ ((?s. s HAS_SIZE (SUC n) /\ P s) <=> - (?a s. s HAS_SIZE n /\ ~(a IN s) /\ P(a INSERT s)))`, + (?(a:A) s. s HAS_SIZE n /\ ~(a IN s) /\ P(a INSERT s)))`, REWRITE_TAC[HAS_SIZE_CLAUSES] THEN MESON_TAC[]) in let qconv_0 = GEN_REWRITE_CONV I [CONJUNCT1 qth] and qconv_1 = GEN_REWRITE_CONV I [CONJUNCT2 qth] @@ -2193,11 +2233,11 @@ let CARD_SUBSET = prove ARITH_TAC]);; let CARD_SUBSET_LE = prove - (`!(a:A->bool) b. FINITE b /\ a SUBSET b /\ (CARD b <= CARD a) ==> (a = b)`, + (`!(a:A->bool) b. FINITE b /\ a SUBSET b /\ CARD b <= CARD a ==> a = b`, MESON_TAC[CARD_SUBSET; CARD_SUBSET_EQ; LE_ANTISYM]);; let SUBSET_CARD_EQ = prove - (`!s t. FINITE t /\ s SUBSET t ==> (CARD s = CARD t <=> s = t)`, + (`!s t:A->bool. FINITE t /\ s SUBSET t ==> (CARD s = CARD t <=> s = t)`, MESON_TAC[CARD_SUBSET_EQ; LE_ANTISYM; CARD_SUBSET]);; let FINITE_CARD_LE_SUBSET = prove @@ -2218,11 +2258,11 @@ let CARD_PSUBSET = prove ASM_MESON_TAC[CARD_EQ_0; MEMBER_NOT_EMPTY]);; let CARD_PSUBSET_IMP = prove - (`!a b. a SUBSET b /\ ~(CARD a = CARD b) ==> a PSUBSET b`, + (`!a b:A->bool. a SUBSET b /\ ~(CARD a = CARD b) ==> a PSUBSET b`, REWRITE_TAC[PSUBSET] THEN MESON_TAC[]);; let CARD_PSUBSET_EQ = prove - (`!a b. FINITE b /\ a SUBSET b ==> (a PSUBSET b <=> CARD a < CARD b)`, + (`!a b:A->bool. FINITE b /\ a SUBSET b ==> (a PSUBSET b <=> CARD a < CARD b)`, MESON_TAC[CARD_PSUBSET_IMP; CARD_PSUBSET; LT_REFL]);; let CARD_UNION_LE = prove @@ -2267,8 +2307,9 @@ let CARD_UNIONS_LE = prove ASM_SIMP_TAC[IN_INSERT]]);; let CARD_UNION_GEN = prove - (`!s t. FINITE s /\ FINITE t - ==> CARD(s UNION t) = (CARD(s) + CARD(t)) - CARD(s INTER t)`, + (`!s t:A->bool. + FINITE s /\ FINITE t + ==> CARD(s UNION t) = (CARD(s) + CARD(t)) - CARD(s INTER t)`, REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[SET_RULE `s UNION t = s UNION (t DIFF s)`] THEN ASM_SIMP_TAC[ARITH_RULE `x:num <= y ==> (a + y) - x = a + (y - x)`; @@ -2277,16 +2318,18 @@ let CARD_UNION_GEN = prove MATCH_MP_TAC CARD_UNION THEN ASM_SIMP_TAC[FINITE_DIFF] THEN SET_TAC[]);; let CARD_UNION_OVERLAP_EQ = prove - (`!s t. FINITE s /\ FINITE t - ==> (CARD(s UNION t) = CARD s + CARD t <=> s INTER t = {})`, + (`!s t:A->bool. + FINITE s /\ FINITE t + ==> (CARD(s UNION t) = CARD s + CARD t <=> s INTER t = {})`, REPEAT GEN_TAC THEN STRIP_TAC THEN ASM_SIMP_TAC[CARD_UNION_GEN] THEN REWRITE_TAC[ARITH_RULE `a - b = a <=> b = 0 \/ a = 0`] THEN ASM_SIMP_TAC[ADD_EQ_0; CARD_EQ_0; FINITE_INTER] THEN SET_TAC[]);; let CARD_UNION_OVERLAP = prove - (`!s t. FINITE s /\ FINITE t /\ CARD(s UNION t) < CARD(s) + CARD(t) - ==> ~(s INTER t = {})`, + (`!s t:A->bool. + FINITE s /\ FINITE t /\ CARD(s UNION t) < CARD(s) + CARD(t) + ==> ~(s INTER t = {})`, SIMP_TAC[GSYM CARD_UNION_OVERLAP_EQ] THEN ARITH_TAC);; (* ------------------------------------------------------------------------- *) @@ -2334,11 +2377,11 @@ let CARD_IMAGE_INJ_EQ = prove MATCH_MP_TAC CARD_IMAGE_INJ THEN ASM_MESON_TAC[]]);; let CARD_SUBSET_IMAGE = prove - (`!f s t. FINITE t /\ s SUBSET IMAGE f t ==> CARD s <= CARD t`, + (`!(f:A->B) s t. FINITE t /\ s SUBSET IMAGE f t ==> CARD s <= CARD t`, MESON_TAC[LE_TRANS; FINITE_IMAGE; CARD_IMAGE_LE; CARD_SUBSET]);; let HAS_SIZE_IMAGE_INJ_EQ = prove - (`!f s n. + (`!(f:A->B) s n. (!x y. x IN s /\ y IN s /\ f x = f y ==> x = y) ==> ((IMAGE f s) HAS_SIZE n <=> s HAS_SIZE n)`, REPEAT STRIP_TAC THEN REWRITE_TAC[HAS_SIZE] THEN @@ -2370,7 +2413,7 @@ let CARD_IMAGE_EQ_INJ = prove ASM SET_TAC[]);; let EXISTS_SMALL_SUBSET_IMAGE_INJ = prove - (`!P f s n. + (`!P (f:A->B) s n. (?t. FINITE t /\ CARD t < n /\ t SUBSET IMAGE f s /\ P t) <=> (?t. FINITE t /\ CARD t < n /\ t SUBSET s /\ (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) /\ @@ -2384,7 +2427,7 @@ let EXISTS_SMALL_SUBSET_IMAGE_INJ = prove MESON_TAC[CARD_IMAGE_INJ; FINITE_IMAGE_INJ_EQ]);; let FORALL_SMALL_SUBSET_IMAGE_INJ = prove - (`!P f s n. + (`!P (f:A->B) s n. (!t. FINITE t /\ CARD t < n /\ t SUBSET IMAGE f s ==> P t) <=> (!t. FINITE t /\ CARD t < n /\ t SUBSET s /\ (!x y. x IN t /\ y IN t ==> (f x = f y <=> x = y)) @@ -2394,7 +2437,7 @@ let FORALL_SMALL_SUBSET_IMAGE_INJ = prove REWRITE_TAC[NOT_IMP; EXISTS_SMALL_SUBSET_IMAGE_INJ; GSYM CONJ_ASSOC]);; let EXISTS_SMALL_SUBSET_IMAGE = prove - (`!P f s n. + (`!P (f:A->B) s n. (?t. FINITE t /\ CARD t < n /\ t SUBSET IMAGE f s /\ P t) <=> (?t. FINITE t /\ CARD t < n /\ t SUBSET s /\ P (IMAGE f t))`, @@ -2403,13 +2446,37 @@ let EXISTS_SMALL_SUBSET_IMAGE = prove MESON_TAC[FINITE_IMAGE; CARD_IMAGE_LE; LET_TRANS; IMAGE_SUBSET]]);; let FORALL_SMALL_SUBSET_IMAGE = prove - (`!P f s n. + (`!P (f:A->B) s n. (!t. FINITE t /\ CARD t < n /\ t SUBSET IMAGE f s ==> P t) <=> (!t. FINITE t /\ CARD t < n /\ t SUBSET s ==> P (IMAGE f t))`, REPEAT GEN_TAC THEN ONCE_REWRITE_TAC[MESON[] `(!t. p t) <=> ~(?t. ~p t)`] THEN REWRITE_TAC[NOT_IMP; EXISTS_SMALL_SUBSET_IMAGE; GSYM CONJ_ASSOC]);; +let CARD_IMAGE_LE2 = prove + (`!(f:A->B) (g:A->C) s. + FINITE s /\ + (!x y. x IN s /\ y IN s /\ g x = g y ==> f x = f y) + ==> CARD(IMAGE f s) <= CARD(IMAGE g s)`, + REPEAT STRIP_TAC THEN FIRST_X_ASSUM(X_CHOOSE_TAC `h:C->B` o + GEN_REWRITE_RULE I [FUNCTION_FACTORS_LEFT_GEN]) THEN + TRANS_TAC LE_TRANS `CARD(IMAGE ((h:C->B) o (g:A->C)) s)` THEN + ASM_SIMP_TAC[IMAGE_o; CARD_IMAGE_LE; FINITE_IMAGE] THEN + MATCH_MP_TAC EQ_IMP_LE THEN AP_TERM_TAC THEN ASM SET_TAC[]);; + +let CARD_IMAGE_LT2 = prove + (`!(f:A->B) (g:A->C) s. + FINITE s /\ + (!x y. x IN s /\ y IN s /\ g x = g y ==> f x = f y) /\ + ~(!x y. x IN s /\ y IN s /\ f x = f y ==> g x = g y) + ==> CARD(IMAGE f s) < CARD(IMAGE g s)`, + REPEAT STRIP_TAC THEN FIRST_X_ASSUM(X_CHOOSE_TAC `h:C->B` o + GEN_REWRITE_RULE I [FUNCTION_FACTORS_LEFT_GEN]) THEN + SUBGOAL_THEN `IMAGE f s = IMAGE (h:C->B) (IMAGE (g:A->C) s)` SUBST1_TAC THENL + [ASM SET_TAC[]; ALL_TAC] THEN + ASM_SIMP_TAC[LT_LE; CARD_IMAGE_LE; FINITE_IMAGE; CARD_IMAGE_EQ_INJ] THEN + ASM SET_TAC[]);; + (* ------------------------------------------------------------------------- *) (* Choosing a smaller subset of a given size. *) (* ------------------------------------------------------------------------- *) @@ -2616,26 +2683,27 @@ let HAS_SIZE_PRODUCT = prove parse_as_infix("CROSS",(22,"right"));; let CROSS = new_definition - `s CROSS t = {x,y | x IN s /\ y IN t}`;; + `(s:A->bool) CROSS (t:B->bool) = {x,y | x IN s /\ y IN t}`;; let IN_CROSS = prove - (`!x y s t. (x,y) IN (s CROSS t) <=> x IN s /\ y IN t`, + (`!(x:A) (y:B) s t. (x,y) IN (s CROSS t) <=> x IN s /\ y IN t`, REWRITE_TAC[CROSS; IN_ELIM_PAIR_THM]);; let HAS_SIZE_CROSS = prove - (`!s t m n. s HAS_SIZE m /\ t HAS_SIZE n ==> (s CROSS t) HAS_SIZE (m * n)`, + (`!(s:A->bool) (t:B->bool) m n. + s HAS_SIZE m /\ t HAS_SIZE n ==> (s CROSS t) HAS_SIZE (m * n)`, REWRITE_TAC[CROSS; HAS_SIZE_PRODUCT]);; let FINITE_CROSS = prove - (`!s t. FINITE s /\ FINITE t ==> FINITE(s CROSS t)`, + (`!(s:A->bool) (t:B->bool). FINITE s /\ FINITE t ==> FINITE(s CROSS t)`, SIMP_TAC[CROSS; FINITE_PRODUCT]);; let CARD_CROSS = prove - (`!s t. FINITE s /\ FINITE t ==> CARD(s CROSS t) = CARD s * CARD t`, + (`!(s:A->bool) (t:B->bool). FINITE s /\ FINITE t ==> CARD(s CROSS t) = CARD s * CARD t`, SIMP_TAC[CROSS; CARD_PRODUCT]);; let CROSS_EQ_EMPTY = prove - (`!s t. s CROSS t = {} <=> s = {} \/ t = {}`, + (`!(s:A->bool) (t:B->bool). s CROSS t = {} <=> s = {} \/ t = {}`, REWRITE_TAC[EXTENSION; FORALL_PAIR_THM; IN_CROSS; NOT_IN_EMPTY] THEN MESON_TAC[]);; @@ -2690,23 +2758,24 @@ let INFINITE_UNIV_PAIR = prove REWRITE_TAC[INFINITE_CROSS_UNIV]);; let FORALL_IN_CROSS = prove - (`!P s t. (!z. z IN s CROSS t ==> P z) <=> + (`!P s t. (!z:A#B. z IN s CROSS t ==> P z) <=> (!x y. x IN s /\ y IN t ==> P(x,y))`, REWRITE_TAC[FORALL_PAIR_THM; IN_CROSS]);; let EXISTS_IN_CROSS = prove - (`!P s t. (?z. z IN s CROSS t /\ P z) <=> + (`!P s t. (?z:A#B. z IN s CROSS t /\ P z) <=> (?x y. x IN s /\ y IN t /\ P(x,y))`, REWRITE_TAC[EXISTS_PAIR_THM; GSYM CONJ_ASSOC; IN_CROSS]);; let SUBSET_CROSS = prove - (`!s t s' t'. s CROSS t SUBSET s' CROSS t' <=> - s = {} \/ t = {} \/ s SUBSET s' /\ t SUBSET t'`, + (`!(s:A->bool) (t:B->bool) s' t'. + s CROSS t SUBSET s' CROSS t' <=> + s = {} \/ t = {} \/ s SUBSET s' /\ t SUBSET t'`, SIMP_TAC[CROSS; EXTENSION; IN_ELIM_PAIR_THM; SUBSET; FORALL_PAIR_THM; IN_CROSS; NOT_IN_EMPTY] THEN MESON_TAC[]);; let CROSS_MONO = prove - (`!s t s' t'. s SUBSET s' /\ t SUBSET t' ==> s CROSS t SUBSET s' CROSS t'`, + (`!(s:A->bool) (t:B->bool) s' t'. s SUBSET s' /\ t SUBSET t' ==> s CROSS t SUBSET s' CROSS t'`, SIMP_TAC[SUBSET_CROSS]);; let CROSS_EQ = prove @@ -2739,47 +2808,59 @@ let IMAGE_PAIRED_CROSS = prove MESON_TAC[]);; let CROSS_INTER = prove - (`(!s t u. s CROSS (t INTER u) = (s CROSS t) INTER (s CROSS u)) /\ - (!s t u. (s INTER t) CROSS u = (s CROSS u) INTER (t CROSS u))`, + (`(!(s:A->bool) (t:B->bool) u. + s CROSS (t INTER u) = (s CROSS t) INTER (s CROSS u)) /\ + (!(s:A->bool) t (u:B->bool). + (s INTER t) CROSS u = (s CROSS u) INTER (t CROSS u))`, REWRITE_TAC[EXTENSION; FORALL_PAIR_THM; IN_INTER; IN_CROSS] THEN REPEAT STRIP_TAC THEN CONV_TAC TAUT);; let CROSS_UNION = prove - (`(!s t u. s CROSS (t UNION u) = (s CROSS t) UNION (s CROSS u)) /\ - (!s t u. (s UNION t) CROSS u = (s CROSS u) UNION (t CROSS u))`, + (`(!(s:A->bool) (t:B->bool) u. + s CROSS (t UNION u) = (s CROSS t) UNION (s CROSS u)) /\ + (!(s:A->bool) t (u:B->bool). + (s UNION t) CROSS u = (s CROSS u) UNION (t CROSS u))`, REWRITE_TAC[EXTENSION; FORALL_PAIR_THM; IN_UNION; IN_CROSS] THEN REPEAT STRIP_TAC THEN CONV_TAC TAUT);; let CROSS_DIFF = prove - (`(!s t u. s CROSS (t DIFF u) = (s CROSS t) DIFF (s CROSS u)) /\ - (!s t u. (s DIFF t) CROSS u = (s CROSS u) DIFF (t CROSS u))`, + (`(!(s:A->bool) (t:B->bool) u. + s CROSS (t DIFF u) = (s CROSS t) DIFF (s CROSS u)) /\ + (!(s:A->bool) t (u:B->bool). + (s DIFF t) CROSS u = (s CROSS u) DIFF (t CROSS u))`, REWRITE_TAC[EXTENSION; FORALL_PAIR_THM; IN_DIFF; IN_CROSS] THEN REPEAT STRIP_TAC THEN CONV_TAC TAUT);; let INTER_CROSS = prove - (`!s s' t t'. + (`!(s:A->bool) s' (t:B->bool) t'. (s CROSS t) INTER (s' CROSS t') = (s INTER s') CROSS (t INTER t')`, REWRITE_TAC[EXTENSION; IN_INTER; FORALL_PAIR_THM; IN_CROSS] THEN CONV_TAC TAUT);; let CROSS_UNIONS_UNIONS,CROSS_UNIONS = (CONJ_PAIR o prove) - (`(!f g. (UNIONS f) CROSS (UNIONS g) = - UNIONS {s CROSS t | s IN f /\ t IN g}) /\ - (!s f. s CROSS (UNIONS f) = UNIONS {s CROSS t | t IN f}) /\ - (!f t. (UNIONS f) CROSS t = UNIONS {s CROSS t | s IN f})`, + (`(!(f:(A->bool)->bool) (g:(B->bool)->bool). + (UNIONS f) CROSS (UNIONS g) = + UNIONS {s CROSS t | s IN f /\ t IN g}) /\ + (!(s:A->bool) (f:(A->bool)->bool). + s CROSS (UNIONS f) = UNIONS {s CROSS t | t IN f}) /\ + (!(f:(A->bool)->bool) (t:B->bool). + (UNIONS f) CROSS t = UNIONS {s CROSS t | s IN f})`, REWRITE_TAC[UNIONS_GSPEC; EXTENSION; FORALL_PAIR_THM; IN_ELIM_THM; IN_CROSS] THEN SET_TAC[]);; let CROSS_INTERS_INTERS,CROSS_INTERS = (CONJ_PAIR o prove) - (`(!f g. (INTERS f) CROSS (INTERS g) = - if f = {} then INTERS {UNIV CROSS t | t IN g} - else if g = {} then INTERS {s CROSS UNIV | s IN f} - else INTERS {s CROSS t | s IN f /\ t IN g}) /\ - (!s f. s CROSS (INTERS f) = - if f = {} then s CROSS UNIV else INTERS {s CROSS t | t IN f}) /\ - (!f t. (INTERS f) CROSS t = - if f = {} then UNIV CROSS t else INTERS {s CROSS t | s IN f})`, + (`(!(f:(A->bool)->bool) (g:(B->bool)->bool). + (INTERS f) CROSS (INTERS g) = + if f = {} then INTERS {UNIV CROSS t | t IN g} + else if g = {} then INTERS {s CROSS UNIV | s IN f} + else INTERS {s CROSS t | s IN f /\ t IN g}) /\ + (!(s:A->bool) (f:(A->bool)->bool). + s CROSS (INTERS f) = + if f = {} then s CROSS UNIV else INTERS {s CROSS t | t IN f}) /\ + (!(f:(A->bool)->bool) (t:B->bool). + (INTERS f) CROSS t = + if f = {} then UNIV CROSS t else INTERS {s CROSS t | s IN f})`, REPEAT STRIP_TAC THEN REPEAT (COND_CASES_TAC THEN REWRITE_TAC[]) THEN ASM_REWRITE_TAC[INTERS_GSPEC; EXTENSION; FORALL_PAIR_THM; IN_ELIM_THM; IN_CROSS; NOT_IN_EMPTY] THEN @@ -2817,7 +2898,7 @@ let EXTENSIONAL_EMPTY = prove REWRITE_TAC[FUN_EQ_THM]);; let EXTENSIONAL_UNIV = prove - (`!f. EXTENSIONAL (:A) f`, + (`!f:A->B. EXTENSIONAL (:A) f`, REWRITE_TAC[EXTENSIONAL; IN_UNIV; IN_ELIM_THM]);; let EXTENSIONAL_EQ = prove @@ -2964,7 +3045,7 @@ let CARTESIAN_PRODUCT_EQ_EMPTY = prove REWRITE_TAC[EXTENSIONAL; IN_ELIM_THM] THEN SIMP_TAC[]);; let CARTESIAN_PRODUCT_EMPTY = prove - (`!s. cartesian_product {} s = {(\i. ARB)}`, + (`!(s:K->A->bool). cartesian_product {} s = {(\i. ARB)}`, REWRITE_TAC[CARTESIAN_PRODUCT; NOT_IN_EMPTY; EXTENSION] THEN REWRITE_TAC[IN_ELIM_THM; IN_SING] THEN REWRITE_TAC[FUN_EQ_THM]);; @@ -2978,7 +3059,7 @@ let CARTESIAN_PRODUCT_EQ_MEMBERS = prove EXISTS_TAC `k:K->bool` THEN ASM_REWRITE_TAC[IN]);; let CARTESIAN_PRODUCT_EQ_MEMBERS_EQ = prove - (`!k s x y. + (`!k s x y:K->A. x IN cartesian_product k s /\ y IN cartesian_product k s ==> (x = y <=> !i. i IN k ==> x i = y i)`, @@ -3039,7 +3120,7 @@ let CARTESIAN_PRODUCT_SINGS = prove REWRITE_TAC[FUN_EQ_THM] THEN MESON_TAC[]);; let CARTESIAN_PRODUCT_SINGS_GEN = prove - (`!k x. cartesian_product k (\i. {x i}) = {RESTRICTION k x}`, + (`!k (x:K->A). cartesian_product k (\i. {x i}) = {RESTRICTION k x}`, REWRITE_TAC[cartesian_product; IN_SING] THEN REWRITE_TAC[EXTENSION; EXTENSIONAL; IN_ELIM_THM; IN_SING] THEN REWRITE_TAC[FUN_EQ_THM; RESTRICTION] THEN MESON_TAC[]);; @@ -3086,7 +3167,7 @@ let FORALL_CARTESIAN_PRODUCT_ELEMENTS = prove ASM_REWRITE_TAC[EXTENSIONAL; IN_ELIM_THM] THEN ASM_MESON_TAC[]);; let FORALL_CARTESIAN_PRODUCT_ELEMENTS_EQ = prove - (`!P k s. + (`!P k (s:K->A->bool). ~(cartesian_product k s = {}) ==> ((!i x. i IN k /\ x IN s i ==> P i x) <=> !z i. z IN cartesian_product k s /\ i IN k ==> P i (z i))`, @@ -3237,15 +3318,15 @@ let HAS_SIZE_FUNSPACE = prove let CARD_FUNSPACE = prove (`!s t. FINITE s /\ FINITE t - ==> (CARD {f | (!x. x IN s ==> f(x) IN t) /\ - (!x. ~(x IN s) ==> (f x = d))} = - (CARD t) EXP (CARD s))`, + ==> (CARD {f:A->B | (!x. x IN s ==> f(x) IN t) /\ + (!x. ~(x IN s) ==> (f x = d))} = + (CARD t) EXP (CARD s))`, MESON_TAC[HAS_SIZE_FUNSPACE; HAS_SIZE]);; let FINITE_FUNSPACE = prove (`!s t. FINITE s /\ FINITE t - ==> FINITE {f | (!x. x IN s ==> f(x) IN t) /\ - (!x. ~(x IN s) ==> (f x = d))}`, + ==> FINITE {f:A->B | (!x. x IN s ==> f(x) IN t) /\ + (!x. ~(x IN s) ==> (f x = d))}`, MESON_TAC[HAS_SIZE_FUNSPACE; HAS_SIZE]);; let HAS_SIZE_FUNSPACE_UNIV = prove @@ -3343,7 +3424,7 @@ let FINITE_CARD_LE_UNIONS = prove MATCH_MP_TAC CARD_UNIONS_LE THEN ASM_REWRITE_TAC[HAS_SIZE]);; let POWERSET_CLAUSES = prove - (`{s | s SUBSET {}} = {{}} /\ + (`{s:A->bool | s SUBSET {}} = {{}} /\ (!a:A t. {s | s SUBSET (a INSERT t)} = {s | s SUBSET t} UNION IMAGE (\s. a INSERT s) {s | s SUBSET t})`, REWRITE_TAC[SUBSET_INSERT_DELETE; SUBSET_EMPTY; SING_GSPEC] THEN @@ -3658,7 +3739,7 @@ let set_of_list = new_recursive_definition list_RECURSION (set_of_list (CONS (h:A) t) = h INSERT (set_of_list t))`;; let list_of_set = new_definition - `list_of_set s = @l. (set_of_list l = s) /\ (LENGTH l = CARD s)`;; + `list_of_set s = @l:A list. set_of_list l = s /\ LENGTH l = CARD s`;; let LIST_OF_SET_PROPERTIES = prove (`!s:A->bool. FINITE(s) @@ -3675,11 +3756,11 @@ let LIST_OF_SET_PROPERTIES = prove ASM_REWRITE_TAC[]]);; let SET_OF_LIST_OF_SET = prove - (`!s. FINITE(s) ==> (set_of_list(list_of_set s) = s)`, + (`!s:A->bool. FINITE(s) ==> (set_of_list(list_of_set s) = s)`, MESON_TAC[LIST_OF_SET_PROPERTIES]);; let LENGTH_LIST_OF_SET = prove - (`!s. FINITE(s) ==> (LENGTH(list_of_set s) = CARD s)`, + (`!s:A->bool. FINITE(s) ==> (LENGTH(list_of_set s) = CARD s)`, MESON_TAC[LIST_OF_SET_PROPERTIES]);; let MEM_LIST_OF_SET = prove @@ -3692,31 +3773,32 @@ let MEM_LIST_OF_SET = prove ASM_REWRITE_TAC[IN_INSERT]);; let FINITE_SET_OF_LIST = prove - (`!l. FINITE(set_of_list l)`, + (`!l:A list. FINITE(set_of_list l)`, LIST_INDUCT_TAC THEN ASM_SIMP_TAC[set_of_list; FINITE_RULES]);; let IN_SET_OF_LIST = prove - (`!x l. x IN (set_of_list l) <=> MEM x l`, + (`!x l:A list. x IN (set_of_list l) <=> MEM x l`, GEN_TAC THEN LIST_INDUCT_TAC THEN REWRITE_TAC[IN_INSERT; NOT_IN_EMPTY; MEM; set_of_list] THEN ASM_MESON_TAC[]);; let SET_OF_LIST_APPEND = prove - (`!l1 l2. set_of_list(APPEND l1 l2) = set_of_list(l1) UNION set_of_list(l2)`, + (`!l1 l2:A list. + set_of_list(APPEND l1 l2) = set_of_list(l1) UNION set_of_list(l2)`, REWRITE_TAC[EXTENSION; IN_SET_OF_LIST; IN_UNION; MEM_APPEND]);; let SET_OF_LIST_MAP = prove - (`!f l. set_of_list(MAP f l) = IMAGE f (set_of_list l)`, + (`!(f:A->B) l. set_of_list(MAP f l) = IMAGE f (set_of_list l)`, GEN_TAC THEN LIST_INDUCT_TAC THEN ASM_REWRITE_TAC[set_of_list; MAP; IMAGE_CLAUSES]);; let SET_OF_LIST_EQ_EMPTY = prove - (`!l. set_of_list l = {} <=> l = []`, + (`!l:A list. set_of_list l = {} <=> l = []`, LIST_INDUCT_TAC THEN REWRITE_TAC[set_of_list; NOT_CONS_NIL; NOT_INSERT_EMPTY]);; let LIST_OF_SET_EMPTY = prove - (`list_of_set {} = []`, + (`list_of_set {}:A list = []`, REWRITE_TAC[GSYM LENGTH_EQ_NIL] THEN SIMP_TAC[LENGTH_LIST_OF_SET; FINITE_EMPTY; CARD_CLAUSES]);; @@ -3757,14 +3839,14 @@ let mk_fset l = mk_setenum(l,type_of(hd l));; (* ------------------------------------------------------------------------- *) let pairwise = new_definition - `pairwise r s <=> !x y. x IN s /\ y IN s /\ ~(x = y) ==> r x y`;; + `pairwise r (s:A->bool) <=> !x y. x IN s /\ y IN s /\ ~(x = y) ==> r x y`;; let PAIRWISE_EMPTY = prove - (`!r. pairwise r {} <=> T`, + (`!r:A->A->bool. pairwise r {} <=> T`, REWRITE_TAC[pairwise; NOT_IN_EMPTY] THEN MESON_TAC[]);; let PAIRWISE_SING = prove - (`!r x. pairwise r {x} <=> T`, + (`!r x:A. pairwise r {x} <=> T`, REWRITE_TAC[pairwise; IN_SING] THEN MESON_TAC[]);; let PAIRWISE_IMP = prove @@ -3775,18 +3857,18 @@ let PAIRWISE_IMP = prove REWRITE_TAC[pairwise] THEN SET_TAC[]);; let PAIRWISE_MONO = prove - (`!r s t. pairwise r s /\ t SUBSET s ==> pairwise r t`, + (`!(r:A->A->bool) s t. pairwise r s /\ t SUBSET s ==> pairwise r t`, REWRITE_TAC[pairwise] THEN SET_TAC[]);; let PAIRWISE_AND = prove (`!R R' s. pairwise R s /\ pairwise R' s <=> - pairwise (\x y. R x y /\ R' x y) s`, + pairwise (\x y:A. R x y /\ R' x y) s`, REWRITE_TAC[pairwise] THEN SET_TAC[]);; let PAIRWISE_INSERT = prove (`!r x s. pairwise r (x INSERT s) <=> - (!y. y IN s /\ ~(y = x) ==> r x y /\ r y x) /\ + (!y:A. y IN s /\ ~(y = x) ==> r x y /\ r y x) /\ pairwise r s`, REWRITE_TAC[pairwise; IN_INSERT] THEN MESON_TAC[]);; @@ -3798,14 +3880,15 @@ let PAIRWISE_INSERT_SYMMETRIC = prove REWRITE_TAC[PAIRWISE_INSERT] THEN MESON_TAC[]);; let PAIRWISE_IMAGE = prove - (`!r f. pairwise r (IMAGE f s) <=> - pairwise (\x y. ~(f x = f y) ==> r (f x) (f y)) s`, + (`!r (f:A->B). + pairwise r (IMAGE f s) <=> + pairwise (\x y. ~(f x = f y) ==> r (f x) (f y)) s`, REWRITE_TAC[pairwise; IN_IMAGE] THEN MESON_TAC[]);; let PAIRWISE_UNION = prove (`!R s t. pairwise R (s UNION t) <=> pairwise R s /\ pairwise R t /\ - (!x y. x IN s DIFF t /\ y IN t DIFF s ==> R x y /\ R y x)`, + (!x y:A. x IN s DIFF t /\ y IN t DIFF s ==> R x y /\ R y x)`, REWRITE_TAC[pairwise] THEN SET_TAC[]);; let PAIRWISE_CHAIN_UNIONS = prove @@ -3895,12 +3978,12 @@ let INTERSECTION_OF_MONO = prove REWRITE_TAC[INTERSECTION_OF] THEN MESON_TAC[]);; let FORALL_UNION_OF = prove - (`(!s. (P UNION_OF Q) s ==> R s) <=> + (`(!s:A->bool. (P UNION_OF Q) s ==> R s) <=> (!t. P t /\ (!c. c IN t ==> Q c) ==> R(UNIONS t))`, REWRITE_TAC[UNION_OF] THEN MESON_TAC[]);; let FORALL_INTERSECTION_OF = prove - (`(!s. (P INTERSECTION_OF Q) s ==> R s) <=> + (`(!s:A->bool. (P INTERSECTION_OF Q) s ==> R s) <=> (!t. P t /\ (!c. c IN t ==> Q c) ==> R(INTERS t))`, REWRITE_TAC[INTERSECTION_OF] THEN MESON_TAC[]);; @@ -4005,8 +4088,9 @@ let ARBITRARY_UNION_OF_UNIONS = prove EXISTS_TAC `u:(A->bool)->bool` THEN ASM_REWRITE_TAC[ARBITRARY]);; let ARBITRARY_UNION_OF_UNION = prove - (`!P s t. (ARBITRARY UNION_OF P) s /\ (ARBITRARY UNION_OF P) t - ==> (ARBITRARY UNION_OF P) (s UNION t)`, + (`!P s t:A->bool. + (ARBITRARY UNION_OF P) s /\ (ARBITRARY UNION_OF P) t + ==> (ARBITRARY UNION_OF P) (s UNION t)`, REPEAT STRIP_TAC THEN REWRITE_TAC[GSYM UNIONS_2] THEN MATCH_MP_TAC ARBITRARY_UNION_OF_UNIONS THEN ASM_REWRITE_TAC[ARBITRARY; FORALL_IN_INSERT] THEN @@ -4022,8 +4106,9 @@ let ARBITRARY_INTERSECTION_OF_INTERS = prove EXISTS_TAC `u:(A->bool)->bool` THEN ASM_REWRITE_TAC[ARBITRARY]);; let ARBITRARY_INTERSECTION_OF_INTER = prove - (`!P s t. (ARBITRARY INTERSECTION_OF P) s /\ (ARBITRARY INTERSECTION_OF P) t - ==> (ARBITRARY INTERSECTION_OF P) (s INTER t)`, + (`!P s t:A->bool. + (ARBITRARY INTERSECTION_OF P) s /\ (ARBITRARY INTERSECTION_OF P) t + ==> (ARBITRARY INTERSECTION_OF P) (s INTER t)`, REPEAT STRIP_TAC THEN REWRITE_TAC[GSYM INTERS_2] THEN MATCH_MP_TAC ARBITRARY_INTERSECTION_OF_INTERS THEN ASM_REWRITE_TAC[ARBITRARY; FORALL_IN_INSERT] THEN @@ -4148,8 +4233,9 @@ let FINITE_UNION_OF_UNIONS = prove EXISTS_TAC `u:(A->bool)->bool` THEN ASM_REWRITE_TAC[]);; let FINITE_UNION_OF_UNION = prove - (`!P s t. (FINITE UNION_OF P) s /\ (FINITE UNION_OF P) t - ==> (FINITE UNION_OF P) (s UNION t)`, + (`!P s t:A->bool. + (FINITE UNION_OF P) s /\ (FINITE UNION_OF P) t + ==> (FINITE UNION_OF P) (s UNION t)`, REPEAT STRIP_TAC THEN REWRITE_TAC[GSYM UNIONS_2] THEN MATCH_MP_TAC FINITE_UNION_OF_UNIONS THEN ASM_REWRITE_TAC[FINITE_INSERT; FORALL_IN_INSERT] THEN @@ -4165,8 +4251,9 @@ let FINITE_INTERSECTION_OF_INTERS = prove EXISTS_TAC `u:(A->bool)->bool` THEN ASM_REWRITE_TAC[]);; let FINITE_INTERSECTION_OF_INTER = prove - (`!P s t. (FINITE INTERSECTION_OF P) s /\ (FINITE INTERSECTION_OF P) t - ==> (FINITE INTERSECTION_OF P) (s INTER t)`, + (`!P s t:A->bool. + (FINITE INTERSECTION_OF P) s /\ (FINITE INTERSECTION_OF P) t + ==> (FINITE INTERSECTION_OF P) (s INTER t)`, REPEAT STRIP_TAC THEN REWRITE_TAC[GSYM INTERS_2] THEN MATCH_MP_TAC FINITE_INTERSECTION_OF_INTERS THEN ASM_REWRITE_TAC[FINITE_INSERT; FORALL_IN_INSERT] THEN @@ -4226,13 +4313,13 @@ let FINITE_INTERSECTION_OF_UNION = prove (* ------------------------------------------------------------------------- *) let CARD_SET_OF_LIST_LE = prove - (`!l. CARD(set_of_list l) <= LENGTH l`, + (`!l:A list. CARD(set_of_list l) <= LENGTH l`, LIST_INDUCT_TAC THEN SIMP_TAC[LENGTH; set_of_list; CARD_CLAUSES; FINITE_SET_OF_LIST] THEN ASM_ARITH_TAC);; let HAS_SIZE_SET_OF_LIST = prove - (`!l. (set_of_list l) HAS_SIZE (LENGTH l) <=> PAIRWISE (\x y. ~(x = y)) l`, + (`!l. (set_of_list l) HAS_SIZE (LENGTH l) <=> PAIRWISE (\x y:A. ~(x = y)) l`, REWRITE_TAC[HAS_SIZE; FINITE_SET_OF_LIST] THEN LIST_INDUCT_TAC THEN ASM_SIMP_TAC[CARD_CLAUSES; LENGTH; set_of_list; PAIRWISE; ALL; FINITE_SET_OF_LIST; GSYM ALL_MEM; IN_SET_OF_LIST] THEN @@ -4281,8 +4368,9 @@ let IMAGE_IMP_INJECTIVE_GEN = prove ASM_MESON_TAC[EXTENSION; IN_IMAGE]);; let IMAGE_IMP_INJECTIVE = prove - (`!s f. FINITE s /\ (IMAGE f s = s) - ==> !x y. x IN s /\ y IN s /\ (f x = f y) ==> (x = y)`, + (`!s f:A->A. + FINITE s /\ IMAGE f s = s + ==> !x y. x IN s /\ y IN s /\ f x = f y ==> x = y`, MESON_TAC[IMAGE_IMP_INJECTIVE_GEN]);; let HAS_SIZE_IMAGE_INJ_RESTRICT = prove @@ -4332,13 +4420,13 @@ let CARD_LE_INJ = prove (* ------------------------------------------------------------------------- *) let FORALL_IN_CLAUSES = prove - (`(!P. (!x. x IN {} ==> P x) <=> T) /\ - (!P a s. (!x. x IN (a INSERT s) ==> P x) <=> P a /\ (!x. x IN s ==> P x))`, + (`(!P. (!x:A. x IN {} ==> P x) <=> T) /\ + (!P a s. (!x:A. x IN (a INSERT s) ==> P x) <=> P a /\ (!x. x IN s ==> P x))`, REWRITE_TAC[IN_INSERT; NOT_IN_EMPTY] THEN MESON_TAC[]);; let EXISTS_IN_CLAUSES = prove - (`(!P. (?x. x IN {} /\ P x) <=> F) /\ - (!P a s. (?x. x IN (a INSERT s) /\ P x) <=> P a \/ (?x. x IN s /\ P x))`, + (`(!P. (?x:A. x IN {} /\ P x) <=> F) /\ + (!P a s. (?x:A. x IN (a INSERT s) /\ P x) <=> P a \/ (?x. x IN s /\ P x))`, REWRITE_TAC[IN_INSERT; NOT_IN_EMPTY] THEN MESON_TAC[]);; (* ------------------------------------------------------------------------- *) @@ -4522,34 +4610,36 @@ let WF_PSUBSET = prove (* ------------------------------------------------------------------------- *) let le_c = new_definition - `s <=_c t <=> ?f. (!x. x IN s ==> f(x) IN t) /\ - (!x y. x IN s /\ y IN s /\ (f(x) = f(y)) ==> (x = y))`;; + `s <=_c t <=> + ?f:A->B. (!x. x IN s ==> f(x) IN t) /\ + (!x y. x IN s /\ y IN s /\ f(x) = f(y) ==> x = y)`;; let lt_c = new_definition - `s <_c t <=> s <=_c t /\ ~(t <=_c s)`;; + `(s:A->bool) <_c (t:B->bool) <=> s <=_c t /\ ~(t <=_c s)`;; let eq_c = new_definition - `s =_c t <=> ?f. (!x. x IN s ==> f(x) IN t) /\ - !y. y IN t ==> ?!x. x IN s /\ (f x = y)`;; + `(s:A->bool) =_c (t:B->bool) <=> + ?f. (!x. x IN s ==> f(x) IN t) /\ + !y. y IN t ==> ?!x. x IN s /\ (f x = y)`;; let ge_c = new_definition - `s >=_c t <=> t <=_c s`;; + `(s:A->bool) >=_c (t:B->bool) <=> t <=_c s`;; let gt_c = new_definition - `s >_c t <=> t <_c s`;; + `(s:A->bool) >_c (t:B->bool) <=> t <_c s`;; let LE_C = prove - (`!s t. s <=_c t <=> ?g. !x. x IN s ==> ?y. y IN t /\ (g y = x)`, + (`!s t. s <=_c t <=> ?g:A->B. !x. x IN s ==> ?y. y IN t /\ g y = x`, REWRITE_TAC[le_c; INJECTIVE_ON_LEFT_INVERSE; SURJECTIVE_ON_RIGHT_INVERSE; RIGHT_IMP_EXISTS_THM; SKOLEM_THM; RIGHT_AND_EXISTS_THM] THEN MESON_TAC[]);; let GE_C = prove - (`!s t. s >=_c t <=> ?f. !y. y IN t ==> ?x. x IN s /\ (y = f x)`, + (`!s t. s >=_c t <=> ?f:A->B. !y. y IN t ==> ?x. x IN s /\ (y = f x)`, REWRITE_TAC[ge_c; LE_C] THEN MESON_TAC[]);; let COUNTABLE = new_definition - `COUNTABLE t <=> (:num) >=_c t`;; + `COUNTABLE (t:A->bool) <=> (:num) >=_c t`;; (* ------------------------------------------------------------------------- *) (* Supremum and infimum. *) diff --git a/theorems.ml b/theorems.ml old mode 100644 new mode 100755 index 99f8eb6b..d84449f5 --- a/theorems.ml +++ b/theorems.ml @@ -222,7 +222,7 @@ let FORALL_UNWIND_THM2 = prove ASM_REWRITE_TAC[]]);; let FORALL_UNWIND_THM1 = prove - (`!P a. (!x. a = x ==> P x) <=> P a`, + (`!P (a:A). (!x. a = x ==> P x) <=> P a`, REPEAT GEN_TAC THEN CONV_TAC(LAND_CONV(ONCE_DEPTH_CONV SYM_CONV)) THEN MATCH_ACCEPT_TAC FORALL_UNWIND_THM2);; @@ -377,7 +377,7 @@ let WLOG_RELATION = prove (`!R P. (!x y. P x y ==> P y x) /\ (!x y. R x y \/ R y x) /\ (!x y. R x y ==> P x y) - ==> !x y. P x y`, + ==> !x y:A. P x y`, REPEAT GEN_TAC THEN DISCH_THEN (CONJUNCTS_THEN2 ASSUME_TAC (CONJUNCTS_THEN2 MP_TAC ASSUME_TAC)) THEN REPEAT(MATCH_MP_TAC MONO_FORALL THEN GEN_TAC) THEN diff --git a/wf.ml b/wf.ml index 82e3eb1f..5a5b9ad3 100644 --- a/wf.ml +++ b/wf.ml @@ -255,7 +255,7 @@ let WF_REC_num = prove (* ------------------------------------------------------------------------- *) let MEASURE = new_definition - `MEASURE m = \x y. m(x) < m(y)`;; + `MEASURE (m:A->num) = \x y. m(x) < m(y)`;; let WF_MEASURE = prove (`!m:A->num. WF(MEASURE m)`, @@ -264,8 +264,8 @@ let WF_MEASURE = prove MATCH_ACCEPT_TAC WF_num);; let MEASURE_LE = prove - (`(!y. MEASURE m y a ==> MEASURE m y b) <=> m(a) <= m(b)`, - REWRITE_TAC[MEASURE] THEN MESON_TAC[NOT_LE; LTE_TRANS; LT_REFL]);; + (`!m:A->num. (!y. MEASURE m y a ==> MEASURE m y b) <=> m(a) <= m(b)`, + REWRITE_TAC[MEASURE] THEN MESON_TAC[NOT_LE; LTE_TRANS; LT_REFL]);; (* ------------------------------------------------------------------------- *) (* Trivially, a WF relation is irreflexive and antisymmetric. *)