FRACTRAN - een tamelijk nutteloze...

44
FRACTRAN FRACTRAN . . . een tamelijk nutteloze programmeertaal Hendrik Jan Hoogeboom Theoretische Informatica Universiteit Leiden 23.11’16 Leidsche Flesch Lunsch “And I thought Brainf*ck was weird” – R.H.

Transcript of FRACTRAN - een tamelijk nutteloze...

FRACTRAN

FRACTRAN. . . een tamelijk nutteloze programmeertaal

Hendrik Jan Hoogeboom

Theoretische Informatica

Universiteit Leiden 23.11’16

Leidsche Flesch Lunsch

“And I thought Brainf*ck was weird” – R.H.

FRACTRAN

“Hello world”

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)

FRACTRAN

searching for simple and powerful models

models for computability

Alan Turing (1912–1954)

“On Computable Numbers, with anApplication to the Entscheidungsproblem” (1937)

Emil Post (1897–1954)

“Finite Combinatory Processes - Formulation 1” (1936)

Marvin Minsky (1927–2016)

counter machine / register machine (1961)

pictures from turingarchive.org, Wikipedia, Bcjordan CC BY 3.0

FRACTRAN

John Horton Conway

Life, Death and the Monster - Numberphile (2014)

John Horton Conway (1937)

combinatorial game theory:surreal numbers, game of Life

geometric topology:knot polynomials

group theory: “A perfect group of order

8,315,553,613,086,720,000 . . .”

algorithmics: doomsday algorithm

theoretical physics:“ if experimenters have free will, then so do

elementary particles”

FRACTRAN

John Horton Conway

Life, Death and the Monster - Numberphile (2014)

John Horton Conway (1937)

combinatorial game theory:surreal numbers, game of Life

geometric topology:knot polynomials

group theory: “A perfect group of order

8,315,553,613,086,720,000 . . .”

algorithmics: doomsday algorithm

theoretical physics:“ if experimenters have free will, then so do

elementary particles”

FRACTRAN

John Horton Conway

Life, Death and the Monster - Numberphile (2014)

John Horton Conway (1937)

combinatorial game theory:surreal numbers, game of Life

geometric topology:knot polynomials

group theory: “A perfect group of order

8,315,553,613,086,720,000 . . .”

algorithmics: doomsday algorithm

theoretical physics:“ if experimenters have free will, then so do

elementary particles”

FRACTRAN

John Horton Conway

Life, Death and the Monster - Numberphile (2014)

John Horton Conway (1937)

combinatorial game theory:surreal numbers, game of Life

geometric topology:knot polynomials

group theory: “A perfect group of order

8,315,553,613,086,720,000 . . .”

algorithmics: doomsday algorithm

theoretical physics:“ if experimenters have free will, then so do

elementary particles”

FRACTRAN

John Horton Conway

Life, Death and the Monster - Numberphile (2014)

John Horton Conway (1937)

combinatorial game theory:surreal numbers, game of Life

geometric topology:knot polynomials

group theory: “A perfect group of order

8,315,553,613,086,720,000 . . .”

algorithmics: doomsday algorithm

theoretical physics:“ if experimenters have free will, then so do

elementary particles”

FRACTRAN

qualities of FRACTRAN

Only FRACTRAN has these star qualities!

Makes workday really easy!no complicated programming manual

Gets those functions really clean!configuration in a single integer, no other foreign concepts

Matches any machine on the marketeasy to write a FRACTRAN program to simulate othermachines

Astoundingly simple universal program!

FRACTRAN

computing with FRACTRAN

A Program for Primes

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)

FRACTRAN

computing with FRACTRAN

A Program for Primes

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132,116, 308, 364, 68, 4, 30, 225, 12375, 10875, 28875, 25375, 67375, 79625,14875, 13650, 2550, 2340, 1980, 1740, 4620, 4060, 10780, 12740, 2380,2184, 408, 152, 92, 380, 230, 950, 575, 2375, 9625, 11375, 2125, 1950,1650, 1450, 3850, 4550, 850, 780, 660, 580, 1540, 1820, 340, 312, 264,232, 616, 728, 136, 8, 60, 450, 3375, 185625, 163125, 433125, 380625,1010625, 888125, 2358125, 2786875, 520625, 477750, 89250, 81900,15300, 14040, 11880, 10440, 27720, 24360, 64680, 56840, 150920,178360, 33320, 30576, 5712, 2128, 1288, 5320, 3220, 13300, 8050, 33250,20125, 83125, 336875, 398125, 74375, 68250, 12750, 11700, 9900, 8700,23100, 20300, 53900, 63700, . . .

FRACTRAN

computing with FRACTRAN

A Program for Primes

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132,116, 308, 364, 68, 4, 30, 225, 12375, 10875, 28875, 25375, 67375, 79625,14875, 13650, 2550, 2340, 1980, 1740, 4620, 4060, 10780, 12740, 2380,2184, 408, 152, 92, 380, 230, 950, 575, 2375, 9625, 11375, 2125, 1950,1650, 1450, 3850, 4550, 850, 780, 660, 580, 1540, 1820, 340, 312, 264,232, 616, 728, 136, 8, 60, 450, 3375, 185625, 163125, 433125, 380625,1010625, 888125, 2358125, 2786875, 520625, 477750, 89250, 81900,15300, 14040, 11880, 10440, 27720, 24360, 64680, 56840, 150920,178360, 33320, 30576, 5712, 2128, 1288, 5320, 3220, 13300, 8050, 33250,20125, 83125, 336875, 398125, 74375, 68250, 12750, 11700, 9900, 8700,23100, 20300, 53900, 63700, . . .

FRACTRAN

computing with FRACTRAN

A Program for Primes

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132,116, 308, 364, 68, 4, 30, 225, 12375, 10875, 28875, 25375, 67375, 79625,14875, 13650, 2550, 2340, 1980, 1740, 4620, 4060, 10780, 12740, 2380,2184, 408, 152, 92, 380, 230, 950, 575, 2375, 9625, 11375, 2125, 1950,1650, 1450, 3850, 4550, 850, 780, 660, 580, 1540, 1820, 340, 312, 264,232, 616, 728, 136, 8, 60, 450, 3375, 185625, 163125, 433125, 380625,1010625, 888125, 2358125, 2786875, 520625, 477750, 89250, 81900,15300, 14040, 11880, 10440, 27720, 24360, 64680, 56840, 150920,178360, 33320, 30576, 5712, 2128, 1288, 5320, 3220, 13300, 8050, 33250,20125, 83125, 336875, 398125, 74375, 68250, 12750, 11700, 9900, 8700,23100, 20300, 53900, 63700, . . .

FRACTRAN

computing with FRACTRAN

A Program for Primes

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132,116, 308, 364, 68, 4, 30, 225, 12375, 10875, 28875, 25375, 67375, 79625,14875, 13650, 2550, 2340, 1980, 1740, 4620, 4060, 10780, 12740, 2380,2184, 408, 152, 92, 380, 230, 950, 575, 2375, 9625, 11375, 2125, 1950,1650, 1450, 3850, 4550, 850, 780, 660, 580, 1540, 1820, 340, 312, 264,232, 616, 728, 136, 8, 60, 450, 3375, 185625, 163125, 433125, 380625,1010625, 888125, 2358125, 2786875, 520625, 477750, 89250, 81900,15300, 14040, 11880, 10440, 27720, 24360, 64680, 56840, 150920,178360, 33320, 30576, 5712, 2128, 1288, 5320, 3220, 13300, 8050, 33250,20125, 83125, 336875, 398125, 74375, 68250, 12750, 11700, 9900, 8700,23100, 20300, 53900, 63700, . . .

FRACTRAN

computing with FRACTRAN

A Program for Primes

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132,116, 308, 364, 68, 4, 30, 225, 12375, 10875, 28875, 25375, 67375, 79625,14875, 13650, 2550, 2340, 1980, 1740, 4620, 4060, 10780, 12740, 2380,2184, 408, 152, 92, 380, 230, 950, 575, 2375, 9625, 11375, 2125, 1950,1650, 1450, 3850, 4550, 850, 780, 660, 580, 1540, 1820, 340, 312, 264,232, 616, 728, 136, 8, 60, 450, 3375, 185625, 163125, 433125, 380625,1010625, 888125, 2358125, 2786875, 520625, 477750, 89250, 81900,15300, 14040, 11880, 10440, 27720, 24360, 64680, 56840, 150920,178360, 33320, 30576, 5712, 2128, 1288, 5320, 3220, 13300, 8050, 33250,20125, 83125, 336875, 398125, 74375, 68250, 12750, 11700, 9900, 8700,23100, 20300, 53900, 63700, . . . ,

FRACTRAN

computing with FRACTRAN

A Program for Primes

(17

91,78

85,19

51,23

38,29

33,77

29,95

23,77

19,1

17,11

13,13

11,15

14,15

2,55

1

)21, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132,116, 308, 364, 68, 4

20, 30, 225, 12375, 10875, 28875, 25375, 67375, 79625,

14875, 13650, 2550, 2340, 1980, 1740, 4620, 4060, 10780, 12740, 2380,2184, 408, 152, 92, 380, 230, 950, 575, 2375, 9625, 11375, 2125, 1950,1650, 1450, 3850, 4550, 850, 780, 660, 580, 1540, 1820, 340, 312, 264,232, 616, 728, 136, 8

70, 60, 450, 3375, 185625, 163125, 433125, 380625,

1010625, 888125, 2358125, 2786875, 520625, 477750, 89250, 81900,15300, 14040, 11880, 10440, 27720, 24360, 64680, 56840, 150920,178360, 33320, 30576, 5712, 2128, 1288, 5320, 3220, 13300, 8050, 33250,20125, 83125, 336875, 398125, 74375, 68250, 12750, 11700, 9900, 8700,23100, 20300, 53900, 63700, . . . , 32

281, . . . , 128

708, . . . , 2048

2364, . . . , 8192

3877, . . .

FRACTRAN

qualities of FRACTRAN

Only FRACTRAN has these star qualities!

Makes workday really easy!no complicated programming manual

Gets those functions really clean!configuration in a single integer, no other foreign concepts

Matches any machine on the marketeasy to write a FRACTRAN program to simulate othermachines

Astoundingly simple universal program!

FRACTRAN

qualities of FRACTRAN

easy to write . . .(36546 ,

29161 ,

79575 ,

679451 ,

3159413 ,

83409 ,

473371 ,

638355 ,

434335 ,

89235 ,

17209 ,

79122 ,

31183 ,

41115 ,

51789 ,

11183 ,

30579 ,

2373 ,

7371 ,

6167 ,

3761 ,

1959 ,

8957 ,

4153 ,

83347 ,

5343

8641 ,

1338 ,

2337 ,

6731 ,

7129 ,

8319 ,

47517 ,

5913 ,

41291 ,

17 ,

111 ,

11024 ,

197 ,

891

)started at 2n the next power of 2 to appear is 2π(n) where

n = 0 1 2 3 4 5 6 7 8 9 10 11 12 . . .π(n) = 3 1 4 1 5 9 2 6 5 3 5 8 9 . . .

π

2=

2

1·23·43·45·65·67·87·89· . . . (Wallis)

FRACTRAN

A Program for Primes

Prime decomposition(17

7·13,2·3·135·17

,19

3·17,23

2·19,29

3·11,7·1129

,5·1923

,7·1119

,1

17,11

13,13

11,3·52·7

,3·52,5·111

)2

FRACTRAN

A Program for Primes

Prime decomposition(17

7·13,2·3·135·17

,19

3·17,23

2·19,29

3·11,7·1129

,5·1923

,7·1119

,1

17,11

13,13

11,3·52·7

,3·52,5·111

)2, 3·5

FRACTRAN

A Program for Primes

Prime decomposition(17

7·13,2·3·135·17

,19

3·17,23

2·19,29

3·11,7·1129

,5·1923

,7·1119

,1

17,11

13,13

11,3·52·7

,3·52,5·111

)2, 3·5, 3·52·11

FRACTRAN

A Program for Primes

Prime decomposition(17

7·13,2·3·135·17

,19

3·17,23

2·19,29

3·11,7·1129

,5·1923

,7·1119

,1

17,11

13,13

11,3·52·7

,3·52,5·111

)2, 3·5, 3·52·11, 52·29

FRACTRAN

A Program for Primes

Prime decomposition(17

7·13,2·3·135·17

,19

3·17,23

2·19,29

3·11,7·1129

,5·1923

,7·1119

,1

17,11

13,13

11,3·52·7

,3·52,5·111

)2, 3·5, 3·52·11, 52·29, 52·7·11

FRACTRAN

A Program for Primes

Prime decomposition(17

7·13,2·3·135·17

,19

3·17,23

2·19,29

3·11,7·1129

,5·1923

,7·1119

,1

17,11

13,13

11,3·52·7

,3·52,5·111

)2, 3·5, 3·52·11, 52·29, 52·7·11, 52·7·13

FRACTRAN

A Program for Primes

Prime decomposition(17

7·13,2·3·135·17

,19

3·17,23

2·19,29

3·11,7·1129

,5·1923

,7·1119

,1

17,11

13,13

11,3·52·7

,3·52,5·111

)2, 3·5, 3·52·11, 52·29, 52·7·11, 52·7·13, 52·17, 2·3·5·13, 2·3·5·11,2·5·29, 2·5·7·11, 2·5·7·13, 2·5·17, 22·3·13, 22·3·11, 22·29, 22·7·11,22·7·13, 22·17, 22, 2·3·5, 32·52, 32·53·11, 3·53·29, 3·537·11, . . .

FRACTRAN

Small program (2

3

)25·33

; 26·32 ; 27·31 ; 28·30

FRACTRAN

Small program (2

3

)25·33 ; 26·32 ; 27·31 ; 28·30

FRACTRAN

Small program (2

3

)25·33 ; 26·32 ; 27·31 ; 28·30

2a·3b ; 2a+ b

FRACTRAN

Small program (2

3

)25·33 ; 26·32 ; 27·31 ; 28·30

2a·3b ; 2a+ b

while b>0 do

a++; b--;

od

// a += b;

// b = 0;

FRACTRAN

Small program (2) (5

2·3,1

2,1

3

)25·33

; 24·32·51 ; 23·31·52 ; 22·30·53 ; 21·53 ; 53

FRACTRAN

Small program (2) (5

2·3,1

2,1

3

)25·33 ; 24·32·51 ; 23·31·52 ; 22·30·53 ; 21·53 ; 53

FRACTRAN

Small program (2) (5

2·3,1

2,1

3

)25·33 ; 24·32·51 ; 23·31·52 ; 22·30·53 ; 21·53 ; 53

2a·3b ; 5min(a, b)

while a·b>0 do

a--; b--; c++

od

// a=0 || b=0

while a>0 do

a--;

od

// a=0

while b>0 do

b--;

od

FRACTRAN

Multiplication

Loops that multiply

multiplication a = b · c

registers a,b,c,d 2, 3, 5, 7states 11, 13, 17, 19, 23

value 2a·3b·5c·7d · s

// (repeat c times) a += b;

while c>0 do

while b>0 do

a++; b--;

d++

od

while d>0 do

d--; b++;

od

c--;

od

// ready: ’exit’

23

exit

15

FRACTRAN

Multiplication

Loops that multiply

multiplication a = b · c

registers a,b,c,d 2, 3, 5, 7states 11, 13, 17, 19, 23

value 2a·3b·5c·7d · s

// (repeat c times) a += b;

while c>0 do

while b>0 do

a++; b--;

d++

od

X while d>0 do

d--; b++;

od

c--;

od

// ready: ’exit’

X

2·73

15

37

exit

1719

FRACTRAN

Multiplication

Loops that multiply

multiplication a = b · c

registers a,b,c,d 2, 3, 5, 7states 11, 13, 17, 19, 23

value 2a·3b·5c·7d · s

// (repeat c times) a += b;

while c>0 do

while b>0 do

a++; b--;

d++

od

while d>0 do

d--; b++;

od

c--;

od

// ready: ’exit’

11

13

17

19

23

2·7·133·11

1113

1711

115·17

3·197·17

2317

1719

(. . . ,

3·197·17

,11

5·17,23

17, . . .

)d > 0 d = 0&c > 0 d = c = 0

17

15

FRACTRAN

Multiplication

multiplication & division (wikipedia)

multiplication(5·7·133·11 ,

1113 ,

111 ,

37 ,

112 ,

13

)

11

13

1

5·73

12

37

13

2a·3b ; 5a·b

division(7·132·3·11 ,

1113 ,

13·11 ,

5·1711 ,

3·197·17 ,

1719 ,

1117 .

13

)

11

13n=n-dd=0r=d

17d=rr=0q++

1

d=0

19

72·3

51

13start

13

37

2n·3d·11 ; 5q ·7r(n = q·d+ r, 0 ≤ r < d)

FRACTRAN

Final Program

(177·13 ,

2·3·135·17 ,

193·17 ,

232·19 ,

293·11 ,

7·1129 ,

5·1923 ,

7·1119 ,

117 ,

1113 ,

1311 ,

3·52·7 ,

3·52 ,

5·111

)

1311 17

1

19

29

23

d--

a++b++c--

a-- c++

b==0c==0c++

c==o

b--a==o

d--

b--

d++ b==0

d==0

b++c++a--d--

b++c++a--

R.K. Guy: Conway’s prime producing machine,Mathematics Magazine (1983)

FRACTRAN

Counter Machines

models for computability

Alan Turing (1912–1954)

“On Computable Numbers, with anApplication to the Entscheidungsproblem” (1937)

Emil Post (1897–1954)

“Finite Combinatory Processes - Formulation 1” (1936)

Marvin Minsky (1927–2016)

counter machine / register machine (1961)

#z: increment counter i, goto #x

#z: if counter i zero, goto #x,else decrement and goto #y

FRACTRAN

Counter Machines

models for computability

Alan Turing (1912–1954)

“On Computable Numbers, with anApplication to the Entscheidungsproblem” (1937)

Emil Post (1897–1954)

“Finite Combinatory Processes - Formulation 1” (1936)

Marvin Minsky (1927–2016)

counter machine / register machine (1961)

#z: increment counter i, goto #xi·xz

#z: if counter i zero, goto #x,

else decrement and goto #yy

i·z,x

z

FRACTRAN

Counter Machines

Only FRACTRAN has these star qualities!

Makes workday really easy!no complicated programming manual

Gets those functions really clean!configuration in a single integer, no other foreign concepts

Matches any machine on the marketeasy to write a FRACTRAN program to simulate othermachines

Astoundingly simple universal program!

FRACTRAN

Counter Machines

Only FRACTRAN has these star qualities!

Makes workday really easy!no complicated programming manual

Gets those functions really clean!configuration in a single integer, no other foreign concepts

Matches any machine on the marketeasy to write a FRACTRAN program to simulate othermachines

Astoundingly simple universal program!(583

559,629

551,437

527,82

517,615

329,371

129,

1

115,53

86,43

53,23

47,341

46,

41

43,47

41,29

37,37

31,299

29,47

23,161

15,527

19,159

7,1

17,1

13,1

3

)

FRACTRAN

Thanks

The End.

FRACTRAN

Bibliography

J.H. Conway.Unpredictable Iterations.In: Proc. 1972 Number Theory Conference, Boulder Colorado,1972.

J.H. Conway.FRACTRAN: A simple universal programming language forarithmeticIn: Open Problems in Communication and Computation,Springer, 1983.

Julian Havil.Nonplussed!Princeton University Press, 2007

FRACTRAN

Bibliography

H.J. Hoogeboom.Carriers and Counters –P Systems with Carriers vs. (Blind) Counter Automata

Developments in Language Theory, LNCS 2450, 2003.(connection between counter automata and computational models)