defgetWhiteSpace(): if hasWhiteSpace==False: return"" str = "" cnt = rd(0,2) for i in range(cnt): type = rd(0,1) if type==0: str = str + " " else: str = str + "\t" return str
defgetSymbol(): if rd(0,1)==1: return"+" else: return"-"
defgetNum(positive): result = "" integer = intPool[rd(0,len(intPool)-1)] iszero = rd(0,2) for i in range(iszero): result = result + "0" if hasLeadZeros==False: result = "" result = result + str(integer) if rd(0,1)==1: if positive==True: result = "+" + result else: result = getSymbol() + result # print("num:"+result) return result
defgetExponent(): result = "**" result = result + getWhiteSpace() case = rd(0,2) if rd(0,1)==1: result = result + "+" if case==0: result = result + "0" elif case==1: result = result + "1" else: result = result + "2" # result = result + getNum(True) # print("exponent:"+result) return result defgetPower(): result = "x" if rd(0,1)==1: result = result + getWhiteSpace() + getExponent() # print("Power:"+result) return result
defgetTerm(genExpr): factorNum = rd(1,maxFactor) result = "" if rd(0,1)==1: result = getSymbol()+getWhiteSpace() for i in range(factorNum): factor = rd(0,2) if factor==0: result = result + getNum(False) elif factor==1: result = result + getPower() elif factor==2and genExpr==True: result = result + getExpr(True) else: result = result + "0" if i < factorNum-1: result = result + getWhiteSpace() + "*" + getWhiteSpace() # print("term:"+result) return result
defgetExpr(isFactor): termNum = rd(1,maxTerm) result = getWhiteSpace() genExpr = True if isFactor==True: genExpr = False for i in range(termNum): result = result + getSymbol() + getWhiteSpace() + getTerm(genExpr) + getWhiteSpace() if isFactor==True: result = "(" + result + ")" if rd(0,1)==1: result = result + getWhiteSpace() + getExponent() # print("Expr:"+result) return result defgenData(): global globalPointer if globalPointer<len(specialData): expr = specialData[globalPointer] globalPointer = globalPointer + 1 else: expr = getExpr(False) x = sympy.Symbol('x') simplifed = sympy.expand(eval(expr)) return str(expr),str(simplifed) x = sympy.Symbol('x') fx = "+x**+0*x**0++3++x**+1*+1" y = sympy.expand(eval(fx)) print(y)
This is copyright.