edgarcosta / endomorphisms

Rigorous computation of the endomorphism ring of a Jacobian
GNU General Public License v2.0
10 stars 8 forks source link

Only compare significant bits #54

Closed edgarcosta closed 2 years ago

edgarcosta commented 2 years ago

This resolves #52, as it boils down to

> CC<I> := ComplexFieldExtra(210);
> r := -8744296296.29629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629629606p210 + 4.63904903109310867053319761531198167208579141366616950416795464078482675799537244792296275814235137316532497932260242969902884145561411596409311814036853462453181613672980721511881820655940576392237105805190800E-200p210*I;
> test, b := RationalReconstruction(r);
> test, b;
false -236096000000/27

as

>  ComplexField(10)!Abs(r - b)
2.396878152E-199

but the right way to compare if two nonzero floating points are close to each other is not by absolute difference, but by their relative differences

> ComplexField(10)!Abs(r - b)/Abs(b)
2.741076092E-209

, and voila, with the PR we get

> RationalReconstruction(r);
true  -236096000000/27
edgarcosta commented 2 years ago

@JRSijsling, @assaferan: I'm happy with the code. But uncertain about the name AlmostEqual. Please let me know what you think. ps: There are certainly more places where we could use AlmostEqual, but I just did the obvious things.

JRSijsling commented 2 years ago

Yes, this makes complete sense and I will look for more places where this can be used. It will certainly help at multiple stages, also when calculating endomorphism rings at low precision.

assaferan commented 2 years ago

Makes sense to me. I think that's pretty much the usual meaning of AlmostEqual.