# Breaking the formulas --- ## How to write a complex formula in TAAL? $$\frac{(123 + 420) \cdot (560 - 32) - 276 \cdot 4}{765 + 187}$$ --- ## Step \#1 Our goal is to translate the infix form to the prefix. Find the latest action in the math expression! ---- $$\frac{\color{#900}{(123 + 420) \cdot (560 - 32) - 276 \cdot 4}}{\color{#00c}{765 + 187}}$$ In our case, it is a **division**. $$\frac{\color{#900}{<top\ section>}}{\color{#00c}{<bottom\ section>}}$$ Never mind about numerator and denominator now! --- ## Step \#2 Write the found action in TAAL. ```lisp (/ <top section> <bottom section>) ``` We just have excluded one action from our complex formula. But we need to go forward. --- ## The repetition loop of two steps To get the answer we need to parse the top and bottom sections step by step. Begin from a bottom _(because it is more simple, we have a plain denominator)_. $$765 + 187$$ It is just a sum of two elements. Write it in TAAL. ```lisp (/ <top section> (+ 765 187)) ``` ---- Take a look at the top section now. $$(123 + 420) \cdot (560 - 32) - 276 \cdot 4$$ Now just repeat Step \#1 and find the latest action for the part of the formula. ---- As you can see it is **subtraction**. $$<left> - <right>$$ As in the previous step do not figure out about the left and the right. ---- Just repeat Step \#2 and improve our formula in TAAL. ```lisp (/ (- <left> <right>) (+ 765 187)) ``` Now we may simplify the part of the top section. ---- The first look at the \<right\> placeholder says us to simplify it first. So... $$276 \cdot 4$$ becomes ```lisp (* 276 4) ``` and inserts in the formula. ```lisp (/ (- <left> (* 276 4)) (+ 765 187)) ``` ---- We strait see the finish line. Just do both steps one more time and have the result. $$(123 + 420) \cdot (560 - 32)$$ The last action here is **multiplication**. So we have... ```lisp (* <sum> <subtraction>) ``` ---- Put it to TAAL formula again. ```lisp (/ (- (* <sum> <subtraction>) (* 276 4)) (+ 765 187)) ``` The last step is absolutely obvious. Just do it. ---- $$123 + 420$$ ```lisp (+ 123 420) ``` $$560 - 32$$ ```lisp (- 560 32) ``` ### The final ```lisp (/ (- (* (+ 123 420) (- 560 32)) (* 276 4)) (+ 765 187)) ``` --- ## Complete result $$\frac{(123 + 420) \cdot (560 - 32) - 276 \cdot 4}{765 + 187}$$ ```lisp (/ (- (* (+ 123 420) (- 560 32)) (* 276 4)) (+ 765 187)) ``` If you will put the formula to the interpreter and execute it you see the answer **300**. Well done! ---- ## All steps together. $$\frac{(123 + 420) \cdot (560 - 32) - 276 \cdot 4}{765 + 187}$$ ```lisp (/ <top section> <bottom section>) (/ <top section> (+ 765 187)) (/ (- <left> <right>) (+ 765 187)) (/ (- <left> (* 276 4)) (+ 765 187)) (/ (- (* <sum> <subtraction>) (* 276 4)) (+ 765 187)) (/ (- (* (+ 123 420) (- 560 32)) (* 276 4)) (+ 765 187)) ``` ---- To see and better understand the TAAL prefix notation just look at the formula again in the formatted view. ```lisp= (/ (- (* (+ 123 420) (- 560 32) ) (* 276 4) ) (+ 765 187) ) ``` --- ## Control tasks $$\frac{4+6}{5\cdot2}+3\cdot\frac{5+5}{1+\frac{1}{2}} \tag{1}$$ $$\sqrt{\left(\frac{4\cdot2+1}{1+2}\right)^2+\left(\sqrt{2\cdot(3+5)}\right)^2} \tag{2}$$ ---- ## Answers $$\frac{4+6}{5\cdot2}+3\cdot\frac{5+5}{1+\frac{1}{2}} = 21 \tag{1}$$ $$\sqrt{\left(\frac{4\cdot2+1}{1+2}\right)^2+\left(\sqrt{2\cdot(3+5)}\right)^2} = 5 \tag{2}$$ --- # The end.
{"metaMigratedAt":"2023-06-15T15:46:15.346Z","metaMigratedFrom":"Content","title":"Breaking the formulas","breaks":true,"contributors":"[{\"id\":\"50e50a49-9bd5-469a-bb18-7a083a8b3cc0\",\"add\":4923,\"del\":1325}]"}
    197 views