On Sat, Jul 01, 2023 at 07:59:07AM -0700, Rafael Andraschko wrote:
> Hi everyone,
>
> I'm trying to calculate the fixed point of the cosine function using the Y
> function (in YSTREAM); my guide to do this is the Scratchpad II Newsletter
> (nov/1987) that describes the fixedPoint function - by the Authors' names I
> inferred that Y and fixedPoint are the same (?).
I am not sure what is written in Scratchpad II Newsletter, but this
looks like the same function. Just to make sure you understand
principles: the function given as argument to Y must be able to
compute element number n of the strean looking only at elements
with number up to n - 1.
> Well, first I tried the following:
>
> scos x == cos(x)$STTF(Float)
> f1(x: Stream Float):Stream Float == cons(1.0, scos(x))
>
> Y f1
>
> That gaves me the error
>
> >> Error detected within library code:
> Trying to use uninitialized stream
I am not sure what you expect from this, but it does not look like
fixed point of cos. Note that cos in STTF compites series composition
of cos and series x. In general composition of g(h) of Taylor
series is defined only when term number 0 in h is 0. cos has
special code to handle case when term number 0 of h is nonzero,
but this code must look at term number 1 in h, violating restriction
on argument to Y.
> Then I made a similar function using the Stream's map! function:
>
> f1(x: Stream Float):Stream Float == cons(1.0, map!(cos, x))
>
> Y f1
>
> Now the error is
>
> Compiling function f1 with type Stream(Float) -> Stream(Float)
>
> >> System error:
> The value
> 0
> is not of type
> CONS
map! is doing in-place modification and this does not play well
with streams, so there are severe restrictions on use of
map! on streams. Instead do:
f1(x: Stream Float):Stream Float == cons(1.0, map(cos, x))
Y f1
AFAICS this gives you stream of approximations to fixed point
of cos.
--
Waldek Hebisch