Skip to content
Extraits de code Groupes Projets
Valider 15933da2 rédigé par EdouardParis's avatar EdouardParis
Parcourir les fichiers

change indentation and finish naive_mul

parent f25aa29a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -7,8 +7,9 @@ module type Coefficient =
type coeff
val print: coeff -> string
val is_null: coeff -> bool
val add: coeff -> coeff -> coeff
val equal: coeff -> coeff -> bool
val add: coeff -> coeff -> coeff
val mul: coeff -> coeff -> coeff
end
;;
......@@ -42,8 +43,7 @@ module Polynome (C : Coefficient) (D : Degree) =
|NotNull (cc, dd, pp)->
(C.print cc)^"X^"^(D.print dd)^"+"^(print pp)
let rec equal x y = match x with
|Null ->
(match y with
|Null -> (match y with
|Null -> true
|NotNull (_, _, _)-> false)
|NotNull (cx, dx, xx)->
......@@ -55,7 +55,8 @@ module Polynome (C : Coefficient) (D : Degree) =
if C.equal cx cy
then equal xx yy
else false
else false)
else false
)
let rec add x y = match x with
|Null -> y
|NotNull (cx, dx, xx)->
......@@ -73,17 +74,24 @@ module Polynome (C : Coefficient) (D : Degree) =
then add xx yy
else NotNull (m, dx, add xx yy)
)
(*let rec naive_mul x y = match x with
(*private function for incrementing the degree of a polynome*)
let rec increment_degree d x = match x with
|Null -> Null
|NotNull (cx, dx, xx)-> NotNull (cx, (D.add d dx), (increment_degree d xx))
(*private function in order to multiply all the coeffs of a pol*)
let rec multiply_coeffs c x = match x with
|Null -> Null
|NotNull -> (cx, dx, xx)->
|NotNull (cx, dx, xx) ->
if C.is_null c then Null
else NotNull ((C.mul c cx), dx, (multiply_coeffs c xx))
(*Naive multiplication of two polynomes*)
let rec naive_mul x y = match x with
|Null -> Null
|NotNull (cx, dx, xx) ->
(match y with
|Null -> Null
|NotNull (cy, dy, yy)->
match xx with
|Null
|NotNull
|NotNull (_, _, _)->
add (increment_degree dx (multiply_coeffs cx y))(naive_mul xx y)
)
*)
end
;;
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter