/usr/share/hol88-2.02.19940316/contrib/aci/aci.ml is in hol88-contrib-source 2.02.19940316-35.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | %=============================================================================
FILE: aci.ml
DESCIPTION: Generalizing an associative and commutative operation with
identity to finite sets.
AUTHOR: Ching-Tsun Chou
LAST CHANGED: Tue Oct 6 14:56:08 PDT 1992
=============================================================================%
new_theory `aci` ;;
%-----------------------------------------------------------------------------
Need the new `pred_sets` library by Tom Melham.
-----------------------------------------------------------------------------%
load_library `pred_sets` ;;
%-----------------------------------------------------------------------------
Miscellaneous ML functions.
-----------------------------------------------------------------------------%
let sing x = [x] ;;
%-----------------------------------------------------------------------------
(Stolen from Brian Graham.)
-----------------------------------------------------------------------------%
let SELECT_UNIQUE_RULE (x,y) th1 th2 =
let Q = mk_abs (x, subst [x,y] (concl th1))
in
let th1' = SUBST [SYM (BETA_CONV "^Q ^y"), "b:bool"] "b:bool" th1
in
( MP (SPECL ["$@ ^Q"; y] th2)
(CONJ (CONV_RULE BETA_CONV (SELECT_INTRO th1')) th1) )
;;
let SELECT_UNIQUE_TAC:tactic (gl,g) =
let Q,y = dest_eq g
in
let x,Qx = dest_select Q
in
let x' = variant (x.freesl(g.gl))x
in
let Qx' = subst [x', x] Qx
in
([gl,subst [y,x]Qx;
gl, "!^x ^x'. (^Qx /\ ^Qx') ==> (^x = ^x')"],
(\thl. SELECT_UNIQUE_RULE (x,y) (hd thl) (hd (tl thl))))
;;
%-----------------------------------------------------------------------------
"ASSOC_COMM_ID_DEF op id" holds iff "op" is an associative and commutative
operation with identity "id".
-----------------------------------------------------------------------------%
let ASSOC_COMM_ID_DEF = new_definition(`ASSOC_COMM_ID_DEF`,
"
ASSOC_COMM_ID (op : ** -> ** -> **) (id : **) =
( ! a b c . (op a (op b c)) = (op (op a b) c) ) /\
( ! a b . (op a b) = (op b a) ) /\
( ! a . (op a id) = a )
");;
%-----------------------------------------------------------------------------
The following is based on ideas stolen from Tom Melham's definition
of cardinality ("CARD") in the library "pred_sets".
-----------------------------------------------------------------------------%
let REL = " REL : (** -> ** -> **) -> ** -> (* -> **) -> (* -> bool) -> **
-> num -> bool " ;;
%-----------------------------------------------------------------------------
"REL op id f s a n" holds iff set s has cardinality n and doing
operation op on f(x)'s with x ranging over s has result a,
where a = id if s = { }.
-----------------------------------------------------------------------------%
let ACI_REL_DEF =
"
( ! op id f s a . ^REL op id f s a 0 = (s = { }) /\ (a = id) ) /\
( ! op id f s a n . ^REL op id f s a (SUC n) =
? x b . x IN s /\ ^REL op id f (s DELETE x) b n /\ (a = op (f x) b) )
" ;;
%-----------------------------------------------------------------------------
Prove that relation "REL", as recursively defined above, exists.
-----------------------------------------------------------------------------%
let ACI_REL_EXISTS = prove_rec_fn_exists num_Axiom ACI_REL_DEF ;;
%-----------------------------------------------------------------------------
All lemmas below about "REL" assume "ASSOC_COMM_ID op id".
-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------
"REL op id f s a 1" holds iff s = {x} and a = f(x) for some x.
-----------------------------------------------------------------------------%
let ACI_REL_1_LEMMA = PROVE(
"
^ACI_REL_DEF ==>
! op id . ASSOC_COMM_ID op id ==>
! f s a . ^REL op id f s a (SUC 0) = ? x . (s = {x}) /\ (a = f x)
" , (
DISCH_THEN \ ACI_REL_asm .
REPEAT GEN_TAC THEN
DISCH_THEN \ ASSOC_COMM_ID_asm .
let [_; _; ID_asm] =
(CONJUNCTS o PURE_ONCE_REWRITE_RULE [ASSOC_COMM_ID_DEF])
ASSOC_COMM_ID_asm
in
REPEAT GEN_TAC THEN
PURE_REWRITE_TAC [ACI_REL_asm] THEN
EQ_TAC THEN
REPEAT STRIP_TAC THEN
EXISTS_TAC "x : *" THENL
[ IMP_RES_TAC DELETE_EQ_SING THEN
ASM_REWRITE_TAC [ID_asm]
;
EXISTS_TAC "id : **" THEN
ASM_REWRITE_TAC [ID_asm; IN_SING; SING_DELETE] ]
) ) ;;
%-----------------------------------------------------------------------------
If "REL op id f s a (SUC n)" holds, then it does not matter which element
of s to delete in the recursive definition of "REL".
-----------------------------------------------------------------------------%
let ACI_REL_SUC_LEMMA = PROVE(
"
^ACI_REL_DEF ==>
! op id . ASSOC_COMM_ID op id ==>
! n f s a . ^REL op id f s a (SUC n) ==>
! x . x IN s ==>
? b . ^REL op id f (s DELETE x) b n /\ (a = op (f x) b)
" , (
DISCH_THEN \ ACI_REL_asm .
REPEAT GEN_TAC THEN
DISCH_THEN \ ASSOC_COMM_ID_asm .
let [ASSOC_asm; COMM_asm; ID_asm] =
(CONJUNCTS o PURE_ONCE_REWRITE_RULE [ASSOC_COMM_ID_DEF])
ASSOC_COMM_ID_asm
and SING_lemma =
itlist (C MATCH_MP) [ASSOC_COMM_ID_asm; ACI_REL_asm]
ACI_REL_1_LEMMA
in
INDUCT_TAC THENL
[ PURE_REWRITE_TAC [SING_lemma; CONJUNCT1 ACI_REL_asm] THEN
REPEAT (FILTER_STRIP_TAC "IN : * -> (* -> bool) -> bool") THEN
ASM_REWRITE_TAC [IN_SING] THEN
DISCH_TAC THEN
EXISTS_TAC "id : **" THEN
ASM_REWRITE_TAC [ID_asm; SING_DELETE]
;
REPEAT GEN_TAC THEN
GEN_REWRITE_TAC (RATOR_CONV o ONCE_DEPTH_CONV)
[ ] [ACI_REL_asm] THEN
REPEAT STRIP_TAC THEN
ASM_CASES_TAC "x' = x : *" THENL
[ EXISTS_TAC "b : **" THEN
ASM_REWRITE_TAC [ ]
;
FIRST_ASSUM (ASSUME_TAC o NOT_EQ_SYM) THEN
IMP_RES_TAC IN_DELETE THEN
RES_TAC THEN
EXISTS_TAC "(op : ** -> ** -> **) (f (x : *)) b'" THEN
CONJ_TAC THENL
[ PURE_REWRITE_TAC [ACI_REL_asm] THEN
EXISTS_TAC "x : *" THEN
EXISTS_TAC "b' : **" THEN
PURE_ONCE_REWRITE_TAC [DELETE_COMM] THEN
ASM_REWRITE_TAC [ ]
;
ASM_REWRITE_TAC [ ] THEN
CONV_TAC (AC_CONV (ASSOC_asm, COMM_asm)) ] ] ]
) ) ;;
%-----------------------------------------------------------------------------
Therefore, for any (op, id, f, s), there is at most one pair (a, n)
such that "REL op id f s a n" holds.
-----------------------------------------------------------------------------%
let ACI_REL_UNIQUE_LEMMA = PROVE(
"
^ACI_REL_DEF ==>
! op id . ASSOC_COMM_ID op id ==>
! n1 n2 f s a1 a2 . ^REL op id f s a1 n1 ==>
^REL op id f s a2 n2 ==> (a1 = a2) /\ (n1 = n2)
" , (
REPEAT (FILTER_STRIP_TAC "n1 : num") THEN
INDUCT_TAC THEN
INDUCT_TAC THENL
[ PURE_ASM_REWRITE_TAC [ ] THEN REPEAT STRIP_TAC THEN
ASM_REWRITE_TAC [ ]
;
PURE_ASM_REWRITE_TAC [ ] THEN REPEAT STRIP_TAC THEN
IMP_RES_TAC MEMBER_NOT_EMPTY
;
PURE_ASM_REWRITE_TAC [ ] THEN REPEAT STRIP_TAC THEN
IMP_RES_TAC MEMBER_NOT_EMPTY
;
REPEAT GEN_TAC THEN
DISCH_TAC THEN
PURE_ASM_REWRITE_TAC [ ] THEN
STRIP_TAC THEN
IMP_RES_TAC ACI_REL_SUC_LEMMA THEN
RES_TAC THEN
FILTER_ASM_REWRITE_TAC
( let op = "op : ** -> ** -> **" and f = "f : * -> **"
in
C mem ["a1 = ^op(^f x)b'"; "a2 = ^op(^f x)b";
"b' = b : **"; "n1 = n2 : num"]
) [ ] ]
) ) ;;
%-----------------------------------------------------------------------------
Furthermore, if s is finite, then there must exist a pair (a, n)
such that "REL op id f s a n" holds.
-----------------------------------------------------------------------------%
let ACI_REL_EXISTS_LEMMA = PROVE(
"
^ACI_REL_DEF ==>
! op id . ASSOC_COMM_ID op id ==>
! f s . FINITE s ==>
? a n . ^REL op id f s a n
" , (
REPEAT (FILTER_STRIP_TAC "s : * -> bool") THEN
SET_INDUCT_TAC THENL
[ EXISTS_TAC "id : **" THEN
EXISTS_TAC "0" THEN
ASM_REWRITE_TAC [ ]
;
FIRST_ASSUM CHOOSE_TAC THEN
FIRST_ASSUM CHOOSE_TAC THEN
EXISTS_TAC "(op : ** -> ** -> **) (f (e : *)) a" THEN
EXISTS_TAC "SUC n" THEN
PURE_ASM_REWRITE_TAC [ ] THEN
EXISTS_TAC "e : *" THEN
EXISTS_TAC "a : **" THEN
IMP_RES_TAC DELETE_NON_ELEMENT THEN
ASM_REWRITE_TAC [IN_INSERT; DELETE_INSERT] ]
) ) ;;
%-----------------------------------------------------------------------------
Hence, if s is finite, then "@ b . ? n . REL op id f s b n" does have
the desired property of satisfying "\ a . ? n . REL op id f s a n".
-----------------------------------------------------------------------------%
let ACI_REL_SELECT_LEMMA = PROVE(
"
^ACI_REL_DEF ==>
! op id . ASSOC_COMM_ID op id ==>
! f s a . FINITE s ==>
( ( (@ b . ? n . ^REL op id f s b n) = a ) =
( ? n . ^REL op id f s a n) )
" , (
REPEAT STRIP_TAC THEN
IMP_RES_TAC ACI_REL_EXISTS_LEMMA THEN
EQ_TAC THENL
[ DISCH_THEN (\asm. PURE_ONCE_REWRITE_TAC [SYM asm]) THEN
CONV_TAC SELECT_CONV THEN
ASM_REWRITE_TAC [ ]
;
STRIP_TAC THEN
SELECT_UNIQUE_TAC THENL
[ EXISTS_TAC "n : num" THEN
ASM_REWRITE_TAC [ ]
;
REPEAT STRIP_TAC THEN
IMP_RES_TAC ACI_REL_UNIQUE_LEMMA ] ]
) ) ;;
%-----------------------------------------------------------------------------
Now, prove that "\ op id f s . @ b . ? n . REL op id f s b n" defines
the function that performs op on f(x)'s with x ranging over s,
for any op and id such that "ASSOC_COMM_ID op id".
-----------------------------------------------------------------------------%
let ACI_OP_EXISTS = PROVE(
"
? OP : (** -> ** -> **) -> ** -> (* -> **) -> (* -> bool) -> ** .
! op id . ASSOC_COMM_ID op id ==>
( ! f . OP op id f { } = id ) /\
( ! f s x . FINITE s ==>
( OP op id f (x INSERT s) = (x IN s) => (OP op id f s)
| (op (f x) (OP op id f s)) ) )
" , (
STRIP_ASSUME_TAC ACI_REL_EXISTS THEN
EXISTS_TAC "\ op id f s . @ b . ? n . ^REL op id f s b n" THEN
CONV_TAC (TOP_DEPTH_CONV BETA_CONV) THEN
REPEAT STRIP_TAC THENL
[ ASSUME_TAC (INST_TYPE [(":*", ":**")] FINITE_EMPTY) THEN
IMP_RES_TAC ACI_REL_SELECT_LEMMA THEN
PURE_ASM_REWRITE_TAC [ ] THEN
EXISTS_TAC "0" THEN
ASM_REWRITE_TAC [ ]
;
IMP_RES_THEN (ASSUME_TAC o ISPEC "x : *") FINITE_INSERT THEN
IMP_RES_TAC ACI_REL_SELECT_LEMMA THEN
PURE_ASM_REWRITE_TAC [ ] THEN
IMP_RES_TAC ACI_REL_EXISTS_LEMMA THEN
ASM_CASES_TAC "(x : *) IN s" THEN
ASM_REWRITE_TAC [ ] THENL
[ IMP_RES_THEN (\th. REWRITE_TAC [th]) ABSORPTION THEN
CONV_TAC SELECT_CONV THEN
ASM_REWRITE_TAC [ ]
;
FIRST_ASSUM (CHOOSE_TAC o SPEC_ALL) THEN
FIRST_ASSUM CHOOSE_TAC THEN
EXISTS_TAC "SUC n" THEN
ASM_REWRITE_TAC [ ] THEN
EXISTS_TAC "x : *" THEN
EXISTS_TAC "a : **" THEN
ASM_REWRITE_TAC [IN_INSERT; DELETE_INSERT] THEN
IMP_RES_THEN (\th. ASM_REWRITE_TAC [th]) DELETE_NON_ELEMENT THEN
AP_TERM_TAC THEN
ASM_REWRITE_TAC [ ] ] ]
) ) ;;
%-----------------------------------------------------------------------------
Finally, introduce a constant ACI_OP for OP via a constant specification.
-----------------------------------------------------------------------------%
let ACI_OP_DEF =
new_specification `ACI_OP_DEF` [(`constant`, `ACI_OP`)] ACI_OP_EXISTS ;;
let ACI_OP =
" ACI_OP : (** -> ** -> **) -> ** -> (* -> **) -> (* -> bool) -> ** " ;;
%-----------------------------------------------------------------------------
ACI_OP on singletons.
-----------------------------------------------------------------------------%
let ACI_OP_SING = prove_thm(`ACI_OP_SING`,
"
! op id . ASSOC_COMM_ID op id ==>
! f x . ^ACI_OP op id f {x} = f x
", (
REPEAT STRIP_TAC THEN
ASSUME_TAC (INST_TYPE [(":*", ":**")] FINITE_EMPTY) THEN
IMP_RES_TAC ACI_OP_DEF THEN
FIRST_ASSUM (ASSUME_TAC o el 3 o CONJUNCTS o
PURE_ONCE_REWRITE_RULE [ASSOC_COMM_ID_DEF]) THEN
ASM_REWRITE_TAC [NOT_IN_EMPTY]
) ) ;;
%-----------------------------------------------------------------------------
ACI_OP on unions.
-----------------------------------------------------------------------------%
let ACI_OP_UNION = prove_thm(`ACI_OP_UNION`,
"
! op id . ASSOC_COMM_ID op id ==>
! f s . FINITE s ==>
! t . FINITE t ==>
( op (^ACI_OP op id f (s UNION t))
(^ACI_OP op id f (s INTER t))
= op (^ACI_OP op id f s)
(^ACI_OP op id f t) )
", (
REPEAT GEN_TAC THEN
DISCH_THEN \ ASSOC_COMM_ID_asm .
let [ASSOC_asm; COMM_asm; _] =
(CONJUNCTS o PURE_ONCE_REWRITE_RULE [ASSOC_COMM_ID_DEF])
ASSOC_COMM_ID_asm
in
let AC_conv = AC_CONV (ASSOC_asm, COMM_asm)
in
let (LR_AC_TAC : thm_tactic) (th) (asl, g) =
let th' = EQT_ELIM (AC_conv " ^(lhs g) = ^(lhs (concl th)) ")
TRANS th TRANS
EQT_ELIM (AC_conv " ^(rhs (concl th)) = ^(rhs g) ")
in ACCEPT_TAC th' (asl, g)
in
let ACI_OP_asm = MATCH_MP ACI_OP_DEF ASSOC_COMM_ID_asm
in
GEN_TAC THEN
SET_INDUCT_TAC THEN
REPEAT STRIP_TAC THENL
[ REWRITE_TAC [UNION_EMPTY; INTER_EMPTY; ACI_OP_asm] THEN
CONV_TAC AC_conv
;
RES_THEN (ASSUME_TAC o AP_TERM "(op : ** -> ** -> **) (f (e : *))") THEN
REWRITE_TAC [INSERT_UNION; INSERT_INTER] THEN
ASM_CASES_TAC "(e : *) IN t" THEN
ASM_REWRITE_TAC [ ] THENL
[ IMP_RES_THEN (ASSUME_TAC o ISPEC "t : * -> bool") INTER_FINITE THEN
IMP_RES_THEN (ASM_REWRITE_TAC o append [IN_INTER] o sing) ACI_OP_asm
;
IMP_RES_TAC FINITE_UNION THEN
IMP_RES_THEN (ASM_REWRITE_TAC o append [IN_UNION] o sing) ACI_OP_asm
] THEN
FIRST_ASSUM LR_AC_TAC ]
) ) ;;
let ACI_OP_DISJOINT = prove_thm(`ACI_OP_DISJOINT`,
"
! op id . ASSOC_COMM_ID op id ==>
! f s t . FINITE s /\ FINITE t /\ DISJOINT s t ==>
( (^ACI_OP op id f (s UNION t))
= op (^ACI_OP op id f s) (^ACI_OP op id f t) )
", (
PURE_ONCE_REWRITE_TAC [DISJOINT_DEF] THEN
REPEAT STRIP_TAC THEN
REPEAT_GTCL IMP_RES_THEN
(PURE_ONCE_REWRITE_TAC o sing o SYM o SPEC_ALL) ACI_OP_UNION THEN
IMP_RES_THEN (ASM_REWRITE_TAC o sing) ACI_OP_DEF THEN
IMP_RES_THEN (REWRITE_TAC o sing o assert (mem "id : **" o vars o concl))
ASSOC_COMM_ID_DEF
) ) ;;
|