-
Notifications
You must be signed in to change notification settings - Fork 0
/
OCL_Types.thy
1794 lines (1548 loc) · 80.8 KB
/
OCL_Types.thy
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
(* Title: Safe OCL
Author: Denis Nikiforov, March 2019
Maintainer: Denis Nikiforov <denis.nikif at gmail.com>
License: LGPL
*)
chapter \<open>Types\<close>
theory OCL_Types
imports Tuple Errorable "HOL-Library.Phantom_Type"
begin
(*** Definition *************************************************************)
section \<open>Definition\<close>
text \<open>
Types are parameterized over classes.\<close>
type_synonym 'a enum_type = "('a, String.literal) phantom"
type_synonym elit = String.literal
type_synonym telem = String.literal
datatype collection_kind =
CollectionKind | SetKind | OrderedSetKind | BagKind | SequenceKind
datatype (plugins del: size) 'a type =
OclAny
| OclVoid
| Boolean
| Real
| Integer
| UnlimitedNatural
| String
| Enum "'a enum_type"
| ObjectType 'a ("\<langle>_\<rangle>\<^sub>\<T>" [0] 1000)
| Tuple "telem \<rightharpoonup>\<^sub>f 'a type\<^sub>N"
| Collection "'a type\<^sub>N"
| Set "'a type\<^sub>N"
| OrderedSet "'a type\<^sub>N"
| Bag "'a type\<^sub>N"
| Sequence "'a type\<^sub>N"
| Map "'a type\<^sub>N" "'a type\<^sub>N"
and 'a type\<^sub>N =
Required "'a type" ("_[\<^bold>1]" [1000] 1000)
| Optional "'a type" ("_[\<^bold>?]" [1000] 1000)
type_synonym 'a type\<^sub>N\<^sub>E = "'a type\<^sub>N errorable"
primrec type_size :: "'a type \<Rightarrow> nat"
and type_size\<^sub>N :: "'a type\<^sub>N \<Rightarrow> nat" where
"type_size OclAny = 0"
| "type_size OclVoid = 0"
| "type_size Boolean = 0"
| "type_size Real = 0"
| "type_size Integer = 0"
| "type_size UnlimitedNatural = 0"
| "type_size String = 0"
| "type_size (Enum \<E>) = 0"
| "type_size (ObjectType \<C>) = 0"
| "type_size (Tuple \<pi>) = Suc (ffold tcf 0 (fset_of_fmap (fmmap type_size\<^sub>N \<pi>)))"
| "type_size (Collection \<tau>) = Suc (type_size\<^sub>N \<tau>)"
| "type_size (Set \<tau>) = Suc (type_size\<^sub>N \<tau>)"
| "type_size (OrderedSet \<tau>) = Suc (type_size\<^sub>N \<tau>)"
| "type_size (Bag \<tau>) = Suc (type_size\<^sub>N \<tau>)"
| "type_size (Sequence \<tau>) = Suc (type_size\<^sub>N \<tau>)"
| "type_size (Map \<tau> \<sigma>) = Suc (type_size\<^sub>N \<tau> + type_size\<^sub>N \<sigma>)"
| "type_size\<^sub>N (Required \<tau>) = Suc (type_size \<tau>)"
| "type_size\<^sub>N (Optional \<tau>) = Suc (type_size \<tau>)"
lemma Tuple_type_size\<^sub>N_intro [intro]:
"\<tau> |\<in>| fmran \<pi> \<Longrightarrow>
type_size\<^sub>N \<tau> < Suc (ffold tcf 0 (fset_of_fmap (fmmap type_size\<^sub>N \<pi>)))"
using fmran'I by fastforce
instantiation type :: (type) size
begin
definition size_type where [simp, code]: "size_type \<equiv> type_size"
instance ..
end
instantiation type\<^sub>N :: (type) size
begin
definition size_type\<^sub>N where [simp, code]: "size_type\<^sub>N \<equiv> type_size\<^sub>N"
instance ..
end
text \<open>
Please take a note that the @{text "UnlimitedNatural"} type is not a subtype
of the @{text "Integer"} type.\<close>
inductive subtype :: "'a::order type \<Rightarrow> 'a type \<Rightarrow> bool" (infix "\<sqsubset>" 65)
and subtype\<^sub>N :: "'a type\<^sub>N \<Rightarrow> 'a type\<^sub>N \<Rightarrow> bool" (infix "\<sqsubset>\<^sub>N" 65) where
\<comment> \<open>Basic Types\<close>
"OclVoid \<sqsubset> Boolean"
| "OclVoid \<sqsubset> Integer"
| "OclVoid \<sqsubset> UnlimitedNatural"
| "OclVoid \<sqsubset> String"
| "OclVoid \<sqsubset> \<langle>\<C>\<rangle>\<^sub>\<T>"
| "OclVoid \<sqsubset> Enum \<E>"
| "Integer \<sqsubset> Real"
| "\<C> < \<D> \<Longrightarrow> \<langle>\<C>\<rangle>\<^sub>\<T> \<sqsubset> \<langle>\<D>\<rangle>\<^sub>\<T>"
| "Boolean \<sqsubset> OclAny"
| "Real \<sqsubset> OclAny"
| "UnlimitedNatural \<sqsubset> OclAny"
| "String \<sqsubset> OclAny"
| "\<langle>\<C>\<rangle>\<^sub>\<T> \<sqsubset> OclAny"
| "Enum \<E> \<sqsubset> OclAny"
\<comment> \<open>Tuple Types\<close>
| "OclVoid \<sqsubset> Tuple \<pi>"
| "strict_subtuple (\<lambda>\<tau> \<sigma>. \<tau> \<sqsubset>\<^sub>N \<sigma> \<or> \<tau> = \<sigma>) \<pi> \<xi> \<Longrightarrow>
Tuple \<pi> \<sqsubset> Tuple \<xi>"
| "Tuple \<pi> \<sqsubset> OclAny"
\<comment> \<open>Collection Types\<close>
| "OclVoid \<sqsubset> Set OclVoid[\<^bold>1]"
| "OclVoid \<sqsubset> OrderedSet OclVoid[\<^bold>1]"
| "OclVoid \<sqsubset> Bag OclVoid[\<^bold>1]"
| "OclVoid \<sqsubset> Sequence OclVoid[\<^bold>1]"
| "\<tau> \<sqsubset>\<^sub>N \<sigma> \<Longrightarrow> Collection \<tau> \<sqsubset> Collection \<sigma>"
| "\<tau> \<sqsubset>\<^sub>N \<sigma> \<Longrightarrow> Set \<tau> \<sqsubset> Set \<sigma>"
| "\<tau> \<sqsubset>\<^sub>N \<sigma> \<Longrightarrow> OrderedSet \<tau> \<sqsubset> OrderedSet \<sigma>"
| "\<tau> \<sqsubset>\<^sub>N \<sigma> \<Longrightarrow> Bag \<tau> \<sqsubset> Bag \<sigma>"
| "\<tau> \<sqsubset>\<^sub>N \<sigma> \<Longrightarrow> Sequence \<tau> \<sqsubset> Sequence \<sigma>"
| "Set \<tau> \<sqsubset> Collection \<tau>"
| "OrderedSet \<tau> \<sqsubset> Collection \<tau>"
| "Bag \<tau> \<sqsubset> Collection \<tau>"
| "Sequence \<tau> \<sqsubset> Collection \<tau>"
| "Collection OclAny[\<^bold>?] \<sqsubset> OclAny"
\<comment> \<open>Map Types\<close>
| "OclVoid \<sqsubset> Map \<tau> \<sigma>"
| "\<sigma> \<sqsubset>\<^sub>N \<upsilon> \<Longrightarrow> Map \<tau> \<sigma> \<sqsubset> Map \<tau> \<upsilon>"
| "\<tau> \<sqsubset>\<^sub>N \<rho> \<Longrightarrow> Map \<tau> \<sigma> \<sqsubset> Map \<rho> \<sigma>"
| "Map \<tau> \<sigma> \<sqsubset> OclAny"
\<comment> \<open>Nullable Types\<close>
| "\<tau> \<sqsubset> \<sigma> \<Longrightarrow> Required \<tau> \<sqsubset>\<^sub>N Required \<sigma>"
| "\<tau> \<sqsubset> \<sigma> \<Longrightarrow> Optional \<tau> \<sqsubset>\<^sub>N Optional \<sigma>"
| "Required \<tau> \<sqsubset>\<^sub>N Optional \<tau>"
declare subtype_subtype\<^sub>N.intros [intro!]
inductive_cases subtype_x_OclAny [elim!]: "\<tau> \<sqsubset> OclAny"
inductive_cases subtype_x_OclVoid [elim!]: "\<tau> \<sqsubset> OclVoid"
inductive_cases subtype_x_Boolean [elim!]: "\<tau> \<sqsubset> Boolean"
inductive_cases subtype_x_Real [elim!]: "\<tau> \<sqsubset> Real"
inductive_cases subtype_x_Integer [elim!]: "\<tau> \<sqsubset> Integer"
inductive_cases subtype_x_UnlimitedNatural [elim!]: "\<tau> \<sqsubset> UnlimitedNatural"
inductive_cases subtype_x_String [elim!]: "\<tau> \<sqsubset> String"
inductive_cases subtype_x_Enum [elim!]: "\<tau> \<sqsubset> Enum \<E>"
inductive_cases subtype_x_ObjectType [elim!]: "\<tau> \<sqsubset> ObjectType \<C>"
inductive_cases subtype_x_Tuple [elim!]: "\<tau> \<sqsubset> Tuple \<pi>"
inductive_cases subtype_x_Collection [elim!]: "\<tau> \<sqsubset> Collection \<sigma>"
inductive_cases subtype_x_Set [elim!]: "\<tau> \<sqsubset> Set \<sigma>"
inductive_cases subtype_x_OrderedSet [elim!]: "\<tau> \<sqsubset> OrderedSet \<sigma>"
inductive_cases subtype_x_Bag [elim!]: "\<tau> \<sqsubset> Bag \<sigma>"
inductive_cases subtype_x_Sequence [elim!]: "\<tau> \<sqsubset> Sequence \<sigma>"
inductive_cases subtype_x_Map [elim!]: "\<tau> \<sqsubset> Map \<rho> \<upsilon>"
inductive_cases subtype_x_Required [elim!]: "\<tau> \<sqsubset>\<^sub>N Required \<sigma>"
inductive_cases subtype_x_Optional [elim!]: "\<tau> \<sqsubset>\<^sub>N Optional \<sigma>"
inductive_cases subtype_OclAny_x [elim!]: "OclAny \<sqsubset> \<sigma>"
inductive_cases subtype_Collection_x [elim!]: "Collection \<tau> \<sqsubset> \<sigma>"
inductive_cases subtype_Map_x [elim!]: "Map \<tau> \<sigma> \<sqsubset> \<psi>"
lemma
subtype_asym: "\<tau> \<sqsubset> \<sigma> \<Longrightarrow> \<sigma> \<sqsubset> \<tau> \<Longrightarrow> False" and
subtype\<^sub>N_asym: "\<tau>\<^sub>N \<sqsubset>\<^sub>N \<sigma>\<^sub>N \<Longrightarrow> \<sigma>\<^sub>N \<sqsubset>\<^sub>N \<tau>\<^sub>N \<Longrightarrow> False"
for \<tau> \<sigma> :: "'a :: order type"
and \<tau>\<^sub>N \<sigma>\<^sub>N :: "'a type\<^sub>N"
apply (induct rule: subtype_subtype\<^sub>N.inducts, auto)
using subtuple_antisym by fastforce
(*** Notation ***************************************************************)
section \<open>Notation\<close>
notation to_error_free_type ("_\<lbrakk>.\<rbrakk>" [1000] 1000)
notation to_errorable_type ("_\<lbrakk>.!\<rbrakk>" [1000] 1000)
fun required_type\<^sub>N where
"required_type\<^sub>N (Required \<tau>) = True"
| "required_type\<^sub>N (Optional \<tau>) = False"
fun required_type where
"required_type (ErrorFree \<tau>) = required_type\<^sub>N \<tau>"
| "required_type (Errorable \<tau>) = required_type\<^sub>N \<tau>"
abbreviation "optional_type\<^sub>N \<tau> \<equiv> \<not> required_type\<^sub>N \<tau>"
abbreviation "optional_type \<tau> \<equiv> \<not> required_type \<tau>"
fun to_required_type\<^sub>N where
"to_required_type\<^sub>N (Required \<tau>) = Required \<tau>"
| "to_required_type\<^sub>N (Optional \<tau>) = Required \<tau>"
abbreviation to_required_type ("_\<lbrakk>1.\<rbrakk>" [1000] 1000) where
"to_required_type \<equiv> map_errorable to_required_type\<^sub>N"
(* Is it realy required? Maybe it is better to check types intersection? *)
fun to_optional_type_nested\<^sub>T
and to_optional_type_nested\<^sub>N where
"to_optional_type_nested\<^sub>T OclAny = OclAny"
| "to_optional_type_nested\<^sub>T OclVoid = OclVoid"
| "to_optional_type_nested\<^sub>T Boolean = Boolean"
| "to_optional_type_nested\<^sub>T Real = Real"
| "to_optional_type_nested\<^sub>T Integer = Integer"
| "to_optional_type_nested\<^sub>T UnlimitedNatural = UnlimitedNatural"
| "to_optional_type_nested\<^sub>T String = String"
| "to_optional_type_nested\<^sub>T (Enum \<E>) = Enum \<E>"
| "to_optional_type_nested\<^sub>T (ObjectType \<C>) = ObjectType \<C>"
| "to_optional_type_nested\<^sub>T (Tuple \<pi>) =
Tuple (fmmap to_optional_type_nested\<^sub>N \<pi>)"
| "to_optional_type_nested\<^sub>T (Collection \<tau>) =
Collection (to_optional_type_nested\<^sub>N \<tau>)"
| "to_optional_type_nested\<^sub>T (Set \<tau>) =
Set (to_optional_type_nested\<^sub>N \<tau>)"
| "to_optional_type_nested\<^sub>T (OrderedSet \<tau>) =
OrderedSet (to_optional_type_nested\<^sub>N \<tau>)"
| "to_optional_type_nested\<^sub>T (Bag \<tau>) =
Bag (to_optional_type_nested\<^sub>N \<tau>)"
| "to_optional_type_nested\<^sub>T (Sequence \<tau>) =
Sequence (to_optional_type_nested\<^sub>N \<tau>)"
| "to_optional_type_nested\<^sub>T (Map \<tau> \<sigma>) =
Map (to_optional_type_nested\<^sub>N \<tau>) (to_optional_type_nested\<^sub>N \<sigma>)"
| "to_optional_type_nested\<^sub>N (Required \<tau>) = Optional (to_optional_type_nested\<^sub>T \<tau>)"
| "to_optional_type_nested\<^sub>N (Optional \<tau>) = Optional (to_optional_type_nested\<^sub>T \<tau>)"
abbreviation to_optional_type_nested ("_\<lbrakk>??.\<rbrakk>" [1000] 1000) where
"to_optional_type_nested \<equiv> map_errorable to_optional_type_nested\<^sub>N"
abbreviation Required_ErrorFree ("_[1]" [1000] 1000) where
"Required_ErrorFree \<tau> \<equiv> ErrorFree (Required \<tau>)"
abbreviation Optional_ErrorFree ("_[?]" [1000] 1000) where
"Optional_ErrorFree \<tau> \<equiv> ErrorFree (Optional \<tau>)"
abbreviation Required_Errorable ("_[1!]" [1000] 1000) where
"Required_Errorable \<tau> \<equiv> Errorable (Required \<tau>)"
abbreviation Optional_Errorable ("_[?!]" [1000] 1000) where
"Optional_Errorable \<tau> \<equiv> Errorable (Optional \<tau>)"
(*** Constructors Bijectivity on Transitive Closures ************************)
section \<open>Constructors Bijectivity on Transitive Closures\<close>
lemma Tuple_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>) Tuple"
unfolding inj_def
using tranclp.cases by fastforce
lemma subtype_tranclp_Collection_x:
"(\<sqsubset>)\<^sup>+\<^sup>+ (Collection \<tau>) \<sigma> \<Longrightarrow>
(\<And>\<rho>. \<sigma> = Collection \<rho> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau> \<rho> \<Longrightarrow> P) \<Longrightarrow>
(\<sigma> = OclAny \<Longrightarrow> P) \<Longrightarrow> P"
apply (induct rule: tranclp_induct)
apply auto[1]
by (metis subtype_Collection_x subtype_OclAny_x tranclp.trancl_into_trancl)
lemma Collection_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>) Collection"
unfolding inj_def
using subtype_tranclp_Collection_x by auto
lemma Set_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>) Set"
unfolding inj_def
using tranclp.cases by fastforce
lemma OrderedSet_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>) OrderedSet"
unfolding inj_def
using tranclp.cases by fastforce
lemma Bag_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>) Bag"
unfolding inj_def
using tranclp.cases by fastforce
lemma Sequence_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>) Sequence"
unfolding inj_def
using tranclp.cases by fastforce
lemma subtype_tranclp_x_Map_key:
"(\<sqsubset>)\<^sup>+\<^sup>+ (Map \<tau> \<sigma>) (Map \<rho> \<upsilon>) \<Longrightarrow>
((\<And>\<tau>'. \<tau> = \<tau>' \<Longrightarrow> \<sigma> = \<upsilon> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau>' \<rho> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<sigma>'. \<tau> = \<rho> \<Longrightarrow> \<sigma> = \<sigma>' \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma>' \<upsilon> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<tau>' \<sigma>'. \<tau> = \<tau>' \<Longrightarrow> \<sigma> = \<sigma>' \<Longrightarrow>
(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau>' \<rho> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma>' \<upsilon> \<Longrightarrow> P) \<Longrightarrow> P) \<Longrightarrow>
((\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau>' \<rho> \<Longrightarrow> P) \<Longrightarrow>
(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau>' \<tau> \<Longrightarrow> P"
by (metis tranclp_trans)
lemma subtype_tranclp_x_Map_value:
"(\<sqsubset>)\<^sup>+\<^sup>+ (Map \<tau> \<sigma>) (Map \<rho> \<upsilon>) \<Longrightarrow>
((\<And>\<tau>'. \<tau> = \<tau>' \<Longrightarrow> \<sigma> = \<upsilon> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau>' \<rho> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<sigma>'. \<tau> = \<rho> \<Longrightarrow> \<sigma> = \<sigma>' \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma>' \<upsilon> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<tau>' \<sigma>'. \<tau> = \<tau>' \<Longrightarrow> \<sigma> = \<sigma>' \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau>' \<rho> \<Longrightarrow>
(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma>' \<upsilon> \<Longrightarrow> P) \<Longrightarrow> P) \<Longrightarrow>
((\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma>' \<upsilon> \<Longrightarrow> P) \<Longrightarrow>
(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma>' \<sigma> \<Longrightarrow> P"
by (metis tranclp_trans)
lemma subtype_tranclp_x_Map:
"(\<sqsubset>)\<^sup>+\<^sup>+ \<phi> (Map \<tau> \<sigma>) \<Longrightarrow>
(\<And>\<rho>. \<phi> = Map \<rho> \<sigma> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<rho> \<tau> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<upsilon>. \<phi> = Map \<tau> \<upsilon> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<upsilon> \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<rho> \<upsilon>. \<phi> = Map \<rho> \<upsilon> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<rho> \<tau> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<upsilon> \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<phi> = OclVoid \<Longrightarrow> P) \<Longrightarrow> P"
apply (induct rule: converse_tranclp_induct)
apply auto[1]
apply (erule subtype.cases; simp)
apply (drule subtype_tranclp_x_Map_value; auto)
apply (drule subtype_tranclp_x_Map_key; auto)
done
lemma Map_key_bij_on_trancl [simp]:
"((\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma> \<sigma> \<Longrightarrow> False) \<Longrightarrow> bij_on_trancl (\<sqsubset>) (\<lambda>\<tau>. Map \<tau> \<sigma>)"
apply (auto simp add: inj_def)
using tranclp.cases apply fastforce
by (erule subtype_tranclp_x_Map; simp add: tranclp.trancl_into_trancl)
lemma Map_value_bij_on_trancl [simp]:
"((\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau> \<tau> \<Longrightarrow> False) \<Longrightarrow> bij_on_trancl (\<sqsubset>) (\<lambda>\<sigma>. Map \<tau> \<sigma>)"
apply (auto simp add: inj_def)
using tranclp.cases apply fastforce
by (erule subtype_tranclp_x_Map; simp add: tranclp.trancl_into_trancl)
lemma Required_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>\<^sub>N) Required"
by (auto simp add: inj_def)
lemma not_subtype_Optional_Required:
"(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ (Optional \<tau>) \<sigma> \<Longrightarrow> \<sigma> = Required \<rho> \<Longrightarrow> P"
by (induct arbitrary: \<rho> rule: tranclp_induct; auto)
lemma Optional_bij_on_trancl [simp]:
"bij_on_trancl (\<sqsubset>\<^sub>N) Optional"
unfolding inj_def
using not_subtype_Optional_Required by blast
(*** Partial Order of Types *************************************************)
section \<open>Partial Order of Types\<close>
instantiation type :: (order) ord
begin
definition "(<) \<equiv> (\<sqsubset>)\<^sup>+\<^sup>+"
definition "(\<le>) \<equiv> (\<sqsubset>)\<^sup>*\<^sup>*"
instance ..
end
instantiation type\<^sub>N :: (order) ord
begin
definition "(<) \<equiv> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+"
definition "(\<le>) \<equiv> (\<sqsubset>\<^sub>N)\<^sup>*\<^sup>*"
instance ..
end
(*** Strict Introduction Rules **********************************************)
subsection \<open>Strict Introduction Rules\<close>
lemma type_less_x_OclAny_intro [intro]:
"\<tau> \<noteq> OclAny \<Longrightarrow> \<tau> < OclAny"
"\<tau>\<^sub>N \<noteq> Optional OclAny \<Longrightarrow> \<tau>\<^sub>N < Optional OclAny"
for \<tau> :: "'a :: order type"
and \<tau>\<^sub>N :: "'a type\<^sub>N"
proof (induct \<tau> and \<tau>\<^sub>N)
case OclAny thus ?case by simp
next
case OclVoid
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid Boolean" by auto
also have "(\<sqsubset>)\<^sup>+\<^sup>+ Boolean OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case Boolean show ?case unfolding less_type_def by auto
next
case Real show ?case unfolding less_type_def by auto
next
case Integer
have "(\<sqsubset>)\<^sup>+\<^sup>+ Integer Real" by auto
also have "(\<sqsubset>)\<^sup>+\<^sup>+ Real OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case UnlimitedNatural show ?case unfolding less_type_def by auto
next
case String show ?case unfolding less_type_def by auto
next
case (Enum \<E>) show ?case unfolding less_type_def by auto
next
case (ObjectType \<C>) show ?case unfolding less_type_def by auto
next
case (Tuple \<pi>) show ?case unfolding less_type_def by auto
next
case (Collection \<tau>)
from Collection.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Collection \<tau>) (Collection OclAny[\<^bold>?])"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
also have "(\<sqsubset>)\<^sup>+\<^sup>+ (Collection OclAny[\<^bold>?]) OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case (Set \<tau>)
have "(\<sqsubset>)\<^sup>*\<^sup>* (Set \<tau>) (Collection \<tau>)" by auto
also from Set.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Collection \<tau>) (Collection OclAny[\<^bold>?])"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
also have "(\<sqsubset>)\<^sup>+\<^sup>+ (Collection OclAny[\<^bold>?]) OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case (OrderedSet \<tau>)
have "(\<sqsubset>)\<^sup>*\<^sup>* (OrderedSet \<tau>) (Collection \<tau>)" by auto
also from OrderedSet.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Collection \<tau>) (Collection OclAny[\<^bold>?])"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
also have "(\<sqsubset>)\<^sup>+\<^sup>+ (Collection OclAny[\<^bold>?]) OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case (Bag \<tau>)
have "(\<sqsubset>)\<^sup>*\<^sup>* (Bag \<tau>) (Collection \<tau>)" by auto
also from Bag.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Collection \<tau>) (Collection OclAny[\<^bold>?])"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
also have "(\<sqsubset>)\<^sup>+\<^sup>+ (Collection OclAny[\<^bold>?]) OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case (Sequence \<tau>)
have "(\<sqsubset>)\<^sup>*\<^sup>* (Sequence \<tau>) (Collection \<tau>)" by auto
also from Sequence.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Collection \<tau>) (Collection OclAny[\<^bold>?])"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
also have "(\<sqsubset>)\<^sup>+\<^sup>+ (Collection OclAny[\<^bold>?]) OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case (Map \<tau> \<sigma>) show ?case unfolding less_type_def by auto
next
case (Required \<tau>)
have "(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ (Required \<tau>) (Optional \<tau>)" by auto
also from Required.hyps
have "(\<sqsubset>\<^sub>N)\<^sup>*\<^sup>* (Optional \<tau>) (Optional OclAny)"
unfolding less_type_def
by (rule_tac ?R="(\<sqsubset>)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
finally show ?case unfolding less_type\<^sub>N_def by simp
next
case (Optional \<tau>) thus ?case
unfolding less_type_def less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>)" in preserve_tranclp, auto)
qed
lemma type_less_OclVoid_x_intro [intro]:
"\<tau> \<noteq> OclVoid \<Longrightarrow> OclVoid < \<tau>"
"\<tau>\<^sub>N \<noteq> Required OclVoid \<Longrightarrow> Required OclVoid < \<tau>\<^sub>N"
for \<tau> :: "'a :: order type"
and \<tau>\<^sub>N :: "'a type\<^sub>N"
proof (induct \<tau> and \<tau>\<^sub>N)
case OclAny
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid Boolean" by auto
also have "(\<sqsubset>)\<^sup>+\<^sup>+ Boolean OclAny" by auto
finally show ?case unfolding less_type_def by simp
next
case OclVoid thus ?case by simp
next
case Boolean show ?case unfolding less_type_def by auto
next
case Real
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid Integer" by auto
also have "(\<sqsubset>)\<^sup>+\<^sup>+ Integer Real" by auto
finally show ?case unfolding less_type_def by simp
next
case Integer show ?case unfolding less_type_def by auto
next
case UnlimitedNatural show ?case unfolding less_type_def by auto
next
case String show ?case unfolding less_type_def by auto
next
case (Enum \<E>) show ?case unfolding less_type_def by auto
next
case (ObjectType \<C>) show ?case unfolding less_type_def by auto
next
case (Tuple \<pi>) show ?case unfolding less_type_def by auto
next
case (Collection \<tau>)
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid (Set OclVoid[\<^bold>1])" by auto
also from Collection.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Set OclVoid[\<^bold>1]) (Set \<tau>)"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
also have "(\<sqsubset>)\<^sup>+\<^sup>+ (Set \<tau>) (Collection \<tau>)" by auto
finally show ?case unfolding less_type_def by simp
next
case (Set \<tau>)
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid (Set OclVoid[\<^bold>1])" by auto
also from Set.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Set OclVoid[\<^bold>1]) (Set \<tau>)"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
finally show ?case unfolding less_type_def by simp
next
case (OrderedSet \<tau>)
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid (OrderedSet OclVoid[\<^bold>1])" by auto
also from OrderedSet.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (OrderedSet OclVoid[\<^bold>1]) (OrderedSet \<tau>)"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
finally show ?case unfolding less_type_def by simp
next
case (Bag \<tau>)
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid (Bag OclVoid[\<^bold>1])" by auto
also from Bag.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Bag OclVoid[\<^bold>1]) (Bag \<tau>)"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
finally show ?case unfolding less_type_def by simp
next
case (Sequence \<tau>)
have "(\<sqsubset>)\<^sup>+\<^sup>+ OclVoid (Sequence OclVoid[\<^bold>1])" by auto
also from Sequence.hyps
have "(\<sqsubset>)\<^sup>*\<^sup>* (Sequence OclVoid[\<^bold>1]) (Sequence \<tau>)"
unfolding less_type\<^sub>N_def
by (rule_tac ?R="(\<sqsubset>\<^sub>N)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
finally show ?case unfolding less_type_def by simp
next
case (Map \<tau> \<sigma>) show ?case unfolding less_type_def by auto
next
case (Required \<tau>) thus ?case
unfolding less_type\<^sub>N_def less_type_def
by (rule_tac ?f="Required" in preserve_tranclp; auto)
next
case (Optional \<tau>)
hence "(\<sqsubset>\<^sub>N)\<^sup>*\<^sup>* (Required OclVoid) (Required \<tau>)"
unfolding less_type_def
by (rule_tac ?R="(\<sqsubset>)" in preserve_rtranclp;
auto simp add: Nitpick.rtranclp_unfold)
also have "(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ (Required \<tau>) (Optional \<tau>)" by auto
finally show ?case unfolding less_type\<^sub>N_def by simp
qed
lemma type_less_x_Real_intro [intro]:
"\<tau> = Integer \<Longrightarrow> \<tau> < Real"
unfolding less_type_def
by (rule rtranclp_into_tranclp2, auto)+
lemma type_less_x_ObjectType_intro [intro]:
"\<tau> = \<langle>\<C>\<rangle>\<^sub>\<T> \<Longrightarrow> \<C> < \<D> \<Longrightarrow> \<tau> < \<langle>\<D>\<rangle>\<^sub>\<T>"
unfolding less_type_def
using dual_order.order_iff_strict by blast
lemma fun_or_eq_refl [intro]:
"reflp (\<lambda>x y. f x y \<or> x = y)"
by (simp add: reflpI)
lemma type_less_x_Tuple_intro [intro]:
assumes "\<tau> = Tuple \<pi>"
and "strict_subtuple (\<le>) \<pi> \<xi>"
shows "\<tau> < Tuple \<xi>"
proof -
have "subtuple (\<lambda>\<tau> \<sigma>. \<tau> \<sqsubset>\<^sub>N \<sigma> \<or> \<tau> = \<sigma>)\<^sup>*\<^sup>* \<pi> \<xi>"
by (metis assms(2) less_eq_type\<^sub>N_def rtranclp_eq_rtranclp)
hence "(subtuple (\<lambda>\<tau> \<sigma>. \<tau> \<sqsubset>\<^sub>N \<sigma> \<or> \<tau> = \<sigma>))\<^sup>+\<^sup>+ \<pi> \<xi>"
by simp (rule subtuple_to_trancl; auto)
hence "(strict_subtuple (\<lambda>\<tau> \<sigma>. \<tau> \<sqsubset>\<^sub>N \<sigma> \<or> \<tau> = \<sigma>))\<^sup>*\<^sup>* \<pi> \<xi>"
by (simp add: tranclp_into_rtranclp)
hence "(strict_subtuple (\<lambda>\<tau> \<sigma>. \<tau> \<sqsubset>\<^sub>N \<sigma> \<or> \<tau> = \<sigma>))\<^sup>+\<^sup>+ \<pi> \<xi>"
by (meson assms(2) rtranclpD)
thus ?thesis
unfolding less_type_def
using assms(1) apply simp
by (rule preserve_tranclp; auto)
qed
lemma type_less_x_Collection_intro [intro]:
"\<tau> = Collection \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> \<tau> < Collection \<sigma>"
"\<tau> = Set \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> \<tau> < Collection \<sigma>"
"\<tau> = OrderedSet \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> \<tau> < Collection \<sigma>"
"\<tau> = Bag \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> \<tau> < Collection \<sigma>"
"\<tau> = Sequence \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> \<tau> < Collection \<sigma>"
unfolding less_type_def less_type\<^sub>N_def less_eq_type\<^sub>N_def
apply simp_all
apply (rule_tac ?f="Collection" in preserve_tranclp; auto)
by (rule preserve_rtranclp''; auto)+
lemma type_less_x_Set_intro [intro]:
"\<tau> = Set \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> \<tau> < Set \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by simp (rule preserve_tranclp; auto)
lemma type_less_x_OrderedSet_intro [intro]:
"\<tau> = OrderedSet \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> \<tau> < OrderedSet \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by simp (rule preserve_tranclp; auto)
lemma type_less_x_Bag_intro [intro]:
"\<tau> = Bag \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> \<tau> < Bag \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by simp (rule preserve_tranclp; auto)
lemma type_less_x_Sequence_intro [intro]:
"\<tau> = Sequence \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> \<tau> < Sequence \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by simp (rule preserve_tranclp; auto)
lemma type_less_x_Map_intro':
assumes "(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau> \<rho>"
and "(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<sigma> \<upsilon>"
shows "(\<sqsubset>)\<^sup>+\<^sup>+ (Map \<tau> \<sigma>) (Map \<rho> \<upsilon>)"
proof -
from assms(2) have "(\<sqsubset>)\<^sup>+\<^sup>+ (Map \<tau> \<sigma>) (Map \<tau> \<upsilon>)"
by (metis preserve_tranclp subtype_subtype\<^sub>N.intros(33))
also have "(\<sqsubset>)\<^sup>+\<^sup>+ (Map \<tau> \<upsilon>) (Map \<rho> \<upsilon>)"
apply (insert assms(1))
by (rule preserve_tranclp; simp add: subtype_subtype\<^sub>N.intros(34))
finally show ?thesis by simp
qed
lemma type_less_x_Map_intro [intro]:
"\<phi> = Map \<tau> \<sigma> \<Longrightarrow> \<tau> = \<rho> \<Longrightarrow> \<sigma> < \<upsilon> \<Longrightarrow> \<phi> < Map \<rho> \<upsilon>"
"\<phi> = Map \<tau> \<sigma> \<Longrightarrow> \<tau> < \<rho> \<Longrightarrow> \<sigma> = \<upsilon> \<Longrightarrow> \<phi> < Map \<rho> \<upsilon>"
"\<phi> = Map \<tau> \<sigma> \<Longrightarrow> \<tau> < \<rho> \<Longrightarrow> \<sigma> < \<upsilon> \<Longrightarrow> \<phi> < Map \<rho> \<upsilon>"
unfolding less_type\<^sub>N_def less_type_def
apply simp_all
apply (rule preserve_tranclp;
simp add: subtype_subtype\<^sub>N.intros(33) subtype_subtype\<^sub>N.intros(34))+
by (simp add: type_less_x_Map_intro')
lemma type_less_x_Required_intro [intro]:
"\<tau> = Required \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> \<tau> < Required \<sigma>"
unfolding less_type\<^sub>N_def less_type_def
by simp (rule preserve_tranclp; auto)
lemma type_less_x_Optional_intro [intro]:
"\<tau> = Required \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> \<tau> < Optional \<sigma>"
"\<tau> = Optional \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> \<tau> < Optional \<sigma>"
unfolding less_type\<^sub>N_def less_type_def less_eq_type_def
apply simp_all
apply (rule preserve_rtranclp''; auto)
by (rule preserve_tranclp; auto)
(*** Strict Elimination Rules ***********************************************)
subsection \<open>Strict Elimination Rules\<close>
lemma type_less_x_OclAny [elim!]:
"\<tau> < OclAny \<Longrightarrow> (\<tau> \<noteq> OclAny \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
by (drule tranclpD; auto)
lemma type_less_x_OclVoid [elim!]:
"\<tau> < OclVoid \<Longrightarrow> P"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
lemma type_less_x_Boolean [elim!]:
"\<tau> < Boolean \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
lemma type_less_x_Real [elim!]:
"\<tau> < Real \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow>
(\<tau> = Integer \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
lemma type_less_x_Integer [elim!]:
"\<tau> < Integer \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
lemma type_less_x_UnlimitedNatural [elim!]:
"\<tau> < UnlimitedNatural \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
lemma type_less_x_String [elim!]:
"\<tau> < String \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
lemma type_less_x_Enum [elim!]:
"\<tau> < Enum \<E> \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
lemma type_less_x_ObjectType [elim!]:
"\<tau> < \<langle>\<D>\<rangle>\<^sub>\<T> \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<C>. \<tau> = \<langle>\<C>\<rangle>\<^sub>\<T> \<Longrightarrow> \<C> < \<D> \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def
apply (induct rule: converse_tranclp_induct)
using less_trans by auto
text \<open>
We will be able to remove the acyclicity assumption only after
we prove that the subtype relation is acyclic.\<close>
lemma type_less_x_Tuple':
assumes "\<tau> < Tuple \<xi>"
and "acyclicP_on (fmran' \<xi>) (\<sqsubset>\<^sub>N)"
and "\<And>\<pi>. \<tau> = Tuple \<pi> \<Longrightarrow> strict_subtuple (\<le>) \<pi> \<xi> \<Longrightarrow> P"
and "\<tau> = OclVoid \<Longrightarrow> P"
shows "P"
proof -
from assms(1) obtain \<pi> where "\<tau> = Tuple \<pi> \<or> \<tau> = OclVoid"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
moreover from assms(2) have
"\<And>\<pi>. Tuple \<pi> < Tuple \<xi> \<Longrightarrow> strict_subtuple (\<le>) \<pi> \<xi>"
unfolding less_type_def less_eq_type\<^sub>N_def
by (rule_tac ?f="Tuple" in strict_subtuple_rtranclp_intro; auto)
ultimately show ?thesis
using assms by auto
qed
lemma type_less_x_Collection [elim!]:
"\<tau> < Collection \<sigma> \<Longrightarrow>
(\<And>\<rho>. \<tau> = Collection \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<rho>. \<tau> = Set \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<rho>. \<tau> = OrderedSet \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<rho>. \<tau> = Bag \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<rho>. \<tau> = Sequence \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<tau> = OclVoid \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def less_type\<^sub>N_def less_eq_type\<^sub>N_def
apply (induct rule: converse_tranclp_induct)
apply auto[1]
by (erule subtype.cases;
auto simp add: converse_rtranclp_into_rtranclp less_eq_type_def
tranclp_into_tranclp2 tranclp_into_rtranclp)
lemma type_less_x_Set [elim!]:
assumes "\<tau> < Set \<sigma>"
and "\<And>\<rho>. \<tau> = Set \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> P"
and "\<tau> = OclVoid \<Longrightarrow> P"
shows "P"
proof -
from assms(1) obtain \<rho> where "\<tau> = Set \<rho> \<or> \<tau> = OclVoid"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
moreover have "\<And>\<tau> \<sigma>. Set \<tau> < Set \<sigma> \<Longrightarrow> \<tau> < \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by (rule reflect_tranclp; auto)
ultimately show ?thesis
using assms by auto
qed
lemma type_less_x_OrderedSet [elim!]:
assumes "\<tau> < OrderedSet \<sigma>"
and "\<And>\<rho>. \<tau> = OrderedSet \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> P"
and "\<tau> = OclVoid \<Longrightarrow> P"
shows "P"
proof -
from assms(1) obtain \<rho> where "\<tau> = OrderedSet \<rho> \<or> \<tau> = OclVoid"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
moreover have "\<And>\<tau> \<sigma>. OrderedSet \<tau> < OrderedSet \<sigma> \<Longrightarrow> \<tau> < \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by (rule reflect_tranclp; auto)
ultimately show ?thesis
using assms by auto
qed
lemma type_less_x_Bag [elim!]:
assumes "\<tau> < Bag \<sigma>"
and "\<And>\<rho>. \<tau> = Bag \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> P"
and "\<tau> = OclVoid \<Longrightarrow> P"
shows "P"
proof -
from assms(1) obtain \<rho> where "\<tau> = Bag \<rho> \<or> \<tau> = OclVoid"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
moreover have "\<And>\<tau> \<sigma>. Bag \<tau> < Bag \<sigma> \<Longrightarrow> \<tau> < \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by (rule reflect_tranclp; auto)
ultimately show ?thesis
using assms by auto
qed
lemma type_less_x_Sequence [elim!]:
assumes "\<tau> < Sequence \<sigma>"
and "\<And>\<rho>. \<tau> = Sequence \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> P"
and "\<tau> = OclVoid \<Longrightarrow> P"
shows "P"
proof -
from assms(1) obtain \<rho> where "\<tau> = Sequence \<rho> \<or> \<tau> = OclVoid"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
moreover have "\<And>\<tau> \<sigma>. Sequence \<tau> < Sequence \<sigma> \<Longrightarrow> \<tau> < \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by (rule reflect_tranclp; auto)
ultimately show ?thesis
using assms by auto
qed
lemma type_less_x_Map [elim!]:
assumes "\<phi> < Map \<rho> \<upsilon>"
and "\<And>\<sigma>. \<phi> = Map \<rho> \<sigma> \<Longrightarrow> \<sigma> < \<upsilon> \<Longrightarrow> P"
and "\<And>\<tau>. \<phi> = Map \<tau> \<upsilon> \<Longrightarrow> \<tau> < \<rho> \<Longrightarrow> P"
and "\<And>\<tau> \<sigma>. \<phi> = Map \<tau> \<sigma> \<Longrightarrow> \<tau> < \<rho> \<Longrightarrow> \<sigma> < \<upsilon> \<Longrightarrow> P"
and "\<phi> = OclVoid \<Longrightarrow> P"
shows "P"
proof -
from assms(1) obtain \<tau> \<sigma> where "\<phi> = Map \<tau> \<sigma> \<or> \<phi> = OclVoid"
unfolding less_type_def
by (induct rule: converse_tranclp_induct; auto)
moreover have
"Map \<tau> \<sigma> < Map \<rho> \<upsilon> \<Longrightarrow>
(\<tau> = \<rho> \<Longrightarrow> \<sigma> < \<upsilon> \<Longrightarrow> P) \<Longrightarrow>
(\<tau> < \<rho> \<Longrightarrow> \<sigma> = \<upsilon> \<Longrightarrow> P) \<Longrightarrow>
(\<tau> < \<rho> \<Longrightarrow> \<sigma> < \<upsilon> \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type_def less_type\<^sub>N_def
by (erule subtype_tranclp_x_Map, auto)
ultimately show ?thesis
using assms by auto
qed
lemma type_less_x_Required [elim!]:
assumes "\<tau> < Required \<sigma>"
and "\<And>\<rho>. \<tau> = Required \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> P"
shows "P"
proof -
from assms(1) obtain \<rho> where "\<tau> = Required \<rho>"
unfolding less_type\<^sub>N_def
by (induct rule: converse_tranclp_induct; auto)
moreover have "Required \<rho> < Required \<sigma> \<Longrightarrow> \<rho> < \<sigma>"
unfolding less_type_def less_type\<^sub>N_def
by (rule reflect_tranclp; auto)
ultimately show ?thesis
using assms by auto
qed
lemma type_less_x_Optional [elim!]:
"\<tau> < Optional \<sigma> \<Longrightarrow>
(\<And>\<rho>. \<tau> = Required \<rho> \<Longrightarrow> \<rho> \<le> \<sigma> \<Longrightarrow> P) \<Longrightarrow>
(\<And>\<rho>. \<tau> = Optional \<rho> \<Longrightarrow> \<rho> < \<sigma> \<Longrightarrow> P) \<Longrightarrow> P"
unfolding less_type\<^sub>N_def less_type_def less_eq_type_def
apply (induct rule: converse_tranclp_induct)
apply auto[1]
apply (erule subtype\<^sub>N.cases)
apply (auto simp: converse_rtranclp_into_rtranclp tranclp_into_tranclp2)[1]
apply (auto simp: converse_rtranclp_into_rtranclp tranclp_into_tranclp2)[1]
using tranclp_into_rtranclp by fastforce
(*** Properties *************************************************************)
subsection \<open>Properties\<close>
lemma
subtype_irrefl: "\<tau> < \<tau> \<Longrightarrow> False" and
subtype\<^sub>N_irrefl: "\<tau>\<^sub>N < \<tau>\<^sub>N \<Longrightarrow> False"
for \<tau> :: "'a :: order type"
and \<tau>\<^sub>N :: "'a type\<^sub>N"
apply (induct \<tau> and \<tau>\<^sub>N, auto)
by (erule type_less_x_Tuple'; auto simp add: less_type\<^sub>N_def tranclp_unfold)
lemma subtype_acyclic:
"acyclicP (\<sqsubset>)"
proof -
have "\<nexists>\<tau>. (\<sqsubset>)\<^sup>+\<^sup>+ \<tau> \<tau>"
by (metis (mono_tags) less_type_def OCL_Types.subtype_irrefl)
thus ?thesis
by (intro acyclicI) (simp add: trancl_def)
qed
lemma subtype\<^sub>N_acyclic:
"acyclicP (\<sqsubset>\<^sub>N)"
proof -
have "\<nexists>\<tau>. (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau> \<tau>"
by (metis (mono_tags) less_type\<^sub>N_def OCL_Types.subtype\<^sub>N_irrefl)
thus ?thesis
by (intro acyclicI) (simp add: trancl_def)
qed
(*** Partial Order **********************************************************)
subsection \<open>Partial Order\<close>
instantiation type :: (order) order
begin
lemma less_le_not_le_type:
"\<tau> < \<sigma> \<longleftrightarrow> \<tau> \<le> \<sigma> \<and> \<not> \<sigma> \<le> \<tau>"
for \<tau> \<sigma> :: "'a type"
proof -
have "(\<sqsubset>)\<^sup>+\<^sup>+ \<tau> \<sigma> \<Longrightarrow> (\<sqsubset>)\<^sup>*\<^sup>* \<sigma> \<tau> \<Longrightarrow> False"
by (metis (mono_tags) subtype_irrefl less_type_def tranclp_rtranclp_tranclp)
moreover have "(\<sqsubset>)\<^sup>*\<^sup>* \<tau> \<sigma> \<Longrightarrow> \<not> (\<sqsubset>)\<^sup>*\<^sup>* \<sigma> \<tau> \<Longrightarrow> (\<sqsubset>)\<^sup>+\<^sup>+ \<tau> \<sigma>"
by (metis rtranclpD)
ultimately show ?thesis
unfolding less_type_def less_eq_type_def by auto
qed
lemma order_refl_type:
"\<tau> \<le> \<tau>"
for \<tau> :: "'a type"
unfolding less_eq_type_def by simp
lemma order_trans_type:
"\<tau> \<le> \<sigma> \<Longrightarrow> \<sigma> \<le> \<rho> \<Longrightarrow> \<tau> \<le> \<rho>"
for \<tau> \<sigma> \<rho> :: "'a type"
unfolding less_eq_type_def by simp
lemma antisym_type:
"\<tau> \<le> \<sigma> \<Longrightarrow> \<sigma> \<le> \<tau> \<Longrightarrow> \<tau> = \<sigma>"
for \<tau> \<sigma> :: "'a type"
unfolding less_eq_type_def less_type_def
by (metis (mono_tags, lifting) less_eq_type_def
less_le_not_le_type less_type_def rtranclpD)
instance
apply intro_classes
apply (simp add: less_le_not_le_type)
apply (simp add: order_refl_type)
using order_trans_type apply blast
by (simp add: antisym_type)
end
instantiation type\<^sub>N :: (order) order
begin
lemma less_le_not_le_type\<^sub>N:
"\<tau> < \<sigma> \<longleftrightarrow> \<tau> \<le> \<sigma> \<and> \<not> \<sigma> \<le> \<tau>"
for \<tau> \<sigma> :: "'a type\<^sub>N"
proof -
have "(\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau> \<sigma> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>*\<^sup>* \<sigma> \<tau> \<Longrightarrow> False"
by (metis subtype\<^sub>N_irrefl less_type\<^sub>N_def tranclp_rtranclp_tranclp)
moreover have "(\<sqsubset>\<^sub>N)\<^sup>*\<^sup>* \<tau> \<sigma> \<Longrightarrow> \<not> (\<sqsubset>\<^sub>N)\<^sup>*\<^sup>* \<sigma> \<tau> \<Longrightarrow> (\<sqsubset>\<^sub>N)\<^sup>+\<^sup>+ \<tau> \<sigma>"
by (metis rtranclpD)
ultimately show ?thesis
unfolding less_type\<^sub>N_def less_eq_type\<^sub>N_def by auto
qed
lemma order_refl_type\<^sub>N:
"\<tau> \<le> \<tau>"
for \<tau> :: "'a type\<^sub>N"
unfolding less_eq_type\<^sub>N_def by simp
lemma order_trans_type\<^sub>N:
"\<tau> \<le> \<sigma> \<Longrightarrow> \<sigma> \<le> \<rho> \<Longrightarrow> \<tau> \<le> \<rho>"
for \<tau> \<sigma> \<rho> :: "'a type\<^sub>N"
unfolding less_eq_type\<^sub>N_def by simp
lemma antisym_type\<^sub>N:
"\<tau> \<le> \<sigma> \<Longrightarrow> \<sigma> \<le> \<tau> \<Longrightarrow> \<tau> = \<sigma>"
for \<tau> \<sigma> :: "'a type\<^sub>N"
unfolding less_eq_type\<^sub>N_def less_type\<^sub>N_def
by (metis (mono_tags, lifting) less_eq_type\<^sub>N_def