On Fri, Mar 05, 2021 at 03:09:40PM -0800, Tobias Neumann wrote:
> Let's construct a series that is zero to all orders:
> ser := series(exp(x),x=0)
> zeroSeries := ser-ser
> 
> I would like to check if the first 10 coefficients are zero,

To check this use two argument version of 'order' like:

order(ser, 10)

   (3)  0
                                                      Type: Fraction(Integer)
(4) -> order(zeroSeries, 10)

   (4)  10
                                                      Type: Fraction(Integer)
(5) -> order(zeroSeries, 25)

   (5)  25
                                                      Type: Fraction(Integer)

First result tells you that 'ser' has order 0, that is term
with exponent 0 is the first term with nonzero coefficient.
Second tell you that 'zeroSeries' has order at least 10,
that is first 10 terms (exponents 0,...,9) have 0 coefficients.


> so I truncate
> 
> trunc := truncate(zeroSeries,10)
> test(trunc = 0$UnivariatePuiseuxSeries(Expression(Integer),x,0))
> 
> and the comparison with 0 is indeed true.
> 
> On the other hand
> zero?(trunc) is false because of the way it checks the coefficients stream. 
> I am not sure if you consider this a bug, but I wanted to have it 
> mentioned, since it seems on the unexpected-behavior side for a finite 
> stream, at least for me.
> 
> zero? x ==
>     empty? (coefs := coefficients x) => true
>     (zero? frst coefs) and (empty? rst coefs) => true
>     false
> 
> Now the interesting behavior goes on:
> 
> test(truncate(zeroSeries,10) = 
> 0$UnivariatePuiseuxSeries(Expression(Integer),x,0))
> is true
> 
> but 
> test(truncate(zeroSeries,20) = 
> 0$UnivariatePuiseuxSeries(Expression(Integer),x,0))
> is false
> 
> So there also seems to be some cutoff built in?
> It seems, the safest way is to directly check the first N terms of 
> coefficients(zeroSeries) and not rely on truncate and "zero?".

By default display code looks at first 10 coefficients to
print them.  So if you print series it will have at least
10 computed coefficient, the rest is lazy.  For dense Laurent
and Puiseux series and for sparse series it is possible to
drop leading zero terms, and some routines do this with
explicitly known zero terms.  This is probably reason for
funny thing  you see.

Note that 'truncate' like other series operations is
lazy, you will see that truncated series is zero
only after you compute all coeficients.  If you
want them computed use 'complete'.

In general presence of 'zero?' and '=' in series domains
is a meta-bug: it is well-known that equality for lazy
series as implemented in FriCAS is undecidable.  Unfortunately,
many "generic" algorithms crucialy depends on equality,
so power series domains provide fake equality.  Fake,
because real equality is replaced by some computable
substitute.  Computable things include: two argument
'order' (one argument version may go into infinite loop),
and check that series is explicitly zero (stream of coefficients
is explicitely empty).  Fakes may go into infinte loop or
may claim that zero series is nozero (it seems that
code is careful enough to avoid claiming that nonzero
series is zero).  Zero test is usually done before
division and division check 1000 coefficient, if all
are zero then we get error.  So fake zero test
normally gives correct results for arithmetic and
from time to time error due to division by potential
zero.  This is similar to floating point computations,
where small nonzero result may be due to roundin error
and real result is zero.  Robust code must check
that computation is "well conditioned", in particular
that divisors are sufficiently far from zero.  In
case of series this means testing the divisors are
trurly nonzero and failnig when this is not known
(which our code do).  We should also do things like
selecting pivots of maximal possible order in
Gaussian elimination -- this is currently not
done so solving linear system may fail while
different choice of pivots would give result.

Anyway, limitations of series domains are fundamental and
well-known.  There are important special cases when
we know that series is nonzero or we know that
series having given number of zero terms must be
exactly zero.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/20210306003040.GD37163%40math.uni.wroc.pl.

Reply via email to