Ejemplo n.º 1
0
def pellSolution(pNumber):
    """return the solution of Pell equation x*x - pNumber*y*y = 1"""
    l = continuedFraction(pNumber, pNumber * 2)
    # print l
    t = fraction(l)
    P, Q = t[0], t[1]
    for i in range(len(P)):
        pi, qi = P[i], Q[i]
        # print pi,qi
        if pi * pi - pNumber * qi * qi == 1:
            return [pi, qi]
Ejemplo n.º 2
0
def fractionPeriod(pN): 
	'''return the period of continued Fraction of 
	squareRoot(n)'''
	squareRoot = int(math.floor(math.sqrt(pN)))
	length = 10 *squareRoot
	l = continuedFraction(pN, length)[1:]
	# print l
	k = 0
	nonSatisfy = True
	while nonSatisfy:	

		k+=1
		nonSatisfy = False
		for t in range(0,10):
			if (t+2)* k < length:
				if not nonSatisfy and l[t*k:(t+1)*k]!= l[(t+1)*k:(t+2)*k]:
					# print l[t*k:(t+1)*k], l[(t+1)*k:(t+2)*k]
					nonSatisfy = True
	return k
Ejemplo n.º 3
0
from functions import gcd, continuedFraction
import math

def properFraction(pNume,pDeno):
	'''pNume: numerator, pDeno: Denominator	
	return [z,x,y] such that pNume/pDeno =z +  x/y and gcd(x,y) = 1'''
	t = gcd(pDeno,pNume)
	z = pNume / pDeno
	x,y = (pNume - z*pDeno)/t, pDeno/t
	return [z,x,y]
print properFraction(20,15)	


print continuedFraction(13,10)

def fractionPeriod(pN): 
	'''return the period of continued Fraction of 
	squareRoot(n)'''
	squareRoot = int(math.floor(math.sqrt(pN)))
	length = 10 *squareRoot
	l = continuedFraction(pN, length)[1:]
	# print l
	k = 0
	nonSatisfy = True
	while nonSatisfy:	

		k+=1
		nonSatisfy = False
		for t in range(0,10):
			if (t+2)* k < length:
				if not nonSatisfy and l[t*k:(t+1)*k]!= l[(t+1)*k:(t+2)*k]: