Does this help any?

sage: R = PolynomialRing(QQ, 2, 'x1,x2', order='lp')
sage: x1,x2 = R.gens()
sage: f1 = 1/2*((x1^2 + 2*x1 - 4)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2)
sage: f2 = 1/2*((x1^2 + 2*x1 + 1)*x2^2 + 2*(x1^2 + x1)*x2 - 4*x1^2)
sage: I = (f1,f2)*R; I
Ideal (1/2*x1^2*x2^2 + x1^2*x2 + 1/2*x1^2 + x1*x2^2 + x1*x2 - 2*x2^2,
1/2*x1^2*x2^2 + x1^2*x2 - 2*x1^2 + x1*x2^2+ x1*x2 + 1/2*x2^2) of
Multivariate Polynomial Ring in x1, x2 over Rational Field
sage: B = I.groebner_basis(); B
[x1^2 - x2^2, x1*x2 - 1/8*x2^6 - 3/8*x2^5 + 9/8*x2^4 + 15/8*x2^3 -
3/2*x2^2, x2^7 + 4*x2^6 - 6*x2^5 - 20*x2^4 + 5*x2^3]

Read http://www.sagemath.org/doc/constructions/polynomials.html#gr-bner-bases
for more examples.


On Wed, Jul 15, 2009 at 11:19 PM, Doug<mcke...@gmail.com> wrote:
>
> I'm sorry for the deluge of questions, but I hope you will bear with
> me as I come up to speed.  This one is more substantive and I think
> related to my first question yesterday about simplify() not
> simplifying enough.  Now, I have two equations with two unknowns I'm
> trying to solve and I'm getting 3 solutions.  Two are correct, but the
> third yields a division by zero error if I try to plug it back into
> the equations.  And the real problem is that the solution I care about
> is missing!  These particular two equations are symmetric, so I could
> (and have) solved it by subsituting x1 for x2 and solving just one
> equation with one unknown.  That works and that's how I know the
> missing solution.  But I want to solve slightly different sets of
> equations that are _not_ symmetric and the fact that sage/Maxima fails
> me here makes me pessimistic that my results for the asymmetric
> versions are correct.
>
> Here's my code:
>
> var('x1, x2')
>
> eqn1 = (1/2*((x1^2 + 2*x1 - 4)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2)
>              / ((x1^2 + 2*x1 + 1)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2) ==
> 0)
> eqn2 = (1/2*((x1^2 + 2*x1 + 1)*x2^2 + 2*(x1^2 + x1)*x2 - 4*x1^2)
>              / ((x1^2 + 2*x1 + 1)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2) ==
> 0)
>
> print "eqn1: ", eqn1
> print "eqn2: ", eqn1
>
> sols = solve([eqn1, eqn2], x1, x2, solution_dict=True)
>
> print "number of sols: ", len(sols)
> print "sols: ", sols
>
> foo = eqn1.lhs().subs(x1=sqrt(5) - 2, x2=sqrt(5) - 2)
> print "What about sqrt(5)-2 in eqn1?", foo
> bar = eqn2.lhs().subs(x1=sqrt(5) - 2, x2=sqrt(5) - 2)
> print "What about sqrt(5)-2 in eqn2?", bar
>
> print "But these both simplify to zero after a simplify_full: ",
> foo.simplify_full()
> print "But these both simplify to zero after a simplify_full: ",
> bar.simplify_full()
>
> print "The third solution I do get yields a divide by zero error, but
> I'm willing to forgive this:"
> eqn1.lhs().subs(sols[2])
>
> *** And here's what I get when I run it: ***
>
> sage: load problem.sage
> eqn1:  1/2*((x1^2 + 2*x1 - 4)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2)/((x1^2 +
> 2*x1 + 1)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2) == 0
> eqn2:  1/2*((x1^2 + 2*x1 - 4)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2)/((x1^2 +
> 2*x1 + 1)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2) == 0
> number of sols:  3
> sols:  [{x2: -sqrt(5), x1: -(sqrt(5) - 10)/(2*sqrt(5) - 1)}, {x2: sqrt
> (5), x1: -(sqrt(5) + 10)/(2*sqrt(5) + 1)}, {x2: 0, x1: 0}]
> What about sqrt(5)-2 in eqn1? 1/2*((sqrt(5) - 2)^2*((sqrt(5) - 2)^2 +
> 2*sqrt(5) - 8) + (sqrt(5) - 2)^2 + 2*(sqrt(5) - 2)*((sqrt(5) - 2)^2 +
> sqrt(5) - 2))/((sqrt(5) - 2)^2*((sqrt(5) - 2)^2 + 2*sqrt(5) - 3) +
> (sqrt(5) - 2)^2 + 2*(sqrt(5) - 2)*((sqrt(5) - 2)^2 + sqrt(5) - 2))
> What about sqrt(5)-2 in eqn2? 1/2*((sqrt(5) - 2)^2*((sqrt(5) - 2)^2 +
> 2*sqrt(5) - 3) - 4*(sqrt(5) - 2)^2 + 2*(sqrt(5) - 2)*((sqrt(5) - 2)^2
> + sqrt(5) - 2))/((sqrt(5) - 2)^2*((sqrt(5) - 2)^2 + 2*sqrt(5) - 3) +
> (sqrt(5) - 2)^2 + 2*(sqrt(5) - 2)*((sqrt(5) - 2)^2 + sqrt(5) - 2))
> But these both simplify to zero after a simplify_full:  0
> But these both simplify to zero after a simplify_full:  0
> The third solution I do get yields a divide by zero error, but I'm
> willing to forgive this:
> ---------------------------------------------------------------------------
> RuntimeError                              Traceback (most recent call
> last)
> ...
> RuntimeError: power::eval(): division by zero
>
> As usual, any help would be greatly appreciated!
>
> Thank you,
>
> Doug
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to