Karim Belabas on Wed, 11 Dec 2024 22:24:17 +0100


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

Re: Is this the way to use auxiliary variables in vector initialized via multiple iterators?


* hermann@stamm-wilbrandt.de [2024-12-11 22:16]:
> Doc talks about
> https://pari.math.u-bordeaux.fr/pub/pari/manuals/2.17.0/users.pdf#page=25
> 
> "To iterate over more than one variable, you may separate clauses with ; as
> in"
> 
> I found no mentioning how to introduce auxiliary variables to avoid
> repetition of terms.
> 
> I wanted to use auxiliary variable s for sum p^2+4*q^2, and this does the
> job:
> 
> ? P=primes([2,100]);vecmin([s|p<-P;q<-P;s<-[p^2+4*q^2],isprime(s)])
> 41
> ?
> 
> Is there another way of assignment to s without having to introduce
> auxiliary single element set?

P = primes([2,100]); vecmin([s | p<-P;q<-P, isprime(s = p^2+4*q^2)])

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/