src/HOL/Lifting_Option.thy
author kuncar
Tue, 18 Feb 2014 23:03:49 +0100
changeset 55564 e81ee43ab290
parent 55525 70b7e91fa1f9
child 55945 e96383acecf9
permissions -rw-r--r--
delete or move now not necessary reflexivity rules due to 1726f46d2aa8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     1
(*  Title:      HOL/Lifting_Option.thy
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     2
    Author:     Brian Huffman and Ondrej Kuncar
55129
26bd1cba3ab5 killed 'More_BNFs' by moving its various bits where they (now) belong
blanchet
parents: 55090
diff changeset
     3
    Author:     Andreas Lochbihler, Karlsruhe Institute of Technology
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     4
*)
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     5
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     6
header {* Setup for Lifting/Transfer for the option type *}
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     7
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     8
theory Lifting_Option
55090
9475b16e520b technical import to avoid infamous 'duplicate Option.size' error at merge time in 'List.thy'
blanchet
parents: 55089
diff changeset
     9
imports Lifting Partial_Function
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    10
begin
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    11
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    12
subsection {* Relator and predicator properties *}
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    13
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    14
lemma rel_option_iff:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    15
  "rel_option R x y = (case (x, y) of (None, None) \<Rightarrow> True
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    16
    | (Some x, Some y) \<Rightarrow> R x y
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    17
    | _ \<Rightarrow> False)"
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    18
by (auto split: prod.split option.split)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    19
53026
e1a548c11845 got rid of the dependency of Lifting_* on the function package; use the original rel constants for basic BNFs;
traytel
parents: 53012
diff changeset
    20
abbreviation (input) option_pred :: "('a \<Rightarrow> bool) \<Rightarrow> 'a option \<Rightarrow> bool" where
55404
5cb95b79a51f transformed 'option' and 'list' into new-style datatypes (but register them as old-style as well)
blanchet
parents: 55129
diff changeset
    21
  "option_pred \<equiv> case_option True"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    22
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    23
lemma rel_option_eq [relator_eq]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    24
  "rel_option (op =) = (op =)"
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    25
  by (simp add: rel_option_iff fun_eq_iff split: option.split)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    26
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    27
lemma rel_option_mono[relator_mono]:
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    28
  assumes "A \<le> B"
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    29
  shows "(rel_option A) \<le> (rel_option B)"
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    30
using assms by (auto simp: rel_option_iff split: option.splits)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    31
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    32
lemma rel_option_OO[relator_distr]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    33
  "(rel_option A) OO (rel_option B) = rel_option (A OO B)"
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    34
by (rule ext)+ (auto simp: rel_option_iff OO_def split: option.split)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    35
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    36
lemma Domainp_option[relator_domain]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    37
  assumes "Domainp A = P"
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    38
  shows "Domainp (rel_option A) = (option_pred P)"
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    39
using assms unfolding Domainp_iff[abs_def] rel_option_iff[abs_def]
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    40
by (auto iff: fun_eq_iff split: option.split)
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    41
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    42
lemma left_total_rel_option[reflexivity_rule]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    43
  "left_total R \<Longrightarrow> left_total (rel_option R)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    44
  unfolding left_total_def split_option_all split_option_ex by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    45
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    46
lemma left_unique_rel_option [reflexivity_rule]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    47
  "left_unique R \<Longrightarrow> left_unique (rel_option R)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    48
  unfolding left_unique_def split_option_all by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    49
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    50
lemma right_total_rel_option [transfer_rule]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    51
  "right_total R \<Longrightarrow> right_total (rel_option R)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    52
  unfolding right_total_def split_option_all split_option_ex by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    53
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    54
lemma right_unique_rel_option [transfer_rule]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    55
  "right_unique R \<Longrightarrow> right_unique (rel_option R)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    56
  unfolding right_unique_def split_option_all by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    57
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    58
lemma bi_total_rel_option [transfer_rule]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    59
  "bi_total R \<Longrightarrow> bi_total (rel_option R)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    60
  unfolding bi_total_def split_option_all split_option_ex by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    61
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    62
lemma bi_unique_rel_option [transfer_rule]:
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    63
  "bi_unique R \<Longrightarrow> bi_unique (rel_option R)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    64
  unfolding bi_unique_def split_option_all by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    65
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    66
lemma option_invariant_commute [invariant_commute]:
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    67
  "rel_option (Lifting.invariant P) = Lifting.invariant (option_pred P)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    68
  by (auto simp add: fun_eq_iff Lifting.invariant_def split_option_all)
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    69
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    70
subsection {* Quotient theorem for the Lifting package *}
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    71
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    72
lemma Quotient_option[quot_map]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    73
  assumes "Quotient R Abs Rep T"
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    74
  shows "Quotient (rel_option R) (map_option Abs)
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    75
    (map_option Rep) (rel_option T)"
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    76
  using assms unfolding Quotient_alt_def rel_option_iff
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    77
  by (simp split: option.split)
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    78
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    79
subsection {* Transfer rules for the Transfer package *}
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    80
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    81
context
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    82
begin
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    83
interpretation lifting_syntax .
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    84
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    85
lemma None_transfer [transfer_rule]: "(rel_option A) None None"
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    86
  by (rule option.rel_inject)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    87
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    88
lemma Some_transfer [transfer_rule]: "(A ===> rel_option A) Some Some"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    89
  unfolding fun_rel_def by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    90
55404
5cb95b79a51f transformed 'option' and 'list' into new-style datatypes (but register them as old-style as well)
blanchet
parents: 55129
diff changeset
    91
lemma case_option_transfer [transfer_rule]:
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    92
  "(B ===> (A ===> B) ===> rel_option A ===> B) case_option case_option"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    93
  unfolding fun_rel_def split_option_all by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    94
55466
786edc984c98 merged 'Option.map' and 'Option.map_option'
blanchet
parents: 55404
diff changeset
    95
lemma map_option_transfer [transfer_rule]:
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
    96
  "((A ===> B) ===> rel_option A ===> rel_option B) map_option map_option"
55466
786edc984c98 merged 'Option.map' and 'Option.map_option'
blanchet
parents: 55404
diff changeset
    97
  unfolding map_option_case[abs_def] by transfer_prover
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    98
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    99
lemma option_bind_transfer [transfer_rule]:
55525
70b7e91fa1f9 folded 'rel_option' into 'option_rel'
blanchet
parents: 55466
diff changeset
   100
  "(rel_option A ===> (A ===> rel_option B) ===> rel_option B)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   101
    Option.bind Option.bind"
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   102
  unfolding fun_rel_def split_option_all by simp
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   103
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   104
end
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   105
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   106
end