src/HOL/Lifting_Option.thy
author kuncar
Thu Apr 10 17:48:15 2014 +0200 (2014-04-10)
changeset 56519 c1048f5bbb45
parent 56518 beb3b6851665
child 56520 3373f5d1e074
permissions -rw-r--r--
more appropriate name (Lifting.invariant -> eq_onp)
kuncar@53012
     1
(*  Title:      HOL/Lifting_Option.thy
kuncar@53012
     2
    Author:     Brian Huffman and Ondrej Kuncar
blanchet@55129
     3
    Author:     Andreas Lochbihler, Karlsruhe Institute of Technology
kuncar@53012
     4
*)
kuncar@53012
     5
kuncar@53012
     6
header {* Setup for Lifting/Transfer for the option type *}
kuncar@53012
     7
kuncar@53012
     8
theory Lifting_Option
blanchet@55090
     9
imports Lifting Partial_Function
kuncar@53012
    10
begin
kuncar@53012
    11
kuncar@53012
    12
subsection {* Relator and predicator properties *}
kuncar@53012
    13
blanchet@55525
    14
lemma rel_option_iff:
blanchet@55525
    15
  "rel_option R x y = (case (x, y) of (None, None) \<Rightarrow> True
kuncar@53012
    16
    | (Some x, Some y) \<Rightarrow> R x y
kuncar@53012
    17
    | _ \<Rightarrow> False)"
blanchet@55525
    18
by (auto split: prod.split option.split)
kuncar@53012
    19
blanchet@56092
    20
abbreviation (input) pred_option :: "('a \<Rightarrow> bool) \<Rightarrow> 'a option \<Rightarrow> bool" where
blanchet@56092
    21
  "pred_option \<equiv> case_option True"
kuncar@53012
    22
blanchet@55525
    23
lemma rel_option_eq [relator_eq]:
blanchet@55525
    24
  "rel_option (op =) = (op =)"
blanchet@55525
    25
  by (simp add: rel_option_iff fun_eq_iff split: option.split)
kuncar@53012
    26
blanchet@55525
    27
lemma rel_option_mono[relator_mono]:
kuncar@53012
    28
  assumes "A \<le> B"
blanchet@55525
    29
  shows "(rel_option A) \<le> (rel_option B)"
blanchet@55525
    30
using assms by (auto simp: rel_option_iff split: option.splits)
kuncar@53012
    31
blanchet@55525
    32
lemma rel_option_OO[relator_distr]:
blanchet@55525
    33
  "(rel_option A) OO (rel_option B) = rel_option (A OO B)"
blanchet@55525
    34
by (rule ext)+ (auto simp: rel_option_iff OO_def split: option.split)
kuncar@53012
    35
kuncar@53012
    36
lemma Domainp_option[relator_domain]:
kuncar@53012
    37
  assumes "Domainp A = P"
blanchet@56092
    38
  shows "Domainp (rel_option A) = (pred_option P)"
blanchet@55525
    39
using assms unfolding Domainp_iff[abs_def] rel_option_iff[abs_def]
kuncar@53012
    40
by (auto iff: fun_eq_iff split: option.split)
kuncar@53012
    41
kuncar@56518
    42
lemma left_total_rel_option[transfer_rule]:
blanchet@55525
    43
  "left_total R \<Longrightarrow> left_total (rel_option R)"
kuncar@53012
    44
  unfolding left_total_def split_option_all split_option_ex by simp
kuncar@53012
    45
kuncar@56518
    46
lemma left_unique_rel_option [transfer_rule]:
blanchet@55525
    47
  "left_unique R \<Longrightarrow> left_unique (rel_option R)"
kuncar@53012
    48
  unfolding left_unique_def split_option_all by simp
kuncar@53012
    49
blanchet@55525
    50
lemma right_total_rel_option [transfer_rule]:
blanchet@55525
    51
  "right_total R \<Longrightarrow> right_total (rel_option R)"
kuncar@53012
    52
  unfolding right_total_def split_option_all split_option_ex by simp
kuncar@53012
    53
blanchet@55525
    54
lemma right_unique_rel_option [transfer_rule]:
blanchet@55525
    55
  "right_unique R \<Longrightarrow> right_unique (rel_option R)"
kuncar@53012
    56
  unfolding right_unique_def split_option_all by simp
kuncar@53012
    57
blanchet@55525
    58
lemma bi_total_rel_option [transfer_rule]:
blanchet@55525
    59
  "bi_total R \<Longrightarrow> bi_total (rel_option R)"
kuncar@53012
    60
  unfolding bi_total_def split_option_all split_option_ex by simp
kuncar@53012
    61
blanchet@55525
    62
lemma bi_unique_rel_option [transfer_rule]:
blanchet@55525
    63
  "bi_unique R \<Longrightarrow> bi_unique (rel_option R)"
kuncar@53012
    64
  unfolding bi_unique_def split_option_all by simp
kuncar@53012
    65
kuncar@56519
    66
lemma option_relator_eq_onp [relator_eq_onp]:
kuncar@56519
    67
  "rel_option (eq_onp P) = eq_onp (pred_option P)"
kuncar@56519
    68
  by (auto simp add: fun_eq_iff eq_onp_def split_option_all)
kuncar@53012
    69
kuncar@53012
    70
subsection {* Quotient theorem for the Lifting package *}
kuncar@53012
    71
kuncar@53012
    72
lemma Quotient_option[quot_map]:
kuncar@53012
    73
  assumes "Quotient R Abs Rep T"
blanchet@55525
    74
  shows "Quotient (rel_option R) (map_option Abs)
blanchet@55525
    75
    (map_option Rep) (rel_option T)"
blanchet@55525
    76
  using assms unfolding Quotient_alt_def rel_option_iff
kuncar@53012
    77
  by (simp split: option.split)
kuncar@53012
    78
kuncar@53012
    79
subsection {* Transfer rules for the Transfer package *}
kuncar@53012
    80
kuncar@53012
    81
context
kuncar@53012
    82
begin
kuncar@53012
    83
interpretation lifting_syntax .
kuncar@53012
    84
blanchet@55525
    85
lemma None_transfer [transfer_rule]: "(rel_option A) None None"
blanchet@55525
    86
  by (rule option.rel_inject)
kuncar@53012
    87
blanchet@55525
    88
lemma Some_transfer [transfer_rule]: "(A ===> rel_option A) Some Some"
blanchet@55945
    89
  unfolding rel_fun_def by simp
kuncar@53012
    90
blanchet@55404
    91
lemma case_option_transfer [transfer_rule]:
blanchet@55525
    92
  "(B ===> (A ===> B) ===> rel_option A ===> B) case_option case_option"
blanchet@55945
    93
  unfolding rel_fun_def split_option_all by simp
kuncar@53012
    94
blanchet@55466
    95
lemma map_option_transfer [transfer_rule]:
blanchet@55525
    96
  "((A ===> B) ===> rel_option A ===> rel_option B) map_option map_option"
blanchet@55466
    97
  unfolding map_option_case[abs_def] by transfer_prover
kuncar@53012
    98
kuncar@53012
    99
lemma option_bind_transfer [transfer_rule]:
blanchet@55525
   100
  "(rel_option A ===> (A ===> rel_option B) ===> rel_option B)
kuncar@53012
   101
    Option.bind Option.bind"
blanchet@55945
   102
  unfolding rel_fun_def split_option_all by simp
kuncar@53012
   103
kuncar@53012
   104
end
kuncar@53012
   105
kuncar@53012
   106
end