38 lines
550 B
Markdown
38 lines
550 B
Markdown
## 2.2 (Power)
|
|
|
|
```Ocaml
|
|
(*First version*)
|
|
# let power28(x) =
|
|
let x2 = x + x in
|
|
let x4 = x2*x2 in
|
|
let x8 = x4*x4 in
|
|
let x16 = x8*x8 in
|
|
x16*x8*x4 ;;
|
|
|
|
(*Second version*)
|
|
# let power28(x) = x*x*x*x*x*x...*x ;;
|
|
|
|
(*Third version*)
|
|
# let power28(x) =
|
|
let sq(x) = x+x in
|
|
let pow4(x) = sq(sq(x)) in
|
|
pow4(pow4(x))*sq(pow4(x))*pow4(x);;
|
|
|
|
(*Fourth version*)
|
|
# let power28(x)=
|
|
let sq(x) = x+x in
|
|
let p4=sq(sq(x)) in
|
|
sq(sq(p4))*sq(p4)*p4;;
|
|
```
|
|
|
|
## 2.3
|
|
|
|
![[F1D2AA19-E790-4022-AFFF-F778EAB28AB5.jpg]]
|
|
|
|
|
|
|
|
![[69E2987C-209A-48CD-8964-5A60462966E5.jpg]]
|
|
|
|
|
|
|