Jacques Gélinas on Mon, 20 Jul 2020 03:39:46 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Feature suggestion: "ifcmp" convenience control statement


Sometimes, I use many comparisons like this polynomial coefficient
depending on global variables

$ ak(k=0,d='d)={ if( 
  BESS==1,1/prod(j=1,k,1+d/(2*j-1)),
  MIKE==1,1/prod(j=1,k-1,prod(i=1,j,1+d/(2*i+1))),
  MIK==1,prod(j=1,k,prod(i=1,j,(2*i-1)/(d+2*i-1))),
  RK==1,prod(j=1,k,(2*j-1)*rks(j)^(k-j)),
  AKX==1,akx(k,d),
  eval(Str("a"k)));}   \\ general case

Jacques Gélinas

De : Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
Envoyé : 19 juillet 2020 17:24
À : pari-users@pari.math.u-bordeaux.fr <pari-users@pari.math.u-bordeaux.fr>
Objet : Re: Feature suggestion: "ifcmp" convenience control statement 
 
On Sun, Jul 19, 2020 at 04:00:23PM -0500, Hans L wrote:
> When writing functions in gp, I think it is fairly common to need to
> do 3 different things depending on a comparison of two values.
> This can of course be done with nested if() but it feels verbose and
> can get messy depending on how complicated the terms are:
> if(a<b, do_lt(), if(a>b, do_gt(), do_eq() ))

You can do
if(a<b, do_lt(), a>b, do_gt(), do_eq())

Cheers,
Bill.