Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2017
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 100.26 KB | None | 0 0
  1. 1
  2. 00:00:00,475 --> 00:00:02,160
  3. - [Presenter] The following
  4. content is provided
  5.  
  6. 2
  7. 00:00:02,160 --> 00:00:04,419
  8. under a Creative Commons license.
  9.  
  10. 3
  11. 00:00:04,419 --> 00:00:06,675
  12. Your support will help MIT OpenCourseWare
  13.  
  14. 4
  15. 00:00:06,675 --> 00:00:08,330
  16. continue to offer high quality
  17.  
  18. 5
  19. 00:00:08,330 --> 00:00:11,139
  20. educational resources for free.
  21.  
  22. 6
  23. 00:00:11,139 --> 00:00:13,748
  24. To make a donation or
  25. view additional materials
  26.  
  27. 7
  28. 00:00:13,748 --> 00:00:16,066
  29. from hundreds of MIT courses,
  30.  
  31. 8
  32. 00:00:16,066 --> 00:00:19,924
  33. visit MIT opencourseware at ocw.mit.edu.
  34.  
  35. 9
  36. 00:00:20,945 --> 00:00:23,518
  37. - So my name is Curran Kelleher,
  38.  
  39. 10
  40. 00:00:23,518 --> 00:00:26,243
  41. I'll be lecturing today
  42. about recursion and fractals.
  43.  
  44. 11
  45. 00:00:26,243 --> 00:00:29,276
  46. Justin Curry's not here
  47. today so I'm gonna fill in.
  48.  
  49. 12
  50. 00:00:30,227 --> 00:00:34,766
  51. So today I'm gonna just do
  52. a bunch of example programs,
  53.  
  54. 13
  55. 00:00:34,766 --> 00:00:36,785
  56. computer programs that are recursive.
  57.  
  58. 14
  59. 00:00:36,785 --> 00:00:39,008
  60. Some of them don't make
  61. pictures and some of them do,
  62.  
  63. 15
  64. 00:00:39,008 --> 00:00:40,373
  65. and when they make
  66. pictures, they're fractals.
  67.  
  68. 16
  69. 00:00:40,373 --> 00:00:43,035
  70. Fractals are things that are self-similar
  71.  
  72. 17
  73. 00:00:43,035 --> 00:00:46,507
  74. at different scales,
  75. so you can zoom in on.
  76.  
  77. 18
  78. 00:00:46,507 --> 00:00:49,946
  79. We're gonna take a break at
  80. four o'clock for 10 minutes.
  81.  
  82. 19
  83. 00:00:49,946 --> 00:00:52,301
  84. And then towards the end,
  85. hopefully I'll show you
  86.  
  87. 20
  88. 00:00:52,301 --> 00:00:56,158
  89. a bunch of examples of fractals
  90. in place in Bach music.
  91.  
  92. 21
  93. 00:00:56,158 --> 00:00:58,702
  94. So first of all,
  95.  
  96. 22
  97. 00:00:58,702 --> 00:01:02,326
  98. let's consider a recursive
  99. mathematical function,
  100.  
  101. 23
  102. 00:01:04,183 --> 00:01:08,629
  103. a factorial, something
  104. factorial like three factorials,
  105.  
  106. 24
  107. 00:01:08,629 --> 00:01:10,991
  108. three times two times one.
  109.  
  110. 25
  111. 00:01:10,991 --> 00:01:14,108
  112. And four factorial is four
  113. times three times two times one.
  114.  
  115. 26
  116. 00:01:14,108 --> 00:01:15,741
  117. So like...
  118.  
  119. 27
  120. 00:01:16,637 --> 00:01:19,339
  121. And this is factorial,
  122. the exclamation point.
  123.  
  124. 28
  125. 00:01:24,607 --> 00:01:29,422
  126. So the way this is defined
  127. is actually recursive.
  128.  
  129. 29
  130. 00:01:30,659 --> 00:01:34,744
  131. So if you take anything
  132. factorial, say n factorial is
  133.  
  134. 30
  135. 00:01:39,125 --> 00:01:41,299
  136. n minus one factorial,
  137.  
  138. 31
  139. 00:01:42,577 --> 00:01:47,061
  140. let's say n is four and n
  141. minus one would be three.
  142.  
  143. 32
  144. 00:01:47,061 --> 00:01:49,223
  145. So four factorial is...
  146.  
  147. 33
  148. 00:01:51,669 --> 00:01:53,367
  149. Wait.
  150.  
  151. 34
  152. 00:01:53,367 --> 00:01:55,575
  153. N, yeah, times n.
  154.  
  155. 35
  156. 00:01:58,030 --> 00:02:01,042
  157. So it's gonna be, well n
  158. times n minus one factorial.
  159.  
  160. 36
  161. 00:02:01,042 --> 00:02:05,224
  162. So four is n times this whole
  163. thing is three factorial.
  164.  
  165. 37
  166. 00:02:07,406 --> 00:02:09,724
  167. It's n minus one factorial.
  168.  
  169. 38
  170. 00:02:12,632 --> 00:02:15,179
  171. So this is a recursive definition.
  172.  
  173. 39
  174. 00:02:15,179 --> 00:02:17,401
  175. And if you look in the handout,
  176.  
  177. 40
  178. 00:02:17,401 --> 00:02:20,541
  179. I wrote a little computer program
  180.  
  181. 41
  182. 00:02:20,541 --> 00:02:24,389
  183. on page three I think
  184.  
  185. 42
  186. 00:02:24,389 --> 00:02:26,131
  187. that does the factorial.
  188.  
  189. 43
  190. 00:02:26,131 --> 00:02:28,577
  191. So it goes like this.
  192.  
  193. 44
  194. 00:02:40,186 --> 00:02:44,766
  195. So for those of you who don't
  196. know much about programming,
  197.  
  198. 45
  199. 00:02:44,766 --> 00:02:46,320
  200. def means define.
  201.  
  202. 46
  203. 00:02:46,320 --> 00:02:49,217
  204. So we're defining a
  205. function called factorial.
  206.  
  207. 47
  208. 00:02:49,217 --> 00:02:51,231
  209. And it takes as an argument n.
  210.  
  211. 48
  212. 00:02:51,231 --> 00:02:53,535
  213. So you can call this
  214. function pass it a number.
  215.  
  216. 49
  217. 00:02:53,535 --> 00:02:56,341
  218. And inside the function,
  219. it's referred to as n.
  220.  
  221. 50
  222. 00:02:56,341 --> 00:03:00,403
  223. So this factorial function
  224. says if n is greater than one,
  225.  
  226. 51
  227. 00:03:05,275 --> 00:03:09,251
  228. return n times factorial of n minus one.
  229.  
  230. 52
  231. 00:03:19,850 --> 00:03:22,397
  232. Else return one.
  233.  
  234. 53
  235. 00:03:29,981 --> 00:03:33,217
  236. So what makes this function recursive
  237.  
  238. 54
  239. 00:03:33,217 --> 00:03:34,938
  240. is the fact that it calls itself.
  241.  
  242. 55
  243. 00:03:34,938 --> 00:03:39,005
  244. Factorial is defined as n times
  245. factorial of something else.
  246.  
  247. 56
  248. 00:03:40,840 --> 00:03:44,619
  249. So a recursive function is a
  250. function that calls itself.
  251.  
  252. 57
  253. 00:03:46,654 --> 00:03:48,064
  254. So maybe an example.
  255.  
  256. 58
  257. 00:03:48,064 --> 00:03:50,433
  258. So if n is five say,
  259.  
  260. 59
  261. 00:03:52,338 --> 00:03:56,767
  262. the way we call this is
  263. we say factorial of five.
  264.  
  265. 60
  266. 00:04:02,029 --> 00:04:05,022
  267. So when we say this,
  268.  
  269. 61
  270. 00:04:05,022 --> 00:04:07,735
  271. it calls this function
  272.  
  273. 62
  274. 00:04:07,735 --> 00:04:10,424
  275. and gives n the number five.
  276.  
  277. 63
  278. 00:04:10,424 --> 00:04:13,214
  279. So what's it's gonna do
  280. is n is gonna be five.
  281.  
  282. 64
  283. 00:04:13,214 --> 00:04:16,565
  284. So n is greater than
  285. one so we return n times
  286.  
  287. 65
  288. 00:04:16,565 --> 00:04:19,075
  289. factorial of n minus one.
  290.  
  291. 66
  292. 00:04:19,075 --> 00:04:23,341
  293. So say we're doing this
  294. algorithm, five is n.
  295.  
  296. 67
  297. 00:04:23,341 --> 00:04:27,295
  298. So we're gonna return five
  299. times factorial of n minus one.
  300.  
  301. 68
  302. 00:04:27,295 --> 00:04:31,448
  303. So we call factorial with the value four,
  304.  
  305. 69
  306. 00:04:31,448 --> 00:04:34,108
  307. and that's also greater than one
  308.  
  309. 70
  310. 00:04:34,108 --> 00:04:37,400
  311. so we return four times
  312. factorial of three.
  313.  
  314. 71
  315. 00:04:38,281 --> 00:04:41,898
  316. So five times four
  317.  
  318. 72
  319. 00:04:41,898 --> 00:04:44,100
  320. times factorial three.
  321.  
  322. 73
  323. 00:04:44,100 --> 00:04:46,203
  324. So we loop,
  325.  
  326. 74
  327. 00:04:46,203 --> 00:04:49,264
  328. we call itself a bunch of times until
  329.  
  330. 75
  331. 00:04:49,264 --> 00:04:51,568
  332. we get down to one.
  333.  
  334. 76
  335. 00:04:57,936 --> 00:04:59,933
  336. So that's what actually ends up happening.
  337.  
  338. 77
  339. 00:04:59,933 --> 00:05:01,495
  340. This is recursion.
  341.  
  342. 78
  343. 00:05:01,495 --> 00:05:04,101
  344. So another simple example,
  345. which is sort of like
  346.  
  347. 79
  348. 00:05:04,101 --> 00:05:08,451
  349. the factorial is the Fibonacci numbers.
  350.  
  351. 80
  352. 00:05:08,451 --> 00:05:10,141
  353. Fibonacci sequence.
  354.  
  355. 81
  356. 00:05:18,971 --> 00:05:21,352
  357. So the Fibonacci numbers
  358.  
  359. 82
  360. 00:05:23,662 --> 00:05:25,589
  361. goes one, one
  362.  
  363. 83
  364. 00:05:25,589 --> 00:05:28,340
  365. and then the next one you
  366. add the first two together.
  367.  
  368. 84
  369. 00:05:28,340 --> 00:05:30,498
  370. So it goes one, one, two.
  371.  
  372. 85
  373. 00:05:30,498 --> 00:05:34,448
  374. One plus two is three,
  375. two plus three is five
  376.  
  377. 86
  378. 00:05:37,268 --> 00:05:39,877
  379. and so on, eight, blah, blah, blah.
  380.  
  381. 87
  382. 00:05:39,877 --> 00:05:42,126
  383. These are the Fibonacci numbers.
  384.  
  385. 88
  386. 00:05:42,126 --> 00:05:44,674
  387. So this is a recursive definition.
  388.  
  389. 89
  390. 00:05:44,674 --> 00:05:47,444
  391. Let's say this is...
  392.  
  393. 90
  394. 00:05:54,368 --> 00:05:57,608
  395. This is like the number of the element,
  396.  
  397. 91
  398. 00:05:57,608 --> 00:06:01,042
  399. like they're just numbers,
  400. indices if you will.
  401.  
  402. 92
  403. 00:06:01,042 --> 00:06:04,756
  404. So Fibonacci of two is Fibonacci of zero
  405.  
  406. 93
  407. 00:06:06,739 --> 00:06:08,830
  408. plus Fibonacci of one.
  409.  
  410. 94
  411. 00:06:08,830 --> 00:06:12,119
  412. And so Fibonacci five is
  413. gonna be Fibonacci of three
  414.  
  415. 95
  416. 00:06:12,119 --> 00:06:13,807
  417. plus Fibonacci of four.
  418.  
  419. 96
  420. 00:06:13,807 --> 00:06:16,591
  421. So generally, Fibonacci of n is gonna be
  422.  
  423. 97
  424. 00:06:16,591 --> 00:06:20,133
  425. Fibonacci of n minus one plus
  426. Fibonacci of n minus two.
  427.  
  428. 98
  429. 00:06:21,986 --> 00:06:24,648
  430. So we could say that here.
  431.  
  432. 99
  433. 00:06:26,814 --> 00:06:29,424
  434. Instead of factorial,
  435. we call it Fibonacci.
  436.  
  437. 100
  438. 00:06:29,424 --> 00:06:31,897
  439. And we'll notice that like
  440. they're almost the same thing.
  441.  
  442. 101
  443. 00:06:33,980 --> 00:06:35,852
  444. Say Fib.
  445.  
  446. 102
  447. 00:06:35,852 --> 00:06:39,076
  448. If n minus, if n is
  449. greater than one, we return
  450.  
  451. 103
  452. 00:06:45,290 --> 00:06:48,622
  453. Fibonacci of n minus one.
  454.  
  455. 104
  456. 00:06:54,828 --> 00:06:58,924
  457. And this gives us the
  458. Fibonacci numbers actually.
  459.  
  460. 105
  461. 00:07:00,337 --> 00:07:03,463
  462. So it makes sense to you guys?
  463.  
  464. 106
  465. 00:07:03,463 --> 00:07:06,872
  466. So in the handout, there
  467. are some example outputs
  468.  
  469. 107
  470. 00:07:06,872 --> 00:07:09,675
  471. of both of these.
  472.  
  473. 108
  474. 00:07:09,675 --> 00:07:11,885
  475. See that's what happens.
  476.  
  477. 109
  478. 00:07:15,803 --> 00:07:19,711
  479. So who has their copy of
  480. Godel, Escher, Bach today?
  481.  
  482. 110
  483. 00:07:19,711 --> 00:07:22,837
  484. So if we look on page 132
  485. of Godel, Escher, Bach...
  486.  
  487. 111
  488. 00:07:25,055 --> 00:07:27,147
  489. Oh no, now I can't look at it.
  490.  
  491. 112
  492. 00:07:27,147 --> 00:07:28,694
  493. Oh well.
  494.  
  495. 113
  496. 00:07:28,694 --> 00:07:31,484
  497. 132 of Grodel, Escher,
  498. Bach has these two diagrams
  499.  
  500. 114
  501. 00:07:31,484 --> 00:07:35,512
  502. that are recursive transition networks.
  503.  
  504. 115
  505. 00:07:35,512 --> 00:07:38,433
  506. They define a grammar,
  507.  
  508. 116
  509. 00:07:38,433 --> 00:07:40,426
  510. like sort of like English.
  511.  
  512. 117
  513. 00:07:40,426 --> 00:07:42,119
  514. It's not English, it's not complete,
  515.  
  516. 118
  517. 00:07:42,119 --> 00:07:44,197
  518. it's a simplified version of English
  519.  
  520. 119
  521. 00:07:44,197 --> 00:07:46,841
  522. but he communicates the essence
  523.  
  524. 120
  525. 00:07:46,841 --> 00:07:49,418
  526. of the notion of a grammar,
  527. a recursive grammar.
  528.  
  529. 121
  530. 00:07:50,385 --> 00:07:52,746
  531. So you'll notice that
  532.  
  533. 122
  534. 00:07:54,306 --> 00:07:56,306
  535. it's hard to do it in my head.
  536.  
  537. 123
  538. 00:07:56,306 --> 00:08:00,457
  539. Fancy noun, one of the nodes
  540. calls fancy noun again.
  541.  
  542. 124
  543. 00:08:02,001 --> 00:08:04,806
  544. It loops back out on itself.
  545.  
  546. 125
  547. 00:08:04,806 --> 00:08:07,334
  548. So this is where the recursion is.
  549.  
  550. 126
  551. 00:08:07,334 --> 00:08:09,955
  552. So what I did is I took this diagram
  553.  
  554. 127
  555. 00:08:09,955 --> 00:08:12,206
  556. and wrote a little computer program
  557.  
  558. 128
  559. 00:08:12,206 --> 00:08:15,651
  560. that whenever there's a
  561. choice of the transitions,
  562.  
  563. 129
  564. 00:08:15,651 --> 00:08:18,244
  565. it chooses one of those
  566. transitions at random.
  567.  
  568. 130
  569. 00:08:18,244 --> 00:08:21,978
  570. And this is the program I wrote.
  571.  
  572. 131
  573. 00:08:21,978 --> 00:08:25,291
  574. I think it's on page five of my handout.
  575.  
  576. 132
  577. 00:08:25,291 --> 00:08:27,743
  578. So if you look at that,
  579.  
  580. 133
  581. 00:08:29,343 --> 00:08:33,439
  582. yeah, I wish I had the
  583. projector, it's unfortunate.
  584.  
  585. 134
  586. 00:08:37,762 --> 00:08:40,968
  587. Actually, can I look at the diagram?
  588.  
  589. 135
  590. 00:08:45,245 --> 00:08:46,710
  591. So if we look at fancy noun,
  592.  
  593. 136
  594. 00:08:46,710 --> 00:08:49,735
  595. we begin and it calls ordinate noun.
  596.  
  597. 137
  598. 00:08:49,735 --> 00:08:53,119
  599. And then if you look at
  600. the program in the handout,
  601.  
  602. 138
  603. 00:08:53,119 --> 00:08:55,246
  604. you find fancy noun.
  605.  
  606. 139
  607. 00:08:55,246 --> 00:08:58,180
  608. It's sort of halfway down,
  609. says the RTN for fancy noun.
  610.  
  611. 140
  612. 00:08:59,050 --> 00:09:01,180
  613. Fancy noun equals,
  614.  
  615. 141
  616. 00:09:03,067 --> 00:09:04,590
  617. and this is a function call.
  618.  
  619. 142
  620. 00:09:04,590 --> 00:09:07,225
  621. Well, first of all, fancy noun equals.
  622.  
  623. 143
  624. 00:09:07,225 --> 00:09:09,032
  625. When you put curly
  626. braces around something,
  627.  
  628. 144
  629. 00:09:09,032 --> 00:09:11,401
  630. it makes it a function pretty much.
  631.  
  632. 145
  633. 00:09:12,468 --> 00:09:14,782
  634. So fancy noun equals,
  635.  
  636. 146
  637. 00:09:17,124 --> 00:09:20,963
  638. and it copies pretty much
  639. directly from the diagram.
  640.  
  641. 147
  642. 00:09:20,963 --> 00:09:25,054
  643. Ornate noun, which is
  644. also a function call,
  645.  
  646. 148
  647. 00:09:25,054 --> 00:09:26,843
  648. which is defined above.
  649.  
  650. 149
  651. 00:09:26,843 --> 00:09:29,624
  652. Plus, I'm still back in fancy noun,
  653.  
  654. 150
  655. 00:09:29,624 --> 00:09:32,820
  656. so ornate noun plus pick from preposition
  657.  
  658. 151
  659. 00:09:34,871 --> 00:09:37,527
  660. or relative pronoun or nothing.
  661.  
  662. 152
  663. 00:09:37,527 --> 00:09:40,083
  664. And if you look at the diagram
  665. in Godel, Escher, Bach,
  666.  
  667. 153
  668. 00:09:40,083 --> 00:09:42,420
  669. the arrows coming out of ornate noun
  670.  
  671. 154
  672. 00:09:42,420 --> 00:09:45,487
  673. point to relative pronoun, nothing,
  674.  
  675. 155
  676. 00:09:45,487 --> 00:09:47,499
  677. the end, and preposition.
  678.  
  679. 156
  680. 00:09:47,499 --> 00:09:51,091
  681. So you can make this
  682. into a computer program,
  683.  
  684. 157
  685. 00:09:53,721 --> 00:09:55,943
  686. which is what I did.
  687.  
  688. 158
  689. 00:09:55,943 --> 00:09:58,610
  690. So if you look at my
  691. program for a little while,
  692.  
  693. 159
  694. 00:09:58,610 --> 00:10:02,094
  695. you'll notice that all
  696. the arrows in the diagrams
  697.  
  698. 160
  699. 00:10:02,094 --> 00:10:05,556
  700. correspond to function
  701. calls in the program.
  702.  
  703. 161
  704. 00:10:07,153 --> 00:10:09,033
  705. And they're recursive
  706. because they eventually
  707.  
  708. 162
  709. 00:10:09,033 --> 00:10:10,651
  710. loop back on themselves.
  711.  
  712. 163
  713. 00:10:10,651 --> 00:10:13,827
  714. So here, Hofstadter is
  715. trying to communicate
  716.  
  717. 164
  718. 00:10:13,827 --> 00:10:15,826
  719. the fact that languages themselves
  720.  
  721. 165
  722. 00:10:15,826 --> 00:10:18,384
  723. are defined by recursive grammars.
  724.  
  725. 166
  726. 00:10:18,384 --> 00:10:22,235
  727. This is why we can nest
  728. sentences inside of each other.
  729.  
  730. 167
  731. 00:10:22,235 --> 00:10:23,866
  732. It's recursive.
  733.  
  734. 168
  735. 00:10:23,866 --> 00:10:26,206
  736. So recursion leads to nesting.
  737.  
  738. 169
  739. 00:10:26,206 --> 00:10:28,740
  740. And sometimes, infinite nesting.
  741.  
  742. 170
  743. 00:10:28,740 --> 00:10:31,332
  744. And that's where fractals come from.
  745.  
  746. 171
  747. 00:10:31,332 --> 00:10:34,653
  748. So right after this
  749. program in the handout,
  750.  
  751. 172
  752. 00:10:37,335 --> 00:10:39,208
  753. there's a sample output.
  754.  
  755. 173
  756. 00:10:39,208 --> 00:10:42,660
  757. So just read through some
  758. of those sample outputs.
  759.  
  760. 174
  761. 00:10:42,660 --> 00:10:44,617
  762. They're pretty funny.
  763.  
  764. 175
  765. 00:10:46,903 --> 00:10:48,258
  766. I have an old version.
  767.  
  768. 176
  769. 00:10:48,258 --> 00:10:51,275
  770. Can I look at someone's
  771. handout just to read?
  772.  
  773. 177
  774. 00:10:54,141 --> 00:10:57,591
  775. So small, small bagel
  776. inside the strange cow.
  777.  
  778. 178
  779. 00:10:57,591 --> 00:11:00,339
  780. It makes sense as an English sentence,
  781.  
  782. 179
  783. 00:11:00,339 --> 00:11:03,009
  784. and it was generated by
  785. this computer program.
  786.  
  787. 180
  788. 00:11:03,009 --> 00:11:05,519
  789. So I think that's just fascinating.
  790.  
  791. 181
  792. 00:11:05,519 --> 00:11:07,653
  793. But of course some of
  794. them don't make sense,
  795.  
  796. 182
  797. 00:11:07,653 --> 00:11:11,217
  798. like large small bagel that
  799. runs large small large horn.
  800.  
  801. 183
  802. 00:11:12,182 --> 00:11:15,585
  803. Just doesn't make any sense.
  804.  
  805. 184
  806. 00:11:15,585 --> 00:11:17,239
  807. So next example.
  808.  
  809. 185
  810. 00:11:20,928 --> 00:11:25,201
  811. So the next example on page
  812. five, I think, is a tree.
  813.  
  814. 186
  815. 00:11:25,201 --> 00:11:29,742
  816. We're gonna make a tree picture
  817. using recursive functions.
  818.  
  819. 187
  820. 00:11:29,742 --> 00:11:33,493
  821. So I'm gonna write some
  822. pseudocode, it's not real code,
  823.  
  824. 188
  825. 00:11:44,127 --> 00:11:46,163
  826. it's sort of pseudocode
  827. to communicate the idea
  828.  
  829. 189
  830. 00:11:46,163 --> 00:11:48,707
  831. of what this program is doing.
  832.  
  833. 190
  834. 00:12:05,294 --> 00:12:08,363
  835. So we have a function
  836.  
  837. 191
  838. 00:12:08,363 --> 00:12:09,541
  839. that grows a tree.
  840.  
  841. 192
  842. 00:12:09,541 --> 00:12:12,298
  843. It starts from a single branch,
  844.  
  845. 193
  846. 00:12:12,298 --> 00:12:14,815
  847. and I'll do it down here.
  848.  
  849. 194
  850. 00:12:14,815 --> 00:12:17,426
  851. This is like the starting point.
  852.  
  853. 195
  854. 00:12:17,426 --> 00:12:18,949
  855. This is the entry point.
  856.  
  857. 196
  858. 00:12:18,949 --> 00:12:22,050
  859. So it says class, all this stuff, tree.
  860.  
  861. 197
  862. 00:12:23,265 --> 00:12:28,017
  863. Tree parentheses, that gets
  864. called when the program starts.
  865.  
  866. 198
  867. 00:12:28,017 --> 00:12:31,259
  868. So this function call, grow
  869. tree 0.5, zero, trunk height,
  870.  
  871. 199
  872. 00:12:31,259 --> 00:12:34,597
  873. all this stuff, is this first one.
  874.  
  875. 200
  876. 00:12:34,597 --> 00:12:37,387
  877. This is what initiates the process.
  878.  
  879. 201
  880. 00:12:37,387 --> 00:12:40,211
  881. And then what the function does
  882.  
  883. 202
  884. 00:12:40,211 --> 00:12:42,257
  885. is pretty much...
  886.  
  887. 203
  888. 00:12:47,514 --> 00:12:50,968
  889. If the depth is greater than zero.
  890.  
  891. 204
  892. 00:13:16,636 --> 00:13:20,551
  893. So this tree function calls itself twice,
  894.  
  895. 205
  896. 00:13:22,156 --> 00:13:24,587
  897. once for each branch.
  898.  
  899. 206
  900. 00:13:25,815 --> 00:13:28,954
  901. So the first time the
  902. program calls this function,
  903.  
  904. 207
  905. 00:13:28,954 --> 00:13:31,880
  906. it makes this, it draws it on the screen.
  907.  
  908. 208
  909. 00:13:31,880 --> 00:13:34,207
  910. So notice here it adds
  911.  
  912. 209
  913. 00:13:40,020 --> 00:13:43,654
  914. the actual line if you look at the code.
  915.  
  916. 210
  917. 00:13:44,882 --> 00:13:49,169
  918. It says add new JV line,
  919. x one, x two, that stuff.
  920.  
  921. 211
  922. 00:13:50,140 --> 00:13:53,692
  923. That actually adds a line to the screen.
  924.  
  925. 212
  926. 00:13:54,614 --> 00:13:58,140
  927. I wish I could show you the
  928. actual code running but I can't.
  929.  
  930. 213
  931. 00:14:00,258 --> 00:14:01,774
  932. So this is the first time.
  933.  
  934. 214
  935. 00:14:01,774 --> 00:14:04,777
  936. And then depth is the number of times
  937.  
  938. 215
  939. 00:14:04,777 --> 00:14:07,145
  940. it's going to branch out.
  941.  
  942. 216
  943. 00:14:07,145 --> 00:14:11,192
  944. And so depth is 11, it's
  945. gonna make a big tree.
  946.  
  947. 217
  948. 00:14:12,590 --> 00:14:16,931
  949. What it's gonna do is
  950. make two sub branches.
  951.  
  952. 218
  953. 00:14:16,931 --> 00:14:20,497
  954. This is grow tree, this one
  955. correlates to this one here,
  956.  
  957. 219
  958. 00:14:21,918 --> 00:14:24,605
  959. and this one corresponds to this one here.
  960.  
  961. 220
  962. 00:14:27,465 --> 00:14:29,874
  963. If you look at the code in the handout,
  964.  
  965. 221
  966. 00:14:29,874 --> 00:14:32,678
  967. it says grow tree, x two, y two.
  968.  
  969. 222
  970. 00:14:34,393 --> 00:14:38,230
  971. X two, y two is the end
  972. point of the previous branch.
  973.  
  974. 223
  975. 00:14:38,230 --> 00:14:40,212
  976. Root length times size factor.
  977.  
  978. 224
  979. 00:14:40,212 --> 00:14:44,392
  980. So size factor is a factor
  981. by which it's going to scale.
  982.  
  983. 225
  984. 00:14:44,392 --> 00:14:48,578
  985. So this would be like
  986. maybe half a size, or 0.7.
  987.  
  988. 226
  989. 00:14:50,237 --> 00:14:53,941
  990. Size factor is 0.58, so
  991. it's about half the size.
  992.  
  993. 227
  994. 00:14:54,820 --> 00:14:57,547
  995. And root angle plus angle factor,
  996.  
  997. 228
  998. 00:14:57,547 --> 00:14:59,495
  999. root angle minus angle factor.
  1000.  
  1001. 229
  1002. 00:14:59,495 --> 00:15:02,697
  1003. These are in the two
  1004. grow tree function calls.
  1005.  
  1006. 230
  1007. 00:15:02,697 --> 00:15:06,686
  1008. Angle factor, which is
  1009. point, well, pi over four,
  1010.  
  1011. 231
  1012. 00:15:08,847 --> 00:15:11,299
  1013. it's exactly 45 degrees.
  1014.  
  1015. 232
  1016. 00:15:11,299 --> 00:15:14,090
  1017. So each time it branches,
  1018. the two branches are gonna
  1019.  
  1020. 233
  1021. 00:15:14,090 --> 00:15:16,611
  1022. branch out as that angle.
  1023.  
  1024. 234
  1025. 00:15:16,611 --> 00:15:20,703
  1026. And so here, say we do depth of four
  1027.  
  1028. 235
  1029. 00:15:22,188 --> 00:15:24,127
  1030. when we call it the first time.
  1031.  
  1032. 236
  1033. 00:15:24,127 --> 00:15:26,138
  1034. The depth here is gonna be four.
  1035.  
  1036. 237
  1037. 00:15:26,138 --> 00:15:30,058
  1038. And then you pass into the
  1039. function, depth minus one.
  1040.  
  1041. 238
  1042. 00:15:31,720 --> 00:15:36,105
  1043. So here inside the function
  1044. that's generating this depth
  1045.  
  1046. 239
  1047. 00:15:36,105 --> 00:15:37,727
  1048. that's gonna be three,
  1049.  
  1050. 240
  1051. 00:15:37,727 --> 00:15:40,342
  1052. and so it's gonna keep going
  1053. down until depth is zero.
  1054.  
  1055. 241
  1056. 00:15:40,342 --> 00:15:44,086
  1057. So here, depth is, well, depth it's four,
  1058.  
  1059. 242
  1060. 00:15:45,970 --> 00:15:48,720
  1061. three, two, one.
  1062.  
  1063. 243
  1064. 00:15:55,817 --> 00:15:58,520
  1065. And it does it on this side too.
  1066.  
  1067. 244
  1068. 00:16:04,506 --> 00:16:05,931
  1069. So it just keeps going like this.
  1070.  
  1071. 245
  1072. 00:16:05,931 --> 00:16:07,647
  1073. This is a fractal.
  1074.  
  1075. 246
  1076. 00:16:09,228 --> 00:16:11,593
  1077. And you could imagine if you were to
  1078.  
  1079. 247
  1080. 00:16:11,593 --> 00:16:13,896
  1081. continue this infinitely,
  1082.  
  1083. 248
  1084. 00:16:15,374 --> 00:16:17,769
  1085. like instead of saying depth of 10 or 11,
  1086.  
  1087. 249
  1088. 00:16:17,769 --> 00:16:19,940
  1089. just say depth of infinity,
  1090.  
  1091. 250
  1092. 00:16:19,940 --> 00:16:21,874
  1093. say theoretically if we could do this,
  1094.  
  1095. 251
  1096. 00:16:21,874 --> 00:16:25,473
  1097. this shape could be zoomed
  1098. in on infinitely forever,
  1099.  
  1100. 252
  1101. 00:16:27,151 --> 00:16:29,008
  1102. and this is the notion of a fractal.
  1103.  
  1104. 253
  1105. 00:16:29,008 --> 00:16:32,709
  1106. And it would look the same as
  1107. it does on the large scale.
  1108.  
  1109. 254
  1110. 00:16:32,709 --> 00:16:35,913
  1111. So any questions about the tree?
  1112.  
  1113. 255
  1114. 00:16:35,913 --> 00:16:38,626
  1115. So next we're gonna do the Koch curve.
  1116.  
  1117. 256
  1118. 00:16:41,559 --> 00:16:44,389
  1119. Koch curve is sort of similar to the tree
  1120.  
  1121. 257
  1122. 00:16:45,775 --> 00:16:48,602
  1123. except that the rules are different.
  1124.  
  1125. 258
  1126. 00:16:50,482 --> 00:16:54,071
  1127. So first conceptually, this
  1128. is what a Koch curve is.
  1129.  
  1130. 259
  1131. 00:16:54,071 --> 00:16:56,517
  1132. You start with a line,
  1133.  
  1134. 260
  1135. 00:16:56,517 --> 00:17:00,135
  1136. or in some cases a triangle
  1137. to make the the whole thing;
  1138.  
  1139. 261
  1140. 00:17:00,135 --> 00:17:03,609
  1141. and you divide it into three
  1142. parts and then you make
  1143.  
  1144. 262
  1145. 00:17:03,609 --> 00:17:07,736
  1146. an equilateral triangle, I
  1147. mean the sides are all the same
  1148.  
  1149. 263
  1150. 00:17:07,736 --> 00:17:11,180
  1151. out of the thing in the middle
  1152. and get rid of this line.
  1153.  
  1154. 264
  1155. 00:17:13,797 --> 00:17:15,253
  1156. So this is the rule.
  1157.  
  1158. 265
  1159. 00:17:15,253 --> 00:17:17,369
  1160. Go from a line to this thing.
  1161.  
  1162. 266
  1163. 00:17:17,369 --> 00:17:19,691
  1164. And then this rule is applied to each one
  1165.  
  1166. 267
  1167. 00:17:19,691 --> 00:17:21,028
  1168. of these segments.
  1169.  
  1170. 268
  1171. 00:17:21,028 --> 00:17:22,722
  1172. So you go like this.
  1173.  
  1174. 269
  1175. 00:17:24,997 --> 00:17:28,752
  1176. And so on, like to each
  1177. of these smaller segments.
  1178.  
  1179. 270
  1180. 00:17:30,795 --> 00:17:33,375
  1181. So the fact that like the simple rule
  1182.  
  1183. 271
  1184. 00:17:33,375 --> 00:17:36,114
  1185. is being applied to
  1186. something over and over again
  1187.  
  1188. 272
  1189. 00:17:36,114 --> 00:17:40,535
  1190. and the thing that's being applied to
  1191. is the result of the previous execution
  1192.  
  1193. 273
  1194. 00:17:40,535 --> 00:17:43,587
  1195. of the rule, makes it recursive.
  1196.  
  1197. 274
  1198. 00:17:45,090 --> 00:17:48,651
  1199. So I keep drawing it.
  1200.  
  1201. 275
  1202. 00:17:48,651 --> 00:17:51,790
  1203. Let's look at the actual
  1204. code, the program.
  1205.  
  1206. 276
  1207. 00:17:51,790 --> 00:17:55,975
  1208. This is Koch, I think it's on page seven.
  1209.  
  1210. 277
  1211. 00:17:59,653 --> 00:18:02,955
  1212. So let's see, CreateCurve.
  1213.  
  1214. 278
  1215. 00:18:12,718 --> 00:18:16,464
  1216. What CreateCurve does essentially is
  1217.  
  1218. 279
  1219. 00:18:19,652 --> 00:18:22,281
  1220. call itself four times.
  1221.  
  1222. 280
  1223. 00:18:27,963 --> 00:18:31,509
  1224. And each of those four times
  1225. corresponds to this one,
  1226.  
  1227. 281
  1228. 00:18:31,509 --> 00:18:34,259
  1229. this one, this one and this one.
  1230.  
  1231. 282
  1232. 00:18:41,286 --> 00:18:44,107
  1233. So yeah, let's look at the actual code.
  1234.  
  1235. 283
  1236. 00:18:45,310 --> 00:18:47,596
  1237. You see these four function
  1238. calls to CreateCurve
  1239.  
  1240. 284
  1241. 00:18:47,596 --> 00:18:49,867
  1242. in the middle there?
  1243.  
  1244. 285
  1245. 00:18:49,867 --> 00:18:53,238
  1246. x one, y one, ax, ay, cx,
  1247. cy, by, all this stuff.
  1248.  
  1249. 286
  1250. 00:18:56,868 --> 00:19:00,027
  1251. If you look at the little red diagram,
  1252.  
  1253. 287
  1254. 00:19:01,010 --> 00:19:04,716
  1255. this point is x one y, one and you know,
  1256.  
  1257. 288
  1258. 00:19:06,026 --> 00:19:08,359
  1259. it's in the diagram what the points are.
  1260.  
  1261. 289
  1262. 00:19:08,359 --> 00:19:10,705
  1263. So the first function call
  1264.  
  1265. 290
  1266. 00:19:12,486 --> 00:19:16,052
  1267. pretty much says apply
  1268. the rule to this segment.
  1269.  
  1270. 291
  1271. 00:19:16,052 --> 00:19:18,061
  1272. The second function call starts from a,
  1273.  
  1274. 292
  1275. 00:19:18,061 --> 00:19:20,741
  1276. which is this point here,
  1277. which says apply the rule
  1278.  
  1279. 293
  1280. 00:19:20,741 --> 00:19:22,310
  1281. to this segment.
  1282.  
  1283. 294
  1284. 00:19:22,310 --> 00:19:24,784
  1285. The third one starts at
  1286. c, which is the top point
  1287.  
  1288. 295
  1289. 00:19:24,784 --> 00:19:28,097
  1290. and it says apply the
  1291. rule to this segment.
  1292.  
  1293. 296
  1294. 00:19:29,182 --> 00:19:33,150
  1295. And and the fourth one
  1296. applies the rule to this one.
  1297.  
  1298. 297
  1299. 00:19:33,150 --> 00:19:36,933
  1300. So it's another beautiful
  1301. recursive fractal.
  1302.  
  1303. 298
  1304. 00:19:39,874 --> 00:19:43,141
  1305. So what happens, so
  1306. this is the Koch curve.
  1307.  
  1308. 299
  1309. 00:19:43,141 --> 00:19:46,560
  1310. If you generalize this and
  1311. add a randomness to it,
  1312.  
  1313. 300
  1314. 00:19:46,560 --> 00:19:50,184
  1315. say these points are a, it doesn't matter
  1316.  
  1317. 301
  1318. 00:19:50,184 --> 00:19:52,516
  1319. what they're called, if you move this one
  1320.  
  1321. 302
  1322. 00:19:52,516 --> 00:19:55,833
  1323. up and down a little bit randomly,
  1324.  
  1325. 303
  1326. 00:19:56,740 --> 00:19:59,467
  1327. so like you start from this
  1328.  
  1329. 304
  1330. 00:19:59,467 --> 00:20:02,511
  1331. instead of making these points exact,
  1332.  
  1333. 305
  1334. 00:20:02,511 --> 00:20:04,524
  1335. make them like a little bit off
  1336.  
  1337. 306
  1338. 00:20:04,524 --> 00:20:07,270
  1339. and then connect the lines
  1340.  
  1341. 307
  1342. 00:20:07,270 --> 00:20:10,554
  1343. and make a line, a triangle there.
  1344.  
  1345. 308
  1346. 00:20:10,554 --> 00:20:12,604
  1347. And this is also a little bit off.
  1348.  
  1349. 309
  1350. 00:20:12,604 --> 00:20:14,984
  1351. And then if you keep doing
  1352. this, adding a little bit
  1353.  
  1354. 310
  1355. 00:20:14,984 --> 00:20:16,974
  1356. of randomization each time,
  1357.  
  1358. 311
  1359. 00:20:16,974 --> 00:20:20,988
  1360. you actually get lines that
  1361. look just like coastlines
  1362.  
  1363. 312
  1364. 00:20:20,988 --> 00:20:24,351
  1365. around pieces of land.
  1366.  
  1367. 313
  1368. 00:20:24,351 --> 00:20:26,637
  1369. And if you generalize
  1370. this into three dimensions
  1371.  
  1372. 314
  1373. 00:20:26,637 --> 00:20:28,943
  1374. and do this randomness,
  1375. it actually generates
  1376.  
  1377. 315
  1378. 00:20:28,943 --> 00:20:33,160
  1379. 3D mountains like virtual 3D surfaces
  1380.  
  1381. 316
  1382. 00:20:33,160 --> 00:20:36,566
  1383. that look exactly like real mountains.
  1384.  
  1385. 317
  1386. 00:20:36,566 --> 00:20:40,885
  1387. So it's sort of strange like
  1388. these recursive structures are
  1389.  
  1390. 318
  1391. 00:20:40,885 --> 00:20:43,385
  1392. definitely in nature.
  1393.  
  1394. 319
  1395. 00:20:45,360 --> 00:20:47,930
  1396. - [Female student] What
  1397. does it mean (mumbles) page,
  1398.  
  1399. 320
  1400. 00:20:47,930 --> 00:20:49,985
  1401. page six, the Koch
  1402. snowflake has finite area
  1403.  
  1404. 321
  1405. 00:20:49,985 --> 00:20:51,344
  1406. but infinite perimeter?
  1407.  
  1408. 322
  1409. 00:20:51,344 --> 00:20:53,587
  1410. - Oh yeah, yeah, I forgot to mention that,
  1411.  
  1412. 323
  1413. 00:20:53,587 --> 00:20:54,970
  1414. that's a really cool thing.
  1415.  
  1416. 324
  1417. 00:20:54,970 --> 00:20:59,595
  1418. So the Koch snowflake is when
  1419. you start with a triangle
  1420.  
  1421. 325
  1422. 00:20:59,595 --> 00:21:02,762
  1423. and you apply the rule to
  1424. each sides of the triangle
  1425.  
  1426. 326
  1427. 00:21:04,845 --> 00:21:09,845
  1428. and you get this curve on all these sides.
  1429.  
  1430. 327
  1431. 00:21:10,214 --> 00:21:12,601
  1432. So it's been mathematically proven,
  1433.  
  1434. 328
  1435. 00:21:12,601 --> 00:21:14,348
  1436. or you know extrapolated that
  1437.  
  1438. 329
  1439. 00:21:14,348 --> 00:21:17,531
  1440. if you were to do this rule
  1441. an infinite number of times,
  1442.  
  1443. 330
  1444. 00:21:17,531 --> 00:21:20,455
  1445. which you can do in math
  1446. because it's all theoretical,
  1447.  
  1448. 331
  1449. 00:21:20,455 --> 00:21:23,717
  1450. the volume inside of this
  1451. object would be finite.
  1452.  
  1453. 332
  1454. 00:21:23,717 --> 00:21:25,989
  1455. It's a definite amount.
  1456.  
  1457. 333
  1458. 00:21:25,989 --> 00:21:28,461
  1459. But the surface area is infinite.
  1460.  
  1461. 334
  1462. 00:21:29,958 --> 00:21:32,193
  1463. Well, not surface area, the perimeter.
  1464.  
  1465. 335
  1466. 00:21:32,193 --> 00:21:34,055
  1467. The perimeter is infinite.
  1468.  
  1469. 336
  1470. 00:21:34,055 --> 00:21:37,284
  1471. That's because every
  1472. time you apply the rule,
  1473.  
  1474. 337
  1475. 00:21:37,284 --> 00:21:40,886
  1476. you actually increase the perimeter.
  1477.  
  1478. 338
  1479. 00:21:40,886 --> 00:21:42,164
  1480. So this
  1481.  
  1482. 339
  1483. 00:21:44,885 --> 00:21:46,697
  1484. has a certain length.
  1485.  
  1486. 340
  1487. 00:21:46,697 --> 00:21:48,441
  1488. And then once you apply the rule to it,
  1489.  
  1490. 341
  1491. 00:21:48,441 --> 00:21:50,628
  1492. if you do this,
  1493.  
  1494. 342
  1495. 00:21:50,628 --> 00:21:54,927
  1496. then this new curve, the
  1497. total length is longer
  1498.  
  1499. 343
  1500. 00:21:54,927 --> 00:21:56,501
  1501. than this one.
  1502.  
  1503. 344
  1504. 00:21:56,501 --> 00:21:58,439
  1505. So you can imagine, if
  1506. you do it infinitely,
  1507.  
  1508. 345
  1509. 00:21:58,439 --> 00:22:01,289
  1510. like it's just gonna be infinitely long.
  1511.  
  1512. 346
  1513. 00:22:01,289 --> 00:22:02,891
  1514. So it's sort of mind-boggling.
  1515.  
  1516. 347
  1517. 00:22:02,891 --> 00:22:05,024
  1518. And this goes, yeah, what's up?
  1519.  
  1520. 348
  1521. 00:22:05,024 --> 00:22:06,670
  1522. (distant indistinct muttering)
  1523.  
  1524. 349
  1525. 00:22:07,910 --> 00:22:10,963
  1526. Yeah, it gets smaller
  1527. and smaller definitely.
  1528.  
  1529. 350
  1530. 00:22:12,379 --> 00:22:16,481
  1531. But if you do it theoretically
  1532. an infinite number of times,
  1533.  
  1534. 351
  1535. 00:22:18,221 --> 00:22:19,902
  1536. like it'll still exist.
  1537.  
  1538. 352
  1539. 00:22:19,902 --> 00:22:22,017
  1540. If you look at the picture
  1541.  
  1542. 353
  1543. 00:22:24,554 --> 00:22:27,831
  1544. on page six, right next to the title,
  1545.  
  1546. 354
  1547. 00:22:29,367 --> 00:22:33,329
  1548. the Koch snowflake, that
  1549. curve there, you see it?
  1550.  
  1551. 355
  1552. 00:22:35,124 --> 00:22:37,011
  1553. That's sort of what it would look like
  1554.  
  1555. 356
  1556. 00:22:37,011 --> 00:22:39,382
  1557. even if you did it an
  1558. infinite number of times.
  1559.  
  1560. 357
  1561. 00:22:39,382 --> 00:22:41,272
  1562. (distant indistinct muttering)
  1563.  
  1564. 358
  1565. 00:22:45,448 --> 00:22:47,679
  1566. Say again?
  1567. (distant indistinct muttering)
  1568.  
  1569. 359
  1570. 00:22:57,351 --> 00:22:59,684
  1571. So like, you just cut it in half?
  1572.  
  1573. 360
  1574. 00:22:59,684 --> 00:23:01,875
  1575. - [Male student] Not in
  1576. half but just cut like
  1577.  
  1578. 361
  1579. 00:23:01,875 --> 00:23:04,230
  1580. (distant indistinct muttering)
  1581.  
  1582. 362
  1583. 00:23:10,537 --> 00:23:12,808
  1584. - I don't really understand.
  1585.  
  1586. 363
  1587. 00:23:12,808 --> 00:23:14,573
  1588. You can draw it on the board if you want.
  1589.  
  1590. 364
  1591. 00:23:14,573 --> 00:23:16,475
  1592. - On the board?
  1593. - Yeah.
  1594.  
  1595. 365
  1596. 00:23:22,013 --> 00:23:26,347
  1597. - I have like a circle, I just
  1598. cut like this part over here.
  1599.  
  1600. 366
  1601. 00:23:26,347 --> 00:23:29,074
  1602. Even if this is like finite area,
  1603.  
  1604. 367
  1605. 00:23:29,074 --> 00:23:31,644
  1606. you're saying that if I
  1607. cut it like that, (mumbles)
  1608.  
  1609. 368
  1610. 00:23:31,644 --> 00:23:33,441
  1611. (crosstalk)
  1612.  
  1613. 369
  1614. 00:23:39,445 --> 00:23:40,798
  1615. - I see what you mean.
  1616.  
  1617. 370
  1618. 00:23:40,798 --> 00:23:43,648
  1619. So say you have Koch curve, this shape,
  1620.  
  1621. 371
  1622. 00:23:48,817 --> 00:23:52,005
  1623. and it were a string and you would cut it
  1624.  
  1625. 372
  1626. 00:23:52,005 --> 00:23:54,273
  1627. so the string would now be loose?
  1628.  
  1629. 373
  1630. 00:23:54,273 --> 00:23:58,045
  1631. And if you pulled it,
  1632. it would go on forever?
  1633.  
  1634. 374
  1635. 00:23:58,045 --> 00:23:59,942
  1636. Yeah, it would.
  1637.  
  1638. 375
  1639. 00:23:59,942 --> 00:24:01,563
  1640. - [Male student] Sounds nice.
  1641.  
  1642. 376
  1643. 00:24:01,563 --> 00:24:02,945
  1644. - Yeah.
  1645.  
  1646. 377
  1647. 00:24:02,945 --> 00:24:05,381
  1648. That's what it means to
  1649. have infinite perimeter,
  1650.  
  1651. 378
  1652. 00:24:05,381 --> 00:24:09,172
  1653. which is why it's just so
  1654. fascinating, like it's crazy.
  1655.  
  1656. 379
  1657. 00:24:09,172 --> 00:24:11,189
  1658. People trying to measure
  1659. the coast of Britain.
  1660.  
  1661. 380
  1662. 00:24:11,189 --> 00:24:12,798
  1663. How long is the coast of Britain, right?
  1664.  
  1665. 381
  1666. 00:24:12,798 --> 00:24:14,697
  1667. Have you heard about this problem?
  1668.  
  1669. 382
  1670. 00:24:14,697 --> 00:24:17,298
  1671. If you look at it on a large scale,
  1672.  
  1673. 383
  1674. 00:24:17,298 --> 00:24:19,738
  1675. like from a satellite
  1676. image of the whole country,
  1677.  
  1678. 384
  1679. 00:24:19,738 --> 00:24:21,846
  1680. you can just draw a line
  1681. around it and say like oh yeah,
  1682.  
  1683. 385
  1684. 00:24:21,846 --> 00:24:23,865
  1685. it's this length, this is the length
  1686.  
  1687. 386
  1688. 00:24:23,865 --> 00:24:25,228
  1689. of the coast of Britain.
  1690.  
  1691. 387
  1692. 00:24:25,228 --> 00:24:28,706
  1693. But if you zoom in on it,
  1694. you'll find tha those big lines
  1695.  
  1696. 388
  1697. 00:24:28,706 --> 00:24:31,302
  1698. that you drew are actually
  1699. like really wrong.
  1700.  
  1701. 389
  1702. 00:24:31,302 --> 00:24:33,716
  1703. Like they don't actually line up.
  1704.  
  1705. 390
  1706. 00:24:33,716 --> 00:24:37,049
  1707. So if you make it more precise
  1708. to this new zooming angle,
  1709.  
  1710. 391
  1711. 00:24:37,049 --> 00:24:39,888
  1712. the zooming, it gets longer.
  1713.  
  1714. 392
  1715. 00:24:39,888 --> 00:24:42,430
  1716. And so actually, the more that you zoom in
  1717.  
  1718. 393
  1719. 00:24:42,430 --> 00:24:45,788
  1720. on the coast of Britain the
  1721. longer the perimeter gets.
  1722.  
  1723. 394
  1724. 00:24:46,673 --> 00:24:49,000
  1725. (distant indistinct muttering)
  1726.  
  1727. 395
  1728. 00:24:50,740 --> 00:24:52,455
  1729. Yeah, just adding little pieces.
  1730.  
  1731. 396
  1732. 00:24:52,455 --> 00:24:56,319
  1733. So say the actual coast
  1734. of Britain is like that,
  1735.  
  1736. 397
  1737. 00:24:57,337 --> 00:25:01,102
  1738. but you look at it like at
  1739. this huge distance away.
  1740.  
  1741. 398
  1742. 00:25:01,102 --> 00:25:04,523
  1743. You say like oh yeah, this
  1744. is approximately that line.
  1745.  
  1746. 399
  1747. 00:25:04,523 --> 00:25:06,757
  1748. But if you look at it
  1749. more detail and refine it,
  1750.  
  1751. 400
  1752. 00:25:06,757 --> 00:25:08,367
  1753. you say oh it's not actually that line,
  1754.  
  1755. 401
  1756. 00:25:08,367 --> 00:25:11,255
  1757. it's maybe like these lines.
  1758.  
  1759. 402
  1760. 00:25:11,255 --> 00:25:14,575
  1761. But the new lines are actually,
  1762. the whole thing is longer.
  1763.  
  1764. 403
  1765. 00:25:14,575 --> 00:25:16,561
  1766. And if you do it even
  1767. more and more precisely,
  1768.  
  1769. 404
  1770. 00:25:16,561 --> 00:25:18,555
  1771. you'd just get longer
  1772. and longer and longer.
  1773.  
  1774. 405
  1775. 00:25:18,555 --> 00:25:20,572
  1776. So nobody's been able to really figure out
  1777.  
  1778. 406
  1779. 00:25:20,572 --> 00:25:22,418
  1780. how long the coast of Britain is.
  1781.  
  1782. 407
  1783. 00:25:22,418 --> 00:25:23,724
  1784. It's a fractal.
  1785.  
  1786. 408
  1787. 00:25:23,724 --> 00:25:26,505
  1788. - [Male] Is it even possible like
  1789.  
  1790. 409
  1791. 00:25:26,505 --> 00:25:29,432
  1792. (distant indistinct muttering)
  1793.  
  1794. 410
  1795. 00:25:32,618 --> 00:25:35,169
  1796. - Well, not really.
  1797.  
  1798. 411
  1799. 00:25:39,334 --> 00:25:41,805
  1800. So he asks like, is it
  1801. possible in this world
  1802.  
  1803. 412
  1804. 00:25:41,805 --> 00:25:44,877
  1805. to have something that's
  1806. really infinite like that?
  1807.  
  1808. 413
  1809. 00:25:44,877 --> 00:25:46,981
  1810. No, it's not.
  1811.  
  1812. 414
  1813. 00:25:46,981 --> 00:25:50,875
  1814. Because I mean, there's only
  1815. finite space on the earth.
  1816.  
  1817. 415
  1818. 00:25:50,875 --> 00:25:53,968
  1819. - [Male student] Yeah but I mean,
  1820.  
  1821. 416
  1822. 00:25:53,968 --> 00:25:57,132
  1823. you just said that even
  1824. if it has finite area
  1825.  
  1826. 417
  1827. 00:25:57,132 --> 00:26:00,486
  1828. (distant indistinct muttering)
  1829.  
  1830. 418
  1831. 00:26:00,486 --> 00:26:03,041
  1832. - Yeah, so the Koch curve theoretically,
  1833.  
  1834. 419
  1835. 00:26:03,041 --> 00:26:05,551
  1836. you know in math language,
  1837.  
  1838. 420
  1839. 00:26:05,551 --> 00:26:07,837
  1840. if you do it mathematically,
  1841. it has infinite perimeter
  1842.  
  1843. 421
  1844. 00:26:07,837 --> 00:26:09,296
  1845. but finite area.
  1846.  
  1847. 422
  1848. 00:26:09,296 --> 00:26:11,519
  1849. But keep in mind this is
  1850. a theoretical creation.
  1851.  
  1852. 423
  1853. 00:26:11,519 --> 00:26:14,713
  1854. It's just in the world of math
  1855.  
  1856. 424
  1857. 00:26:14,713 --> 00:26:18,666
  1858. and it can't really exist in the universe.
  1859.  
  1860. 425
  1861. 00:26:18,666 --> 00:26:21,702
  1862. But things come pretty
  1863. close to it in nature.
  1864.  
  1865. 426
  1866. 00:26:21,702 --> 00:26:24,394
  1867. It's not actually infinite,
  1868. the coastline of Britain
  1869.  
  1870. 427
  1871. 00:26:24,394 --> 00:26:25,979
  1872. is not actually infinite,
  1873.  
  1874. 428
  1875. 00:26:25,979 --> 00:26:29,437
  1876. but it really resembles
  1877. this sort of shape.
  1878.  
  1879. 429
  1880. 00:26:30,596 --> 00:26:32,100
  1881. So let's see.
  1882.  
  1883. 430
  1884. 00:26:35,359 --> 00:26:38,769
  1885. Yeah, so any questions
  1886. about the Koch curve?
  1887.  
  1888. 431
  1889. 00:26:38,769 --> 00:26:40,821
  1890. It's really interesting.
  1891.  
  1892. 432
  1893. 00:26:41,671 --> 00:26:45,241
  1894. So the next example is
  1895.  
  1896. 433
  1897. 00:26:45,241 --> 00:26:47,896
  1898. the Sierpinski triangle, page eight.
  1899.  
  1900. 434
  1901. 00:26:50,372 --> 00:26:53,811
  1902. So the Sierpinski triangle
  1903. is very interesting.
  1904.  
  1905. 435
  1906. 00:27:02,911 --> 00:27:05,696
  1907. You take a big triangle
  1908.  
  1909. 436
  1910. 00:27:06,987 --> 00:27:10,866
  1911. and you add a smaller triangle
  1912. inside of it like this.
  1913.  
  1914. 437
  1915. 00:27:13,712 --> 00:27:17,792
  1916. So this is the rule for
  1917. the Sierpinski triangle.
  1918.  
  1919. 438
  1920. 00:27:17,792 --> 00:27:21,778
  1921. And you know, this is
  1922. colored in or something.
  1923.  
  1924. 439
  1925. 00:27:23,044 --> 00:27:26,230
  1926. So this is the rule and what
  1927. you get is three new triangles.
  1928.  
  1929. 440
  1930. 00:27:26,230 --> 00:27:30,356
  1931. And then you apply the same
  1932. rule to these new triangles.
  1933.  
  1934. 441
  1935. 00:27:35,386 --> 00:27:38,776
  1936. So that's recursion when you apply a rule
  1937.  
  1938. 442
  1939. 00:27:38,776 --> 00:27:41,494
  1940. to something that you
  1941. already applied a rule to.
  1942.  
  1943. 443
  1944. 00:27:41,494 --> 00:27:45,762
  1945. So you apply it again and you
  1946. get these even smaller things,
  1947.  
  1948. 444
  1949. 00:27:47,576 --> 00:27:50,970
  1950. these smaller triangles,
  1951. and it goes down infinitely
  1952.  
  1953. 445
  1954. 00:27:50,970 --> 00:27:54,068
  1955. if you do it infinitely.
  1956.  
  1957. 446
  1958. 00:27:54,068 --> 00:27:55,667
  1959. So imagine this.
  1960.  
  1961. 447
  1962. 00:27:55,667 --> 00:27:58,033
  1963. So this is one way of computing
  1964. it, one way of doing it,
  1965.  
  1966. 448
  1967. 00:27:58,033 --> 00:28:00,085
  1968. one way of looking at the rule.
  1969.  
  1970. 449
  1971. 00:28:00,085 --> 00:28:04,247
  1972. But what I did in the, if
  1973. you look in the lecture notes
  1974.  
  1975. 450
  1976. 00:28:04,247 --> 00:28:07,667
  1977. I talked about iterated function system.
  1978.  
  1979. 451
  1980. 00:28:08,658 --> 00:28:10,495
  1981. So that means...
  1982.  
  1983. 452
  1984. 00:28:12,849 --> 00:28:14,940
  1985. Oh, I'll just do it and
  1986. you'll see what it means.
  1987.  
  1988. 453
  1989. 00:28:14,940 --> 00:28:16,556
  1990. So let's say we start with a point.
  1991.  
  1992. 454
  1993. 00:28:16,556 --> 00:28:19,553
  1994. Say this point here, it could be any point
  1995.  
  1996. 455
  1997. 00:28:21,614 --> 00:28:23,468
  1998. and we have three possible choices,
  1999.  
  2000. 456
  2001. 00:28:23,468 --> 00:28:25,838
  2002. this is called the chaos game.
  2003.  
  2004. 457
  2005. 00:28:25,838 --> 00:28:27,696
  2006. We have three possible
  2007. choices of something
  2008.  
  2009. 458
  2010. 00:28:27,696 --> 00:28:29,105
  2011. to do with this point.
  2012.  
  2013. 459
  2014. 00:28:29,105 --> 00:28:30,808
  2015. We either bring it halfway to this point,
  2016.  
  2017. 460
  2018. 00:28:30,808 --> 00:28:34,209
  2019. half way to this point or
  2020. half way to this point.
  2021.  
  2022. 461
  2023. 00:28:34,209 --> 00:28:36,606
  2024. So let's say we bring it
  2025. halfway to this point.
  2026.  
  2027. 462
  2028. 00:28:36,606 --> 00:28:39,624
  2029. We go right here, right in the middle.
  2030.  
  2031. 463
  2032. 00:28:39,624 --> 00:28:42,243
  2033. And what we do in an
  2034. iterated function system,
  2035.  
  2036. 464
  2037. 00:28:42,243 --> 00:28:44,506
  2038. we do this over and over and over again,
  2039.  
  2040. 465
  2041. 00:28:44,506 --> 00:28:47,038
  2042. picking randomly which
  2043. one of the three points
  2044.  
  2045. 466
  2046. 00:28:47,038 --> 00:28:49,537
  2047. we go half way towards.
  2048.  
  2049. 467
  2050. 00:28:49,537 --> 00:28:52,763
  2051. So let's say we go to this
  2052. one next, we go here half way.
  2053.  
  2054. 468
  2055. 00:28:52,763 --> 00:28:54,525
  2056. And we go half way to this one.
  2057.  
  2058. 469
  2059. 00:28:54,525 --> 00:28:55,826
  2060. Half way to this one again,
  2061.  
  2062. 470
  2063. 00:28:55,826 --> 00:28:57,330
  2064. half way to this one again.
  2065.  
  2066. 471
  2067. 00:28:57,330 --> 00:28:59,971
  2068. And then half way to this one.
  2069.  
  2070. 472
  2071. 00:28:59,971 --> 00:29:02,954
  2072. And then half way to this one.
  2073.  
  2074. 473
  2075. 00:29:02,954 --> 00:29:05,313
  2076. Half way to this one and
  2077. half way to this one,
  2078.  
  2079. 474
  2080. 00:29:05,313 --> 00:29:08,722
  2081. half way to this one,
  2082. half way to this one.
  2083.  
  2084. 475
  2085. 00:29:08,722 --> 00:29:10,794
  2086. So we just plot these points
  2087.  
  2088. 476
  2089. 00:29:10,794 --> 00:29:14,545
  2090. and the program that I wrote,
  2091.  
  2092. 477
  2093. 00:29:14,545 --> 00:29:16,988
  2094. which is in the handout does this.
  2095.  
  2096. 478
  2097. 00:29:16,988 --> 00:29:19,421
  2098. It executes this.
  2099.  
  2100. 479
  2101. 00:29:19,421 --> 00:29:22,741
  2102. It just keeps going and it
  2103. keeps plotting the points.
  2104.  
  2105. 480
  2106. 00:29:22,741 --> 00:29:26,843
  2107. And eventually, what you get
  2108. is the Sierpinski triangle.
  2109.  
  2110. 481
  2111. 00:29:26,843 --> 00:29:28,209
  2112. It's crazy.
  2113.  
  2114. 482
  2115. 00:29:29,386 --> 00:29:31,556
  2116. So page eight is the...
  2117.  
  2118. 483
  2119. 00:29:32,557 --> 00:29:34,670
  2120. The picture of this is
  2121. on page eight, right?
  2122.  
  2123. 484
  2124. 00:29:34,670 --> 00:29:35,663
  2125. Yeah?
  2126.  
  2127. 485
  2128. 00:29:35,663 --> 00:29:37,025
  2129. - [Male student] So
  2130. when you do it randomly,
  2131.  
  2132. 486
  2133. 00:29:37,025 --> 00:29:39,621
  2134. it doesn't matter which one you choose?
  2135.  
  2136. 487
  2137. 00:29:39,621 --> 00:29:41,186
  2138. No matter what you choose whenever you do
  2139.  
  2140. 488
  2141. 00:29:41,186 --> 00:29:43,934
  2142. (distant indistinct muttering)
  2143.  
  2144. 489
  2145. 00:29:48,393 --> 00:29:49,862
  2146. but now this time since it's random,
  2147.  
  2148. 490
  2149. 00:29:49,862 --> 00:29:52,189
  2150. we're gonna have like
  2151. (distant indistinct muttering)
  2152.  
  2153. 491
  2154. 00:29:52,189 --> 00:29:53,670
  2155. still gonna make the same triangle?
  2156.  
  2157. 492
  2158. 00:29:53,670 --> 00:29:55,372
  2159. - Yeah, exactly.
  2160.  
  2161. 493
  2162. 00:29:55,372 --> 00:29:57,619
  2163. So he's getting at,
  2164.  
  2165. 494
  2166. 00:29:58,660 --> 00:29:59,999
  2167. say you run the program again,
  2168.  
  2169. 495
  2170. 00:29:59,999 --> 00:30:01,917
  2171. it's gonna choose differently.
  2172.  
  2173. 496
  2174. 00:30:01,917 --> 00:30:03,641
  2175. Maybe it'll choose instead
  2176. of going to this one first,
  2177.  
  2178. 497
  2179. 00:30:03,641 --> 00:30:05,579
  2180. it'll go to this one first.
  2181.  
  2182. 498
  2183. 00:30:05,579 --> 00:30:10,018
  2184. Say it does it 10 times
  2185. or 100 times to this one.
  2186.  
  2187. 499
  2188. 00:30:10,018 --> 00:30:13,225
  2189. But the program chooses
  2190. randomly which one to go to.
  2191.  
  2192. 500
  2193. 00:30:16,226 --> 00:30:18,487
  2194. And it goes to this one
  2195. and just chooses randomly.
  2196.  
  2197. 501
  2198. 00:30:18,487 --> 00:30:20,606
  2199. So he asked even though it's random,
  2200.  
  2201. 502
  2202. 00:30:20,606 --> 00:30:22,295
  2203. will it still generate the same picture?
  2204.  
  2205. 503
  2206. 00:30:22,295 --> 00:30:24,980
  2207. And the answer is yes, it will.
  2208.  
  2209. 504
  2210. 00:30:24,980 --> 00:30:26,925
  2211. It's crazy, like just fascinating.
  2212.  
  2213. 505
  2214. 00:30:28,521 --> 00:30:30,245
  2215. And we'll understand this better
  2216.  
  2217. 506
  2218. 00:30:30,245 --> 00:30:33,167
  2219. after we do the next example,
  2220. which is making a fern,
  2221.  
  2222. 507
  2223. 00:30:33,167 --> 00:30:35,826
  2224. a fractal fern, which is really cool.
  2225.  
  2226. 508
  2227. 00:30:36,885 --> 00:30:40,175
  2228. So let's just look at the code quickly
  2229.  
  2230. 509
  2231. 00:30:42,131 --> 00:30:43,174
  2232. and think about this.
  2233.  
  2234. 510
  2235. 00:30:43,174 --> 00:30:45,570
  2236. Is the code for the
  2237. Sierpinski triangle recursive?
  2238.  
  2239. 511
  2240. 00:30:47,082 --> 00:30:49,630
  2241. So what it does is
  2242.  
  2243. 512
  2244. 00:30:49,630 --> 00:30:51,098
  2245. see def, draw Sierpinski,
  2246.  
  2247. 513
  2248. 00:30:51,098 --> 00:30:53,732
  2249. that's the thing that draws the triangle.
  2250.  
  2251. 514
  2252. 00:30:53,732 --> 00:30:56,994
  2253. Def a, b and c are these three points.
  2254.  
  2255. 515
  2256. 00:30:56,994 --> 00:30:59,165
  2257. So this is like a, b, c.
  2258.  
  2259. 516
  2260. 00:31:06,569 --> 00:31:09,427
  2261. Def points equals a list of a, b and c.
  2262.  
  2263. 517
  2264. 00:31:10,537 --> 00:31:14,337
  2265. Current point is just, you
  2266. know, say start at point a.
  2267.  
  2268. 518
  2269. 00:31:17,894 --> 00:31:20,140
  2270. This statement, while true,
  2271.  
  2272. 519
  2273. 00:31:21,387 --> 00:31:24,325
  2274. means execute this code repeatedly.
  2275.  
  2276. 520
  2277. 00:31:24,325 --> 00:31:26,124
  2278. Just keep doing it an
  2279. infinite number of times
  2280.  
  2281. 521
  2282. 00:31:26,124 --> 00:31:29,025
  2283. until you stop the program.
  2284.  
  2285. 522
  2286. 00:31:29,025 --> 00:31:32,794
  2287. So it says def next point
  2288. equals pick from points,
  2289.  
  2290. 523
  2291. 00:31:32,794 --> 00:31:34,938
  2292. and pick from is a function defined above,
  2293.  
  2294. 524
  2295. 00:31:34,938 --> 00:31:37,596
  2296. which pretty much picks
  2297. at random out of the list
  2298.  
  2299. 525
  2300. 00:31:37,596 --> 00:31:39,380
  2301. that you give it.
  2302.  
  2303. 526
  2304. 00:31:39,380 --> 00:31:42,528
  2305. So that pick from is the
  2306. thing that picks randomly
  2307.  
  2308. 527
  2309. 00:31:42,528 --> 00:31:45,137
  2310. which one of these to go to.
  2311.  
  2312. 528
  2313. 00:31:45,137 --> 00:31:47,484
  2314. So it says okay, next
  2315. point, pick from points.
  2316.  
  2317. 529
  2318. 00:31:47,484 --> 00:31:49,619
  2319. So that gives you a point
  2320.  
  2321. 530
  2322. 00:31:49,619 --> 00:31:52,229
  2323. and then current point
  2324. x equals current point x
  2325.  
  2326. 531
  2327. 00:31:52,229 --> 00:31:54,366
  2328. plus next point x divided by two.
  2329.  
  2330. 532
  2331. 00:31:54,366 --> 00:31:56,558
  2332. So what you're doing is averaging
  2333.  
  2334. 533
  2335. 00:31:56,558 --> 00:31:59,172
  2336. the x coordinates of the current point
  2337.  
  2338. 534
  2339. 00:31:59,172 --> 00:32:01,528
  2340. and the point that you're
  2341. going to go to next.
  2342.  
  2343. 535
  2344. 00:32:01,528 --> 00:32:03,143
  2345. And if you do that for x and y,
  2346.  
  2347. 536
  2348. 00:32:03,143 --> 00:32:05,581
  2349. what you do is go, that's going halfway
  2350.  
  2351. 537
  2352. 00:32:05,581 --> 00:32:08,130
  2353. between the current
  2354. point and the next point.
  2355.  
  2356. 538
  2357. 00:32:09,674 --> 00:32:11,259
  2358. That's what that does.
  2359.  
  2360. 539
  2361. 00:32:11,259 --> 00:32:13,927
  2362. An image dot fill pixel at that point.
  2363.  
  2364. 540
  2365. 00:32:13,927 --> 00:32:16,971
  2366. So that's what plots it on the screen.
  2367.  
  2368. 541
  2369. 00:32:16,971 --> 00:32:19,089
  2370. And the picture here is actually,
  2371.  
  2372. 542
  2373. 00:32:19,089 --> 00:32:22,847
  2374. what's actually generated
  2375. by this very program.
  2376.  
  2377. 543
  2378. 00:32:24,347 --> 00:32:26,300
  2379. So it keeps going, keeps plotting it.
  2380.  
  2381. 544
  2382. 00:32:26,300 --> 00:32:28,418
  2383. So here's the question, is this recursive?
  2384.  
  2385. 545
  2386. 00:32:28,418 --> 00:32:30,566
  2387. Is this thing actually recursive?
  2388.  
  2389. 546
  2390. 00:32:30,566 --> 00:32:32,510
  2391. Because we said a recursive function
  2392.  
  2393. 547
  2394. 00:32:32,510 --> 00:32:34,873
  2395. is a function that calls itself.
  2396.  
  2397. 548
  2398. 00:32:34,873 --> 00:32:37,123
  2399. Let's hold off on that answer
  2400.  
  2401. 549
  2402. 00:32:37,123 --> 00:32:38,984
  2403. until after we do the next one.
  2404.  
  2405. 550
  2406. 00:32:38,984 --> 00:32:41,440
  2407. Any questions so far?
  2408.  
  2409. 551
  2410. 00:32:41,440 --> 00:32:43,890
  2411. So the next thing we're
  2412. gonna do is the fern.
  2413.  
  2414. 552
  2415. 00:32:43,890 --> 00:32:45,304
  2416. Yeah?
  2417.  
  2418. 553
  2419. 00:32:45,304 --> 00:32:48,532
  2420. (distant indistinct muttering)
  2421.  
  2422. 554
  2423. 00:32:48,532 --> 00:32:50,387
  2424. So recursion is...
  2425.  
  2426. 555
  2427. 00:32:52,403 --> 00:32:55,471
  2428. Generally, recursion is
  2429. something which is defined
  2430.  
  2431. 556
  2432. 00:32:55,471 --> 00:32:57,696
  2433. in terms of itself.
  2434.  
  2435. 557
  2436. 00:32:59,927 --> 00:33:03,698
  2437. Something that loops back on itself.
  2438.  
  2439. 558
  2440. 00:33:03,698 --> 00:33:05,853
  2441. (distant indistinct muttering)
  2442.  
  2443. 559
  2444. 00:33:07,138 --> 00:33:08,131
  2445. Say again?
  2446.  
  2447. 560
  2448. 00:33:08,131 --> 00:33:10,400
  2449. - [Female student] Like
  2450. if you apply that rule,
  2451.  
  2452. 561
  2453. 00:33:10,400 --> 00:33:12,194
  2454. it'll become the same
  2455. thing you started with?
  2456.  
  2457. 562
  2458. 00:33:12,194 --> 00:33:13,355
  2459. - If you apply which rule?
  2460.  
  2461. 563
  2462. 00:33:13,355 --> 00:33:14,897
  2463. The recursive rule?
  2464. - [Female student] Yeah.
  2465.  
  2466. 564
  2467. 00:33:14,897 --> 00:33:18,182
  2468. - It'll become the same
  2469. that it started with?
  2470.  
  2471. 565
  2472. 00:33:18,182 --> 00:33:22,059
  2473. No, not necessarily because
  2474. each time it applies the rule,
  2475.  
  2476. 566
  2477. 00:33:23,895 --> 00:33:25,956
  2478. there's a slight change.
  2479.  
  2480. 567
  2481. 00:33:25,956 --> 00:33:29,897
  2482. With this factorial, it's
  2483. not just saying n factorial
  2484.  
  2485. 568
  2486. 00:33:29,897 --> 00:33:31,693
  2487. equals n factorial.
  2488.  
  2489. 569
  2490. 00:33:31,693 --> 00:33:34,659
  2491. It's saying n factorial
  2492. equals n minus one factorial.
  2493.  
  2494. 570
  2495. 00:33:36,971 --> 00:33:38,556
  2496. The factorial part is recursive,
  2497.  
  2498. 571
  2499. 00:33:38,556 --> 00:33:41,529
  2500. but it doesn't loop
  2501. back on itself exactly.
  2502.  
  2503. 572
  2504. 00:33:41,529 --> 00:33:43,889
  2505. There's some change.
  2506.  
  2507. 573
  2508. 00:33:43,889 --> 00:33:47,638
  2509. And with recursive functions at least...
  2510.  
  2511. 574
  2512. 00:33:49,821 --> 00:33:53,159
  2513. So the function is
  2514. defined, it calls itself.
  2515.  
  2516. 575
  2517. 00:33:53,159 --> 00:33:56,115
  2518. I don't know if this really
  2519. answers your question but
  2520.  
  2521. 576
  2522. 00:33:56,115 --> 00:33:58,310
  2523. say if we didn't have these parts,
  2524.  
  2525. 577
  2526. 00:33:58,310 --> 00:34:00,181
  2527. if the function just was this,
  2528.  
  2529. 578
  2530. 00:34:00,181 --> 00:34:03,623
  2531. if def Fibonachi, return
  2532. Fibonacci of n minus one,
  2533.  
  2534. 579
  2535. 00:34:03,623 --> 00:34:06,711
  2536. n minus two, what would
  2537. happen is it would call itself
  2538.  
  2539. 580
  2540. 00:34:08,545 --> 00:34:10,894
  2541. and just keep going infinitely,
  2542.  
  2543. 581
  2544. 00:34:10,894 --> 00:34:12,958
  2545. which is a problem.
  2546.  
  2547. 582
  2548. 00:34:12,958 --> 00:34:16,805
  2549. So all recursive functions,
  2550. in order to do anything,
  2551.  
  2552. 583
  2553. 00:34:16,805 --> 00:34:18,570
  2554. have to bottom out at some
  2555. point, they have to stop.
  2556.  
  2557. 584
  2558. 00:34:18,570 --> 00:34:20,618
  2559. And that's what this is.
  2560.  
  2561. 585
  2562. 00:34:20,618 --> 00:34:23,063
  2563. Only do this if n is greater than one.
  2564.  
  2565. 586
  2566. 00:34:23,063 --> 00:34:25,638
  2567. If n is less than or equal to one, return.
  2568.  
  2569. 587
  2570. 00:34:27,103 --> 00:34:29,165
  2571. So it just stops it.
  2572.  
  2573. 588
  2574. 00:34:29,165 --> 00:34:32,656
  2575. So I mean, does it answer your question?
  2576.  
  2577. 589
  2578. 00:34:34,691 --> 00:34:37,146
  2579. You can ask it again if you want.
  2580.  
  2581. 590
  2582. 00:34:38,079 --> 00:34:40,471
  2583. - [Female student] So from the trianble b
  2584.  
  2585. 591
  2586. 00:34:40,471 --> 00:34:43,510
  2587. (distant indistinct muttering)
  2588.  
  2589. 592
  2590. 00:34:43,510 --> 00:34:45,383
  2591. - It is yeah.
  2592.  
  2593. 593
  2594. 00:34:45,383 --> 00:34:47,525
  2595. - [Female student] Because it
  2596. has to return to some place
  2597.  
  2598. 594
  2599. 00:34:47,525 --> 00:34:50,416
  2600. (distant indistinct muttering)
  2601.  
  2602. 595
  2603. 00:34:52,309 --> 00:34:55,331
  2604. - Only functions, computer functions
  2605.  
  2606. 596
  2607. 00:34:55,331 --> 00:34:57,901
  2608. that are recursive need to bottom out.
  2609.  
  2610. 597
  2611. 00:34:57,901 --> 00:35:01,562
  2612. There are other kinds of recursion.
  2613.  
  2614. 598
  2615. 00:35:01,562 --> 00:35:03,504
  2616. - [Female student] Natural recursions?
  2617.  
  2618. 599
  2619. 00:35:03,504 --> 00:35:04,791
  2620. - Well, they do.
  2621.  
  2622. 600
  2623. 00:35:04,791 --> 00:35:07,115
  2624. Like natural recursions don't bottom out.
  2625.  
  2626. 601
  2627. 00:35:07,115 --> 00:35:09,591
  2628. Well, they do have to
  2629. bottom out eventually.
  2630.  
  2631. 602
  2632. 00:35:09,591 --> 00:35:11,764
  2633. Take for example a tree in nature.
  2634.  
  2635. 603
  2636. 00:35:11,764 --> 00:35:13,328
  2637. It branches and branches and branches,
  2638.  
  2639. 604
  2640. 00:35:13,328 --> 00:35:15,261
  2641. but eventually it just gets to a leaf
  2642.  
  2643. 605
  2644. 00:35:15,261 --> 00:35:16,720
  2645. and it stops branching.
  2646.  
  2647. 606
  2648. 00:35:16,720 --> 00:35:18,540
  2649. There's some sort of program
  2650.  
  2651. 607
  2652. 00:35:18,540 --> 00:35:22,346
  2653. that's executing inside of
  2654. this tree that's recursive
  2655.  
  2656. 608
  2657. 00:35:22,346 --> 00:35:26,026
  2658. and there's a certain signal
  2659. that this program gets
  2660.  
  2661. 609
  2662. 00:35:26,026 --> 00:35:28,316
  2663. when the branch gets to
  2664. a certain size I think
  2665.  
  2666. 610
  2667. 00:35:28,316 --> 00:35:31,393
  2668. or something, that signals
  2669. it to generate a leaf.
  2670.  
  2671. 611
  2672. 00:35:31,393 --> 00:35:35,589
  2673. So I mean, those kind of
  2674. recursive processes do bottom out.
  2675.  
  2676. 612
  2677. 00:35:35,589 --> 00:35:37,463
  2678. But this one is actually recursive.
  2679.  
  2680. 613
  2681. 00:35:37,463 --> 00:35:38,922
  2682. We'll see why in a minute,
  2683.  
  2684. 614
  2685. 00:35:38,922 --> 00:35:40,244
  2686. but it doesn't bottom out
  2687.  
  2688. 615
  2689. 00:35:40,244 --> 00:35:42,872
  2690. because it just keeps going forever.
  2691.  
  2692. 616
  2693. 00:35:42,872 --> 00:35:45,544
  2694. - [Male student] Do you mean
  2695. that when you have like,
  2696.  
  2697. 617
  2698. 00:35:45,544 --> 00:35:48,567
  2699. when you're doing (distant
  2700. indistinct muttering)
  2701.  
  2702. 618
  2703. 00:36:09,066 --> 00:36:10,868
  2704. - Yeah, exactly, exactly.
  2705.  
  2706. 619
  2707. 00:36:10,868 --> 00:36:12,805
  2708. That was very well put.
  2709.  
  2710. 620
  2711. 00:36:12,805 --> 00:36:15,572
  2712. So what he's basically
  2713. was if you want to get
  2714.  
  2715. 621
  2716. 00:36:15,572 --> 00:36:19,538
  2717. any real manifestation of recursion,
  2718.  
  2719. 622
  2720. 00:36:19,538 --> 00:36:22,526
  2721. it has to bottom out in order
  2722. to return to you the result.
  2723.  
  2724. 623
  2725. 00:36:22,526 --> 00:36:24,630
  2726. But yeah, you can imagine
  2727. theoretical worlds
  2728.  
  2729. 624
  2730. 00:36:24,630 --> 00:36:26,806
  2731. where it doesn't bottom out.
  2732.  
  2733. 625
  2734. 00:36:26,806 --> 00:36:28,333
  2735. It goes on forever.
  2736.  
  2737. 626
  2738. 00:36:28,333 --> 00:36:30,722
  2739. Actually, Douglas
  2740. Hofstadter in the dialogue
  2741.  
  2742. 627
  2743. 00:36:30,722 --> 00:36:33,073
  2744. before this chapter does that.
  2745.  
  2746. 628
  2747. 00:36:33,073 --> 00:36:35,885
  2748. A genie has to ask a meta
  2749. genie, has to ask a meta genie.
  2750.  
  2751. 629
  2752. 00:36:35,885 --> 00:36:37,374
  2753. Did anybody read that?
  2754.  
  2755. 630
  2756. 00:36:37,374 --> 00:36:39,750
  2757. (distant indistinct muttering)
  2758.  
  2759. 631
  2760. 00:36:41,619 --> 00:36:43,703
  2761. Yeah, the time is smaller and smaller.
  2762.  
  2763. 632
  2764. 00:36:43,703 --> 00:36:46,638
  2765. So like eventually, you just repeat
  2766.  
  2767. 633
  2768. 00:36:46,638 --> 00:36:48,724
  2769. an infinite number of intensely small...
  2770.  
  2771. 634
  2772. 00:36:48,724 --> 00:36:50,835
  2773. (distant indistinct muttering)
  2774.  
  2775. 635
  2776. 00:36:50,835 --> 00:36:54,237
  2777. Yeah, yeah, isn't that crazy?
  2778.  
  2779. 636
  2780. 00:36:54,237 --> 00:36:57,780
  2781. Yeah, it's really something
  2782. to think about, yeah.
  2783.  
  2784. 637
  2785. 00:36:57,780 --> 00:36:59,625
  2786. But that's like theoretical
  2787.  
  2788. 638
  2789. 00:36:59,625 --> 00:37:03,050
  2790. but it is very interesting to think about.
  2791.  
  2792. 639
  2793. 00:37:03,050 --> 00:37:05,762
  2794. So we'll see how this is
  2795. recursive after we do the fern.
  2796.  
  2797. 640
  2798. 00:37:05,762 --> 00:37:09,002
  2799. So the fractal fern is next, page nine.
  2800.  
  2801. 641
  2802. 00:37:11,735 --> 00:37:14,708
  2803. Yeah, this is really, really cool.
  2804.  
  2805. 642
  2806. 00:37:26,999 --> 00:37:28,885
  2807. So the fractal fern.
  2808.  
  2809. 643
  2810. 00:37:28,885 --> 00:37:31,356
  2811. It looks beautiful, doesn't it?
  2812.  
  2813. 644
  2814. 00:37:31,356 --> 00:37:34,110
  2815. So we have this triangle.
  2816.  
  2817. 645
  2818. 00:37:38,921 --> 00:37:40,840
  2819. This isn't a picture in the handout.
  2820.  
  2821. 646
  2822. 00:37:40,840 --> 00:37:43,149
  2823. There's an outside triangle that's black
  2824.  
  2825. 647
  2826. 00:37:43,149 --> 00:37:46,306
  2827. and there's an inside triangle that's blue
  2828.  
  2829. 648
  2830. 00:37:46,306 --> 00:37:50,181
  2831. and some other triangles
  2832. that (mumbles) leaves.
  2833.  
  2834. 649
  2835. 00:37:50,181 --> 00:37:51,865
  2836. So first of all, I wanna talk about
  2837.  
  2838. 650
  2839. 00:37:51,865 --> 00:37:54,857
  2840. this notion of a
  2841. coordinate transformation.
  2842.  
  2843. 651
  2844. 00:37:54,857 --> 00:37:56,300
  2845. You have...
  2846.  
  2847. 652
  2848. 00:37:59,267 --> 00:38:01,526
  2849. Say we had a coordinate transformation
  2850.  
  2851. 653
  2852. 00:38:01,526 --> 00:38:05,286
  2853. between this rectangle and this rectangle.
  2854.  
  2855. 654
  2856. 00:38:05,286 --> 00:38:07,891
  2857. What would happen it like
  2858. it's a function on a point,
  2859.  
  2860. 655
  2861. 00:38:07,891 --> 00:38:10,229
  2862. a two-dimensional point.
  2863.  
  2864. 656
  2865. 00:38:10,229 --> 00:38:13,464
  2866. So say you had the point
  2867. right here, this point.
  2868.  
  2869. 657
  2870. 00:38:14,584 --> 00:38:16,976
  2871. You apply this transformation to the point
  2872.  
  2873. 658
  2874. 00:38:16,976 --> 00:38:19,992
  2875. and what you get is this point here.
  2876.  
  2877. 659
  2878. 00:38:21,481 --> 00:38:24,537
  2879. So you have this point here
  2880.  
  2881. 660
  2882. 00:38:24,537 --> 00:38:27,710
  2883. and you apply the
  2884. transformation to that point,
  2885.  
  2886. 661
  2887. 00:38:27,710 --> 00:38:30,578
  2888. you'll get this point here.
  2889.  
  2890. 662
  2891. 00:38:30,578 --> 00:38:34,059
  2892. It's just like a little
  2893. copy of this, okay?
  2894.  
  2895. 663
  2896. 00:38:35,518 --> 00:38:39,924
  2897. So this is a function,
  2898. this is the function part
  2899.  
  2900. 664
  2901. 00:38:39,924 --> 00:38:42,427
  2902. of iterated function systems.
  2903.  
  2904. 665
  2905. 00:38:42,427 --> 00:38:45,554
  2906. Iteration is the fact that
  2907. you just keep doing it,
  2908.  
  2909. 666
  2910. 00:38:45,554 --> 00:38:48,673
  2911. and a system is the fact that
  2912. there's more than one of them.
  2913.  
  2914. 667
  2915. 00:38:48,673 --> 00:38:51,290
  2916. It's like a bunch, in
  2917. this case it's three.
  2918.  
  2919. 668
  2920. 00:38:51,290 --> 00:38:54,014
  2921. I'll talk about it in a minute.
  2922.  
  2923. 669
  2924. 00:38:58,396 --> 00:39:01,363
  2925. With a fractal fern, what we have is
  2926.  
  2927. 670
  2928. 00:39:05,450 --> 00:39:07,434
  2929. a rectangle like this.
  2930.  
  2931. 671
  2932. 00:39:14,311 --> 00:39:17,644
  2933. So this, the fractal fern
  2934.  
  2935. 672
  2936. 00:39:17,644 --> 00:39:20,341
  2937. is an iterated function system
  2938.  
  2939. 673
  2940. 00:39:20,341 --> 00:39:23,486
  2941. that has four possible functions.
  2942.  
  2943. 674
  2944. 00:39:23,486 --> 00:39:25,385
  2945. This one has three.
  2946.  
  2947. 675
  2948. 00:39:25,385 --> 00:39:27,852
  2949. Each one of those points
  2950. is one, it's a function.
  2951.  
  2952. 676
  2953. 00:39:27,852 --> 00:39:30,106
  2954. Going halfway to one of
  2955. those points as a function.
  2956.  
  2957. 677
  2958. 00:39:30,106 --> 00:39:33,442
  2959. But in the fern one,
  2960. there are four functions.
  2961.  
  2962. 678
  2963. 00:39:33,442 --> 00:39:35,953
  2964. This is one of them.
  2965.  
  2966. 679
  2967. 00:39:35,953 --> 00:39:38,771
  2968. And each function is a
  2969. coordinate transformation.
  2970.  
  2971. 680
  2972. 00:39:38,771 --> 00:39:40,544
  2973. This function is a
  2974. coordinate transformation
  2975.  
  2976. 681
  2977. 00:39:40,544 --> 00:39:42,211
  2978. from this outer one.
  2979.  
  2980. 682
  2981. 00:39:42,211 --> 00:39:45,162
  2982. This outer rectangle to
  2983. this inner rectangle.
  2984.  
  2985. 683
  2986. 00:39:45,162 --> 00:39:48,038
  2987. So if we had this point in this rectangle
  2988.  
  2989. 684
  2990. 00:39:48,038 --> 00:39:50,500
  2991. and we applied this transformation,
  2992.  
  2993. 685
  2994. 00:39:50,500 --> 00:39:53,695
  2995. we would get this point here.
  2996.  
  2997. 686
  2998. 00:39:56,221 --> 00:40:00,395
  2999. So say we have the middle
  3000. point of this outer rectangle.
  3001.  
  3002. 687
  3003. 00:40:03,549 --> 00:40:07,315
  3004. And we apply this transformation once.
  3005.  
  3006. 688
  3007. 00:40:07,315 --> 00:40:09,852
  3008. We would get the middle point
  3009. of this inner rectangle,
  3010.  
  3011. 689
  3012. 00:40:09,852 --> 00:40:12,528
  3013. which is about right here.
  3014.  
  3015. 690
  3016. 00:40:14,758 --> 00:40:18,113
  3017. But here, what we do is we say okay,
  3018.  
  3019. 691
  3020. 00:40:18,113 --> 00:40:22,033
  3021. now this new point is actually
  3022. in the outer rectangle,
  3023.  
  3024. 692
  3025. 00:40:22,033 --> 00:40:25,717
  3026. and we'll apply the
  3027. transformation again on that.
  3028.  
  3029. 693
  3030. 00:40:26,655 --> 00:40:29,587
  3031. So this this point in the outer rectangle
  3032.  
  3033. 694
  3034. 00:40:29,587 --> 00:40:33,249
  3035. maps to about this point
  3036. in the smaller rectangle.
  3037.  
  3038. 695
  3039. 00:40:35,009 --> 00:40:38,402
  3040. And then you say okay, this
  3041. point is now a point in this one
  3042.  
  3043. 696
  3044. 00:40:38,402 --> 00:40:41,528
  3045. and you apply it again,
  3046. and you get this point here
  3047.  
  3048. 697
  3049. 00:40:41,528 --> 00:40:44,107
  3050. in this point here, this point here.
  3051.  
  3052. 698
  3053. 00:40:44,107 --> 00:40:46,723
  3054. And like all these points.
  3055.  
  3056. 699
  3057. 00:40:46,723 --> 00:40:50,275
  3058. And eventually, they just
  3059. get smaller and smaller
  3060.  
  3061. 700
  3062. 00:40:50,275 --> 00:40:53,578
  3063. because the corner points
  3064.  
  3065. 701
  3066. 00:40:53,578 --> 00:40:57,754
  3067. of these two rectangles
  3068. are the same point.
  3069.  
  3070. 702
  3071. 00:40:57,754 --> 00:41:00,000
  3072. I think, (mumbles)
  3073.  
  3074. 703
  3075. 00:41:01,300 --> 00:41:04,650
  3076. So let's look at another one.
  3077.  
  3078. 704
  3079. 00:41:04,650 --> 00:41:06,368
  3080. Let's see.
  3081.  
  3082. 705
  3083. 00:41:16,840 --> 00:41:20,821
  3084. So this is the thing that's gonna map to.
  3085.  
  3086. 706
  3087. 00:41:23,060 --> 00:41:26,829
  3088. It's a line, but think
  3089. of it as a rectangle.
  3090.  
  3091. 707
  3092. 00:41:28,128 --> 00:41:30,084
  3093. It's a coordinate transformation.
  3094.  
  3095. 708
  3096. 00:41:30,084 --> 00:41:34,371
  3097. So we go from any point
  3098. in this outer rectangle
  3099.  
  3100. 709
  3101. 00:41:35,641 --> 00:41:37,348
  3102. to a point on here.
  3103.  
  3104. 710
  3105. 00:41:37,348 --> 00:41:41,113
  3106. So say if we have this point
  3107. here in the outer rectangle,
  3108.  
  3109. 711
  3110. 00:41:41,113 --> 00:41:44,129
  3111. it's gonna go to the
  3112. top point of this line.
  3113.  
  3114. 712
  3115. 00:41:44,129 --> 00:41:46,047
  3116. If we have this point here, it's gonna go
  3117.  
  3118. 713
  3119. 00:41:46,047 --> 00:41:47,279
  3120. to the bottom point of this line.
  3121.  
  3122. 714
  3123. 00:41:47,279 --> 00:41:48,469
  3124. If we have the center point,
  3125.  
  3126. 715
  3127. 00:41:48,469 --> 00:41:50,982
  3128. it'll go to the center of this line.
  3129.  
  3130. 716
  3131. 00:41:50,982 --> 00:41:54,692
  3132. So let's imagine an
  3133. iterated function system
  3134.  
  3135. 717
  3136. 00:41:54,692 --> 00:41:56,267
  3137. with only these two functions.
  3138.  
  3139. 718
  3140. 00:41:56,267 --> 00:42:00,371
  3141. What's gonna happen is, and
  3142. let's say each one is chosen,
  3143.  
  3144. 719
  3145. 00:42:01,381 --> 00:42:04,721
  3146. well, let's see, each one is chosen
  3147.  
  3148. 720
  3149. 00:42:04,721 --> 00:42:08,726
  3150. about half the time randomly,
  3151. picked between each one.
  3152.  
  3153. 721
  3154. 00:42:08,726 --> 00:42:11,620
  3155. Or no, let's say that
  3156. it applies this mapping
  3157.  
  3158. 722
  3159. 00:42:11,620 --> 00:42:13,940
  3160. about 90% of the time.
  3161.  
  3162. 723
  3163. 00:42:13,940 --> 00:42:16,471
  3164. So say we start with this point here,
  3165.  
  3166. 724
  3167. 00:42:16,471 --> 00:42:19,833
  3168. it'll map to this point
  3169. here and this point here
  3170.  
  3171. 725
  3172. 00:42:19,833 --> 00:42:23,231
  3173. and it will just go up and up into here
  3174.  
  3175. 726
  3176. 00:42:23,231 --> 00:42:27,561
  3177. as long as this transformation
  3178. is being applied.
  3179.  
  3180. 727
  3181. 00:42:27,561 --> 00:42:31,196
  3182. But say it does that like a hundred times
  3183.  
  3184. 728
  3185. 00:42:31,196 --> 00:42:35,042
  3186. and then one time it goes down to here.
  3187.  
  3188. 729
  3189. 00:42:35,042 --> 00:42:36,507
  3190. So say it's all the way up here
  3191.  
  3192. 730
  3193. 00:42:36,507 --> 00:42:38,605
  3194. and we map to this one,
  3195. it's gonna start here
  3196.  
  3197. 731
  3198. 00:42:38,605 --> 00:42:40,246
  3199. and it's gonna map here and here and here,
  3200.  
  3201. 732
  3202. 00:42:40,246 --> 00:42:41,301
  3203. it's gonna go up.
  3204.  
  3205. 733
  3206. 00:42:41,301 --> 00:42:44,483
  3207. And say we at this point
  3208. the computer decides
  3209.  
  3210. 734
  3211. 00:42:44,483 --> 00:42:46,872
  3212. to map to here.
  3213.  
  3214. 735
  3215. 00:42:46,872 --> 00:42:51,872
  3216. It's about 3/4 up, it's
  3217. gonna go 3/4 up here.
  3218.  
  3219. 736
  3220. 00:42:52,104 --> 00:42:55,274
  3221. So because it's random,
  3222.  
  3223. 737
  3224. 00:42:55,274 --> 00:42:57,892
  3225. if you do this just forever,
  3226.  
  3227. 738
  3228. 00:42:57,892 --> 00:43:00,538
  3229. it's gonna eventually fill
  3230. in pretty much every point
  3231.  
  3232. 739
  3233. 00:43:00,538 --> 00:43:05,190
  3234. on this line, which is very
  3235. interesting to think about.
  3236.  
  3237. 740
  3238. 00:43:05,190 --> 00:43:07,622
  3239. Any questions so far?
  3240.  
  3241. 741
  3242. 00:43:08,599 --> 00:43:11,539
  3243. So let's have this rectangle.
  3244.  
  3245. 742
  3246. 00:43:15,384 --> 00:43:16,888
  3247. All four of the transformations
  3248.  
  3249. 743
  3250. 00:43:16,888 --> 00:43:19,573
  3251. are from the outer
  3252. rectangle, this big one,
  3253.  
  3254. 744
  3255. 00:43:19,573 --> 00:43:23,828
  3256. to one of the ones inside, one
  3257. of the smaller ones inside.
  3258.  
  3259. 745
  3260. 00:43:24,879 --> 00:43:29,588
  3261. So say we have this point up here
  3262.  
  3263. 746
  3264. 00:43:29,588 --> 00:43:32,220
  3265. and we apply this
  3266. transformation to this one.
  3267.  
  3268. 747
  3269. 00:43:32,220 --> 00:43:36,106
  3270. It's gonna go to this point here.
  3271.  
  3272. 748
  3273. 00:43:36,106 --> 00:43:37,634
  3274. Makes sense?
  3275.  
  3276. 749
  3277. 00:43:37,634 --> 00:43:40,873
  3278. And if we have this one, it's
  3279. gonna go to this point here.
  3280.  
  3281. 750
  3282. 00:43:40,873 --> 00:43:45,292
  3283. So the transformation is
  3284. pretty much going like this.
  3285.  
  3286. 751
  3287. 00:43:45,292 --> 00:43:50,292
  3288. So say our IFS, iterated
  3289. function system, has these three.
  3290.  
  3291. 752
  3292. 00:43:51,365 --> 00:43:53,462
  3293. Say we go about halfway up here
  3294.  
  3295. 753
  3296. 00:43:53,462 --> 00:43:55,435
  3297. and we choose to apply this mapping.
  3298.  
  3299. 754
  3300. 00:43:55,435 --> 00:43:58,193
  3301. It's gonna go about here,
  3302. the middle of this one.
  3303.  
  3304. 755
  3305. 00:43:58,193 --> 00:44:01,436
  3306. And then we apply this
  3307. mapping like a bunch of times,
  3308.  
  3309. 756
  3310. 00:44:01,436 --> 00:44:03,672
  3311. just keep going up and up and up.
  3312.  
  3313. 757
  3314. 00:44:03,672 --> 00:44:05,534
  3315. We apply this mapping again,
  3316.  
  3317. 758
  3318. 00:44:05,534 --> 00:44:06,908
  3319. but it's sort of closer
  3320. to the top this time
  3321.  
  3322. 759
  3323. 00:44:06,908 --> 00:44:10,881
  3324. so it's gonna be out here closer to this,
  3325.  
  3326. 760
  3327. 00:44:10,881 --> 00:44:12,452
  3328. the top of this rectangle.
  3329.  
  3330. 761
  3331. 00:44:12,452 --> 00:44:14,842
  3332. And then we apply it
  3333. again and again and again
  3334.  
  3335. 762
  3336. 00:44:14,842 --> 00:44:17,279
  3337. and maybe it only goes up one.
  3338.  
  3339. 763
  3340. 00:44:17,279 --> 00:44:18,725
  3341. So it'll be down here.
  3342.  
  3343. 764
  3344. 00:44:18,725 --> 00:44:22,578
  3345. So eventually, it's gonna fill in
  3346.  
  3347. 765
  3348. 00:44:22,578 --> 00:44:26,010
  3349. this rectangle with this pattern.
  3350.  
  3351. 766
  3352. 00:44:27,415 --> 00:44:29,197
  3353. It's gonna look like this.
  3354.  
  3355. 767
  3356. 00:44:31,084 --> 00:44:32,372
  3357. Okay?
  3358.  
  3359. 768
  3360. 00:44:32,372 --> 00:44:34,949
  3361. And this, since that's,
  3362.  
  3363. 769
  3364. 00:44:34,949 --> 00:44:38,777
  3365. every point in here is
  3366. probably going to get applied
  3367.  
  3368. 770
  3369. 00:44:38,777 --> 00:44:42,568
  3370. to this mapping a bunch of
  3371. times so what we're gonna get is
  3372.  
  3373. 771
  3374. 00:44:44,718 --> 00:44:47,515
  3375. this fern structure.
  3376.  
  3377. 772
  3378. 00:44:52,778 --> 00:44:54,272
  3379. Okay.
  3380.  
  3381. 773
  3382. 00:44:54,272 --> 00:44:56,623
  3383. Isn't that really cool?
  3384.  
  3385. 774
  3386. 00:44:56,623 --> 00:44:59,598
  3387. (distant indistinct muttering)
  3388.  
  3389. 775
  3390. 00:45:09,997 --> 00:45:13,971
  3391. Are you tlaking about the
  3392. Sierpinski triangle or the fern?
  3393.  
  3394. 776
  3395. 00:45:13,971 --> 00:45:15,360
  3396. - [Male student] The fern.
  3397.  
  3398. 777
  3399. 00:45:15,360 --> 00:45:17,936
  3400. (distant indistinct muttering)
  3401.  
  3402. 778
  3403. 00:45:37,071 --> 00:45:39,180
  3404. - Right, you can't actually.
  3405.  
  3406. 779
  3407. 00:45:39,180 --> 00:45:40,590
  3408. And this is...
  3409.  
  3410. 780
  3411. 00:45:41,794 --> 00:45:43,589
  3412. Okay, I'll go through an example.
  3413.  
  3414. 781
  3415. 00:45:43,589 --> 00:45:47,358
  3416. Say we have, instead of just
  3417. applying it to one point,
  3418.  
  3419. 782
  3420. 00:45:48,700 --> 00:45:51,100
  3421. we apply it to a bunch of points.
  3422.  
  3423. 783
  3424. 00:45:51,100 --> 00:45:54,020
  3425. Say all the points on this
  3426. line, or almost all the points.
  3427.  
  3428. 784
  3429. 00:45:57,089 --> 00:46:00,344
  3430. Say we apply this
  3431. mapping a bunch of times.
  3432.  
  3433. 785
  3434. 00:46:00,344 --> 00:46:03,307
  3435. So we get this one, this
  3436. one, this one, this one.
  3437.  
  3438. 786
  3439. 00:46:07,344 --> 00:46:11,882
  3440. And say we apply this mapping
  3441. to all of these points.
  3442.  
  3443. 787
  3444. 00:46:11,882 --> 00:46:14,143
  3445. It's gonna map to here.
  3446.  
  3447. 788
  3448. 00:46:14,143 --> 00:46:16,420
  3449. And then we do that again
  3450. and again and again.
  3451.  
  3452. 789
  3453. 00:46:16,420 --> 00:46:18,609
  3454. And say, and then what we have,
  3455.  
  3456. 790
  3457. 00:46:18,609 --> 00:46:20,958
  3458. say all those points eventually
  3459.  
  3460. 791
  3461. 00:46:20,958 --> 00:46:23,546
  3462. are going to get mapped to this one.
  3463.  
  3464. 792
  3465. 00:46:23,546 --> 00:46:27,747
  3466. So you have a whole little
  3467. copy of this thing in here.
  3468.  
  3469. 793
  3470. 00:46:27,747 --> 00:46:30,481
  3471. So you have these little branches.
  3472.  
  3473. 794
  3474. 00:46:32,531 --> 00:46:34,794
  3475. And then that is gonna be mapped up here
  3476.  
  3477. 795
  3478. 00:46:34,794 --> 00:46:37,339
  3479. and then it branches, branches, branches.
  3480.  
  3481. 796
  3482. 00:46:37,339 --> 00:46:42,184
  3483. And then since you have
  3484. the smaller branches here,
  3485.  
  3486. 797
  3487. 00:46:42,184 --> 00:46:43,736
  3488. you have two levels down.
  3489.  
  3490. 798
  3491. 00:46:43,736 --> 00:46:46,948
  3492. And then this whole thing
  3493. gets mapped back onto here
  3494.  
  3495. 799
  3496. 00:46:46,948 --> 00:46:49,550
  3497. including the new branches.
  3498.  
  3499. 800
  3500. 00:46:49,550 --> 00:46:52,646
  3501. And it gets filled in as it goes on.
  3502.  
  3503. 801
  3504. 00:46:54,959 --> 00:46:59,515
  3505. But it doesn't just keep going
  3506. up to here and just like,
  3507.  
  3508. 802
  3509. 00:47:00,938 --> 00:47:03,200
  3510. say we were to apply this
  3511. mapping 100% of the time,
  3512.  
  3513. 803
  3514. 00:47:03,200 --> 00:47:05,741
  3515. it would just go up here
  3516. and go nowhere else.
  3517.  
  3518. 804
  3519. 00:47:05,741 --> 00:47:09,519
  3520. But say we apply this
  3521. mapping like 7% of the time,
  3522.  
  3523. 805
  3524. 00:47:09,519 --> 00:47:11,916
  3525. it'll go up different lengths and then
  3526.  
  3527. 806
  3528. 00:47:13,213 --> 00:47:16,587
  3529. it will map back down there
  3530. and go up, map back down.
  3531.  
  3532. 807
  3533. 00:47:16,587 --> 00:47:20,942
  3534. And then if we add this transformation,
  3535.  
  3536. 808
  3537. 00:47:20,942 --> 00:47:23,181
  3538. going from this one to this one,
  3539.  
  3540. 809
  3541. 00:47:23,181 --> 00:47:27,516
  3542. we have this and it's recursive.
  3543.  
  3544. 810
  3545. 00:47:27,516 --> 00:47:31,016
  3546. The reason why it's recursive
  3547. is because the mappings
  3548.  
  3549. 811
  3550. 00:47:31,016 --> 00:47:34,896
  3551. map onto themselves eventually.
  3552.  
  3553. 812
  3554. 00:47:34,896 --> 00:47:37,000
  3555. If we look at the code,
  3556. it's really similar
  3557.  
  3558. 813
  3559. 00:47:37,000 --> 00:47:40,885
  3560. to the Sierpinski triangle code.
  3561.  
  3562. 814
  3563. 00:47:40,885 --> 00:47:45,045
  3564. The code itself is not
  3565. recursive, but the mappings are.
  3566.  
  3567. 815
  3568. 00:47:45,045 --> 00:47:48,392
  3569. And that's what makes this
  3570. whole thing recursive.
  3571.  
  3572. 816
  3573. 00:47:52,339 --> 00:47:55,737
  3574. So yeah, let's just look
  3575. at the code a little bit.
  3576.  
  3577. 817
  3578. 00:47:55,737 --> 00:47:57,816
  3579. Class fern.
  3580.  
  3581. 818
  3582. 00:47:57,816 --> 00:48:00,864
  3583. So draw fern.
  3584.  
  3585. 819
  3586. 00:48:00,864 --> 00:48:03,562
  3587. While true, so that means execute this,
  3588.  
  3589. 820
  3590. 00:48:03,562 --> 00:48:06,136
  3591. just keep doing it over and over and over,
  3592.  
  3593. 821
  3594. 00:48:06,136 --> 00:48:10,680
  3595. pick from these list of transformations.
  3596.  
  3597. 822
  3598. 00:48:10,680 --> 00:48:13,197
  3599. So the first one says maps to the stem.
  3600.  
  3601. 823
  3602. 00:48:13,197 --> 00:48:17,050
  3603. That means it goes from
  3604. here to here, to the stem.
  3605.  
  3606. 824
  3607. 00:48:17,050 --> 00:48:19,558
  3608. The second one maps to the left branch,
  3609.  
  3610. 825
  3611. 00:48:19,558 --> 00:48:22,611
  3612. meaning it goes from here to this one.
  3613.  
  3614. 826
  3615. 00:48:22,611 --> 00:48:25,337
  3616. The third one maps to the
  3617. right branch, goes down here.
  3618.  
  3619. 827
  3620. 00:48:25,337 --> 00:48:27,867
  3621. And the fourth one maps from here to here,
  3622.  
  3623. 828
  3624. 00:48:27,867 --> 00:48:30,105
  3625. just goes up and up like that.
  3626.  
  3627. 829
  3628. 00:48:31,050 --> 00:48:34,419
  3629. And following that, just
  3630. pick from a list of functions
  3631.  
  3632. 830
  3633. 00:48:36,104 --> 00:48:38,667
  3634. and then a list of probabilities.
  3635.  
  3636. 831
  3637. 00:48:38,667 --> 00:48:41,186
  3638. It says .01, .07, .07 .85.
  3639.  
  3640. 832
  3641. 00:48:42,340 --> 00:48:45,864
  3642. So these are the probabilities at which
  3643.  
  3644. 833
  3645. 00:48:45,864 --> 00:48:48,654
  3646. these mapping functions
  3647. are gonna be chosen.
  3648.  
  3649. 834
  3650. 00:48:48,654 --> 00:48:50,819
  3651. If you choose them all equally,
  3652.  
  3653. 835
  3654. 00:48:50,819 --> 00:48:54,402
  3655. then the chances are very
  3656. low that this mapping
  3657.  
  3658. 836
  3659. 00:48:55,476 --> 00:48:58,478
  3660. is going to occur more than
  3661. like five times or something.
  3662.  
  3663. 837
  3664. 00:48:58,478 --> 00:49:00,715
  3665. So we just go up here and get map.
  3666.  
  3667. 838
  3668. 00:49:00,715 --> 00:49:03,280
  3669. So it'd be a very sparse fractal.
  3670.  
  3671. 839
  3672. 00:49:03,280 --> 00:49:06,485
  3673. Most of the points
  3674. would be like down here.
  3675.  
  3676. 840
  3677. 00:49:06,485 --> 00:49:08,120
  3678. It just didn't look very good, I tried it.
  3679.  
  3680. 841
  3681. 00:49:08,120 --> 00:49:11,519
  3682. I wish I could like code it and show you.
  3683.  
  3684. 842
  3685. 00:49:12,949 --> 00:49:16,156
  3686. So the .01 means that
  3687. the mapping to the stem
  3688.  
  3689. 843
  3690. 00:49:16,156 --> 00:49:18,680
  3691. happens 1% of the time.
  3692.  
  3693. 844
  3694. 00:49:18,680 --> 00:49:20,243
  3695. The mapping to each of the branches
  3696.  
  3697. 845
  3698. 00:49:20,243 --> 00:49:21,719
  3699. happens 7% of the time.
  3700.  
  3701. 846
  3702. 00:49:21,719 --> 00:49:23,769
  3703. And the mapping up and spiraling
  3704.  
  3705. 847
  3706. 00:49:23,769 --> 00:49:26,321
  3707. happens 85% of the time.
  3708.  
  3709. 848
  3710. 00:49:28,939 --> 00:49:32,220
  3711. So I'm gonna take a
  3712. break now for 10 minutes.
  3713.  
  3714. 849
  3715. 00:49:33,573 --> 00:49:35,811
  3716. Anybody have any questions?
  3717.  
  3718. 850
  3719. 00:49:38,233 --> 00:49:40,268
  3720. So I guess we'll start up again.
  3721.  
  3722. 851
  3723. 00:49:43,003 --> 00:49:45,804
  3724. Before we leave these
  3725. iterated function system,
  3726.  
  3727. 852
  3728. 00:49:45,804 --> 00:49:48,748
  3729. I wanna point out how
  3730. the Sierpinski triangles
  3731.  
  3732. 853
  3733. 00:49:49,635 --> 00:49:52,758
  3734. is pretty much the same thing as the ferns
  3735.  
  3736. 854
  3737. 00:49:52,758 --> 00:49:54,924
  3738. in terms of mappings.
  3739.  
  3740. 855
  3741. 00:50:05,870 --> 00:50:09,515
  3742. With a Sierpinski triangle,
  3743. we have these three mappings.
  3744.  
  3745. 856
  3746. 00:50:09,515 --> 00:50:13,156
  3747. One of them maps from this triangle
  3748.  
  3749. 857
  3750. 00:50:13,156 --> 00:50:16,462
  3751. to this triangle here.
  3752.  
  3753. 858
  3754. 00:50:18,673 --> 00:50:21,442
  3755. One of them maps from the
  3756. big triangle to this triangle
  3757.  
  3758. 859
  3759. 00:50:21,442 --> 00:50:25,126
  3760. and the other one maps from
  3761. this triangle to this triangle.
  3762.  
  3763. 860
  3764. 00:50:25,126 --> 00:50:29,254
  3765. And each one of them are
  3766. applied with equal probability.
  3767.  
  3768. 861
  3769. 00:50:29,254 --> 00:50:32,644
  3770. So if you think about it, going half way
  3771.  
  3772. 862
  3773. 00:50:32,644 --> 00:50:35,651
  3774. from any of these points
  3775. to one of the other points
  3776.  
  3777. 863
  3778. 00:50:35,651 --> 00:50:39,222
  3779. is essentially mapping it down.
  3780.  
  3781. 864
  3782. 00:50:39,222 --> 00:50:42,492
  3783. So say you have this one, this line,
  3784.  
  3785. 865
  3786. 00:50:43,603 --> 00:50:46,989
  3787. you apply the function
  3788. to all these points.
  3789.  
  3790. 866
  3791. 00:50:46,989 --> 00:50:50,517
  3792. What it does is maps it
  3793. down to that triangle.
  3794.  
  3795. 867
  3796. 00:50:52,692 --> 00:50:55,659
  3797. So you can see these triangles
  3798.  
  3799. 868
  3800. 00:50:55,659 --> 00:50:58,957
  3801. map onto themselves recursively,
  3802.  
  3803. 869
  3804. 00:51:00,217 --> 00:51:02,510
  3805. and that's why it actually is,
  3806.  
  3807. 870
  3808. 00:51:02,510 --> 00:51:04,317
  3809. there is a recursion going on here
  3810.  
  3811. 871
  3812. 00:51:04,317 --> 00:51:05,722
  3813. but it's not in the code itself.
  3814.  
  3815. 872
  3816. 00:51:05,722 --> 00:51:07,526
  3817. The code itself is just repetitive,
  3818.  
  3819. 873
  3820. 00:51:07,526 --> 00:51:08,963
  3821. but what it's repeating
  3822.  
  3823. 874
  3824. 00:51:08,963 --> 00:51:12,531
  3825. is these recursive
  3826. mappings onto themselves.
  3827.  
  3828. 875
  3829. 00:51:12,531 --> 00:51:14,554
  3830. Yeah?
  3831. (distant indistinct muttering)
  3832.  
  3833. 876
  3834. 00:51:16,987 --> 00:51:21,754
  3835. There's always more than one
  3836. way to represent an algorithm.
  3837.  
  3838. 877
  3839. 00:51:21,754 --> 00:51:23,881
  3840. Yeah, it's really fascinating,
  3841.  
  3842. 878
  3843. 00:51:23,881 --> 00:51:26,361
  3844. especially with these fractals and things.
  3845.  
  3846. 879
  3847. 00:51:26,361 --> 00:51:30,397
  3848. It seems like there's
  3849. always another way to do it,
  3850.  
  3851. 880
  3852. 00:51:30,397 --> 00:51:32,113
  3853. to achieve the same result.
  3854.  
  3855. 881
  3856. 00:51:32,113 --> 00:51:34,801
  3857. And that's one thing,
  3858. especially Sierpinski triangle,
  3859.  
  3860. 882
  3861. 00:51:34,801 --> 00:51:36,582
  3862. it's really amazing.
  3863.  
  3864. 883
  3865. 00:51:36,582 --> 00:51:39,324
  3866. (distant indistinct muttering)
  3867.  
  3868. 884
  3869. 00:51:52,947 --> 00:51:55,107
  3870. Ah, so how can you figure out
  3871.  
  3872. 885
  3873. 00:51:55,107 --> 00:51:57,283
  3874. if the output is gonna be recursive
  3875.  
  3876. 886
  3877. 00:51:57,283 --> 00:51:59,029
  3878. without running the code?
  3879.  
  3880. 887
  3881. 00:51:59,029 --> 00:52:02,292
  3882. (distant indistinct muttering)
  3883.  
  3884. 888
  3885. 00:52:02,292 --> 00:52:04,753
  3886. Right.
  3887. (distant indistinct muttering)
  3888.  
  3889. 889
  3890. 00:52:11,958 --> 00:52:15,938
  3891. So he said since the code
  3892. itself is not recursive,
  3893.  
  3894. 890
  3895. 00:52:16,785 --> 00:52:19,830
  3896. how do you know that the
  3897. output is gonna be recursive?
  3898.  
  3899. 891
  3900. 00:52:19,830 --> 00:52:21,567
  3901. (distant indistinct muttering)
  3902.  
  3903. 892
  3904. 00:52:21,567 --> 00:52:24,337
  3905. Even without any recursive functions.
  3906.  
  3907. 893
  3908. 00:52:24,337 --> 00:52:26,942
  3909. Right, I mean the thing is
  3910.  
  3911. 894
  3912. 00:52:26,942 --> 00:52:29,278
  3913. when you write the code,
  3914. if you realize that
  3915.  
  3916. 895
  3917. 00:52:29,278 --> 00:52:32,034
  3918. what the code is doing is mapping
  3919.  
  3920. 896
  3921. 00:52:32,034 --> 00:52:35,694
  3922. these two dimensional mappings,
  3923.  
  3924. 897
  3925. 00:52:35,694 --> 00:52:39,205
  3926. you could sort of think
  3927. in your head, okay,
  3928.  
  3929. 898
  3930. 00:52:39,205 --> 00:52:43,206
  3931. these mappings are gonna be
  3932. applied with equal probability.
  3933.  
  3934. 899
  3935. 00:52:48,179 --> 00:52:52,301
  3936. So just by mentally
  3937. extrapolating in your head,
  3938.  
  3939. 900
  3940. 00:52:52,301 --> 00:52:54,749
  3941. so you're sort of stepping
  3942. out of the system,
  3943.  
  3944. 901
  3945. 00:52:54,749 --> 00:52:57,046
  3946. you're saying okay, what's
  3947. the thing actually doing?
  3948.  
  3949. 902
  3950. 00:52:57,046 --> 00:53:00,268
  3951. (distant indistinct muttering)
  3952.  
  3953. 903
  3954. 00:53:02,265 --> 00:53:03,618
  3955. While you're in the system?
  3956.  
  3957. 904
  3958. 00:53:03,618 --> 00:53:05,351
  3959. Well, being in the system in this case
  3960.  
  3961. 905
  3962. 00:53:05,351 --> 00:53:07,953
  3963. is actually running
  3964. the code and like being
  3965.  
  3966. 906
  3967. 00:53:07,953 --> 00:53:11,052
  3968. a computer program running it.
  3969.  
  3970. 907
  3971. 00:53:11,052 --> 00:53:14,051
  3972. Stepping out of the system,
  3973. what I mean by that,
  3974.  
  3975. 908
  3976. 00:53:14,051 --> 00:53:16,909
  3977. is like taking a higher level
  3978. view of what's going on.
  3979.  
  3980. 909
  3981. 00:53:16,909 --> 00:53:19,826
  3982. (distant indistinct muttering)
  3983.  
  3984. 910
  3985. 00:53:24,606 --> 00:53:27,562
  3986. Yeah, exactly, exactly.
  3987.  
  3988. 911
  3989. 00:53:27,562 --> 00:53:29,341
  3990. Yes, that's it.
  3991.  
  3992. 912
  3993. 00:53:29,341 --> 00:53:32,814
  3994. So he said when you abstract
  3995. away from all the details
  3996.  
  3997. 913
  3998. 00:53:32,814 --> 00:53:35,809
  3999. of what's going on with
  4000. the actual functions,
  4001.  
  4002. 914
  4003. 00:53:35,809 --> 00:53:39,682
  4004. you begin to perceive
  4005. this higher level thing
  4006.  
  4007. 915
  4008. 00:53:39,682 --> 00:53:43,229
  4009. which is itself recursion, yeah,
  4010.  
  4011. 916
  4012. 00:53:43,229 --> 00:53:45,099
  4013. and has recursion in it.
  4014.  
  4015. 917
  4016. 00:53:45,099 --> 00:53:49,269
  4017. So if you abstract your thought process
  4018.  
  4019. 918
  4020. 00:53:49,269 --> 00:53:52,851
  4021. significantly enough, you'll
  4022. be able to logically tell
  4023.  
  4024. 919
  4025. 00:53:52,851 --> 00:53:57,244
  4026. that it's going to create
  4027. this recursive shape, yeah.
  4028.  
  4029. 920
  4030. 00:53:57,244 --> 00:53:59,736
  4031. (distant indistinct muttering)
  4032.  
  4033. 921
  4034. 00:54:03,833 --> 00:54:05,861
  4035. Yeah, so you mean like a test?
  4036.  
  4037. 922
  4038. 00:54:05,861 --> 00:54:10,113
  4039. No, you have to think about
  4040. it, that's what humans can do.
  4041.  
  4042. 923
  4043. 00:54:10,113 --> 00:54:13,722
  4044. Like, there's no strict
  4045. test that could be applied
  4046.  
  4047. 924
  4048. 00:54:13,722 --> 00:54:16,223
  4049. to some computer program
  4050. that would tell you
  4051.  
  4052. 925
  4053. 00:54:16,223 --> 00:54:19,115
  4054. whether or not it's going
  4055. to create a recursive result
  4056.  
  4057. 926
  4058. 00:54:19,115 --> 00:54:21,207
  4059. because in this case, there's
  4060. no recursive function.
  4061.  
  4062. 927
  4063. 00:54:21,207 --> 00:54:24,212
  4064. So the computer can't
  4065. know like okay, hmmm oh,
  4066.  
  4067. 928
  4068. 00:54:24,212 --> 00:54:26,672
  4069. can I abstract them to, you know?
  4070.  
  4071. 929
  4072. 00:54:26,672 --> 00:54:30,271
  4073. Only humans can do that, yeah, so far.
  4074.  
  4075. 930
  4076. 00:54:30,271 --> 00:54:34,068
  4077. And it's not coded up
  4078. as a system of mappings,
  4079.  
  4080. 931
  4081. 00:54:34,068 --> 00:54:36,358
  4082. it's just these simple functions.
  4083.  
  4084. 932
  4085. 00:54:36,358 --> 00:54:37,786
  4086. I don't know.
  4087.  
  4088. 933
  4089. 00:54:39,259 --> 00:54:41,187
  4090. So yeah.
  4091.  
  4092. 934
  4093. 00:54:41,187 --> 00:54:43,493
  4094. It's really cool.
  4095.  
  4096. 935
  4097. 00:54:43,493 --> 00:54:45,603
  4098. So yeah, if you just think about mapping,
  4099.  
  4100. 936
  4101. 00:54:45,603 --> 00:54:47,611
  4102. mapping, mapping and you map it over here,
  4103.  
  4104. 937
  4105. 00:54:47,611 --> 00:54:49,905
  4106. all the stuff that was in
  4107. here that goes infinitely down
  4108.  
  4109. 938
  4110. 00:54:49,905 --> 00:54:54,282
  4111. is now like, like this little subsection
  4112.  
  4113. 939
  4114. 00:54:55,635 --> 00:54:59,779
  4115. of this little triangle,
  4116. and you just, yeah.
  4117.  
  4118. 940
  4119. 00:54:59,779 --> 00:55:01,693
  4120. It's a recursive structure.
  4121.  
  4122. 941
  4123. 00:55:01,693 --> 00:55:03,431
  4124. So let's go on to the next example,
  4125.  
  4126. 942
  4127. 00:55:03,431 --> 00:55:06,507
  4128. which is very interesting,
  4129. the Mandelbrot set.
  4130.  
  4131. 943
  4132. 00:55:07,694 --> 00:55:10,020
  4133. First, now that we have
  4134. this up and running,
  4135.  
  4136. 944
  4137. 00:55:10,020 --> 00:55:14,652
  4138. I just wanna run the programs
  4139. that are in the handout
  4140.  
  4141. 945
  4142. 00:55:14,652 --> 00:55:18,087
  4143. to give you a sense of what's going on.
  4144.  
  4145. 946
  4146. 00:55:18,087 --> 00:55:21,549
  4147. So the recursive transition
  4148. network, let's run it
  4149.  
  4150. 947
  4151. 00:55:21,549 --> 00:55:23,432
  4152. and see what happens.
  4153.  
  4154. 948
  4155. 00:55:23,432 --> 00:55:25,370
  4156. It's gonna generate a hundred sentences
  4157.  
  4158. 949
  4159. 00:55:25,370 --> 00:55:28,049
  4160. because if you look at the code,
  4161.  
  4162. 950
  4163. 00:55:28,049 --> 00:55:32,600
  4164. there's a print statement
  4165. that goes a hundred times.
  4166.  
  4167. 951
  4168. 00:55:35,841 --> 00:55:37,179
  4169. Yeah, page five.
  4170.  
  4171. 952
  4172. 00:55:37,179 --> 00:55:42,179
  4173. Zero to 100 .each, print line,
  4174. call the function fancy noun.
  4175.  
  4176. 953
  4177. 00:55:43,290 --> 00:55:45,218
  4178. So this is just fancy notation
  4179.  
  4180. 954
  4181. 00:55:45,218 --> 00:55:47,976
  4182. in the groovy programming
  4183. language to just, oh crap.
  4184.  
  4185. 955
  4186. 00:55:47,976 --> 00:55:49,897
  4187. It's not working.
  4188.  
  4189. 956
  4190. 00:55:51,547 --> 00:55:54,823
  4191. Oh well, I'll just try to get
  4192. this to work as I'm talking.
  4193.  
  4194. 957
  4195. 00:55:56,509 --> 00:55:58,754
  4196. I can't do the examples.
  4197.  
  4198. 958
  4199. 00:56:03,692 --> 00:56:07,701
  4200. Yeah, I've been having problems
  4201. with this thing all day.
  4202.  
  4203. 959
  4204. 00:56:07,701 --> 00:56:09,412
  4205. So the next example and the last example
  4206.  
  4207. 960
  4208. 00:56:09,412 --> 00:56:11,465
  4209. is the Mandelbrot set.
  4210.  
  4211. 961
  4212. 00:56:14,066 --> 00:56:16,891
  4213. You guys probably have heard
  4214. about the Mandelbrot set.
  4215.  
  4216. 962
  4217. 00:56:16,891 --> 00:56:18,517
  4218. It's very famous, probably one of the most
  4219.  
  4220. 963
  4221. 00:56:18,517 --> 00:56:20,902
  4222. famous fractals of all.
  4223.  
  4224. 964
  4225. 00:56:24,738 --> 00:56:28,197
  4226. It's called Mandelbrot
  4227. because this guy, Mandelbrot,
  4228.  
  4229. 965
  4230. 00:56:28,197 --> 00:56:30,673
  4231. really loved fractals
  4232. and tried to communicate
  4233.  
  4234. 966
  4235. 00:56:30,673 --> 00:56:33,432
  4236. the notion of fractals to the world
  4237.  
  4238. 967
  4239. 00:56:33,432 --> 00:56:37,389
  4240. and this is really a great fractal.
  4241.  
  4242. 968
  4243. 00:56:37,389 --> 00:56:41,104
  4244. So it'll get a little bit
  4245. mathy but that's okay.
  4246.  
  4247. 969
  4248. 00:56:43,204 --> 00:56:46,472
  4249. So we'll have, it's in the complex plane.
  4250.  
  4251. 970
  4252. 00:56:46,472 --> 00:56:49,258
  4253. So that means that we have this plane
  4254.  
  4255. 971
  4256. 00:56:49,258 --> 00:56:51,486
  4257. where these are the real numbers
  4258.  
  4259. 972
  4260. 00:56:51,486 --> 00:56:54,172
  4261. and these are the imaginary numbers.
  4262.  
  4263. 973
  4264. 00:56:54,172 --> 00:56:57,778
  4265. I think this is the way it goes.
  4266.  
  4267. 974
  4268. 00:56:57,778 --> 00:57:02,041
  4269. So the Mandelbrot set is
  4270. defined by the function
  4271.  
  4272. 975
  4273. 00:57:04,653 --> 00:57:08,407
  4274. z equals z squared plus c.
  4275.  
  4276. 976
  4277. 00:57:10,647 --> 00:57:14,873
  4278. And when you square a complex number,
  4279.  
  4280. 977
  4281. 00:57:14,873 --> 00:57:16,848
  4282. well first of all, first of all,
  4283.  
  4284. 978
  4285. 00:57:16,848 --> 00:57:18,931
  4286. a complex number is a point in this plane.
  4287.  
  4288. 979
  4289. 00:57:18,931 --> 00:57:21,607
  4290. So say this point is,
  4291.  
  4292. 980
  4293. 00:57:24,640 --> 00:57:28,726
  4294. this is b say and this is a.
  4295.  
  4296. 981
  4297. 00:57:28,726 --> 00:57:32,159
  4298. This point is represented by a plus b, i,
  4299.  
  4300. 982
  4301. 00:57:35,437 --> 00:57:38,220
  4302. and i is the square root of negative one,
  4303.  
  4304. 983
  4305. 00:57:38,220 --> 00:57:40,686
  4306. which is not really possible,
  4307.  
  4308. 984
  4309. 00:57:40,686 --> 00:57:44,373
  4310. that's why it's called imaginary.
  4311.  
  4312. 985
  4313. 00:57:44,373 --> 00:57:48,750
  4314. So if you multiply two
  4315. complex numbers together,
  4316.  
  4317. 986
  4318. 00:57:59,830 --> 00:58:03,273
  4319. it's not really that simple.
  4320.  
  4321. 987
  4322. 00:58:03,273 --> 00:58:06,533
  4323. You have to do like the
  4324. actual multiplication out.
  4325.  
  4326. 988
  4327. 00:58:06,533 --> 00:58:09,831
  4328. What you get is ac plus you know.
  4329.  
  4330. 989
  4331. 00:58:15,176 --> 00:58:17,362
  4332. I don't know if I should do it all out.
  4333.  
  4334. 990
  4335. 00:58:17,362 --> 00:58:20,077
  4336. It'll take a little bit of time.
  4337.  
  4338. 991
  4339. 00:58:20,927 --> 00:58:24,736
  4340. But you get this sort of a
  4341. mapping function essentially
  4342.  
  4343. 992
  4344. 00:58:24,736 --> 00:58:27,569
  4345. that's not really linear.
  4346.  
  4347. 993
  4348. 00:58:27,569 --> 00:58:30,937
  4349. It's not really that
  4350. predictable what it's gonna do.
  4351.  
  4352. 994
  4353. 00:58:30,937 --> 00:58:33,657
  4354. So you have this this point here and
  4355.  
  4356. 995
  4357. 00:58:36,528 --> 00:58:39,028
  4358. okay, so the way the algorithm works,
  4359.  
  4360. 996
  4361. 00:58:39,028 --> 00:58:42,501
  4362. you take a point on the complex plane.
  4363.  
  4364. 997
  4365. 00:58:42,501 --> 00:58:45,781
  4366. C gets the value of that point and then z
  4367.  
  4368. 998
  4369. 00:58:45,781 --> 00:58:47,922
  4370. starts off at zero, just zero, zero.
  4371.  
  4372. 999
  4373. 00:58:47,922 --> 00:58:51,192
  4374. And you apply this
  4375. function a bunch of times.
  4376.  
  4377. 1000
  4378. 00:58:53,506 --> 00:58:56,599
  4379. So say we apply this function once.
  4380.  
  4381. 1001
  4382. 00:58:56,599 --> 00:58:58,891
  4383. Z equals z squared plus c.
  4384.  
  4385. 1002
  4386. 00:58:58,891 --> 00:59:01,370
  4387. So zero squared is nothing plus c.
  4388.  
  4389. 1003
  4390. 00:59:01,370 --> 00:59:04,228
  4391. So the first iteration,
  4392. z gets the value c.
  4393.  
  4394. 1004
  4395. 00:59:04,228 --> 00:59:06,374
  4396. So z is gonna be there.
  4397.  
  4398. 1005
  4399. 00:59:06,374 --> 00:59:09,408
  4400. And you apply the function again
  4401.  
  4402. 1006
  4403. 00:59:09,408 --> 00:59:13,383
  4404. and this c is now the
  4405. new z that we just got.
  4406.  
  4407. 1007
  4408. 00:59:14,293 --> 00:59:17,163
  4409. So z equals z squared plus c.
  4410.  
  4411. 1008
  4412. 00:59:17,163 --> 00:59:20,990
  4413. So z squared, you apply
  4414. the squaring function,
  4415.  
  4416. 1009
  4417. 00:59:23,588 --> 00:59:26,090
  4418. and you add c, you add the real
  4419.  
  4420. 1010
  4421. 00:59:26,090 --> 00:59:28,235
  4422. and imaginary components of c.
  4423.  
  4424. 1011
  4425. 00:59:28,235 --> 00:59:31,973
  4426. So it just maps this
  4427. point to some other point
  4428.  
  4429. 1012
  4430. 00:59:31,973 --> 00:59:35,000
  4431. over here say.
  4432.  
  4433. 1013
  4434. 00:59:35,000 --> 00:59:38,555
  4435. And then you apply this again
  4436. and again and again and again.
  4437.  
  4438. 1014
  4439. 00:59:38,555 --> 00:59:41,815
  4440. So apply it here and you're here.
  4441.  
  4442. 1015
  4443. 00:59:41,815 --> 00:59:44,356
  4444. So I don't know if I'm
  4445. going too fast but like
  4446.  
  4447. 1016
  4448. 00:59:44,356 --> 00:59:47,741
  4449. we get this point after
  4450. applying the function to this.
  4451.  
  4452. 1017
  4453. 00:59:47,741 --> 00:59:50,122
  4454. So now this is the new z.
  4455.  
  4456. 1018
  4457. 00:59:50,122 --> 00:59:52,637
  4458. And then the new z loops back around
  4459.  
  4460. 1019
  4461. 00:59:52,637 --> 00:59:54,954
  4462. and so we apply it.
  4463.  
  4464. 1020
  4465. 00:59:54,954 --> 00:59:58,239
  4466. Now z squared plus c, c is always gonna be
  4467.  
  4468. 1021
  4469. 00:59:58,239 --> 01:00:01,846
  4470. the initial point but z will be changing.
  4471.  
  4472. 1022
  4473. 01:00:01,846 --> 01:00:04,636
  4474. And it maps to here for example.
  4475.  
  4476. 1023
  4477. 01:00:04,636 --> 01:00:08,882
  4478. And now the new point is z
  4479. equals z squared plus c again
  4480.  
  4481. 1024
  4482. 01:00:10,704 --> 01:00:14,014
  4483. that maps over here.
  4484.  
  4485. 1025
  4486. 01:00:14,014 --> 01:00:17,430
  4487. So I wrote a little applet
  4488.  
  4489. 1026
  4490. 01:00:19,541 --> 01:00:21,571
  4491. that demonstrates this mapping
  4492.  
  4493. 1027
  4494. 01:00:21,571 --> 01:00:22,877
  4495. and what it actually looks like.
  4496.  
  4497. 1028
  4498. 01:00:22,877 --> 01:00:23,634
  4499. Yeah?
  4500.  
  4501. 1029
  4502. 01:00:23,634 --> 01:00:25,864
  4503. - [Male student] Z can
  4504. be anywhere in the plane?
  4505.  
  4506. 1030
  4507. 01:00:25,864 --> 01:00:27,835
  4508. - Z can be anywhere?
  4509. (crosstalk)
  4510.  
  4511. 1031
  4512. 01:00:27,835 --> 01:00:31,595
  4513. The starting point
  4514. could be anywhere, yeah.
  4515.  
  4516. 1032
  4517. 01:00:31,595 --> 01:00:34,758
  4518. But when you actually run the algorithm,
  4519.  
  4520. 1033
  4521. 01:00:34,758 --> 01:00:38,275
  4522. you only go from negative two to two.
  4523.  
  4524. 1034
  4525. 01:00:40,167 --> 01:00:42,149
  4526. Negative two, two,
  4527.  
  4528. 1035
  4529. 01:00:43,466 --> 01:00:45,457
  4530. because that's the only region
  4531.  
  4532. 1036
  4533. 01:00:45,457 --> 01:00:48,151
  4534. in which interesting things
  4535. happen with this fractal.
  4536.  
  4537. 1037
  4538. 01:00:48,151 --> 01:00:52,339
  4539. So I didn't finish
  4540. explaining the algorithm.
  4541.  
  4542. 1038
  4543. 01:00:52,339 --> 01:00:54,523
  4544. So say a point in here,
  4545. a point that's very close
  4546.  
  4547. 1039
  4548. 01:00:54,523 --> 01:00:56,907
  4549. to the origin, zero, zero,
  4550.  
  4551. 1040
  4552. 01:00:56,907 --> 01:01:00,480
  4553. what it tends to do is spiral inward
  4554.  
  4555. 1041
  4556. 01:01:00,480 --> 01:01:02,395
  4557. as you iterate it.
  4558.  
  4559. 1042
  4560. 01:01:02,395 --> 01:01:04,653
  4561. But a point out here,
  4562. what it tends to do...
  4563.  
  4564. 1043
  4565. 01:01:05,975 --> 01:01:08,898
  4566. Oh definitely a point outside of two.
  4567.  
  4568. 1044
  4569. 01:01:08,898 --> 01:01:11,594
  4570. What it tends to do when
  4571. you apply this function
  4572.  
  4573. 1045
  4574. 01:01:11,594 --> 01:01:13,095
  4575. is to get mapped out here
  4576.  
  4577. 1046
  4578. 01:01:13,095 --> 01:01:14,706
  4579. and then to get mapped like over there
  4580.  
  4581. 1047
  4582. 01:01:14,706 --> 01:01:17,471
  4583. and just go like really far away.
  4584.  
  4585. 1048
  4586. 01:01:17,471 --> 01:01:22,471
  4587. So what we do to render the Mandelbrot set
  4588.  
  4589. 1049
  4590. 01:01:22,538 --> 01:01:26,117
  4591. is apply the function a number of times.
  4592.  
  4593. 1050
  4594. 01:01:29,038 --> 01:01:34,038
  4595. And if the point eventually
  4596. goes outside this circle
  4597.  
  4598. 1051
  4599. 01:01:35,589 --> 01:01:39,219
  4600. at the origin of radius two,
  4601. sorry it's a bad circle,
  4602.  
  4603. 1052
  4604. 01:01:39,219 --> 01:01:42,514
  4605. if the point eventually
  4606. goes outside of the circle,
  4607.  
  4608. 1053
  4609. 01:01:42,514 --> 01:01:44,851
  4610. we stop performing the
  4611. function because we know
  4612.  
  4613. 1054
  4614. 01:01:44,851 --> 01:01:46,535
  4615. that after it gets outside,
  4616.  
  4617. 1055
  4618. 01:01:46,535 --> 01:01:48,413
  4619. it's gonna keep going forever out.
  4620.  
  4621. 1056
  4622. 01:01:48,413 --> 01:01:51,102
  4623. It has escaped.
  4624.  
  4625. 1057
  4626. 01:01:51,102 --> 01:01:53,407
  4627. It's called the escape iterations,
  4628.  
  4629. 1058
  4630. 01:01:53,407 --> 01:01:55,202
  4631. the number of iterations it takes
  4632.  
  4633. 1059
  4634. 01:01:55,202 --> 01:01:58,821
  4635. to escape outside of the circle,
  4636. so the escape iterations.
  4637.  
  4638. 1060
  4639. 01:01:58,821 --> 01:02:03,165
  4640. So what we do is we color the point
  4641.  
  4642. 1061
  4643. 01:02:03,165 --> 01:02:06,042
  4644. depending on its escape iteration.
  4645.  
  4646. 1062
  4647. 01:02:06,042 --> 01:02:08,511
  4648. So when we actually, and
  4649. the other part of it is
  4650.  
  4651. 1063
  4652. 01:02:08,511 --> 01:02:10,934
  4653. if it never escapes, we color it black.
  4654.  
  4655. 1064
  4656. 01:02:10,934 --> 01:02:12,848
  4657. To actually test that, we just iterate
  4658.  
  4659. 1065
  4660. 01:02:12,848 --> 01:02:16,306
  4661. a certain number of
  4662. times, say like 500 times
  4663.  
  4664. 1066
  4665. 01:02:16,306 --> 01:02:18,376
  4666. or like 70 times.
  4667.  
  4668. 1067
  4669. 01:02:18,376 --> 01:02:21,148
  4670. And if it hasn't escaped
  4671. after that many iterations,
  4672.  
  4673. 1068
  4674. 01:02:21,148 --> 01:02:23,026
  4675. we sort of assume that
  4676. it's never going to.
  4677.  
  4678. 1069
  4679. 01:02:23,026 --> 01:02:26,230
  4680. It's not valid, so it's an
  4681. approximation to the actual set
  4682.  
  4683. 1070
  4684. 01:02:26,230 --> 01:02:29,910
  4685. but we have to do it to
  4686. render the actual thing.
  4687.  
  4688. 1071
  4689. 01:02:29,910 --> 01:02:31,550
  4690. Then we color black.
  4691.  
  4692. 1072
  4693. 01:02:31,550 --> 01:02:33,861
  4694. So when we actually render
  4695. it, what we do is go through
  4696.  
  4697. 1073
  4698. 01:02:33,861 --> 01:02:37,457
  4699. each pixel on the screen
  4700. and apply this algorithm.
  4701.  
  4702. 1074
  4703. 01:02:38,416 --> 01:02:40,393
  4704. So for this point, this point becomes c
  4705.  
  4706. 1075
  4707. 01:02:40,393 --> 01:02:44,341
  4708. and we iterate, test,
  4709. iterate, test, iterate, test,
  4710.  
  4711. 1076
  4712. 01:02:44,341 --> 01:02:48,095
  4713. and it's a test and what we're testing
  4714.  
  4715. 1077
  4716. 01:02:48,095 --> 01:02:49,804
  4717. is if it's outside of the circle.
  4718.  
  4719. 1078
  4720. 01:02:49,804 --> 01:02:52,357
  4721. If it's outside of the
  4722. circle, we assign it a color
  4723.  
  4724. 1079
  4725. 01:02:52,357 --> 01:02:54,781
  4726. based on the number of iterations it took.
  4727.  
  4728. 1080
  4729. 01:02:54,781 --> 01:02:57,988
  4730. And we do that for each one.
  4731.  
  4732. 1081
  4733. 01:02:57,988 --> 01:03:00,729
  4734. So we keep going and
  4735. say this one for example
  4736.  
  4737. 1082
  4738. 01:03:00,729 --> 01:03:03,185
  4739. is gonna spiral in.
  4740.  
  4741. 1083
  4742. 01:03:03,185 --> 01:03:06,374
  4743. It's not a continuous line,
  4744. it just applies the function
  4745.  
  4746. 1084
  4747. 01:03:06,374 --> 01:03:08,384
  4748. and spirals in.
  4749.  
  4750. 1085
  4751. 01:03:09,669 --> 01:03:11,530
  4752. So that's never going to escape
  4753.  
  4754. 1086
  4755. 01:03:11,530 --> 01:03:13,640
  4756. so we're gonna color it black.
  4757.  
  4758. 1087
  4759. 01:03:13,640 --> 01:03:18,091
  4760. And this applet is
  4761. excellent in showing this.
  4762.  
  4763. 1088
  4764. 01:03:21,728 --> 01:03:26,368
  4765. So I implemented this algorithm in Java
  4766.  
  4767. 1089
  4768. 01:03:26,368 --> 01:03:29,735
  4769. and it's gonna output the point
  4770.  
  4771. 1090
  4772. 01:03:33,382 --> 01:03:37,345
  4773. and it's gonna draw the
  4774. lines between each point.
  4775.  
  4776. 1091
  4777. 01:03:38,192 --> 01:03:40,720
  4778. So say it starts here, it's
  4779. gonna draw a line here,
  4780.  
  4781. 1092
  4782. 01:03:40,720 --> 01:03:42,757
  4783. here, here, here.
  4784.  
  4785. 1093
  4786. 01:03:42,757 --> 01:03:44,842
  4787. So what we're gonna see is really cool.
  4788.  
  4789. 1094
  4790. 01:03:44,842 --> 01:03:47,959
  4791. So this is what we get in the end.
  4792.  
  4793. 1095
  4794. 01:03:47,959 --> 01:03:52,045
  4795. And as I move my mouse
  4796. around, it does these tests.
  4797.  
  4798. 1096
  4799. 01:03:52,045 --> 01:03:55,672
  4800. So here we can see that
  4801. there's only one iteration,
  4802.  
  4803. 1097
  4804. 01:03:55,672 --> 01:03:59,310
  4805. the one iteration gets
  4806. the color light blue.
  4807.  
  4808. 1098
  4809. 01:03:59,310 --> 01:04:01,689
  4810. And then here, there are two iterations
  4811.  
  4812. 1099
  4813. 01:04:01,689 --> 01:04:04,176
  4814. and they're listed up there, one, two.
  4815.  
  4816. 1100
  4817. 01:04:04,176 --> 01:04:07,506
  4818. So you can see all the way,
  4819. wherever it's this color,
  4820.  
  4821. 1101
  4822. 01:04:07,506 --> 01:04:11,180
  4823. there are only two iterations
  4824. before the point gets outside
  4825.  
  4826. 1102
  4827. 01:04:11,180 --> 01:04:13,113
  4828. of this circle.
  4829.  
  4830. 1103
  4831. 01:04:13,113 --> 01:04:15,643
  4832. Two, two, two I think.
  4833.  
  4834. 1104
  4835. 01:04:17,482 --> 01:04:21,038
  4836. So as we go deeper in and
  4837. it takes three iterations,
  4838.  
  4839. 1105
  4840. 01:04:21,038 --> 01:04:24,096
  4841. four or five, six, a lot of iterations.
  4842.  
  4843. 1106
  4844. 01:04:24,096 --> 01:04:27,355
  4845. So all the points that are colored
  4846.  
  4847. 1107
  4848. 01:04:27,355 --> 01:04:29,972
  4849. they do eventually escape.
  4850.  
  4851. 1108
  4852. 01:04:29,972 --> 01:04:32,601
  4853. But all the points that
  4854. are black don't escape.
  4855.  
  4856. 1109
  4857. 01:04:32,601 --> 01:04:35,506
  4858. And so the patterns that are
  4859. inside are really interesting.
  4860.  
  4861. 1110
  4862. 01:04:35,506 --> 01:04:38,787
  4863. See these in the middle,
  4864. they just sort of spiral
  4865.  
  4866. 1111
  4867. 01:04:38,787 --> 01:04:40,829
  4868. and keep going.
  4869.  
  4870. 1112
  4871. 01:04:40,829 --> 01:04:43,980
  4872. The ones here, there's
  4873. some looping pattern.
  4874.  
  4875. 1113
  4876. 01:04:43,980 --> 01:04:47,719
  4877. See, the function loops back on itself.
  4878.  
  4879. 1114
  4880. 01:04:47,719 --> 01:04:49,119
  4881. So it's sort of recursive,
  4882.  
  4883. 1115
  4884. 01:04:49,119 --> 01:04:52,287
  4885. like I don't really understand
  4886. how its recursive but
  4887.  
  4888. 1116
  4889. 01:04:52,287 --> 01:04:53,871
  4890. it sort of is.
  4891.  
  4892. 1117
  4893. 01:04:53,871 --> 01:04:55,762
  4894. So if we go out to this other nub,
  4895.  
  4896. 1118
  4897. 01:04:55,762 --> 01:04:59,005
  4898. the second nub out, it gets
  4899. this, it's really cool shape.
  4900.  
  4901. 1119
  4902. 01:05:00,276 --> 01:05:04,121
  4903. So what we could do is
  4904. zoom in actually on this.
  4905.  
  4906. 1120
  4907. 01:05:04,121 --> 01:05:06,151
  4908. It redraws it.
  4909.  
  4910. 1121
  4911. 01:05:06,151 --> 01:05:08,592
  4912. So it's calculating this
  4913. algorithm for every single point
  4914.  
  4915. 1122
  4916. 01:05:08,592 --> 01:05:10,984
  4917. as we speak, it's getting really fast.
  4918.  
  4919. 1123
  4920. 01:05:13,701 --> 01:05:17,912
  4921. So we can see all these really cool shapes
  4922.  
  4923. 1124
  4924. 01:05:17,912 --> 01:05:20,245
  4925. that generate this fractal.
  4926.  
  4927. 1125
  4928. 01:05:22,242 --> 01:05:24,847
  4929. And it's just crazy.
  4930.  
  4931. 1126
  4932. 01:05:31,435 --> 01:05:34,331
  4933. So we can sort of see recursion here.
  4934.  
  4935. 1127
  4936. 01:05:34,331 --> 01:05:36,318
  4937. Like it looks like there's definitely some
  4938.  
  4939. 1128
  4940. 01:05:36,318 --> 01:05:38,644
  4941. recursive thing going on,
  4942.  
  4943. 1129
  4944. 01:05:38,644 --> 01:05:41,258
  4945. and the recursive part
  4946. of this is the fact that
  4947.  
  4948. 1130
  4949. 01:05:43,463 --> 01:05:45,617
  4950. z gets applied to itself.
  4951.  
  4952. 1131
  4953. 01:05:48,388 --> 01:05:52,263
  4954. The nth z is equal to
  4955. the z that came before it
  4956.  
  4957. 1132
  4958. 01:05:54,196 --> 01:05:56,112
  4959. squared plus c.
  4960.  
  4961. 1133
  4962. 01:05:56,112 --> 01:05:59,326
  4963. And then this z is reframed as the old z,
  4964.  
  4965. 1134
  4966. 01:05:59,326 --> 01:06:02,319
  4967. and this reframing and
  4968. reapplying of the function
  4969.  
  4970. 1135
  4971. 01:06:02,319 --> 01:06:05,033
  4972. is what makes it recursive.
  4973.  
  4974. 1136
  4975. 01:06:05,033 --> 01:06:09,682
  4976. Yeah, it sort of makes sense.
  4977.  
  4978. 1137
  4979. 01:06:10,598 --> 01:06:13,339
  4980. Let's just go through the code quickly
  4981.  
  4982. 1138
  4983. 01:06:13,339 --> 01:06:15,490
  4984. and then I want to
  4985.  
  4986. 1139
  4987. 01:06:16,578 --> 01:06:19,761
  4988. show some really cool things.
  4989.  
  4990. 1140
  4991. 01:06:20,834 --> 01:06:22,816
  4992. Oh, where did it go?
  4993.  
  4994. 1141
  4995. 01:06:22,816 --> 01:06:25,397
  4996. (distant indistinct muttering)
  4997.  
  4998. 1142
  4999. 01:06:25,397 --> 01:06:28,802
  5000. So yeah, in the black part
  5001. it just recurses infinitely.
  5002.  
  5003. 1143
  5004. 01:06:28,802 --> 01:06:30,854
  5005. And the code itself is not recursive,
  5006.  
  5007. 1144
  5008. 01:06:30,854 --> 01:06:34,372
  5009. but the mapping function,
  5010. again, it's what's recursive.
  5011.  
  5012. 1145
  5013. 01:06:34,372 --> 01:06:38,996
  5014. So yeah, the black parts are in the set.
  5015.  
  5016. 1146
  5017. 01:06:40,740 --> 01:06:42,939
  5018. So the real actual Mandelbrot set
  5019.  
  5020. 1147
  5021. 01:06:42,939 --> 01:06:44,719
  5022. is just the black points.
  5023.  
  5024. 1148
  5025. 01:06:44,719 --> 01:06:47,961
  5026. We just color the other
  5027. point so it looks pretty.
  5028.  
  5029. 1149
  5030. 01:06:47,961 --> 01:06:50,916
  5031. So let's look at the code.
  5032.  
  5033. 1150
  5034. 01:06:50,916 --> 01:06:52,687
  5035. Def draw Mandelbrot.
  5036.  
  5037. 1151
  5038. 01:06:52,687 --> 01:06:54,848
  5039. See that there?
  5040.  
  5041. 1152
  5042. 01:06:57,625 --> 01:06:59,561
  5043. Window .set negative two, two.
  5044.  
  5045. 1153
  5046. 01:06:59,561 --> 01:07:01,907
  5047. So it just sets the
  5048. window, the plotting range
  5049.  
  5050. 1154
  5051. 01:07:01,907 --> 01:07:03,824
  5052. to be in this range.
  5053.  
  5054. 1155
  5055. 01:07:03,824 --> 01:07:08,247
  5056. For every x pixel in
  5057. the height of the window
  5058.  
  5059. 1156
  5060. 01:07:08,247 --> 01:07:09,874
  5061. or the width of the window,
  5062.  
  5063. 1157
  5064. 01:07:09,874 --> 01:07:11,680
  5065. and every y pixel in the height,
  5066.  
  5067. 1158
  5068. 01:07:11,680 --> 01:07:15,114
  5069. c .real and c .imaginary
  5070. get the x and y values
  5071.  
  5072. 1159
  5073. 01:07:15,114 --> 01:07:17,446
  5074. on the screen.
  5075.  
  5076. 1160
  5077. 01:07:17,446 --> 01:07:20,682
  5078. So what we're doing there is saying
  5079.  
  5080. 1161
  5081. 01:07:20,682 --> 01:07:25,524
  5082. basically the pixel gets this
  5083. actual point in the space
  5084.  
  5085. 1162
  5086. 01:07:25,524 --> 01:07:28,713
  5087. that we're working, the complex plane.
  5088.  
  5089. 1163
  5090. 01:07:28,713 --> 01:07:32,553
  5091. Def iterations equals
  5092. calculate iterations c.
  5093.  
  5094. 1164
  5095. 01:07:32,553 --> 01:07:36,298
  5096. And we pass it c, keep in mind this is c.
  5097.  
  5098. 1165
  5099. 01:07:36,298 --> 01:07:38,548
  5100. The starting point is c.
  5101.  
  5102. 1166
  5103. 01:07:38,548 --> 01:07:42,891
  5104. So let's just stay inside
  5105. this function for now.
  5106.  
  5107. 1167
  5108. 01:07:42,891 --> 01:07:46,314
  5109. Def color equals calculate
  5110. color iterations.
  5111.  
  5112. 1168
  5113. 01:07:46,314 --> 01:07:48,456
  5114. So we're calculating the color
  5115.  
  5116. 1169
  5117. 01:07:48,456 --> 01:07:51,316
  5118. based on the number of
  5119. iterations it took to escape.
  5120.  
  5121. 1170
  5122. 01:07:51,316 --> 01:07:54,427
  5123. And then fill the pixel with the color.
  5124.  
  5125. 1171
  5126. 01:07:54,427 --> 01:07:56,761
  5127. That plots it on the screen.
  5128.  
  5129. 1172
  5130. 01:07:56,761 --> 01:07:59,336
  5131. So let's look at the
  5132. calculate iterations function,
  5133.  
  5134. 1173
  5135. 01:07:59,336 --> 01:08:01,637
  5136. int calculated iterations.
  5137.  
  5138. 1174
  5139. 01:08:01,637 --> 01:08:05,167
  5140. This notation means that it
  5141. will return an integer number.
  5142.  
  5143. 1175
  5144. 01:08:05,167 --> 01:08:07,062
  5145. It takes a complex number c.
  5146.  
  5147. 1176
  5148. 01:08:07,062 --> 01:08:10,299
  5149. So z real z imaginary
  5150. start at zero, start there.
  5151.  
  5152. 1177
  5153. 01:08:10,299 --> 01:08:13,582
  5154. And then iteration starts off at zero.
  5155.  
  5156. 1178
  5157. 01:08:15,500 --> 01:08:19,814
  5158. So this is, we're gonna count
  5159. how many iterations it takes.
  5160.  
  5161. 1179
  5162. 01:08:19,814 --> 01:08:22,240
  5163. So while the circled contains z,
  5164.  
  5165. 1180
  5166. 01:08:22,240 --> 01:08:26,248
  5167. that's another function that
  5168. just tests if it's inside,
  5169.  
  5170. 1181
  5171. 01:08:26,248 --> 01:08:29,830
  5172. and the number of iterations
  5173. is less than max iterations,
  5174.  
  5175. 1182
  5176. 01:08:31,165 --> 01:08:34,077
  5177. max iterations is the number of iterations
  5178.  
  5179. 1183
  5180. 01:08:34,077 --> 01:08:37,357
  5181. after which we assume is
  5182. it's just gonna spiral inward
  5183.  
  5184. 1184
  5185. 01:08:37,357 --> 01:08:40,254
  5186. and just stay inside.
  5187.  
  5188. 1185
  5189. 01:08:40,254 --> 01:08:44,682
  5190. So while that stuff is true,
  5191. z equals z squared plus c.
  5192.  
  5193. 1186
  5194. 01:08:44,682 --> 01:08:47,836
  5195. Z equals z times z plus
  5196. c, which is the squared.
  5197.  
  5198. 1187
  5199. 01:08:49,066 --> 01:08:53,576
  5200. So we can do that because
  5201. I overloaded the operators,
  5202.  
  5203. 1188
  5204. 01:08:53,576 --> 01:08:57,440
  5205. the multiplication and
  5206. addition, for a complex number.
  5207.  
  5208. 1189
  5209. 01:08:57,440 --> 01:08:59,359
  5210. So it behaves correctly,
  5211.  
  5212. 1190
  5213. 01:08:59,359 --> 01:09:02,508
  5214. it does this strange multiplication thing.
  5215.  
  5216. 1191
  5217. 01:09:03,584 --> 01:09:06,604
  5218. And so we do that, iterations plus, plus.
  5219.  
  5220. 1192
  5221. 01:09:06,604 --> 01:09:10,337
  5222. That means we increment the
  5223. number of iterations by one.
  5224.  
  5225. 1193
  5226. 01:09:10,337 --> 01:09:13,408
  5227. And calculate color just,
  5228.  
  5229. 1194
  5230. 01:09:13,408 --> 01:09:16,615
  5231. it calculates a color based
  5232. on number of iterations.
  5233.  
  5234. 1195
  5235. 01:09:18,711 --> 01:09:20,255
  5236. So we have 20 minutes left,
  5237.  
  5238. 1196
  5239. 01:09:20,255 --> 01:09:23,660
  5240. I want to blow you away
  5241.  
  5242. 1197
  5243. 01:09:23,660 --> 01:09:26,162
  5244. with music and fractals.
  5245.  
  5246. 1198
  5247. 01:09:29,464 --> 01:09:33,311
  5248. So I'm gonna play a piece,
  5249. three pieces of Bach.
  5250.  
  5251. 1199
  5252. 01:09:33,311 --> 01:09:35,795
  5253. And yeah, this is great.
  5254.  
  5255. 1200
  5256. 01:09:36,855 --> 01:09:40,373
  5257. So the first one, it's
  5258. actually not written by Bach.
  5259.  
  5260. 1201
  5261. 01:09:40,373 --> 01:09:42,590
  5262. Oh no, what's going on here?
  5263.  
  5264. 1202
  5265. 01:09:46,488 --> 01:09:47,670
  5266. It's not written by Bach,
  5267.  
  5268. 1203
  5269. 01:09:47,670 --> 01:09:49,728
  5270. but it's the Little Harmonic Labyrinth,
  5271.  
  5272. 1204
  5273. 01:09:49,728 --> 01:09:53,728
  5274. which is the song that
  5275. the dialogue is based on
  5276.  
  5277. 1205
  5278. 01:09:55,204 --> 01:09:58,282
  5279. in Godel, Escher, Bach.
  5280.  
  5281. 1206
  5282. 01:09:58,282 --> 01:10:01,800
  5283. English language has a grammar.
  5284.  
  5285. 1207
  5286. 01:10:01,800 --> 01:10:05,392
  5287. We could nest sentences
  5288. inside which we can nest
  5289.  
  5290. 1208
  5291. 01:10:05,392 --> 01:10:08,864
  5292. more sentences in which we
  5293. could nest more sentences.
  5294.  
  5295. 1209
  5296. 01:10:08,864 --> 01:10:10,663
  5297. And that itself was a nested sentence.
  5298.  
  5299. 1210
  5300. 01:10:10,663 --> 01:10:12,748
  5301. So music, sort of like English,
  5302.  
  5303. 1211
  5304. 01:10:12,748 --> 01:10:16,314
  5305. has sort of a grammar to it.
  5306.  
  5307. 1212
  5308. 01:10:16,314 --> 01:10:19,660
  5309. These chord progressions
  5310. and melodies and harmonies
  5311.  
  5312. 1213
  5313. 01:10:19,660 --> 01:10:23,444
  5314. particularly have a sort of a language
  5315.  
  5316. 1214
  5317. 01:10:23,444 --> 01:10:26,877
  5318. in which they can move
  5319. between keys and whatnot.
  5320.  
  5321. 1215
  5322. 01:10:26,877 --> 01:10:31,087
  5323. And so that's one way in
  5324. which Bach embeds recursion
  5325.  
  5326. 1216
  5327. 01:10:33,631 --> 01:10:35,089
  5328. inside of music.
  5329.  
  5330. 1217
  5331. 01:10:35,089 --> 01:10:38,536
  5332. He has these nested harmonic structures
  5333.  
  5334. 1218
  5335. 01:10:38,536 --> 01:10:40,059
  5336. of chord progressions.
  5337.  
  5338. 1219
  5339. 01:10:40,059 --> 01:10:44,437
  5340. In Chapter five of Godel,
  5341. Escher, Bach, he talks about it.
  5342.  
  5343. 1220
  5344. 01:10:44,437 --> 01:10:47,132
  5345. And the dialogue is modeled after
  5346.  
  5347. 1221
  5348. 01:10:49,312 --> 01:10:52,686
  5349. that first song that we heard,
  5350. Little Harmonic Labyrinth.
  5351.  
  5352. 1222
  5353. 01:10:52,686 --> 01:10:55,497
  5354. And melodies also can
  5355. sort of have recursion
  5356.  
  5357. 1223
  5358. 01:10:55,497 --> 01:10:57,716
  5359. in that they can have patterns.
  5360.  
  5361. 1224
  5362. 01:10:57,716 --> 01:11:01,113
  5363. Like this theme for example,
  5364.  
  5365. 1225
  5366. 01:11:01,113 --> 01:11:04,680
  5367. this theme, like Bach does this a lot,
  5368.  
  5369. 1226
  5370. 01:11:06,758 --> 01:11:09,996
  5371. what he does is he takes
  5372. themes and he restates them
  5373.  
  5374. 1227
  5375. 01:11:09,996 --> 01:11:12,381
  5376. with maybe different harmonies
  5377.  
  5378. 1228
  5379. 01:11:12,381 --> 01:11:17,110
  5380. and embeds them inside
  5381. smaller and larger scales.
  5382.  
  5383. 1229
  5384. 01:11:18,351 --> 01:11:20,973
  5385. So for example, I don't
  5386. know if he did this,
  5387.  
  5388. 1230
  5389. 01:11:20,973 --> 01:11:24,210
  5390. like maybe on a larger scale,
  5391.  
  5392. 1231
  5393. 01:11:24,210 --> 01:11:27,290
  5394. the actual harmony might actually follow
  5395.  
  5396. 1232
  5397. 01:11:27,290 --> 01:11:30,765
  5398. this sort of theme.
  5399.  
  5400. 1233
  5401. 01:11:30,765 --> 01:11:34,171
  5402. And inside those, like
  5403. for a long period of time
  5404.  
  5405. 1234
  5406. 01:11:34,171 --> 01:11:36,887
  5407. be this key, and a long
  5408. period of time, be this key.
  5409.  
  5410. 1235
  5411. 01:11:36,887 --> 01:11:41,671
  5412. And then when you're in that
  5413. key, he plays this theme.
  5414.  
  5415. 1236
  5416. 01:11:41,671 --> 01:11:43,673
  5417. So that's an example of nesting.
  5418.  
  5419. 1237
  5420. 01:11:43,673 --> 01:11:47,546
  5421. So recursion per se is not there,
  5422.  
  5423. 1238
  5424. 01:11:47,546 --> 01:11:50,339
  5425. but the result of recursion,
  5426.  
  5427. 1239
  5428. 01:11:50,339 --> 01:11:52,866
  5429. this is the distinction
  5430. between recursive processes
  5431.  
  5432. 1240
  5433. 01:11:52,866 --> 01:11:54,762
  5434. and recursive structures.
  5435.  
  5436. 1241
  5437. 01:11:54,762 --> 01:11:56,923
  5438. Recursive structures are
  5439. basically any structure
  5440.  
  5441. 1242
  5442. 01:11:56,923 --> 01:11:58,560
  5443. that has nesting to it.
  5444.  
  5445. 1243
  5446. 01:11:58,560 --> 01:12:00,552
  5447. So English languages is
  5448. a recursive structure
  5449.  
  5450. 1244
  5451. 01:12:00,552 --> 01:12:03,769
  5452. because it comes from a
  5453. recursive grammar, it's nesting.
  5454.  
  5455. 1245
  5456. 01:12:03,769 --> 01:12:07,763
  5457. And music also, it's
  5458. a recursive structure,
  5459.  
  5460. 1246
  5461. 01:12:07,763 --> 01:12:09,996
  5462. not a recursive process.
  5463.  
  5464. 1247
  5465. 01:12:09,996 --> 01:12:12,782
  5466. (distant indistinct muttering)
  5467.  
  5468. 1248
  5469. 01:12:16,724 --> 01:12:18,048
  5470. Exactly, that's it.
  5471.  
  5472. 1249
  5473. 01:12:18,048 --> 01:12:21,001
  5474. He says so a recursive process is
  5475.  
  5476. 1250
  5477. 01:12:21,001 --> 01:12:23,416
  5478. sort of like a function
  5479. or something that defines
  5480.  
  5481. 1251
  5482. 01:12:23,416 --> 01:12:26,300
  5483. how you end up with a recursive structure.
  5484.  
  5485. 1252
  5486. 01:12:26,300 --> 01:12:28,259
  5487. That's exactly it, yeah.
  5488.  
  5489. 1253
  5490. 01:12:28,259 --> 01:12:30,712
  5491. (distant indistinct muttering)
  5492.  
  5493. 1254
  5494. 01:12:43,998 --> 01:12:46,695
  5495. Yeah, it's hard to hear.
  5496.  
  5497. 1255
  5498. 01:12:46,695 --> 01:12:50,324
  5499. It takes a really fine
  5500. musical ear to hear this.
  5501.  
  5502. 1256
  5503. 01:12:54,058 --> 01:12:56,128
  5504. Let's see, how much time?
  5505.  
  5506. 1257
  5507. 01:12:56,128 --> 01:12:58,063
  5508. Three minutes.
  5509.  
  5510. 1258
  5511. 01:12:58,063 --> 01:13:02,333
  5512. So we talked about pushing
  5513. and popping of stacks.
  5514.  
  5515. 1259
  5516. 01:13:05,496 --> 01:13:08,373
  5517. So a function, a computer function,
  5518.  
  5519. 1260
  5520. 01:13:08,373 --> 01:13:10,433
  5521. say f, Foo actually.
  5522.  
  5523. 1261
  5524. 01:13:14,827 --> 01:13:17,256
  5525. Foo is a function.
  5526.  
  5527. 1262
  5528. 01:13:17,256 --> 01:13:21,608
  5529. Or better yet, well no (mumbles).
  5530.  
  5531. 1263
  5532. 01:13:21,608 --> 01:13:25,844
  5533. and inside this Foo, it
  5534. calls the function bar.
  5535.  
  5536. 1264
  5537. 01:13:28,821 --> 01:13:31,692
  5538. And here's a function bar.
  5539.  
  5540. 1265
  5541. 01:13:34,223 --> 01:13:36,956
  5542. It does some stuff and it calls maybe g.
  5543.  
  5544. 1266
  5545. 01:13:39,056 --> 01:13:41,878
  5546. And does some other stuff, here's g.
  5547.  
  5548. 1267
  5549. 01:13:44,699 --> 01:13:48,610
  5550. G maybe does just one thing
  5551. and I don't know, ends.
  5552.  
  5553. 1268
  5554. 01:13:48,610 --> 01:13:52,596
  5555. So what you have is a stack, a call stack.
  5556.  
  5557. 1269
  5558. 01:13:52,596 --> 01:13:57,056
  5559. Like it happens in any grammar actually
  5560.  
  5561. 1270
  5562. 01:13:57,056 --> 01:13:59,343
  5563. that's sort of recursive.
  5564.  
  5565. 1271
  5566. 01:13:59,343 --> 01:14:01,565
  5567. So in computer programs
  5568. and also in English,
  5569.  
  5570. 1272
  5571. 01:14:01,565 --> 01:14:03,174
  5572. you have this notion of a stack.
  5573.  
  5574. 1273
  5575. 01:14:03,174 --> 01:14:05,817
  5576. So here, you do some
  5577. stuff, you do some stuff.
  5578.  
  5579. 1274
  5580. 01:14:05,817 --> 01:14:09,529
  5581. And then when you call bar,
  5582. your focus actually changes
  5583.  
  5584. 1275
  5585. 01:14:10,826 --> 01:14:13,013
  5586. to over here, bar.
  5587.  
  5588. 1276
  5589. 01:14:13,013 --> 01:14:15,973
  5590. But you retain, sort of in your mind
  5591.  
  5592. 1277
  5593. 01:14:15,973 --> 01:14:19,410
  5594. or in the memory of the
  5595. computer, where you were,
  5596.  
  5597. 1278
  5598. 01:14:19,410 --> 01:14:20,920
  5599. where you left from.
  5600.  
  5601. 1279
  5602. 01:14:20,920 --> 01:14:23,593
  5603. So yeah?
  5604. (distant indistinct muttering)
  5605.  
  5606. 1280
  5607. 01:14:29,795 --> 01:14:31,997
  5608. Goals, yeah exactly.
  5609.  
  5610. 1281
  5611. 01:14:31,997 --> 01:14:35,320
  5612. So that's why computer
  5613. programming is tough
  5614.  
  5615. 1282
  5616. 01:14:35,320 --> 01:14:37,044
  5617. because like you have a high level goal
  5618.  
  5619. 1283
  5620. 01:14:37,044 --> 01:14:38,943
  5621. but then to get to that
  5622. goal, just like you said,
  5623.  
  5624. 1284
  5625. 01:14:38,943 --> 01:14:40,527
  5626. you have other goals that you need to meet
  5627.  
  5628. 1285
  5629. 01:14:40,527 --> 01:14:42,785
  5630. and each of those goals
  5631. require some other goals.
  5632.  
  5633. 1286
  5634. 01:14:42,785 --> 01:14:44,590
  5635. So it's actually recursive.
  5636.  
  5637. 1287
  5638. 01:14:44,590 --> 01:14:46,389
  5639. Like it's crazy.
  5640.  
  5641. 1288
  5642. 01:14:48,180 --> 01:14:51,589
  5643. So when this program
  5644. executes, it does this stuff,
  5645.  
  5646. 1289
  5647. 01:14:51,589 --> 01:14:55,637
  5648. it puts this position a,
  5649. let's say, on the stack.
  5650.  
  5651. 1290
  5652. 01:14:55,637 --> 01:14:58,514
  5653. So this is a stack, a.
  5654.  
  5655. 1291
  5656. 01:14:58,514 --> 01:15:00,919
  5657. And then it goes into here
  5658. bar, blah, blah, blah,
  5659.  
  5660. 1292
  5661. 01:15:00,919 --> 01:15:02,459
  5662. does all this stuff and it calls g.
  5663.  
  5664. 1293
  5665. 01:15:02,459 --> 01:15:05,133
  5666. But to remember where this is,
  5667. let's call this position b,
  5668.  
  5669. 1294
  5670. 01:15:05,133 --> 01:15:07,347
  5671. it puts be on the stack
  5672.  
  5673. 1295
  5674. 01:15:07,347 --> 01:15:10,768
  5675. and it calls g and then
  5676. does all this stuff.
  5677.  
  5678. 1296
  5679. 01:15:10,768 --> 01:15:12,458
  5680. And then after this it returns.
  5681.  
  5682. 1297
  5683. 01:15:12,458 --> 01:15:15,087
  5684. And when it returns, it
  5685. asks where was I last time?
  5686.  
  5687. 1298
  5688. 01:15:16,249 --> 01:15:18,761
  5689. And this is what the stack is for.
  5690.  
  5691. 1299
  5692. 01:15:18,761 --> 01:15:20,038
  5693. So where was I last time?
  5694.  
  5695. 1300
  5696. 01:15:20,038 --> 01:15:21,110
  5697. I was at b.
  5698.  
  5699. 1301
  5700. 01:15:21,110 --> 01:15:24,815
  5701. So we pop, putting something
  5702. on the stack is pushing.
  5703.  
  5704. 1302
  5705. 01:15:24,815 --> 01:15:26,642
  5706. Taking off is called popping.
  5707.  
  5708. 1303
  5709. 01:15:26,642 --> 01:15:28,370
  5710. We pop it and say okay, here's b,
  5711.  
  5712. 1304
  5713. 01:15:28,370 --> 01:15:31,402
  5714. b is where we were, we go back
  5715. to there and we finish this.
  5716.  
  5717. 1305
  5718. 01:15:31,402 --> 01:15:34,509
  5719. Once we finish this, we say oh
  5720. where we were the last time?
  5721.  
  5722. 1306
  5723. 01:15:34,509 --> 01:15:38,600
  5724. So that's a, and then
  5725. go back to a and finish.
  5726.  
  5727. 1307
  5728. 01:15:38,600 --> 01:15:40,572
  5729. (distant indistinct muttering)
  5730.  
  5731. 1308
  5732. 01:15:48,075 --> 01:15:49,483
  5733. Yeah, sure, yeah, exactly.
  5734.  
  5735. 1309
  5736. 01:15:49,483 --> 01:15:51,193
  5737. (distant indistinct muttering)
  5738.  
  5739. 1310
  5740. 01:15:52,713 --> 01:15:55,791
  5741. Yeah, yeah, so the dialogue which reflects
  5742.  
  5743. 1311
  5744. 01:15:55,791 --> 01:15:58,288
  5745. Little Harmonic Labyrinvth
  5746.  
  5747. 1312
  5748. 01:15:58,288 --> 01:15:59,925
  5749. has this sort of structure.
  5750.  
  5751. 1313
  5752. 01:15:59,925 --> 01:16:01,890
  5753. It goes inside something,
  5754. inside yet another thing
  5755.  
  5756. 1314
  5757. 01:16:01,890 --> 01:16:03,517
  5758. then back out and then back out.
  5759.  
  5760. 1315
  5761. 01:16:03,517 --> 01:16:05,299
  5762. So it's five o'clock, I'm finished.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement