Changeset 7f3ad4 in git for Singular/LIB/decodegb.lib
- Timestamp:
- Jan 14, 2009, 5:07:05 PM (15 years ago)
- Branches:
- (u'spielwiese', 'd0474371d8c5d8068ab70bfb42719c97936b18a6')
- Children:
- 0721816437af5ddabc83aa203a12d9b58b42a33c
- Parents:
- 95edd5641377e851d4a1d4e986853687991d0895
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/decodegb.lib
r95edd5 r7f3ad4 1 1 /////////////////////////////////////////////////////////////////////////////// 2 version="$Id: decodegb.lib,v 1. 8 2008-10-22 13:31:48 bulyginExp $";2 version="$Id: decodegb.lib,v 1.9 2009-01-14 16:07:03 Singular Exp $"; 3 3 category="Coding theory"; 4 4 info=" 5 5 LIBRARY: decodegb.lib Decoding and min distance of linear codes with GB 6 AUTHOR: Stanislav Bulygin, bulygin@mathematik.uni-kl.de 6 AUTHOR: Stanislav Bulygin, bulygin@mathematik.uni-kl.de 7 7 8 8 OVERVIEW: 9 9 In this library we generate several systems used for decoding cyclic codes and 10 finding their minimum distance. Namely, we work with the Cooper's philosophy 11 and generalized Newton identities. The original method of quadratic equations 12 is worked out here as well. We also (for comparison) enable to work with the 13 system of Fitzgerald-Lax. We provide some auxiliary functions for further 14 manipulations and decoding. For an overview of the methods mentioned above @ref{Decoding codes with GB} 15 For the vanishing ideal computation the algorithm of Farr and Gao is 10 finding their minimum distance. Namely, we work with the Cooper's philosophy 11 and generalized Newton identities. The original method of quadratic equations 12 is worked out here as well. We also (for comparison) enable to work with the 13 system of Fitzgerald-Lax. We provide some auxiliary functions for further 14 manipulations and decoding. For an overview of the methods mentioned above @ref{Decoding codes with GB} 15 For the vanishing ideal computation the algorithm of Farr and Gao is 16 16 implemented. 17 17 18 MAIN PROCEDURES: 18 MAIN PROCEDURES: 19 19 sysCRHT(..); generates the CRHT-ideal as in Cooper's philosophy 20 20 sysCRHTMindist(..); CRHT-ideal to find the minimum distance in the binary case … … 29 29 genMDSMat(n,a); generates an MDS (actually an RS) matrix 30 30 mindist(check); computes the minimum distance of a code 31 decode(rec); decoding of a word using the system of quadratic equations 31 decode(rec); decoding of a word using the system of quadratic equations 32 32 decodeRandom(..); a procedure for manipulation with random codes 33 33 decodeCode(..); a procedure for manipulation with the given code … … 35 35 sysFL(..); generates the Fitzgerald-Lax system 36 36 decodeRandomFL(..); manipulation with random codes via Fitzgerald-Lax 37 38 39 KEYWORDS: Cyclic code; Linear code; Decoding; 37 38 39 KEYWORDS: Cyclic code; Linear code; Decoding; 40 40 Minimum distance; Groebner bases 41 41 "; … … 76 76 77 77 /////////////////////////////////////////////////////////////////////////////// 78 // the polynomial for Sala's restrictions 78 // the polynomial for Sala's restrictions 79 79 static proc p_poly(int n, int a, int b) 80 80 { … … 92 92 "USAGE: sysCRHT(n,defset,e,q,m,[k]); n,e,q,m,k int, defset list of int's 93 93 @format 94 - n length of the cyclic code, 94 - n length of the cyclic code, 95 95 - defset is a list representing the defining set, 96 - e the error-correcting capacity, 96 - e the error-correcting capacity, 97 97 - q field size 98 - m degree extension of the splitting field, 99 - if k>0 additional equations representing the fact that every two 98 - m degree extension of the splitting field, 99 - if k>0 additional equations representing the fact that every two 100 100 error positions are either different or at least one of them is zero 101 101 @end format 102 RETURN: the ring to work with the CRHT-ideal (with Sala's additions), 102 RETURN: the ring to work with the CRHT-ideal (with Sala's additions), 103 103 containig an ideal with name 'crht' 104 THEORY: Based on 'defset' of the given cyclic code, the procedure constructs 105 the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht'. With its 104 THEORY: Based on 'defset' of the given cyclic code, the procedure constructs 105 the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht'. With its 106 106 help one can solve the decoding problem. For basics of the method @ref{Cooper philosophy}. 107 107 SEE ALSO: sysNewton, sysBin … … 109 109 " 110 110 { 111 int r=size(defset); 111 int r=size(defset); 112 112 ring @crht=(q,a),(Y(e..1),Z(1..e),X(r..1)),lp; 113 113 ideal crht; … … 115 115 poly sum; 116 116 int k; 117 if ( size(#) > 0) 118 { 119 k = #[1]; 120 } 121 117 if ( size(#) > 0) 118 { 119 k = #[1]; 120 } 121 122 122 //---------------------- add check equations -------------------------- 123 123 for (i=1; i<=r; i++) … … 130 130 crht[i]=sum-X(i); 131 131 } 132 132 133 133 //--------------------- field equations on syndromes ------------------ 134 134 for (i=1; i<=r; i++) … … 136 136 crht=crht,X(i)^(q^m)-X(i); 137 137 } 138 138 139 139 //------ restrictions on error-locations: n-th roots of unity ---------- 140 140 for (i=1; i<=e; i++) … … 142 142 crht=crht,Z(i)^(n+1)-Z(i); 143 143 } 144 144 145 145 for (i=1; i<=e; i++) 146 146 { 147 147 crht=crht,Y(i)^(q-1)-1; 148 } 149 148 } 149 150 150 //--------- add Sala's additional conditions if necessary -------------- 151 151 if ( k > 0 ) 152 152 153 153 { 154 154 for (i=1; i<=e; i++) … … 159 159 } 160 160 } 161 } 162 export crht; 163 return(@crht); 164 } 161 } 162 export crht; 163 return(@crht); 164 } 165 165 example 166 166 { "EXAMPLE:"; echo=2; … … 168 168 intvec v = option(get); 169 169 170 list defset=1,3; // defining set 170 list defset=1,3; // defining set 171 171 int n=15; // length 172 172 int e=2; // error-correcting capacity … … 174 174 int m=4; // degree extension of the splitting field 175 175 int sala=1; // indicator to add additional equations 176 177 def A=sysCRHT(n,defset,e,q,m); 176 177 def A=sysCRHT(n,defset,e,q,m); 178 178 setring A; 179 179 A; // shows the ring we are working in 180 print(crht); // the CRHT-ideal 180 print(crht); // the CRHT-ideal 181 181 option(redSB); 182 182 ideal red_crht=std(crht); // reduced Groebner basis 183 183 print(red_crht); 184 184 185 185 //============================ 186 A=sysCRHT(n,defset,e,q,m,sala); 187 setring A; 186 A=sysCRHT(n,defset,e,q,m,sala); 187 setring A; 188 188 print(crht); // CRHT-ideal with additional equations from Sala 189 189 option(redSB); 190 190 ideal red_crht=std(crht); // reduced Groebner basis 191 print(red_crht); 191 print(red_crht); 192 192 red_crht[5]; // general error-locator polynomial for this code 193 193 option(set,v); … … 198 198 199 199 proc sysCRHTMindist (int n, list defset, int w) 200 "USAGE: sysCRHTMindist(n,defset,w); n,w are int, defset is list of int's 200 "USAGE: sysCRHTMindist(n,defset,w); n,w are int, defset is list of int's 201 201 @format 202 - n length of the cyclic code, 202 - n length of the cyclic code, 203 203 - defset is a list representing the defining set, 204 204 - w is a candidate for the minimum distance 205 205 @end format 206 RETURN: the ring to work with the Sala's ideal for the minimum distance 206 RETURN: the ring to work with the Sala's ideal for the minimum distance 207 207 containing the ideal with name 'crht_md' 208 THEORY: Based on 'defset' of the given cyclic code, the procedure constructs 209 the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht_md'. With 210 its help one can find minimum distance of the code in the binary 208 THEORY: Based on 'defset' of the given cyclic code, the procedure constructs 209 the corresponding Cooper-Reed-Heleseth-Truong ideal 'crht_md'. With 210 its help one can find minimum distance of the code in the binary 211 211 case. For basics of the method @ref{Cooper philosophy}. 212 212 EXAMPLE: example sysCRHTMindist; shows an example 213 213 " 214 214 { 215 int r=size(defset); 215 int r=size(defset); 216 216 ring @crht_md=2,Z(1..w),lp; 217 217 ideal crht_md; 218 218 int i,j; 219 219 poly sum; 220 220 221 221 //------------ add check equations -------------- 222 222 for (i=1; i<=r; i++) … … 228 228 } 229 229 crht_md[i]=sum; 230 } 231 232 230 } 231 232 233 233 //----------- locations are n-th roots of unity ------------ 234 234 for (i=1; i<=w; i++) 235 235 { 236 236 crht_md=crht_md,Z(i)^n-1; 237 } 238 237 } 238 239 239 //------------ adding conditions on locations being different ------------ 240 240 for (i=1; i<=w; i++) … … 245 245 } 246 246 } 247 248 export crht_md; 249 return(@crht_md); 250 } 247 248 export crht_md; 249 return(@crht_md); 250 } 251 251 example 252 252 { … … 254 254 intvec v = option(get); 255 255 // binary cyclic [15,7,5] code with defining set (1,3) 256 257 list defset=1,3; // defining set 258 int n=15; // length 259 int d=5; // candidate for the minimum distance 260 261 def A=sysCRHTMindist(n,defset,d); 256 257 list defset=1,3; // defining set 258 int n=15; // length 259 int d=5; // candidate for the minimum distance 260 261 def A=sysCRHTMindist(n,defset,d); 262 262 setring A; 263 263 A; // shows the ring we are working in 264 264 print(crht_md); // the Sala's ideal for mindist 265 265 option(redSB); 266 ideal red_crht_md=std(crht_md); 266 ideal red_crht_md=std(crht_md); 267 267 print(red_crht_md); // reduced Groebner basis 268 268 269 269 option(set,v); 270 270 } … … 281 281 282 282 proc sysNewton (int n, list defset, int t, int q, int m, list #) 283 "USAGE: sysNewton (n,defset,t,q,m,[tr]); n,t,q,m,tr int, defset list int's 283 "USAGE: sysNewton (n,defset,t,q,m,[tr]); n,t,q,m,tr int, defset list int's 284 284 @format 285 - n is length, 285 - n is length, 286 286 - defset is the defining set, 287 - t is the number of errors, 288 - q is basefield size, 287 - t is the number of errors, 288 - q is basefield size, 289 289 - m is degree extension of the splitting field, 290 - if tr>0 it indicates that Newton identities in triangular 290 - if tr>0 it indicates that Newton identities in triangular 291 291 form should be constructed 292 292 @end format 293 RETURN: the ring to work with the generalized Newton identities (in 293 RETURN: the ring to work with the generalized Newton identities (in 294 294 triangular form if applicable) containing the ideal with name 'newton' 295 THEORY: Based on 'defset' of the given cyclic code, the procedure constructs 296 the corresponding ideal 'newton' with the generalized Newton 297 identities. With its help one can solve the decoding problem. For 295 THEORY: Based on 'defset' of the given cyclic code, the procedure constructs 296 the corresponding ideal 'newton' with the generalized Newton 297 identities. With its help one can solve the decoding problem. For 298 298 basics of the method @ref{Cooper philosophy}. 299 299 SEE ALSO: sysCRHT, sysBin 300 300 EXAMPLE: example sysNewton; shows an example 301 301 " 302 { 302 { 303 303 string s="ring @newton=("+string(q)+",a),("; 304 304 int i,j; 305 305 int flag; 306 306 int tr; 307 307 308 308 if (size(#)>0) 309 309 { 310 310 tr=#[1]; 311 311 } 312 312 313 313 for (i=n; i>=1; i--) 314 314 { … … 319 319 { 320 320 flag=0; 321 break; 321 break; 322 322 } 323 323 } … … 332 332 s=s+"S("+string(defset[i])+"),"; 333 333 } 334 s=s+"S("+string(defset[1])+")),lp;"; 335 334 s=s+"S("+string(defset[1])+")),lp;"; 335 336 336 execute(s); 337 338 ideal newton; 337 338 ideal newton; 339 339 poly sum; 340 341 340 341 342 342 //------------ generate generalized Newton identities ---------- 343 343 if (tr) … … 353 353 } 354 354 } else 355 { 355 { 356 356 for (i=1; i<=t; i++) 357 357 { … … 372 372 } 373 373 newton=newton,S(t+i)+sum; 374 } 375 374 } 375 376 376 //----------- add field equations on sigma's -------------- 377 377 for (i=1; i<=t; i++) … … 379 379 newton=newton,sigma(i)^(q^m)-sigma(i); 380 380 } 381 381 382 382 //----------- add conjugacy relations ------------------ 383 383 for (i=1; i<=n; i++) … … 387 387 newton=simplify(newton,2); 388 388 export newton; 389 return(@newton); 390 } 391 example 389 return(@newton); 390 } 391 example 392 392 { 393 393 "EXAMPLE:"; echo = 2; 394 // Newton identities for a binary 3-error-correcting cyclic code of 394 // Newton identities for a binary 3-error-correcting cyclic code of 395 395 //length 31 with defining set (1,5,7) 396 396 397 397 int n=31; // length 398 398 list defset=1,5,7; //defining set … … 401 401 int m=5; // degree extension of the splitting field 402 402 int tr=1; // indicator of triangular form of Newton identities 403 404 403 404 405 405 def A=sysNewton(n,defset,t,q,m); 406 406 setring A; 407 407 A; // shows the ring we are working in 408 408 print(newton); // generalized Newton identities 409 409 410 410 //=============================== 411 411 A=sysNewton(n,defset,t,q,m,tr); 412 setring A; 412 setring A; 413 413 print(newton); // generalized Newton identities in triangular form 414 414 } 415 415 416 416 /////////////////////////////////////////////////////////////////////////////// 417 // forms a list of special combinations needed for computation of Waring's 417 // forms a list of special combinations needed for computation of Waring's 418 418 //function 419 419 static proc combinations_sum (int m, int n) … … 438 438 count++; 439 439 } 440 if (flag) 440 if (flag) 441 441 { 442 442 for (j=2; j<=m; j++) … … 444 444 interm[i][j]=interm[i][j] div j; 445 445 } 446 result[size(result)+1]=interm[i]; 446 result[size(result)+1]=interm[i]; 447 447 } 448 448 } … … 470 470 "USAGE: sysBin (v,Q,n,[odd]); v,n,odd are int, Q is list of int's 471 471 @format 472 - v a number if errors, 473 - Q is a generating set of the code, 474 - n the length, 475 - odd is an additional parameter: if 476 set to 1, then the generating set is enlarged by odd elements, 472 - v a number if errors, 473 - Q is a generating set of the code, 474 - n the length, 475 - odd is an additional parameter: if 476 set to 1, then the generating set is enlarged by odd elements, 477 477 which are 2^(some power)*(some elment in the gen.set) mod n 478 478 @end format 479 479 RETURN: the ring with the resulting system called 'bin' 480 THEORY: Based on Q of the given cyclic code, the procedure constructs 481 the corresponding ideal 'bin' with the use of Waring function. 482 With its help one can solve the decoding problem. 480 THEORY: Based on Q of the given cyclic code, the procedure constructs 481 the corresponding ideal 'bin' with the use of Waring function. 482 With its help one can solve the decoding problem. 483 483 For basics of the method @ref{Generalized Newton identities}. 484 484 SEE ALSO: sysNewton, sysCRHT … … 527 527 Q_update=Q; 528 528 } 529 530 //---- form polynomials for the Bin system via Waring's function --------- 529 530 //---- form polynomials for the Bin system via Waring's function --------- 531 531 for (i=1; i<=size(Q_update); i++) 532 532 { … … 541 541 } 542 542 count1=0; 543 for (j=2; j<=upper-1; j++) 543 for (j=2; j<=upper-1; j++) 544 544 { 545 545 count1=count1+exp_count(j,2); … … 564 564 sum_=sum_+coef_*mon; 565 565 } 566 result=result,S(Q_update[i])-sum_; 566 result=result,S(Q_update[i])-sum_; 567 567 } 568 568 ideal bin=simplify(result,2); 569 569 export bin; 570 570 return(r); 571 } 572 example 571 } 572 example 573 573 { 574 574 "EXAMPLE:"; echo = 2; … … 592 592 if (ncols(x)!=nrows(g)) {print("ERRORencode2!");} 593 593 return(x*g); 594 } 595 example 594 } 595 example 596 596 { 597 597 "EXAMPLE:"; echo = 2; … … 603 603 0,0,0,1,1,1,0; 604 604 //encode x with the generator matrix g 605 print(encode(x,g)); 605 print(encode(x,g)); 606 606 } 607 607 … … 616 616 if (nrows(c)>1) {print("ERRORsyndrome1!");} 617 617 if (ncols(c)!=ncols(h)) {print("ERRORsyndrome2!");} 618 return(h*transpose(c)); 619 } 620 example 618 return(h*transpose(c)); 619 } 620 example 621 621 { 622 622 "EXAMPLE:"; echo = 2; … … 636 636 print(syndrome(check,c)); 637 637 c[1,3]=1; 638 //now c is a codeword 638 //now c is a codeword 639 639 print(syndrome(check,c)); 640 640 } … … 657 657 "USAGE: sysQE(check,y,t,[fieldeq,formal]);check,y matrix;t,fieldeq,formal int 658 658 @format 659 - check is the check matrix of the code 660 - y is a received word, 661 - t the number of errors to be corrected, 662 - if fieldeq=1, then field equations are added, 663 - if formal=0, field equations on (known) syndrome variables 664 are not added, in order to add them (note that the exponent should 659 - check is the check matrix of the code 660 - y is a received word, 661 - t the number of errors to be corrected, 662 - if fieldeq=1, then field equations are added, 663 - if formal=0, field equations on (known) syndrome variables 664 are not added, in order to add them (note that the exponent should 665 665 be as a number of elements in the INITIAL alphabet) one 666 666 needs to set formal>0 for the exponent 667 667 @end format 668 668 RETURN: the ring to work with together with the resulting system called 'qe' 669 THEORY: Based on 'check' of the given linear code, the procedure constructs 669 THEORY: Based on 'check' of the given linear code, the procedure constructs 670 670 the corresponding ideal that gives an opportunity to compute 671 671 unknown syndrome of the received word y. Further 672 one is able to solve the decoding problem. 672 one is able to solve the decoding problem. 673 673 For basics of the method @ref{Decoding method based on quadratic equations}. 674 674 SEE ALSO: sysFL … … 686 686 formal=#[2]; 687 687 } 688 689 def br=basering; 688 689 def br=basering; 690 690 list rl=ringlist(br); 691 691 692 692 int red=nrows(check); 693 693 int n=ncols(check); 694 694 int q=rl[1][1]; 695 695 696 696 if (formal==0) 697 { 697 { 698 698 ring work=(q,a),(V(1..t),U(1..n)),dp; 699 699 } else … … 701 701 ring work=(q,a),(V(1..t),U(1..n),s(1..red)),(dp(t),lp(n),dp(red)); 702 702 } 703 703 704 704 matrix check=imap(br,check); 705 705 matrix y=imap(br,y); 706 706 707 707 matrix h_full=genMDSMat(n,a); 708 708 matrix h=submat(h_full,1..red,1..n); 709 709 if (nrows(y)!=1) {print("ERROR1Pell");} 710 710 if (ncols(y)!=n) {print("ERROR2Pell");} 711 711 712 712 ideal result; 713 713 714 714 list c; 715 715 list a; … … 722 722 c[i]=tmp; 723 723 } 724 724 725 725 int tim=rtimer; 726 726 matrix transf=inverse(transpose(h_full)); 727 727 728 728 //------ expression matrix of check vectors w.r.t. the MDS basis ----------- 729 729 tim=rtimer; … … 733 733 a[i]=transf*a[i]; 734 734 } 735 735 736 736 //----------- compute the structure constants ------------------------ 737 737 tim=rtimer; 738 matrix te[n][1]; 738 matrix te[n][1]; 739 739 for (i=1; i<=n; i++) 740 740 { … … 742 742 { 743 743 if ((j<i)&&(i<=t+1)) {c[i][j]=c[j][i];} 744 else 744 else 745 745 { 746 if (i+j<=n+1) 746 if (i+j<=n+1) 747 747 { 748 748 c[i][j]=te; 749 c[i][j][i+j-1,1]=1; 749 c[i][j][i+j-1,1]=1; 750 750 } 751 751 else … … 753 753 c[i][j]=star(h_full,i,j); 754 754 c[i][j]=transf*c[i][j]; 755 } 755 } 756 756 } 757 757 } 758 758 } 759 760 761 tim=rtimer; 759 760 761 tim=rtimer; 762 762 if (formal==0) 763 763 { … … 798 798 result=result,V(j)^q-V(j); 799 799 } 800 } 801 800 } 801 802 802 //----- form the quadratic equations according to the theory ----------- 803 803 for (i=1; i<=n; i++) … … 819 819 } 820 820 result=result,sum1-sum3; 821 } 822 821 } 822 823 823 result=simplify(result,2); 824 824 825 825 ideal qe=result; 826 826 export qe; 827 return(work); 828 } 829 example 827 return(work); 828 } 829 example 830 830 { 831 831 "EXAMPLE:"; echo = 2; 832 832 intvec v = option(get); 833 833 834 834 //correct 2 errors in [7,3] 8-ary code RS code 835 835 int t=2; int q=8; int n=7; int redun=4; … … 840 840 matrix x[1][3]=0,0,1,0; 841 841 matrix y[1][7]=encode(x,g); 842 842 843 843 //disturb with 2 errors 844 matrix rec[1][7]=errorInsert(y,list(2,4),list(1,a)); 845 844 matrix rec[1][7]=errorInsert(y,list(2,4),list(1,a)); 845 846 846 //generate the system 847 847 def A=sysQE(h,rec,t); 848 848 setring A; 849 849 print(qe); 850 850 851 851 //let us decode 852 852 option(redSB); 853 853 ideal sys_qe=std(qe); 854 print(sys_qe); 855 854 print(sys_qe); 855 856 856 option(set,v); 857 857 } … … 862 862 "USAGE: errorInsert(y,pos,val); y is matrix, pos,val list of int's 863 863 @format 864 - y is a (code) word, 865 - pos = positions where errors occured, 864 - y is a (code) word, 865 - pos = positions where errors occured, 866 866 - val = their corresponding values 867 867 @end format … … 877 877 } 878 878 return(result); 879 } 880 example 879 } 880 example 881 881 { 882 882 "EXAMPLE:"; echo = 2; … … 890 890 matrix y[1][7]=encode(x,g); 891 891 print(y); 892 892 893 893 //disturb with 2 errors 894 894 matrix rec[1][7]=errorInsert(y,list(2,4),list(1,a)); … … 902 902 "USAGE: errorRand(y, num, e); y matrix, num,e int 903 903 @format 904 - y is a (code) word, 905 - num is the number of errors, 904 - y is a (code) word, 905 - num is the number of errors, 906 906 - e is an extension degree (if one wants values to be from GF(p^e)) 907 907 @end format … … 926 926 } 927 927 if (flag) {pos[i]=temp;break;} 928 } 929 } 930 928 } 929 } 930 931 931 for (i=1; i<=num; i++) 932 932 { 933 933 flag=1; 934 934 while(flag) 935 { 936 tempnum=randomvector(1,e); 937 if (tempnum!=0) {flag=0;} 938 } 939 val[i]=tempnum; 940 } 941 935 { 936 tempnum=randomvector(1,e); 937 if (tempnum!=0) {flag=0;} 938 } 939 val[i]=tempnum; 940 } 941 942 942 for (i=1; i<=size(pos); i++) 943 943 { … … 945 945 } 946 946 return(result); 947 } 948 example 947 } 948 example 949 949 { 950 950 "EXAMPLE:"; echo = 2; … … 957 957 matrix x[1][3]=0,0,1,0; 958 958 matrix y[1][7]=encode(x,g); 959 959 960 960 //disturb with 2 random errors 961 961 matrix rec[1][7]=errorRand(y,2,3); 962 962 print(rec); 963 print(rec-y); 963 print(rec-y); 964 964 } 965 965 … … 969 969 "USAGE: randomCheck(m, n, e); m,n,e are int 970 970 @format 971 - m x n are dimensions of the matrix, 971 - m x n are dimensions of the matrix, 972 972 - e is an extension degree (if one wants values to be from GF(p^e)) 973 973 @end format … … 986 986 { 987 987 rand[i,j]=temp[j,1]; 988 } 988 } 989 989 } 990 990 result=concat(rand,unitmat(m)); 991 991 return(result); 992 } 993 example 994 { 995 "EXAMPLE:"; echo = 2; 992 } 993 example 994 { 995 "EXAMPLE:"; echo = 2; 996 996 int redun=5; int n=15; 997 997 ring r=2,x,dp; 998 998 999 999 //generate random check matrix for a [15,5] binary code 1000 1000 matrix h=randomCheck(redun,n,1); 1001 1001 print(h); 1002 1002 1003 1003 //corresponding generator matrix 1004 1004 matrix g=dual_code(h); 1005 print(g); 1005 print(g); 1006 1006 } 1007 1007 … … 1011 1011 "USAGE: genMDSMat(n, a); n is int, a is number 1012 1012 @format 1013 - n x n are dimensions of the MDS matrix, 1013 - n x n are dimensions of the MDS matrix, 1014 1014 - a is a primitive element of the field. 1015 @end format 1016 NOTE: An MDS matrix is constructed in the following way. We take a to be a 1017 generator of the multiplicative group of the field. Then we construct 1015 @end format 1016 NOTE: An MDS matrix is constructed in the following way. We take a to be a 1017 generator of the multiplicative group of the field. Then we construct 1018 1018 the Vandermonde matrix with this a. 1019 ASSUME: extension field should already be defined 1019 ASSUME: extension field should already be defined 1020 1020 RETURN: a matrix with the MDS property 1021 EXAMPLE: example genMDSMat; shows an example 1021 EXAMPLE: example genMDSMat; shows an example 1022 1022 " 1023 1023 { … … 1029 1029 { 1030 1030 result[j+1,i+1]=(a^i)^j; 1031 } 1031 } 1032 1032 } 1033 1033 return(result); 1034 } 1035 example 1034 } 1035 example 1036 1036 { 1037 1037 "EXAMPLE:"; echo = 2; 1038 1038 int q=16; int n=15; 1039 1039 ring r=(q,a),x,dp; 1040 1040 1041 1041 //generate an MDS (Vandermonde) matrix 1042 1042 matrix h_full=genMDSMat(n,a); 1043 print(h_full); 1043 print(h_full); 1044 1044 } 1045 1045 … … 1050 1050 "USAGE: mindist (check, q); check matrix, q int 1051 1051 @format 1052 - check is a check matrix, 1052 - check is a check matrix, 1053 1053 - q is the field size 1054 1054 @end format 1055 RETURN: minimum distance of the code together with the time needed for its 1055 RETURN: minimum distance of the code together with the time needed for its 1056 1056 calculation 1057 EXAMPLE: example mindist; shows an example 1057 EXAMPLE: example mindist; shows an example 1058 1058 " 1059 1059 { … … 1061 1061 1062 1062 int n=ncols(check); int redun=nrows(check); int t=redun+1; 1063 1064 def br=basering; 1065 list rl=ringlist(br); 1063 1064 def br=basering; 1065 list rl=ringlist(br); 1066 1066 int q=rl[1][1]; 1067 1068 ring work=(q,a),(V(1..t),U(1..n)),dp; 1069 matrix check=imap(br,check); 1070 1067 1068 ring work=(q,a),(V(1..t),U(1..n)),dp; 1069 matrix check=imap(br,check); 1070 1071 1071 ideal temp; 1072 1072 int count=1; … … 1074 1074 int flag2; 1075 1075 int i, tim, timsolve; 1076 matrix z[1][n]; 1076 matrix z[1][n]; 1077 1077 option(redSB); 1078 1078 def A=sysQE(check,z,count); 1079 1079 1080 //proceed with solving the system w.r.t zero vector until some solutions 1080 //proceed with solving the system w.r.t zero vector until some solutions 1081 1081 //are found 1082 1082 while (flag) … … 1087 1087 tim=rtimer; 1088 1088 temp=std(temp); 1089 timsolve=timsolve+rtimer-tim; 1089 timsolve=timsolve+rtimer-tim; 1090 1090 flag2=1; 1091 1091 setring work; 1092 temp=imap(A,temp); 1092 temp=imap(A,temp); 1093 1093 for (i=1; i<=n; i++) 1094 1094 { 1095 if 1096 (temp[i]!=U(n-i+1)) 1095 if 1096 (temp[i]!=U(n-i+1)) 1097 1097 { 1098 1098 flag2=0; 1099 1099 } 1100 1100 } 1101 if (!flag2) 1101 if (!flag2) 1102 1102 { 1103 1103 flag=0; 1104 1104 } 1105 else 1105 else 1106 1106 { 1107 1107 count++; 1108 1108 } 1109 1109 } 1110 list result=list(count,timsolve); 1111 1110 list result=list(count,timsolve); 1111 1112 1112 option(set,vopt); 1113 return(result); 1114 } 1115 example 1113 return(result); 1114 } 1115 example 1116 1116 { 1117 1117 "EXAMPLE:"; echo = 2; 1118 //determine a minimum distance for a [7,3] binary code 1119 int q=8; int n=7; int redun=4; int t=redun+1; 1120 ring r=(q,a),x,dp; 1121 1118 //determine a minimum distance for a [7,3] binary code 1119 int q=8; int n=7; int redun=4; int t=redun+1; 1120 ring r=(q,a),x,dp; 1121 1122 1122 //generate random check matrix 1123 1123 matrix h=randomCheck(redun,n,1); 1124 1124 print(h); 1125 list l=mindist(h); 1126 print(l[1]); 1127 //time for the comutation in secs 1128 print(l[2]); 1125 list l=mindist(h); 1126 print(l[1]); 1127 //time for the comutation in secs 1128 print(l[2]); 1129 1129 } 1130 1130 … … 1135 1135 @format 1136 1136 - check is the check matrix of the code, 1137 - rec is a received word, 1137 - rec is a received word, 1138 1138 - t is an upper bound for the number of errors one wants to correct 1139 1139 @end format 1140 ASSUME: Errors in rec should be correctable, otherwise the output is 1140 ASSUME: Errors in rec should be correctable, otherwise the output is 1141 1141 unpredictable 1142 1142 RETURN: a codeword that is closest to rec 1143 EXAMPLE: example decode; shows an example 1143 EXAMPLE: example decode; shows an example 1144 1144 " 1145 1145 { 1146 intvec vopt = option(get); 1147 1146 intvec vopt = option(get); 1147 1148 1148 def br=basering; 1149 int n=ncols(check); 1150 1151 int count=1; 1149 int n=ncols(check); 1150 1151 int count=1; 1152 1152 def A=sysQE(check,rec,count); 1153 1153 while(1) 1154 1154 { 1155 1155 A=sysQE(check,rec,count); 1156 setring A; 1156 setring A; 1157 1157 matrix h_full=genMDSMat(n,a); 1158 1158 matrix rec=imap(br,rec); 1159 1159 option(redSB); 1160 ideal qe_red=std(qe); 1160 ideal qe_red=std(qe); 1161 1161 if (qe_red[1]!=1) 1162 1162 { 1163 1163 break; 1164 1164 } 1165 else 1165 else 1166 1166 { 1167 1167 count++; … … 1169 1169 setring br; 1170 1170 } 1171 1172 setring A; 1173 1171 1172 setring A; 1173 1174 1174 //obtain a codeword 1175 1175 //this works only if our code is indeed can correct these errors … … 1178 1178 { 1179 1179 syn[i,1]=-qe_red[n-i+1]+lead(qe_red[n-i+1]); 1180 } 1181 1182 matrix real_syn=inverse(h_full)*syn; 1180 } 1181 1182 matrix real_syn=inverse(h_full)*syn; 1183 1183 setring br; 1184 1184 matrix real_syn=imap(A,real_syn); 1185 1185 1186 1186 option(set,vopt); 1187 return(rec-transpose(real_syn)); 1188 } 1189 example 1190 { 1191 "EXAMPLE:"; echo = 2; 1192 //correct 1 error in [15,7] binary code 1187 return(rec-transpose(real_syn)); 1188 } 1189 example 1190 { 1191 "EXAMPLE:"; echo = 2; 1192 //correct 1 error in [15,7] binary code 1193 1193 int t=1; int q=16; int n=15; int redun=10; 1194 ring r=(q,a),x,dp; 1195 1194 ring r=(q,a),x,dp; 1195 1196 1196 //generate random check matrix 1197 matrix h=randomCheck(redun,n,1); 1197 matrix h=randomCheck(redun,n,1); 1198 1198 matrix g=dual_code(h); 1199 1199 matrix x[1][n-redun]=0,0,1,0,1,0,1; 1200 1200 matrix y[1][n]=encode(x,g); 1201 1201 print(y); 1202 1202 1203 1203 // find out the minimum distance of the code 1204 1204 list l=mindist(h); 1205 1205 1206 1206 //disturb with errors 1207 1207 "Correct ",(l[1]-1) div 2," errors"; 1208 1208 matrix rec[1][n]=errorRand(y,(l[1]-1) div 2,1); 1209 print(rec); 1210 1209 print(rec); 1210 1211 1211 //let us decode 1212 1212 matrix dec_word=decode(h,rec); 1213 print(dec_word); 1213 print(dec_word); 1214 1214 } 1215 1215 … … 1221 1221 @format 1222 1222 - redun is a redundabcy of a (random) code, 1223 - q is the field size, 1223 - q is the field size, 1224 1224 - ncodes is the number of random codes to be processed, 1225 1225 - ntrials is the number of received vectors per code to be corrected 1226 - If e is given it sets the correction capacity explicitly. It 1226 - If e is given it sets the correction capacity explicitly. It 1227 1227 should be used in case one expects some lower bound, 1228 otherwise the procedure tries to compute the real minimum distance 1228 otherwise the procedure tries to compute the real minimum distance 1229 1229 to find out the error-correction capacity 1230 1230 @end format 1231 RETURN: nothing; 1232 EXAMPLE: example decodeRandom; shows an example 1231 RETURN: nothing; 1232 EXAMPLE: example decodeRandom; shows an example 1233 1233 " 1234 1234 { … … 1248 1248 option(redSB); 1249 1249 def br=basering; 1250 matrix h_full=genMDSMat(n,a); 1250 matrix h_full=genMDSMat(n,a); 1251 1251 matrix z[1][ncols(h_full)]; 1252 1252 … … 1268 1268 dist=tmp[1]; 1269 1269 printf("d= %p",dist); 1270 t=(dist-1) div 2; 1271 } 1272 tim2=rtimer; 1270 t=(dist-1) div 2; 1271 } 1272 tim2=rtimer; 1273 1273 tim3=rtimer; 1274 1274 … … 1279 1279 ideal sys2,sys3; 1280 1280 matrix h=imap(br,h); 1281 matrix g=dual_code(h); 1281 matrix g=dual_code(h); 1282 1282 ideal sys=qe; 1283 1283 print("The system is generated"); 1284 timdec3=timdec3+rtimer-tim3; 1284 timdec3=timdec3+rtimer-tim3; 1285 1285 1286 1286 //------ modify the template according to every received word -------------- 1287 1287 for (j=1; j<=ntrials; j++) 1288 1288 { 1289 word=randomvector(n-redun,1); 1289 word=randomvector(n-redun,1); 1290 1290 y=encode(transpose(word),g); 1291 rec=errorRand(y,t,1); 1292 sys2=add_synd(rec,h,redun,sys); 1293 1291 rec=errorRand(y,t,1); 1292 sys2=add_synd(rec,h,redun,sys); 1293 1294 1294 tim=rtimer; 1295 sys3=std(sys2); 1296 timdec=timdec+rtimer-tim; 1297 } 1295 sys3=std(sys2); 1296 timdec=timdec+rtimer-tim; 1297 } 1298 1298 timdec2=timdec2+rtimer-tim2; 1299 1299 kill A; 1300 1300 option(set,vopt); 1301 } 1301 } 1302 1302 printf("Time for mindist: %p", timdist); 1303 1303 printf("Time for GB in mindist: %p", timdist); 1304 1304 printf("Time for decoding: %p", timdec2); 1305 1305 printf("Time for GB in decoding: %p", timdec); 1306 printf("Time for sysQE in decoding: %p", timdec3); 1307 } 1308 example 1306 printf("Time for sysQE in decoding: %p", timdec3); 1307 } 1308 example 1309 1309 { 1310 1310 "EXAMPLE:"; echo = 2; 1311 1311 int q=32; int n=25; int redun=n-11; int t=redun+1; 1312 1312 ring r=(q,a),x,dp; 1313 1313 1314 1314 // correct 2 errors in 5 random binary codes, 50 trials each 1315 decodeRandom(n,redun,5,50,2); 1315 decodeRandom(n,redun,5,50,2); 1316 1316 } 1317 1317 … … 1320 1320 1321 1321 proc decodeCode(matrix check, int ntrials, list #) 1322 "USAGE: decodeCode(check, ntrials, [e]); check matrix, ntrials,e int 1323 @format 1324 - check is a check matrix for the code, 1325 - ntrials is the number of received vectors per code to be 1322 "USAGE: decodeCode(check, ntrials, [e]); check matrix, ntrials,e int 1323 @format 1324 - check is a check matrix for the code, 1325 - ntrials is the number of received vectors per code to be 1326 1326 corrected. 1327 - If e is given it sets the correction capacity explicitly. It 1327 - If e is given it sets the correction capacity explicitly. It 1328 1328 should be used in case one expects some lower bound, 1329 otherwise the procedure tries to compute the real minimum distance 1329 otherwise the procedure tries to compute the real minimum distance 1330 1330 to find out the error-correction capacity 1331 1331 @end format 1332 RETURN: nothing; 1333 EXAMPLE: example decodeCode; shows an example 1332 RETURN: nothing; 1333 EXAMPLE: example decodeCode; shows an example 1334 1334 " 1335 1335 { … … 1351 1351 option(redSB); 1352 1352 def br=basering; 1353 matrix h_full=genMDSMat(n,a); 1353 matrix h_full=genMDSMat(n,a); 1354 1354 matrix z[1][ncols(h_full)]; 1355 1355 setring br; … … 1369 1369 dist=tmp[1]; 1370 1370 printf("d= %p",dist); 1371 t=(dist-1) div 2; 1372 } 1373 tim2=rtimer; 1371 t=(dist-1) div 2; 1372 } 1373 tim2=rtimer; 1374 1374 tim3=rtimer; 1375 1375 … … 1380 1380 ideal sys2,sys3; 1381 1381 matrix h=imap(br,h); 1382 matrix g=dual_code(h); 1382 matrix g=dual_code(h); 1383 1383 ideal sys=qe; 1384 1384 print("The system is generated"); 1385 timdec3=timdec3+rtimer-tim3; 1386 1387 //--- modify the template according to every received word --------------- 1385 timdec3=timdec3+rtimer-tim3; 1386 1387 //--- modify the template according to every received word --------------- 1388 1388 for (j=1; j<=ntrials; j++) 1389 1389 { 1390 word=randomvector(n-redun,1); 1390 word=randomvector(n-redun,1); 1391 1391 y=encode(transpose(word),g); 1392 rec=errorRand(y,t,1); 1393 sys2=add_synd(rec,h,redun,sys); 1394 1392 rec=errorRand(y,t,1); 1393 sys2=add_synd(rec,h,redun,sys); 1394 1395 1395 tim=rtimer; 1396 sys3=std(sys2); 1397 timdec=timdec+rtimer-tim; 1398 } 1399 timdec2=timdec2+rtimer-tim2; 1400 1396 sys3=std(sys2); 1397 timdec=timdec+rtimer-tim; 1398 } 1399 timdec2=timdec2+rtimer-tim2; 1400 1401 1401 printf("Time for mindist: %p", timdist); 1402 1402 printf("Time for GB in mindist: %p", timdist); 1403 1403 printf("Time for decoding: %p", timdec2); 1404 1404 printf("Time for GB in decoding: %p", timdec); 1405 printf("Time for sysQE in decoding: %p", timdec3); 1406 1405 printf("Time for sysQE in decoding: %p", timdec3); 1406 1407 1407 option(set,vopt); 1408 } 1409 example 1408 } 1409 example 1410 1410 { 1411 1411 "EXAMPLE:"; echo = 2; … … 1413 1413 ring r=(q,a),x,dp; 1414 1414 matrix check=randomCheck(redun,n,1); 1415 1416 // correct 2 errors in using the code above, 50 trials 1417 decodeCode(check,50,2); 1415 1416 // correct 2 errors in using the code above, 50 trials 1417 decodeCode(check,50,2); 1418 1418 } 1419 1419 … … 1426 1426 matrix s[redun][1]=syndrome(check,rec); 1427 1427 for (int i=1; i<=redun; i++) 1428 1429 { 1430 result[i]=result[i]-s[i,1]; 1428 1429 { 1430 result[i]=result[i]-s[i,1]; 1431 1431 } 1432 1432 return(result); … … 1448 1448 1449 1449 /////////////////////////////////////////////////////////////////////////////// 1450 // return index of an element in the ideal where it does not vanish at the 1450 // return index of an element in the ideal where it does not vanish at the 1451 1451 //given point 1452 1452 static proc find_index (ideal G, matrix p) … … 1488 1488 1489 1489 /////////////////////////////////////////////////////////////////////////////// 1490 // check whether given polynomial is divisible by some leading monomial of the 1490 // check whether given polynomial is divisible by some leading monomial of the 1491 1491 //ideal 1492 1492 static proc divisible (poly m, ideal G) … … 1494 1494 for (int i=1; i<=size(G); i++) 1495 1495 { 1496 if (m/leadmonom(G[i])!=0) {return(1);} 1496 if (m/leadmonom(G[i])!=0) {return(1);} 1497 1497 } 1498 1498 return(0); … … 1503 1503 proc vanishId (list points) 1504 1504 "USAGE: vanishId (points); point is a list of matrices 1505 'points' is a list of points for which the vanishing ideal is to be 1506 constructed 1505 'points' is a list of points for which the vanishing ideal is to be 1506 constructed 1507 1507 RETURN: Vanishing ideal corresponding to the given set of points 1508 EXAMPLE: example vanishId; shows an example 1508 EXAMPLE: example vanishId; shows an example 1509 1509 " 1510 1510 { 1511 1511 int m=size(points[1]); 1512 1512 int n=size(points); 1513 1513 1514 1514 ideal G=1; 1515 1515 int i,k,j; … … 1519 1519 //------------- proceed according to Farr-Gao algorithm ---------------- 1520 1520 for (k=1; k<=n; k++) 1521 { 1521 { 1522 1522 i=find_index(G,points[k]); 1523 cur=G[i]; 1523 cur=G[i]; 1524 1524 for(j=i+1; j<=size(G); j++) 1525 1525 { … … 1529 1529 temp=ideal2list(G); 1530 1530 temp=delete(temp,i); 1531 G=list2ideal(temp); 1531 G=list2ideal(temp); 1532 1532 for (j=1; j<=m; j++) 1533 1533 { … … 1535 1535 { 1536 1536 attrib(G,"isSB",1); 1537 h=NF((x(j)-points[k][j,1])*cur,G); 1537 h=NF((x(j)-points[k][j,1])*cur,G); 1538 1538 temp=ideal2list(G); 1539 1539 temp=insert(temp,h); 1540 1540 G=list2ideal(temp); 1541 G=sort(G)[1]; 1541 G=sort(G)[1]; 1542 1542 } 1543 1543 } … … 1545 1545 attrib(G,"isSB",1); 1546 1546 return(G); 1547 } 1548 example 1547 } 1548 example 1549 1549 { 1550 1550 "EXAMPLE:"; echo = 2; 1551 1551 ring r=3,(x(1..3)),dp; 1552 1552 1553 1553 //generate all 3-vectors over GF(3) 1554 1554 list points=pointsGen(3,1); 1555 1555 1556 1556 list points2=convPoints(points); 1557 1557 1558 1558 //grasps the first 11 points 1559 1559 list p=graspList(points2,1,11); 1560 1560 print(p); 1561 1561 1562 1562 //construct the vanishing ideal 1563 1563 ideal id=vanishId(p); … … 1566 1566 1567 1567 /////////////////////////////////////////////////////////////////////////////// 1568 // construct the list of all vectors of length m with elements in p^e, where p 1568 // construct the list of all vectors of length m with elements in p^e, where p 1569 1569 //is characteristics 1570 1570 proc pointsGen (int m, int e) … … 1588 1588 count++; 1589 1589 for (j=1; j<=charac^(e)-1; j++) 1590 { 1590 { 1591 1591 result[count][m]=a^j; 1592 1592 count++; … … 1594 1594 return(result); 1595 1595 } 1596 list prev=pointsGen(m-1,e); 1596 list prev=pointsGen(m-1,e); 1597 1597 for (i=1; i<=size(prev); i++) 1598 1598 { … … 1609 1609 return(result); 1610 1610 } 1611 1611 1612 1612 if (e==1) 1613 1613 { … … 1616 1616 int i,j; 1617 1617 list l=ringlist(basering); 1618 int charac=l[1][1]; 1618 int charac=l[1][1]; 1619 1619 list tmp; 1620 1620 for (i=1; i<=charac^m; i++) … … 1625 1625 { 1626 1626 for (j=0; j<=charac-1; j++) 1627 { 1627 { 1628 1628 result[count][m]=number(j); 1629 1629 count++; … … 1631 1631 return(result); 1632 1632 } 1633 list prev=pointsGen(m-1,e); 1633 list prev=pointsGen(m-1,e); 1634 1634 for (i=1; i<=size(prev); i++) 1635 1635 { … … 1643 1643 return(result); 1644 1644 } 1645 1645 1646 1646 } 1647 1647 … … 1688 1688 { 1689 1689 poly prod=1; 1690 list rl=ringlist(basering); 1690 list rl=ringlist(basering); 1691 1691 int charac=rl[1][1]; 1692 1692 int l; … … 1730 1730 "USAGE: sysFL (check,y,t,e,s); check,y matrix, t,e,s int 1731 1731 @format 1732 - check is a check matrix of the code, 1733 - y is a received word, 1732 - check is a check matrix of the code, 1733 - y is a received word, 1734 1734 - t the number of errors to correct, 1735 - e is the extension degree, 1735 - e is the extension degree, 1736 1736 - s is the dimension of the point for the vanishing ideal 1737 1737 @end format 1738 1738 RETURN: the system of Fitzgerald-Lax for the given decoding problem 1739 THEORY: Based on 'check' of the given linear code, the procedure constructs 1739 THEORY: Based on 'check' of the given linear code, the procedure constructs 1740 1740 the corresponding ideal constructed with a generalization of 1741 1741 Cooper's philosophy. For basics of the method @ref{Fitzgerald-Lax method}. … … 1744 1744 " 1745 1745 { 1746 list rl=ringlist(basering); 1747 int charac=rl[1][1]; 1746 list rl=ringlist(basering); 1747 int charac=rl[1][1]; 1748 1748 int n=ncols(check); 1749 int m=nrows(check); 1749 int m=nrows(check); 1750 1750 list points=pointsGen(s,e); 1751 1751 list points2=convPoints(points); 1752 list p=graspList(points2,1,n); 1753 ideal id=vanishId(p,e); 1754 ideal funcs=gener_funcs(check,p,e,id,s); 1755 1752 list p=graspList(points2,1,n); 1753 ideal id=vanishId(p,e); 1754 ideal funcs=gener_funcs(check,p,e,id,s); 1755 1756 1756 ideal result; 1757 1757 poly temp; 1758 1758 int i,j,k; 1759 1759 1760 1760 //--------------- add vanishing realtions --------------------- 1761 1761 for (i=1; i<=t; i++) 1762 { 1762 { 1763 1763 for (j=1; j<=size(id); j++) 1764 1764 { 1765 temp=id[j]; 1765 temp=id[j]; 1766 1766 for (k=1; k<=s; k++) 1767 1767 { 1768 1768 temp=subst(temp,x(k),x_var(i,k,s)); 1769 } 1769 } 1770 1770 result=result,temp; 1771 1771 } 1772 } 1773 1772 } 1773 1774 1774 //--------------- add field equations -------------------- 1775 1775 for (i=1; i<=t; i++) … … 1784 1784 result=result,e(i)^(charac^e-1)-1; 1785 1785 } 1786 1786 1787 1787 result=simplify(result,8); 1788 1788 1789 1789 //--------------- add check realtions -------------------- 1790 1790 poly sum; 1791 matrix syn[m][1]=syndrome(check,y); 1791 matrix syn[m][1]=syndrome(check,y); 1792 1792 for (i=1; i<=size(funcs); i++) 1793 { 1793 { 1794 1794 sum=0; 1795 1795 for (j=1; j<=t; j++) … … 1800 1800 temp=subst(temp,x(k),x_var(j,k,s)); 1801 1801 } 1802 sum=sum+temp*e(j); 1802 sum=sum+temp*e(j); 1803 1803 } 1804 1804 result=result,sum-syn[i,1]; 1805 1805 } 1806 1806 1807 1807 result=simplify(result,2); 1808 1808 1809 1809 points=points2; 1810 export points; 1810 export points; 1811 1811 return(result); 1812 } 1812 } 1813 1813 example 1814 1814 { 1815 1815 "EXAMPLE:"; echo = 2; 1816 1816 intvec vopt = option(get); 1817 1817 1818 1818 list l=FLpreprocess(3,1,11,2,""); 1819 1819 def r=l[1]; 1820 1820 setring r; 1821 int s_work=l[2]; 1822 1821 int s_work=l[2]; 1822 1823 1823 //the check matrix of [11,6,5] ternary code 1824 1824 matrix h[5][11]=1,0,0,0,0,1,1,1,-1,-1,0, … … 1833 1833 matrix rec[1][11]=errorInsert(y,list(2,4),list(1,-1)); 1834 1834 1835 //the Fitzgerald-Lax system 1835 //the Fitzgerald-Lax system 1836 1836 ideal sys=sysFL(h,rec,2,1,s_work); 1837 1837 print(sys); 1838 1838 option(redSB); 1839 1839 ideal red_sys=std(sys); 1840 red_sys; 1840 red_sys; 1841 1841 // read the solutions from this redGB 1842 1842 // the points are (0,0,1) and (0,1,0) with error values 1 and -1 resp. 1843 1843 // use list points to find error positions; 1844 1844 points; 1845 1845 1846 1846 option(set,vopt); 1847 1847 } … … 1856 1856 { 1857 1857 s++; 1858 } 1858 } 1859 1859 list var_ord; 1860 1860 int i,j; … … 1874 1874 count++; 1875 1875 } 1876 } 1877 1876 } 1877 1878 1878 list rl; 1879 1879 list tmp; 1880 1880 1881 1881 if (e>1) 1882 1882 { … … 1886 1886 rl[1][2][1]=string("a"); 1887 1887 rl[1][3]=tmp; 1888 rl[1][3][1]=tmp; 1888 rl[1][3][1]=tmp; 1889 1889 rl[1][3][1][1]=string("lp"); 1890 1890 rl[1][3][1][2]=1; … … 1893 1893 rl[1]=p; 1894 1894 } 1895 1895 1896 1896 rl[2]=var_ord; 1897 1897 1898 1898 rl[3]=tmp; 1899 rl[3][1]=tmp; 1899 rl[3][1]=tmp; 1900 1900 rl[3][1][1]=string("lp"); 1901 1901 intvec v=1; … … 1904 1904 v=v,1; 1905 1905 } 1906 rl[3][1][2]=v; 1906 rl[3][1][2]=v; 1907 1907 rl[3][2]=tmp; 1908 rl[3][2][1]=string("C"); 1908 rl[3][2][1]=string("C"); 1909 1909 rl[3][2][2]=intvec(0); 1910 1911 rl[4]=ideal(0); 1912 1910 1911 rl[4]=ideal(0); 1912 1913 1913 def r2=ring(rl); 1914 1914 setring r2; 1915 list l=ringlist(r2); 1915 list l=ringlist(r2); 1916 1916 if (e>1) 1917 1917 { 1918 execute(string("poly f="+minp)); 1919 ideal id=f; 1918 execute(string("poly f="+minp)); 1919 ideal id=f; 1920 1920 l[1][4]=id; 1921 1921 } 1922 1922 1923 1923 def r=ring(l); 1924 setring r; 1925 1924 setring r; 1925 1926 1926 return(list(r,s)); 1927 1927 } … … 1930 1930 // imitating two indeces 1931 1931 static proc x_var (int i, int j, int s) 1932 { 1932 { 1933 1933 return(x1(s*(i-1)+j)); 1934 1934 } … … 1937 1937 // random vector of length n with entries from p^e, p the characteristic 1938 1938 static proc randomvector(int n, int e) 1939 { 1939 { 1940 1940 int i; 1941 1941 matrix result[n][1]; … … 1944 1944 result[i,1]=asElement(random_prime_vector(e)); 1945 1945 } 1946 return(result); 1947 } 1948 1949 /////////////////////////////////////////////////////////////////////////////// 1950 // "convert" representation of an element from the field extension from vector 1946 return(result); 1947 } 1948 1949 /////////////////////////////////////////////////////////////////////////////// 1950 // "convert" representation of an element from the field extension from vector 1951 1951 //to an elelemnt 1952 1952 static proc asElement(list l) … … 1955 1955 int i; 1956 1956 number w=1; 1957 if (size(l)>1) {w=par(1);} 1957 if (size(l)>1) {w=par(1);} 1958 1958 for (i=0; i<=size(l)-1; i++) 1959 1959 { … … 1966 1966 // random vector of length n with entries from p, p the characteristic 1967 1967 static proc random_prime_vector (int n) 1968 { 1968 { 1969 1969 list rl=ringlist(basering); 1970 1970 int i, charac; … … 1972 1972 { 1973 1973 if (rl[1][1] mod i ==0) 1974 { 1974 { 1975 1975 break; 1976 1976 } 1977 1977 } 1978 charac=i; 1979 1978 charac=i; 1979 1980 1980 list l; 1981 1981 1982 1982 for (i=1; i<=n; i++) 1983 1983 { … … 1990 1990 1991 1991 proc decodeRandomFL(int n, int redun, int p, int e, int t, int ncodes, int ntrials, string minpol) 1992 "USAGE: decodeRandomFL(redun,p,e,n,t,ncodes,ntrials,minpol); 1992 "USAGE: decodeRandomFL(redun,p,e,n,t,ncodes,ntrials,minpol); 1993 1993 @format 1994 - n is length of codes generated, redun = redundancy of codes 1995 generated, 1996 - p is characteristics, 1997 - e is the extension degree, 1998 - t is the number of errors to correct, 1994 - n is length of codes generated, redun = redundancy of codes 1995 generated, 1996 - p is characteristics, 1997 - e is the extension degree, 1998 - t is the number of errors to correct, 1999 1999 - ncodes is the number of random codes to be processed, 2000 2000 - ntrials is the number of received vectors per code to be corrected, 2001 - minpol: due to some pecularities of SINGULAR one needs to provide 2001 - minpol: due to some pecularities of SINGULAR one needs to provide 2002 2002 minimal polynomial for the extension explicitly 2003 2003 @end format … … 2008 2008 intvec vopt = option(get); 2009 2009 2010 list l=FLpreprocess(p,e,n,t,minpol); 2011 2010 list l=FLpreprocess(p,e,n,t,minpol); 2011 2012 2012 def r=l[1]; 2013 int s_work=l[2]; 2013 int s_work=l[2]; 2014 2014 export(s_work); 2015 2015 setring r; 2016 2016 2017 2017 int i,j; 2018 2018 matrix h, g, word, y, rec; 2019 2019 int dist, tim, tim2, tim3, timdist, timdec, timdist2, timdec2, timdec3; 2020 2020 ideal sys, sys2, sys3; 2021 list tmp; 2022 2023 option(redSB); 2024 matrix z[1][n]; 2025 2021 list tmp; 2022 2023 option(redSB); 2024 matrix z[1][n]; 2025 2026 2026 for (i=1; i<=ncodes; i++) 2027 2027 { 2028 h=randomCheck(redun,n,e); 2028 h=randomCheck(redun,n,e); 2029 2029 g=dual_code(h); 2030 tim2=rtimer; 2030 tim2=rtimer; 2031 2031 tim3=rtimer; 2032 2032 2033 //---------------- generate the template system ----------------------- 2034 sys=sysFL(h,z,t,e,s_work); 2033 //---------------- generate the template system ----------------------- 2034 sys=sysFL(h,z,t,e,s_work); 2035 2035 timdec3=timdec3+rtimer-tim3; 2036 2036 2037 2037 //------ modifying the template according to the received word --------- 2038 2038 for (j=1; j<=ntrials; j++) … … 2041 2041 y=encode(transpose(word),g); 2042 2042 rec=errorRand(y,t,e); 2043 sys2=LF_add_synd(rec,h,sys); 2043 sys2=LF_add_synd(rec,h,sys); 2044 2044 tim=rtimer; 2045 2045 sys3=std(sys2); 2046 2046 timdec=timdec+rtimer-tim; 2047 } 2047 } 2048 2048 timdec2=timdec2+rtimer-tim2; 2049 } 2050 2049 } 2050 2051 2051 printf("Time for decoding: %p", timdec2); 2052 2052 printf("Time for GB in decoding: %p", timdec); 2053 printf("Time for generating Fitzgerald-Lax system during decoding: %p", timdec3); 2054 2053 printf("Time for generating Fitzgerald-Lax system during decoding: %p", timdec3); 2054 2055 2055 option(set,vopt); 2056 } 2056 } 2057 2057 example 2058 2058 { 2059 2059 "EXAMPLE:"; echo = 2; 2060 2061 // correcting one error for one random binary code of length 25, 2060 2061 // correcting one error for one random binary code of length 25, 2062 2062 //redundancy 14; 300 words are processed 2063 2063 decodeRandomFL(25,14,2,1,1,1,300,""); … … 2084 2084 2085 2085 "EXAMPLE:"; echo = 2; 2086 int q=128; int n=120; int redun=n-30; 2086 int q=128; int n=120; int redun=n-30; 2087 2087 ring r=(q,a),x,dp; 2088 2088 decodeRandom(n,redun,1,1,6); 2089 2089 2090 int q=128; int n=120; int redun=n-20; 2090 int q=128; int n=120; int redun=n-20; 2091 2091 ring r=(q,a),x,dp; 2092 2092 decodeRandom(n,redun,1,1,9); … … 2106 2106 2107 2107 "EXAMPLE:"; echo = 2; 2108 int q=128; int n=120; int redun=n-40; 2108 int q=128; int n=120; int redun=n-40; 2109 2109 ring r=(q,a),x,dp; 2110 2110 decodeRandom(n,redun,1,1,6); … … 2119 2119 decodeRandom(n,redun,1,1,24); 2120 2120 2121 int q=256; int n=150; int redun=n-10; 2121 int q=256; int n=150; int redun=n-10; 2122 2122 ring r=(q,a),x,dp; 2123 2123 decodeRandom(n,redun,1,1,26); … … 2156 2156 setring A; 2157 2157 print(qe); 2158 ideal red_qe=stdfglm(qe); 2158 ideal red_qe=stdfglm(qe); 2159 2159 2160 2160 */
Note: See TracChangeset
for help on using the changeset viewer.