Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  calculating an inverse multiplicative modulus in java...  (Read 448 times)
0 Members and 1 Guest are viewing this topic.
Offline lcass
« Posted 2014-08-21 23:14:07 »

Yer I have the kind of feeling this is going to go well or be very painful.
So I cant find any detailed example that explains this well , if someone would be able to just show me how it works with an example of code that calculates for example d = inverse multiplicate modulus of x(mod d)
Online Roquen
« Reply #1 - Posted 2014-08-22 07:56:42 »

What's with matrix inversion questions...what do you really want to do?  What's the field of the matrix elements?
Offline pjt33
« Reply #2 - Posted 2014-08-22 09:25:24 »

@Roquen, this isn't about matrices.

@lcass, are you guaranteed that d is a prime? If not, the inverse may not exist. If it does exist, it can be found efficiently with the extended Euclidean algorithm. That page has a section on multiplicative inverses.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lcass
« Reply #3 - Posted 2014-08-22 09:28:18 »

Modulus inversion , not matrix inversion , So for instance if I have something of the form ax = 1 (mod(n)) how do I solve for x (in an algorithm) I know you turn it to the form of a fraction by performing a^-1 = x (mod(n)) then you find a value of x that works , however running through every value of x (for values in the long size) is difficult.
Offline lcass
« Reply #4 - Posted 2014-08-22 09:28:55 »

@Roquen, this isn't about matrices.

@lcass, are you guaranteed that d is a prime? If not, the inverse may not exist. If it does exist, it can be found efficiently with the extended Euclidean algorithm. That page has a section on multiplicative inverses.
Thanks for that info , yes I have made a prime number generator.
Online Roquen
« Reply #5 - Posted 2014-08-22 09:47:44 »

Bad me. There's a modulo inverse for all odd integers.  This is newton's method instead:  https://github.com/roquendm/JGO-Grabbag/blob/master/src/roquen/math/Int32.java
Online Roquen
« Reply #6 - Posted 2014-08-22 09:51:09 »

I think I need to go have a drink or something.  Trouble with reading comprehension. 
Offline pjt33
« Reply #7 - Posted 2014-08-22 11:07:46 »

Bad me. There's a modulo inverse for all odd integers.
No, there's a modulo inverse for all numbers which are coprime with the modulus. Hence the link with Euclid's algorithm for finding gcd. (I'm not sure whether you realised this and that's why the bit about needing a drink, but even if you have it might be helpful for other people reading the thread).

I think your linked code is calculating inverses modulo 2^32 for odd integers, but the Javadoc isn't clear enough for me.

Thanks for that info , yes I have made a prime number generator.
I should add that in general you can use Euler's theorem, and for primes that's Fermat's little theorem: a^(p-1) == 1 (mod p) provided that a is not a multiple of p. So if you already have a modular exponentiation function and you don't have an extended Euclid function, that's an alternative approach. I think they should have the same asymptotic complexity.
Online Roquen
« Reply #8 - Posted 2014-08-22 11:39:19 »

Indeed it's mod 2^32.  I should update the docs.
Offline lcass
« Reply #9 - Posted 2014-08-22 11:45:49 »

I use a nifty little function for generating long primenumbers , I am still finding it really difficult to understand how inverse modulus works so if I plonk this down would someone be able to give an explanation of it?
So say i need to calculate D , D = inverse multiplicate modulus of e % n; or d = e^-1 %n;
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (137 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!