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

The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)Roberto Bettazzoni
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfkalichargn70th171
 
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckMarc Lester
 
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with GraphGraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with GraphNeo4j
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Andreas Granig
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfICS
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In hararekasambamuno
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit MilanNeo4j
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanNeo4j
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdfSelfMade bd
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletAndrea Goulet
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...drm1699
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Chirag Panchal
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConNatan Silnitsky
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Flutter Agency
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Andrea Goulet
 

Recently uploaded (20)

The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
 
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with GraphGraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 

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