Quot/QuotSum.thy
author Christian Urban <urbanc@in.tum.de>
Sat, 12 Dec 2009 15:07:59 +0100
changeset 734 ac2ed047988d
parent 698 ed44eaaea63e
child 779 3b21b24a5fb6
permissions -rw-r--r--
annotated some questions to the code; some simple changes
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
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    19
declare [[map * = (sum_map, sum_rel)]]
545
95371a8b17e1 Cleaning the Quotients file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 538
diff changeset
    20
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    21
lemma sum_equivp[quot_equiv]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    22
  assumes a: "equivp R1"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    23
  assumes b: "equivp R2"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    24
  shows "equivp (sum_rel R1 R2)"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    25
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
    26
apply(auto)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    27
apply(case_tac x)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    28
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
    29
apply(case_tac x)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    30
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    31
prefer 3
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    32
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    33
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
    34
apply(case_tac x)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    35
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    36
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    37
prefer 3
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    38
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    39
prefer 5
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    40
apply(case_tac y)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    41
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    42
prefer 3
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    43
apply(case_tac z)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    44
apply(auto)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    45
apply(metis equivp_transp[OF b])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    46
apply(metis equivp_transp[OF a])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    47
done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    49
lemma sum_fun_fun:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    50
  assumes q1: "Quotient R1 Abs1 Rep1"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    51
  assumes q2: "Quotient R2 Abs2 Rep2"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    52
  shows  "sum_rel R1 R2 r s =
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    53
          (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
    54
  using q1 q2
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    55
  apply(case_tac r)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    56
  apply(case_tac s)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    57
  apply(simp_all)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    58
  prefer 2
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    59
  apply(case_tac s)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    60
  apply(auto)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    61
  unfolding Quotient_def 
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    62
  apply metis+
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    63
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    65
lemma sum_quotient[quot_thm]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    66
  assumes q1: "Quotient R1 Abs1 Rep1"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    67
  assumes q2: "Quotient R2 Abs2 Rep2"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    68
  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
    69
  unfolding Quotient_def
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    70
  apply(rule conjI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    71
  apply(rule allI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    72
  apply(case_tac a)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    73
  apply(simp add: Quotient_abs_rep[OF q1])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    74
  apply(simp add: Quotient_abs_rep[OF q2])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    75
  apply(rule conjI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    76
  apply(rule allI)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    77
  apply(case_tac a)
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    78
  apply(simp add: Quotient_rel_rep[OF q1])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    79
  apply(simp add: Quotient_rel_rep[OF q2])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    80
  apply(rule allI)+
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    81
  apply(rule sum_fun_fun[OF q1 q2])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    82
  done
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    83
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 613
diff changeset
    84
end