Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:2024:l09 [2024/04/29 08:40]
tpruteanu
pp:2024:l09 [2024/04/29 15:57] (current)
tpruteanu
Line 151: Line 151:
 -- This is an infinite data type, no way to stop generating the tree -- This is an infinite data type, no way to stop generating the tree
 data StreamBTree = StreamNode Int StreamBTree StreamBTree data StreamBTree = StreamNode Int StreamBTree StreamBTree
 +
 +sbtree = StreamNode 1 sbtree sbtree
  
 </​code>​ </​code>​
Line 159: Line 161:
  
 {- {-
-> sliceTree 2 (repeatTree 3)+> sliceTree 2 sbtree
  
-       3+       1
        |        |
    ​---------    ​---------
    ​| ​      |    ​| ​      |
-         ​3+         ​1
  ​----- ​  ​----- ​  ​----- ​  ​----- ​
  ​| ​  ​| ​  ​| ​  |  ​| ​  ​| ​  ​| ​  |
Line 270: Line 272:
 ==== Mathematical Constants ==== ==== Mathematical Constants ====
  
-**9.3.4.** ​ +**9.3.4.** Knowing that $math[\displaystyle \lim_{n \rightarrow \infty} \frac{F_{n+1}}{F_n} = \varphi], where $math[F_n] is the nth element of the **Fibonacci** sequence, write an\\
- +
-Knowing that $math[\displaystyle \lim_{n \rightarrow \infty} \frac{F_{n+1}}{F_n} = \varphi], where $math[F_n] is the nth element of the **Fibonacci** sequence, write an\\+
 approximation with **tolerance** ''​e=0.00001''​ of the **Golden Ration** ($math[\varphi]). Use the previously defined ''​fibs''​ **stream** and the ''​select''​ function. approximation with **tolerance** ''​e=0.00001''​ of the **Golden Ration** ($math[\varphi]). Use the previously defined ''​fibs''​ **stream** and the ''​select''​ function.
  
Line 281: Line 281:
 </​code>​ </​code>​
  
-**9.3.5.** ​ +**9.3.5.** Consider the //​sequence//:​
- +
-Consider the //​sequence//:​+
  
 $math[a_{n+1} = a_n + sin(a_n)]; where $math[a_0] is an //initial approximation//,​ randomly chosen (but **not** 0 because $math[a_{n+1} != a_n]). $math[a_{n+1} = a_n + sin(a_n)]; where $math[a_0] is an //initial approximation//,​ randomly chosen (but **not** 0 because $math[a_{n+1} != a_n]).
Line 297: Line 295:
 ==== Square Root ==== ==== Square Root ====
  
-**9.3.6.** ​ +**9.3.6.** Given a number ''​k'',​ we want to create a function which calculates the\\
- +
-Given a number ''​k'',​ we want to create a function which calculates the\\+
 **square root** of ''​k''​. This is another place where **laziness** and **streams** come into play.  **square root** of ''​k''​. This is another place where **laziness** and **streams** come into play. 
  
Line 316: Line 312:
 ==== Derivatives ==== ==== Derivatives ====
  
-**9.3.7.** ​ +**9.3.7.** We can approximate the derivative of a function in a certain point using the definition of the derivative:
- +
-We can approximate the derivative of a function in a certain point using the definition of the derivative:+
  
 $math[\displaystyle f'​(a)=\lim_{h \rightarrow 0} \frac{f(a+h)-f(a)}{h}] $math[\displaystyle f'​(a)=\lim_{h \rightarrow 0} \frac{f(a+h)-f(a)}{h}]