Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong result from LT for rational numbers! #3474

Closed
stevelinton opened this issue May 25, 2019 · 8 comments · Fixed by #3478
Closed

Wrong result from LT for rational numbers! #3474

stevelinton opened this issue May 25, 2019 · 8 comments · Fixed by #3478
Assignees
Labels
kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them topic: kernel
Milestone

Comments

@stevelinton
Copy link
Contributor

Arising from a bug that Leonard Soicher had, we have a reproducible serious bug in rational number arithmetic

Observed behaviour

gap> x := -9303829819079165/4076863488;
-9303829819079165/4076863488
gap> x < x; 
false
gap> y := -9303829819079165/4076863488;
-9303829819079165/4076863488
gap> x < y;
true
gap> x = y;
true
gap> y < x;
true

Expected behaviour

x < y and y < x should return false.

Copy and paste GAP banner (to tell us about your setup)

[sal@MCC02XF17NJGH8 crypting-0.9 (master)]$ gap4
 ┌───────┐   GAP 4.10dev-2057-g8e281e4 of today
 │  GAP  │   https://www.gap-system.org
 └───────┘   Architecture: x86_64-apple-darwin18.5.0-default64-kv6
 Configuration:  gmp 6.1.2, GASMAN
 Loading the library and packages ...
 Packages:   AClib 1.3.1, Alnuth 3.1.0, AtlasRep 1.5.1, AutoDoc 2018.09.20, AutPGrp 1.10, CRISP 1.4.4, Cryst 4.1.18, CrystCat 1.1.8, 
             CTblLib 1.2.2, FactInt 1.6.2, FGA 1.4.0, GAPDoc 1.6.2, IRREDSOL 1.4, LAGUNA 3.9.0, Polenta 1.3.8, Polycyclic 2.14, 
             PrimGrp 3.3.2, RadiRoot 2.8, ResClasses 4.7.1, SmallGrp 1.3, Sophus 1.24, SpinSym 1.5, TomLib 1.2.7, TransGrp 2.0.4, 
             utils 0.59
 Try '??help' for help. See also '?copyright', '?cite' and '?authors'

I'm looking into this now.

@stevelinton stevelinton added kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them topic: kernel labels May 25, 2019
@stevelinton stevelinton self-assigned this May 25, 2019
@stevelinton
Copy link
Contributor Author

Turns out that this is actually an integer problem

gap> q1 := -37930444087969493570027520;
-37930444087969493570027520
gap> q2 := -37930444087969493570027520;
-37930444087969493570027520
gap> q1 < q2;
true
gap> q1+1 < q2+1;
true
gap> q1+1000000 < q2+1000000;
true
gap> 2*q1 < 2*q2; 
true

@stevelinton
Copy link
Contributor Author

Looks like the bug is in src/integer.c:1210

 /* if both arguments are negative, flip the result */
    if (IS_INTNEG(opL))
        res = !res;

This is incorrect when the two values are equal.

@stevelinton
Copy link
Contributor Author

Seems to have been introduced in a refactoring last December.

@stevelinton
Copy link
Contributor Author

I have a fix. Will make PR shortly.

@fingolfin
Copy link
Member

Ouch, that's quite terrible. Glad you caught it.

@olexandr-konovalov
Copy link
Member

olexandr-konovalov commented Jun 2, 2019

This still has to be cherry-picked onto stable-4.10 and is worth making a GAP 4.10.2 release (also, about 40 package updates are waiting). I am reopening this issue to prevent it falling below the radar.

@wilfwilson
Copy link
Member

@alex-konovalov The fix for this (PR #3478) has been backported to stable-4.10 now. Is there any reason you still want to keep this open?

@olexandr-konovalov
Copy link
Member

The fix backported to stable-4.10 in commit 3ad3a2b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them topic: kernel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants