Bill Allombert on Sun, 10 Sep 2023 15:08:19 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Manually transpile Python code to GP: what about class / __name__ ?
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: Manually transpile Python code to GP: what about class / __name__ ?
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Sun, 10 Sep 2023 15:03:10 +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=1694350984; c=relaxed/relaxed; bh=KAHVT5YML3JjbH6o6Y9Fd2KLHQgzjiD80i/GruPjc54=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=hxKJSMG4c3R5xm5IoRuX8Gp4YkU+2BWzyaaNprtg9IPcEUpmjtyfvQmKCCh+AKfeQ2QINs6HDds7V+0IpMgicWS3oZClFZUB+gndMUqm4BtOjSXxIClecp/SoneKYooIS+jCJp9PTLHtfrznlWJK53Akf5bjFx37I+B4oPuVOLenWbA9KYHWYjIst6qKYM7/fWHx/h/CpFplm/Ryyf9NyMXKqDPNzng57rCQvwYBcl0mBmeu1slHP7giTurZikKahcq1QOSa3NoEgZkZ7JAn2USjOPBRVfEFUt6dqsvI4xwbzuBM/VjnA+mDZi1vHRl4WBCPpYzbR9rtGoZc3AUcHXu8Cv/FjSYdumKT09zT7p+auXH4aZNCoiDUPkv+vCpEiHjc6X4yxoZeHZPDUiltSYn35cYKi/FlzBaoZDPcJO+x0U6HfYjit5w2aIsGvhrIrQ1vfthtkGjb7fkI1uQHTot2w2Iji3o6khET9RqAK5rxB9bKbLvHSU18YWsQ5wsl00iyI4AqHp3/z7UqKaxTW1VqxMgPnrDNLHZNcahic/jOsCEBo2i+WQPpC5ydYD4qOglMfWdjrkF8tGO5y8TRqsqOg4fOF4t429MngkQXJ6asMjtt7BWFfpPlOTkYU9gRL23xjHEyh40i7KWaxQW8/ojJ30GALLSy2FrAu56GAsw=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1694350984; cv=none; b=Z+EPtkCTP4bKvZoOZdlm6YPU7X7r12zzyxTtSE+GEXW/pZwaJBB7D5SY1JkNwhXuhkVKb7oYVU8rC0doV3JTiyHVxDIdET/hwwRYnl+q14C1DYcgvwyJLWemlqyh1cJ7+Q88lSJtz5KnPWLMb/FBF1oui07LXmNv1AVHMYa1bR9cs3HstsHdsxn2JU4QS+1JaDim2QR5ZseCppmjCp3Bm9ahgvplBgYTltEW+/KMqyNM5o35eWJCJCFikQTdtEKyNCPIGmnPZcMJ8qkVOJLfiUiu0F1xipX3Uc1Vfr7zmaKsyE7x8XIpVtcgOVGh5QyVHdseqfUVAHbT7VkCUSh1yX8rTgNEQq/T/KdXDo9QoV8rOrlPJT79RmIRPvMUMNg+D63vQFyEhC8K+T//PSCf7wUYdx7c/zcdJjc+xZdryMzXF4JqPOqroVmX1637pZzmImwRaGlPYorfpCGIeIoGse8ANbHmIzCXn2/lItNBuMbFZpLRN/UjjNKKNwoHVsJjLY9eVGZLAjQHAQoYC6yN0p+PofyFIgFaOXZRCxuR9M9r3ouWbhKtTtJiFCQ2hpxoIx+yxuwxEYQ8LHzD+EOWmHu8KYGWZJYPybYXTx4dBklG/itJyxa9xlZx7x0Sm09ej4U3kXSLfvAs62B8CmQxrKc3+ZDunm+z2YcOBpcVxtg=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Delivery-date: Sun, 10 Sep 2023 15:08:19 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1694350984; bh=KAHVT5YML3JjbH6o6Y9Fd2KLHQgzjiD80i/GruPjc54=; h=Date:From:To:Subject:References:In-Reply-To:From; b=FBXzNCkaYwEg+qD3ts+OitRgtOyYxUynNZJzv5Qq+WDLCWGBAsGKZVAIuAZc8fk8O UBXhhfbNukEl4kL7BtUa00F33Wng7d/7YNDY5nH0KwxWRacsG9nCf3DDxtU9Xb3ZG3 kv8GMmcAQxN19TMD6nsdpIrolwBWtOkRgaqrtzO/qUPrsxPTQg8zw1yamh1jLbg+UQ 45HAt4sGlMUQT2/tLNIWkVVkMzLi82twyjOzAkIp1a6PcKO2mLW24c4nMfolWrITqn Wcpz02HOkh7IcLNpqwyIX2pOaOYjZAFjkJDGEppT5qzpsq0dQuFsVpreS/sziynvAh cCpd6IlQipAopVY4fWiX3QpR0a5SrjFXKm/f4O/RoW10Uvr4AxUns2EEV9+W+ckciE IK6f8Zb9FQT7b58iJAei0LCBVeemsRjgon+4RD6BRWizF/k6B9328uoS4H3ZqTVM9h bl+BYe49oxcNA2l2U6C/O4ZGSWSA+882177Uvw/1xBa1Kg3bslfwVS9Or9DI71Q1CL tUwwAyS0YinxYGgIDS10kpLydaMOZS2sPZUWztJdH+Fe1EyXVI51zwB8+dZGUzTrS2 jPPDwKmukDgKwjvt6oQrm6I4ogIDKpBxmdiCmlsqcTKUpSdax3o5o+2iSv3MVgyoep Ac6kE9qKh1mUF7qRolcqMVyw=
- In-reply-to: <ed43398d523c725eaa392053af97e256@stamm-wilbrandt.de>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <ec226c878c74a0444c9f63a4353b8eae@stamm-wilbrandt.de> <ZPy8uXRFpfpMao8k@seventeen> <ed43398d523c725eaa392053af97e256@stamm-wilbrandt.de>
On Sun, Sep 10, 2023 at 10:40:18AM +0200, hermann@stamm-wilbrandt.de wrote:
> Perhaps a bit of motivation first.
> RSA_numbers_repo is available in Python, nodejs/JavaScript and PARI/GP.
>
> On 2023-09-09 20:43, Bill Allombert wrote:
> > > What remains is transpilation of Python class RSA.
> > > Is there a "class" concept in GP?
> >
> > No, GP is not object-oriented at all. It has some minimal
> > functional-programming features
> > (anonymous functions and closure).
> >
> Thanks, what I need is that it "looks similar" to Python class code.
> In order to port easily code from one language to the other.
>
> > > It seems so, as "." is not a normal name character:
> >
> > You know, there is a GP manual you could read...
> >
> I did of course, but searched for "class" and found many hits, but not on GP
> class.
Because there are no classes in GP in the object-oriented programmning/Python sense.
> Thanks, I found "2.8 Member functions":
> https://pari.math.u-bordeaux.fr/pub/pari/manuals/2.15.4/users.pdf#page=48
>
> The preceding chapters on functions and closures helped as well.
>
> I am happy with RSA member function "square_sums_4()".
> Function comment "Example" section shows how to use.
> In case mailing software scambles display, here is function on github:
> https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/pari/RSA_numbers_factored.gp#L1525-L1552
>
> RSA.square_sums_4=x->{
> }
The whole problem is that this does not allow to change RSA.
? RSA.set=x->RSA[1]=x
%1 = (RSA)->x->RSA[1]=x
? RSA=[0,0];
? RSA.set(2)
%3 = 2
? RSA
%4 = [0,0]
> I have few questions I was not able to resolve by reading GP manual and
> experiment:
>
> 1)
> Is it possible to define a member function without parameter?
you can do this
RSA.factored_2=()->{
...
}
> 2)
> I was not able to get the syntax right for a parameter with default value.
> I used below workaround.
> Is is possible to define default value for GP member function parameter
> directly?
>
> factored(mod4=-1)=
> {
> \\ ...
> return([r[1..4]|r<-rsa,has_factors(r,mod4)]);
> }
> RSA.factored=factored;
RSA.factored = (mod4=-1)->{
}
>
>
> 3)
> I did not need sofar, but is it possible to pass multiple parameter"s to GP
> member function?
> (this likely does not make sense for what GP member functions have been
> implemented)
You can do
RSA.fun=(x,y)->{...
}
If this is what you have in mind.
Cheers,
Bill