Quot/QuotSum.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri, 08 Jan 2010 15:02:12 +0100
changeset 829 42b90994ac77
parent 779 3b21b24a5fb6
child 924 5455b19ef138
permissions -rw-r--r--
map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
     1
theory QuotSum
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
     2
imports QuotMain
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
fun
545
95371a8b17e1 Cleaning the Quotients file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 538
diff changeset
     6
  sum_rel
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
where
545
95371a8b17e1 Cleaning the Quotients file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 538
diff changeset
     8
  "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
95371a8b17e1 Cleaning the Quotients file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 538
diff changeset
     9
| "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
95371a8b17e1 Cleaning the Quotients file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 538
diff changeset
    10
| "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
95371a8b17e1 Cleaning the Quotients file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 538
diff changeset
    11
| "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
fun
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  sum_map
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
where
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  "sum_map f1 f2 (Inl a) = Inl (f1 a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
| "sum_map f1 f2 (Inr a) = Inr (f2 a)"
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 698
diff changeset
    19
declare [[map "+" = (sum_map, sum_rel)]]
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 698
diff changeset
    20
545
95371a8b17e1 Cleaning the Quotients file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 538
diff changeset
    21
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    22
lemma sum_equivp[quot_equiv]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    23
  assumes a: "equivp R1"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    24
  assumes b: "equivp R2"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    25
  shows "equivp (sum_rel R1 R2)"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    26
unfolding equivp_reflp_symp_transp reflp_def symp_def transp_def
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    27
apply(auto)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    28
apply(case_tac x)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    29
apply(auto simp add: equivp_reflp[OF a] equivp_reflp[OF b])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    30
apply(case_tac x)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    31
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    32
prefer 3
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    33
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    34
apply(auto simp add: equivp_symp[OF a] equivp_symp[OF b])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    35
apply(case_tac x)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    36
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    37
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    38
prefer 3
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    39
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    40
prefer 5
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    41
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    42
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    43
prefer 3
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    44
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    45
apply(auto)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    46
apply(metis equivp_transp[OF b])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    47
apply(metis equivp_transp[OF a])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    48
done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    50
lemma sum_fun_fun:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    51
  assumes q1: "Quotient R1 Abs1 Rep1"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    52
  assumes q2: "Quotient R2 Abs2 Rep2"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    53
  shows  "sum_rel R1 R2 r s =
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    54
          (sum_rel R1 R2 r r \<and> sum_rel R1 R2 s s \<and> sum_map Abs1 Abs2 r = sum_map Abs1 Abs2 s)"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    55
  using q1 q2
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    56
  apply(case_tac r)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    57
  apply(case_tac s)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    58
  apply(simp_all)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    59
  prefer 2
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    60
  apply(case_tac s)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    61
  apply(auto)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    62
  unfolding Quotient_def 
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    63
  apply metis+
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    64
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    66
lemma sum_quotient[quot_thm]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    67
  assumes q1: "Quotient R1 Abs1 Rep1"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    68
  assumes q2: "Quotient R2 Abs2 Rep2"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    69
  shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    70
  unfolding Quotient_def
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    71
  apply(rule conjI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    72
  apply(rule allI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    73
  apply(case_tac a)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    74
  apply(simp add: Quotient_abs_rep[OF q1])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    75
  apply(simp add: Quotient_abs_rep[OF q2])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    76
  apply(rule conjI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    77
  apply(rule allI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    78
  apply(case_tac a)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    79
  apply(simp add: Quotient_rel_rep[OF q1])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    80
  apply(simp add: Quotient_rel_rep[OF q2])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    81
  apply(rule allI)+
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    82
  apply(rule sum_fun_fun[OF q1 q2])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    83
  done
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    84
829
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    85
lemma sum_map_id[id_simps]: "sum_map id id \<equiv> id"
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    86
  apply (rule eq_reflection)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    87
  apply (rule ext)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    88
  apply (case_tac x)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    89
  apply (auto)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    90
  done
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    91
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    92
lemma sum_rel_eq[id_simps]: "sum_rel op = op = \<equiv> op ="
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    93
  apply (rule eq_reflection)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    94
  apply (rule ext)+
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    95
  apply (case_tac x)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    96
  apply auto
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    97
  apply (case_tac xa)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    98
  apply auto
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    99
  apply (case_tac xa)
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
   100
  apply auto
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
   101
  done
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
   102
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
   103
end