Message Boards Message Boards

0
|
5200 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Use dynamic nested Do cycles and automatically discern input parameters?

Hi everybody,

I managed to create a simple program calculating the weight spectra of non-binary linear block codes (using the old GF package):

<< GaloisField`GaloisField`

DeclareGaloisField[GF8]

pp = 2^ExtensionDegree[GF8];

nd = 12; (* code word length *)

kd = 5;  (* the length of information vector *)

pmat = {{GF8[1], GF8[1], GF8[1], GF8[1], GF8[1], GF8[1], GF8[1]},
   {GF8[5], GF8[7], GF8[6], GF8[3], GF8[4], GF8[2], GF8[1]},
   {GF8[7], GF8[3], GF8[2], GF8[5], GF8[6], GF8[4], GF8[1]},
   {GF8[1], GF8[1], GF8[1], GF8[1], GF8[1], GF8[1], GF8[1]},
   {GF8[1], GF8[1], GF8[1], GF8[1], GF8[1], GF8[1], GF8[1]}}; (* parity part of generator matrix *)

 vysl = Array[w, nd, 0];

Do[w[i] = 0, {i, 0, nd}];

 Do[
   Do[
    Do[
     Do[
      Do[
       info = {GF8[n], GF8[m], GF8[l], GF8[j], GF8[i]};
       r = kd - Count[info, GF8[0]];
        s = (nd - kd) - Count[info.pmat, 0];
        t = r + s;
       ++w[t],
       {j, 0, pp - 1}],
      {i, 0, pp - 1}],
     {l, 0, pp - 1}],
    {m, 0, pp - 1}],
   {n, 0, pp - 1}];

Do[Print["code word weight ", p, " = ", w[p]], {p, 0, nd}]

Note: the above assumes a systematic form of generator matrix.

My question is how to make this nested "Do" structure dynamic, so I do not have to input it manually and it will be created automatically based on the input parameters: "nd" and "kd"?

I tried to use Nest[] but I wasn't successful (I am not a good programmer). Many thanks for your help,

Martin

POSTED BY: Martin Rakus
3 Replies

Hi Neil,

thanks for your answer. I am sorry for my delayed reply, I was very busy. Basically my program should calculate the weight spectrum of a given linear block code, which is defined by parity check matrix "pmat". It means that it should multiply every possible "kd" tuple from GF8 with "pmat" and count the number of nonzero coordinates of the product.Your proposed solution generates all information words at one instant, what in a real application will bring a very large matrix. I'll be thankful for some other suggestions,

Regards,

Martin

POSTED BY: Martin Rakus

Martin,

You should post the code in code format to make it easier to read. I hope that I am properly understanding what you want to do.

Using Do is *almost never the best approach in Mathematica -- it is best to use lists.

I would create a list of your permutations and then map your counting function onto the list. For example:

pp=3
perms =Permutations[Flatten[Table[Range[0,pp],pp]],{3}]

(*{{0,1,2},{0,1,3},{0,1,0},{0,1,1},{0,2,1},{0,2,3},{0,2,0},{0,2,2},{0,3,1},{0,3,2},{0,3,0},{0,3,3},{0,0,1},{0,0,2},{0,0,3},{0,0,0},{1,0,2},{1,0,3},{1,0,0},{1,0,1},{1,2,0},{1,2,3},{1,2,1},{1,2,2},{1,3,0},{1,3,2},{1,3,1},{1,3,3},{1,1,0},{1,1,2},{1,1,3},{1,1,1},{2,0,1},{2,0,3},{2,0,0},{2,0,2},{2,1,0},{2,1,3},{2,1,1},{2,1,2},{2,3,0},{2,3,1},{2,3,2},{2,3,3},{2,2,0},{2,2,1},{2,2,3},{2,2,2},{3,0,1},{3,0,2},{3,0,0},{3,0,3},{3,1,0},{3,1,2},{3,1,1},{3,1,3},{3,2,0},{3,2,1},{3,2,2},{3,2,3},{3,3,0},{3,3,1},{3,3,2},{3,3,3}}*)

Now map the GF8 onto it, but only at the second level:

Map[GF8,perms,{2}]

This returns a list of all your "info" lists from inside your do loop.

(*{{GF8[0],GF8[1],GF8[2]},{GF8[0],GF8[1],GF8[3]},{GF8[0],GF8[1],GF8[0]},{GF8[0],GF8[1],GF8[1]},{GF8[0],GF8[2],GF8[1]},{GF8[0],GF8[2],GF8[3]},{GF8[0],GF8[2],GF8[0]},{GF8[0],GF8[2],GF8[2]},{GF8[0],GF8[3],GF8[1]},{GF8[0],GF8[3],GF8[2]},{GF8[0],GF8[3],GF8[0]},{GF8[0],GF8[3],GF8[3]},{GF8[0],GF8[0],GF8[1]},{GF8[0],GF8[0],GF8[2]},{GF8[0],GF8[0],GF8[3]},{GF8[0],GF8[0],GF8[0]},{GF8[1],GF8[0],GF8[2]},{GF8[1],GF8[0],GF8[3]},{GF8[1],GF8[0],GF8[0]},{GF8[1],GF8[0],GF8[1]},{GF8[1],GF8[2],GF8[0]},{GF8[1],GF8[2],GF8[3]},{GF8[1],GF8[2],GF8[1]},{GF8[1],GF8[2],GF8[2]},{GF8[1],GF8[3],GF8[0]},{GF8[1],GF8[3],GF8[2]},{GF8[1],GF8[3],GF8[1]},{GF8[1],GF8[3],GF8[3]},{GF8[1],GF8[1],GF8[0]},{GF8[1],GF8[1],GF8[2]},{GF8[1],GF8[1],GF8[3]},{GF8[1],GF8[1],GF8[1]},{GF8[2],GF8[0],GF8[1]},{GF8[2],GF8[0],GF8[3]},{GF8[2],GF8[0],GF8[0]},{GF8[2],GF8[0],GF8[2]},{GF8[2],GF8[1],GF8[0]},{GF8[2],GF8[1],GF8[3]},{GF8[2],GF8[1],GF8[1]},{GF8[2],GF8[1],GF8[2]},{GF8[2],GF8[3],GF8[0]},{GF8[2],GF8[3],GF8[1]},{GF8[2],GF8[3],GF8[2]},{GF8[2],GF8[3],GF8[3]},{GF8[2],GF8[2],GF8[0]},{GF8[2],GF8[2],GF8[1]},{GF8[2],GF8[2],GF8[3]},{GF8[2],GF8[2],GF8[2]},{GF8[3],GF8[0],GF8[1]},{GF8[3],GF8[0],GF8[2]},{GF8[3],GF8[0],GF8[0]},{GF8[3],GF8[0],GF8[3]},{GF8[3],GF8[1],GF8[0]},{GF8[3],GF8[1],GF8[2]},{GF8[3],GF8[1],GF8[1]},{GF8[3],GF8[1],GF8[3]},{GF8[3],GF8[2],GF8[0]},{GF8[3],GF8[2],GF8[1]},{GF8[3],GF8[2],GF8[2]},{GF8[3],GF8[2],GF8[3]},{GF8[3],GF8[3],GF8[0]},{GF8[3],GF8[3],GF8[1]},{GF8[3],GF8[3],GF8[2]},{GF8[3],GF8[3],GF8[3]}}*)

Now you can map a simple function that takes your dot product and counts zeros. This approach simplifies your code.

I hope this helps. Did I understand what you want?

Regards

POSTED BY: Neil Singer

I think the pieces of code under test and/or t1 in the attached notebook could be helpful. You have to specify the number of Do-Loops (Lm) and the "endpoints" placed in the list j.

I forgot what I was trying to achieve in the last part of the notebook, so simpliy forget it

Hans

Attachments:
POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract