Writing a vector variable in Magma.











up vote
0
down vote

favorite












So let's assume I am working with $n$-dimensional functions. In Magma I have a code that goes like this:



n:=4;
function fun(x1,x2,x3,x4)
return (x1*x2+x3*x4) mod 2;
end function;


Now, if I want to increase $n$, I have to manually write all the variables from $x_1$ to $x_8$. Is there a more convenient way to do this, by saying that $x$ is in some Vector space $GF(2)^8$ or something similar, to avoid this manual writing.










share|cite|improve this question




























    up vote
    0
    down vote

    favorite












    So let's assume I am working with $n$-dimensional functions. In Magma I have a code that goes like this:



    n:=4;
    function fun(x1,x2,x3,x4)
    return (x1*x2+x3*x4) mod 2;
    end function;


    Now, if I want to increase $n$, I have to manually write all the variables from $x_1$ to $x_8$. Is there a more convenient way to do this, by saying that $x$ is in some Vector space $GF(2)^8$ or something similar, to avoid this manual writing.










    share|cite|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      So let's assume I am working with $n$-dimensional functions. In Magma I have a code that goes like this:



      n:=4;
      function fun(x1,x2,x3,x4)
      return (x1*x2+x3*x4) mod 2;
      end function;


      Now, if I want to increase $n$, I have to manually write all the variables from $x_1$ to $x_8$. Is there a more convenient way to do this, by saying that $x$ is in some Vector space $GF(2)^8$ or something similar, to avoid this manual writing.










      share|cite|improve this question















      So let's assume I am working with $n$-dimensional functions. In Magma I have a code that goes like this:



      n:=4;
      function fun(x1,x2,x3,x4)
      return (x1*x2+x3*x4) mod 2;
      end function;


      Now, if I want to increase $n$, I have to manually write all the variables from $x_1$ to $x_8$. Is there a more convenient way to do this, by saying that $x$ is in some Vector space $GF(2)^8$ or something similar, to avoid this manual writing.







      abstract-algebra magma-cas






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Nov 12 at 19:54









      André 3000

      12.1k22041




      12.1k22041










      asked Nov 12 at 17:33









      zermelovac

      499212




      499212






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Yes, this can be done: you can pull the dimension of the parent of the input. See the following code:



          function f(x)
          V := Parent(x);
          F := BaseField(V);
          d := Dimension(V);
          ans := F!0;
          for i := 1 to (d div 2) do
          ans := ans + x[2*i-1]*x[2*i];
          end for;
          return ans;
          end function;

          F := GF(2);
          V := VectorSpace(F,8);
          my_x := Random(V);

          f(my_x);


          For more, see the Magma handbook.






          share|cite|improve this answer




























            up vote
            0
            down vote













            You can do this several ways.



            If $x$ is a vector in $V = {GF(2)}^{n}$, then you can define



            f := func<x | &+[x[i] : i in [1..OverDimension(x)]]>;


            and call through



            f(V![x1, x2, x3, .., xn]);


            but this is a pain if you want to use different vectors of different lengths.
            You might as well just have $x$ be a sequence of $GF(2)$ elements, so you can define



            f := func<x | &+x>;


            and call through



            f([x1, x2, x3, .., xn]);


            A third option is to use a variadic function, that can take varying number of inputs and stores them all as a list. Here you would define



            f := func<x, ... | &+[a : a in x]>;


            This is nicest in terms of calling since these will all work:



            f(a);
            f(a,b);
            f(a,b,c,d,e,f,g);





            share|cite|improve this answer





















              Your Answer





              StackExchange.ifUsing("editor", function () {
              return StackExchange.using("mathjaxEditing", function () {
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              });
              });
              }, "mathjax-editing");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "69"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              noCode: true, onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2995593%2fwriting-a-vector-variable-in-magma%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              Yes, this can be done: you can pull the dimension of the parent of the input. See the following code:



              function f(x)
              V := Parent(x);
              F := BaseField(V);
              d := Dimension(V);
              ans := F!0;
              for i := 1 to (d div 2) do
              ans := ans + x[2*i-1]*x[2*i];
              end for;
              return ans;
              end function;

              F := GF(2);
              V := VectorSpace(F,8);
              my_x := Random(V);

              f(my_x);


              For more, see the Magma handbook.






              share|cite|improve this answer

























                up vote
                0
                down vote













                Yes, this can be done: you can pull the dimension of the parent of the input. See the following code:



                function f(x)
                V := Parent(x);
                F := BaseField(V);
                d := Dimension(V);
                ans := F!0;
                for i := 1 to (d div 2) do
                ans := ans + x[2*i-1]*x[2*i];
                end for;
                return ans;
                end function;

                F := GF(2);
                V := VectorSpace(F,8);
                my_x := Random(V);

                f(my_x);


                For more, see the Magma handbook.






                share|cite|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Yes, this can be done: you can pull the dimension of the parent of the input. See the following code:



                  function f(x)
                  V := Parent(x);
                  F := BaseField(V);
                  d := Dimension(V);
                  ans := F!0;
                  for i := 1 to (d div 2) do
                  ans := ans + x[2*i-1]*x[2*i];
                  end for;
                  return ans;
                  end function;

                  F := GF(2);
                  V := VectorSpace(F,8);
                  my_x := Random(V);

                  f(my_x);


                  For more, see the Magma handbook.






                  share|cite|improve this answer












                  Yes, this can be done: you can pull the dimension of the parent of the input. See the following code:



                  function f(x)
                  V := Parent(x);
                  F := BaseField(V);
                  d := Dimension(V);
                  ans := F!0;
                  for i := 1 to (d div 2) do
                  ans := ans + x[2*i-1]*x[2*i];
                  end for;
                  return ans;
                  end function;

                  F := GF(2);
                  V := VectorSpace(F,8);
                  my_x := Random(V);

                  f(my_x);


                  For more, see the Magma handbook.







                  share|cite|improve this answer












                  share|cite|improve this answer



                  share|cite|improve this answer










                  answered Nov 12 at 20:29









                  André 3000

                  12.1k22041




                  12.1k22041






















                      up vote
                      0
                      down vote













                      You can do this several ways.



                      If $x$ is a vector in $V = {GF(2)}^{n}$, then you can define



                      f := func<x | &+[x[i] : i in [1..OverDimension(x)]]>;


                      and call through



                      f(V![x1, x2, x3, .., xn]);


                      but this is a pain if you want to use different vectors of different lengths.
                      You might as well just have $x$ be a sequence of $GF(2)$ elements, so you can define



                      f := func<x | &+x>;


                      and call through



                      f([x1, x2, x3, .., xn]);


                      A third option is to use a variadic function, that can take varying number of inputs and stores them all as a list. Here you would define



                      f := func<x, ... | &+[a : a in x]>;


                      This is nicest in terms of calling since these will all work:



                      f(a);
                      f(a,b);
                      f(a,b,c,d,e,f,g);





                      share|cite|improve this answer

























                        up vote
                        0
                        down vote













                        You can do this several ways.



                        If $x$ is a vector in $V = {GF(2)}^{n}$, then you can define



                        f := func<x | &+[x[i] : i in [1..OverDimension(x)]]>;


                        and call through



                        f(V![x1, x2, x3, .., xn]);


                        but this is a pain if you want to use different vectors of different lengths.
                        You might as well just have $x$ be a sequence of $GF(2)$ elements, so you can define



                        f := func<x | &+x>;


                        and call through



                        f([x1, x2, x3, .., xn]);


                        A third option is to use a variadic function, that can take varying number of inputs and stores them all as a list. Here you would define



                        f := func<x, ... | &+[a : a in x]>;


                        This is nicest in terms of calling since these will all work:



                        f(a);
                        f(a,b);
                        f(a,b,c,d,e,f,g);





                        share|cite|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You can do this several ways.



                          If $x$ is a vector in $V = {GF(2)}^{n}$, then you can define



                          f := func<x | &+[x[i] : i in [1..OverDimension(x)]]>;


                          and call through



                          f(V![x1, x2, x3, .., xn]);


                          but this is a pain if you want to use different vectors of different lengths.
                          You might as well just have $x$ be a sequence of $GF(2)$ elements, so you can define



                          f := func<x | &+x>;


                          and call through



                          f([x1, x2, x3, .., xn]);


                          A third option is to use a variadic function, that can take varying number of inputs and stores them all as a list. Here you would define



                          f := func<x, ... | &+[a : a in x]>;


                          This is nicest in terms of calling since these will all work:



                          f(a);
                          f(a,b);
                          f(a,b,c,d,e,f,g);





                          share|cite|improve this answer












                          You can do this several ways.



                          If $x$ is a vector in $V = {GF(2)}^{n}$, then you can define



                          f := func<x | &+[x[i] : i in [1..OverDimension(x)]]>;


                          and call through



                          f(V![x1, x2, x3, .., xn]);


                          but this is a pain if you want to use different vectors of different lengths.
                          You might as well just have $x$ be a sequence of $GF(2)$ elements, so you can define



                          f := func<x | &+x>;


                          and call through



                          f([x1, x2, x3, .., xn]);


                          A third option is to use a variadic function, that can take varying number of inputs and stores them all as a list. Here you would define



                          f := func<x, ... | &+[a : a in x]>;


                          This is nicest in terms of calling since these will all work:



                          f(a);
                          f(a,b);
                          f(a,b,c,d,e,f,g);






                          share|cite|improve this answer












                          share|cite|improve this answer



                          share|cite|improve this answer










                          answered 2 days ago









                          Morgan Rodgers

                          9,53521338




                          9,53521338






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2995593%2fwriting-a-vector-variable-in-magma%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                              ComboBox Display Member on multiple fields

                              Is it possible to collect Nectar points via Trainline?