2

How do you write a F# recursive function 'something' that takes a single point (x, y) and index i as an arguments and returns an ℎ element of the infinite list corresponding to S(x, y).

ex: let something (x,y) i =

F# function F(,) should be defined as:

F(x,y)(u, v) = (u2 − v2 + x, 2uv + y)

F# function 'something' (x, y) of a point (x, y) should be an infinite list of items:

S(x, y) = {(0, 0), F(x,y)(0, 0), F(,y)(F(x,y)(0, 0)), F(x,y)(F(x,y)(F(x,y)(0, 0))), …}


CTNgel
  • 75
  • 4
  • Well this sounds like an obvious assignment question. Have you tried anything yourself? What specific problem do you have implementing it? – glennsl Nov 26 '19 at 21:29

1 Answers1

1

This looks like an assignment to me. I don't mind helping out but at the same time I don't want to give the full solution.

The exercise itself looks like generating the series:

Z' = Z*Z + C 

For a complex number Z and C. This is commonly done when generating the mandelbrot or julia set.

The function F can be written almost like the definition in F#:

let f (x, y) (u, v) = (u*u - v*v + x, 2.*u*v + y)

The infinite set S is generated from a starting point (0,0) and applying the output of f on itself over and over again.

An infinite set in F# can be represented using seq and you can create them using seq comprehesions

Once you have an infinite seq with the right values you can pick the ith value by using Seq.item