Bill Allombert on Thu, 08 Jun 2023 23:55:27 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Pari/GP "halfgcd()" implementation
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: Pari/GP "halfgcd()" implementation
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Thu, 8 Jun 2023 23:50:45 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1686261036; c=relaxed/relaxed; bh=R+cTy5h/kI7ft6iZyWrNIr8gK0DeZuc8rvAwL3kfwAc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=xCPKBTDDQmbV6nO8jK3UTo90ffslA/idm0CmQGtaOeh7kQ5A5f/FW6VTjIl7sMWCp7FNp7wo6idywV91mGxtM3CV/sb6t0m7lK/w/YsvrEk2hXmRofFnQ3yhjY3LI8FAOj8H0cnvzf6wBlOnsfXx2b7NeGT2B96OM79jxsmvaGuKdbBQkKDQoBNVlpPMW7uSodGnA5gB/QXEviiQR1ERyVc6Ue+MZ1gp4mgQbU6TXAo+iwuzjFioa43UDhYMQyEU5mK6azNhJJsC+Ddx8/Oc3djGkZ6UJqHNXuffff6fjzVi4IJ1i77Cc7GyzOfHzyvHAmFR1Sz0jCT1B0+mt/Bp10SlcShgE9k4fMRiGt5IBFvlXVL0vuWu2nCcOtjsVcvwS3jhJLSpxvvhGMqLOoeRgOqPlB2sLIoWLacFWmZRDV5DI4nbLfCGMuhILg9ePXfYOM1ntTLfvgIQ2SRcjm5qKGZz8TSiytGhR9MtM6B6yCOXYVd7Fy2yUfIVew5XUlzkZZvVJPaQsONqV1cUs7e8GAMoWzkO5i9K+GB0G93iW5bELl+Hyl2HQST+YLWgTPpLtJ9xZVarnmdbWLJZXLIbZcGs9KtF54qtpIw9wIdA+f/6jvif51BV3iJOmfaAslz4D978KLBP110KrFuDvajcwO0jhFeiZiqbB6BcwdVWfpY=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1686261036; cv=none; b=0Ethlw8zUajsNVub59HU8JwTjFGHiggfWOUyd1yPX9iXYNcVgviQWtjHWz34A9w22djKtKEhxCIzW7087KyelkOx4s+6v4bXRFQIMaFTMp3hhmMb2KO9jW30mKIwXzVdEsatgoliElEB9VlLdbALop7eYgPV5hIQukpIMb0DQZ/EXFq1KBdUEDe5WmHohsUJjPjy7hTPmK0edqjK5AoRcrVKk7AWqxHKAMeYxvyBByo6qG+5PGIBX0S6Uim1eUmxigolKTNkxZPgJrZtsE+XkwnG17WYngDsSV0HELOqjPlBt1DNAyWWy1qm8EquR5eMLzl2Xil5/CgNeBR+4/ac30tr1FU1b0kzLrLKN/oYbfV2eupE+r/sb1+3/2UqK8uk6r112NZODb1suJecI+NgyYT3pJztHFYKugtW+YnSam6gtgXHma+7Cqevc1Gx+I+U27NbWkXzwRf3JuLwzgkTBORbB/g4UgpBRi5xiwp4MBJljE/rDbLwYXhvW7cnXTzSCQIpJSZLPS531+x9b9OGh9UGrOVefDKWCS5EGdTdLpLq0BKi0gN26tEnC7V2oPqpdIQupFR9vx3MC56wkPl6Hz5wyO5Eav7SAB95R1UZCvoCALvjWv6KLr05hfaZDQ3Km/AnNd3u/nLhQMeFN3u91Rip/UJ/bFImk320RRcUDJU=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Delivery-date: Thu, 08 Jun 2023 23:55:27 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1686261036; bh=R+cTy5h/kI7ft6iZyWrNIr8gK0DeZuc8rvAwL3kfwAc=; h=Date:From:To:Subject:References:In-Reply-To:From; b=I9oOGBwmtZqgU3bZ3hMnHYRP/fctTVyLr9o5cBy2tDeCPnucApphJJbPEzzKPyrkN J9LhPftljTmCePx0EWnd1gFV7egI0vXtVStFss0pxRkHAAWP8P+1Z0aE2OgHzvFcBT 4M6lpg/pOW7UCcKcuveEYOR1ZlPDkwIftUXI+Kj1t8WKdKMTr0W34JBjUvFgCL2C7w /GWdAbSEpCz9CJYLrSadLVLeQSy0ukEh+2vlSTG0wKPPxatps0FVRxaqqD+9SguqkV AnOWDIJ+XyEJgg27h+NjZQkcbTOE5QQiRAv7nuJkTxAzNZxAsPqcPVjI2xLjv+BUbS /QqfuRC+JLjCPNytVe9UdouTH2qmFG2gnk+gtZTkJIP1bSOVNcgkB64QsW2awKpCR2 cN5atiscpkmYCcvbwZDwJCD2JAd5tvN3ZY1b3f5y796DOE+wmUwwAyyYamH21qcZtF 9nwxre4B44Xw5+/qO9wNDM71JOi7R1gcvj8NSieAk1bxBHEKqRXhsKud3haU2wme58 QBSCAxll6p9h/oK2sSrGTyqdfFwBOJRYfXSdhvj/KftvpPXSVaEfZhkKK7OIX75puD W94iJy9Ku/jWdooS1TsUuhyLrOKbiUH224LfKRpYWeypXsevJ07RRQ0ou44glX1zLq NK1+BPQOWyFRgFUrE1xeT9dw=
- In-reply-to: <314e5e4d76d8c6f35ab851401ad9869b@stamm-wilbrandt.de>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <314e5e4d76d8c6f35ab851401ad9869b@stamm-wilbrandt.de>
On Thu, Jun 08, 2023 at 10:56:19PM +0200, hermann@stamm-wilbrandt.de wrote:
> I really like Pari/GP "halfgcd()" function:
> https://pari.math.u-bordeaux.fr/pub/pari/manuals/2.15.1/users.pdf#page=204
>
> It allows very fast computation even on 388342-digit prime:
> Allows to determine sqrt(-1) (mod p) given sum of squares p = x^2 + y^2
> (in 123ms on i7-11850H):
> https://forums.raspberrypi.com/viewtopic.php?p=2112166#p2112166
>
> I wanted to see whether it is possible to make "halfgcd()" available for
> Python.
> Just did analyze "halfgcdii()" implementation in master branch
> "pari/Olinux-aarch64/mpker.c".
> The huge C callgraph made me step away from that plan, I will simply use
> Pari/GP instead.
Well, if you want a slow halfgcd, it is not harder than extended GCD:
myhalfgcd(a,b)=
{
my(M=matid(2));
my(n = max(a,b));
while (b^2>=n,
my([q,r]=divrem(a,b));
[a,b] = [b,r];
M = [0,1;1,-q]*M;
);
[M,[a,b]~];
}
(the matrix product can be inlined.)
halfgcdii implements both the Lehmer-Jebelean acceleration and the
subquadratic algorithm (following Thull-Yap).
Cheers,
Bill