ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 14 Jun 2020 07:14:04 -0500Possible bug when a symbolic function is declared twicehttps://ask.sagemath.org/question/51964/possible-bug-when-a-symbolic-function-is-declared-twice/ I don't understand the output of the following code:
sage: f = function('f')
sage: f(x).operator() is f
True
sage: f = function('f')
sage: f(x).operator() is f
False
Is that the intended behavior?
It seems that ``operator`` returns the first symbolic function defined with this name, not the actual operator. This is problematic for me because it means there are some cells in my notebook I can only run once, so I have to restart the kernel everytime I want to press "run all".Florentin JaffredoSun, 14 Jun 2020 07:14:04 -0500https://ask.sagemath.org/question/51964/Ideal.variety() when working with symbolic ringshttps://ask.sagemath.org/question/43873/idealvariety-when-working-with-symbolic-rings/I have a system of multivariate polynomials I would like to solve (the equations come from chemical reaction networks). I have many symbolic constants, but I've managed to generate a Groebner basis with the following code (using a toy example with solutions {{x: x0, y:0},{x: 0,y: x0}):
x0 = var('x0') # In practice, there are many constants
S.<x,y> = PolynomialRing(SR,order='lex'); # in practice, there are 3-10 variables
I = S.ideal(
x**2 + y**2 - x0**2,
x + y - x0
)
print(I.dimension()) # dimension should always be zero
# >> 0
print(I.groebner_basis())
# >> [x + y - x0,
# >> y^2 + (-x0)*y]
In practice, I get many resulting equations which are extremely long, and it is numerically challenging to sequentially find the roots of these polynomials (in downstream code, I will get values for the constant parameters and then need to return solutions to these equations on the fly). Using the `I.variety()` method would be great to symbolically isolate all possible solutions, but I get confusing internal errors when I try to evaluate it.
print(I.variety()) # should be equivalent to: I.variety(ring=SR)
#/Users/ksb/SageMath/local/lib/python2.7/site-packages/sage/rings/polynomial/multi_polynomial_ideal.pyc in _variety(T, V, v)
# 2340
# 2341 variable = f.variable(0)
#-> 2342 roots = f.univariate_polynomial().roots(ring=ring, multiplicities=False)
# 2343
# 2344 for root in roots:
#
#/Users/ksb/SageMath/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_element.pyx in sage.rings.polynomial.polynomial_element.Polynomial.roots (build/cythonized/sage/rings/polynomial/polynomial_element.c:68811)()
# 7714 return l
# 7715 else:
#-> 7716 return [val for val,m in l]
# 7717 vname = 'do_not_use_this_name_in_a_polynomial_coefficient'
# 7718 var = SR(vname)
# TypeError: 'sage.symbolic.expression.Expression' object is not iterable
Is this expected behavior? When I try `f.univariate_polynomial().roots(ring=ring, multiplicities=False)` (setting `multiplicities=True` is what `I.variety()` does and leads to the error) I get `[1/2*x0,2]` for roots, which makes little sense (it seems like the roots should be `[0,-x0]`).
I would be happy to convert the `MPolynomial_polydict` (or the `sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class` generated by `univariate_polynomial()`) into a symbolic expression that I could just set it equal to zero and use `solve` on it, but I don't know how to do this type conversion. ksbMon, 08 Oct 2018 12:41:03 -0500https://ask.sagemath.org/question/43873/Matrix Group over Symbolic Ringhttps://ask.sagemath.org/question/40976/matrix-group-over-symbolic-ring/I have problem on generate matrix group over symbolic ring.
First, I define
eta=I;
eta2=(1+I)*sqrt(2)/2;
Then, define a generator matrix
T=matrix(SR,4,[eta**(i*j)*eta2/2 for i in range(4) for j in range(4)]);
I try to make a matrix group by
G=MatrixGroup(T);
What I get is only very long computation that does not give any result.
Can somebody help me? Thank you very much.
I have checked the order of T, I got 8 since T**8=I where I is identity matrix. dimahphoneSun, 04 Feb 2018 22:31:14 -0600https://ask.sagemath.org/question/40976/recursively solve and substitutehttps://ask.sagemath.org/question/40753/recursively-solve-and-substitute/I'm working on a pretty complicated problem (theoretically, not necessarily computationally). I'm not sure how to distill my question down to a simple example. But basically I have a system of equations over the ring of polynomials (or power series) over the symbolic ring. I want to be able to recursively solve for one symbolic function in terms of another, substitute the solution, and repeat. The ultimate goal is to extract relevant data all as a function of some positive integer k. It seems like I should be able to build a loop to do this, but I'm new to sage and programming in general. I haven't been able to find anything quite like what I'm trying to do online. So I'm asking for suggestions.
Here are some more details:
I have several polynomial expressions
j,k,z = var('j,k,z')
a,f=function('a,f')
p= lambda k : z^(-2*k) + sum(a(j)*z^(-j) for j in range(2*k-1))
F= lambda k : sum(f(j)*z^j, j, 2, 2*k)
which I plug into a formal matrix valued function and perform a series of algebraic manipulations. In the end I get a matrix whose entries are polynomials in the a(j)'s and f(j)'s. I want to recursively solve for the f(j)'s in terms of the a(j)'s so as to diagonalize this matrix expression. I can do this "by hand" but I want a function that will just spit out the end result. For example I know that f(2) = 1/4*a(2*k-2) for any k.
I've tried, for example:
def A1(k) :
for j in range(2,2*k) :
A0(k)=A0(k).substitute(f0(k,j)[0])
return A0(k)
Here A0(k) is a previously defined matrix expression and f0(k,j) is a function that solves for f(j). This code actually runs but then trying to call A1(2), etc., leads to errors.
Another attempt was to define
A1= lambda k,j : coef(A0(k),-k-2+j).substitute(f0(k,j)[0])
and then try to define a function of k in terms of the A1(k,j)'s using the sum() command. (In the code above coef(A,j) is a function that returns the coefficient of the z^j term in a polynomial over a ring of matrices).
The problem with this last attempt is that A1(k,j) for j bigger than 2 returns terms that include f(2), f(3), etc. I need something that solves for f(2), substitutes this value for f(2) into all future computations; then solves for f(3), substitutes this values for f(3) into all future computations; and so on until f(2*k).
I apologize if this question is too broad somehow. In looking over some of the literature on loops, solve(), substitute(), etc., I haven't found anything quite like this. Any suggestions? And thank you.charleslebarronTue, 23 Jan 2018 12:33:04 -0600https://ask.sagemath.org/question/40753/