scalarp and nonscalarp



We have the open bug report ID: 2306402 - scalarp bug.

The documentation of scalarp says that an expression is assumed to be
scalar if the expression is composed only out of numbers, constants, or
variables declared to be scalar. Furthermore, the implementation of
scalarp is in a way that functions, which have only scalar arguments are
assumed to have a scalar value too.

Because of these assumptions we get the following results e.g. for the
build-in functions sin and gamma_incomplete:

(%i1) declare(x,scalar, a,nonscalar)$

(%i2) scalarp(sin(y));
(%o2) false
(%i3) scalarp(sin(x));
(%o3) true
(%i4) scalarp(sin(a));
(%o4) false
(%i5) scalarp(sin(1));
(%o5) true

(%i6) scalarp(gamma_incomplete(1,y));
(%o6) false
(%i7) scalarp(gamma_incomplete(1,x));
(%o7) true
(%i8) scalarp(gamma_incomplete(1,a));
(%o8) false
(%i9) scalarp(gamma_incomplete(1,1));
(%o9) true

If we use an unknown function we get the following. The results for
scalarp(foo(1)) and scalarp(foo(1,1)) are inconsistent with the results
from above:

(%i10) scalarp(foo(1,y));
(%o10) false
(%i11) scalarp(foo(1,x));
(%o11) true
(%i12) scalarp(foo(1,a));
(%o12) false
(%i13) scalarp(foo(1,1));  
(%o13) false               <- inconsistent

(%i14) scalarp(foo(y));
(%o14) false
(%i15) scalarp(foo(x));
(%o15) true
(%i16) scalarp(foo(a));
(%o16) false
(%i17) scalarp(foo(1));
(%o17) false             <- inconsistent

Therefore, I think the example scalarp(foo(1)) -> false of the bug
report might be wrong. To be consistent with the assumptions from above
we should get the result true too.

Furthermore, we get the following inconsistent results:

(%i1) scalarp(a[1]);
(%o1) false

But if we use a symbol declared to be a scalar we get:

(%i3) declare(x,scalar)$

(%i4) scalarp(a[x]);
(%o4) true

At last, we have the open bug report 1985748 "array and scalar
declarations yield inconsistent results". This bug report is related to
the problems reported here.

To get the last problems consistent we have to make the additional
assumption that subscripted symbols always are assumed to be nonscalar.
I have tried the assumption of a scalar too, but this causes a lot of
problems with code we already have.

Therefore, to get a consistent implementation of scalarp and nonscalarp
we need the following assumptions:

1. 
Functions not declared to be nonscalar have a scalar value, if the
arguments are scalar.

2. 
Subscripted symbols not declared to be scalar are assumed to represent a
nonscalar expression.

I have already done an implementation, based on the above assumptions.
It works and has no problems with the testsuite or share_testsuite. 

If there are no further comments I would like to gone on and to commit
this implementation.

Dieter Kaiser