Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-09 Thread fabioromano1
> I have implemented the Zimmermann's square root algorithm, available in works > [here](https://inria.hal.science/inria-00072854/en/) and > [here](https://www.researchgate.net/publication/220532560_A_proof_of_GMP_square_root). > > The algorithm is proved to be asymptotically faster than the New

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-10 Thread Raffaello Giulietti
On Tue, 9 Jul 2024 20:06:40 GMT, fabioromano1 wrote: >> I have implemented the Zimmermann's square root algorithm, available in >> works [here](https://inria.hal.science/inria-00072854/en/) and >> [here](https://www.researchgate.net/publication/220532560_A_proof_of_GMP_square_root). >> >> The

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-10 Thread fabioromano1
On Wed, 10 Jul 2024 12:13:32 GMT, Raffaello Giulietti wrote: > Yes, thanks, I saw it. If some other clarifications are needed, please let me know. - PR Comment: https://git.openjdk.org/jdk/pull/19710#issuecomment-2220362708

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Tue, 9 Jul 2024 20:06:40 GMT, fabioromano1 wrote: >> I have implemented the Zimmermann's square root algorithm, available in >> works [here](https://inria.hal.science/inria-00072854/en/) and >> [here](https://www.researchgate.net/publication/220532560_A_proof_of_GMP_square_root). >> >> The

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:04:42 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Fri, 12 Jul 2024 13:28:14 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/MutableBigInteger.java line 128: >> >>> 126: intLen = 2; >>> 127: value[0] = hi; >>> 128: value[1] = (int) val; >> >> Suggestion: >> >> value = new int

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:06:35 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:06:46 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Fri, 12 Jul 2024 13:43:29 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/MutableBigInteger.java line 1941: >> >>> 1939: >>> 1940: // Initial estimate is the square root of the unsigned >>> long value. >>> 1941: long s = (long) Math.sqrt(x > 0 ? x :

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:07:02 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:49:55 GMT, Raffaello Giulietti wrote: >> The proof has been made simply by exaustive experiment: for every long value >> `s` in [0, 2^32) such that `x == s * s`, it is true that `s == (long) >> Math.sqrt(x >= 0 ? x : x + 0x1p64)`. This can be verified directly by a Java

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:07:39 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:07:51 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:08:29 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 14:16:38 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/MutableBigInteger.java line 2040: >> >>> 2038: sqrt.add(q); >>> 2039: >>> 2040: MutableBigInteger chunk = u; >> >> I don't get the need for `chunk`. It should be possible to use `u` d

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:08:37 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 13:08:59 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added comment on normalization in MutableBigInteger.sqrtRemZimmermann() > > src/java.base/share/classes/java/ma

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Fri, 12 Jul 2024 13:57:55 GMT, fabioromano1 wrote: >> (Yes, I proved it to myself in this way.) >> >> A similar explanation should be in a comment in the code, not here. The >> source of truth is the code, not the comments on GitHub ;-) > > I would keep zero as the only special case, so as n

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Fri, 12 Jul 2024 13:51:24 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/MutableBigInteger.java line 1967: >> >>> 1965: MutableBigInteger[] sqrtRem = x.sqrtRemZimmermann(x.intLen, >>> needRemainder); >>> 1966: >>> 1967: // Unnormalize >> >> This unnormali

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Fri, 12 Jul 2024 14:20:23 GMT, fabioromano1 wrote: >> Ok, but what should the name be? > > Like `u_a0`? It is the most "mathematical" name that comes to my mind. In the paper `u` is called R'', so I'd rename it as `rpp` (for R prime prime). Generally, the more the names in the code match the

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread fabioromano1
On Fri, 12 Jul 2024 14:42:33 GMT, Raffaello Giulietti wrote: >> Like `u_a0`? It is the most "mathematical" name that comes to my mind. > > In the paper `u` is called R'', so I'd rename it as `rpp` (for R prime > prime). Generally, the more the names in the code match the ones in the > paper, t

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Fri, 12 Jul 2024 14:55:19 GMT, fabioromano1 wrote: >> In the paper `u` is called R'', so I'd rename it as `rpp` (for R prime >> prime). Generally, the more the names in the code match the ones in the >> paper, the easier it becomes to read the code with the paper at hand. >> >> Then you can

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-12 Thread Raffaello Giulietti
On Fri, 12 Jul 2024 14:22:33 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/MutableBigInteger.java line 2054: >> >>> 2052: >>> 2053: rem.add(ONE); >>> 2054: rem.subtract(twiceSqrt); >> >> Shouldn't these be `rem + twiceSqrt - 1`? > > No, becau

Re: RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]

2024-07-13 Thread fabioromano1
On Fri, 12 Jul 2024 14:39:51 GMT, Raffaello Giulietti wrote: >> The full explanation for the unnormalization is in the second paper, "A >> proof of GMP square root", par. 3.2 at page 11. > > Well, I have to compare that section, which is clear to me, with the code > again. @rgiulietti I notic