ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Mar 2018 19:06:41 +0100Creating a symbolic matrix in a loop and then substituting values in for the variables?https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/I need to create a symbolic matrix in terms of the variables xi with one row of n elements for a given integer n, so for example if n=5 i would need to compute the matrix `[x0, x1, x2, x3, x4]`
As a follow on from this i then need to substitute in random values from a finite field say `GF(q)` for the first `v` number of variables in the matrix for a given integer `v < n` . So for example if `v = 3` then i would need to substitute in random values from `GF(q)` for the first `x0, x1, x2 ` variables of the matrix to get something like `[GF(q).random_element(), GF(q).random_element(), GF(q).random_element(), x3, x4 ]` of course i need to be able to do this for any integers n and v i choose. Any help about how to do this in sage would be great, thanks.
EDIT: I need to substitute in random values from a finite field say `GF(q)` for the first `v` number of variables for a given integer `v < n` into each of the multivariate equations in a list. So for example, if my list of multivariate equations is given by `eqn` where `eqn` looks like the following: `[[10*x0^2 + 11*x0*x1 - 12*x1^2 - 14*x0*x2 + 8*x1*x2 + 6*x2^2 - 15*x0*x3 - 13*x1*x3 - 7*x2*x3 + 9*x3^2 - 13*x0*x4 + 11*x1*x4 + 6*x2*x4 - 15*x3*x4 + 11*x4^2 - 13*x0*x5 + 12*x1*x5 + 6*x2*x5 - 8*x4*x5 + x5^2], [4*x0^2 + 8*x0*x1 - 3*x1^2 - 8*x0*x2 - 3*x1*x2 - 10*x2^2 + 5*x0*x3 - 14*x1*x3 - 5*x2*x3 - 12*x3^2 - 10*x0*x4 + 8*x1*x4 - 10*x2*x4 - 4*x3*x4 + 6*x4^2 - 11*x0*x5 - 3*x1*x5 - 9*x2*x5 + 9*x3*x5 + 4*x4*x5 - 11*x5^2]]` when `o = 2` then i need to substitute random values from GF(q) into the first v variables, to obtain a list of multivariate equations in only the remaining variables that have not been substituted.Tue, 20 Mar 2018 15:44:10 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/Comment by slelievre for <p>I need to create a symbolic matrix in terms of the variables xi with one row of n elements for a given integer n, so for example if n=5 i would need to compute the matrix <code>[x0, x1, x2, x3, x4]</code> </p>
<p>As a follow on from this i then need to substitute in random values from a finite field say <code>GF(q)</code> for the first <code>v</code> number of variables in the matrix for a given integer <code>v < n</code> . So for example if <code>v = 3</code> then i would need to substitute in random values from <code>GF(q)</code> for the first <code>x0, x1, x2</code> variables of the matrix to get something like <code>[GF(q).random_element(), GF(q).random_element(), GF(q).random_element(), x3, x4 ]</code> of course i need to be able to do this for any integers n and v i choose. Any help about how to do this in sage would be great, thanks. </p>
<p>EDIT: I need to substitute in random values from a finite field say <code>GF(q)</code> for the first <code>v</code> number of variables for a given integer <code>v < n</code> into each of the multivariate equations in a list. So for example, if my list of multivariate equations is given by <code>eqn</code> where <code>eqn</code> looks like the following: <code>[[10*x0^2 + 11*x0*x1 - 12*x1^2 - 14*x0*x2 + 8*x1*x2 + 6*x2^2 - 15*x0*x3 - 13*x1*x3 - 7*x2*x3 + 9*x3^2 - 13*x0*x4 + 11*x1*x4 + 6*x2*x4 - 15*x3*x4 + 11*x4^2 - 13*x0*x5 + 12*x1*x5 + 6*x2*x5 - 8*x4*x5 + x5^2], [4*x0^2 + 8*x0*x1 - 3*x1^2 - 8*x0*x2 - 3*x1*x2 - 10*x2^2 + 5*x0*x3 - 14*x1*x3 - 5*x2*x3 - 12*x3^2 - 10*x0*x4 + 8*x1*x4 - 10*x2*x4 - 4*x3*x4 + 6*x4^2 - 11*x0*x5 - 3*x1*x5 - 9*x2*x5 + 9*x3*x5 + 4*x4*x5 - 11*x5^2]]</code> when <code>o = 2</code> then i need to substitute random values from GF(q) into the first v variables, to obtain a list of multivariate equations in only the remaining variables that have not been substituted.</p>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41675#post-id-41675In the definition of `eqn`, why do you have `[[f], [g]]` instead of `[f, g]`?Wed, 21 Mar 2018 13:24:42 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41675#post-id-41675Answer by tmonteil for <p>I need to create a symbolic matrix in terms of the variables xi with one row of n elements for a given integer n, so for example if n=5 i would need to compute the matrix <code>[x0, x1, x2, x3, x4]</code> </p>
<p>As a follow on from this i then need to substitute in random values from a finite field say <code>GF(q)</code> for the first <code>v</code> number of variables in the matrix for a given integer <code>v < n</code> . So for example if <code>v = 3</code> then i would need to substitute in random values from <code>GF(q)</code> for the first <code>x0, x1, x2</code> variables of the matrix to get something like <code>[GF(q).random_element(), GF(q).random_element(), GF(q).random_element(), x3, x4 ]</code> of course i need to be able to do this for any integers n and v i choose. Any help about how to do this in sage would be great, thanks. </p>
<p>EDIT: I need to substitute in random values from a finite field say <code>GF(q)</code> for the first <code>v</code> number of variables for a given integer <code>v < n</code> into each of the multivariate equations in a list. So for example, if my list of multivariate equations is given by <code>eqn</code> where <code>eqn</code> looks like the following: <code>[[10*x0^2 + 11*x0*x1 - 12*x1^2 - 14*x0*x2 + 8*x1*x2 + 6*x2^2 - 15*x0*x3 - 13*x1*x3 - 7*x2*x3 + 9*x3^2 - 13*x0*x4 + 11*x1*x4 + 6*x2*x4 - 15*x3*x4 + 11*x4^2 - 13*x0*x5 + 12*x1*x5 + 6*x2*x5 - 8*x4*x5 + x5^2], [4*x0^2 + 8*x0*x1 - 3*x1^2 - 8*x0*x2 - 3*x1*x2 - 10*x2^2 + 5*x0*x3 - 14*x1*x3 - 5*x2*x3 - 12*x3^2 - 10*x0*x4 + 8*x1*x4 - 10*x2*x4 - 4*x3*x4 + 6*x4^2 - 11*x0*x5 - 3*x1*x5 - 9*x2*x5 + 9*x3*x5 + 4*x4*x5 - 11*x5^2]]</code> when <code>o = 2</code> then i need to substitute random values from GF(q) into the first v variables, to obtain a list of multivariate equations in only the remaining variables that have not been substituted.</p>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?answer=41656#post-id-41656For constistency, let me use polynomial undeterminates instead of symbols. Does the following solve your problem ?
sage: F = GF(9)
sage: F
Finite Field in z2 of size 3^2
sage: R = PolynomialRing(F,'x',5)
sage: R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Finite Field in z2 of size 3^2
sage: R.inject_variables()
Defining x0, x1, x2, x3, x4
sage: R.gens()
(x0, x1, x2, x3, x4)
sage: M = matrix([list(R.gens())])
sage: M
[x0 x1 x2 x3 x4]
sage: substitution = {R.gens()[i]:F.random_element() for i in range(3)}
sage: substitution
{x2: 2*z2 + 2, x1: 1, x0: 2*z2 + 2}
sage: M.apply_map(lambda x : x.substitute(substitution))
[(-z2 - 1) 1 (-z2 - 1) x3 x4]
If yes, i can add some comments and explanations on demand. If no, could you please be more precise ?
Tue, 20 Mar 2018 17:47:12 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?answer=41656#post-id-41656Comment by Dalvir for <p>For constistency, let me use polynomial undeterminates instead of symbols. Does the following solve your problem ?</p>
<pre><code>sage: F = GF(9)
sage: F
Finite Field in z2 of size 3^2
sage: R = PolynomialRing(F,'x',5)
sage: R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Finite Field in z2 of size 3^2
sage: R.inject_variables()
Defining x0, x1, x2, x3, x4
sage: R.gens()
(x0, x1, x2, x3, x4)
sage: M = matrix([list(R.gens())])
sage: M
[x0 x1 x2 x3 x4]
sage: substitution = {R.gens()[i]:F.random_element() for i in range(3)}
sage: substitution
{x2: 2*z2 + 2, x1: 1, x0: 2*z2 + 2}
sage: M.apply_map(lambda x : x.substitute(substitution))
[(-z2 - 1) 1 (-z2 - 1) x3 x4]
</code></pre>
<p>If yes, i can add some comments and explanations on demand. If no, could you please be more precise ?</p>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41658#post-id-41658Thanks for your help i have edited the question to be more specific with what i require as i realize my initial question was not as precise. If you can help with that that would be great.Tue, 20 Mar 2018 18:28:59 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41658#post-id-41658Answer by nbruin for <p>I need to create a symbolic matrix in terms of the variables xi with one row of n elements for a given integer n, so for example if n=5 i would need to compute the matrix <code>[x0, x1, x2, x3, x4]</code> </p>
<p>As a follow on from this i then need to substitute in random values from a finite field say <code>GF(q)</code> for the first <code>v</code> number of variables in the matrix for a given integer <code>v < n</code> . So for example if <code>v = 3</code> then i would need to substitute in random values from <code>GF(q)</code> for the first <code>x0, x1, x2</code> variables of the matrix to get something like <code>[GF(q).random_element(), GF(q).random_element(), GF(q).random_element(), x3, x4 ]</code> of course i need to be able to do this for any integers n and v i choose. Any help about how to do this in sage would be great, thanks. </p>
<p>EDIT: I need to substitute in random values from a finite field say <code>GF(q)</code> for the first <code>v</code> number of variables for a given integer <code>v < n</code> into each of the multivariate equations in a list. So for example, if my list of multivariate equations is given by <code>eqn</code> where <code>eqn</code> looks like the following: <code>[[10*x0^2 + 11*x0*x1 - 12*x1^2 - 14*x0*x2 + 8*x1*x2 + 6*x2^2 - 15*x0*x3 - 13*x1*x3 - 7*x2*x3 + 9*x3^2 - 13*x0*x4 + 11*x1*x4 + 6*x2*x4 - 15*x3*x4 + 11*x4^2 - 13*x0*x5 + 12*x1*x5 + 6*x2*x5 - 8*x4*x5 + x5^2], [4*x0^2 + 8*x0*x1 - 3*x1^2 - 8*x0*x2 - 3*x1*x2 - 10*x2^2 + 5*x0*x3 - 14*x1*x3 - 5*x2*x3 - 12*x3^2 - 10*x0*x4 + 8*x1*x4 - 10*x2*x4 - 4*x3*x4 + 6*x4^2 - 11*x0*x5 - 3*x1*x5 - 9*x2*x5 + 9*x3*x5 + 4*x4*x5 - 11*x5^2]]</code> when <code>o = 2</code> then i need to substitute random values from GF(q) into the first v variables, to obtain a list of multivariate equations in only the remaining variables that have not been substituted.</p>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?answer=41659#post-id-41659It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:
sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]Tue, 20 Mar 2018 19:08:33 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?answer=41659#post-id-41659Comment by Dalvir for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41664#post-id-41664Thanks a lot for this. However when i have tried to implement this as follows:
`Rx=PolynomialRing(GF(q),n,'x')`
`Ry=PolynomialRing(GF(q),n-v,['x%s'%p for p in[v..n-1]])`
`images = [GF(q).random_element() for i in range(v)]+list(Ry.gens())`
`phi=Rx.hom(images,Ry)`
`List=[eqn[j] for j in range(o)]`
`[phi(f) for f in List]`
Where eqn is my list of `o` random multivariate equations in `n` variables
But when running this it shows the following error `TypeError: [10*x0^2 + 11*x0*x1 - 12*x1^2 - 14*x0*x2 + 8*x1*x2 + 6*x2^2 - 15*x0*x3 - 13*x1*x3 - 7*x2*x3 + 9*x3^2 - 13*x0*x4 + 11*x1*x4 + 6*x2*x4 - 15*x3*x4 + 11*x4^2 - 13*x0*x5 + 12*x1*x5 + 6*x2*x5 - 8*x4*x5 + x5^2] fails to convert into the map's domain Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5 over Finite Field`Wed, 21 Mar 2018 01:24:43 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41664#post-id-41664Comment by nbruin for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41665#post-id-41665Make sure that the polynomials you work with are actually members of Rx. If you define those polynomials by typing/pasting them in, try `Rx.inject_variables()` before defining them.Wed, 21 Mar 2018 02:33:49 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41665#post-id-41665Comment by Dalvir for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41668#post-id-41668After changing `Rx` to `P=PolynomialRing(K,'x',n)` where `K.<a>=GF(q)` as my polynomials are members of a ring `P` i defined earlier (although the generators of `Rx` in your example above and `P` are actually exactly the same) i now get the following errors: `raise TypeError("%s fails to convert into the map's domain %s, but a pushforward method is not properly implemented" % (x, D))`
`TypeError: [3*x0^2 + 11*x0*x1 + 9*x1^2 - 10*x0*x2 - 9*x1*x2 - 10*x2^2 - 11*x0*x3 + 8*x1*x3 - 3*x2*x3 - 11*x3^2 + 9*x0*x4 + x1*x4 - 3*x3*x4 - 8*x4^2 + 3*x0*x5 + 3*x1*x5 + 2*x2*x5 - 15*x3*x5 + 4*x4*x5 + 13*x5^2] fails to convert into the map's domain Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5 over Finite Field of size 31, but a pushforward method is not properly implemented`Wed, 21 Mar 2018 09:03:24 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41668#post-id-41668Comment by slelievre for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41674#post-id-41674This error is after running what command exactly?Wed, 21 Mar 2018 13:23:53 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41674#post-id-41674Comment by Dalvir for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41676#post-id-41676The error occurs after running `[phi(f) for f in List]`. And in answer to your question above about why in the definition of `eqn` i have `[[f], [[g]]`, this is because the equations are actually formed from the following: `eqn =[tp1*P[i]*tp1.transpose() for i in range(o)]` where `tp1=matrix(P.gens())` and `tp1. transpose` is just the transpose of that matrix and the central matrix `P[i]` is a square `nxn` matrix of values in `GF(q)` that i have determined. This multiplication when `n=6`looks like `[x0, x1, x2, x3, x4, x5]*P[i]*[x0, x1, x2, x3, x4, x5].transpose` and this yields a matrix with 1 element, and that element is the multivariate equation, and that is why the equations in the list `eqn` are of the form: 1x1 dense matrices over Multivariate Polynomial Ring in x0,...,x5 over GF(q)Wed, 21 Mar 2018 14:05:34 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41676#post-id-41676Comment by nbruin for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41687#post-id-41687Then just use `eqn =[(tp1*P[i]*tp1.transpose())[0,0] for i in range(o)]` to strip away the 1x1 matrices around the polynomials.Wed, 21 Mar 2018 16:26:39 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41687#post-id-41687Comment by Dalvir for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41688#post-id-41688Okay thanks for that, that seems to have worked for me. But i have now ran into another issue. After substitution of these random values i have made the resulting equations in the remaining variables equal to random values in `GF(q)` for example `[-3*x4 + 2*x5 + 8, -11*x4 + 6*x5 + 3] = [4,5]` but when i try to use the solve function to solve the equations for `x4` and `x5` with the following `l=solve(s, Ry.gens())` where `s` is the list of equations given above in which each equation has been made equal to a value in `GF(q)` i get the following error `TypeError: x4 is not a valid variable.` and even if i try to solve in the explicit example above as follows `l=solve(s, x4, x5)` it simply keeps on returning an empty list `[]` regardless of what the equations turn out to be. ??Wed, 21 Mar 2018 16:45:49 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41688#post-id-41688Comment by nbruin for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41689#post-id-41689Solve doesn't work in positive characteristic. You could try `Ry.ideal(s).variety()`.Wed, 21 Mar 2018 17:47:05 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41689#post-id-41689Comment by Dalvir for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41691#post-id-41691After trying this it says that `The dimension of the ideal is 2, but it should be 0` ...i require the dimension to be zero so finitely many solutions though, is there a way around this? When i check what the ideal of s is i get the following: `Ideal (0, 0) of Multivariate Polynomial Ring in x4, x5 over Finite Field of size 31
`Wed, 21 Mar 2018 18:41:40 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41691#post-id-41691Comment by nbruin for <p>It's presently not entirely clear if you want new random values for each evaluation or if you want to establish random values first and then evaluate all polynomials at them (the latter can occur as part of the former, just with very low probability). Since evaluation establishes a ring homomorphism, you could construct one that does what you want. If you're going to use each homomorphism only once, it might be a bit of an overhead, but otherwise it's nice and concise:</p>
<pre><code>sage: n=5
sage: v=3
sage: Rx=PolynomialRing(F,n,'x')
sage: Ry=PolynomialRing(F,n-v,'y')
sage: images = [F.random_element() for i in range(v)]+list(Ry.gens())
sage: phi=Rx.hom(images,Ry)
sage: L=[Rx.random_element() for j in range(3)] # as an example
sage: [phi(f) for f in L]
[-2*y1^2 - y0 - y1, -y1^2 - 2*y1 + 2, y0^2 + y1^2]
</code></pre>
https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41694#post-id-41694Hm, I see. Don't put equations as a generators into an ideal. Would be nicer if you'd get an error instead of 0 out of that, but sometimes python gets in the way of things. Instead, perhaps do s=[eqn.lhs()-eqn.rhs() for eqn in s], or just don't make equations in the first place.Wed, 21 Mar 2018 19:06:41 +0100https://ask.sagemath.org/question/41655/creating-a-symbolic-matrix-in-a-loop-and-then-substituting-values-in-for-the-variables/?comment=41694#post-id-41694