diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 15bbd93..e0fc82e 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -148,10 +148,10 @@ }, "active": "13c9bfe482ec2d42", "lastOpenFiles": [ - "Algo/Séminaire/Introduction.md", - "Algo/Séminaire/Exercices sémaines.md", - "Algo/Séminaire/Chapter 2 - Functions.md", "Algo/Séminaire/Chapter 1 - CAML basics.md", + "Algo/Séminaire/Chapter 2 - Functions.md", + "Algo/Séminaire/Exercices sémaines.md", + "Algo/Séminaire/Introduction.md", "Algo/Séminaire/assets/69E2987C-209A-48CD-8964-5A60462966E5.jpg", "Algo/Séminaire/assets", "Algo/Séminaire/assets/F1D2AA19-E790-4022-AFFF-F778EAB28AB5.jpg", diff --git a/Algo/Séminaire/Chapter 1 - CAML basics.md b/Algo/Séminaire/Chapter 1 - CAML basics.md index 195e890..4564939 100644 --- a/Algo/Séminaire/Chapter 1 - CAML basics.md +++ b/Algo/Séminaire/Chapter 1 - CAML basics.md @@ -11,20 +11,20 @@ It's a simple language to write. - **;;** is the end of the line ```Ocaml -_: int=3 *That a Caml answer to the previus program* +_: int=3 (*That a Caml answer to the previus program*) ``` ```Ocaml -# 1+2.2;; *That an error* +# 1+2.2;; (*That an error*) -# 1. +. 2.2;; *This is good* +# 1. +. 2.2;; (*This is good*) ``` ## 1.2. CAML interaction ```Ocaml -# 1;; *He can be a simple expression* +# 1;; (*He can be a simple expression*) _: int=1 -# "Hello World";; *He can be a string* +# "Hello World";; (*He can be a string*) _:string = "Hello World" ``` @@ -38,10 +38,10 @@ _: type of the evaluation = result of the evaluation ### Global definitions ```Ocaml # let x=1+2;; -val x:int = 3 *our current env is x -> 3* +val x:int = 3 (*our current env is x -> 3*) # let y=x/2;; -val y:int = 1 *our current env is x -> 3 ; y -> 1* +val y:int = 1 (*our current env is x -> 3 ; y -> 1*) # let x = 2 val x : int = 2 @@ -61,7 +61,7 @@ _ : float = 6.28 _ : float = 30 # x;; -_ : int =2 *see global definition section* +_ : int =2 (*see global definition section*) # pi;; error: unbound value pi @@ -71,15 +71,14 @@ when there is the keyword ``len``and ``in`` that create a local definition. A lo ### Multiple definitions ```Ocaml -# let r = 1. and pi : 3.14 in 2 *. pi *. r;; *local version* +# let r = 1. and pi : 3.14 in 2 *. pi *. r;; (*local version*) _ : float = 6.28 # let x = 1.2 and y = "Hello";; -val x: float = 1.2 *our current env is x -> 3 ; y -> 1 ; x -> 1.2 * -val y: string = "Hello" *our current env is x -> 3 ; y -> 1 ; x -> 1.2 ; y -> "Hello"* - +val x: float = 1.2 (*our current env is x -> 3 ; y -> 1 ; x -> 1.2 *) +val y: string = "Hello" (*our current env is x -> 3 ; y -> 1 ; x -> 1.2 ; y -> "Hello"*) # let x = 2 and y = x + 1 in y + 2;; -Error *because x is 1.2 in our current evaluation* +Error (*because x is 1.2 in our current evaluation*) ``` > ⚠️ We have only one `let` and one `in` for the multiple definitions methods @@ -129,7 +128,7 @@ _: bool = false - String: `string` ```Ocaml # "ab" < "abc" ;; -_: bool = true *because O chars -> 2^24 - 6 chars* +_: bool = true (*because O chars -> 2^24 - 6 chars*) # "Hello" ^" World" _: string = "Hello World" diff --git a/Algo/Séminaire/Chapter 2 - Functions.md b/Algo/Séminaire/Chapter 2 - Functions.md index 75e63c6..5c408ab 100644 --- a/Algo/Séminaire/Chapter 2 - Functions.md +++ b/Algo/Séminaire/Chapter 2 - Functions.md @@ -25,7 +25,7 @@ val g: int -> int = # fg 3;; Error: was expecting an integer and get a function -# f(g 3);; *This way there is no error* +# f(g 3);; (*This way there is no error*) _: int = 7 ``` @@ -47,7 +47,7 @@ _: float -> int = # length "toto" ;; Error : Unboud -# String.lenght "toto";; *String is a library* +# String.lenght "toto";; (*String is a library*) _: int = 4 ``` @@ -71,5 +71,5 @@ val square_of_pred: int -> int = val pred: int -> int = # square_of_pred 3;; -_: int = 4 *same things but with another method* +_: int = 4 (*same things but with another method*) ``` diff --git a/Algo/Séminaire/Exercices sémaines.md b/Algo/Séminaire/Exercices sémaines.md index 4237a26..7552bc6 100644 --- a/Algo/Séminaire/Exercices sémaines.md +++ b/Algo/Séminaire/Exercices sémaines.md @@ -1,7 +1,7 @@ ## 2.2 (Power) ```Ocaml -(*First version*) +(*First version ; 6 multiplications*) # let power28(x) = let x2 = x + x in let x4 = x2*x2 in @@ -9,16 +9,16 @@ let x16 = x8*x8 in x16*x8*x4 ;; -(*Second version*) +(*Second version ; 27 multiplications*) # let power28(x) = x*x*x*x*x*x...*x ;; -(*Third version*) +(*Third version ; 11 multiplications*) # let power28(x) = - let sq(x) = x+x in + let sq(x) = x*x in let pow4(x) = sq(sq(x)) in pow4(pow4(x))*sq(pow4(x))*pow4(x);; -(*Fourth version*) +(*Fourth version ; 7 multiplications*) # let power28(x)= let sq(x) = x+x in let p4=sq(sq(x)) in