Gottfried Helms on Fri, 18 Nov 2022 00:18:49 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Conversion of a function/closure with rational coefficients into one with real coefficients |
Am 17.11.2022 um 20:02 schrieb Bill Allombert: > Well, if you define > p[4] = 1/4*x^2-2/3*x+1/6 > then you can define > my(f=p[4]);(pp[4]=x->eval(f)); > my(f=p[4]*1.);(pr[4]=x->eval(f)); > > or > if you really want to use pp[4](x) = 1/4*x^2-2/3*x+1/6, > then you can do > > my(f=pp[4](x)*1.);ppr[4]=x->eval(f); > Bill - many thanks for your help. Unfortunately I couldn't get your ideas working as I have it intended. After rethinking (and consultation of the user.pdf) I understand now, that my intention would best be described by the (impossible) construction {for(k=1,4, component(ppr[4](x))[k] = 1.0*component(pp[4](x)[k]; );} this means, the creation or alteration of the components of the closure programmatically. But this idea belongs to the old 70'ies programming in PL/I where you have pointers and I would have found how to access the internal constants of a function/closure... But this is impossible (and likely not wanted: protected memory and so on) here in Pari/GP. What I do at the moment is to use the 'eval(Str("..."))'- construct to define the function-array, where I already have the polynomials with rational coefficients in array of closures 'pp[1..128]' so {default(realprecision,60); default(format,"g0.60");\\ or something I want ppr=vectorv(128); for(r=1,128, st=Str("ppr[",r,"]=x->",1.0*pp[r](x)); eval(st); ); default(format,"g0.12"); default(realprecision,200); \\ resetting to my standard } With this I can give it another try; my implementation with the rational 'pp[r](x)' polynomials needed in a certain loop with call on various 'x' 20 sec, while a concurring implementation from someone else using real valued (50 dec digits) coefficients/polynomials ran with 0.2 secs... or so... I think this shows also the way to implement it as program-initialization; the strings 'st' in the 'for'- loop shall be stored as strings in a file which should then be loaded/read at programinititalization. Thanks for help and making me rethink the problem! Kind regards- Gottried