An elementary symbolics question: simplifying a nested/continued fraction?

(Julia version 1.10.3, Symbolics version 5.33.0)

Here’s a simple example:

using Symbolics
@variables y
eq = 1/(7+1/(2+1/(4+y)))
simplify(eq)
simplify_fractions(eq)
expand(eq)

None of the last three work - the fraction remains in its fully nested form. What I want, of course, is the output

(2y+9)/(15y+67)

I would have thought this would be a very standard and straightforward process, so clearly I’m missing something, or doing something incorrectly - but I don’t know what! Do I need the SymbolicUtils.jl package? (I though that its functionality had been subsumed into Symbolics.jl, however.)

I’ve looked through the list of methods in the Symbolics package, and I can’t see anything else that looks as though it should work.

Anyway - how do I reduce a nested or finite continued fraction to a single fraction? Many thanks.

This likely needs more rules added to simplification.

1 Like

Many thanks - I was initially surprised that such an elementary (to me) functionality was not already available, but if it is a matter of adding some routines to the simplification code, I’ll leave that to the experts!

I discovered I could do the simplification using the AbstractAlgebra package, using a polynomial ring R over the rationals, and the total ring of fractions over R. This, however, may be too abstract for some people. Anyway, I think that being able to reduce a nested/continued fraction to a single fraction would be worth including in Symbolics, if it was not too much trouble to code.

Again, many thanks.

Yes, we’d be happy to have extensions which make use of AbstractAlgebra/OSCAR. I think most users would be scared off by their interfaces, but using them within Symbolics would be a way to make them accessible. We just haven’t done all of the integrations we’ve wanted to do.

1 Like

Another option is simply to import the SymPy package. Although this is not a “native Julia” package as such, it seems to work well enough:

import SymPy as sy
sy.@syms y
eq = 1/(7+1/(2+1/(4+y)))
sy.simplify(eq)

gives the result

(2y+9)/(15y+67)

At the present time, this seems to be the best way for me to do symbolic work in Julia. It helps that I have a fairly good knowledge of SymPy in Python. But I prefer using Julia simply because it’s faster and more efficient.

Yes, and there are conversion functions to make it so you can move between the two.