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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
|
(* ====================================================================== *)
(* CONDENSE *)
(* ====================================================================== *)
(*
let merge_interpsign ord_thm (thm1,thm2,thm3) =
let thm1' = BETA_RULE(PURE_REWRITE_RULE[interpsign] thm1) in
let thm2' = BETA_RULE(PURE_REWRITE_RULE[interpsign] thm2) in
let thm3' = BETA_RULE(PURE_REWRITE_RULE[interpsign] thm3) in
let set1,_,_ = dest_interpsign thm1 in
let _,s1 = dest_abs set1 in
let set3,_,_ = dest_interpsign thm3 in
let _,s3 = dest_abs set3 in
let gthm =
if is_conj s1 && is_conj s3 then gen_thm
else if is_conj s1 && not (is_conj s3) then gen_thm_noright
else if not (is_conj s1) && is_conj s3 then gen_thm_noleft
else gen_thm_noboth in
PURE_REWRITE_RULE[GSYM interpsign] (MATCH_MPL[gthm;ord_thm;thm1';thm2';thm3']);;
*)
(* {{{ Examples *)
(*
length thms
merge_interpsign ord_thm (hd thms)
let thm1,thm2,thm3 = hd thms
let ord_thm = ASSUME `x2 < x3`;;
let thm1 = ASSUME `interpsign (\x. x < x2) [&1; &2; &3] Pos`;;
let thm2 = ASSUME `interpsign (\x. x = x2) [&1; &2; &3] Pos`;;
let thm3 = ASSUME `interpsign (\x. x2 < x /\ x < x3) [&1; &2; &3] Pos`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
let ord_thm = ASSUME `x1 < x2`;;
let thm1 = ASSUME `interpsign (\x. x1 < x /\ x < x2) [&1; &2; &3] Pos`;;
let thm2 = ASSUME `interpsign (\x. x = x2) [&1; &2; &3] Pos`;;
let thm3 = ASSUME `interpsign (\x. x2 < x) [&1; &2; &3] Pos`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
let ord_thm = TRUTH;;
let thm1 = ASSUME `interpsign (\x. x < x1) [&1; &2; &3] Pos`;;
let thm2 = ASSUME `interpsign (\x. x = x1) [&1; &2; &3] Pos`;;
let thm3 = ASSUME `interpsign (\x. x1 < x) [&1; &2; &3] Pos`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
let ord_thm = ASSUME `x1 < x2 /\ x2 < x3`;;
let thm1 = ASSUME `interpsign (\x. x1 < x /\ x < x2) [&1; &2; &3] Pos`;;
let thm2 = ASSUME `interpsign (\x. x = x2) [&1; &2; &3] Pos`;;
let thm3 = ASSUME `interpsign (\x. x2 < x /\ x < x3) [&1; &2; &3] Pos`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
let ord_thm = ASSUME `x1 < x3`;;
let thm1 = ASSUME `interpsign (\x. x1 < x /\ x < x2) [&1; &2; &3] Neg`;;
let thm2 = ASSUME `interpsign (\x. x = x2) [&1; &2; &3] Neg`;;
let thm3 = ASSUME `interpsign (\x. x2 < x /\ x < x3) [&1; &2; &3] Neg`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
let ord_thm = ASSUME `x1 < x3`;;
let thm1 = ASSUME `interpsign (\x. x1 < x /\ x < x2) [&1; &2; &3] Zero`;;
let thm2 = ASSUME `interpsign (\x. x = x2) [&1; &2; &3] Zero`;;
let thm3 = ASSUME `interpsign (\x. x2 < x /\ x < x3) [&1; &2; &3] Zero`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
let ord_thm = ASSUME `x1 < x3`;;
let thm1 = ASSUME `interpsign (\x. x1 < x /\ x < x2) [&1; &2; &3] Nonzero`;;
let thm2 = ASSUME `interpsign (\x. x = x2) [&1; &2; &3] Nonzero`;;
let thm3 = ASSUME `interpsign (\x. x2 < x /\ x < x3) [&1; &2; &3] Nonzero`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
let ord_thm = ASSUME `x1 < x3`;;
let thm1 = ASSUME `interpsign (\x. x1 < x /\ x < x2) [&1; &2; &3] Unknown`;;
let thm2 = ASSUME `interpsign (\x. x = x2) [&1; &2; &3] Unknown`;;
let thm3 = ASSUME `interpsign (\x. x2 < x /\ x < x3) [&1; &2; &3] Unknown`;;
merge_interpsign ord_thm (thm1,thm2,thm3);;
*)
(* }}} *)
(*
let rec merge_three l1 l2 l3 =
match l1 with
[] -> []
| h::t -> (hd l1,hd l2,hd l3)::merge_three (tl l1) (tl l2) (tl l3);;
*)
(* {{{ Doc *)
(*
combine_interpsigns
|- interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x1 < x /\ x < x2)
[Unknown; Pos; Pos; Neg]
|- interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x = x2)
[Unknown; Pos; Pos; Neg];
|- interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x2 < x /\ x < x3)
[Unknown; Pos; Pos; Neg];
-->
|- interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x1 < x /\ x < x3)
[Unknown; Pos; Pos; Neg];
*)
(* }}} *)
(*
let combine_interpsigns ord_thm thm1 thm2 thm3 =
let _,_,s1 = dest_interpsigns thm1 in
let _,_,s2 = dest_interpsigns thm2 in
let _,_,s3 = dest_interpsigns thm3 in
if not (s1 = s2) || not (s1 = s3) then failwith "combine_interpsigns: signs not equal" else
try
let thms1 = CONJUNCTS(PURE_REWRITE_RULE[interpsigns;ALL2] thm1) in
let thms2 = CONJUNCTS(PURE_REWRITE_RULE[interpsigns;ALL2] thm2) in
let thms3 = CONJUNCTS(PURE_REWRITE_RULE[interpsigns;ALL2] thm3) in
let thms = butlast (merge_three thms1 thms2 thms3) (* ignore the T at end *) in
let thms' = map (merge_interpsign ord_thm) thms in
mk_interpsigns thms'
with Failure s -> failwith ("combine_interpsigns: " ^ s);;
*)
(* {{{ Examples *)
(*
let thm = combine_interpsigns
let ord_thm,thm1,thm2,thm3 = ord_thm5 ,ci1 ,ci2 ,ci3
let h1 = combine_interpsigns ord_thm int1 pt int2 in
let thm1,thm2,thm3 = int1,pt,int2
let tmp = (ith 0 thms)
merge_interpsign ord_thm tmp
let thm1 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x1 < x /\ x < x2)
[Unknown; Pos; Pos; Neg]`;;
let thm2 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x = x2)
[Unknown; Pos; Pos; Neg]`;;
let thm3 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x2 < x /\ x < x3)
[Unknown; Pos; Pos; Neg]`;;
let ord_thm = ASSUME `x1 < x2 /\ x2 < x3`
combine_interpsigns ord_thm thm1 thm2 thm3;;
let thm1 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x < x5)
[Unknown; Pos; Pos; Neg]`;;
let thm2 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x = x5)
[Unknown; Pos; Pos; Neg]`;;
let thm3 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x5 < x /\ x < x6)
[Unknown; Pos; Pos; Neg]`;;
let ord_thm = ASSUME `x5 < x6`;;
combine_interpsigns ord_thm thm1 thm2 thm3;;
let thm1 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x < x6)
[Unknown; Pos; Pos; Neg]`;;
let thm2 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x = x6)
[Unknown; Pos; Pos; Neg]`;;
let thm3 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]]
(\x. x6 < x)
[Unknown; Pos; Pos; Neg]`;;
let ord_thm = ASSUME `x5 < x6`;;
combine_interpsigns ord_thm thm1 thm2 thm3;;
*)
(* }}} *)
(* {{{ Doc *)
(*
get_bounds `\x. x < x1` `\x. x1 < x /\ x < x2`
-->
x1 < x2
get_bounds `\x. x0 < x < x1` `\x. x1 < x /\ x < x2`
-->
x0 < x1 /\ x1 < x2
get_bounds `\x. x < x1` `\x. x1 < x`
-->
T
*)
(* }}} *)
(*
let get_bounds set1 set2 =
let _,s1 = dest_abs set1 in
let _,s2 = dest_abs set2 in
let c1 =
if is_conj s1 then
let l,r = dest_conj s1 in
let l1,l2 = dest_binop rlt l in
let l3,l4 = dest_binop rlt r in
mk_binop rlt l1 l4
else t_tm in
let c2 =
if is_conj s2 then
let l,r = dest_conj s2 in
let l1,l2 = dest_binop rlt l in
let l3,l4 = dest_binop rlt r in
mk_binop rlt l1 l4
else t_tm in
if c1 = t_tm then c2
else if c2 = t_tm then c1
else mk_conj (c1,c2);;
*)
(* {{{ Examples *)
(*
get_bounds `\x. x < x1` `\x. x1 < x /\ x < x2`
get_bounds `\x. x0 < x /\ x < x1` `\x. x1 < x /\ x < x2`
get_bounds `\x. x < x1` `\x. x1 < x`
*)
(* }}} *)
(* {{{ Doc *)
(* collect_pts
|- interpsigns ... (\x. x < x1) ...
|- interpsigns ... (\x. x1 < x /\ x < x4) ...
|- interpsigns ... (\x. x4 < x /\ x < x7) ...
|- interpsigns ... (\x. x7 < x) ...
-->
[x1,x4,x7]
*)
(* }}} *)
(*
let rec collect_pts thms =
match thms with
[] -> []
| h::t ->
let rest = collect_pts t in
let _,set,_ = dest_interpsigns h in
let x,b = dest_abs set in
let bds =
if b = t_tm then []
else if is_conj b then
let l,r = dest_conj b in
[fst(dest_binop rlt l);snd(dest_binop rlt r)]
else
let _,l,r = get_binop b in
if x = l then [r] else [l] in
match rest with
[] -> bds
| h::t -> if not (h = (last bds)) then failwith "pts not in order"
else if length bds = 2 then hd bds::rest else rest;;
*)
(* {{{ Examples *)
(*
let thms = [ASSUME `interpsigns [\x. &0 + x * &1; \x. &1] (\x. T) [Unknown; Pos]`]
let h::t = [ASSUME `interpsigns [\x. &0 + x * &1; \x. &1] (\x. T) [Unknown; Pos]`]
collect_pts [ASSUME `interpsigns [\x. &0 + x * &1; \x. &1] (\x. T) [Unknown; Pos]`]
let t1 = ASSUME `interpsigns [[&1]] (\x. x < x1) [Pos]`
let t2 = ASSUME `interpsigns [[&1]] (\x. x1 < x /\ x < x4) [Pos]`
let t3 = ASSUME `interpsigns [[&1]] (\x. x4 < x /\ x < x7) [Pos]`
let t4 = ASSUME `interpsigns [[&1]] (\x. x7 < x) [Pos]`
collect_pts [t1;t2;t3;t4]
let t1 = ASSUME `interpsigns [[&1]] (\x. x0 < x /\ x < x1) [Pos]`
let t2 = ASSUME `interpsigns [[&1]] (\x. x1 < x /\ x < x4) [Pos]`
let t3 = ASSUME `interpsigns [[&1]] (\x. x4 < x /\ x < x7) [Pos]`
let t4 = ASSUME `interpsigns [[&1]] (\x. x7 < x) [Pos]`
collect_pts [t1;t2;t3;t4]
let t1 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0;
&1]]
(\x. x < x1)
[Unknown; Pos; Pos; Pos]`;;
let t2 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0;
&1]]
(\x. x = x1)
[Neg; Pos; Pos; Zero]`;;
let t3 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0;
&1]]
(\x. x1 < x /\ x < x4)
[Unknown; Pos; Pos; Neg]`;;
let t4 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0;
&1]]
(\x. x = x4)
[Pos; Pos; Zero; Neg]`;;
let t5 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0;
&1]]
(\x. x4 < x /\ x < x5)
[Unknown; Pos; Neg; Neg]`;;
let t6 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0;
&1]]
(\x. x = x5)
[Pos; Pos; Zero; Zero]`;;
let t7 = ASSUME
`interpsigns
[[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0;
&1]]
(\x. x5 < x)
[Unknown; Pos; Pos; Pos]`;;
let thms = [t1;t2;t3;t4;t5;t6;t7]
collect_pts thms
*)
(*
combine_identical_lines
|- real_ordered_list [x1; x2; x3; x4; x5]
|- ALL2
(interpsigns [[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]])
(partition_line [x1; x2; x3; x4; x5])
[[Unknown; Pos; Pos; Pos];
x1 [Neg; Pos; Pos; Zero];
[Unknown; Pos; Pos; Neg];
x2 [Unknown; Pos; Pos; Neg];
[Unknown; Pos; Pos; Neg];
x3 [Unknown; Pos; Pos; Neg];
[Unknown; Pos; Pos; Neg];
x4 [Pos; Pos; Zero; Neg];
[Unknown; Pos; Neg; Neg];
x5 [Pos; Pos; Zero; Zero];
[Unknown; Pos; Pos; Pos]]
-->
|- ALL2
(interpsigns [[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]])
(partition_line [x1; x4; x5])
[[Unknown; Pos; Pos; Pos];
x1 [Neg; Pos; Pos; Zero];
[Unknown; Pos; Pos; Neg];
x4 [Pos; Pos; Zero; Neg];
[Unknown; Pos; Neg; Neg];
x5 [Pos; Pos; Zero; Zero];
[Unknown; Pos; Pos; Pos]]
*)
(* }}} *)
(*
let sublist i j l =
let _,r = chop_list i l in
let l2,r2 = chop_list (j-i+1) r in
l2;;
*)
(* {{{ Examples *)
(*
let i,j,l = 1,4,[1;2;3;4;5;6;7]
sublist 1 4 [1;2;3;4;5;6;7]
sublist 2 4 [1;2;3;4;5;6;7]
sublist 1 1 [1;2;3;4;5;6;7]
*)
(* }}} *)
(*
let rec combine ord_thms l =
let lem = REWRITE_RULE[AND_IMP_THM] REAL_LT_TRANS in
match l with
[int] -> [int]
| [int1;int2] -> [int1;int2]
| int1::pt::int2::rest ->
try
let _,set1,_ = dest_interpsigns int1 in
let _,set2,_ = dest_interpsigns int2 in
let ord_tm = get_bounds set1 set2 in
if ord_tm = t_tm then
let h1 = combine_interpsigns TRUTH int1 pt int2 in
combine ord_thms (h1::rest)
else
let lt,rt =
if is_conj ord_tm then
let c1,c2 = dest_conj ord_tm in
let l,_ = dest_binop rlt c1 in
let _,r = dest_binop rlt c2 in
l,r
else dest_binop rlt ord_tm in
let e1 = find (fun x -> lt = fst(dest_binop rlt (concl x))) ord_thms in
let i1 = index e1 ord_thms in
let e2 = find (fun x -> rt = snd(dest_binop rlt (concl x))) ord_thms in
let i2 = index e2 ord_thms in
let ord_thms' = sublist i1 i2 ord_thms in
let ord_thm = end_itlist (fun x y -> MATCH_MPL[lem;x;y]) ord_thms' in
let h1 = combine_interpsigns ord_thm int1 pt int2 in
combine ord_thms (h1::rest)
with
Failure "combine_interpsigns: signs not equal" ->
int1::pt::(combine ord_thms(int2::rest));;
*)
(*
let combine_identical_lines rol_thm all_thm =
let tmp,mat = dest_comb (concl all_thm) in
let _,line = dest_comb tmp in
let _,pts = dest_comb line in
let part_thm = PARTITION_LINE_CONV pts in
let thm' = REWRITE_RULE[ALL2;part_thm] all_thm in
let thms = CONJUNCTS thm' in
let ord_thms = rol_thms rol_thm in
let thms' = combine ord_thms thms in
let pts = collect_pts thms' in
let part_thm' = PARTITION_LINE_CONV (mk_list (pts,real_ty)) in
mk_all2_interpsigns part_thm' thms';;
*)
(* {{{ Examples *)
(*
#untrace combine
#trace combine
let int1::pt::int2::rest = snd (chop_list 6 thms)
let int1::pt::int2::rest = snd (chop_list 0 thms)
let int1::pt::int2::rest = snd (chop_list 2 thms)
let l = thms
let int1::pt::int2::rest = l
combine thms
let rol_thm = ASSUME `real_ordered_list [x1; x2; x3; x4; x5]`
let all_thm = ASSUME
`ALL2
(interpsigns [[&1; &1; &1; &1]; [&1; &2; &3]; [&2; -- &3; &1]; [-- &4; &0; &1]])
(partition_line [x1; x2; x3; x4; x5])
[[Unknown; Pos; Pos; Pos];
[Neg; Pos; Pos; Zero];
[Unknown; Pos; Pos; Neg];
[Unknown; Pos; Pos; Neg];
[Unknown; Pos; Pos; Neg];
[Unknown; Pos; Pos; Neg];
[Unknown; Pos; Pos; Neg];
[Pos; Pos; Zero; Neg];
[Unknown; Pos; Neg; Neg];
[Pos; Pos; Zero; Zero];
[Unknown; Pos; Pos; Pos]]`;;
let all_thm' = combine_identical_lines rol_thm all_thm
*)
(* }}} *)
(* {{{ Doc *)
(*
assumes l2 is a sublist of l1
list_diff [1;2;3;4] [2;3] --> [1;4]
*)
(* }}} *)
(*
let rec list_diff l1 l2 =
match l1 with
[] -> if l2 = [] then [] else failwith "l2 not a sublist of l1"
| h::t ->
match l2 with
[] -> l1
| h'::t' -> if h = h' then list_diff t t'
else h::list_diff t l2;;
*)
(* {{{ Examples *)
(*
list_diff [1;2;3;4] [2;3]
list_diff [1;2;3;4] [1;3;4]
*)
(* }}} *)
(*
let CONDENSE mat_thm =
let rol_thm,all_thm = interpmat_thms mat_thm in
let pts = dest_list (snd (dest_comb (concl rol_thm))) in
let all_thm' = combine_identical_lines rol_thm all_thm in
let _,part,_ = dest_all2 (concl all_thm) in
let plist = dest_list (snd (dest_comb part)) in
let _,part',_ = dest_all2 (concl all_thm') in
let plist' = dest_list (snd (dest_comb part')) in
let rol_thm' = itlist ROL_REMOVE (list_diff plist plist') rol_thm in
let mat_thm' = mk_interpmat_thm rol_thm' all_thm' in
mat_thm';;
*)
(* ---------------------------------------------------------------------- *)
(* OPT *)
(* ---------------------------------------------------------------------- *)
let rec triple_index l =
match l with
[] -> failwith "triple_index"
| [x] -> failwith "triple_index"
| [x;y] -> failwith "triple_index"
| x::y::z::rest -> if x = y && y = z then 0 else 1 + triple_index (y::z::rest);;
let tmp = ref TRUTH;;
(*
let
tmp
let mat_thm = !tmp
let mat_thm = mat_thm'
*)
let rec CONDENSE =
let real_app = `APPEND:real list -> real list -> real list` in
let sign_app = `APPEND:(sign list) list -> (sign list) list -> (sign list) list` in
let real_len = `LENGTH:real list -> num` in
let sign_len = `LENGTH:(sign list) list -> num` in
let num_mul = `( * ):num -> num -> num` in
let real_ty = `:real` in
let two = `2` in
let sl_ty = `:sign list` in
fun mat_thm ->
try
tmp := mat_thm;
let pts,_,sgns = dest_interpmat (concl mat_thm) in
let sgnl = dest_list sgns in
let ptl = dest_list pts in
let i = triple_index sgnl (* fail here if fully condensed *) in
if not (i mod 2 = 0) then failwith "misshifted matrix" else
if i = 0 then
if length ptl = 1 then MATCH_MP INTERPMAT_SING mat_thm
else CONDENSE (MATCH_MP INTERPMAT_TRIO mat_thm) else
let l,r = chop_list (i - 2) sgnl in
let sgn1,sgn2 = mk_list(l,sl_ty),mk_list(r,sl_ty) in
let sgns' = mk_comb(mk_comb(sign_app,sgn1),sgn2) in
let sgn_thm = prove(mk_eq(sgns,sgns'),REWRITE_TAC[APPEND]) in
let l',r' = chop_list (i / 2 - 1) ptl (* i always even *) in
let pt1,pt2 = mk_list(l',real_ty),mk_list(r',real_ty) in
let pts' = mk_comb(mk_comb(real_app,pt1),pt2) in
let pt_thm = prove(mk_eq(pts,pts'),REWRITE_TAC[APPEND]) in
let mat_thm' = ONCE_REWRITE_RULE[sgn_thm;pt_thm] mat_thm in
let len_thm = prove((mk_eq(mk_comb(sign_len,sgn1),mk_binop num_mul two (mk_comb(real_len,pt1)))),REWRITE_TAC[LENGTH] THEN ARITH_TAC) in
CONDENSE (REWRITE_RULE[APPEND]
(MATCH_MP (MATCH_MP INTERPMAT_TRIO_INNER mat_thm') len_thm))
with
Failure "triple_index" -> mat_thm
| Failure x -> failwith ("CONDENSE: " ^ x);;
(* {{{ Examples *)
(*
let mat_thm = mat_thm'
CONDENSE mat_thm
let mat_thm = ASSUME
`interpmat [x1; x2; x3; x4; x5]
[\x. &1 + x * (&2 + x * &3); \x. &2 + x * (-- &3 + x * &1); \x. -- &4 + x * (&0 + x * &1);
\x. &8 + x * &4; \x. -- &7 + x * &11; \x. &5 + x * &5]
[
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Pos; Neg; Neg; Neg];
[Zero; Pos; Pos; Neg; Neg; Neg];
[Neg; Pos; Pos; Neg; Neg; Neg]
]`
let mat_thm = ASSUME
`interpmat [x1; x2; x3; x4; x5]
[\x. &1 + x * (&2 + x * &3); \x. &2 + x * (-- &3 + x * &1); \x. -- &4 + x * (&0 + x * &1);
\x. &8 + x * &4; \x. -- &7 + x * &11; \x. &5 + x * &5]
[[Pos; Pos; Pos; Neg; Neg; Neg];
[Pos; Pos; Zero; Zero; Neg; Neg];
[Pos; Pos; Neg; Pos; Neg; Neg];
[Pos; Pos; Neg; Pos; Neg; Zero];
[Pos; Pos; Neg; Pos; Neg; Pos];
[Pos; Pos; Neg; Pos; Zero; Pos];
[Pos; Pos; Neg; Pos; Pos; Pos];
[Pos; Zero; Neg; Pos; Pos; Pos];
[Pos; Neg; Neg; Pos; Pos; Pos];
[Pos; Zero; Zero; Pos; Pos; Pos];
[Pos; Pos; Pos; Pos; Pos; Pos]]`
let mat_thm' = INFERPSIGN vars sgns mat_thm div_thms
CONDENSE mat_thm
*)
(* }}} *)
(* ---------------------------------------------------------------------- *)
(* Timing *)
(* ---------------------------------------------------------------------- *)
let CONDENSE mat_thm =
let start_time = Sys.time() in
let res = CONDENSE mat_thm in
condense_timer +.= (Sys.time() -. start_time);
res;;
|