On Mon, May 30, 2022 at 08:28:03PM +0200, Ralf Hemmecke wrote:
> >>I am not so sure what to do for Stream and n<0.
> >>The result is actually a finite stream, but it would
> >>mean to expand the input stream up to A just to get
> >>the first element of the result. Doable, but should
> >>it be implemented, i.e. who would ever use that?
> >
> >I think that for stream error in case of negative increment
> >is reasonable.
>
> In the end it was easier than I thought.
>
> The original implementation in LazyStreamAggregate used
>
> (not index?(low, x)) or (not index?(high, x))
>
> to check whether the indices are OK.
This looks wrong. Evaluating things only when there is demand
is essential to stream semantics (otherwise recursive constructions
could fail). To say the truth, several things in LazyStreamAggregate
could be suspected (but to make progress ATM it is better to focus
just on 'elt').
> Since that already expands the stream
> up to that point, it should not be a problem for negative step sizes.
>
> See pull-request.
Using 'maxIndex' will fail for infinite streams. You should
test with something like:
my_fun(i : Integer) : Integer == i + 1
s := stream(my_fun, 1)@Stram(Integer);
Note: I used ';' to avoid calculationg elements for printing,
so that all elements are evaluated on demand.
Also, please use Unittest and associated machinery for testing.
--
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/20220530220929.GA10970%40fricas.math.uni.wroc.pl.