Bill Allombert on Tue, 07 Dec 2021 21:34:41 +0100


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

Re: logical operators -- documentation


On Tue, Dec 07, 2021 at 08:46:35PM +0100, Paul Underwood wrote:
> I am sorry for using "associativity" wrongly.
> 
> I don't think it is "precedence"; Both || and && have the same "priority" in the documentation.
> 
> Here is another example:
> 
> for(n=1,9,if(n%2==1 || 1<0 && 3<2 || 3>2 ,print1(n" ")))
> 1 2 3 4 5 6 7 8 9

There are too many way this can be read to reach a conclusion...

> I think the documentation should read "right to left"

it would not work. It meant that print(1) && print(2) would print 2.

I offer this test:

? forvec(V=vector(3,i,[0,1]),print(V,":",(V[1]&&V[2]||V[3])==((V[1]&&V[2])||V[3])))
[0,0,0]:1
[0,0,1]:1
[0,1,0]:1
[0,1,1]:1
[1,0,0]:1
[1,0,1]:1
[1,1,0]:1
[1,1,1]:1

? forvec(V=vector(3,i,[0,1]),print(V,":",(V[1]||V[2]&&V[3])==((V[1]||V[2])&&V[3])))
[0,0,0]:1
[0,0,1]:1
[0,1,0]:1
[0,1,1]:1
[1,0,0]:1
[1,0,1]:1
[1,1,0]:1
[1,1,1]:1

(This second one is not true with PARI 2.3, which apparently follow the
C convention. I do not know if it makes sense to "fix" it.).

Cheers,
Bill.