I'm in high school, (don't judge) and I've recently been working on coding a synthetic division calculator, and as of right now, it works. However, as you can see from the below record of the output and input, the information gathering stage is quite tedious.
Enter the degree of the numerator (max 12):
3
Enter the coefficient of x^3 in the numerator:
2
Enter the coefficient of x^2 in the numerator:
-6
Enter the coefficient of x in the numerator:
-3
Enter the value of the constant in the numerator:
8
Enter the degree of the denominator (max 2):
2
Enter the coefficient of x^2 in the denominator:
7
Enter the coefficient of x in the denominator:
-5
Enter the value of the constant in the denominator:
3
The quotient of the numerator 2x^3-6x^2-3x+8 and the denominator 7x^2-5x+3
is equal to (2/7)x+(-32/49)+((-349/49)x+(488/49))/(7x^2-5x+3) which is
(0.285714285714)x+(-0.65306122449)+((-7.12244897959)x+(9.95918367347))/(7x^2-5x+3)
in rounded decimal format.
What I want is to turn this:
import re
numerator = '7x^12-6x^5+2/3x-19'
for m in re.finditer( r'(-{0,1}\d*)x\^{0,1}(-{0,1}\d*)', numerator):
coef, expn = list(map( lambda x: x if x != '' and x != '-' else x + '1' , m.groups( ) ))
print ('coef:{}, exp:{}'.format( coef, expn ))
Into something like this:
import re
numerator = '7x^12-6x^5+2/3x-19'
for m in re.finditer( r'(-{0,1}\d*)x\^{0,1}(-{0,1}\d*)', numerator):
coef, expn = list(map( lambda x: x if x != '' and x != '-' else x + '1' , m.groups( ) ))
[A, B, C, ... , M] = #???
#so "print [A, B, C, ... , M]" would print "7, 0, 0, 0, ... ,-6 , ... , -19"
#currently, it completly misses the point and prints "coef:7, exp:12, coef:-6, exp:5, coef:3, exp:-19"
The goal is to be able to simply input 2x^3-6x^2-3x+8 and 7x^2-5x+3, or any other combination of polynomials, and have the program convert each coefficient into a variable. If this is to complicated (I'm sure it can be done, but I don't have the slightest idea how) then it might be easier to have the program look at what is in between parentheses. This would require the user to be more careful when inputting polynomials because a single extra "(" could potentially mess up the whole thing, but it is significantly easier, I would be satisfied.