src/HOL/Library/Quotient_List.thy
author paulson <lp15@cam.ac.uk>
Wed, 21 Feb 2018 12:57:49 +0000
changeset 67683 817944aeac3f
parent 67399 eab6ce8368fa
permissions -rw-r--r--
Lots of new material about matrices, etc.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47455
26315a545e26 updated headers;
wenzelm
parents: 47308
diff changeset
     1
(*  Title:      HOL/Library/Quotient_List.thy
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents: 52308
diff changeset
     2
    Author:     Cezary Kaliszyk and Christian Urban
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
*)
35788
f1deaca15ca3 observe standard header format;
wenzelm
parents: 35222
diff changeset
     4
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 58961
diff changeset
     5
section \<open>Quotient infrastructure for the list type\<close>
35788
f1deaca15ca3 observe standard header format;
wenzelm
parents: 35222
diff changeset
     6
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
theory Quotient_List
62954
c5d0fdc260fa tuned imports;
wenzelm
parents: 60500
diff changeset
     8
imports Quotient_Set Quotient_Product Quotient_Option
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
begin
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 58961
diff changeset
    11
subsection \<open>Rules for the Quotient package\<close>
47641
2cddc27a881f new transfer package rules and lifting setup for lists
huffman
parents: 47634
diff changeset
    12
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    13
lemma map_id [id_simps]:
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    14
  "map id = id"
46663
7fe029e818c2 explicit is better than implicit
haftmann
parents: 45806
diff changeset
    15
  by (fact List.map.id)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents: 52308
diff changeset
    17
lemma list_all2_eq [id_simps]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 63649
diff changeset
    18
  "list_all2 (=) = (=)"
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    19
proof (rule ext)+
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    20
  fix xs ys
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 63649
diff changeset
    21
  show "list_all2 (=) xs ys \<longleftrightarrow> xs = ys"
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    22
    by (induct xs ys rule: list_induct2') simp_all
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    23
qed
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    24
55564
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    25
lemma reflp_list_all2:
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    26
  assumes "reflp R"
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    27
  shows "reflp (list_all2 R)"
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    28
proof (rule reflpI)
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    29
  from assms have *: "\<And>xs. R xs xs" by (rule reflpE)
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    30
  fix xs
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    31
  show "list_all2 R xs xs"
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    32
    by (induct xs) (simp_all add: *)
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    33
qed
e81ee43ab290 delete or move now not necessary reflexivity rules due to 1726f46d2aa8
kuncar
parents: 53012
diff changeset
    34
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    35
lemma list_symp:
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    36
  assumes "symp R"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    37
  shows "symp (list_all2 R)"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    38
proof (rule sympI)
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    39
  from assms have *: "\<And>xs ys. R xs ys \<Longrightarrow> R ys xs" by (rule sympE)
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    40
  fix xs ys
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    41
  assume "list_all2 R xs ys"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    42
  then show "list_all2 R ys xs"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    43
    by (induct xs ys rule: list_induct2') (simp_all add: *)
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    44
qed
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    46
lemma list_transp:
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    47
  assumes "transp R"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    48
  shows "transp (list_all2 R)"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    49
proof (rule transpI)
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    50
  from assms have *: "\<And>xs ys zs. R xs ys \<Longrightarrow> R ys zs \<Longrightarrow> R xs zs" by (rule transpE)
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    51
  fix xs ys zs
45803
fe44c0b216ef remove some duplicate lemmas, simplify some proofs
huffman
parents: 40820
diff changeset
    52
  assume "list_all2 R xs ys" and "list_all2 R ys zs"
fe44c0b216ef remove some duplicate lemmas, simplify some proofs
huffman
parents: 40820
diff changeset
    53
  then show "list_all2 R xs zs"
fe44c0b216ef remove some duplicate lemmas, simplify some proofs
huffman
parents: 40820
diff changeset
    54
    by (induct arbitrary: zs) (auto simp: list_all2_Cons1 intro: *)
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    55
qed
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    56
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    57
lemma list_equivp [quot_equiv]:
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    58
  "equivp R \<Longrightarrow> equivp (list_all2 R)"
51994
82cc2aeb7d13 stronger reflexivity prover
kuncar
parents: 51956
diff changeset
    59
  by (blast intro: equivpI reflp_list_all2 list_symp list_transp elim: equivpE)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    61
lemma list_quotient3 [quot_thm]:
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    62
  assumes "Quotient3 R Abs Rep"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    63
  shows "Quotient3 (list_all2 R) (map Abs) (map Rep)"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    64
proof (rule Quotient3I)
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    65
  from assms have "\<And>x. Abs (Rep x) = x" by (rule Quotient3_abs_rep)
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    66
  then show "\<And>xs. map Abs (map Rep xs) = xs" by (simp add: comp_def)
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    67
next
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    68
  from assms have "\<And>x y. R (Rep x) (Rep y) \<longleftrightarrow> x = y" by (rule Quotient3_rel_rep)
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    69
  then show "\<And>xs. list_all2 R (map Rep xs) (map Rep xs)"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    70
    by (simp add: list_all2_map1 list_all2_map2 list_all2_eq)
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    71
next
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    72
  fix xs ys
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    73
  from assms have "\<And>x y. R x x \<and> R y y \<and> Abs x = Abs y \<longleftrightarrow> R x y" by (rule Quotient3_rel)
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    74
  then show "list_all2 R xs ys \<longleftrightarrow> list_all2 R xs xs \<and> list_all2 R ys ys \<and> map Abs xs = map Abs ys"
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    75
    by (induct xs ys rule: list_induct2') auto
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    76
qed
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    78
declare [[mapQ3 list = (list_all2, list_quotient3)]]
47094
1a7ad2601cb5 store the relational theorem for every relator
kuncar
parents: 46663
diff changeset
    79
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    80
lemma cons_prs [quot_preserve]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    81
  assumes q: "Quotient3 R Abs Rep"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 63649
diff changeset
    82
  shows "(Rep ---> (map Rep) ---> (map Abs)) (#) = (#)"
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    83
  by (auto simp add: fun_eq_iff comp_def Quotient3_abs_rep [OF q])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    85
lemma cons_rsp [quot_respect]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    86
  assumes q: "Quotient3 R Abs Rep"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 63649
diff changeset
    87
  shows "(R ===> list_all2 R ===> list_all2 R) (#) (#)"
40463
75e544159549 fun_rel_def is no simp rule by default
haftmann
parents: 40032
diff changeset
    88
  by auto
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    89
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    90
lemma nil_prs [quot_preserve]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    91
  assumes q: "Quotient3 R Abs Rep"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
  shows "map Abs [] = []"
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
  by simp
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    94
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
    95
lemma nil_rsp [quot_respect]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
    96
  assumes q: "Quotient3 R Abs Rep"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
    97
  shows "list_all2 R [] []"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
  by simp
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   100
lemma map_prs_aux:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   101
  assumes a: "Quotient3 R1 abs1 rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   102
  and     b: "Quotient3 R2 abs2 rep2"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
  shows "(map abs2) (map ((abs1 ---> rep2) f) (map rep1 l)) = map f l"
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   104
  by (induct l)
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   105
     (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   106
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
   107
lemma map_prs [quot_preserve]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   108
  assumes a: "Quotient3 R1 abs1 rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   109
  and     b: "Quotient3 R2 abs2 rep2"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   110
  shows "((abs1 ---> rep2) ---> (map rep1) ---> (map abs2)) map = map"
36216
8fb6cc6f3b94 respectfullness and preservation of map for identity quotients
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36154
diff changeset
   111
  and   "((abs1 ---> id) ---> map rep1 ---> id) map = map"
40463
75e544159549 fun_rel_def is no simp rule by default
haftmann
parents: 40032
diff changeset
   112
  by (simp_all only: fun_eq_iff map_prs_aux[OF a b] comp_def)
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   113
    (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
40463
75e544159549 fun_rel_def is no simp rule by default
haftmann
parents: 40032
diff changeset
   114
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
   115
lemma map_rsp [quot_respect]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   116
  assumes q1: "Quotient3 R1 Abs1 Rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   117
  and     q2: "Quotient3 R2 Abs2 Rep2"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   118
  shows "((R1 ===> R2) ===> (list_all2 R1) ===> list_all2 R2) map map"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 63649
diff changeset
   119
  and   "((R1 ===> (=)) ===> (list_all2 R1) ===> (=)) map map"
58961
7c507e664047 dropped redundant transfer rules (now proved and registered by datatype and plugins)
traytel
parents: 58881
diff changeset
   120
  unfolding list_all2_eq [symmetric] by (rule list.map_transfer)+
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   122
lemma foldr_prs_aux:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   123
  assumes a: "Quotient3 R1 abs1 rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   124
  and     b: "Quotient3 R2 abs2 rep2"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   125
  shows "abs2 (foldr ((abs1 ---> abs2 ---> rep2) f) (map rep1 l) (rep2 e)) = foldr f l e"
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   126
  by (induct l) (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   127
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
   128
lemma foldr_prs [quot_preserve]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   129
  assumes a: "Quotient3 R1 abs1 rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   130
  and     b: "Quotient3 R2 abs2 rep2"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
  shows "((abs1 ---> abs2 ---> rep2) ---> (map rep1) ---> rep2 ---> abs2) foldr = foldr"
40463
75e544159549 fun_rel_def is no simp rule by default
haftmann
parents: 40032
diff changeset
   132
  apply (simp add: fun_eq_iff)
75e544159549 fun_rel_def is no simp rule by default
haftmann
parents: 40032
diff changeset
   133
  by (simp only: fun_eq_iff foldr_prs_aux[OF a b])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   134
     (simp)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   136
lemma foldl_prs_aux:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   137
  assumes a: "Quotient3 R1 abs1 rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   138
  and     b: "Quotient3 R2 abs2 rep2"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
  shows "abs1 (foldl ((abs1 ---> abs2 ---> rep1) f) (rep1 e) (map rep2 l)) = foldl f e l"
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   140
  by (induct l arbitrary:e) (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
   142
lemma foldl_prs [quot_preserve]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   143
  assumes a: "Quotient3 R1 abs1 rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   144
  and     b: "Quotient3 R2 abs2 rep2"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   145
  shows "((abs1 ---> abs2 ---> rep1) ---> rep1 ---> (map rep2) ---> abs1) foldl = foldl"
40463
75e544159549 fun_rel_def is no simp rule by default
haftmann
parents: 40032
diff changeset
   146
  by (simp add: fun_eq_iff foldl_prs_aux [OF a b])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   147
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   148
lemma foldl_rsp[quot_respect]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   149
  assumes q1: "Quotient3 R1 Abs1 Rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   150
  and     q2: "Quotient3 R2 Abs2 Rep2"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   151
  shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_all2 R2 ===> R1) foldl foldl"
47641
2cddc27a881f new transfer package rules and lifting setup for lists
huffman
parents: 47634
diff changeset
   152
  by (rule foldl_transfer)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   154
lemma foldr_rsp[quot_respect]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   155
  assumes q1: "Quotient3 R1 Abs1 Rep1"
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   156
  and     q2: "Quotient3 R2 Abs2 Rep2"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   157
  shows "((R1 ===> R2 ===> R2) ===> list_all2 R1 ===> R2 ===> R2) foldr foldr"
47641
2cddc27a881f new transfer package rules and lifting setup for lists
huffman
parents: 47634
diff changeset
   158
  by (rule foldr_transfer)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   160
lemma list_all2_rsp:
36154
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   161
  assumes r: "\<forall>x y. R x y \<longrightarrow> (\<forall>a b. R a b \<longrightarrow> S x a = T y b)"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   162
  and l1: "list_all2 R x y"
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   163
  and l2: "list_all2 R a b"
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   164
  shows "list_all2 S x a = list_all2 T y b"
45803
fe44c0b216ef remove some duplicate lemmas, simplify some proofs
huffman
parents: 40820
diff changeset
   165
  using l1 l2
fe44c0b216ef remove some duplicate lemmas, simplify some proofs
huffman
parents: 40820
diff changeset
   166
  by (induct arbitrary: a b rule: list_all2_induct,
fe44c0b216ef remove some duplicate lemmas, simplify some proofs
huffman
parents: 40820
diff changeset
   167
    auto simp: list_all2_Cons1 list_all2_Cons2 r)
36154
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   168
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
   169
lemma [quot_respect]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 63649
diff changeset
   170
  "((R ===> R ===> (=)) ===> list_all2 R ===> list_all2 R ===> (=)) list_all2 list_all2"
58961
7c507e664047 dropped redundant transfer rules (now proved and registered by datatype and plugins)
traytel
parents: 58881
diff changeset
   171
  by (rule list.rel_transfer)
36154
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   172
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
   173
lemma [quot_preserve]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   174
  assumes a: "Quotient3 R abs1 rep1"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   175
  shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_all2 = list_all2"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   176
  apply (simp add: fun_eq_iff)
36154
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   177
  apply clarify
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   178
  apply (induct_tac xa xb rule: list_induct2')
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   179
  apply (simp_all add: Quotient3_abs_rep[OF a])
36154
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   180
  done
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   181
40820
fd9c98ead9a9 more systematic and compact proofs on type relation operators using natural deduction rules
haftmann
parents: 40463
diff changeset
   182
lemma [quot_preserve]:
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   183
  assumes a: "Quotient3 R abs1 rep1"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   184
  shows "(list_all2 ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 47094
diff changeset
   185
  by (induct l m rule: list_induct2') (simp_all add: Quotient3_rel_rep[OF a])
36154
11c6106d7787 Respectfullness and preservation of list_rel
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 35788
diff changeset
   186
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   187
lemma list_all2_find_element:
36276
92011cc923f5 fun_rel introduction and list_rel elimination for quotient package
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36216
diff changeset
   188
  assumes a: "x \<in> set a"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   189
  and b: "list_all2 R a b"
36276
92011cc923f5 fun_rel introduction and list_rel elimination for quotient package
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36216
diff changeset
   190
  shows "\<exists>y. (y \<in> set b \<and> R x y)"
45803
fe44c0b216ef remove some duplicate lemmas, simplify some proofs
huffman
parents: 40820
diff changeset
   191
  using b a by induct auto
36276
92011cc923f5 fun_rel introduction and list_rel elimination for quotient package
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36216
diff changeset
   192
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   193
lemma list_all2_refl:
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   194
  assumes a: "\<And>x y. R x y = (R x = R y)"
37492
ab36b1a50ca8 Replace 'list_rel' by 'list_all2'; they are equivalent.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36812
diff changeset
   195
  shows "list_all2 R x x"
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   196
  by (induct x) (auto simp add: a)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   197
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   198
end