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.Sun, 11 Dec 2022 16:47:37 +0100How can I get solutions to this inequalities in sage?Or how I have to interpret the outcomehttps://ask.sagemath.org/question/65317/how-can-i-get-solutions-to-this-inequalities-in-sageor-how-i-have-to-interpret-the-outcome/These inequalities
a,a_1,a_2,b,b_1,b_2=var('a,a_1,a_2,b,b_1,b_2')
solve([b_2<a_2,a<b,0<a<a_1<a_2,0<b<b_1<b_2,a_1^2+b_1^2-2*a_1*b_1+(a_2-b_2)*(a-b)<0],a,a_1,a_2,b,b_1,b_2,solution_dict=True)KeyvanSun, 11 Dec 2022 16:47:37 +0100https://ask.sagemath.org/question/65317/All the solutions of a polynomial system over a finite ringhttps://ask.sagemath.org/question/62787/all-the-solutions-of-a-polynomial-system-over-a-finite-ring/Let $E$ be a finite list of polynomial equations with variables $t_0, \dots, t_r$ over the finite ring of integers modulo $n$ (for some $n$). We can compute the Groebner basis as follows:
ZN=Integers(n)
R=PolynomialRing(ZN,r,"t")
R.inject_variables()
Id=R.ideal(E)
G=Id.groebner_basis()
Usually, over a field and if `Id.dimension()=0` then we can get all the solutions by `Id.variety()`. But here the dimension is not necessarily $0$ and moreover it is not over a field but a ring, the finite ring of integers modulo $n$. By finiteness of the ring, there still have finitely many solutions. How to get them all?
*Example*: $n=248832$, $r=10$ and:
sage: G
[t4*t7, t7*t8, t7*t9, t0, t1, t2, t3 + 248831*t4, 2*t4, t5 + 248783*t7, t6 + 11*t7, 9*t7, 4*t8 + 248828*t9, 16*t9]Sébastien PalcouxSat, 11 Jun 2022 12:47:46 +0200https://ask.sagemath.org/question/62787/How do I filter only integer solutions in sagemath?https://ask.sagemath.org/question/62060/how-do-i-filter-only-integer-solutions-in-sagemath/How do I filter only integer solutions in sagemath?
import time
Start_Time = time.time()
var('x y N M F f G g L l Q q S s U u')
eq0 = N-1019 == 0
eq3 = (32*((2*(3*3/4*M+1)-3*(-x)+1)/24)+3*(2*f-1)^2-3)/8-F==0
eq4 = ((2*(3*3/4*M+1)-3*(-x)+1)/24)+3/4*M- F == 0
eq5 = (32*((2*(3*F+1)-3*(f)+1)/24)+3*(2*g-1)^2-3)/8-G==0
eq6 = ((2*(3*F+1)-3*(f)+1)/24)+3/4*M- G == 0
eq7 = (32*((2*(3*G+1)-3*(g)+1)/24)+3*(2*l-1)^2-3)/8-L==0
eq8 = ((2*(3*G+1)-3*(g)+1)/24)+3/4*M- L == 0
eq9 = (32*((2*(3*L+1)-3*(l)+1)/24)+3*(2*q-1)^2-3)/8-Q==0
eq10 = ((2*(3*L+1)-3*(l)+1)/24)+3/4*M- Q == 0
eq11 = (32*((2*(3*Q+1)-3*(q)+1)/24)+3*(2*s-1)^2-3)/8-S==0
eq12 = ((2*(3*Q+1)-3*(q)+1)/24)+3/4*M- S == 0
eq13 = (32*((2*(3*S+1)-3*(s)+1)/24)+3*(2*u-1)^2-3)/8-U==0
eq14 = ((2*(3*S+1)-3*(s)+1)/24)+3/4*M- U == 0
eq15 =u+1==0
eq16 = (N-3)/8+y*(y-1)/2-M == 0
eq17 = 2*x*(x+1)-M == 0
solutions = solve([eq0,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,eq13,eq14,eq15,eq16,eq17],x,y,N,M,F,f,G,g,L,l,Q,q,S,s,U,u)
sol = solutions
Execution_Time = time.time() - Start_Time
print (Execution_Time)
print(sol)Periodic_1_6Wed, 20 Apr 2022 11:10:08 +0200https://ask.sagemath.org/question/62060/Unexpected result for trigonometric functionhttps://ask.sagemath.org/question/51525/unexpected-result-for-trigonometric-function/I'm trying to solve the following trig eqn using sage.
$$sin(x)-cos(x) = 0$$
Hand calculation give me the result of: $$x=\frac{\pi}{4} + n\pi$$
However, the `solve()` function gives me a different result, why is that?:
sage:
sage: solve(sin(x)-cos(x) == 0, x, to_poly_solve=True)
[x == 1/4*pi + pi*z25]
sage:
Also, what's `z` in the answer? I haven't defined any such variable.ggSun, 24 May 2020 03:39:24 +0200https://ask.sagemath.org/question/51525/can sage return a list of numbers from solve() instead of expressions?https://ask.sagemath.org/question/49245/can-sage-return-a-list-of-numbers-from-solve-instead-of-expressions/ is there any builtin methods to have `solve()` return a list of numbers instead of the sequence of expressions that it does?
which is to say `solve(eqn, x)` would return:
> $[x_1, x_2, ...,x_n]$
instead of:
> $[x == x_1, x == x_2, ... , x == x_n]$
or if there are not any built in functions recommended approaches? this is in a sage script im rating that at this point in the program is taking polynomials, computing their first and second derivatives, and adding the roots of those derivatives to a list, which needs to be iterable. if there does not exist some sage method or options for this, i believe i would need to revert to regex, which feels like im doing something wrong if thats what im having to do herealienfetuseaterSun, 29 Dec 2019 07:02:07 +0100https://ask.sagemath.org/question/49245/A way of checking that a multivariate system of equations has a solution?https://ask.sagemath.org/question/41913/a-way-of-checking-that-a-multivariate-system-of-equations-has-a-solution/Is there a way to check that a multivariate system of polynomial equations does indeed have a solution(or not)? The context i am using this in is as follows: say i have a system of multivariate polynomial equations over a finite field, i then put values in for some of the variables, and then i need to check if the resulting system in the remaining unassigned variables has a solution or not? If not, then i will reassign different values to the other variables until a system with a solution is yielded. Of course because the assigning of these values is random there is a high chance the system has a solution anyway, but in the event that it does not is where i need a way to check whether a solution exists or not.DalvirSun, 08 Apr 2018 20:40:45 +0200https://ask.sagemath.org/question/41913/Use `solve`output to create a functionhttps://ask.sagemath.org/question/39802/use-solveoutput-to-create-a-function/Hi there,
I want to use the ouptut of `solve` to create a function from it.
My system depends on some parameter, say $a$, it is a tiny linear system $2\times 2$, and I know there is always a solution. The right-hand term also contains some $a$ into it. What I want to do is to use the first and the second component to buy functions, calle them `x1(a)` and `x2(a)` that I will call later. I tried something like
`var("v1, v2, a")`
`Sols = solve([v1+a*v2 == a, -a*v1 + v2 ==0],[v1,v2])`
`x1(a) = Sols[0][0].rhs()`
`x2(a) = Sols[0][1].rhs()`
This gives the expected expressions for `x1` and `x2` but I cannot use these to do further computations, for instance, using `x1(1)` wont evaluate the expression when $a=1$, as I would expect.
The very precise example above is not what I actually want to handle, my actual system is actually more complex.
Many thanks!JCSun, 26 Nov 2017 21:25:48 +0100https://ask.sagemath.org/question/39802/Ritt-Wu algorithm?https://ask.sagemath.org/question/27046/ritt-wu-algorithm/Has anybody implemented in Sage the [Ritt-Wu](http://en.wikipedia.org/wiki/Wu%27s_method_of_characteristic_set) algorithm for solving multivariate polynomial equations? Apparently (I've never used it, although I'd certainly like to try it!) it can be used as an alternative to the better known technique of Groebner bases. There is a `wsolve` operation in Maple, but I don't have access to Maple.AlasdairSun, 07 Jun 2015 08:18:20 +0200https://ask.sagemath.org/question/27046/Substituting a particular value for a parameterhttps://ask.sagemath.org/question/11024/substituting-a-particular-value-for-a-parameter/This question is a follow-on to [this one](http://ask.sagemath.org/question/3501/two-questions-about-parameters-in-solutions) I asked earlier. Suppose I have a return value (a list called `sols`) to a `solve` command which includes an extra parameter, like
[2+r1,2-r1,2*r1]
If I want to substitute a value for `r1`, I need to, for example:
var('r1')
[xx.subs(r1=2/3) for xx in sols]
However, if I happen to run the solve command again, the new parameter changes to r2, and then I have to change the above commands to work with r2 instead of r1. And of course if other parameters have been created in the course of my Sage session, the r1 above could be anything.
What I need is some way of both isolating that extra parameter, and substituting for it. One way seems to be something like:
params = [xx.variables()[0] for xx in sols]
[xx.subs_expr(p==2/3) for xx,p in zip(sols,params)]
which works if the extra parameter is listed first in each variable list. The command
solvars = reduce(lambda x,y:union(x,y),[xx.variables() for xx in svals])
produces a list in which the extra parameter is last. So I could use
[xx.subs_expr(solvars[-1]==2/3) for xx in sols]
But none of these particularly automatic, in terms of isolating the extra parameter. They seem to require some extra knowledge of where the parameter is in the variables list.
So what is the best way of doing this, which is robust and automatic?AlasdairTue, 11 Feb 2014 18:38:22 +0100https://ask.sagemath.org/question/11024/Two questions about parameters in solutionshttps://ask.sagemath.org/question/10997/two-questions-about-parameters-in-solutions/In the Sage documentation, this example is given:
sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
of a solution which includes an extra parameter:
[[x=?r1+3,y=r1]]
1. If I run this comand again, the solution is given with r2, then again with r3 etc. Is it possible to "reset" the parameter number?
2. How does one substitute a particular value for this parameter? I can do it by iterating through the list and using rhs():
[i.rhs().subs(r1=1/2) for i in sols]
or by setting solution_dict=True and fiddling another way:
[sols[i].subs(r1=1/2) for i in [x,y]]
Neither of these seem particularly elegant - is there a more "natural" way?AlasdairThu, 06 Feb 2014 00:04:20 +0100https://ask.sagemath.org/question/10997/