Merge branch 'maudule'
Ajout du joli système de modules, qui est très pratique pour utiliser les fonctions, mais moins pour les modifier
This commit is contained in:
commit
2c864f9957
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
*.cmi
|
*.cmi
|
||||||
*.cmx
|
*.cmx
|
||||||
|
*.cmo
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
*.ascii.txt
|
*.ascii.txt
|
||||||
|
|||||||
@ -22,22 +22,31 @@
|
|||||||
* on représente un vecteur dans F_2 par un entier dont la décomposition binaire correspond aux composantes du vecteur
|
* on représente un vecteur dans F_2 par un entier dont la décomposition binaire correspond aux composantes du vecteur
|
||||||
* on représente une matrice par un liste d'entier, il s'agit de la liste de ses colonnes (qui sont donc des vecteurs)
|
* 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";;
|
||||||
*)
|
*)
|
||||||
|
|
||||||
#cd "/home/mysaa/Documents/Arbeiten/TIPE2021";;
|
open Math;;
|
||||||
#use "Maths.ml";;
|
|
||||||
|
(*************************************************************)
|
||||||
|
(************************Module CLineaire*********************)
|
||||||
|
(*************************************************************)
|
||||||
|
|
||||||
|
module CLineaire =
|
||||||
|
struct
|
||||||
|
;;
|
||||||
|
|
||||||
(* La bonne structure *)
|
(* La bonne structure *)
|
||||||
type code_lineaire = {klin : int; nlin : int; g : matrice; h : matrice};;
|
type t = {k : int; n : int; g : Math.matrice; h : Math.matrice};;
|
||||||
|
type code_lineaire = t;; (* Le type du module *)
|
||||||
(* La super stucture *)
|
|
||||||
type code_cyclique = {kcyc : int; ncyc: int; pol: polynome};;
|
|
||||||
|
|
||||||
(* Calcule Y = GX *)
|
(* Calcule Y = GX *)
|
||||||
let encoder code x = produit code.g x ;;
|
let encoder code x = produit code.g x ;;
|
||||||
|
|
||||||
|
|
||||||
(* Le nom de cette fonction n'est pas assez explicite *)
|
let systematiqueFromRedondance k n redondance =
|
||||||
let construire_code_lineaire_systematique k n redondance =
|
|
||||||
let g =
|
let g =
|
||||||
let decalage = deux_puissance k in
|
let decalage = deux_puissance k in
|
||||||
let rec iteredon ajout = function
|
let rec iteredon ajout = function
|
||||||
@ -47,36 +56,9 @@ let construire_code_lineaire_systematique k n redondance =
|
|||||||
c :: (iteredon (ajout * 2) queue)
|
c :: (iteredon (ajout * 2) queue)
|
||||||
in iteredon 1 redondance
|
in iteredon 1 redondance
|
||||||
and h = redondance @ (identite (n-k)) in
|
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 *)
|
(* 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 suivants d vecteurs =
|
||||||
let contraintes = ref [] in
|
let contraintes = ref [] in
|
||||||
@ -100,6 +82,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é *)
|
(* 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 plus_petit_verifiant propriete poids_max d =
|
||||||
let rec chercher p vecteurs =
|
let rec chercher p vecteurs =
|
||||||
@ -112,20 +95,12 @@ let plus_petit_verifiant propriete poids_max d =
|
|||||||
in chercher 0 [0]
|
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;;
|
exception PasDansLeCodeException;;
|
||||||
|
|
||||||
(* Calcul de façons à ouf l'antécédent de 'y' pour le code 'code' *)
|
(* Calcul de façons à ouf l'antécédent de 'y' pour le code 'code' *)
|
||||||
let antecedent code y =
|
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
|
let rec iterer = function
|
||||||
| x when x = mot_max -> raise PasDansLeCodeException
|
| x when x = mot_max -> raise PasDansLeCodeException
|
||||||
| x ->
|
| x ->
|
||||||
@ -136,10 +111,20 @@ let antecedent code y =
|
|||||||
|
|
||||||
exception IndecodableException;;
|
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é *)
|
(* Applique notre algorithme préféré *)
|
||||||
let decoder code z =
|
let decoder code z =
|
||||||
let d_min = distance_minimale code in
|
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
|
let propriete = fun v -> appartenir code ((lxor) z v) in
|
||||||
match plus_petit_verifiant propriete e_c n with
|
match plus_petit_verifiant propriete e_c n with
|
||||||
| (-1, 0) -> raise IndecodableException
|
| (-1, 0) -> raise IndecodableException
|
||||||
@ -149,4 +134,61 @@ let decoder code z =
|
|||||||
let cyclencode code (x:vecteur) :vecteur = polmul code.pol x;;
|
let cyclencode code (x:vecteur) :vecteur = polmul code.pol x;;
|
||||||
|
|
||||||
|
|
||||||
|
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à *)
|
(* Voilà *)
|
||||||
27
Code.mli
Normal file
27
Code.mli
Normal file
@ -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
|
||||||
10
Makefile
10
Makefile
@ -7,6 +7,14 @@ ascii: $(shell find textes/ -type f -iname "*.txt" ! -iname "*.ascii.txt" | sed
|
|||||||
%.cmx: %.ml
|
%.cmx: %.ml
|
||||||
ocamlopt -c $<
|
ocamlopt -c $<
|
||||||
|
|
||||||
|
Code.cmo: Math.cmo
|
||||||
|
|
||||||
|
%.cmi: %.mli
|
||||||
|
ocamlc -c $<
|
||||||
|
%.cmo: %.ml
|
||||||
|
if [ -f $*".mli" ]; then ocamlc -c $*".mli" ; fi
|
||||||
|
ocamlc -c $<
|
||||||
|
|
||||||
tipe: tipe.cmx
|
tipe: tipe.cmx
|
||||||
ocamlopt -o tipe str.cmxa tipe.cmx
|
ocamlopt -o tipe str.cmxa tipe.cmx
|
||||||
|
|
||||||
@ -16,4 +24,4 @@ tipe: tipe.cmx
|
|||||||
runall: $(shell find textes/ -type f -iname "*.txt" ! -iname "*.ascii.txt" | sed "s/\.txt/\.txt\.test/")
|
runall: $(shell find textes/ -type f -iname "*.txt" ! -iname "*.ascii.txt" | sed "s/\.txt/\.txt\.test/")
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf tipe *.cmx *.cmi *.o textes/*.ascii.txt
|
rm -rf tipe *.cmx *.cmi *.cmo *.o textes/*.ascii.txt *.ntl.ml
|
||||||
|
|||||||
20
Math.mli
Normal file
20
Math.mli
Normal file
@ -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
|
||||||
31
Test.ml
31
Test.ml
@ -1,5 +1,10 @@
|
|||||||
#cd "/home/mysaa/Documents/Arbeiten/TIPE2021";;
|
#cd "/home/mysaa/Documents/Arbeiten/TIPE2021";;
|
||||||
#use "Codes.ml";;
|
Sys.command "make Math.cmo Code.cmo";;
|
||||||
|
#load "Math.cmo";;
|
||||||
|
#load "Code.cmo";;
|
||||||
|
|
||||||
|
open Math;;
|
||||||
|
open Code;;
|
||||||
|
|
||||||
(* Test du produit de matrice *)
|
(* Test du produit de matrice *)
|
||||||
let matest = [0b01110; 0b00101; 0b10111];;
|
let matest = [0b01110; 0b00101; 0b10111];;
|
||||||
@ -35,10 +40,10 @@ respecter 7 [3];;
|
|||||||
-> les 3 dernières lignes : H
|
-> les 3 dernières lignes : H
|
||||||
*)
|
*)
|
||||||
let code_hamming =
|
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;;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -48,24 +53,21 @@ for i=0 to 20
|
|||||||
do
|
do
|
||||||
Random.self_init ();
|
Random.self_init ();
|
||||||
let matPapa = matriceAuPif 9 12 in
|
let matPapa = matriceAuPif 9 12 in
|
||||||
let code_paparfait = construire_code_lineaire_systematique 12 21 matPapa in
|
let code_paparfait = CLineaire.systematiqueFromRedondance 12 21 matPapa in
|
||||||
let dst = distance_minimale code_paparfait in
|
let dst = CLineaire.distance_minimale code_paparfait in
|
||||||
if dst>1
|
if dst>1
|
||||||
then raise (GTROUVE matPapa)
|
then raise (GTROUVE matPapa)
|
||||||
done;;
|
done;;
|
||||||
|
|
||||||
|
|
||||||
|
print_vecteur 7 (CLineaire.encoder code_hamming 0b0100);;
|
||||||
print_matrice 3 (suivants 3 (suivants 3 (suivants 3 (suivants 3 [0b000]))));;
|
CLineaire.decoder code_hamming 0b1010100;;
|
||||||
|
CLineaire.decoder code_hamming 0b0010100;;
|
||||||
print_vecteur 7 (encoder code_hamming 0b0100);;
|
CLineaire.decoder code_hamming 0b1110000;;
|
||||||
decoder code_hamming 0b1010100;;
|
|
||||||
decoder code_hamming 0b0010100;;
|
|
||||||
decoder code_hamming 0b1110000;;
|
|
||||||
print_vecteur 7 21;;
|
print_vecteur 7 21;;
|
||||||
|
|
||||||
(* Tests des codes cycliques *)
|
(* Tests des codes cycliques *)
|
||||||
let cocycl = {ncyc=7;kcyc=4;pol=13};;
|
let cocycl = CCyclique.get 7 4 13;;
|
||||||
print_polynome cocycl.pol;;
|
print_polynome cocycl.pol;;
|
||||||
poldiveuc ((deux_puissance 7) +1) cocycl.pol;;
|
poldiveuc ((deux_puissance 7) +1) cocycl.pol;;
|
||||||
print_polynome ((deux_puissance 7) +1);;
|
print_polynome ((deux_puissance 7) +1);;
|
||||||
@ -73,7 +75,8 @@ print_polynome (poldiv ((deux_puissance 7) +1) cocycl.pol);;
|
|||||||
let cocylined = cycliqueVersLineaire cocycl;;
|
let cocylined = cycliqueVersLineaire cocycl;;
|
||||||
print_matrice 7 cocylined.g;;
|
print_matrice 7 cocylined.g;;
|
||||||
print_matrice 4 cocylined.h;;
|
print_matrice 4 cocylined.h;;
|
||||||
distance_minimale cocylined;;
|
|
||||||
|
CLineaire.distance_minimale cocylined;;
|
||||||
|
|
||||||
print_vecteur 7 (cyclencode cocycl 0b1010);;
|
print_vecteur 7 (cyclencode cocycl 0b1010);;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user