Skip to content
Extraits de code Groupes Projets
Valider 7bfc2809 rédigé par Edouard Paris's avatar Edouard Paris
Parcourir les fichiers

methods add, equal of polynome

parent a4085165
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
(*projet AP Edouard Paris 2016*)
open Polynome;;
open Polynome
open Simplepolynome;;
......@@ -5,21 +5,29 @@ open Big_int;;
module type Coefficient =
sig
type coeff
val print_coeff: coeff -> string
val print: coeff -> string
val is_null: coeff -> bool
val add: coeff -> coeff -> coeff
val equal: coeff -> coeff -> bool
end
;;
module type Degree =
sig
type degree
val print_degree: degree -> string
val print: degree -> string
val add: degree -> degree -> degree
val equal: degree -> degree -> bool
val is_bigger: degree -> degree -> bool
end
;;
module type Polynomes =
sig
type polynome
val print_pol: polynome -> string
val print: polynome -> string
val equal: polynome -> polynome -> bool
val add: polynome -> polynome -> polynome
end
;;
......@@ -28,9 +36,41 @@ module Polynome (C : Coefficient) (D : Degree) =
type polynome =
|Null
|NotNull of C.coeff*D.degree*polynome
let rec print_pol p = match p with
let rec print p = match p with
|Null -> "0"
|NotNull (cc, dd, pp)->
(C.print_coeff cc)^"X^"^(D.print_degree dd)^"+"^(print_pol pp)
(C.print cc)^"X^"^(D.print dd)^"+"^(print pp)
let rec equal x y = match x with
|Null ->
(match y with
|Null -> true
|NotNull (_, _, _)-> false)
|NotNull (cx, dx, xx)->
(match y with
|Null -> false
|NotNull (cy, dy, yy) ->
if D.equal dx dy
then
if C.equal cx cy
then equal xx yy
else false
else false)
let rec add x y = match x with
|Null -> y
|NotNull (cx, dx, xx)->
(match y with
|Null -> x
|NotNull (cy, dy, yy)->
if D.is_bigger dy dx
then NotNull (cy, dy, add x yy)
else
if D.is_bigger dx dy
then NotNull (cx, dx, add xx yy)
else
let m = C.add cx cy in
if C.is_null m
then add xx yy
else NotNull (m, dx, add xx yy)
)
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