src/HOL/Lifting.thy
author huffman
Wed, 04 Apr 2012 13:42:01 +0200
changeset 47351 0193e663a19e
parent 47325 ec6187036495
child 47354 95846613e414
permissions -rw-r--r--
lift_definition command generates transfer rule
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     1
(*  Title:      HOL/Lifting.thy
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     2
    Author:     Brian Huffman and Ondrej Kuncar
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     3
    Author:     Cezary Kaliszyk and Christian Urban
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     4
*)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     5
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     6
header {* Lifting package *}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     7
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
     8
theory Lifting
47325
ec6187036495 new transfer proof method
huffman
parents: 47308
diff changeset
     9
imports Plain Equiv_Relations Transfer
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    10
keywords
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    11
  "print_quotmaps" "print_quotients" :: diag and
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    12
  "lift_definition" :: thy_goal and
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    13
  "setup_lifting" :: thy_decl
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    14
uses
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    15
  ("Tools/Lifting/lifting_info.ML")
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    16
  ("Tools/Lifting/lifting_term.ML")
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    17
  ("Tools/Lifting/lifting_def.ML")
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    18
  ("Tools/Lifting/lifting_setup.ML")
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    19
begin
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    20
47325
ec6187036495 new transfer proof method
huffman
parents: 47308
diff changeset
    21
subsection {* Function map *}
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    22
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    23
notation map_fun (infixr "--->" 55)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    24
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    25
lemma map_fun_id:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    26
  "(id ---> id) = id"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    27
  by (simp add: fun_eq_iff)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    28
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    29
subsection {* Quotient Predicate *}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    30
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    31
definition
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    32
  "Quotient R Abs Rep T \<longleftrightarrow>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    33
     (\<forall>a. Abs (Rep a) = a) \<and> 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    34
     (\<forall>a. R (Rep a) (Rep a)) \<and>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    35
     (\<forall>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s) \<and>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    36
     T = (\<lambda>x y. R x x \<and> Abs x = y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    37
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    38
lemma QuotientI:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    39
  assumes "\<And>a. Abs (Rep a) = a"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    40
    and "\<And>a. R (Rep a) (Rep a)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    41
    and "\<And>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    42
    and "T = (\<lambda>x y. R x x \<and> Abs x = y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    43
  shows "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    44
  using assms unfolding Quotient_def by blast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    45
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    46
lemma Quotient_abs_rep:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    47
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    48
  shows "Abs (Rep a) = a"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    49
  using a
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    50
  unfolding Quotient_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    51
  by simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    52
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    53
lemma Quotient_rep_reflp:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    54
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    55
  shows "R (Rep a) (Rep a)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    56
  using a
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    57
  unfolding Quotient_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    58
  by blast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    59
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    60
lemma Quotient_rel:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    61
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    62
  shows "R r r \<and> R s s \<and> Abs r = Abs s \<longleftrightarrow> R r s" -- {* orientation does not loop on rewriting *}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    63
  using a
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    64
  unfolding Quotient_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    65
  by blast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    66
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    67
lemma Quotient_cr_rel:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    68
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    69
  shows "T = (\<lambda>x y. R x x \<and> Abs x = y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    70
  using a
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    71
  unfolding Quotient_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    72
  by blast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    73
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    74
lemma Quotient_refl1: 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    75
  assumes a: "Quotient R Abs Rep T" 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    76
  shows "R r s \<Longrightarrow> R r r"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    77
  using a unfolding Quotient_def 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    78
  by fast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    79
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    80
lemma Quotient_refl2: 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    81
  assumes a: "Quotient R Abs Rep T" 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    82
  shows "R r s \<Longrightarrow> R s s"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    83
  using a unfolding Quotient_def 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    84
  by fast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    85
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    86
lemma Quotient_rel_rep:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    87
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    88
  shows "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    89
  using a
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    90
  unfolding Quotient_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    91
  by metis
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    92
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    93
lemma Quotient_rep_abs:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    94
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    95
  shows "R r r \<Longrightarrow> R (Rep (Abs r)) r"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    96
  using a unfolding Quotient_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    97
  by blast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    98
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
    99
lemma Quotient_rel_abs:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   100
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   101
  shows "R r s \<Longrightarrow> Abs r = Abs s"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   102
  using a unfolding Quotient_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   103
  by blast
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   104
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   105
lemma Quotient_symp:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   106
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   107
  shows "symp R"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   108
  using a unfolding Quotient_def using sympI by (metis (full_types))
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   109
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   110
lemma Quotient_transp:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   111
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   112
  shows "transp R"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   113
  using a unfolding Quotient_def using transpI by (metis (full_types))
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   114
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   115
lemma Quotient_part_equivp:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   116
  assumes a: "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   117
  shows "part_equivp R"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   118
by (metis Quotient_rep_reflp Quotient_symp Quotient_transp a part_equivpI)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   119
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   120
lemma identity_quotient: "Quotient (op =) id id (op =)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   121
unfolding Quotient_def by simp 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   122
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   123
lemma Quotient_alt_def:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   124
  "Quotient R Abs Rep T \<longleftrightarrow>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   125
    (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   126
    (\<forall>b. T (Rep b) b) \<and>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   127
    (\<forall>x y. R x y \<longleftrightarrow> T x (Abs x) \<and> T y (Abs y) \<and> Abs x = Abs y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   128
apply safe
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   129
apply (simp (no_asm_use) only: Quotient_def, fast)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   130
apply (simp (no_asm_use) only: Quotient_def, fast)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   131
apply (simp (no_asm_use) only: Quotient_def, fast)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   132
apply (simp (no_asm_use) only: Quotient_def, fast)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   133
apply (simp (no_asm_use) only: Quotient_def, fast)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   134
apply (simp (no_asm_use) only: Quotient_def, fast)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   135
apply (rule QuotientI)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   136
apply simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   137
apply metis
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   138
apply simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   139
apply (rule ext, rule ext, metis)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   140
done
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   141
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   142
lemma Quotient_alt_def2:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   143
  "Quotient R Abs Rep T \<longleftrightarrow>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   144
    (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   145
    (\<forall>b. T (Rep b) b) \<and>
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   146
    (\<forall>x y. R x y \<longleftrightarrow> T x (Abs y) \<and> T y (Abs x))"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   147
  unfolding Quotient_alt_def by (safe, metis+)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   148
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   149
lemma fun_quotient:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   150
  assumes 1: "Quotient R1 abs1 rep1 T1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   151
  assumes 2: "Quotient R2 abs2 rep2 T2"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   152
  shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2) (T1 ===> T2)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   153
  using assms unfolding Quotient_alt_def2
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   154
  unfolding fun_rel_def fun_eq_iff map_fun_apply
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   155
  by (safe, metis+)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   156
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   157
lemma apply_rsp:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   158
  fixes f g::"'a \<Rightarrow> 'c"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   159
  assumes q: "Quotient R1 Abs1 Rep1 T1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   160
  and     a: "(R1 ===> R2) f g" "R1 x y"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   161
  shows "R2 (f x) (g y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   162
  using a by (auto elim: fun_relE)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   163
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   164
lemma apply_rsp':
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   165
  assumes a: "(R1 ===> R2) f g" "R1 x y"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   166
  shows "R2 (f x) (g y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   167
  using a by (auto elim: fun_relE)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   168
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   169
lemma apply_rsp'':
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   170
  assumes "Quotient R Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   171
  and "(R ===> S) f f"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   172
  shows "S (f (Rep x)) (f (Rep x))"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   173
proof -
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   174
  from assms(1) have "R (Rep x) (Rep x)" by (rule Quotient_rep_reflp)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   175
  then show ?thesis using assms(2) by (auto intro: apply_rsp')
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   176
qed
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   177
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   178
subsection {* Quotient composition *}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   179
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   180
lemma Quotient_compose:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   181
  assumes 1: "Quotient R1 Abs1 Rep1 T1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   182
  assumes 2: "Quotient R2 Abs2 Rep2 T2"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   183
  shows "Quotient (T1 OO R2 OO conversep T1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2) (T1 OO T2)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   184
proof -
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   185
  from 1 have Abs1: "\<And>a b. T1 a b \<Longrightarrow> Abs1 a = b"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   186
    unfolding Quotient_alt_def by simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   187
  from 1 have Rep1: "\<And>b. T1 (Rep1 b) b"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   188
    unfolding Quotient_alt_def by simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   189
  from 2 have Abs2: "\<And>a b. T2 a b \<Longrightarrow> Abs2 a = b"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   190
    unfolding Quotient_alt_def by simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   191
  from 2 have Rep2: "\<And>b. T2 (Rep2 b) b"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   192
    unfolding Quotient_alt_def by simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   193
  from 2 have R2:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   194
    "\<And>x y. R2 x y \<longleftrightarrow> T2 x (Abs2 x) \<and> T2 y (Abs2 y) \<and> Abs2 x = Abs2 y"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   195
    unfolding Quotient_alt_def by simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   196
  show ?thesis
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   197
    unfolding Quotient_alt_def
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   198
    apply simp
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   199
    apply safe
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   200
    apply (drule Abs1, simp)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   201
    apply (erule Abs2)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   202
    apply (rule pred_compI)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   203
    apply (rule Rep1)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   204
    apply (rule Rep2)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   205
    apply (rule pred_compI, assumption)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   206
    apply (drule Abs1, simp)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   207
    apply (clarsimp simp add: R2)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   208
    apply (rule pred_compI, assumption)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   209
    apply (drule Abs1, simp)+
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   210
    apply (clarsimp simp add: R2)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   211
    apply (drule Abs1, simp)+
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   212
    apply (clarsimp simp add: R2)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   213
    apply (rule pred_compI, assumption)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   214
    apply (rule pred_compI [rotated])
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   215
    apply (erule conversepI)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   216
    apply (drule Abs1, simp)+
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   217
    apply (simp add: R2)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   218
    done
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   219
qed
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   220
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   221
subsection {* Invariant *}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   222
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   223
definition invariant :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" 
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   224
  where "invariant R = (\<lambda>x y. R x \<and> x = y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   225
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   226
lemma invariant_to_eq:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   227
  assumes "invariant P x y"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   228
  shows "x = y"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   229
using assms by (simp add: invariant_def)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   230
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   231
lemma fun_rel_eq_invariant:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   232
  shows "((invariant R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   233
by (auto simp add: invariant_def fun_rel_def)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   234
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   235
lemma invariant_same_args:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   236
  shows "invariant P x x \<equiv> P x"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   237
using assms by (auto simp add: invariant_def)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   238
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   239
lemma copy_type_to_Quotient:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   240
  assumes "type_definition Rep Abs UNIV"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   241
  and T_def: "T \<equiv> (\<lambda>x y. Abs x = y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   242
  shows "Quotient (op =) Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   243
proof -
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   244
  interpret type_definition Rep Abs UNIV by fact
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   245
  from Abs_inject Rep_inverse T_def show ?thesis by (auto intro!: QuotientI)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   246
qed
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   247
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   248
lemma copy_type_to_equivp:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   249
  fixes Abs :: "'a \<Rightarrow> 'b"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   250
  and Rep :: "'b \<Rightarrow> 'a"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   251
  assumes "type_definition Rep Abs (UNIV::'a set)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   252
  shows "equivp (op=::'a\<Rightarrow>'a\<Rightarrow>bool)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   253
by (rule identity_equivp)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   254
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   255
lemma invariant_type_to_Quotient:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   256
  assumes "type_definition Rep Abs {x. P x}"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   257
  and T_def: "T \<equiv> (\<lambda>x y. (invariant P) x x \<and> Abs x = y)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   258
  shows "Quotient (invariant P) Abs Rep T"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   259
proof -
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   260
  interpret type_definition Rep Abs "{x. P x}" by fact
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   261
  from Rep Abs_inject Rep_inverse T_def show ?thesis by (auto intro!: QuotientI simp: invariant_def)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   262
qed
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   263
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   264
lemma invariant_type_to_part_equivp:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   265
  assumes "type_definition Rep Abs {x. P x}"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   266
  shows "part_equivp (invariant P)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   267
proof (intro part_equivpI)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   268
  interpret type_definition Rep Abs "{x. P x}" by fact
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   269
  show "\<exists>x. invariant P x x" using Rep by (auto simp: invariant_def)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   270
next
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   271
  show "symp (invariant P)" by (auto intro: sympI simp: invariant_def)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   272
next
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   273
  show "transp (invariant P)" by (auto intro: transpI simp: invariant_def)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   274
qed
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   275
47351
0193e663a19e lift_definition command generates transfer rule
huffman
parents: 47325
diff changeset
   276
lemma Quotient_to_transfer:
0193e663a19e lift_definition command generates transfer rule
huffman
parents: 47325
diff changeset
   277
  assumes "Quotient R Abs Rep T" and "R c c" and "c' \<equiv> Abs c"
0193e663a19e lift_definition command generates transfer rule
huffman
parents: 47325
diff changeset
   278
  shows "T c c'"
0193e663a19e lift_definition command generates transfer rule
huffman
parents: 47325
diff changeset
   279
  using assms by (auto dest: Quotient_cr_rel)
0193e663a19e lift_definition command generates transfer rule
huffman
parents: 47325
diff changeset
   280
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   281
subsection {* ML setup *}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   282
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   283
text {* Auxiliary data for the lifting package *}
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   284
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   285
use "Tools/Lifting/lifting_info.ML"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   286
setup Lifting_Info.setup
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   287
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   288
declare [[map "fun" = (fun_rel, fun_quotient)]]
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   289
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   290
use "Tools/Lifting/lifting_term.ML"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   291
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   292
use "Tools/Lifting/lifting_def.ML"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   293
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   294
use "Tools/Lifting/lifting_setup.ML"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   295
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   296
hide_const (open) invariant
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   297
9caab698dbe4 new package Lifting - initial commit
kuncar
parents:
diff changeset
   298
end