SlideShare a Scribd company logo
1 of 90
Download to read offline
Program Language
Program Derivation
郗昀彥 (代)
3
Construction?
Derivation!
Program
4
Algorithm
5
Efficient Program
Specification
Algorithm
6
Specification
Efficient Program
Algorithm
•Hard
•Depend on Tools
•Correctness by Testing
7
Efficient Program
Specification
Algorithm
•Straightforward
•Math. or Logic
8
Algorithm
Efficient Program
Specification
•Correctness by Verification
•Model Checking
•Automata
9
Algorithm
Efficient Program
Specification •Program Construction
•Derivation
•Synthesis
•Hoare Logic
10
Program
Derivation
11
•fold
•fold fusion
•list homomorphism
•3rd list homomorphism theorem
foldr
In computer science,
a list or sequence is an
abstract data type that
implements a finite ordered
collection of values, where
the same value may occur more
than once.
- wikipedia
1 2 3 4 5
1 2 3 4 5: : : : :
data List a = []
| a : (List a)
1 2 3 4 5 [ ]: : : : :
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
1 2 3 4 5: : : : :
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
[ ]
1 2 3 4 5: : : : :
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
[ ]
1 2 3 4 5: : : : :
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
[ ]
1 2 3 4 5: : : : :
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
[ ]
1 2 3 4 5: : : : :
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
[ ]
1 2 3 4 5: : : : : e
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
1 2 3 4 5: : : : e◁
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
1 2 3 4 5: : : e◁◁
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
1 2 3 4 5: : e◁◁◁
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
1 2 3 4 5: e◁◁◁◁
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
foldr :: (a → b → b) → b →
[a] → b
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
1 2 3 4 5 e◁◁◁◁◁
sum [1..1000]
=>
foldr (+) 0 [1..1000]
1 + (foldr (+) 0 [2..1000])
1 + (2 + (foldr (+) 0 [3..1000]))
...
1 + (2 + (... + (1000 + (foldr (+) 0 []))...))
1 + (2 + (... + (1000 + 0)...)))
...
1 + (2 + 500497)
1 + 500499
500500
sum [1..1000]
=>
foldr (+) 0 [1..1000]
1 + (foldr (+) 0 [2..1000])
1 + (2 + (foldr (+) 0 [3..1000]))
...
1 + (2 + (... + (1000 + (foldr (+) 0 []))...))
1 + (2 + (... + (1000 + 0)...)))
...
1 + (2 + 500497)
1 + 500499
500500
1 + (2 + (... + (1000 + 0)...)))
length :: [a] → Int
sum :: (Num a) ⇒ [a] → a
map :: (a → b) → [a] → [b]
filter :: (a → Bool) → [a] → [a]
inits :: [a] → [[a]]
concat :: [[a]] → [a]
maximum :: (Ord a) ⇒ [a] → a
e ?
(◁) ?
foldl
1 2 3 4 5 [ ]: : : : :
foldr :: (a → b → b) → b → [a] → b
foldl :: (b → a → b) → b → [a] → b
foldl (▷) e [] = e
foldl (▷) e (x : xs) =
foldl (▷) (e ▷ x) xs
1 2 3 [ ]: : :
foldl (▷) Para0 Para1
{
{
e
1 2 3 [ ]: : :
foldl (▷) Para0 Para1
{
{
e 1▷
1 2 3 [ ]: : :
foldl (▷) Para0 Para1
{
{
e 1▷ 2▷
1 2 3 [ ]: : :
foldl (▷) Para0 Para1
{
{
e 1▷ 2▷ 3▷
13
sum [1..1000]
=>
foldl (+) 0 [1..1000]
foldl (+) (0 + 1) [2..1000]
foldr (+) (1 + 2) [3..1000]
foldr (+) (3 + 3) [4..1000]
...
foldr (+) (498501 + 999) [1000]
foldr (+) (499500 + 1000) []
foldr (+) 500500 []
500500
13
sum [1..1000]
=>
foldl (+) 0 [1..1000]
foldl (+) (0 + 1) [2..1000]
foldr (+) (1 + 2) [3..1000]
foldr (+) (3 + 3) [4..1000]
...
foldr (+) (498501 + 999) [1000]
foldr (+) (499500 + 1000) []
foldr (+) 500500 []
500500
length :: [a] → Int
sum :: (Num a) ⇒ [a] → a
map :: (a → b) → [a] → [b]
filter :: (a → Bool) → [a] → [a]
concat :: [[a]] → [a]
maximum :: (Ord a) ⇒ [a] → a
e ?
(▷) ?
fusion
42
map f ◦ map g
42
map (f ◦ g)
43
filter q ◦ filter p
43
filter (q ∧ p)
44
foldr-fusion
f ◦ foldr (◁) e
44
foldr-fusion
⇐ f (x ◁ z) = x ≪ (f z)
foldr (≪) (f e)
45
f $ foldr (◁) e []
= { definition of foldr }
f e
= { definition of foldr }
foldr (≪) (f e) []
foldr-fusion
f ◦ foldr (◁) e = foldr (≪) (f e)
46
f $ foldr (◁) e (x:xs)
= f (x ◁ (foldr (◁) e xs))
= { f (x ◁ z) = x ≪ (f z) }
x ≪ (f (foldr (◁) e xs))
= x ≪ (foldr (≪) (f e) xs)
= foldr (≪) (f e) (x:xs)
foldr-fusion
f ◦ foldr (◁) e = foldr (≪) (f e)
47
f $ foldr (◁) e (x:xs)
= f (x ◁ (foldr (◁) e xs))
= { f (x ◁ z) = x ≪ (f z) }
x ≪ (f (foldr (◁) e xs))
= x ≪ (foldr (≪) (f e) xs)
= foldr (≪) (f e) (x:xs)
foldr-fusion
f ◦ foldr (◁) e = foldr (≪) (f e)
48
f $ foldr (◁) e (x:xs)
= f (x ◁ (foldr (◁) e xs))
= { f (x ◁ z) = x ≪ (f z) }
x ≪ (f (foldr (◁) e xs))
= x ≪ (foldr (≪) (f e) xs)
= foldr (≪) (f e) (x:xs)
foldr-fusion
f ◦ foldr (◁) e = foldr (≪) (f e)
49
f $ foldr (◁) e (x:xs)
= f (x ◁ (foldr (◁) e xs))
= { f (x ◁ z) = x ≪ (f z) }
x ≪ (f (foldr (◁) e xs))
= x ≪ (foldr (≪) (f e) xs)
= foldr (≪) (f e) (x:xs)
foldr-fusion
f ◦ foldr (◁) e = foldr (≪) (f e)
50
f $ foldr (◁) e (x:xs)
= f (x ◁ (foldr (◁) e xs))
= { f (x ◁ z) = x ≪ (f z) }
x ≪ (f (foldr (◁) e xs))
= x ≪ (foldr (≪) (f e) xs)
= foldr (≪) (f e) (x:xs)
foldr-fusion
f ◦ foldr (◁) e = foldr (≪) (f e)
51
http://www.openrice.com/restaurant/
commentdetail.htm?commentid=2106508
範例
52
inits :: [a] → [[a]]
tails :: [a] → [[a]]
concat :: [[a]] → [a]
filter :: (a → Bool) → [a] → [a]
power :: [a] → [[a]]
filter (/=[])◦concat◦map tails◦inits
Suffixes of Prefixes
53
inits :: [a] → [[a]]
inits [] = [[]]
inits (x:xs) = [] : map (x:) (inits xs)
filter (/=[])◦concat◦map tails◦inits
Suffixes of Prefixes
54
inits :: [a] → [[a]]
inits [] = [[]]
inits (x:xs) = [] : map (x:) (inits xs)
inits’ =
foldr (x hs → [] : (map (x:) hs)) [[]]
filter (/=[])◦concat◦map tails◦inits
Suffixes of Prefixes
55
filter (/=[])◦concat◦map tails◦inits
map tails ◦ inits
= f ◦ foldr (◁) [[]]
foldr-fusion
= foldr (≪) (map tails [[]])
= foldr (≪) [[[]]]
1. f = map tails
2. (◁) = x hs → [] : (map (x:) hs)
Suffixes of Prefixes
56
filter (/=[])◦concat◦map tails◦inits
map tails ◦ inits
= f ◦ foldr (◁) [[]]
foldr-fusion
= foldr (≪) (map tails [[]])
= foldr (≪) [[[]]]
1. f = map tails
2. (◁) = x hs → [] : (map (x:) hs)
3. (≪) = x h → [[]] : map (hs → (x : (head hs)) : hs) h
Suffixes of Prefixes
57
filter (/=[])◦concat◦foldr (≪) [[[]]]
filter (/=[]) ◦ concat
= g ◦ foldr (++) []
foldr-fusion
= foldr (⋆) []
1. g = filter (/=[])
2. (⋆) = x h → filter (/=[]) x) ++ h
Suffixes of Prefixes
58
filter (/=[]) ◦ concat
= g ◦ foldr (++) []
foldr-fusion
= foldr (⋆) []
1. g = filter (/=[])
2. (⋆) = x h → filter (/=[]) x) ++ h
filter (/=[])◦concat◦foldr (≪) [[[]]]
Suffixes of Prefixes
59
foldr (⋆) []◦foldr (≪) [[[]]]
= foldr (⊙) []
1. (≪) = x h → [[]] : map (hs → (x : (head hs)) : hs) h
2. (⋆) = x h → filter (/=[]) x) ++ h
Suffixes of Prefixes
if... foldr (⋆) [] (x ≪ z)
= x ⊙ (foldr (⋆) [] z)
60
foldr (⋆) []◦foldr (≪) [[[]]]
= foldr (⊙) []
1. (≪) = x h → [[]] : map (hs → (x : (head hs)) : hs) h
2. (⋆) = x h → filter (/=[]) x) ++ h
Suffixes of Prefixes
if... foldr (⋆) [] (x ≪ z)
= x ⊙ (foldr (⋆) [] z)
... after 3 hours
61
fusion
foldl
foldr
62
1 2 3
1 2 3: : :
data ConsList a = []
| a : (ConsList a)
63
1 2 3
1 2 3‡ ‡‡
data SnocList a = []
| (SnocList a) ‡ a
64
1 2 3‡ ‡‡
f (▷) e
e 1▷ 2▷ 3▷
65
1 2 3‡ ‡‡
e 1▷ 2▷ 3▷
folds (▷) e [] = e
folds (▷) e (ys ‡ y) =
(folds (▷) e ys) ▷ y
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
66
1 2 3‡ ‡‡
e 1▷ 2▷ 3▷
folds (▷) e [] = e
folds (▷) e (ys ‡ y) =
(folds (▷) e ys) ▷ y
1 2 3: : :
foldl (▷) e [] = e
foldl (▷) e (x : xs) =
foldl (▷) (e ▷ x) xs
67
foldl (▷) e [] = e
foldl (▷) e (x : xs) =
foldl (▷) (e ▷ x) xs
foldl (▷) e (ys ‡ y) =
(foldl (▷) e ys) ▷ y
foldr (◁) e [] = e
foldr (◁) e (x : xs) =
x ◁ (foldr (◁) e xs)
68
h is foldl with (▷) e:
h [] = e
h (ys‡y) = (h ys) ▷ y
h ◦ (‡y) = (▷ y) ◦ h
h is foldr with (◁) e:
h [] = e
h (x:xs) = x ◁ (h xs)
h ◦ (x:) = (x ◁) ◦ h
point free
69
interesting...
h = foldr (◁) e = foldl (▷) e
if .... ?
thr 11
70
別管 fold 了
你有聽過
List Homomorphism
嗎?!
List Homomorphism
71
•h (xs ++ ys) = (h xs) ⊕ (h ys)
•h ◦ (++ys) = (⊕ h ys) ◦ h
•... parallel
length :: [a] → Int
maximum :: (Ord a) ⇒ [a] → a
to prove h is homo...
thr 11
萬
全
73
3rd List Homo.Theorem
h is a list homomorphism
if h can be
foldr (◁) e and
foldl (▷) e
for some (◁), (▷) and e
74
h ◦ (++ys)
={ foldr-fusion, since (++ys) = foldr (∶) ys }
foldr (◁) (h ys )
={ foldr-fusion (backwards) }
(⊕ h ys) ◦ foldr (◁) e
= (⊕ h ys) ◦ h
For the second foldr-fusion
h ys = e ⊕ h ys and
(x ◁ y) ⊕ h ys = x ◁ (y ⊕ h ys)
h ◦ (‡z)
={ foldr-fusion, since (‡z) = foldr (∶) [z]}
foldr (◁) (h [z])
={ foldr-fusion (backwards) }
(▷ z) ◦ foldr (◁) e
= (▷ z) ◦ h
For the second foldr-fusion
z ◁ e = e ▷ z and
(x ◁ y) ▷ z = x ◁ (y ▷ z)
h
= foldr
= foldl
h is
homo.
75
h ys = e ⊕ h ys and
(x ◁ y) ⊕ h ys = x ◁ (y ⊕ h ys)
z ◁ e = e ▷ z and
(x ◁ y) ▷ z = x ◁ (y ▷ z)
h
= foldr
= foldl
h is
homo.
Requirement 1
Requirement 2
h = foldr = foldl
h is list homo.
requirement 1
requirement 2
(◁), (▷)
(⊕)
the way to go
77
(x ◁ y) ▷ z
=
=
=
=
=
=
=
x ◁ (y ▷ z)
z z
z
z
z
(x ◁ y) ▷ z = x ◁ (y ▷ z)
78
(x ◁ y) ▷ z
=
=
=
=
=
=
=
x ◁ (y ▷ z)
(1) (▷ z) => (⊕ (h ys))
z z
z
z
z
79
(x ◁ y) ⊕ (h ys)
=
=
=
=
=
=
=
x ◁ (y ⊕ (h ys))
(1) (▷ z) => (⊕ (h ys))
z z
z
z
z
80
(x ◁ y) ⊕ (h ys)
=
=
=
=
=
=
=
x ◁ (y ⊕ (h ys))
(1) (▷ z) => (⊕ (h ys))
(2) z => free variables
z z
z
z
z
81
(x ◁ y) ⊕ (h ys)
=
=
=
=
=
=
=
x ◁ (y ⊕ (h ys))
(1) (▷ z) => (⊕ (h ys))
(2) z => free variables
X1 X2
X2
X1
X1
82
(x ◁ y) ⊕ (h ys)
=
=
=
=
=
=
=
x ◁ (y ⊕ (h ys))
X1 X2
X2
X1
X1
(x ◁ y) ⊕ (h ys) = x ◁ (y ⊕ (h ys))
83
(x ◁ y) ⊕ (h ys)
=
=
=
=
=
=
=
x ◁ (y ⊕ (h ys))
X1 X2
X2
X1
X1
(x ◁ y) ⊕ (h ys) = x ◁ (y ⊕ (h ys))
h ys
= e ⊕ h ys
requirement 2
(base case)
84
(x ◁ y) ⊕ (h ys)
=
=
=
=
=
=
=
x ◁ (y ⊕ (h ys))
(x ◁ y) ⊕ (h ys) = x ◁ (y ⊕ (h ys))
ಠ_ಠ
thr 11
必
死
tupling
86
Algorithm
Efficient Program
Specification
• total functional
• fold
• fold-fusion
• 3rd list homo.
• hoard logic
• logic/type
Reference
87
• Constructing List Homomorphisms from
Proofs. [Yun-Yan Chi, Shin-Cheng Mu]
• Introduction to Funcional Programming
using Haskell [Richard Bird]

More Related Content

What's hot

統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半Ken'ichi Matsui
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisSpbDotNet Community
 
Introduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionIntroduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionChristoph Matthies
 
The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180Mahmoud Samir Fayed
 
Multiplying and-dividingfor web
Multiplying and-dividingfor webMultiplying and-dividingfor web
Multiplying and-dividingfor webMs. Jones
 
Re:ゲーム理論入門 第14回 - 仁 -
Re:ゲーム理論入門 第14回 - 仁 -Re:ゲーム理論入門 第14回 - 仁 -
Re:ゲーム理論入門 第14回 - 仁 -ssusere0a682
 
【演習】Re:ゲーム理論入門 第14回 -仁-
【演習】Re:ゲーム理論入門 第14回 -仁-【演習】Re:ゲーム理論入門 第14回 -仁-
【演習】Re:ゲーム理論入門 第14回 -仁-ssusere0a682
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」Ken'ichi Matsui
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料Ken'ichi Matsui
 
Processing Basics 1
Processing Basics 1Processing Basics 1
Processing Basics 1June-Hao Hou
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」Ken'ichi Matsui
 

What's hot (18)

統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 
Ejercicio 211 del libro de Baldor
Ejercicio 211 del libro de BaldorEjercicio 211 del libro de Baldor
Ejercicio 211 del libro de Baldor
 
Introduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionIntroduction to Homomorphic Encryption
Introduction to Homomorphic Encryption
 
The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180
 
V2.0
V2.0V2.0
V2.0
 
Multiplying and-dividingfor web
Multiplying and-dividingfor webMultiplying and-dividingfor web
Multiplying and-dividingfor web
 
Re:ゲーム理論入門 第14回 - 仁 -
Re:ゲーム理論入門 第14回 - 仁 -Re:ゲーム理論入門 第14回 - 仁 -
Re:ゲーム理論入門 第14回 - 仁 -
 
【演習】Re:ゲーム理論入門 第14回 -仁-
【演習】Re:ゲーム理論入門 第14回 -仁-【演習】Re:ゲーム理論入門 第14回 -仁-
【演習】Re:ゲーム理論入門 第14回 -仁-
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
 
Haskell Tour (Part 2)
Haskell Tour (Part 2)Haskell Tour (Part 2)
Haskell Tour (Part 2)
 
Exam1 101
Exam1 101Exam1 101
Exam1 101
 
Processing Basics 1
Processing Basics 1Processing Basics 1
Processing Basics 1
 
Estadistica U4
Estadistica U4Estadistica U4
Estadistica U4
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
 
Haskell Tour (Part 3)
Haskell Tour (Part 3)Haskell Tour (Part 3)
Haskell Tour (Part 3)
 

Similar to Program Language - Fall 2013

Worksheet 3 addition & subtraction
Worksheet 3 addition & subtractionWorksheet 3 addition & subtraction
Worksheet 3 addition & subtractionkrunamthip
 
Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...
Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...
Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...teaghet
 
functions limits and continuity
functions limits and continuityfunctions limits and continuity
functions limits and continuityPume Ananda
 
01 derivadas
01   derivadas01   derivadas
01 derivadasklorofila
 
Hideitsu Hino
Hideitsu HinoHideitsu Hino
Hideitsu HinoSuurist
 
Algebra 2 Section 5-1
Algebra 2 Section 5-1Algebra 2 Section 5-1
Algebra 2 Section 5-1Jimbo Lamb
 
All You Need is Fold
All You Need is FoldAll You Need is Fold
All You Need is FoldMike Harris
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture gVlad Patryshev
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdfHebaEng
 
Tabela completa de derivadas e integrais
Tabela completa de derivadas e integraisTabela completa de derivadas e integrais
Tabela completa de derivadas e integraisDiego Rodrigues Vaz
 
Pre-calculus 1, 2 and Calculus I (exam notes)
Pre-calculus 1, 2 and Calculus I (exam notes)Pre-calculus 1, 2 and Calculus I (exam notes)
Pre-calculus 1, 2 and Calculus I (exam notes)William Faber
 
Operation on functions
Operation on functionsOperation on functions
Operation on functionsJeralyn Obsina
 
Tabela derivadas-e-integrais
Tabela derivadas-e-integraisTabela derivadas-e-integrais
Tabela derivadas-e-integraismariasousagomes
 
Calculus B Notes (Notre Dame)
Calculus B Notes (Notre Dame)Calculus B Notes (Notre Dame)
Calculus B Notes (Notre Dame)Laurel Ayuyao
 
lesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptxlesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptxJohnReyManzano2
 
3.4 Composition of Functions
3.4 Composition of Functions3.4 Composition of Functions
3.4 Composition of Functionssmiller5
 
Summary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And IntegrationSummary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And IntegrationAhmed Hamed
 
51554 0131469657 ism-13
51554 0131469657 ism-1351554 0131469657 ism-13
51554 0131469657 ism-13Carlos Fuentes
 

Similar to Program Language - Fall 2013 (20)

Worksheet 3 addition & subtraction
Worksheet 3 addition & subtractionWorksheet 3 addition & subtraction
Worksheet 3 addition & subtraction
 
Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...
Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...
Η έννοια της εξίσωσης, Οι εξισώσεις: α + x = β, x – α = β, α – x = β, αx = β,...
 
functions limits and continuity
functions limits and continuityfunctions limits and continuity
functions limits and continuity
 
01 derivadas
01   derivadas01   derivadas
01 derivadas
 
Hideitsu Hino
Hideitsu HinoHideitsu Hino
Hideitsu Hino
 
Functions limits and continuity
Functions limits and continuityFunctions limits and continuity
Functions limits and continuity
 
Algebra 2 Section 5-1
Algebra 2 Section 5-1Algebra 2 Section 5-1
Algebra 2 Section 5-1
 
All You Need is Fold
All You Need is FoldAll You Need is Fold
All You Need is Fold
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture g
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
 
Tabela completa de derivadas e integrais
Tabela completa de derivadas e integraisTabela completa de derivadas e integrais
Tabela completa de derivadas e integrais
 
Pre-calculus 1, 2 and Calculus I (exam notes)
Pre-calculus 1, 2 and Calculus I (exam notes)Pre-calculus 1, 2 and Calculus I (exam notes)
Pre-calculus 1, 2 and Calculus I (exam notes)
 
Operation on functions
Operation on functionsOperation on functions
Operation on functions
 
Tabela derivadas-e-integrais
Tabela derivadas-e-integraisTabela derivadas-e-integrais
Tabela derivadas-e-integrais
 
Calculus B Notes (Notre Dame)
Calculus B Notes (Notre Dame)Calculus B Notes (Notre Dame)
Calculus B Notes (Notre Dame)
 
EPCA_MODULE-2.pptx
EPCA_MODULE-2.pptxEPCA_MODULE-2.pptx
EPCA_MODULE-2.pptx
 
lesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptxlesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptx
 
3.4 Composition of Functions
3.4 Composition of Functions3.4 Composition of Functions
3.4 Composition of Functions
 
Summary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And IntegrationSummary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And Integration
 
51554 0131469657 ism-13
51554 0131469657 ism-1351554 0131469657 ism-13
51554 0131469657 ism-13
 

More from Yun-Yan Chi

Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019Yun-Yan Chi
 
Traversing on Algebraic Datatype
Traversing on Algebraic DatatypeTraversing on Algebraic Datatype
Traversing on Algebraic DatatypeYun-Yan Chi
 
for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"Yun-Yan Chi
 
Machine X Language
Machine X LanguageMachine X Language
Machine X LanguageYun-Yan Chi
 
Examples for loopless
Examples for looplessExamples for loopless
Examples for looplessYun-Yan Chi
 
Data type a la carte
Data type a la carteData type a la carte
Data type a la carteYun-Yan Chi
 
Genetic programming
Genetic programmingGenetic programming
Genetic programmingYun-Yan Chi
 
Paper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognitionPaper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognitionYun-Yan Chi
 
Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level Yun-Yan Chi
 
Number System in Haskell
Number System in Haskell Number System in Haskell
Number System in Haskell Yun-Yan Chi
 
Constructing List Homomorphisms from Proofs
Constructing List Homomorphisms from ProofsConstructing List Homomorphisms from Proofs
Constructing List Homomorphisms from ProofsYun-Yan Chi
 

More from Yun-Yan Chi (13)

Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019
 
Traversing on Algebraic Datatype
Traversing on Algebraic DatatypeTraversing on Algebraic Datatype
Traversing on Algebraic Datatype
 
for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"
 
Machine X Language
Machine X LanguageMachine X Language
Machine X Language
 
Examples for loopless
Examples for looplessExamples for loopless
Examples for loopless
 
Insert 2 Merge
Insert 2 MergeInsert 2 Merge
Insert 2 Merge
 
Any tutor
Any tutorAny tutor
Any tutor
 
Data type a la carte
Data type a la carteData type a la carte
Data type a la carte
 
Genetic programming
Genetic programmingGenetic programming
Genetic programming
 
Paper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognitionPaper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognition
 
Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level
 
Number System in Haskell
Number System in Haskell Number System in Haskell
Number System in Haskell
 
Constructing List Homomorphisms from Proofs
Constructing List Homomorphisms from ProofsConstructing List Homomorphisms from Proofs
Constructing List Homomorphisms from Proofs
 

Recently uploaded

Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PPRINCE C P
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)Areesha Ahmad
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPirithiRaju
 
fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyDrAnita Sharma
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)Areesha Ahmad
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​kaibalyasahoo82800
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticssakshisoni2385
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...Sérgio Sacani
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencySheetal Arora
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 

Recently uploaded (20)

Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomology
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 

Program Language - Fall 2013

  • 2.
  • 8. 8 Algorithm Efficient Program Specification •Correctness by Verification •Model Checking •Automata
  • 9. 9 Algorithm Efficient Program Specification •Program Construction •Derivation •Synthesis •Hoare Logic
  • 12. foldr
  • 13. In computer science, a list or sequence is an abstract data type that implements a finite ordered collection of values, where the same value may occur more than once. - wikipedia
  • 14. 1 2 3 4 5 1 2 3 4 5: : : : : data List a = [] | a : (List a)
  • 15. 1 2 3 4 5 [ ]: : : : : foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 16. 1 2 3 4 5: : : : : foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs) [ ]
  • 17. 1 2 3 4 5: : : : : foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs) [ ]
  • 18. 1 2 3 4 5: : : : : foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs) [ ]
  • 19. 1 2 3 4 5: : : : : foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs) [ ]
  • 20. 1 2 3 4 5: : : : : foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs) [ ]
  • 21. 1 2 3 4 5: : : : : e foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 22. 1 2 3 4 5: : : : e◁ foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 23. 1 2 3 4 5: : : e◁◁ foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 24. 1 2 3 4 5: : e◁◁◁ foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 25. 1 2 3 4 5: e◁◁◁◁ foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 26. foldr :: (a → b → b) → b → [a] → b foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs) 1 2 3 4 5 e◁◁◁◁◁
  • 27. sum [1..1000] => foldr (+) 0 [1..1000] 1 + (foldr (+) 0 [2..1000]) 1 + (2 + (foldr (+) 0 [3..1000])) ... 1 + (2 + (... + (1000 + (foldr (+) 0 []))...)) 1 + (2 + (... + (1000 + 0)...))) ... 1 + (2 + 500497) 1 + 500499 500500
  • 28. sum [1..1000] => foldr (+) 0 [1..1000] 1 + (foldr (+) 0 [2..1000]) 1 + (2 + (foldr (+) 0 [3..1000])) ... 1 + (2 + (... + (1000 + (foldr (+) 0 []))...)) 1 + (2 + (... + (1000 + 0)...))) ... 1 + (2 + 500497) 1 + 500499 500500
  • 29. 1 + (2 + (... + (1000 + 0)...)))
  • 30. length :: [a] → Int sum :: (Num a) ⇒ [a] → a map :: (a → b) → [a] → [b] filter :: (a → Bool) → [a] → [a] inits :: [a] → [[a]] concat :: [[a]] → [a] maximum :: (Ord a) ⇒ [a] → a e ? (◁) ?
  • 31. foldl
  • 32. 1 2 3 4 5 [ ]: : : : : foldr :: (a → b → b) → b → [a] → b foldl :: (b → a → b) → b → [a] → b foldl (▷) e [] = e foldl (▷) e (x : xs) = foldl (▷) (e ▷ x) xs
  • 33. 1 2 3 [ ]: : : foldl (▷) Para0 Para1 { { e
  • 34. 1 2 3 [ ]: : : foldl (▷) Para0 Para1 { { e 1▷
  • 35. 1 2 3 [ ]: : : foldl (▷) Para0 Para1 { { e 1▷ 2▷
  • 36. 1 2 3 [ ]: : : foldl (▷) Para0 Para1 { { e 1▷ 2▷ 3▷
  • 37. 13 sum [1..1000] => foldl (+) 0 [1..1000] foldl (+) (0 + 1) [2..1000] foldr (+) (1 + 2) [3..1000] foldr (+) (3 + 3) [4..1000] ... foldr (+) (498501 + 999) [1000] foldr (+) (499500 + 1000) [] foldr (+) 500500 [] 500500
  • 38. 13 sum [1..1000] => foldl (+) 0 [1..1000] foldl (+) (0 + 1) [2..1000] foldr (+) (1 + 2) [3..1000] foldr (+) (3 + 3) [4..1000] ... foldr (+) (498501 + 999) [1000] foldr (+) (499500 + 1000) [] foldr (+) 500500 [] 500500
  • 39.
  • 40. length :: [a] → Int sum :: (Num a) ⇒ [a] → a map :: (a → b) → [a] → [b] filter :: (a → Bool) → [a] → [a] concat :: [[a]] → [a] maximum :: (Ord a) ⇒ [a] → a e ? (▷) ?
  • 42. 42 map f ◦ map g
  • 44. 43 filter q ◦ filter p
  • 47. 44 foldr-fusion ⇐ f (x ◁ z) = x ≪ (f z) foldr (≪) (f e)
  • 48. 45 f $ foldr (◁) e [] = { definition of foldr } f e = { definition of foldr } foldr (≪) (f e) [] foldr-fusion f ◦ foldr (◁) e = foldr (≪) (f e)
  • 49. 46 f $ foldr (◁) e (x:xs) = f (x ◁ (foldr (◁) e xs)) = { f (x ◁ z) = x ≪ (f z) } x ≪ (f (foldr (◁) e xs)) = x ≪ (foldr (≪) (f e) xs) = foldr (≪) (f e) (x:xs) foldr-fusion f ◦ foldr (◁) e = foldr (≪) (f e)
  • 50. 47 f $ foldr (◁) e (x:xs) = f (x ◁ (foldr (◁) e xs)) = { f (x ◁ z) = x ≪ (f z) } x ≪ (f (foldr (◁) e xs)) = x ≪ (foldr (≪) (f e) xs) = foldr (≪) (f e) (x:xs) foldr-fusion f ◦ foldr (◁) e = foldr (≪) (f e)
  • 51. 48 f $ foldr (◁) e (x:xs) = f (x ◁ (foldr (◁) e xs)) = { f (x ◁ z) = x ≪ (f z) } x ≪ (f (foldr (◁) e xs)) = x ≪ (foldr (≪) (f e) xs) = foldr (≪) (f e) (x:xs) foldr-fusion f ◦ foldr (◁) e = foldr (≪) (f e)
  • 52. 49 f $ foldr (◁) e (x:xs) = f (x ◁ (foldr (◁) e xs)) = { f (x ◁ z) = x ≪ (f z) } x ≪ (f (foldr (◁) e xs)) = x ≪ (foldr (≪) (f e) xs) = foldr (≪) (f e) (x:xs) foldr-fusion f ◦ foldr (◁) e = foldr (≪) (f e)
  • 53. 50 f $ foldr (◁) e (x:xs) = f (x ◁ (foldr (◁) e xs)) = { f (x ◁ z) = x ≪ (f z) } x ≪ (f (foldr (◁) e xs)) = x ≪ (foldr (≪) (f e) xs) = foldr (≪) (f e) (x:xs) foldr-fusion f ◦ foldr (◁) e = foldr (≪) (f e)
  • 55. 52 inits :: [a] → [[a]] tails :: [a] → [[a]] concat :: [[a]] → [a] filter :: (a → Bool) → [a] → [a] power :: [a] → [[a]] filter (/=[])◦concat◦map tails◦inits Suffixes of Prefixes
  • 56. 53 inits :: [a] → [[a]] inits [] = [[]] inits (x:xs) = [] : map (x:) (inits xs) filter (/=[])◦concat◦map tails◦inits Suffixes of Prefixes
  • 57. 54 inits :: [a] → [[a]] inits [] = [[]] inits (x:xs) = [] : map (x:) (inits xs) inits’ = foldr (x hs → [] : (map (x:) hs)) [[]] filter (/=[])◦concat◦map tails◦inits Suffixes of Prefixes
  • 58. 55 filter (/=[])◦concat◦map tails◦inits map tails ◦ inits = f ◦ foldr (◁) [[]] foldr-fusion = foldr (≪) (map tails [[]]) = foldr (≪) [[[]]] 1. f = map tails 2. (◁) = x hs → [] : (map (x:) hs) Suffixes of Prefixes
  • 59. 56 filter (/=[])◦concat◦map tails◦inits map tails ◦ inits = f ◦ foldr (◁) [[]] foldr-fusion = foldr (≪) (map tails [[]]) = foldr (≪) [[[]]] 1. f = map tails 2. (◁) = x hs → [] : (map (x:) hs) 3. (≪) = x h → [[]] : map (hs → (x : (head hs)) : hs) h Suffixes of Prefixes
  • 60. 57 filter (/=[])◦concat◦foldr (≪) [[[]]] filter (/=[]) ◦ concat = g ◦ foldr (++) [] foldr-fusion = foldr (⋆) [] 1. g = filter (/=[]) 2. (⋆) = x h → filter (/=[]) x) ++ h Suffixes of Prefixes
  • 61. 58 filter (/=[]) ◦ concat = g ◦ foldr (++) [] foldr-fusion = foldr (⋆) [] 1. g = filter (/=[]) 2. (⋆) = x h → filter (/=[]) x) ++ h filter (/=[])◦concat◦foldr (≪) [[[]]] Suffixes of Prefixes
  • 62. 59 foldr (⋆) []◦foldr (≪) [[[]]] = foldr (⊙) [] 1. (≪) = x h → [[]] : map (hs → (x : (head hs)) : hs) h 2. (⋆) = x h → filter (/=[]) x) ++ h Suffixes of Prefixes if... foldr (⋆) [] (x ≪ z) = x ⊙ (foldr (⋆) [] z)
  • 63. 60 foldr (⋆) []◦foldr (≪) [[[]]] = foldr (⊙) [] 1. (≪) = x h → [[]] : map (hs → (x : (head hs)) : hs) h 2. (⋆) = x h → filter (/=[]) x) ++ h Suffixes of Prefixes if... foldr (⋆) [] (x ≪ z) = x ⊙ (foldr (⋆) [] z) ... after 3 hours
  • 65. 62 1 2 3 1 2 3: : : data ConsList a = [] | a : (ConsList a)
  • 66. 63 1 2 3 1 2 3‡ ‡‡ data SnocList a = [] | (SnocList a) ‡ a
  • 67. 64 1 2 3‡ ‡‡ f (▷) e e 1▷ 2▷ 3▷
  • 68. 65 1 2 3‡ ‡‡ e 1▷ 2▷ 3▷ folds (▷) e [] = e folds (▷) e (ys ‡ y) = (folds (▷) e ys) ▷ y foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 69. 66 1 2 3‡ ‡‡ e 1▷ 2▷ 3▷ folds (▷) e [] = e folds (▷) e (ys ‡ y) = (folds (▷) e ys) ▷ y 1 2 3: : : foldl (▷) e [] = e foldl (▷) e (x : xs) = foldl (▷) (e ▷ x) xs
  • 70. 67 foldl (▷) e [] = e foldl (▷) e (x : xs) = foldl (▷) (e ▷ x) xs foldl (▷) e (ys ‡ y) = (foldl (▷) e ys) ▷ y foldr (◁) e [] = e foldr (◁) e (x : xs) = x ◁ (foldr (◁) e xs)
  • 71. 68 h is foldl with (▷) e: h [] = e h (ys‡y) = (h ys) ▷ y h ◦ (‡y) = (▷ y) ◦ h h is foldr with (◁) e: h [] = e h (x:xs) = x ◁ (h xs) h ◦ (x:) = (x ◁) ◦ h point free
  • 72. 69 interesting... h = foldr (◁) e = foldl (▷) e if .... ? thr 11
  • 74. List Homomorphism 71 •h (xs ++ ys) = (h xs) ⊕ (h ys) •h ◦ (++ys) = (⊕ h ys) ◦ h •... parallel length :: [a] → Int maximum :: (Ord a) ⇒ [a] → a
  • 75. to prove h is homo... thr 11 萬 全
  • 76. 73 3rd List Homo.Theorem h is a list homomorphism if h can be foldr (◁) e and foldl (▷) e for some (◁), (▷) and e
  • 77. 74 h ◦ (++ys) ={ foldr-fusion, since (++ys) = foldr (∶) ys } foldr (◁) (h ys ) ={ foldr-fusion (backwards) } (⊕ h ys) ◦ foldr (◁) e = (⊕ h ys) ◦ h For the second foldr-fusion h ys = e ⊕ h ys and (x ◁ y) ⊕ h ys = x ◁ (y ⊕ h ys) h ◦ (‡z) ={ foldr-fusion, since (‡z) = foldr (∶) [z]} foldr (◁) (h [z]) ={ foldr-fusion (backwards) } (▷ z) ◦ foldr (◁) e = (▷ z) ◦ h For the second foldr-fusion z ◁ e = e ▷ z and (x ◁ y) ▷ z = x ◁ (y ▷ z) h = foldr = foldl h is homo.
  • 78. 75 h ys = e ⊕ h ys and (x ◁ y) ⊕ h ys = x ◁ (y ⊕ h ys) z ◁ e = e ▷ z and (x ◁ y) ▷ z = x ◁ (y ▷ z) h = foldr = foldl h is homo. Requirement 1 Requirement 2
  • 79. h = foldr = foldl h is list homo. requirement 1 requirement 2 (◁), (▷) (⊕) the way to go
  • 80. 77 (x ◁ y) ▷ z = = = = = = = x ◁ (y ▷ z) z z z z z (x ◁ y) ▷ z = x ◁ (y ▷ z)
  • 81. 78 (x ◁ y) ▷ z = = = = = = = x ◁ (y ▷ z) (1) (▷ z) => (⊕ (h ys)) z z z z z
  • 82. 79 (x ◁ y) ⊕ (h ys) = = = = = = = x ◁ (y ⊕ (h ys)) (1) (▷ z) => (⊕ (h ys)) z z z z z
  • 83. 80 (x ◁ y) ⊕ (h ys) = = = = = = = x ◁ (y ⊕ (h ys)) (1) (▷ z) => (⊕ (h ys)) (2) z => free variables z z z z z
  • 84. 81 (x ◁ y) ⊕ (h ys) = = = = = = = x ◁ (y ⊕ (h ys)) (1) (▷ z) => (⊕ (h ys)) (2) z => free variables X1 X2 X2 X1 X1
  • 85. 82 (x ◁ y) ⊕ (h ys) = = = = = = = x ◁ (y ⊕ (h ys)) X1 X2 X2 X1 X1 (x ◁ y) ⊕ (h ys) = x ◁ (y ⊕ (h ys))
  • 86. 83 (x ◁ y) ⊕ (h ys) = = = = = = = x ◁ (y ⊕ (h ys)) X1 X2 X2 X1 X1 (x ◁ y) ⊕ (h ys) = x ◁ (y ⊕ (h ys)) h ys = e ⊕ h ys requirement 2 (base case)
  • 87. 84 (x ◁ y) ⊕ (h ys) = = = = = = = x ◁ (y ⊕ (h ys)) (x ◁ y) ⊕ (h ys) = x ◁ (y ⊕ (h ys))
  • 89. 86 Algorithm Efficient Program Specification • total functional • fold • fold-fusion • 3rd list homo. • hoard logic • logic/type
  • 90. Reference 87 • Constructing List Homomorphisms from Proofs. [Yun-Yan Chi, Shin-Cheng Mu] • Introduction to Funcional Programming using Haskell [Richard Bird]