#7276: Fix PPC issues in totallyreal_rel.py
-----------------------------+----------------------------------------------
Reporter: kcrisman | Owner: davidloeffler
Type: defect | Status: new
Priority: major | Milestone: sage-4.2.1
Component: number fields | Keywords: PPC, powerpc, lattice
Work_issues: | Author:
Reviewer: | Merged:
-----------------------------+----------------------------------------------
Changes (by kcrisman):
* cc: georgSWeber (removed)
* cc: GeorgSWeber, was (added)
Comment:
Here is the code for integral_elements_in_box line by line, up to the
first place where PPC differs from Intel:
{{{
sage: K.<alpha> = NumberField(x^2-2)
sage: d = K.degree()
sage: Z_F = K.maximal_order()
sage: Foo = K.real_embeddings()
sage: B = K.reduced_basis()
sage: import numpy
sage: import numpy.linalg
sage: L = numpy.array([ [v(b) for b in B] for v in Foo])
sage: Linv = numpy.linalg.inv(L)
sage: C = [[0,5],[0,5]]
sage: Vi = [[C[0][0]],[C[0][1]]]
sage:
sage: Linv
array([[ 0.5 , 0.5 ],
[-0.35355339, 0.35355339]])
sage: for i in range(1,d):
....: Vi = sum([ [v + [C[i][0]], v + [C[i][1]]] for v in Vi], [])
....:
sage: Vi
[[0, 0], [0, 5], [5, 0], [5, 5]]
sage: V = numpy.matrix(Linv)*(numpy.matrix(Vi).transpose())
sage: V
matrix([[ 0.00000000e+00, 2.50000000e+00, 2.50000000e+00,
5.00000000e+00],
[ 0.00000000e+00, 1.76776695e+00, -1.76776695e+00,
5.55111512e-17]])
}}}
In particular, the matrices Linv and Vi, even in their numpy versions, are
still the same. Essentially, on PPC (at least G4) the computation
-0.35355339*5+0.35355339*5 is not (quite) zero, but on Intel it is. On
Intel we get the same stuff but with just 0., 2.5, etc - and the last
entry is 0., no hint of the 5.55e-17.
Anyway, this leads to the following error (since we are depending on the
ceil of zero to be zero, but the ceil of 5.55e-17 is 1):
{{{
sage: while j < 2**d:
for i in range(d):
if V[i,j] < V[i,j+1]:
V[i,j] = math.floor(V[i,j])
V[i,j+1] = math.ceil(V[i,j+1])
else:
V[i,j] = math.ceil(V[i,j])
V[i,j+1] = math.floor(V[i,j+1])
j +=2
....:
sage: V
matrix([[ 0., 3., 2., 5.],
[ 0., 2., -2., 1.]])
}}}
Where Intel correctly gives 0. in the last entry.
Just so that it's clear that PPC is the issue:
{{{
sage: matrix(Linv)*matrix(Vi).transpose()
[ 0.0 2.5 2.5 5.0]
[ 0.0 1.76776695297 -1.76776695297 5.55111512313e-17]
}}}
Slightly more digits, but same problem. I can in fact do the computation
completely in Sage (which I assume doesn't call numpy for matrix
multiplication?) and get the same. Note however that Sage CAN multiply
correctly, as can Numpy:
{{{
sage: -0.35355339*5+0.35355339*5
0.000000000000000
sage:
numpy.int(5)*numpy.float(-0.35355339)+numpy.int(5)*numpy.float(0.35355339)
0.0
}}}
So somehow it has to do with our matrix multiplication algorithm and how
it works on PPC. Perhaps there are other nasty bugs lurking as yet
unseen. Any thoughts?
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7276#comment:1>
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
-~----------~----~----~----~------~----~------~--~---