src/HOL/Lifting_Option.thy
author blanchet
Mon Jan 20 23:34:26 2014 +0100 (2014-01-20)
changeset 55089 181751ad852f
parent 53026 e1a548c11845
child 55090 9475b16e520b
permissions -rw-r--r--
swapped dependencies of 'Finite_Set' and 'Option' (to move BNF up)
kuncar@53012
     1
(*  Title:      HOL/Lifting_Option.thy
kuncar@53012
     2
    Author:     Brian Huffman and Ondrej Kuncar
kuncar@53012
     3
*)
kuncar@53012
     4
kuncar@53012
     5
header {* Setup for Lifting/Transfer for the option type *}
kuncar@53012
     6
kuncar@53012
     7
theory Lifting_Option
blanchet@55089
     8
imports Lifting Option
kuncar@53012
     9
begin
kuncar@53012
    10
kuncar@53012
    11
subsection {* Relator and predicator properties *}
kuncar@53012
    12
traytel@53026
    13
definition
kuncar@53012
    14
  option_rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a option \<Rightarrow> 'b option \<Rightarrow> bool"
kuncar@53012
    15
where
kuncar@53012
    16
  "option_rel R x y = (case (x, y) of (None, None) \<Rightarrow> True
kuncar@53012
    17
    | (Some x, Some y) \<Rightarrow> R x y
kuncar@53012
    18
    | _ \<Rightarrow> False)"
kuncar@53012
    19
traytel@53026
    20
lemma option_rel_simps[simp]:
traytel@53026
    21
  "option_rel R None None = True"
traytel@53026
    22
  "option_rel R (Some x) None = False"
traytel@53026
    23
  "option_rel R None (Some y) = False"
traytel@53026
    24
  "option_rel R (Some x) (Some y) = R x y"
traytel@53026
    25
  unfolding option_rel_def by simp_all
kuncar@53012
    26
traytel@53026
    27
abbreviation (input) option_pred :: "('a \<Rightarrow> bool) \<Rightarrow> 'a option \<Rightarrow> bool" where
traytel@53026
    28
  "option_pred \<equiv> option_case True"
kuncar@53012
    29
kuncar@53012
    30
lemma option_rel_eq [relator_eq]:
kuncar@53012
    31
  "option_rel (op =) = (op =)"
traytel@53026
    32
  by (simp add: option_rel_def fun_eq_iff split: option.split)
kuncar@53012
    33
kuncar@53012
    34
lemma option_rel_mono[relator_mono]:
kuncar@53012
    35
  assumes "A \<le> B"
kuncar@53012
    36
  shows "(option_rel A) \<le> (option_rel B)"
traytel@53026
    37
using assms by (auto simp: option_rel_def split: option.splits)
kuncar@53012
    38
kuncar@53012
    39
lemma option_rel_OO[relator_distr]:
kuncar@53012
    40
  "(option_rel A) OO (option_rel B) = option_rel (A OO B)"
traytel@53026
    41
by (rule ext)+ (auto simp: option_rel_def OO_def split: option.split)
kuncar@53012
    42
kuncar@53012
    43
lemma Domainp_option[relator_domain]:
kuncar@53012
    44
  assumes "Domainp A = P"
kuncar@53012
    45
  shows "Domainp (option_rel A) = (option_pred P)"
traytel@53026
    46
using assms unfolding Domainp_iff[abs_def] option_rel_def[abs_def]
kuncar@53012
    47
by (auto iff: fun_eq_iff split: option.split)
kuncar@53012
    48
kuncar@53012
    49
lemma reflp_option_rel[reflexivity_rule]:
kuncar@53012
    50
  "reflp R \<Longrightarrow> reflp (option_rel R)"
kuncar@53012
    51
  unfolding reflp_def split_option_all by simp
kuncar@53012
    52
kuncar@53012
    53
lemma left_total_option_rel[reflexivity_rule]:
kuncar@53012
    54
  "left_total R \<Longrightarrow> left_total (option_rel R)"
kuncar@53012
    55
  unfolding left_total_def split_option_all split_option_ex by simp
kuncar@53012
    56
kuncar@53012
    57
lemma left_unique_option_rel [reflexivity_rule]:
kuncar@53012
    58
  "left_unique R \<Longrightarrow> left_unique (option_rel R)"
kuncar@53012
    59
  unfolding left_unique_def split_option_all by simp
kuncar@53012
    60
kuncar@53012
    61
lemma right_total_option_rel [transfer_rule]:
kuncar@53012
    62
  "right_total R \<Longrightarrow> right_total (option_rel R)"
kuncar@53012
    63
  unfolding right_total_def split_option_all split_option_ex by simp
kuncar@53012
    64
kuncar@53012
    65
lemma right_unique_option_rel [transfer_rule]:
kuncar@53012
    66
  "right_unique R \<Longrightarrow> right_unique (option_rel R)"
kuncar@53012
    67
  unfolding right_unique_def split_option_all by simp
kuncar@53012
    68
kuncar@53012
    69
lemma bi_total_option_rel [transfer_rule]:
kuncar@53012
    70
  "bi_total R \<Longrightarrow> bi_total (option_rel R)"
kuncar@53012
    71
  unfolding bi_total_def split_option_all split_option_ex by simp
kuncar@53012
    72
kuncar@53012
    73
lemma bi_unique_option_rel [transfer_rule]:
kuncar@53012
    74
  "bi_unique R \<Longrightarrow> bi_unique (option_rel R)"
kuncar@53012
    75
  unfolding bi_unique_def split_option_all by simp
kuncar@53012
    76
kuncar@53012
    77
lemma option_invariant_commute [invariant_commute]:
kuncar@53012
    78
  "option_rel (Lifting.invariant P) = Lifting.invariant (option_pred P)"
kuncar@53012
    79
  by (auto simp add: fun_eq_iff Lifting.invariant_def split_option_all)
kuncar@53012
    80
kuncar@53012
    81
subsection {* Quotient theorem for the Lifting package *}
kuncar@53012
    82
kuncar@53012
    83
lemma Quotient_option[quot_map]:
kuncar@53012
    84
  assumes "Quotient R Abs Rep T"
kuncar@53012
    85
  shows "Quotient (option_rel R) (Option.map Abs)
kuncar@53012
    86
    (Option.map Rep) (option_rel T)"
traytel@53026
    87
  using assms unfolding Quotient_alt_def option_rel_def
kuncar@53012
    88
  by (simp split: option.split)
kuncar@53012
    89
kuncar@53012
    90
subsection {* Transfer rules for the Transfer package *}
kuncar@53012
    91
kuncar@53012
    92
context
kuncar@53012
    93
begin
kuncar@53012
    94
interpretation lifting_syntax .
kuncar@53012
    95
kuncar@53012
    96
lemma None_transfer [transfer_rule]: "(option_rel A) None None"
kuncar@53012
    97
  by simp
kuncar@53012
    98
kuncar@53012
    99
lemma Some_transfer [transfer_rule]: "(A ===> option_rel A) Some Some"
kuncar@53012
   100
  unfolding fun_rel_def by simp
kuncar@53012
   101
kuncar@53012
   102
lemma option_case_transfer [transfer_rule]:
kuncar@53012
   103
  "(B ===> (A ===> B) ===> option_rel A ===> B) option_case option_case"
kuncar@53012
   104
  unfolding fun_rel_def split_option_all by simp
kuncar@53012
   105
kuncar@53012
   106
lemma option_map_transfer [transfer_rule]:
kuncar@53012
   107
  "((A ===> B) ===> option_rel A ===> option_rel B) Option.map Option.map"
kuncar@53012
   108
  unfolding Option.map_def by transfer_prover
kuncar@53012
   109
kuncar@53012
   110
lemma option_bind_transfer [transfer_rule]:
kuncar@53012
   111
  "(option_rel A ===> (A ===> option_rel B) ===> option_rel B)
kuncar@53012
   112
    Option.bind Option.bind"
kuncar@53012
   113
  unfolding fun_rel_def split_option_all by simp
kuncar@53012
   114
kuncar@53012
   115
end
kuncar@53012
   116
kuncar@53012
   117
end
kuncar@53012
   118