login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for #90 coredump with infinite stream revision 1 of 4

1 2 3 4
Editor:
Time: 2007/11/17 23:04:11 GMT-8
Note:

changed:
-
I understand that the following is not a smart thing to do.  Axiom should complain, but it just coredumps silently::

  !\begin{axiom}
  primes:Stream Integer := generate(nextPrime, 2)
  smallerThan(stream, n) == [ s for s in stream | s < n ]
  smallerThan(primes, 100) -- Axiom 3.0 Beta coredumps
  \end{axiom}

Matthias


The failure is unrelated to '100'. It fails with the value 5.

Tim

This is likely due to stack overflow (previously reported). The construct for smallerThan requires Axiom to test EVERY element in the stream to see if s < n. There is no reason why Axiom should complain. Axiom is not designed to be able to figure out a general formula for the nth entry of the output stream for smallerThan whose signature is:

\begin{axiom}
smallerThan: (Stream Integer, PositiveInteger) -> Stream Integer
\end{axiom}

To do what you are trying to do, do this:
\begin{axiom}
)clear all
p:Stream Integer := generate(nextPrime, 2)
filterWhile(s+->s<5, p)
\end{axiom}

However, why should this give an error?
  \begin{axiom}
  entries p
  \end{axiom}

The expected result would be the first 11 (default stream length) entries. And here is another problem:

\begin{axiom}
lessThan(n)==
  g(s)== (s < n)
  print(g(3))
  filterWhile(g, p)
lessThan(5)
\end{axiom}

The local function g is not compiled correctly because n is not passed to it. So it compiles as false for all input.  The same error occurs in the NAG version.
One  would then expect Axiom to go into an infinite loop if we use not(s$<$n). But Axiom is "smart enough" to know and creates the stream even though the answer is still wrong.

\begin{axiom}
lessTest(n)==
  g(s) == not(s < n)
  print(g 3)
  filterWhile(g, p)
lessTest(5)
\end{axiom}

This crashes::

  !\begin{axiom}
  largerThan(st,n)==[s for s in st | not(s < n)]
  largerThan(p,5)
  \end{axiom}

This one below crashes, but not for the NAG version, which gives the correct answer::

  !\begin{axiom}
  before(st, n)==filterWhile(s+-> s < n, st)
  before(p,5)
  \end{axiom}

And this also crashes (whereas it does NOT crash for NAG version, giving the correct answer).::

  !\begin{axiom}
  lessThan(n)==filterWhile(s+-> (s < n), p)
  lessThan(5)
  \end{axiom}

William

From unknown Wed Feb 9 07:04:50 -0600 2005
From: 
Date: Wed, 09 Feb 2005 07:04:50 -0600
Subject: 
Message-ID: <20050209070450-0600@page.axiom-developer.org>

I understand that smallerThan in the original version does not work (I hoped it would return a stream as filterWhile does).  However, instead of coredumping silently (and taking the whole Axiom session with it), Axiom should say something like "stack limit reached in function suchandsuch" and return "failed" or something.

From unknown Tue Mar 22 20:09:15 -0600 2005
From: 
Date: Tue, 22 Mar 2005 20:09:15 -0600
Subject: property change
Message-ID: <20050322200915-0600@page.axiom-developer.org>

Severity: serious => critical 



Submitted by : (unknown) at: 2007-11-17T23:04:11-08:00 (17 years ago)
Name :
Axiom Version :
Category : Severity : Status :
Optional subject :  
Optional comment :

I understand that the following is not a smart thing to do. Axiom should complain, but it just coredumps silently:

  \begin{axiom}
  primes:Stream Integer := generate(nextPrime, 2)
  smallerThan(stream, n) == [ s for s in stream | s < n ]
  smallerThan(primes, 100) -- Axiom 3.0 Beta coredumps
  \end{axiom}

Matthias

The failure is unrelated to 100. It fails with the value 5.

Tim

This is likely due to stack overflow (previously reported). The construct for smallerThan requires Axiom to test EVERY element in the stream to see if s < n. There is no reason why Axiom should complain. Axiom is not designed to be able to figure out a general formula for the nth entry of the output stream for smallerThan whose signature is:

axiom
smallerThan: (Stream Integer, PositiveInteger) -> Stream Integer
Type: Void

To do what you are trying to do, do this:

axiom
)clear all All user variables and function definitions have been cleared. p:Stream Integer := generate(nextPrime, 2)
LatexWiki Image(1)
Type: Stream Integer
axiom
filterWhile(s+->s<5, p)
LatexWiki Image(2)
Type: Stream Integer

However, why should this give an error?

axiom
entries p >> Error detected within library code: infinite stream

The expected result would be the first 11 (default stream length) entries. And here is another problem:

axiom
lessThan(n)== g(s)== (s < n) print(g(3)) filterWhile(g, p)
Type: Void
axiom
lessThan(5)
axiom
Compiling function g with type PositiveInteger -> Boolean
axiom
Compiling function g with type Integer -> Boolean
axiom
Compiling function lessThan with type PositiveInteger -> Stream 
      Integer 
   false
LatexWiki Image(3)
Type: Stream Integer

The local function g is not compiled correctly because n is not passed to it. So it compiles as false for all input. The same error occurs in the NAG version. One would then expect Axiom to go into an infinite loop if we use not(sLatexWiki Imagen). But Axiom is "smart enough" to know and creates the stream even though the answer is still wrong.

axiom
lessTest(n)== g(s) == not(s < n) print(g 3) filterWhile(g, p)
Type: Void
axiom
lessTest(5) Compiled code for g has been cleared. Compiled code for lessThan has been cleared. 1 old definition(s) deleted for function or rule g
axiom
Compiling function g with type PositiveInteger -> Boolean
axiom
Compiling function lessTest with type PositiveInteger -> Stream 
      Integer 
   true
axiom
Compiling function g with type Integer -> Boolean
LatexWiki Image(4)
Type: Stream Integer

This crashes:

  \begin{axiom}
  largerThan(st,n)==[s for s in st | not(s < n)]
  largerThan(p,5)
  \end{axiom}

This one below crashes, but not for the NAG version, which gives the correct answer:

  \begin{axiom}
  before(st, n)==filterWhile(s+-> s < n, st)
  before(p,5)
  \end{axiom}

And this also crashes (whereas it does NOT crash for NAG version, giving the correct answer).:

  \begin{axiom}
  lessThan(n)==filterWhile(s+-> (s < n), p)
  lessThan(5)
  \end{axiom}

William

...
Wed, 09 Feb 2005 07:04:50 -0600 reply
I understand that smallerThan in the original version does not work (I hoped it would return a stream as filterWhile does). However, instead of coredumping silently (and taking the whole Axiom session with it), Axiom should say something like "stack limit reached in function suchandsuch" and return "failed" or something.
property change
Tue, 22 Mar 2005 20:09:15 -0600 reply
Severity: serious => critical