Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
# Length of Preperiod and Period
a = 1
b = 2*7

u = denominator(a/b).valuation(2)
v = denominator(a/b).valuation(5)
def PreperiodLength(a,b): return max(u,v)

m = denominator(a/b) / (2^u*5^v)
y = 1/m
def PeriodLength(a,b):
    if m == 1:
        return 0
    else:
        return y.period()

#print 'm=', m
#print a,'/',b, '=', float(a/b)
print a,'/',b, '=', numerical_approx(a/b, digits=PreperiodLength(a,b)+PeriodLength(a,b))
print 'PreperiodLength:', PreperiodLength(a,b)
print 'PeriodLength:', PeriodLength(a,b)

Out:

1 / 14 = 0.07142857
PreperiodLength: 1
PeriodLength: 6
# 

Length of Preperiod and Period Period

a = 1
b = 2*7

u = denominator(a/b).valuation(2)
v = denominator(a/b).valuation(5)
 def PreperiodLength(a,b): PreperiodLength(a,b):
    return max(u,v)

m = denominator(a/b) / (2^u*5^v)
y = 1/m
 def PeriodLength(a,b):
    if m == 1:
        return 0
    else:
        return y.period()

#print 'm=', m
#print a,'/',b, '=', float(a/b)
print a,'/',b, '=', # print('m = {}'.format(m))
# print('{} / {} = {}'.format(a, b, float(a/b)))
print('{} / {} = {}'.format(a, b, numerical_approx(a/b, digits=PreperiodLength(a,b)+PeriodLength(a,b))
print 'PreperiodLength:', PreperiodLength(a,b)
print 'PeriodLength:', PeriodLength(a,b)
digits=PreperiodLength(a,b) + PeriodLength(a,b))
print('PreperiodLength: {}'.format(PreperiodLength(a,b)))
print('PeriodLength: {}'.format(PeriodLength(a,b))

Out:

1 / 14 = 0.07142857
PreperiodLength: 1
PeriodLength: 6

Length of Preperiod and Period

a = 1
b = 2*7

u = denominator(a/b).valuation(2)
v = denominator(a/b).valuation(5)

def PreperiodLength(a,b):
    return max(u,v)

m = denominator(a/b) / (2^u*5^v)
y = 1/m

def PeriodLength(a,b):
    if m == 1:
        return 0
    else:
        return y.period()

# print('m #print('m = {}'.format(m))
# print('{} #print('{} / {} = {}'.format(a, b, float(a/b)))
print('{} / {} = {}'.format(a, b, numerical_approx(a/b, digits=PreperiodLength(a,b) + PeriodLength(a,b))
PeriodLength(a,b))))
print('PreperiodLength: {}'.format(PreperiodLength(a,b)))
print('PeriodLength: {}'.format(PeriodLength(a,b))
{}'.format(PeriodLength(a,b)))

Out:

1 / 14 = 0.07142857
PreperiodLength: 1
PeriodLength: 6

Length of Preperiod and Period

a = 1
b = 2*7

u = denominator(a/b).valuation(2)
v = denominator(a/b).valuation(5)

def PreperiodLength(a,b):
    PreperiodLength(a,b): return max(u,v)

m = denominator(a/b) / (2^u*5^v)
y = 1/m

def PeriodLength(a,b):
    if m == 1:
        return 0
    else:
        return y.period()

#print('m = {}'.format(m))
#print('{} / {} = {}'.format(a, b, float(a/b)))
print('{} / {} = {}'.format(a, b, numerical_approx(a/b, digits=PreperiodLength(a,b) + PeriodLength(a,b))))
print('PreperiodLength: {}'.format(PreperiodLength(a,b)))
print('PeriodLength: {}'.format(PeriodLength(a,b)))

Out:

1 / 14 = 0.07142857
PreperiodLength: 1
PeriodLength: 6

Length of Preperiod and Period

a = 1
b = 2*7

u = denominator(a/b).valuation(2)
v = denominator(a/b).valuation(5)

def PreperiodLength(a,b): return max(u,v)

m = denominator(a/b) / (2^u*5^v)
y = 1/m

def PeriodLength(a,b):
    if m == 1:
        return 0
    else:
        return y.period()

#print('m = {}'.format(m))
#print('{} / {} = {}'.format(a, b, float(a/b)))
print('{} / {} = {}'.format(a, b, numerical_approx(a/b, digits=PreperiodLength(a,b) + PeriodLength(a,b))))
print('PreperiodLength: {}'.format(PreperiodLength(a,b)))
print('PeriodLength: {}'.format(PeriodLength(a,b)))

Out:

1 / 14 = 0.07142857
PreperiodLength: 1
PeriodLength: 6