stream bug?

0 views
Skip to first unread message

leh...@bayou.uni-linz.ac.at

unread,
Dec 13, 2009, 10:27:17 AM12/13/09
to fricas...@googlegroups.com
Hello,

there is a strange error when using
select$Stream in compiled code.
It seems that a such generated stream is not
initialized properly.
After compiling the attached code I get

(1) -> IN:= expand [1..]

(1) [1,2,3,4,5,6,7,8,9,10,...]
Type:Stream(Integer)
(2) -> nth(IN,3)

>> System error:
Unhandled memory fault at #x4B.

however doing the steps interactively works as expected.
What am I missing?

regards,
Franz
selectbug.spad

Ralf Hemmecke

unread,
Dec 13, 2009, 11:04:44 AM12/13/09
to fricas...@googlegroups.com
Hi Franz,

Maybe that is indeed a bug, but I wouldn't care too much. I'd rather say
that your function looks much too complicated for what you want to achieve.

As far as I understand, you'd like to get a stream that returns the nth
element. So I tried the following.

)abbrev package SELBUG SelectBug
SelectBug(R: Ring): with
nth: (Stream R, Integer) -> Stream R
== add
nth(st, n) == delay
s := st
for k in 1..n-1 repeat s := rest s
concat(first s, nth(rest s, n))


(1) -> st: Stream(Integer) := expand [1..]

(1) [1,2,3,4,5,6,7,8,9,10,...]
Type: Stream(Integer)
(2) -> nth(st, 3)

(2) [3,6,9,12,15,18,21,24,27,30,...]
Type: Stream(Integer)
(3) -> nth(st, 4)

(3) [4,8,12,16,20,24,28,32,36,40,...]
Type: Stream(Integer)
(4) -> nth(st, 2)

(4) [2,4,6,8,10,12,14,16,18,20,...]
Compilation of your code shows me.

Semantic Errors:
[1] nth: mk is BOTH a variable and a literal

Warnings:
[1] nth: kk has no value
[2] nth: mk has no value

And in the end

(1) -> st: Stream(Integer) := expand [1..]

(1) [1,2,3,4,5,6,7,8,9,10,...]
Type: Stream(Integer)
(2) -> mth(st, 3)


(2) [1,2,3,4,5,6,7,8,9,10,...]
Type: Stream(Integer)
(3) -> nth(st, 3)



>> System error:

The variable |mkRecord| is unbound.


No idea, whether that helps to find the bug.

Ralf

Waldek Hebisch

unread,
Dec 13, 2009, 11:30:07 AM12/13/09
to fricas...@googlegroups.com
Spad compiler mis-optimized one of your functions, the '+->' form
in:

mpstr:Stream MPAIR := map((mk:R,k1:Integer):MPAIR +-> ([mk,k1]$MPAIR), _
st, ii)$StreamFunctions3(R,Integer,MPAIR)

gives wrong code. The other parts (in particular select) seem to
work fine.

I am looking at this. We could quickly fix problem disabling responsible
optimization. But I want both optimization and correct code so
I need to find out which cases are problematic (and disable otimization
only for them).

--
Waldek Hebisch
heb...@math.uni.wroc.pl

leh...@bayou.uni-linz.ac.at

unread,
Dec 13, 2009, 11:31:45 AM12/13/09
to fricas...@googlegroups.com
Hi Ralf,

On Sun, Dec 13, 2009 at 05:04:44PM +0100, Ralf Hemmecke wrote:
> As far as I understand, you'd like to get a stream that returns the nth
> element. So I tried the following.
ok that looks much better. I was looking at bottomup messages
what
[x for x in xx for k in 1..|even? k]
is doing and concluded the construction I gave.

> Compilation of your code shows me.
>
> Semantic Errors:
> [1] nth: mk is BOTH a variable and a literal
seems to be harmless, the error persists after changing it.

> >> System error:
>
> The variable |mkRecord| is unbound.
I have --with-algebra-optimization=((speed 3) (safety 0))
perhaps this is the reason for different error messages.
Indeed the compiler log shows
; caught WARNING:
; undefined variable: |mkRecord|

Franz

Ralf Hemmecke

unread,
Dec 13, 2009, 11:59:04 AM12/13/09
to fricas...@googlegroups.com
> I was looking at bottomup messages what
> [x for x in xx for k in 1..|even? k]
> is doing and concluded the construction I gave.

Hmm, OK. Then what about

[x for x in 1.. for i in repeating [1,1,0] | zero? i ]

?

But I'm not sure that is efficient since it constructs another stream
"repeating [1,1,0]".

Interesting, even the following works (in the Interpreter)

[x for x in 1.. | x > 10 for i in repeating [1,1,0] | zero? i ]

I'm too lazy to try Aldor or the Spad compiler here. ;-)

Ralf

Waldek Hebisch

unread,
Dec 19, 2009, 7:57:48 PM12/19/09
to fricas...@googlegroups.com

The only problematic case was record constructor. I have now disabled
wrong optimization -- the code above should work fine.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Reply all
Reply to author
Forward
0 new messages