src/HOL/Lifting_Option.thy
author blanchet
Sun Feb 16 21:33:28 2014 +0100 (2014-02-16)
changeset 55525 70b7e91fa1f9
parent 55466 786edc984c98
child 55564 e81ee43ab290
permissions -rw-r--r--
folded 'rel_option' into 'option_rel'
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
traytel@53026
    20
abbreviation (input) option_pred :: "('a \<Rightarrow> bool) \<Rightarrow> 'a option \<Rightarrow> bool" where
blanchet@55404
    21
  "option_pred \<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@55525
    38
  shows "Domainp (rel_option A) = (option_pred 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
blanchet@55525
    42
lemma reflp_rel_option[reflexivity_rule]:
blanchet@55525
    43
  "reflp R \<Longrightarrow> reflp (rel_option R)"
kuncar@53012
    44
  unfolding reflp_def split_option_all by simp
kuncar@53012
    45
blanchet@55525
    46
lemma left_total_rel_option[reflexivity_rule]:
blanchet@55525
    47
  "left_total R \<Longrightarrow> left_total (rel_option R)"
kuncar@53012
    48
  unfolding left_total_def split_option_all split_option_ex by simp
kuncar@53012
    49
blanchet@55525
    50
lemma left_unique_rel_option [reflexivity_rule]:
blanchet@55525
    51
  "left_unique R \<Longrightarrow> left_unique (rel_option R)"
kuncar@53012
    52
  unfolding left_unique_def split_option_all by simp
kuncar@53012
    53
blanchet@55525
    54
lemma right_total_rel_option [transfer_rule]:
blanchet@55525
    55
  "right_total R \<Longrightarrow> right_total (rel_option R)"
kuncar@53012
    56
  unfolding right_total_def split_option_all split_option_ex by simp
kuncar@53012
    57
blanchet@55525
    58
lemma right_unique_rel_option [transfer_rule]:
blanchet@55525
    59
  "right_unique R \<Longrightarrow> right_unique (rel_option R)"
kuncar@53012
    60
  unfolding right_unique_def split_option_all by simp
kuncar@53012
    61
blanchet@55525
    62
lemma bi_total_rel_option [transfer_rule]:
blanchet@55525
    63
  "bi_total R \<Longrightarrow> bi_total (rel_option R)"
kuncar@53012
    64
  unfolding bi_total_def split_option_all split_option_ex by simp
kuncar@53012
    65
blanchet@55525
    66
lemma bi_unique_rel_option [transfer_rule]:
blanchet@55525
    67
  "bi_unique R \<Longrightarrow> bi_unique (rel_option R)"
kuncar@53012
    68
  unfolding bi_unique_def split_option_all by simp
kuncar@53012
    69
kuncar@53012
    70
lemma option_invariant_commute [invariant_commute]:
blanchet@55525
    71
  "rel_option (Lifting.invariant P) = Lifting.invariant (option_pred P)"
kuncar@53012
    72
  by (auto simp add: fun_eq_iff Lifting.invariant_def split_option_all)
kuncar@53012
    73
kuncar@53012
    74
subsection {* Quotient theorem for the Lifting package *}
kuncar@53012
    75
kuncar@53012
    76
lemma Quotient_option[quot_map]:
kuncar@53012
    77
  assumes "Quotient R Abs Rep T"
blanchet@55525
    78
  shows "Quotient (rel_option R) (map_option Abs)
blanchet@55525
    79
    (map_option Rep) (rel_option T)"
blanchet@55525
    80
  using assms unfolding Quotient_alt_def rel_option_iff
kuncar@53012
    81
  by (simp split: option.split)
kuncar@53012
    82
kuncar@53012
    83
subsection {* Transfer rules for the Transfer package *}
kuncar@53012
    84
kuncar@53012
    85
context
kuncar@53012
    86
begin
kuncar@53012
    87
interpretation lifting_syntax .
kuncar@53012
    88
blanchet@55525
    89
lemma None_transfer [transfer_rule]: "(rel_option A) None None"
blanchet@55525
    90
  by (rule option.rel_inject)
kuncar@53012
    91
blanchet@55525
    92
lemma Some_transfer [transfer_rule]: "(A ===> rel_option A) Some Some"
kuncar@53012
    93
  unfolding fun_rel_def by simp
kuncar@53012
    94
blanchet@55404
    95
lemma case_option_transfer [transfer_rule]:
blanchet@55525
    96
  "(B ===> (A ===> B) ===> rel_option A ===> B) case_option case_option"
kuncar@53012
    97
  unfolding fun_rel_def split_option_all by simp
kuncar@53012
    98
blanchet@55466
    99
lemma map_option_transfer [transfer_rule]:
blanchet@55525
   100
  "((A ===> B) ===> rel_option A ===> rel_option B) map_option map_option"
blanchet@55466
   101
  unfolding map_option_case[abs_def] by transfer_prover
kuncar@53012
   102
kuncar@53012
   103
lemma option_bind_transfer [transfer_rule]:
blanchet@55525
   104
  "(rel_option A ===> (A ===> rel_option B) ===> rel_option B)
kuncar@53012
   105
    Option.bind Option.bind"
kuncar@53012
   106
  unfolding fun_rel_def split_option_all by simp
kuncar@53012
   107
kuncar@53012
   108
end
kuncar@53012
   109
kuncar@53012
   110
end