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