diff --git a/Code.ml b/Code.ml index f754ac6..66e4583 100644 --- a/Code.ml +++ b/Code.ml @@ -23,24 +23,29 @@ * on représente une matrice par un liste d'entier, il s'agit de la liste de ses colonnes (qui sont donc des vecteurs) *) - +(* #cd "/home/mysaa/Documents/Arbeiten/TIPE2021/";; #load "Math.cmo";; +*) open Math;; -(* La bonne structure *) -type code_lineaire = {klin : int; nlin : int; g : matrice; h : Math.matrice};; +(*************************************************************) +(************************Module CLineaire*********************) +(*************************************************************) -(* La super stucture *) -type code_cyclique = {kcyc : int; ncyc: int; pol: polynome};; +module CLineaire = +struct + +(* La bonne structure *) +type t = {k : int; n : int; g : Math.matrice; h : Math.matrice};; +type code_lineaire = t;; (* Le type du module *) (* Calcule Y = GX *) let encoder code x = produit code.g x ;; -(* Le nom de cette fonction n'est pas assez explicite *) -let construire_code_lineaire_systematique k n redondance = +let systematiqueFromRedondance k n redondance = let g = let decalage = deux_puissance k in let rec iteredon ajout = function @@ -50,36 +55,9 @@ let construire_code_lineaire_systematique k n redondance = c :: (iteredon (ajout * 2) queue) in iteredon 1 redondance and h = redondance @ (identite (n-k)) in - {klin = k; nlin = n; g = g; h = h} + {k = k; n = n; g = g; h = h} ;; -(* Construit le code linéaire associé au code cyclique *) -let cycliqueVersLineaire code = - let k=code.kcyc and n=code.ncyc and pol=code.pol in - let g = - let rec itdecal i l = - if i<0 - then l - else itdecal (i-1) ((pol lsl i)::l) - in itdecal (k-1) [] - and h = - let polh = poldiv ((deux_puissance n) + 1) pol in - print_polynome polh; - let filtre = (deux_puissance (n-k+1))-1 in - let rec sub i l = - if i<(-k) - then l - else sub (i-1) (((decagauche polh i) land filtre)::l) - in sub (n-k-1) [] - in {klin = k; nlin = n; g = g; h = h} -;; - - -let lineaireVersCyclique code = - (*TODO*)1 -;; - - (* Etant donnés tous les vecteurs de poids p dans un espace de dimension d, retourne touts ceux de poids p+1 dans ce même espace *) let suivants d vecteurs = let contraintes = ref [] in @@ -103,6 +81,7 @@ let suivants d vecteurs = ;; + (* Renvoit le plus petit mot (au sens de Hamming) dans F_2^d vérifiant 'propriete' et de poids inférieur à poids_max. Renvoie le couple (-1, 0) si aucun mot n'a été trouvé *) let plus_petit_verifiant propriete poids_max d = let rec chercher p vecteurs = @@ -115,20 +94,12 @@ let plus_petit_verifiant propriete poids_max d = in chercher 0 [0] ;; -let appartenir code v = produit code.h v = 0;; - -(* Calcul la distance minimale d'un code *) -let distance_minimale code = - let n = code.nlin in - let propriete = fun v -> (0 < v) && (appartenir code v) in - let (p, _) = plus_petit_verifiant propriete n n in p -;; exception PasDansLeCodeException;; (* Calcul de façons à ouf l'antécédent de 'y' pour le code 'code' *) let antecedent code y = - let mot_max = (deux_puissance code.klin) - 1 in + let mot_max = (deux_puissance code.k) - 1 in let rec iterer = function | x when x = mot_max -> raise PasDansLeCodeException | x -> @@ -139,10 +110,20 @@ let antecedent code y = exception IndecodableException;; + +let appartenir code v = produit code.h v = 0;; + +(* Calcul la distance minimale d'un code *) +let distance_minimale code = + let n = code.n in + let propriete = fun v -> (0 < v) && (appartenir code v) in + let (p, _) = plus_petit_verifiant propriete n n in p +;; + (* Applique notre algorithme préféré *) let decoder code z = let d_min = distance_minimale code in - let e_c = (d_min - 1) / 2 and n = code.nlin in + let e_c = (d_min - 1) / 2 and n = code.n in let propriete = fun v -> appartenir code ((lxor) z v) in match plus_petit_verifiant propriete e_c n with | (-1, 0) -> raise IndecodableException @@ -150,4 +131,61 @@ let decoder code z = ;; +end;; + +(*************************************************************) +(************************Module CCyclique*********************) +(*************************************************************) + +module CCyclique = +struct +;; +(* La super stucture *) +type t = {k : int; n: int; pol: polynome};; +type code_cyclique = t;; + +let get k n pol = {k=k;n=n;pol=pol};; + + +end;; + +(*************************************************************) +(*****************************Suite***************************) +(*************************************************************) + +open CLineaire;; +open CCyclique;; + +(* Construit le code linéaire associé au code cyclique *) +let cycliqueVersLineaire code = + let k=code.k and n=code.n and pol=code.pol in + let g = + let rec itdecal i l = + if i<0 + then l + else itdecal (i-1) ((pol lsl i)::l) + in itdecal (k-1) [] + and h = + let polh = poldiv ((deux_puissance n) + 1) pol in + print_polynome polh; + let filtre = (deux_puissance (n-k+1))-1 in + let rec sub i l = + if i<(-k) + then l + else sub (i-1) (((decagauche polh i) land filtre)::l) + in sub (n-k-1) [] + in {k = k; n = n; g = g; h = h} +;; + + +let lineaireVersCyclique code = + (*TODO*)1 +;; + + + + + + + (* Voilà *) \ No newline at end of file diff --git a/Code.mli b/Code.mli new file mode 100644 index 0000000..4f845ee --- /dev/null +++ b/Code.mli @@ -0,0 +1,27 @@ +module CLineaire : +sig +type t = { + k : int; + n : int; + g : Math.matrice; + h : Math.matrice; } +type code_lineaire = t + +val encoder : code_lineaire -> Math.vecteur -> Math.vecteur +val systematiqueFromRedondance : int -> int -> int list -> code_lineaire +val distance_minimale : code_lineaire -> int +val decoder : code_lineaire -> int -> Math.vecteur +val appartenir : code_lineaire -> Math.vecteur -> bool +end + +module CCyclique : +sig + type t = { + k : int; + n : int; + pol : Math.polynome; } + + val get : int -> int -> Math.polynome -> t +end + +val cycliqueVersLineaire : CCyclique.t -> CLineaire.t diff --git a/AlgCodeCycl.pdf b/Documents/AlgCodeCycl.pdf similarity index 100% rename from AlgCodeCycl.pdf rename to Documents/AlgCodeCycl.pdf diff --git a/Cours_Pierre_Abbrugiati.pdf b/Documents/Cours_Pierre_Abbrugiati.pdf similarity index 100% rename from Cours_Pierre_Abbrugiati.pdf rename to Documents/Cours_Pierre_Abbrugiati.pdf diff --git a/m89lm1ea.pdf b/Documents/m89lm1ea.pdf similarity index 100% rename from m89lm1ea.pdf rename to Documents/m89lm1ea.pdf diff --git a/Makefile b/Makefile index 02d022d..6108f82 100644 --- a/Makefile +++ b/Makefile @@ -7,16 +7,13 @@ ascii: $(shell find textes/ -type f -iname "*.txt" ! -iname "*.ascii.txt" | sed %.cmx: %.ml ocamlopt -c $< -%.cmo: %.ml +Code.cmo: Math.cmo + +%.cmi: %.mli + ocamlc -c $< +%.cmo: %.ml + if [ -f $*".mli" ]; then ocamlc -c $*".mli" ; fi ocamlc -c $< - - -Code.cmo: Code.ml Math.cmo - mkdir tmp - cat Code.ml | sed '/^#/d' > tmp/Code.ml - ocamlc -c tmp/Code.ml Math.cmo - mv tmp/Code.cmo Code.cmo - rm -r tmp tipe: tipe.cmx ocamlopt -o tipe str.cmxa tipe.cmx diff --git a/Math.mli b/Math.mli new file mode 100644 index 0000000..48f67f9 --- /dev/null +++ b/Math.mli @@ -0,0 +1,20 @@ +type vecteur = int +type matrice = int list +type polynome = int +val nthOfBinarint : int -> int -> string +val print_matrice : int -> matrice -> unit +val print_vecteur : int -> vecteur -> unit +val print_polynome : polynome -> unit +val produit : matrice -> vecteur -> vecteur +val deux_puissance : int -> int +val orderize : 'a -> 'a -> 'a * 'a +val identite : int -> int list +val changer_bit : int -> int -> int +val decagauche : int -> int -> int +val respecter : int -> int list -> bool +val matriceAuPif : int -> int -> matrice +val polmul : polynome -> polynome -> polynome +val degre : polynome -> int +val poldiveuc : polynome -> polynome -> polynome * polynome +val poldiv : polynome -> polynome -> polynome +val polrst : polynome -> polynome -> polynome diff --git a/Test.ml b/Test.ml index 8656e08..439b43b 100644 --- a/Test.ml +++ b/Test.ml @@ -2,6 +2,7 @@ Sys.command "make Math.cmo Code.cmo";; #load "Math.cmo";; #load "Code.cmo";; + open Math;; open Code;; @@ -39,10 +40,10 @@ respecter 7 [3];; -> les 3 dernières lignes : H *) let code_hamming = - construire_code_lineaire_systematique 4 7 [7; 3; 5; 6] + CLineaire.systematiqueFromRedondance 4 7 [7; 3; 5; 6] ;; -distance_minimale code_hamming;; +CLineaire.distance_minimale code_hamming;; @@ -52,25 +53,22 @@ for i=0 to 20 do Random.self_init (); let matPapa = matriceAuPif 9 12 in - let code_paparfait = construire_code_lineaire_systematique 12 21 matPapa in - let dst = distance_minimale code_paparfait in + let code_paparfait = CLineaire.systematiqueFromRedondance 12 21 matPapa in + let dst = CLineaire.distance_minimale code_paparfait in if dst>1 then raise (GTROUVE matPapa) done;; -print_vecteur 21 (encoder code_paparfait 0b011011011001);; +print_vecteur 21 (CLineaire.encoder code_paparfait 0b011011011001);; - -print_matrice 3 (suivants 3 (suivants 3 (suivants 3 (suivants 3 [0b000]))));; - -print_vecteur 7 (encoder code_hamming 0b0100);; -decoder code_hamming 0b1010100;; -decoder code_hamming 0b0010100;; -decoder code_hamming 0b1110000;; +print_vecteur 7 (CLineaire.encoder code_hamming 0b0100);; +CLineaire.decoder code_hamming 0b1010100;; +CLineaire.decoder code_hamming 0b0010100;; +CLineaire.decoder code_hamming 0b1110000;; print_vecteur 7 21;; (* Tests des codes cycliques *) -let cocycl = {ncyc=7;kcyc=4;pol=13};; +let cocycl = CCyclique.get 7 4 13;; print_polynome cocycl.pol;; poldiveuc ((deux_puissance 7) +1) cocycl.pol;; print_polynome ((deux_puissance 7) +1);; @@ -78,4 +76,4 @@ print_polynome (poldiv ((deux_puissance 7) +1) cocycl.pol);; let cocylined = cycliqueVersLineaire cocycl;; print_matrice 7 cocylined.g;; print_matrice 4 cocylined.h;; -distance_minimale cocylined;; +CLineaire.distance_minimale cocylined;;