[sympy] Re: Continued fraction representation of quadratic irrationalities

2013-06-27 Thread mario
This seems to work ``` >>> from sympy import sqrt, sympify >>> from sympy.simplify.simplify import rad_rationalize >>> def continued_fraction(x, y): ... x = sympify(x) ... v, res = [], [] ... q = x/y ... while 1: ... v.append(q) ... a = int(q) ... res.append

[sympy] Re: Continued fraction representation of quadratic irrationalities

2013-06-27 Thread Stephen Loo
def continued_fraction(r): while True: i = int(r) yield i if i == r: break r = 1 / (r - i) Thilina Rathnayake於 2013年6月28日星期五UTC+8上午4時16分34秒寫道: > > Hi all, > > Is there a function in sympy which gives the continued fraction > representation > of qua

Re: [sympy] Re: Continued fraction representation of quadratic irrationalities

2013-06-27 Thread Thilina Rathnayake
Thanks guys for the help. Shouldn't we add this functionality to the current continued_fraction or add a new function to SymPy so user can use it directly? On Fri, Jun 28, 2013 at 7:45 AM, Stephen Loo wrote: > def continued_fraction(r): > while True: > i = int(r) > yield i

Re: [sympy] Re: Continued fraction representation of quadratic irrationalities

2013-06-27 Thread Stephen Loo
I have considered this, in quantum module, the continued_fraction function is only work for rational number a/b = continued_fraction(a, b), but my function above is work for float and depending on the precision. I don't know how to combine into single function, and it is not suggested to place

Re: [sympy] Re: Continued fraction representation of quadratic irrationalities

2013-06-28 Thread Thilina Rathnayake
Yes, that is where it should go. I don't think it will be that hard to combine. There is a Java code that is used in Dario Alpern's website. I need the continued_fraction representation of quadratic irrational numbers in the Diophantine equation module. I

Re: [sympy] Re: Continued fraction representation of quadratic irrationalities

2013-06-28 Thread Thilina Rathnayake
One approach would be to have three inputs to continued_fraction() function corresponding to the general form of a quadratic irrational fraction (a + sqrt(b)) / c We can set b = 0 for other cases. But I think it is not a good approach. Another approach would be to keep the current interface of co

Re: [sympy] Re: Continued fraction representation of quadratic irrationalities

2013-06-28 Thread Thilina Rathnayake
Code segment I proposed should be changed as below. Otherwise it fails when sqrt()'s are not involved. def continued_fraction(a, b): p = Wild('p') q = Wild('q') r = Wild('r') a = Add(a) match = a.match(p + r*sqrt(q)) # and do the processing acc

Re: [sympy] Re: Continued fraction representation of quadratic irrationalities

2013-07-03 Thread Aaron Meurer
Yes, this functionality would be useful in a general setting (probably in the ntheory module). It would also be useful to have a class, ContinuedFraction, which can help with the abstractions of the continued fraction representation, especially the infinite ones. There is actually a lot of cool ari

Re: [sympy] Re: Continued fraction representation of quadratic irrationalities

2013-07-09 Thread Thilina Rathnayake
Sure, Aaron I will open an issue for this. On Thu, Jul 4, 2013 at 5:38 AM, Aaron Meurer wrote: > Yes, this functionality would be useful in a general setting (probably in > the ntheory module). It would also be useful to have a class, > ContinuedFraction, which can help with the abstractions of