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.
abstract-algebra magma-cas
add a comment |
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.
abstract-algebra magma-cas
add a comment |
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.
abstract-algebra magma-cas
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
abstract-algebra magma-cas
edited Nov 12 at 19:54
André 3000
12.1k22041
12.1k22041
asked Nov 12 at 17:33
zermelovac
499212
499212
add a comment |
add a comment |
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.
add a comment |
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);
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 12 at 20:29
André 3000
12.1k22041
12.1k22041
add a comment |
add a comment |
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);
add a comment |
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);
add a comment |
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);
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);
answered 2 days ago
Morgan Rodgers
9,53521338
9,53521338
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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