forked from CakeML/candle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
impconv.ml.patch
1124 lines (1124 loc) · 35.4 KB
/
impconv.ml.patch
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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
18,19c18,22
< let IMP_REWRITE_TAC,TARGET_REWRITE_TAC,HINT_EXISTS_TAC,
< SEQ_IMP_REWRITE_TAC,CASE_REWRITE_TAC =
---
> (* OA: Reorganized this file b/c first-class modules.
>
> Lots of the syntax was incompatible with out parser, and there was
> an 'open' somewhere in there.
> *)
21c24
< let I = fun x -> x in
---
> module Impconv = struct
26c29
< p,UNDISCH th in
---
> p,UNDISCH th ;;
34c37
< with Failure _ -> [],th in
---
> with Failure _ -> [],th ;;
39c42
< DISCH p (f th) in
---
> DISCH p (f th) ;;
41c44
< let strip_conj = binops `(/\)` in
---
> let strip_conj = binops `(/\)` ;;
47c50
< |f::fs' -> try f x with Failure _ -> tryfind_fun fs' x in
---
> |f::fs' -> try f x with Failure _ -> tryfind_fun fs' x ;;
58c61
< self 0 in
---
> self 0 ;;
60c63
< let list_of_option = function None -> [] | Some x -> [x] in
---
> let list_of_option = function None -> [] | Some x -> [x] ;;
62c65
< let try_list f x = try f x with Failure _ -> [] in
---
> let try_list f x = try f x with Failure _ -> [] ;;
65,66c68,69
< let A_ = `A:bool` and B_ = `B:bool` and C_ = `C:bool` and D_ = `D:bool` in
< let T_ = `T:bool` in
---
> let A_Tm = `A:bool` and B_Tm = `B:bool` and C_Tm = `C:bool` and D_Tm = `D:bool`
> and T_Tm = `T:bool` ;;
71c74
< fun t -> INST [t,A_] lem in
---
> fun t -> INST [t,A_Tm] lem ;;
81c84
< DEPTH_CONV (fun u -> ALPHA_CONV (assoc (bndvar u) mapping) u) t in
---
> DEPTH_CONV (fun u -> ALPHA_CONV (assoc (bndvar u) mapping) u) t ;;
84c87
< let VARIANT_RULE = CONV_RULE o VARIANT_CONV in
---
> let VARIANT_RULE = CONV_RULE o VARIANT_CONV ;;
87c90
< let DISCH_HD th = DISCH (hd (hyp th)) th in
---
> let DISCH_HD th = DISCH (hd (hyp th)) th ;;
90c93
< let REWR_RULE = CONV_RULE o REWR_CONV in
---
> let REWR_RULE = CONV_RULE o REWR_CONV ;;
100c103
< f o rev in
---
> f o rev ;;
107c110
< with Failure _ -> DISCH t th in
---
> with Failure _ -> DISCH t th ;;
117c120
< with Failure _ -> [],th in
---
> with Failure _ -> [],th ;;
122c125
< GENL vs (f th) in
---
> GENL vs (f th) ;;
127c130
< let GEN_MAP_CONCLUSION = MAP_FORALL_BODY o MAP_CONCLUSION o MAP_FORALL_BODY in
---
> let GEN_MAP_CONCLUSION = MAP_FORALL_BODY o MAP_CONCLUSION o MAP_FORALL_BODY ;;
139c142
< RIGHT_IMP_FORALL_THM;IMPLY_AND_RDISTRIB;GSYM CONJ_ASSOC] in
---
> RIGHT_IMP_FORALL_THM;IMPLY_AND_RDISTRIB;GSYM CONJ_ASSOC] ;;
146c149
< |_ -> failwith "dest_binary_blind" in
---
> |_ -> failwith "dest_binary_blind" ;;
148c151
< let spec_all = repeat (snd o dest_forall) in
---
> let spec_all = repeat (snd o dest_forall) ;;
150c153
< let thm_lt (th1:thm) th2 = th1 < th2 in
---
> let thm_lt (th1:thm) th2 = Thm.(<) th1 th2 ;;
181c184
< loop [] hs in
---
> loop [] hs ;;
198c201
< self [] th1 ths1' ths2 in
---
> self [] th1 ths1' ths2 ;;
208c211
< self ths2 ths1 in
---
> self ths2 ths1 ;;
211,319c214,308
< let module Tset =
< struct
< type t = term list
< let cmp (x:term) y = Pervasives.compare x y
< let lt (x:term) y = Pervasives.compare x y < 0
< let lift f = List.sort cmp o f
< let of_list = lift I
< let insert ts t =
< let rec self = function
< |[] -> [t]
< |x::xs when lt x t -> x::self xs
< |x::_ as xs when x = t -> xs
< |xs -> t::xs
< in
< if t = T_ then ts else self ts
< let remove ts t =
< let rec self = function
< |[] -> []
< |x::xs when lt x t -> x::self xs
< |x::xs when x = t -> xs
< |_::_ as xs -> xs
< in
< self ts
< let strip_conj =
< let rec self acc t =
< try
< let t1,t2 = dest_conj t in
< self (self acc t1) t2
< with Failure _ -> insert acc t
< in
< self []
< let rec union l1 l2 =
< match l1 with
< |[] -> l2
< |h1::t1 ->
< match l2 with
< |[] -> l1
< |h2::t2 when lt h1 h2 -> h1::union t1 l2
< |h2::t2 when h1 = h2 -> h1::union t1 t2
< |h2::t2 -> h2::union l1 t2
< let rec mem x = function
< |x'::xs when x' = x -> true
< |x'::xs when lt x' x -> mem x xs
< |_ -> false
< let subtract l1 l2 = filter (fun x -> not (mem x l2)) l1
< let empty = []
< let flat_revmap f =
< let rec self acc = function
< |[] -> acc
< |x::xs -> self (union (f x) acc) xs
< in
< self []
< let flat_map f = flat_revmap f o rev
< let rec frees acc = function
< |Var _ as t -> insert acc t
< |Const _ -> acc
< |Abs(v,b) -> remove (frees acc b) v
< |Comb(u,v) -> frees (frees acc u) v
< let freesl ts = itlist (C frees) ts empty
< let frees = frees empty
< end in
<
< let module Type_annoted_term =
< struct
< type t =
< |Var_ of string * hol_type
< |Const_ of string * hol_type * term
< |Comb_ of t * t * hol_type
< |Abs_ of t * t * hol_type
<
< let type_of = function
< |Var_(_,ty) -> ty
< |Const_(_,ty,_) -> ty
< |Comb_(_,_,ty) -> ty
< |Abs_(_,_,ty) -> ty
<
< let rec of_term = function
< |Var(s,ty) -> Var_(s,ty)
< |Const(s,ty) as t -> Const_(s,ty,t)
< |Comb(u,v) ->
< let u' = of_term u and v' = of_term v in
< Comb_(u',v',snd (dest_fun_ty (type_of u')))
< |Abs(x,b) ->
< let x' = of_term x and b' = of_term b in
< Abs_(x',b',mk_fun_ty (type_of x') (type_of b'))
<
< let rec equal t1 t2 =
< match t1,t2 with
< |Var_(s1,ty1),Var_(s2,ty2)
< |Const_(s1,ty1,_),Const_(s2,ty2,_) -> s1 = s2 && ty1 = ty2
< |Comb_(u1,v1,_),Comb_(u2,v2,_) -> equal u1 u2 && equal v1 v2
< |Abs_(v1,b1,_),Abs_(v2,b2,_) -> equal v1 v2 && equal b1 b2
< |_ -> false
<
< let rec to_term = function
< |Var_(s,ty) -> mk_var(s,ty)
< |Const_(_,_,t) -> t
< |Comb_(u,v,_) -> mk_comb(to_term u,to_term v)
< |Abs_(v,b,_) -> mk_abs(to_term v,to_term b)
<
< let dummy = Var_("",aty)
<
< let rec find_term p t =
< if p t then t else
< match t with
< |Abs_(_,b,_) -> find_term p b
< |Comb_(u,v,_) -> try find_term p u with Failure _ -> find_term p v
< |_ -> failwith "Annot.find_term"
< end in
---
> module Tset = struct
> (*type t = term list*) (* TODO Makes CakeML pretty printer system dizzy *)
> let lift f = List.sort Term.(<) o f
> let of_list = lift I
> let insert ts t =
> let rec self xs = match xs with
> |[] -> [t]
> |x::xs when Term.(<) x t -> x::self xs
> |x::_ as xs when x = t -> xs
> |xs -> t::xs
> in
> if t = T_Tm then ts else self ts
> let remove ts t =
> let rec self xs = match xs with
> |[] -> []
> |x::xs when Term.(<) x t -> x::self xs
> |x::xs when x = t -> xs
> |_::_ as xs -> xs
> in
> self ts
> let strip_conj =
> let rec self acc t =
> try
> let t1,t2 = dest_conj t in
> self (self acc t1) t2
> with Failure _ -> insert acc t
> in
> self []
> let rec union l1 l2 =
> match l1 with
> |[] -> l2
> |h1::t1 ->
> match l2 with
> |[] -> l1
> |h2::t2 when Term.(<) h1 h2 -> h1::union t1 l2
> |h2::t2 when h1 = h2 -> h1::union t1 t2
> |h2::t2 -> h2::union l1 t2
> let rec mem x = function
> |x'::xs when x' = x -> true
> |x'::xs when Term.(<) x' x -> mem x xs
> |_ -> false
> let subtract l1 l2 = filter (fun x -> not (mem x l2)) l1
> let empty = []
> let flat_revmap f =
> let rec self acc = function
> |[] -> acc
> |x::xs -> self (union (f x) acc) xs
> in
> self []
> let flat_map f = flat_revmap f o rev
> let rec frees acc = function
> |Var (_,_) as t -> insert acc t
> |Const (_,_) -> acc
> |Abs(v,b) -> remove (frees acc b) v
> |Comb(u,v) -> frees (frees acc u) v
> let freesl ts = itlist (C frees) ts empty
> let frees = frees empty
> end ;;
>
> module Annot = struct
> type t =
> |Var_ of string * hol_type
> |Const_ of string * hol_type * term
> |Comb_ of t * t * hol_type
> |Abs_ of t * t * hol_type
>
> let type_of = function
> |Var_(_,ty) -> ty
> |Const_(_,ty,_) -> ty
> |Comb_(_,_,ty) -> ty
> |Abs_(_,_,ty) -> ty
>
> let rec of_term tm = match tm with
> |Var(s,ty) -> Var_(s,ty)
> |Const(s,ty) as t -> Const_(s,ty,t)
> |Comb(u,v) ->
> let u' = of_term u and v' = of_term v in
> Comb_(u',v',snd (dest_fun_ty (type_of u')))
> |Abs(x,b) ->
> let x' = of_term x and b' = of_term b in
> Abs_(x',b',mk_fun_ty (type_of x') (type_of b'))
>
> let rec equal t1 t2 =
> match t1,t2 with
> |Var_(s1,ty1),Var_(s2,ty2)
> |Const_(s1,ty1,_),Const_(s2,ty2,_) -> s1 = s2 && ty1 = ty2
> |Comb_(u1,v1,_),Comb_(u2,v2,_) -> equal u1 u2 && equal v1 v2
> |Abs_(v1,b1,_),Abs_(v2,b2,_) -> equal v1 v2 && equal b1 b2
> |_ -> false
>
> let rec to_term tm = match tm with
> |Var_(s,ty) -> mk_var(s,ty)
> |Const_(_,_,t) -> t
> |Comb_(u,v,_) -> mk_comb(to_term u,to_term v)
> |Abs_(v,b,_) -> mk_abs(to_term v,to_term b)
321c310,318
< let module Annot = Type_annoted_term in
---
> let dummy = Var_("",aty)
>
> let rec find_term p t =
> if p t then t else
> match t with
> |Abs_(_,b,_) -> find_term p b
> |Comb_(u,v,_) -> try find_term p u with Failure _ -> find_term p v
> |_ -> failwith "Annot.find_term"
> end ;;
332a330,336
> let rec rev_map acc f xs =
> match xs with
> | [] -> acc
> | x::xs -> rev_map (f x::acc) f xs;;
>
> let rev_map f xs = rev_map [] f xs;;
>
335c339
< let rec self bnds (tenv,tyenv as env) p t =
---
> let rec self bnds ((tenv,tyenv) as env) p t =
346c350
< |Var(n,ty) as v,t ->
---
> | (Var(n,ty) as v),t ->
366c370
< List.rev_map (fun t,v -> Annot.to_term t,inst v) tenv,tyenv in
---
> rev_map (fun t,v -> Annot.to_term t,inst v) tenv,tyenv ;;
395c399
< if Pervasives.compare tm' tm = 0 then fth else
---
> if tm' = tm then fth else
397c401
< with Failure _ -> failwith "PART_MATCH: Sanity check failure" in
---
> with Failure _ -> failwith "PART_MATCH: Sanity check failure" ;;
399,434c403,437
< let module Fo_nets =
< struct
< type term_label =
< |Vnet of int
< |Lcnet of string * int
< |Cnet of string * int
< |Lnet of int
<
< type 'a t = Netnode of (term_label * 'a t) list * 'a list
<
< let empty_net = Netnode([],[])
<
< let enter =
< let label_to_store lcs t =
< let op,args = strip_comb t in
< let nargs = length args in
< match op with
< |Const(n,_) -> Cnet(n,nargs),args
< |Abs(v,b) ->
< let b' = if mem v lcs then vsubst [genvar(type_of v),v] b else b in
< Lnet nargs,b'::args
< |Var(n,_) when mem op lcs -> Lcnet(n,nargs),args
< |Var(_,_) -> Vnet nargs,args
< |_ -> assert false
< in
< let rec net_update lcs elem (Netnode(edges,tips)) = function
< |[] -> Netnode(edges,elem::tips)
< |t::rts ->
< let label,nts = label_to_store lcs t in
< let child,others =
< try (snd F_F I) (remove (fun (x,y) -> x = label) edges)
< with Failure _ -> empty_net,edges in
< let new_child = net_update lcs elem child (nts@rts) in
< Netnode ((label,new_child)::others,tips)
< in
< fun lcs (t,elem) net -> net_update lcs elem net [t]
---
> module Fo_nets = struct
> type term_label =
> |Vnet of int
> |Lcnet of string * int
> |Cnet of string * int
> |Lnet of int
>
> type 'a t = Netnode of (term_label * 'a t) list * 'a list
>
> let empty_net = Netnode([],[])
>
> let enter lcs =
> let label_to_store lcs t =
> let op,args = strip_comb t in
> let nargs = length args in
> match op with
> |Const(n,_) -> Cnet(n,nargs),args
> |Abs(v,b) ->
> let b' = if mem v lcs then vsubst [genvar(type_of v),v] b else b in
> Lnet nargs,b'::args
> |Var(n,_) when mem op lcs -> Lcnet(n,nargs),args
> |Var(_,_) -> Vnet nargs,args
> |_ -> raise Bind (* assert false *)
> in
> let rec net_update lcs elem (Netnode(edges,tips)) = function
> |[] -> Netnode(edges,elem::tips)
> |t::rts ->
> let label,nts = label_to_store lcs t in
> let child,others =
> try (snd F_F I) (remove (fun (x,y) -> x = label) edges)
> with Failure _ -> empty_net,edges in
> let new_child = net_update lcs elem child (nts@rts) in
> Netnode ((label,new_child)::others,tips)
> in
> fun (t,elem) net -> net_update lcs elem net [t]
436,463c439,464
< let lookup =
< let label_for_lookup t =
< let op,args = strip_comb t in
< let nargs = length args in
< match op with
< |Const(n,_) -> Cnet(n,nargs),args
< |Abs(_,b) -> Lnet nargs,b::args
< |Var(n,_) -> Lcnet(n,nargs),args
< |Comb _ -> assert false
< in
< let rec follow (Netnode(edges,tips)) = function
< |[] -> tips
< |t::rts ->
< let label,nts = label_for_lookup t in
< let collection =
< try follow (assoc label edges) (nts@rts) with Failure _ -> []
< in
< let rec support = function
< |[] -> [0,rts]
< |t::ts ->
< let ((k,nts')::res') as res = support ts in
< (k+1,(t::nts'))::res
< in
< let follows =
< let f (k,nts) =
< try follow (assoc (Vnet k) edges) nts with Failure _ -> []
< in
< map f (support nts)
---
> let lookup t =
> let label_for_lookup t =
> let op,args = strip_comb t in
> let nargs = length args in
> match op with
> |Const(n,_) -> Cnet(n,nargs),args
> |Abs(_,b) -> Lnet nargs,b::args
> |Var(n,_) -> Lcnet(n,nargs),args
> |Comb (_,_) -> raise Bind (* assert false *)
> in
> let rec follow (Netnode(edges,tips)) = function
> |[] -> tips
> |t::rts ->
> let label,nts = label_for_lookup t in
> let collection =
> try follow (assoc label edges) (nts@rts) with Failure _ -> []
> in
> let rec support xs = match xs with
> |[] -> [0,rts]
> |t::ts ->
> let ((k,nts')::res') as res = support ts in
> (k+1,(t::nts'))::res
> in
> let follows =
> let f (k,nts) =
> try follow (assoc (Vnet k) edges) nts with Failure _ -> []
465,467c466,470
< collection @ flat follows
< in
< fun t net -> follow net [t]
---
> map f (support nts)
> in
> collection @ flat follows
> in
> fun net -> follow net [t]
469,479c472,481
< let rec filter p (Netnode(edges,tips)) =
< Netnode(
< List.map (fun l,n -> l,filter p n) edges,
< List.filter p tips)
< end in
<
< let module Variance =
< struct
< type t = Co | Contra
< let neg = function Co -> Contra | Contra -> Co
< end in
---
> let rec filter p (Netnode(edges,tips)) =
> Netnode(
> List.map (fun l,n -> l,filter p n) edges,
> List.filter p tips)
> end ;;
>
> module Variance = struct
> type t = Co | Contra
> let neg = function Co -> Contra | Contra -> Co
> end ;;
487,488d488
< let module Impconv =
< struct
492c492
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
518c518
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
531c531
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
538c538
< MP (INST [a,A_;b,B_;c,C_] lem) th
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm] lem) th
547c547
< MP (INST [a,A_;b,B_;d,D_] lem) th
---
> MP (INST [a,A_Tm;b,B_Tm;d,D_Tm] lem) th
556c556
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
565c565
< MP (INST [a,A_;b,B_;c,C_] lem) th
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm] lem) th
572c572
< MP (INST [a,A_;b,B_;d,D_] lem) th
---
> MP (INST [a,A_Tm;b,B_Tm;d,D_Tm] lem) th
579c579
< MP (INST [a,A_;b,B_;c,C_;d,D_] MONO_IMP) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] MONO_IMP) (CONJ th1 th2)
582c582
< let lem' = REWRITE_RULE[] (INST [C_,D_] lem) in
---
> let lem' = REWRITE_RULE[] (INST [C_Tm,D_Tm] lem) in
585c585
< MP (INST [a,A_;b,B_;t,C_] lem') th
---
> MP (INST [a,A_Tm;b,B_Tm;t,C_Tm] lem') th
601c601
< let MONO_IMP' = REWRITE_RULE[] (INST [C_,D_] MONO_IMP) in
---
> let MONO_IMP' = REWRITE_RULE[] (INST [C_Tm,D_Tm] MONO_IMP) in
604c604
< MP (INST [a,A_;b,B_;t,C_] MONO_IMP') th
---
> MP (INST [a,A_Tm;b,B_Tm;t,C_Tm] MONO_IMP') th
607c607
< let lem' = REWRITE_RULE[] (INST [A_,B_] lem) in
---
> let lem' = REWRITE_RULE[] (INST [A_Tm,B_Tm] lem) in
610c610
< MP (INST [c,C_;d,D_;t,A_] lem') th
---
> MP (INST [c,C_Tm;d,D_Tm;t,A_Tm] lem') th
630c630
< MP (INST [a,A_;b,B_] MONO_NOT) th
---
> MP (INST [a,A_Tm;b,B_Tm] MONO_NOT) th
660c660
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
668c668
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
679c679
< MP (INST [c,C_;d,D_;a,A_] lem) th
---
> MP (INST [c,C_Tm;d,D_Tm;a,A_Tm] lem) th
691c691
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
698c698
< MP (INST [a,A_;b,B_;c,C_] lem) th
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm] lem) th
705c705
< MP (INST [a,A_;c,C_;d,D_] lem) th
---
> MP (INST [a,A_Tm;c,C_Tm;d,D_Tm] lem) th
712c712
< MP (INST [a,A_;b,B_;c,C_;d,D_] lem) (CONJ th1 th2)
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm;d,D_Tm] lem) (CONJ th1 th2)
718c718
< fun c -> MP (INST [a,A_;b,B_;c,C_] lem) th
---
> fun c -> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm] lem) th
725c725
< MP (INST [a,A_;b,B_;c,C_] lem) th
---
> MP (INST [a,A_Tm;b,B_Tm;c,C_Tm] lem) th
734c734
< open Variance
---
> (*open Variance*)
743c743
< let imp_conv_of_conv:conv->imp_conv =
---
> let (imp_conv_of_conv:conv->imp_conv) =
746c746
< match v with Co -> th2 | Contra -> th1
---
> match v with Variance.Co -> th2 | Variance.Contra -> th1
751c751
< match v with Co -> t1 | Contra -> t2
---
> match v with Variance.Co -> t1 | Variance.Contra -> t2
754c754
< let ALL_IMPCONV:imp_conv = fun _ -> IMP_REFL
---
> let (ALL_IMPCONV:imp_conv) = fun _ -> IMP_REFL
757c757
< let NO_IMPCONV:imp_conv = fun _ _ -> failwith "NO_IMPCONV"
---
> let (NO_IMPCONV:imp_conv) = fun _ _ -> failwith "NO_IMPCONV"
762,763c762,763
< |Co -> IMP_TRANS (c v t1) th
< |Contra -> IMP_TRANS th (c v t2)
---
> |Variance.Co -> IMP_TRANS (c v t1) th
> |Variance.Contra -> IMP_TRANS th (c v t2)
778c778
< let MATCH_MP_IMPCONV:thm->imp_conv =
---
> let (MATCH_MP_IMPCONV:thm->imp_conv) =
780,781c780,781
< |Co -> GEN_PART_MATCH rand th
< |Contra -> GEN_PART_MATCH lhand th
---
> |Variance.Co -> GEN_PART_MATCH rand th
> |Variance.Contra -> GEN_PART_MATCH lhand th
791c791
< let IMPCONV_RULE:imp_conv->thm->thm =
---
> let (IMPCONV_RULE:imp_conv->thm->thm) =
794c794
< MATCH_MP (c Contra t) th
---
> MATCH_MP (c Variance.Contra t) th
797,799c797,799
< let IMPCONV_TAC:imp_conv->tactic =
< fun cnv (_,c as g) ->
< (MATCH_MP_TAC (cnv Co c) THEN TRY (ACCEPT_TAC TRUTH)) g
---
> let (IMPCONV_TAC:imp_conv->tactic) =
> fun cnv ((_,c) as g) ->
> (MATCH_MP_TAC (cnv Variance.Co c) THEN TRY (ACCEPT_TAC TRUTH)) g
808c808
< With_context of 'a * (Tset.t -> 'a with_context) * (term -> 'a with_context)
---
> With_context of 'a * ((*Tset.t*) term list -> 'a with_context) * (term -> 'a with_context)
821,824c821,824
< * Suppose [ic1 Co A] returns [B ==> A], and [ic2 Co C] returns [D ==> C],
< * then [CONJ_IMPCONV ic1 ic2 Co (A /\ C)] returns [B /\ D ==> A /\ C].
< * Suppose [ic1 Contra A] returns [A ==> B], and [ic2 Contra C] returns
< * [C ==> D], then [CONJ_IMPCONV ic1 ic2 Contra (A /\ B)]
---
> * Suppose [ic1 Variance.Co A] returns [B ==> A], and [ic2 Variance.Co C] returns [D ==> C],
> * then [CONJ_IMPCONV ic1 ic2 Variance.Co (A /\ C)] returns [B /\ D ==> A /\ C].
> * Suppose [ic1 Variance.Contra A] returns [A ==> B], and [ic2 Variance.Contra C] returns
> * [C ==> D], then [CONJ_IMPCONV ic1 ic2 Variance.Contra (A /\ B)]
827c827
< * Additionally takes the context into account, i.e., if [ic2 Co C] returns
---
> * Additionally takes the context into account, i.e., if [ic2 Variance.Co C] returns
829c829
< * then [CONJ_IMPCONV ic1 ic2 Co (A /\ B)] returns [|- C /\ D ==> A /\ B]
---
> * then [CONJ_IMPCONV ic1 ic2 Variance.Co (A /\ B)] returns [|- C /\ D ==> A /\ B]
837c837
< |Co ->
---
> |Variance.Co ->
839c839
< let th1 = apply c Co t1 in
---
> let th1 = apply c Variance.Co t1 in
841,842c841,842
< let t1' = imp_conv_outcome th1 Co in
< MKIMP_CONJ_CO_CTXT th1 (apply_with_context c t1' Co t2)
---
> let t1' = imp_conv_outcome th1 Variance.Co in
> MKIMP_CONJ_CO_CTXT th1 (apply_with_context c t1' Variance.Co t2)
844,845c844,845
< with Failure _ -> MKIMPR_CONJ_CO_CTXT (apply_with_context c t1 Co t2))
< |Contra ->
---
> with Failure _ -> MKIMPR_CONJ_CO_CTXT (apply_with_context c t1 Variance.Co t2))
> |Variance.Contra ->
851c851
< let th1 = apply (augment c t2s) Contra t1 in
---
> let th1 = apply (augment c t2s) Variance.Contra t1 in
853c853
< let t1' = imp_conv_outcome th1 Contra in
---
> let t1' = imp_conv_outcome th1 Variance.Contra in
856c856
< let th2 = apply (augment c t1s'') Contra t2 in
---
> let th2 = apply (augment c t1s'') Variance.Contra t2 in
861c861
< MKIMPR_CONJ_CONTRA_CTXT (apply_with_context c t1 Contra t2))
---
> MKIMPR_CONJ_CONTRA_CTXT (apply_with_context c t1 Variance.Contra t2))
867,870c867,870
< * Suppose [ic1 Co A] returns [B ==> A], and [ic2 Co C] returns [D ==> C],
< * then [DISJ_IMPCONV ic1 ic2 Co (A \/ C)] returns [B \/ D ==> A \/ C].
< * Suppose [ic1 Contra A] returns [A ==> B], and [ic2 Contra C] returns
< * [C ==> D], then [DISJ_IMPCONV ic1 ic2 Contra (A \/ B)]
---
> * Suppose [ic1 Variance.Co A] returns [B ==> A], and [ic2 Variance.Co C] returns [D ==> C],
> * then [DISJ_IMPCONV ic1 ic2 Variance.Co (A \/ C)] returns [B \/ D ==> A \/ C].
> * Suppose [ic1 Variance.Contra A] returns [A ==> B], and [ic2 Variance.Contra C] returns
> * [C ==> D], then [DISJ_IMPCONV ic1 ic2 Variance.Contra (A \/ B)]
885,888c885,888
< * Suppose [ic1 Contra A] returns [A ==> B], and [ic2 Co C] returns [D ==> C],
< * then [IMP_IMPCONV ic1 ic2 Co (A ==> C)] returns [(B ==> D) ==> (A ==> C)].
< * Suppose [ic1 Co A] returns [B ==> A], and [ic2 Contra C] returns
< * [C ==> D], then [IMP_IMPCONV ic1 ic2 Contra (A ==> C)]
---
> * Suppose [ic1 Variance.Contra A] returns [A ==> B], and [ic2 Variance.Co C] returns [D ==> C],
> * then [IMP_IMPCONV ic1 ic2 Variance.Co (A ==> C)] returns [(B ==> D) ==> (A ==> C)].
> * Suppose [ic1 Variance.Co A] returns [B ==> A], and [ic2 Variance.Contra C] returns
> * [C ==> D], then [IMP_IMPCONV ic1 ic2 Variance.Contra (A ==> C)]
891,892c891,892
< * Additionally takes the context into account, i.e., if [ic2 Co C] returns
< * [B |- D ==> C], then [IMP_IMPCONV ic1 ic2 Co (A ==> C)] returns
---
> * Additionally takes the context into account, i.e., if [ic2 Variance.Co C] returns
> * [B |- D ==> C], then [IMP_IMPCONV ic1 ic2 Variance.Co (A ==> C)] returns
906c906
< match v with Co -> MKIMP_IMP_CO_CTXT | Contra -> MKIMP_IMP_CONTRA_CTXT
---
> match v with Variance.Co -> MKIMP_IMP_CO_CTXT | Variance.Contra -> MKIMP_IMP_CONTRA_CTXT
921,922c921,922
< |Co -> MKIMP_CO_IFF,MKIMPL_CO_IFF,MKIMPR_CO_IFF
< |Contra -> MKIMP_CONTRA_IFF,MKIMPL_CONTRA_IFF,MKIMPR_CONTRA_IFF
---
> |Variance.Co -> MKIMP_CO_IFF,MKIMPL_CO_IFF,MKIMPR_CO_IFF
> |Variance.Contra -> MKIMP_CONTRA_IFF,MKIMPL_CONTRA_IFF,MKIMPR_CONTRA_IFF
935,938c935,938
< * Suppose [ic Contra A] returns [A ==> B]
< * then [NOT_IMPCONV ic Co ~A] returns [~B ==> ~A].
< * Suppose [ic Co A] returns [B ==> A]
< * then [NOT_IMPCONV ic Contra ~A] returns [~A ==> ~B].
---
> * Suppose [ic Variance.Contra A] returns [A ==> B]
> * then [NOT_IMPCONV ic Variance.Co ~A] returns [~B ==> ~A].
> * Suppose [ic Variance.Co A] returns [B ==> A]
> * then [NOT_IMPCONV ic Variance.Contra ~A] returns [~A ==> ~B].
956,959c956,959
< * Suppose [ic Co A] returns [B ==> A]
< * then [FORALL_IMPCONV ic Co (!x.A)] returns [(!x.B) ==> (!x.A)].
< * Suppose [ic Contra A] returns [A ==> B]
< * then [FORALL_IMPCONV ic Contra (!x.A)] returns [(!x.A) ==> (!x.B)].
---
> * Suppose [ic Variance.Co A] returns [B ==> A]
> * then [FORALL_IMPCONV ic Variance.Co (!x.A)] returns [(!x.B) ==> (!x.A)].
> * Suppose [ic Variance.Contra A] returns [A ==> B]
> * then [FORALL_IMPCONV ic Variance.Contra (!x.A)] returns [(!x.A) ==> (!x.B)].
964,967c964,967
< * Suppose [ic Co A] returns [B ==> A]
< * then [EXISTS_IMPCONV ic Co (?x.A)] returns [(?x.B) ==> (?x.A)].
< * Suppose [ic Contra A] returns [A ==> B]
< * then [EXISTS_IMPCONV ic Contra (?x.A)] returns [(?x.A) ==> (?x.B)].
---
> * Suppose [ic Variance.Co A] returns [B ==> A]
> * then [EXISTS_IMPCONV ic Variance.Co (?x.A)] returns [(?x.B) ==> (?x.A)].
> * Suppose [ic Variance.Contra A] returns [A ==> B]
> * then [EXISTS_IMPCONV ic Variance.Contra (?x.A)] returns [(?x.A) ==> (?x.B)].
972c972
< let rec SUB_CTXIMPCONV =
---
> let SUB_CTXIMPCONV =
974c974
< fun c ->
---
> let rec SUB_CTXIMPCONV c =
990a991
> in SUB_CTXIMPCONV;;
998,999c999,1000
< |Co -> IMP_TRANS (apply c v t1) th
< |Contra -> IMP_TRANS th (apply c v t2)
---
> |Variance.Co -> IMP_TRANS (apply c v t1) th
> |Variance.Contra -> IMP_TRANS th (apply c v t2)
1051,1072c1052,1070
< let rec REPEAT_UNCHANGED_CTXIMPCONV =
< let rec map_all f xs x =
< match xs with
< |[] -> []
< |y::ys -> f y x :: map_all f ys x
< in
< fun (cs:imp_conv with_context list) ->
< With_context(
< ((fun v t ->
< let rec loop changed acc = function
< |[] when changed -> loop false acc cs
< |[] -> acc
< |c::cs' ->
< try
< let acc' = bind_ctximpconv c v acc in
< loop true acc' cs'
< with Unchanged -> loop changed acc cs'
< in
< loop false (IMP_REFL t) cs):imp_conv),
< REPEAT_UNCHANGED_CTXIMPCONV o map_all augment cs,
< REPEAT_UNCHANGED_CTXIMPCONV o map_all diminish cs)
<
---
> let rec map_all f xs x =
> match xs with
> |[] -> []
> |y::ys -> f y x :: map_all f ys x ;;
> let rec REPEAT_UNCHANGED_CTXIMPCONV (cs:imp_conv with_context list) =
> With_context(
> ((fun v t ->
> let rec loop changed acc = function
> |[] when changed -> loop false acc cs
> |[] -> acc
> |c::cs' ->
> try
> let acc' = bind_ctximpconv c v acc in
> loop true acc' cs'
> with Unchanged -> loop changed acc cs'
> in
> loop false (IMP_REFL t) cs):imp_conv),
> REPEAT_UNCHANGED_CTXIMPCONV o map_all augment cs,
> REPEAT_UNCHANGED_CTXIMPCONV o map_all diminish cs);;
1080,1081c1078,1079
< |Co -> IMP_TRANS (apply c na v t1) th
< |Contra -> IMP_TRANS th (apply c na v t2)
---
> |Variance.Co -> IMP_TRANS (apply c na v t1) th
> |Variance.Contra -> IMP_TRANS th (apply c na v t2)
1127c1125
< MATCH_MP (apply c Contra (concl th)) th
---
> MATCH_MP (apply c Variance.Contra (concl th)) th
1130c1128
< fun (asms,c as g) ->
---
> fun ((asms,c) as g) ->
1132c1130
< (MATCH_MP_TAC (apply cnv' Co c) THEN TRY (ACCEPT_TAC TRUTH)) g
---
> (MATCH_MP_TAC (apply cnv' Variance.Co c) THEN TRY (ACCEPT_TAC TRUTH)) g
1186c1184
< let IMPREWR_CONV:Tset.t->thm->annot_conv =
---
> let (IMPREWR_CONV:(*Tset.t*)term list->thm->annot_conv) =
1202c1200
< let th,_,_ as res = cnv t in
---
> let (th,_,_) as res = cnv t in
1258c1256
< (net:((term list -> annot_conv) * Tset.t * thm) Fo_nets.t) avs t =
---
> (net:((term list -> annot_conv) * (*Tset.t*)term list * thm) Fo_nets.t) avs t =
1264c1262
< let IMPREWR_CTXCONV :thm list -> (atomic->annot_conv) with_context =
---
> let (IMPREWR_CTXCONV :thm list -> (atomic->annot_conv) with_context) =
1268,1269c1266,1267
< |_,Some _,_ as c1t -> c1t
< |th1,None,vs1 as c1t ->
---
> |(_,Some _,_) as c1t -> c1t
> |(th1,None,vs1) as c1t ->
1298c1296
< res,!ho,!vs
---
> res,(!ho),(!vs)
1301,1302c1299,1300
< let rec (!) c avs t = (c ++ !c) avs t in
< (!c + (SUB_QCONV (top_depth c) ++ top_depth c)) avs t
---
> let rec (!) c avs t = (c ++ (!c)) avs t in
> ((!c) + (SUB_QCONV (top_depth c) ++ top_depth c)) avs t
1324c1322
< if not (Tset.mem v vs) then (ths := th :: !ths; true) else false
---
> if not (Tset.mem v vs) then (ths := th :: (!ths); true) else false
1327c1325
< self net' !ths))
---
> self net' (!ths)))
1342c1340
< let rec REWR_IMPCONV_OF_CONV =
---
> let REWR_IMPCONV_OF_CONV =
1346c1344
< fun (c:(atomic -> annot_conv) with_context) ->
---
> let rec REWR_IMPCONV_OF_CONV (c:(atomic -> annot_conv) with_context) =
1353c1351
< |Co ->
---
> |Variance.Co ->
1355c1353
< let rec exists_intro = function
---
> let rec exists_intro vs = match vs with
1362c1360
< |Contra ->
---
> |Variance.Contra ->
1373c1371,1372
< REWR_IMPCONV_OF_CONV o diminish c)
---
> REWR_IMPCONV_OF_CONV o diminish c) in
> REWR_IMPCONV_OF_CONV;;
1413c1412
< let rec CASE_REWR_IMPCONV_OF_CONV =
---
> let CASE_REWR_IMPCONV_OF_CONV =
1417c1416
< fun (c:(atomic -> annot_conv) with_context) ->
---
> let rec CASE_REWR_IMPCONV_OF_CONV (c:(atomic -> annot_conv) with_context) =
1427c1426,1427
< CASE_REWR_IMPCONV_OF_CONV o diminish c)
---
> CASE_REWR_IMPCONV_OF_CONV o diminish c) in
> CASE_REWR_IMPCONV_OF_CONV;;
1446,1448c1446,1448
< * Suppose [ic1 Co A] returns a list [B1 ==> A; ...; Bk ==> A],
< * and [ic2 Co C] returns [D1 ==> C; ...; Dn ==> C],
< * then [CONJ_IMPMCONV ic1 ic2 Co (A /\ C)] returns
---
> * Suppose [ic1 Variance.Co A] returns a list [B1 ==> A; ...; Bk ==> A],
> * and [ic2 Variance.Co C] returns [D1 ==> C; ...; Dn ==> C],
> * then [CONJ_IMPMCONV ic1 ic2 Variance.Co (A /\ C)] returns
1461,1462c1461,1462
< |Co -> MKIMPL_CONJ_CO2_CTXT,MKIMPR_CONJ_CO_CTXT
< |Contra -> MKIMPL_CONJ_CONTRA_CTXT,MKIMPR_CONJ_CONTRA_CTXT
---
> |Variance.Co -> MKIMPL_CONJ_CO2_CTXT,MKIMPR_CONJ_CO_CTXT
> |Variance.Contra -> MKIMPL_CONJ_CONTRA_CTXT,MKIMPR_CONJ_CONTRA_CTXT
1471,1473c1471,1473
< * Suppose [ic1 Co A] returns a list [B1 ==> A; ...; Bk ==> A],
< * and [ic2 Co C] returns [D1 ==> C; ...; Dn ==> C],
< * then [DISJ_IMPMCONV ic1 ic2 Co (A \/ C)] returns
---
> * Suppose [ic1 Variance.Co A] returns a list [B1 ==> A; ...; Bk ==> A],
> * and [ic2 Variance.Co C] returns [D1 ==> C; ...; Dn ==> C],
> * then [DISJ_IMPMCONV ic1 ic2 Variance.Co (A \/ C)] returns
1491,1493c1491,1493
< * Suppose [ic1 Contra A] returns a list [A ==> B1; ...; A ==> Bk],
< * and [ic2 Co C] returns [D1 ==> C; ...; Dn ==> C],
< * then [DISJ_IMPMCONV ic1 ic2 Co (A \/ C)] returns
---
> * Suppose [ic1 Variance.Contra A] returns a list [A ==> B1; ...; A ==> Bk],
> * and [ic2 Variance.Co C] returns [D1 ==> C; ...; Dn ==> C],
> * then [DISJ_IMPMCONV ic1 ic2 Variance.Co (A \/ C)] returns
1516,1517c1516,1517
< |Co -> MKIMPL_CO_IFF,MKIMPR_CO_IFF
< |Contra -> MKIMPL_CONTRA_IFF,MKIMPR_CONTRA_IFF
---
> |Variance.Co -> MKIMPL_CO_IFF,MKIMPR_CO_IFF