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

Compute modular inverses of integers faster #2053

Merged
merged 4 commits into from
Jan 9, 2018

Conversation

fingolfin
Copy link
Member

This PR is against master. Of course if people feel it would be useful for 4.9 or 4.9.1, could also retarget it against stable-4.9

Before (on a 64 bit machine):

gap> q:=1/3;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
258
gap> q:=1/3;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
295
gap> q:=1/3;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
569
gap> q:=1/3^60;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
537
gap> q:=1/3^60;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
2364
gap> q:=1/3^60;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
2821
gap> q:=1/2^6000;;n:=3^6000;; for i in [1..6000] do x:= (q mod n); od; time;
19358

After:

gap> q:=1/3;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
255
gap> q:=1/3;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
244
gap> q:=1/3;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
392
gap> q:=1/3^60;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
245
gap> q:=1/3^60;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
1219
gap> q:=1/3^60;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
1292
gap> q:=1/2^6000;;n:=3^6000;; for i in [1..6000] do x:= (q mod n); od; time;
692

@fingolfin fingolfin added topic: kernel topic: performance bugs or enhancements related to performance (improvements or regressions) kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements labels Dec 28, 2017
@fingolfin fingolfin added this to the GAP 4.10.0 milestone Jan 3, 2018
@fingolfin fingolfin force-pushed the mh/integer branch 2 times, most recently from 3fc7feb to 46cd6d0 Compare January 4, 2018 11:24
@codecov
Copy link

codecov bot commented Jan 4, 2018

Codecov Report

Merging #2053 into master will decrease coverage by <.01%.
The diff coverage is 89.47%.

@@            Coverage Diff             @@
##           master    #2053      +/-   ##
==========================================
- Coverage   67.03%   67.03%   -0.01%     
==========================================
  Files         899      899              
  Lines      273551   273554       +3     
==========================================
- Hits       183380   183370      -10     
- Misses      90171    90184      +13
Impacted Files Coverage Δ
src/integer.h 96.42% <ø> (ø) ⬆️
src/dteval.c 2.8% <0%> (ø) ⬆️
src/objcftl.c 17.81% <0%> (ø) ⬆️
src/integer.c 90.47% <100%> (+0.15%) ⬆️
src/rational.c 96.83% <100%> (+0.99%) ⬆️
src/permutat.c 79.89% <100%> (ø) ⬆️
extern/gmp/mpn/generic/gcdext_lehmer.c 74.35% <0%> (-11.12%) ⬇️
extern/gmp/mpn/generic/gcdext_1.c 91.3% <0%> (-8.7%) ⬇️
lib/queue.g 66.4% <0%> (-3.2%) ⬇️
hpcgap/lib/hpc/stdtasks.g 38.87% <0%> (+0.25%) ⬆️

@fingolfin fingolfin force-pushed the mh/integer branch 2 times, most recently from 2d44975 to 72926c4 Compare January 7, 2018 19:57
Before (on a 64 bit machine):

gap> q:=3;;n:=7;; for i in [1..2000000] do INVMODINT(q,n); od; time;
360
gap> q:=3;;n:=2^59;; for i in [1..2000000] do INVMODINT(q,n); od; time;
350
gap> q:=3;;n:=2^60;; for i in [1..2000000] do INVMODINT(q,n); od; time;
373
gap> q:=3^60;;n:=7;; for i in [1..2000000] do INVMODINT(q,n); od; time;
380
gap> q:=3^60;;n:=2^59;; for i in [1..2000000] do INVMODINT(q,n); od; time;
1234
gap> q:=3^60;;n:=2^60;; for i in [1..2000000] do INVMODINT(q,n); od; time;
1256
gap> q:=2^6000;;n:=3^6000;; for i in [1..6000] do INVMODINT(q,n); od; time;
637

After:

gap> q:=3;;n:=7;; for i in [1..2000000] do INVMODINT(q,n); od; time;
222
gap> q:=3;;n:=2^59;; for i in [1..2000000] do INVMODINT(q,n); od; time;
219
gap> q:=3;;n:=2^60;; for i in [1..2000000] do INVMODINT(q,n); od; time;
350
gap> q:=3^60;;n:=7;; for i in [1..2000000] do INVMODINT(q,n); od; time;
205
gap> q:=3^60;;n:=2^59;; for i in [1..2000000] do INVMODINT(q,n); od; time;
1193
gap> q:=3^60;;n:=2^60;; for i in [1..2000000] do INVMODINT(q,n); od; time;
1257
gap> q:=2^6000;;n:=3^6000;; for i in [1..6000] do INVMODINT(q,n); od; time;
653
Before (on a 64 bit machine):

gap> q:=1/3;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
258
gap> q:=1/3;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
295
gap> q:=1/3;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
569
gap> q:=1/3^60;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
537
gap> q:=1/3^60;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
2364
gap> q:=1/3^60;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
2821
gap> q:=1/2^6000;;n:=3^6000;; for i in [1..6000] do x:= q mod n; od; time;
19358

After:

gap> q:=1/3;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
255
gap> q:=1/3;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
244
gap> q:=1/3;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
392
gap> q:=1/3^60;;n:=7;; for i in [1..2000000] do x:= q mod n; od; time;
245
gap> q:=1/3^60;;n:=2^59;; for i in [1..2000000] do x:= q mod n; od; time;
1219
gap> q:=1/3^60;;n:=2^60;; for i in [1..2000000] do x:= q mod n; od; time;
1292
gap> q:=1/2^6000;;n:=3^6000;; for i in [1..6000] do x:= q mod n; od; time;
692
@fingolfin fingolfin merged commit 026be2b into gap-system:master Jan 9, 2018
@fingolfin fingolfin deleted the mh/integer branch January 9, 2018 14:35
@olexandr-konovalov olexandr-konovalov changed the title Compute modular inverses of integer faster Compute modular inverses of integers faster Jan 29, 2018
@olexandr-konovalov olexandr-konovalov added the release notes: added PRs introducing changes that have since been mentioned in the release notes label Jan 29, 2018
@olexandr-konovalov
Copy link
Member

olexandr-konovalov commented Jan 29, 2018

Added to release notes for GAP 4.10 at https://github.com/gap-system/gap/wiki/GAP-4.10-release-notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: added PRs introducing changes that have since been mentioned in the release notes topic: kernel topic: performance bugs or enhancements related to performance (improvements or regressions)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants