-->
0 Members and 1 Guest are viewing this topic.
AwesomeCAS v1.0> (2x+5)(x+4)(5x+6)^5
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1
1 2 1 1 3 3 1
> (2x+5)(x+4)(5x+6)^5
1x^5 + 5(x^4)y + 10(x^3)(y^2) + 10(x^2)(y^3) + 5x(y^4) + 1y^5
3125 x^5+18750 x^4+45000 x^3+54000 x^2+32400 x+7776
equArray = [ [1, ["x", 5]], equPlus, [5, ["x",4], ["y",1]], equPlus, [10,["x",3],["y",2]], equPlus, [10,["x",2],["y",3]], equPlus, [5,["x",1],["y",4]], equPlus, [1,["y",5]]]equEquateX = ["x",[5, ["x", 1]]]equEquateY = ["y", [6]]
for equPart in equArray: # This loops grabs every item of equArray into equPart buffInt = 1 # Initialize a "blank" integer for us to use. This will serve as a standing point to create the final coefficient... for this part, anyway. :P for varEquPart in equArray: # This loop grabs every item of the equPart into varEquPart if type(varEquPart) == int: buffInt = buffInt * varEquPart # Multiple the coefficient into the final one else: # This should be an elemental array for actVarEquPart in varEquPart: # You see why I don't exactly like turning this idea into code, eh? :P if type(actVarEquPart) == str: if actVarEquPart == equEquateX[1]: # Substitute X in! for varEquPartInSubstitution in equEquateX if type(varEquPart) == int: buffInt = buffInt * varEquPart # Multiple the coefficient into the final one else: # This should be an elemental array
#!/usr/bin/env python# Experimental floating point implementation# Written by Albert H# VariablesDEBUG = 1n1 = raw_input("> Enter 1st floating point number: ")n2 = raw_input("> Enter 2nd floating point number: ")op = raw_input("> Enter operation (+, -, *, or /) to perform: ")# Now for the REAL guts of this program!# We use absolutely NO floating point operations here at all. NONE.# If you enable the DEBUG var above, you get to see every part of the# process. No single number used is a floating point number at all.if op == '+': # Easiest one of the bunch. Align the decimal point! pointpos1 = n1.index(".") pointpos2 = n2.index(".") if pointpos1 < pointpos2: # If pointpos1 has a lower index than pointpos2... that means # we have n1 being 3.14 and n2 being 12.4. for n in range(0, pointpos2-pointpos1): n1 = " " + str(n1) if DEBUG == 1: print ">> DEBUG: n1 string is: "+str(n1) print ">> DEBUG: n2 string is: "+str(n2) # Number crunching time! lenOfNum1 = len(n1) lenOfNum2 = len(n2) # TODO: Fix bug with entering same number/dec place == crash # TODO: Fix 0.9+12.9 =12.18 due to lack of carryover correction result = "" tempResult = "" for nIndex in range(0, max(lenOfNum1, lenOfNum2)): if nIndex <= (lenOfNum1 - 1): if nIndex <= (lenOfNum2 - 1): if n1[nIndex] != ' ': if n2[nIndex] != ' ': # TODO: add checking for misalign of decimal points if n1[nIndex] != '.': if DEBUG == 1: print ">> DEBUG: Both n1 and n2 digits are present! Adding integers: "+n1[nIndex]+" + "+n2[nIndex] tempResult = int(n1[nIndex]) + int(n2[nIndex]) result = result + str(tempResult) else: if DEBUG == 1: print ">> DEBUG: Decimal point detected! Appending decimal point to result." result = result + "." else: if DEBUG == 1: print ">> DEBUG: n2[nIndex] is a space, so adding n1's digit to result. Digit: "+str(n1[nIndex]) result = result + str(n1[nIndex]) else: if n2[nIndex] != ' ': if DEBUG == 1: print ">> DEBUG: n1[nIndex] is a space, so adding n2's digit to result. Digit: "+str(n2[nIndex]) result = result + str(n2[nIndex]) else: print "ERROR: Something went wrong in preprocessing!" print "Guru meditation: n1[nIndex] and n2[nIndex] are both spaces! n1='"+n1+"', n2='"+n2+"', nIndex="+str(nIndex) exit(1) else: if DEBUG == 1: print ">> DEBUG: n2[nIndex] does not exist, so adding n1's digit to result. Digit: "+str(n1[nIndex]) result = result + str(n1[nIndex]) else: if nIndex <= (lenOfNum2 - 1): print ">> DEBUG: n1[nIndex] does not exist, so adding n2's digit to result. Digit: "+str(n2[nIndex]) result = result + str(n2[nIndex]) else: print "ERROR: Something went wrong in preprocessing!" print "Guru meditation: nIndex is out of range! n1='"+n1+"', n2='"+n2+"', nIndex="+str(nIndex) print "> Result: "+result
If you need math stuffs I can help.
I am working on some fp math routines I have most things of the adding routine working.
102 10 /----10 * 10remainder: 2do the remainder *10 returns 20divide remainder 2010 /---2*10 so first decimal is 2repeat until there is no remainder leftAnswer: 10.2