Not really a question per se on any problems I have with my code but more so on how to get a more accurate calculation in shorter order of time. Effectively speaking, I wish to have my method correctly calculate out to "X" decimal places for the output value but in less time than the baseline process.
The method I'm currently using works just dandy but requires an upper bound of roughly 100-1000 elements in the series calculation to be approximately within 10 decimal places of accuracy. The question I have is would altering/changing the expression used for a converging series (i.e. rather than 2^k, say 10^k ?) give a "quicker" way of approaching the same output value but in shorter iterations and how?
The code in question:
The method I'm currently using works just dandy but requires an upper bound of roughly 100-1000 elements in the series calculation to be approximately within 10 decimal places of accuracy. The question I have is would altering/changing the expression used for a converging series (i.e. rather than 2^k, say 10^k ?) give a "quicker" way of approaching the same output value but in shorter iterations and how?
The code in question:
def logN(val, base):
#logarithm of base 'N'
list_series = []
inc, integer, partial_sum = 0, 0, 0
bound = 1000
val = float(val)
while val >= base:
integer += 1
val /= base
partial = val
while inc < bound:
partial *= partial
if partial >= base:
list_series.append(1)
partial /= base
elif partial < base:
list_series.append(0)
inc += 1
for var in range(len(list_series)):
expr = ((list_series[var])/2.0)**(var+1)
partial_sum = expr + partial_sum
log_val = integer + partial_sum
return log_val