SlideShare a Scribd company logo
1 of 144
Haskell でテキスト圧縮
Haskell でテキスト圧縮の前処理
Haskell でテキスト圧縮
@hsjoihs
の前処理
2 年前
2 年前
2 年前
• 夏季セミナーで Haskell を勉強
2 年前
• 夏季セミナーで Haskell を勉強
• Haskell すごい!
2 年前
• 夏季セミナーで Haskell を勉強
• Haskell すごい!
• Haskell 楽しい!
2 年前
• 夏季セミナーで Haskell を勉強
• Haskell すごい!
• Haskell 楽しい!
• 関数型言語最高!
ということで今回は
ということで今回は
関数プログラミング
珠玉のアルゴリズムデザイン
ということで今回は
関数プログラミング
珠玉のアルゴリズムデザイン
を目指すべく
ということで今回は
関数プログラミング
珠玉のアルゴリズムデザイン
ということで今回は
関数プログラミング
珠玉のアルゴリズムデザイン
という本で勉強
ということで今回は
関数プログラミング
珠玉のアルゴリズムデザイン
という本で勉強
プロになれたと
は言っていない
今回の内容
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
Burrows-Wheeler 変換とは
Burrows-Wheeler 変換とは
リストの並び替えにより重複する要素をま
とめ、
Burrows-Wheeler 変換とは
リストの並び替えにより重複する要素をま
とめ、
ランレングス法などの圧縮法の効率を
Burrows-Wheeler 変換とは
リストの並び替えにより重複する要素をま
とめ、
ランレングス法などの圧縮法の効率を
大幅に高めることのできる可逆変換
Burrows-Wheeler 変換とは (take 2)
  
Burrows-Wheeler 変換とは (take 2)
情報を圧縮する時に使える
  
Burrows-Wheeler 変換とは (take 2)
情報を圧縮する時に使える
賢いアルゴリズム
  
例えば
例えば
'this, that or the other'
例えば
'this, that or the other'
例えば
_人人人人人人人人人人人人人人人_
>  繰り返し部分が散らばっている  <
 ̄ Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  ̄
'this, that or the other'
例えば
散らばっている  
'this, that or the other'
例えば
散らばっている  
↓
'this, that or the other'
例えば
散らばっている  
↓
まとめたい
'this, that or the other'
ここで突然
ここで突然
文字列を回してみる
ここで突然
this, that or the other|
his, that or the other|t
is, that or the other|th
s, that or the other|thi
, that or the other|this
that or the other|this,
that or the other|this,
hat or the other|this, t
at or the other|this, th
t or the other|this, tha
or the other|this, that
or the other|this, that
r the other|this, that o
the other|this, that or
the other|this, that or
he other|this, that or t
e other|this, that or th
other|this, that or the
other|this, that or the
ther|this, that or the o
her|this, that or the ot
er|this, that or the oth
r|this, that or the othe
|this, that or the other
文字列を回してみる
これをさらに
this, that or the other|
his, that or the other|t
is, that or the other|th
s, that or the other|thi
, that or the other|this
that or the other|this,
that or the other|this,
hat or the other|this, t
at or the other|this, th
t or the other|this, tha
or the other|this, that
or the other|this, that
r the other|this, that o
the other|this, that or
the other|this, that or
he other|this, that or t
e other|this, that or th
other|this, that or the
other|this, that or the
ther|this, that or the o
her|this, that or the ot
er|this, that or the oth
r|this, that or the othe
|this, that or the other
これをさらに
this, that or the other|
his, that or the other|t
is, that or the other|th
s, that or the other|thi
, that or the other|this
that or the other|this,
that or the other|this,
hat or the other|this, t
at or the other|this, th
t or the other|this, tha
or the other|this, that
or the other|this, that
r the other|this, that o
the other|this, that or
the other|this, that or
he other|this, that or t
e other|this, that or th
other|this, that or the
other|this, that or the
ther|this, that or the o
her|this, that or the ot
er|this, that or the oth
r|this, that or the othe
|this, that or the other
…行ごとにソートすると
これをさらに
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
…行ごとにソートすると
これをさらに
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
…行ごとにソートすると
拡大
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
拡大
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
原文に "th" が多い
↓
"h" で始まる行の終わりは "t" になりや
すい
ということは
ということは
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
ということは
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
ということは
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
ということは
rte,rshhhtttth eoia o|
ということは
rte,rshhhtttth eoia o|
ということは
rte,rshhhtttth eoia o|
ということは
rte,rshhhtttth eoia o|
this, that or the other|
ということは
rte,rshhhtttth eoia o|
this, that or the other|
バラバラ
ということは
rte,rshhhtttth eoia o|
this, that or the other|
バラバラ
まとまった
他の例
他の例
the rain in Spain stays mainly in the plain|
他の例
the rain in Spain stays mainly in the plain|
バラバラ
他の例
nnnyseenn lrpmthhtta aa apn iiiiiiS y s |la
the rain in Spain stays mainly in the plain|
バラバラ
他の例
nnnyseenn lrpmthhtta aa apn iiiiiiS y s |la
the rain in Spain stays mainly in the plain|
バラバラ
まとまった
さらに例
さらに例
peter piper picked a peck of pickled pepper|
さらに例
peter piper picked a peck of pickled pepper|
バラバラ
さらに例
rdkadrfr eiieepklppptpopppccck pi| eeeee
peter piper picked a peck of pickled pepper|
バラバラ
さらに例
rdkadrfr eiieepklppptpopppccck pi| eeeee
peter piper picked a peck of pickled pepper|
バラバラ
まとまった
先ほど
先ほど
Burrows-Wheeler 変換とは
リストの並び替えにより重複する要素をま
とめ、
ランレングス法などの圧縮法の効率を
大幅に高めることのできる可逆変換
OK
Burrows-Wheeler 変換とは
リストの並び替えにより重複する要素をま
とめ、
ランレングス法などの圧縮法の効率を
大幅に高めることのできる可逆変換this, that or the other|
rte,rshhhtttth eoia o|
↓ 並び替え
これも OK
Burrows-Wheeler 変換とは
リストの並び替えにより重複する要素をま
とめ、
ランレングス法などの圧縮法の効率を
大幅に高めることのできる可逆変換this, that or the other|
rte,rshhhtttth eoia o|
???
Burrows-Wheeler 変換とは
リストの並び替えにより重複する要素をま
とめ、
ランレングス法などの圧縮法の効率を
大幅に高めることのできる可逆変換this, that or the other|
rte,rshhhtttth eoia o|
↑ 逆変換?
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
逆変換
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
逆変換
…変換の方は
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
逆変換
…変換の方は
1. 簡潔に説明するのが ( 私の説明力では ) 難しい
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
逆変換
…変換の方は
1. 簡潔に説明するのが ( 私の説明力では ) 難しい
2. 本のソースを実行したら Index out of range→ 自力修正なので
合ってる保証がない
今回の内容
Haskell での効率的な Burrows-Wheeler 変換の実装
逆変換
…変換の方は
1. 簡潔に説明するのが ( 私の説明力では ) 難しい
2. 本のソースを実行したら Index out of range→ 自力修正なので
合ってる保証がない
ので断念
逆変換
逆変換
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
逆変換
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
------->
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
------->
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
------->
これが欲しい
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
⇒
|
,
a
e
e
h
h
h
h
i
o
o
r
r
s
t
t
t
t
t
sort
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
r
t
e
,
r
s
h
h
h
t
t
t
t
h
e
o
i
a
o
|
⇒
|
,
a
e
e
h
h
h
h
i
o
o
r
r
s
t
t
t
t
t
sort
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
r|
t
e
,
r
s,
ha
he
he
th
th
th
th
hi
o
o
er
or
is
at
t
t
ot
|t
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
⇒
r|
t
e
,
r
s,
ha
he
he
th
th
th
th
hi
o
o
er
or
is
at
t
t
ot
|t
sort
|t
o
o
t
t
,
at
e
er
ha
he
he
hi
is
or
ot
r|
r
s,
t
th
th
th
th
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
⇒
r|
t
e
,
r
s,
ha
he
he
th
th
th
th
hi
o
o
er
or
is
at
t
t
ot
|t
sort
|t
o
o
t
t
,
at
e
er
ha
he
he
hi
is
or
ot
r|
r
s,
t
th
th
th
th
逆変換
|this, that or the other
or the other|this, that
other|this, that or the
that or the other|this,
the other|this, that or
, that or the other|this
at or the other|this, th
e other|this, that or th
er|this, that or the oth
hat or the other|this, t
he other|this, that or t
her|this, that or the ot
his, that or the other|t
is, that or the other|th
or the other|this, that
other|this, that or the
r|this, that or the othe
r the other|this, that o
s, that or the other|thi
t or the other|this, tha
that or the other|this,
the other|this, that or
ther|this, that or the o
this, that or the other|
⇒
r|
t
e
,
r
s,
ha
he
he
th
th
th
th
hi
o
o
er
or
is
at
t
t
ot
|t
sort
|t
o
o
t
t
,
at
e
er
ha
he
he
hi
is
or
ot
r|
r
s,
t
th
th
th
th
これを繰り返
す
問題点
問題点
重い
問題点
重い
• ソート Θ(n log n) が n 回 → Θ(n2
log n)
問題点
重い
• ソート Θ(n log n) が n 回 → Θ(n2
log n)
• メモリも n2
そこで
• ソート Θ(n log n) が n 回 → Θ(n2
log n)
• メモリも n2
ソート
ソート
r 0
t 1
e 2
, 3
r 4
s 5
h 6
h 7
h 8
t 9
t 10
t 11
t 12
h 13
14
15
e 16
o 17
i 18
a 19
20
21
o 22
| 23
| 23
14
15
20
21
, 3
a 19
e 2
e 16
h 6
h 7
h 8
h 13
i 18
o 17
o 22
r 0
r 4
s 5
t 1
t 9
t 10
t 11
t 12
ソート
r 0
t 1
e 2
, 3
r 4
s 5
h 6
h 7
h 8
t 9
t 10
t 11
t 12
h 13
14
15
e 16
o 17
i 18
a 19
20
21
o 22
| 23
| 23
14
15
20
21
, 3
a 19
e 2
e 16
h 6
h 7
h 8
h 13
i 18
o 17
o 22
r 0
r 4
s 5
t 1
t 9
t 10
t 11
t 12
r| 0
t 1
e 2
, 3
r 4
s, 5
ha 6
he 7
he 8
th 9
th 10
th 11
th 12
hi 13
o 14
o 15
er 16
or 17
is 18
at 19
t 20
t 21
ot 22
|t 23
|t 23
o 14
o 15
t 20
t 21
, 3
at 19
e 2
er 16
ha 6
he 7
he 8
hi 13
is 18
or 17
ot 22
r| 0
r 4
s, 5
t 1
th 9
th 10
th 11
th 12
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
t
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
th
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
thi
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this,
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this,
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, t
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, th
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, tha
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that o
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or t
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or th
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the o
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the ot
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the oth
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the othe
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the other
よって
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
this, that or the other|
Haskell では
r 0 → | 23
t 1 → 14
e 2 → 15
, 3 → 20
r 4 → 21
s 5 → , 3
h 6 → a 19
h 7 → e 2
h 8 → e 16
t 9 → h 6
t 10 → h 7
t 11 → h 8
t 12 → h 13
h 13 → i 18
14 → o 17
15 → o 22
e 16 → r 0
o 17 → r 4
i 18 → s 5
a 19 → t 1
20 → t 9
21 → t 10
o 22 → t 11
| 23 → t 12
Haskell では
f 0 = 23
f 1 = 14
f 2 = 15
f 3 = 20
f 4 = 21
f 5 = 3
f 6 = 19
f 7 = 2
f 8 = 16
f 9 = 6
f 10 = 7
f 11 = 8
f 12 = 13
f 13 = 18
f 14 = 17
f 15 = 22
f 16 = 0
f 17 = 4
f 18 = 5
f 19 = 1
f 20 = 9
f 21 = 10
f 22 = 11
f 23 = 12
Haskell では
f 0 = 23
f 1 = 14
f 2 = 15
f 3 = 20
f 4 = 21
f 5 = 3
f 6 = 19
f 7 = 2
f 8 = 16
f 9 = 6
f 10 = 7
f 11 = 8
f 12 = 13
f 13 = 18
f 14 = 17
f 15 = 22
f 16 = 0
f 17 = 4
f 18 = 5
f 19 = 1
f 20 = 9
f 21 = 10
f 22 = 11
f 23 = 12
[23, f 23, f(f 23), .. ]
Haskell では
f 0 = 23
f 1 = 14
f 2 = 15
f 3 = 20
f 4 = 21
f 5 = 3
f 6 = 19
f 7 = 2
f 8 = 16
f 9 = 6
f 10 = 7
f 11 = 8
f 12 = 13
f 13 = 18
f 14 = 17
f 15 = 22
f 16 = 0
f 17 = 4
f 18 = 5
f 19 = 1
f 20 = 9
f 21 = 10
f 22 = 11
f 23 = 12
[23, 12, f( 12), .. ]
Haskell では
f 0 = 23
f 1 = 14
f 2 = 15
f 3 = 20
f 4 = 21
f 5 = 3
f 6 = 19
f 7 = 2
f 8 = 16
f 9 = 6
f 10 = 7
f 11 = 8
f 12 = 13
f 13 = 18
f 14 = 17
f 15 = 22
f 16 = 0
f 17 = 4
f 18 = 5
f 19 = 1
f 20 = 9
f 21 = 10
f 22 = 11
f 23 = 12
[23, 12, 13 , .. ]
Haskell では
f 0 = 23
f 1 = 14
f 2 = 15
f 3 = 20
f 4 = 21
f 5 = 3
f 6 = 19
f 7 = 2
f 8 = 16
f 9 = 6
f 10 = 7
f 11 = 8
f 12 = 13
f 13 = 18
f 14 = 17
f 15 = 22
f 16 = 0
f 17 = 4
f 18 = 5
f 19 = 1
f 20 = 9
f 21 = 10
f 22 = 11
f 23 = 12
[23, 12, 13 , .. ]
さっきとやっていることは
同じ
ここで
[23, f 23, f(f 23), ... ]
ここで
[23, f 23, f(f 23), ... ]
ここで
[23, f 23, f(f 23), ... ]
_人人人人人_
>完全に一致<
 ̄ Y Y Y Y Y^ ^ ^ ^  ̄
ここで
[23, f 23, f(f 23), ... ]
おやぁ?
infinite list
infinite list
• 日本語では「無限リスト」
infinite list
• 日本語では「無限リスト」
• Haskell の「遅延評価」によって実現される
遅延評価
遅延評価
• 「必要になるまで値を計算しない」とい
う戦略
遅延評価
• 「必要になるまで値を計算しない」とい
う戦略
• 英語では Lazy evaluation
遅延評価
• 「必要になるまで値を計算しない」とい
う戦略
• 英語では Lazy evaluation
• 夏休みの宿題に対してとる戦略としても
有名
遅延評価
• 「必要になるまで値を計算しない」とい
う戦略
• 英語では Lazy evaluation
• 夏休みの宿題に対してとる戦略としても
有名
計算量
計算量
• 初回のソートが O(n log n)
計算量
• 初回のソートが O(n log n)
• それ以外の処理は O(n)
計算量
• 初回のソートが O(n log n)
• それ以外の処理は O(n)
• メモリも O(n)
計算量
• 初回のソートが O(n log n)
• それ以外の処理は O(n)
• メモリも O(n)
• 大勝利
ご清聴ありがとうございました

More Related Content

Viewers also liked

Trabajo de fisica grupo1
Trabajo de fisica grupo1Trabajo de fisica grupo1
Trabajo de fisica grupo1Eloscar Hugo
 
Composición: Elipsis y transiciones
Composición: Elipsis y transicionesComposición: Elipsis y transiciones
Composición: Elipsis y transicionesVladimir
 
Ip estatica y dinamica
Ip estatica y dinamicaIp estatica y dinamica
Ip estatica y dinamicatitanes4erever
 
Presentación amsterdam
Presentación amsterdam Presentación amsterdam
Presentación amsterdam xavier laborda
 
Decision making process
Decision making processDecision making process
Decision making processAnjana Mathew
 

Viewers also liked (6)

York City
York CityYork City
York City
 
Trabajo de fisica grupo1
Trabajo de fisica grupo1Trabajo de fisica grupo1
Trabajo de fisica grupo1
 
Composición: Elipsis y transiciones
Composición: Elipsis y transicionesComposición: Elipsis y transiciones
Composición: Elipsis y transiciones
 
Ip estatica y dinamica
Ip estatica y dinamicaIp estatica y dinamica
Ip estatica y dinamica
 
Presentación amsterdam
Presentación amsterdam Presentación amsterdam
Presentación amsterdam
 
Decision making process
Decision making processDecision making process
Decision making process
 

Recently uploaded

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 

Recently uploaded (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 

Haskellでテキスト圧縮(の前処理)