Quot/QuotList.thy
author Christian Urban <urbanc@in.tum.de>
Sun, 13 Dec 2009 02:35:34 +0100
changeset 741 8437359e811c
parent 668 ef5b941f00e2
child 768 e9e205b904e2
permissions -rw-r--r--
another pass on apply_rsp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory QuotList
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
     2
imports QuotMain List
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
537
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
     6
  list_rel
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
where
537
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
     8
  "list_rel R [] [] = True"
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
     9
| "list_rel R (x#xs) [] = False"
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
    10
| "list_rel R [] (x#xs) = False"
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
    11
| "list_rel R (x#xs) (y#ys) = (R x y \<and> list_rel R xs ys)"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    13
declare [[map list = (map, list_rel)]]
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    14
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 623
diff changeset
    15
lemma list_equivp[quot_equiv]:
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
    16
  assumes a: "equivp R"
537
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
    17
  shows "equivp (list_rel R)"
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    18
  unfolding equivp_def
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    19
  apply(rule allI)+
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    20
  apply(induct_tac x y rule: list_induct2')
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    21
  apply(simp_all add: expand_fun_eq)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    22
  apply(metis list_rel.simps(1) list_rel.simps(2))
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    23
  apply(metis list_rel.simps(1) list_rel.simps(2))
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    24
  apply(rule iffI)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    25
  apply(rule allI)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    26
  apply(case_tac x)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    27
  apply(simp_all)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    28
  using a
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    29
  apply(unfold equivp_def)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    30
  apply(auto)[1]
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    31
  apply(metis list_rel.simps(4))
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    32
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    34
lemma list_rel_rel:
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
    35
  assumes q: "Quotient R Abs Rep"
537
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
    36
  shows "list_rel R r s = (list_rel R r r \<and> list_rel R s s \<and> (map Abs r = map Abs s))"
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    37
  apply(induct r s rule: list_induct2')
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    38
  apply(simp_all)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    39
  using Quotient_rel[OF q]
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    40
  apply(metis)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    41
  done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 623
diff changeset
    43
lemma list_quotient[quot_thm]:
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
    44
  assumes q: "Quotient R Abs Rep"
537
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
    45
  shows "Quotient (list_rel R) (map Abs) (map Rep)"
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    46
  unfolding Quotient_def
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    47
  apply(rule conjI)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    48
  apply(rule allI)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    49
  apply(induct_tac a)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    50
  apply(simp)
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    51
  apply(simp add: Quotient_abs_rep[OF q])
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    52
  apply(rule conjI)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    53
  apply(rule allI)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    54
  apply(induct_tac a)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    55
  apply(simp)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    56
  apply(simp)
541
94deffed619d more name cleaning and removing
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 540
diff changeset
    57
  apply(simp add: Quotient_rep_reflp[OF q])
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    58
  apply(rule allI)+
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    59
  apply(rule list_rel_rel[OF q])
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    60
  done
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    61
600
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    62
lemma map_id: "map id \<equiv> id"
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    63
  apply (rule eq_reflection)
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    64
  apply (rule ext)
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    65
  apply (rule_tac list="x" in list.induct)
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    66
  apply (simp_all)
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    67
  done
5d932e7a856c List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 597
diff changeset
    68
644
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    69
lemma cons_prs_aux:
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    70
  assumes q: "Quotient R Abs Rep"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    71
  shows "(map Abs) ((Rep h) # (map Rep t)) = h # t"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    72
by (induct t) (simp_all add: Quotient_abs_rep[OF q])
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
    73
644
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    74
lemma cons_prs[quot_preserve]:
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    75
  assumes q: "Quotient R Abs Rep"
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    76
  shows "(Rep ---> (map Rep) ---> (map Abs)) (op #) = (op #)"
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    77
by (simp only: expand_fun_eq fun_map.simps cons_prs_aux[OF q])
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    78
   (simp)
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    79
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 623
diff changeset
    80
lemma cons_rsp[quot_respect]:
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
    81
  assumes q: "Quotient R Abs Rep"
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    82
  shows "(R ===> list_rel R ===> list_rel R) op # op #"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    83
by (auto)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
644
97a397ba5743 started to reformulate preserve lemmas
Christian Urban <urbanc@in.tum.de>
parents: 636
diff changeset
    85
lemma nil_prs[quot_preserve]:
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
    86
  assumes q: "Quotient R Abs Rep"
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    87
  shows "map Abs [] \<equiv> []"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
by (simp)
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 623
diff changeset
    90
lemma nil_rsp[quot_respect]:
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
    91
  assumes q: "Quotient R Abs Rep"
537
57073b0b8fac Even more name changes and cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 533
diff changeset
    92
  shows "list_rel R [] []"
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
by simp
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
645
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
    95
lemma map_prs_aux:
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    96
  assumes a: "Quotient R1 abs1 rep1"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    97
  and     b: "Quotient R2 abs2 rep2"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    98
  shows "(map abs2) (map ((abs1 ---> rep2) f) (map rep1 l)) = map f l"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
    99
by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
645
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   101
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   102
lemma map_prs[quot_preserve]:
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   103
  assumes a: "Quotient R1 abs1 rep1"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   104
  and     b: "Quotient R2 abs2 rep2"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   105
  shows "((abs1 ---> rep2) ---> (map rep1) ---> (map abs2)) map = map"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   106
by (simp only: expand_fun_eq fun_map.simps map_prs_aux[OF a b])
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   107
   (simp)
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   108
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   109
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 623
diff changeset
   110
lemma map_rsp[quot_respect]:
529
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
   111
  assumes q1: "Quotient R1 Abs1 Rep1"
6348c2a57ec2 More name changes
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 515
diff changeset
   112
  and     q2: "Quotient R2 Abs2 Rep2"
565
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   113
  shows "((R1 ===> R2) ===> (list_rel R1) ===> list_rel R2) map map"
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   114
apply(simp)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   115
apply(rule allI)+
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   116
apply(rule impI)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   117
apply(rule allI)+
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   118
apply (induct_tac xa ya rule: list_induct2')
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   119
apply simp_all
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   120
done
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   121
645
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   122
lemma foldr_prs_aux:
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   123
  assumes a: "Quotient R1 abs1 rep1"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   124
  and     b: "Quotient R2 abs2 rep2"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   125
  shows "abs2 (foldr ((abs1 ---> abs2 ---> rep2) f) (map rep1 l) (rep2 e)) = foldr f l e"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   126
by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   127
645
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   128
lemma foldr_prs[quot_respect]:
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   129
  assumes a: "Quotient R1 abs1 rep1"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   130
  and     b: "Quotient R2 abs2 rep2"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   131
  shows "((abs1 ---> abs2 ---> rep2) ---> (map rep1) ---> rep2 ---> abs2) foldr = foldr"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   132
by (simp only: expand_fun_eq fun_map.simps foldr_prs_aux[OF a b])
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   133
   (simp)
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   134
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   135
lemma foldl_prs_aux:
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   136
  assumes a: "Quotient R1 abs1 rep1"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   137
  and     b: "Quotient R2 abs2 rep2"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   138
  shows "abs1 (foldl ((abs1 ---> abs2 ---> rep1) f) (rep1 e) (map rep2 l)) = foldl f e l"
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   139
by (induct l arbitrary:e) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
645
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   141
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   142
lemma foldl_prs[quot_preserve]:
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   143
  assumes a: "Quotient R1 abs1 rep1"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   144
  and     b: "Quotient R2 abs2 rep2"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   145
  shows "((abs1 ---> abs2 ---> rep1) ---> rep1 ---> (map rep2) ---> abs1) foldl = foldl"
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   146
by (simp only: expand_fun_eq fun_map.simps foldl_prs_aux[OF a b])
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   147
   (simp)
fe2a37cfecd3 proper formulation of all preservation theorems
Christian Urban <urbanc@in.tum.de>
parents: 644
diff changeset
   148
565
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   149
lemma list_rel_empty: "list_rel R [] b \<Longrightarrow> length b = 0"
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   150
by (induct b) (simp_all)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
565
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   152
lemma list_rel_len: "list_rel R a b \<Longrightarrow> length a = length b"
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   153
apply (induct a arbitrary: b)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   154
apply (simp add: list_rel_empty)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   155
apply (case_tac b)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   156
apply simp_all
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   157
done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
668
ef5b941f00e2 Code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 666
diff changeset
   159
(* induct_tac doesn't accept 'arbitrary', so we manually 'spec' *)
636
520a4084d064 changed names of attributes
Christian Urban <urbanc@in.tum.de>
parents: 623
diff changeset
   160
lemma foldl_rsp[quot_respect]:
565
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   161
  assumes q1: "Quotient R1 Abs1 Rep1"
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   162
  and     q2: "Quotient R2 Abs2 Rep2"
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   163
  shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_rel R2 ===> R1) foldl foldl"
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   164
apply auto
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   165
apply (subgoal_tac "R1 xa ya \<longrightarrow> list_rel R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   166
apply simp
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   167
apply (rule_tac x="xa" in spec)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   168
apply (rule_tac x="ya" in spec)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   169
apply (rule_tac xs="xb" and ys="yb" in list_induct2)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   170
apply (rule list_rel_len)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   171
apply (simp_all)
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   172
done
baff284c6fcc Proved foldl_rsp and ho_map_rsp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 541
diff changeset
   173
666
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   174
lemma foldr_rsp[quot_respect]:
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   175
  assumes q1: "Quotient R1 Abs1 Rep1"
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   176
  and     q2: "Quotient R2 Abs2 Rep2"
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   177
  shows "((R1 ===> R2 ===> R2) ===> list_rel R1 ===> R2 ===> R2) foldr foldr"
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   178
apply auto
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   179
apply(subgoal_tac "R2 xb yb \<longrightarrow> list_rel R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   180
apply simp
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   181
apply (rule_tac xs="xa" and ys="ya" in list_induct2)
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   182
apply (rule list_rel_len)
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   183
apply (simp_all)
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   184
done
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   185
666
adcceaf31f92 foldr_rsp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 645
diff changeset
   186
(* Rest are unused *)
540
c0b13fb70d6d More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 539
diff changeset
   187
541
94deffed619d more name cleaning and removing
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 540
diff changeset
   188
lemma list_rel_eq:
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   189
  shows "list_rel (op =) \<equiv> (op =)"
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   190
apply(rule eq_reflection)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   191
unfolding expand_fun_eq
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   192
apply(rule allI)+
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   193
apply(induct_tac x xa rule: list_induct2')
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   194
apply(simp_all)
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   195
done
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
541
94deffed619d more name cleaning and removing
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 540
diff changeset
   197
lemma list_rel_refl:
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   198
  assumes a: "\<And>x y. R x y = (R x = R y)"
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   199
  shows "list_rel R x x"
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   200
by (induct x) (auto simp add: a)
0
ebe0ea8fe247 initial commit
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
539
8287fb5b8d7a Cleaning & Renaming coming from QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 537
diff changeset
   202
end