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 according to whether
        # q = 0 or not



On Fri, Jun 28, 2013 at 10:00 PM, Thilina Rathnayake <thilina.r...@gmail.com
> wrote:

> 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
> continued_fraction()
> unchanged and pattern match to identify sqrt() s involved in the numerator.
>
>     def continued_fraction(a, b):
>         p = Wild('p')
>         q = Wild('q')
>         match = a.match(p + sqrt(q))
>         # and do the processing according to whether
>         # q = 0 or not
>
>
>
> On Fri, Jun 28, 2013 at 8:23 PM, Thilina Rathnayake <
> thilina.r...@gmail.com> wrote:
>
>> Yes, that is where it should go. I don't think it will be that hard to
>> combine.
>> There is a Java code <http://www.alpertron.com.ar/CONTFRAC.HTM> that is
>> used in Dario Alpern's website.
>>
>> I need the continued_fraction representation of quadratic irrational
>> numbers
>> in the Diophantine equation module. I can implement it in diophantine
>> module
>> but I think that does not belong there. We should implement it in ntheory
>> and then use it in Diophantine module. Shall I start on this?
>>
>>
>>
>> On Fri, Jun 28, 2013 at 8:49 AM, Stephen Loo <hingk...@gmail.com> wrote:
>>
>>> 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 in quantum module, it should be in ntheory.
>>>
>>> Stephen
>>>
>>> Thilina Rathnayake於 2013年6月28日星期五UTC+8上午10時58分36秒寫道:
>>>>
>>>>
>>>> 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 <hing...@gmail.com> wrote:
>>>>
>>>>> 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 quadratic irrationalities like, (sqrt(17) + 5 ) / 4?
>>>>>>
>>>>>> I found an implementation of a continued fraction function in  Shor's
>>>>>> algorithm:
>>>>>> http://docs.sympy.org/dev/**modu**les/physics/quantum/shor.**html<http://docs.sympy.org/dev/modules/physics/quantum/shor.html>
>>>>>>
>>>>>> But it doesn't seem to give correct results when irrationalities are
>>>>>> involved.
>>>>>>
>>>>>> >>> from sympy.physics.quantum.shor import continued_fraction
>>>>>>> >>> continued_fraction(sqrt(17)+5, 4)
>>>>>>> [2, 4]
>>>>>>>
>>>>>>
>>>>>> Actual answer should be 2, [3, 1, 1] with the numbers inside []
>>>>>> repeating forever.
>>>>>> Any help would be appreciated.
>>>>>>
>>>>>> Regards,
>>>>>> Thilina.
>>>>>> .
>>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "sympy" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to sympy+un...@**googlegroups.com.
>>>>> To post to this group, send email to sy...@googlegroups.com.
>>>>>
>>>>> Visit this group at 
>>>>> http://groups.google.com/**group/sympy<http://groups.google.com/group/sympy>
>>>>> .
>>>>> For more options, visit 
>>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>>> .
>>>>>
>>>>>
>>>>>
>>>>
>>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "sympy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to sympy+unsubscr...@googlegroups.com.
>>> To post to this group, send email to sympy@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/sympy.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>


Thilina Rathnayake,

Undergraduate,

Dept. of Comp. Sci.

UoM.
[image: 
LinkedIn]<http://s.wisestamp.com/links?url=http%3A%2F%2Flk.linkedin.com%2Fpub%2Fthilina-bandara-rathnayake%2F35%2F36a%2F50%2F>
 “"A casual stroll through the lunatic asylum shows that faith does not
prove anything." - Friedrich
Nietzsche<http://s.wisestamp.com/links?url=http%3A%2F%2Fwww.quotesdaddy.com%2Fquote%2F477550%2Ffriedrich-nietzsche%2Fa-casual-stroll-through-the-lunatic-asylum-shows-that>
”  Get this email app!
<http://s.wisestamp.com/links?url=http%3A%2F%2Fwww.wisestamp.com%2Fapps%2Fquotes%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_term%3Dquotes%26utm_campaign%3Dapps>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to