#!/usr/bin/python import sympy def tokenize_node(a,b): #a GCD(a,b) funcion that remembers the multipliers along each step token_list=[] while a: a, b = b%a, a try: token_list.append(int(b/a)) except: note="division by zero on last try is normal" return token_list token_list=gcd(4913,1594) x=sympy.symbols('x') frac=x token_list.reverse() for token in token_list: frac=(token+(1/frac)) print frac print sympy.simplify(frac)