#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 SimonKing):
Replying to [comment:23 kcrisman]:
> What happens with the already existing doctests? That would be what I
would be most concerned about.
There are two tests (really in fact only one) in `sage.stats` where I had
to change the expected output. The old and new output are equivalent:
{{{
sage: std([I, sqrt(2), 3/5]) # result with patch
sqrt(1/450*(-5*sqrt(2) + 10*I - 3)^2 + 1/450*(-5*sqrt(2) - 5*I + 6)^2 +
1/450*(10*sqrt(2) - 5*I - 3)^2)
# Without patch, we had sqrt(1/450*(5*sqrt(2) + 5*I - 6)^2 +
1/450*(5*sqrt(2) - 10*I + 3)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2)
# Testing equality:
sage: bool(sqrt(1/450*(5*sqrt(2) + 5*I - 6)^2 + 1/450*(5*sqrt(2) - 10*I +
3)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2) == std([I, sqrt(2), 3/5]))
True
}}}
There is essentially the same happening with `variance([I, sqrt(2),
3/5])`.
> Also, is the infinite loop now gone? IIRC you had fixed that somehow.
Yep. The problem was that in an old version of my patch I would not try
conversion to `ZZ` but conversion to the prime subfield. A real number
with finitely many digits can of course ''always'' be converted into
`RR.prime_subfield()`, which is `QQ`. So, I guess that the segfault came
from rationals with very large numerator and denominator. Here is the
proof that the segfault has gone:
{{{
sage: F(x) = 1/sqrt(2*pi*1^2)*exp(-1/(2*1^2)*(x-0)^2)
sage: G(x) = 1/sqrt(2*pi*n(1)^2)*exp(-1/(2*n(1)^2)*(x-n(0))^2)
sage: (F-G)**2
x |--> 1/4*(sqrt(2)*e^(-1/2*x^2)/sqrt(pi) -
1.41421356237309*e^(-0.500000000000000*x^2)/sqrt(pi))^2
}}}
which coincides with the answer of unpatched Sage.
> Really, in some sense the new version is 'better' because it keeps the
minus where the user put it. Do `(-I - 1/3*sqrt(2))^2` and `(I +
1/3*sqrt(2))^2` do anything different from before?
They do.
{{{
sage: (-I - 1/3*sqrt(2))^2
1/9*(-sqrt(2) - 3*I)^2
# Was: 1/9*(sqrt(2) + 3*I)^2
sage: (I + 1/3*sqrt(2))^2
1/9*(sqrt(2) + 3*I)^2
# Was: 1/9*(sqrt(2) + 3*I)^2
}}}
Really I don't understand where that comes from. Namely, as far as I know,
the sign of gcd or lcm did not change. The only difference in gcd/lcm
examples involving `I` and `sqrt(2)` is the fact that without my patch an
error would be raised.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10771#comment:24>
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.