#10771: gcd and lcm for fraction fields
--------------------------------+-------------------------------------------
Reporter: SimonKing | Owner: AlexGhitza
Type: defect | Status: needs_review
Priority: major | Milestone: sage-4.7
Component: basic arithmetic | Keywords: gcd lcm fraction fields
Author: Simon King | Upstream: N/A
Reviewer: Marco Streng | Merged:
Work_issues: |
--------------------------------+-------------------------------------------
Comment(by dsm):
I think I've figured out hg queues now, so I can actually try out the
patch! [No guarantees, though.] Was fuzz-testing it and noticed the
following:
{{{
sage: var("x")
x
sage: a = 1/3*x**0
sage: b = 2/5*x**0
sage: type(a)
<type 'sage.symbolic.expression.Expression'>
sage: gcd(a,b)
1/15
sage: lcm(a,b)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/Applications/sage_devel/devel/sage-main/<ipython console> in <module>()
/Applications/sage_devel/local/lib/python2.6/site-
packages/sage/rings/arith.pyc in lcm(a, b)
1562 return ZZ(a).lcm(ZZ(b))
1563 except TypeError:
-> 1564 raise TypeError, "unable to find lcm of %s and
%s"%(a,b)
1565 return LCM(b)
1566
TypeError: unable to find lcm of 1/3 and 2/5
}}}
All bets are off in SR, but there is an Expression.gcd (no .lcm,
strangely). Now that QQ reduces to ZZ, maybe switch the attempt to try ZZ
to QQ, so that rationals Just Work(tm)?
This surprised me a little too:
{{{
sage: R.<x>=QQ[]
sage:
sage: a = 1/3*x**0
sage: b = 2/5*x**0
sage: type(a)
<type
'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint'>
sage: gcd(a,b), lcm(a,b)
(1, 1)
sage:
sage: a = (1*x**0)/(3*x**0)
sage: b = (2*x**0)/(5*x**0)
sage: type(a)
<class
'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'>
sage: gcd(a,b), lcm(a,b)
(1, 1)
}}}
given that the seemingly harder cases
{{{
sage: a = 1/3+x
sage: b = 2/5+x
sage: type(a)
<type
'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint'>
sage: gcd(a,b), lcm(a,b), a*b-gcd(a,b)*lcm(a,b)
(1, x^2 + 11/15*x + 2/15, 0)
sage:
sage: a = (1*x**0)/(3*x**0)+x
sage: b = (2*x**0)/(5*x**0)+x
sage: type(a)
<class
'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'>
sage: gcd(a,b), lcm(a,b), a*b-gcd(a,b)*lcm(a,b)
(1, x^2 + 11/15*x + 2/15, 0)
}}}
behave a little nicer. Is it possible to recover the rational results?
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10771#comment:26>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.