On 31.05.22 00:09, Waldek Hebisch wrote:
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.

That is not originally my code. So if you consider it wrong, then it is wrong even in the current code base.

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').

Can you give a congrete example for your "recursion" argument? When elt(st, a..b by s) comes into play, st must already be defined whether by recursion or not.

If "index?(high, x)" comes into play then the user requests a closed segment of the stream, so the result will be an explicitly finite stream.

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);

I do not see maxIndex x in the elt implementation in stream.spad, it is only in ListAggregate.

And I already tested with an infinite stream in eltuniseg.input.

https://github.com/hemmecke/fricas/blob/f63c14a4ef45a14fb70988dbd626251c170f3ed3/src/input/eltuniseg.input#L7

Also, please use Unittest and associated machinery for testing.

OK, I can do this.

Ralf

--
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/89ac26de-bea0-a5c6-3f3b-fd7538a4abc1%40hemmecke.org.

Reply via email to