diff -r 22dce9134953 -r a0b16d42d489 src/HOL/Bali/TypeRel.thy --- a/src/HOL/Bali/TypeRel.thy Wed Oct 30 12:44:18 2002 +0100 +++ b/src/HOL/Bali/TypeRel.thy Thu Oct 31 18:27:10 2002 +0100 @@ -34,11 +34,11 @@ (*subcls1, in Decl.thy*)  (* direct subclass *) (*subcls , by translation*)   (* subclass *) (*subclseq, by translation*)  (* subclass + identity *) - implmt1 :: "prog \ (qtname \ qtname) set" (* direct implementation *) - implmt :: "prog \ (qtname \ qtname) set" (* implementation *) - widen :: "prog \ (ty \ ty ) set" (* widening *) - narrow :: "prog \ (ty \ ty ) set" (* narrowing *) - cast :: "prog \ (ty \ ty ) set"  (* casting *) + implmt1 :: "prog \ (qtname \ qtname) set" --{* direct implementation *} + implmt :: "prog \ (qtname \ qtname) set" --{* implementation *} + widen :: "prog \ (ty \ ty ) set" --{* widening *} + narrow :: "prog \ (ty \ ty ) set" --{* narrowing *} + cast :: "prog \ (ty \ ty ) set"  --{* casting *} syntax @@ -73,7 +73,7 @@ translations "G\I \I1 J" == "(I,J) \ subint1 G" - "G\I \I J" == "(I,J) \(subint1 G)^*" (* cf. 9.1.3 *) + "G\I \I J" == "(I,J) \(subint1 G)^*" --{* cf. 9.1.3 *} (* Defined in Decl.thy: "G\C \\<^sub>C\<^sub>1 D" == "(C,D) \ subcls1 G" "G\C \\<^sub>C D" == "(C,D) \(subcls1 G)^*" @@ -359,7 +359,7 @@ section "implementation relation" defs - (* direct implementation, cf. 8.1.3 *) + --{* direct implementation, cf. 8.1.3 *} implmt1_def:"implmt1 G\{(C,I). C\Object \ (\c\class G C: I\set (superIfs c))}" lemma implmt1D: "G\C\1I \ C\Object \ (\c\class G C: I\set (superIfs c))" @@ -368,7 +368,7 @@ done -inductive "implmt G" intros (* cf. 8.1.4 *) +inductive "implmt G" intros --{* cf. 8.1.4 *} direct: "G\C\1J \\ \ G\C\J" subint: "\G\C\1I; G\I\I J\ \ G\C\J" @@ -400,10 +400,11 @@ section "widening relation" -inductive "widen G" intros(*widening, viz. method invocation conversion, cf. 5.3 - i.e. kind of syntactic subtyping *) - refl: "G\T\T"(*identity conversion, cf. 5.1.1 *) - subint: "G\I\I J \ G\Iface I\ Iface J"(*wid.ref.conv.,cf. 5.1.4 *) +inductive "widen G" intros + --{*widening, viz. method invocation conversion, cf. 5.3 + i.e. kind of syntactic subtyping *} + refl: "G\T\T" --{*identity conversion, cf. 5.1.1 *} + subint: "G\I\I J \ G\Iface I\ Iface J" --{*wid.ref.conv.,cf. 5.1.4 *} int_obj: "G\Iface I\ Class Object" subcls: "G\C\\<^sub>C D \ G\Class C\ Class D" implmt: "G\C\I \ G\Class C\ Iface I" @@ -428,6 +429,26 @@ apply (ind_cases "G\S\T") by auto +text {* + These widening lemmata hold in Bali but are to strong for ordinary + Java. They would not work for real Java Integral Types, like short, + long, int. These lemmata are just for documentation and are not used. + *} + +lemma widen_PrimT_strong: "G\PrimT x\T \ T = PrimT x" +by (ind_cases "G\S\T") simp_all + +lemma widen_PrimT2_strong: "G\S\PrimT x \ S = PrimT x" +by (ind_cases "G\S\T") simp_all + +text {* Specialized versions for booleans also would work for real Java *} + +lemma widen_Boolean: "G\PrimT Boolean\T \ T = PrimT Boolean" +by (ind_cases "G\S\T") simp_all + +lemma widen_Boolean2: "G\S\PrimT Boolean \ S = PrimT Boolean" +by (ind_cases "G\S\T") simp_all + lemma widen_RefT: "G\RefT R\T \ \t. T=RefT t" apply (ind_cases "G\S\T") by auto @@ -516,10 +537,7 @@ lemma widen_Array_Class: "G\S.[] \ Class C \ C=Object" by (auto dest: widen_Array) -(* -qed_typerel "widen_NT2" "G\S\NT \ S = NT" - [prove_widen_lemma "G\S\T \ T = NT \ S = NT"] -*) + lemma widen_NT2: "G\S\NT \ S = NT" apply (ind_cases "G\S\T") by auto @@ -634,18 +652,32 @@ apply (ind_cases "G\S\T") by auto +text {* + These narrowing lemmata hold in Bali but are to strong for ordinary + Java. They would not work for real Java Integral Types, like short, + long, int. These lemmata are just for documentation and are not used. + *} +lemma narrow_PrimT_strong: "G\PrimT pt\T \ T=PrimT pt" +by (ind_cases "G\S\T") simp_all + +lemma narrow_PrimT2_strong: "G\S\PrimT pt \ S=PrimT pt" +by (ind_cases "G\S\T") simp_all + +text {* Specialized versions for booleans also would work for real Java *} + +lemma narrow_Boolean: "G\PrimT Boolean\T \ T=PrimT Boolean" +by (ind_cases "G\S\T") simp_all + +lemma narrow_Boolean2: "G\S\PrimT Boolean \ S=PrimT Boolean" +by (ind_cases "G\S\T") simp_all section "casting relation" -inductive "cast G" intros (* casting conversion, cf. 5.5 *) +inductive "cast G" intros --{* casting conversion, cf. 5.5 *} widen: "G\S\T \ G\S\? T" narrow: "G\S\T \ G\S\? T" -(* -lemma ??unknown??: "\G\S\T; G\S\T\ \ R" - deferred *) - (*unused*) lemma cast_RefT: "G\RefT R\? T \ \t. T=RefT t" apply (ind_cases "G\S\? T") @@ -664,4 +696,36 @@ apply (ind_cases "G\S\? T") by (auto dest: widen_PrimT2 narrow_PrimT2) +lemma cast_Boolean: + assumes bool_cast: "G\PrimT Boolean\? T" + shows "T=PrimT Boolean" +using bool_cast +proof (cases) + case widen + hence "G\PrimT Boolean\ T" + by simp + thus ?thesis by (rule widen_Boolean) +next + case narrow + hence "G\PrimT Boolean\T" + by simp + thus ?thesis by (rule narrow_Boolean) +qed + +lemma cast_Boolean2: + assumes bool_cast: "G\S\? PrimT Boolean" + shows "S = PrimT Boolean" +using bool_cast +proof (cases) + case widen + hence "G\S\ PrimT Boolean" + by simp + thus ?thesis by (rule widen_Boolean2) +next + case narrow + hence "G\S\PrimT Boolean" + by simp + thus ?thesis by (rule narrow_Boolean2) +qed + end