26

2

**Bug introduced in 9.0.0 and fixed in 10.3**

I am trying to speed up a function that involves continued fractions. Since `ContinuedFraction`

cannot be compiled, and the alternative way with `Nestlist`

of `FractionalPart`

does not produce the same results due to `ContinuedFraction`

's internal algorithm for the choice of the number of terms, I think the best way is to compute the continued fractions and then pass the integer list to the compiled function. Here's what I did:

```
fc = Compile[{{z, _Real}, {xcf, _Integer, 1}},
Fold[z/(#1 + #2) &, 0, 1/xcf]/z, RuntimeAttributes -> Listable]
z = {-.5, .5}
xcf = Reverse /@ Rest /@ ContinuedFraction[{.123455, .546452}]
fc[z, xcf]
```

This approach should work, however on my computer (*Mathematica* 10.0.2, Xubuntu 15.04), evaluating the compiled function over a list of arguments always crashes the kernel and sometimes displays this message:

```
No more memory available.
Mathematica kernel has shut down.
Try quitting other applications and then retry.
```

Why doesn't it work and how to fix this?

By the way, I am trying to recreate a higher quality version of the "Road to the Horizon" transformation of continued fractions from Linas Vepstas's math art gallery.

**Update**: Setting `Parallelization -> False`

in the compiled function as per @Joel Klein's answer in 17971 works, and it seems this is a confirmed bug. However, in my case it does not seem to be fixed as reported in that thread.

4FWIW, it also crashes on

Mathematica9.0.1, butnoton 8.0.4. – Oleksandr R. – 2015-08-07T10:53:12.5131I can also confirm it crashes with Mathematica 10.2. – shrx – 2015-08-07T11:59:55.260

1As a workaround, it does not crash for me if you change the type of

`xcf`

to`Real`

and use`Parallelization -> False`

. – rcollyer – 2015-08-07T13:08:30.8701@rcollyer is changing the type of

`xcf`

even necessary? See the update in my question, disabling parallelization alone prevents the crash (but slows down the execution). – shrx – 2015-08-07T13:47:16.400Nope, not necessary. It appears I was changing two things at once, and did not isolate which actually caused it not to crash. – rcollyer – 2015-08-07T13:53:15.480

I'd be interested if the kernel crashes with Mathematica 8.04 if

`Parallelization`

is explicitly set to`True`

. Can anyone check? – shrx – 2015-08-07T13:56:03.8571@shrx no, it does not. – Oleksandr R. – 2015-08-07T14:08:55.637

I should say I didn't try this in 9.0.0 (I don't have it installed). So we do not know for sure that this appeared only in 9.0.1. – Oleksandr R. – 2015-08-07T14:12:07.527

6Bug reported internally. Thank you! – ilian – 2015-08-07T15:22:39.900

@OleksandrR. you are right, I edited the notice. – shrx – 2015-08-07T16:29:06.860

3@shrx 9.0.0 is correct. I checked before making my edit. – ilian – 2015-08-07T16:33:45.017

3Fixed in the development version. – ilian – 2015-08-11T15:16:49.380