author | Manuel Eberl <manuel@pruvisto.org> |
Tue, 22 Apr 2025 15:41:34 +0200 | |
changeset 82536 | e0892dfd1b27 |
parent 66453 | cc19f7ca2ed6 |
permissions | -rw-r--r-- |
62696 | 1 |
(* Title: HOL/Corec_Examples/Tests/TLList_Friends.thy |
2 |
Author: Aymeric Bouzy, Ecole polytechnique |
|
3 |
Author: Jasmin Blanchette, Inria, LORIA, MPII |
|
4 |
Copyright 2015, 2016 |
|
5 |
||
62726 | 6 |
Friendly functions on terminated lists. |
62696 | 7 |
*) |
8 |
||
62726 | 9 |
section \<open>Friendly Functions on Terminated Lists\<close> |
62696 | 10 |
|
11 |
theory TLList_Friends |
|
66453
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents:
62726
diff
changeset
|
12 |
imports "HOL-Library.BNF_Corec" |
62696 | 13 |
begin |
14 |
||
15 |
codatatype ('a, 'b) tllist = |
|
16 |
TLNil (trm: 'b) |
|
17 |
| TLCons (tlhd: 'a) (tltl: "('a, 'b) tllist") |
|
18 |
||
19 |
corec pls :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
20 |
"pls s s' = TLCons (tlhd s + tlhd s') (pls (tltl s) (tltl s'))" |
|
21 |
||
22 |
friend_of_corec pls where |
|
23 |
"pls s s' = TLCons (tlhd s + tlhd s') (pls (tltl s) (tltl s'))" |
|
24 |
sorry |
|
25 |
||
26 |
corec prd :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
27 |
"prd xs ys = TLCons (tlhd xs * tlhd ys) (pls (prd xs (tltl ys)) (prd (tltl xs) ys))" |
|
28 |
||
29 |
friend_of_corec prd where |
|
30 |
"prd xs ys = TLCons (tlhd xs * tlhd ys) (pls (prd xs (tltl ys)) (prd (tltl xs) ys))" |
|
31 |
sorry |
|
32 |
||
33 |
corec onetwo :: "(nat, 'b) tllist" where |
|
34 |
"onetwo = TLCons 1 (TLCons 2 onetwo)" |
|
35 |
||
36 |
corec Exp :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
37 |
"Exp xs = TLCons (2 ^^ tlhd xs) (prd (tltl xs) (Exp xs))" |
|
38 |
||
39 |
friend_of_corec Exp where |
|
40 |
"Exp xs = TLCons (2 ^^ tlhd xs) (prd (tltl xs) (Exp xs))" |
|
41 |
sorry |
|
42 |
||
43 |
corec prd2 :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
44 |
"prd2 xs ys = TLCons (tlhd xs * tlhd ys) (pls (prd xs (tltl ys)) (prd2 (tltl xs) ys))" |
|
45 |
||
62726 | 46 |
text \<open>Outer if:\<close> |
62696 | 47 |
|
48 |
corec takeUntilOdd :: "(int, int) tllist \<Rightarrow> (int, int) tllist" where |
|
49 |
"takeUntilOdd xs = |
|
50 |
(if is_TLNil xs then TLNil (trm xs) |
|
51 |
else if tlhd xs mod 2 = 0 then TLCons (tlhd xs) (takeUntilOdd (tltl xs)) |
|
52 |
else TLNil (tlhd xs))" |
|
53 |
||
54 |
friend_of_corec takeUntilOdd where |
|
55 |
"takeUntilOdd xs = |
|
56 |
(if is_TLNil xs then TLNil (trm xs) |
|
57 |
else if tlhd xs mod 2 = 0 then TLCons (tlhd xs) (takeUntilOdd (tltl xs)) |
|
58 |
else TLNil (tlhd xs))" |
|
59 |
sorry |
|
60 |
||
61 |
corec takeUntilEven :: "(int, int) tllist \<Rightarrow> (int, int) tllist" where |
|
62 |
"takeUntilEven xs = |
|
63 |
(case xs of |
|
64 |
TLNil y \<Rightarrow> TLNil y |
|
65 |
| TLCons y ys \<Rightarrow> |
|
66 |
if y mod 2 = 1 then TLCons y (takeUntilEven ys) |
|
67 |
else TLNil y)" |
|
68 |
||
69 |
friend_of_corec takeUntilEven where |
|
70 |
"takeUntilEven xs = |
|
71 |
(case xs of |
|
72 |
TLNil y \<Rightarrow> TLNil y |
|
73 |
| TLCons y ys \<Rightarrow> |
|
74 |
if y mod 2 = 1 then TLCons y (takeUntilEven ys) |
|
75 |
else TLNil y)" |
|
76 |
sorry |
|
77 |
||
62726 | 78 |
text \<open>If inside the constructor:\<close> |
62696 | 79 |
|
80 |
corec prd3 :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
81 |
"prd3 xs ys = TLCons (tlhd xs * tlhd ys) |
|
82 |
(if undefined then pls (prd xs (tltl ys)) (prd (tltl xs) ys) |
|
83 |
else prd3 (tltl xs) (tltl ys))" |
|
84 |
||
85 |
friend_of_corec prd3 where |
|
86 |
"prd3 xs ys = TLCons (tlhd xs * tlhd ys) |
|
87 |
(if undefined then pls (prd xs (tltl ys)) (prd (tltl xs) ys) |
|
88 |
else prd3 (tltl xs) (tltl ys))" |
|
89 |
sorry |
|
90 |
||
62726 | 91 |
text \<open>If inside the inner friendly operation:\<close> |
62696 | 92 |
|
93 |
corec prd4 :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
94 |
"prd4 xs ys = TLCons (tlhd xs * tlhd ys) |
|
95 |
(pls (if undefined then prd xs (tltl ys) else xs) (prd (tltl xs) ys))" |
|
96 |
||
97 |
friend_of_corec prd4 :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
98 |
"prd4 xs ys = TLCons (tlhd xs * tlhd ys) |
|
99 |
(pls (if undefined then prd xs (tltl ys) else xs) (prd (tltl xs) ys))" |
|
100 |
sorry |
|
101 |
||
62726 | 102 |
text \<open>Lots of if's:\<close> |
62696 | 103 |
|
104 |
corec iffy :: "(nat, 'b) tllist \<Rightarrow> (nat, 'b) tllist" where |
|
105 |
"iffy xs = |
|
106 |
(if undefined (0::nat) then |
|
107 |
TLNil undefined |
|
108 |
else |
|
109 |
Exp (if undefined (1::nat) then |
|
110 |
Exp undefined |
|
111 |
else |
|
112 |
TLCons undefined |
|
113 |
(if undefined (2::nat) then |
|
114 |
Exp (if undefined (3::nat) then |
|
115 |
Exp (if undefined (4::nat) then |
|
116 |
iffy (tltl xs) |
|
117 |
else if undefined (5::nat) then |
|
118 |
iffy xs |
|
119 |
else |
|
120 |
xs) |
|
121 |
else |
|
122 |
xs) |
|
123 |
else |
|
124 |
undefined)))" |
|
125 |
||
126 |
end |