def test_skip_arguments(self): from partial import SKIP template = "{0} {1} {2} and {3}" skip_first = partial(template.format, SKIP, 2) skip_last = partial(template.format, 1, 2, SKIP) with_two_skips = partial(template.format, SKIP, 2, SKIP) # Unevaluated skips with self.assertRaises(Exception): skip_last() with self.assertRaises(Exception): skip_last(3) with self.assertRaises(Exception): with_two_skips(1) with self.assertRaises(Exception): with_two_skips(1, 2) # Correct skips self.assertEqual(skip_last(3, 4), "1 2 3 and 4") self.assertEqual(with_two_skips(4, 6, 7), "4 2 6 and 7") self.assertEqual(with_two_skips(4, 7, 8), "4 2 7 and 8") self.assertEqual(skip_first(1, 3, 4), "1 2 3 and 4") # Unevaluated skips still don't work with self.assertRaises(Exception): skip_last() with self.assertRaises(Exception): skip_last(2) with self.assertRaises(Exception): with_two_skips(1) with self.assertRaises(Exception): with_two_skips(3, 4)
def test_sanity(self): def foo(x,y,z): return 100*x + 10*y + z f = partial(foo) # don't bind anything self.assertEqual(f(1,2,z=3),foo(1,2,z=3)) f = partial(foo,1) self.assertEqual(f(2,3),foo(1,2,3)) f = partial(foo,1,z=3) self.assertEqual(f(2),foo(1,2,3))
def test_arguments_held_for_later_execution(self): def add(x, y): return x + y add_3_and_4 = partial(add, 3, 4) self.assertEqual(add_3_and_4(), 7) add_3 = partial(add, 3) self.assertEqual(add_3(7), 10) add_1_and_4 = partial(add, x=1, y=4) self.assertEqual(add_1_and_4(), 5) add_4 = partial(add, y=4) self.assertEqual(add_4(8), 12) self.assertEqual(add_4(8), 12) # Calling twice works
def test_nice_string_representation(self): fake_file = StringIO() fake_print = partial(print, file=fake_file) self.assertIn('print', repr(fake_print)) self.assertIn('file', repr(fake_print)) print_one_two_three = fake_print.partial(1, 2, 3) self.assertIn('print', repr(print_one_two_three)) self.assertIn('file', repr(print_one_two_three)) self.assertIn('1, 2, 3', repr(print_one_two_three))
def test_partial_method(self): template = "{0} {1} and {2} and {red} {green} and {blue}" x = partial(template.format, 'purple', 'white') y = x.partial(green=2, blue=3) z = y.partial('red', red=1) w = y.partial('black', blue=4, green=2) self.assertEqual( x('pink', green=1, blue=2, red=3), "purple white and pink and 3 1 and 2", "Original partial shouldn't change on .partial() method call!", ) self.assertEqual(z(), "purple white and red and 1 2 and 3") self.assertEqual(w(red=0), "purple white and black and 0 2 and 4") self.assertEqual(y(None, red=9), "purple white and None and 9 2 and 3")
def main(): options = sys.argv[1] # options='010000000' if int(options) == 0: options = '1' + options[1:] options = options[0:4] + '0' + options[4:10] # extrema options = options[0:10] + '0' + options[10] # work,circulation,flux pick = [] for i in range(len(options)): if options[i] == '1': pick.append(i) type1 = pick[random.randrange(0, len(pick))] # type1=2 # Derivatives # 0 Partial Derivatives # 1 Chain Rule # 2 Directional, and (need to be added) gradient, Tangent Planes # 3 Lagrange Multipliers ####4 Extrema # Integrals # 5-7 Multiple (rectangular, polar, combine spherical/cylindrical) Integrals # Vectors # 8 divergence and curl ####9 Line Integrals ####10 Work, Circulation, Flux # 11 potential functions # Add later # 4 Extrema and Saddle Points # 7'Green’s Theorem' # 8'Divergence/Stokes Theorem' master_bank = {} # partial derivatives if type1 == 0: subtype = random.randint(1, 5) if subtype < 3: implicit = partial.partial(2, 'mixed') func = 'f(x,y)' if subtype >= 3: implicit = partial.partial(3, 'dummy') func = 'f(x,y,z)' f = implicit.f if subtype == 1 or subtype == 3: ans = implicit.fx der = 'f_x' if subtype == 2 or subtype == 4: ans = implicit.fy der = 'f_y' if subtype == 5: ans = implicit.fz der = 'f_z' probtex = 'Given the function $' + func + '=' + frac( toTEX(f)) + '$, find $' + der + '$.' prefix = '$' + der + '=$' anstex = 'The answer is $' + der + '=' + frac(toTEX(ans)) + '$' prefix = '' hint = '' # Chain Rule if type1 == 1: subtype = random.randint(1, 4) if subtype % 2 == 0: option = 't' else: option = 'uv' uorv = random.randint(0, len(option) - 1) der = 'f_%s' % option[uorv] if subtype < 3: implicit = partial.partial(2, 'short') implicit.tuv(option, 2) f = [implicit.fx, implicit.fy] func = 'f(x,y)' df = '(' + f[0] + ')' + '*' + implicit.dtuv[0][ uorv] + '+' + '(' + f[1] + ')' + '*' + implicit.dtuv[1][uorv] df = df.replace('x', '(' + implicit.tuv[0] + ')') df = df.replace('y', '(' + implicit.tuv[1] + ')') if subtype >= 3: implicit = partial.partial(3, 'short') f = [implicit.fx, implicit.fy, implicit.fz] implicit.tuv(option, 3) func = 'f(x,y,z)' df = '(' + f[0] + ')' + '*' + implicit.dtuv[0][ uorv] + '+' + '(' + f[1] + ')' + '*' + implicit.dtuv[1][ uorv] + '+' + f[2] + '*' + implicit.dtuv[2][uorv] df = df.replace('x', implicit.tuv[0]) df = df.replace('y', implicit.tuv[1]) df = df.replace('z', implicit.tuv[2]) if subtype == 1: probtex = 'Given the function $' + func + '=' + toTEX( implicit.f) + '$, <br>with $x(u,v)=' + toTEX( implicit.tuv[0]) + '$ and $y(u,v)=' + toTEX( implicit.tuv[1]) + '$ find $' + der + '$.' if subtype == 2: probtex = 'Given the function $' + func + '=' + toTEX( implicit.f) + '$, <br>with $x(t)=' + toTEX( implicit.tuv[0]) + '$ and $y(t)=' + toTEX( implicit.tuv[1]) + '$ find $' + der + '$.' if subtype == 3: probtex = 'Given the function $' + func + '=' + toTEX( implicit.f) + '$, <br>with $x(u,v)=' + toTEX( implicit.tuv[0]) + '$, $y(u,v)=' + toTEX( implicit.tuv[1]) + '$ and $z(u,v)=' + toTEX( implicit.tuv[2]) + '$ find $' + der + '$.' if subtype == 4: probtex = 'Given the function $' + func + '=' + toTEX( implicit.f) + '$, <br>with $x(t)=' + toTEX( implicit.tuv[0]) + '$, $y(t)=' + toTEX( implicit.tuv[1]) + '$ and $z(t)=' + toTEX( implicit.tuv[2]) + '$ find $' + der + '$.' import sympy from sympy.parsing.sympy_parser import parse_expr t, u, v, x, y, z = sympy.symbols('t u v x y z') df = df.replace('^', '**') sympy_exp = parse_expr(df) ans = str(sympy_exp) ans = ans.replace('**', '^') ans = ans.replace('log', 'ln') # ans=df prefix = '$' + der + '=$' anstex = 'The answer is $' + der + '=' + toTEX(ans) + '$' prefix = '' hint = '' # Directional Derivatives if type1 == 2: subtype = random.randint(1, 2) if subtype == 1: grad = partial.partial(2, 'mixed') vect = vector.vector(2) (x, y) = vect.point evalfx = grad.fx.replace('^', '**') evalfy = grad.fy.replace('^', '**') evalfx = evalfx.replace('x', str(vect.point[0])) evalfy = evalfy.replace('y', str(vect.point[1])) totalder = (eval(reduce(evalfx)), eval(reduce(evalfy))) func = 'f(x,y)' probtex = 'Given the function $' + func + '=' + toTEX( grad.f ) + '$, find the derivative at $(%d,%d)$ in the direction $ \left\langle %d,%d \\right\\rangle $.' % tuple( vect.point + vect.vec1) if subtype == 2: grad = partial.partial(3, 'dummy') vect = vector.vector(3) (x, y, z) = vect.point grad.fx = grad.fx.replace('x', str(vect.point[0])) grad.fy = grad.fy.replace('y', str(vect.point[1])) grad.fz = grad.fz.replace('z', str(vect.point[2])) totalder = (eval(reduce(grad.fx)), eval(reduce(grad.fy)), eval(reduce(grad.fz))) func = 'f(x,y,z)' probtex = 'Given the function $' + func + '=' + toTEX( grad.f ) + '$, find the derivative at $(%d,%d,%d)$ in the direction $\left\langle %d,%d,%d \\right\\rangle$.' % tuple( vect.point + vect.vec1) roundlim = 4 ans = str(float(vector.dot(totalder, vect.vec1)) / float(vect.norm1)) ans = str(round( vector.dot(totalder, vect.vec1) / vect.norm1, roundlim)) prefix = '' anstex = 'The answer is %s $ %s $.' % (prefix, toTEX(ans)) hint = '' # Lagrange Multipliers if type1 == 3: bank = {} # bank['problem']=['ans','prefix','hint','anstex'] bank[ 'Find the maximum volume of a box with a surface area of $24$.'] = [ '8', '$V=$', 'Optimize $f=xyz$ constrained by $g=2xy+2yz+2xz-24=0$.' ] bank[ 'Find the maximum volume contained by a box with a surface area of $12$ with the top missing (5 sides).'] = [ '4', '$V=$', 'Optimize $f=xyz$ constrained by $g=2xy+2yz+xz-12=0$.' ] # more geo? cylinder? bank[ 'Find the maximum volume of a cylinder inscribed in a sphere with radius $r_s=5$.'] = [ '32*pi', '$V=$', 'Use the constraint $r_s=\sqrt{r^2+(h/2)^2}$.' ] bank[ 'Find the maximum volume of a rectangular prism inscribed in a sphere with a diameter $d_s=3$.'] = [ '1', '$V=$', 'Use the constraint $d_s=\sqrt{x^2+y^2+z^2}$.' ] bank[ 'Maximize the equation $f=xy$, subject to the constraints $x,y>0$ and $x^2+4y^2=50$.'] = [ '25/2', '', '' ] bank[ 'Maximize the equation $f=xy$, subject to the constraint $x+4y=16$.'] = [ '16', '', '' ] bank[ 'Maximize the equation $f=xy^3z$, subject to the constraints $x,y,z>0$ and $x+y+z=5$.'] = [ '27', '', '' ] bank[ 'Maximize the equation $f=xy\sqrt{z}$, subject to the constraints $x,y,z>0$ and $x+y+z=20$.'] = [ '128', '', '' ] bank[ 'Maximize the equation $f=x^2+y^2+z^2$, subject to the constraints $x,y,z>0$ and $x+y+z=6$.'] = [ '12', '', '' ] bank[ 'Maximize the equation $2x-3y$ subject to the constraint $x^2+y^2=13$.'] = [ '13', '', '' ] bank[ 'Maximize the equation $3x-y$ subject to the constraint $x^2+y^2=40$.'] = [ '20', '', '' ] bank[ 'Minimize the equation $x-2y$ subject to the constraint $x^2+y^2=45$.'] = [ '15', '', '' ] bank[ 'Find the minimum distance from the surface $xyz=1$ to the origin'] = [ '3^(1/2)', '', 'Let $f=x^2+y^2+z^2$' ] bank[ 'Find the minimum distance from the surface $x^2y=1$ to the origin'] = [ '(2^(1/3)+2^(-2/3))^(1/2)', '', '' ] bank[ 'Find the minimum distance from the surface $x^3y=1$ to the origin'] = [ '(3^(1/4)+3^(-3/4))^(1/2)', '', '' ] # to finish (2 each) bank[ 'Find the maximum value of $x+y+z$ if the points lie on the sphere $x^2+y^2+z^2=5$.'] = [ 'ans', 'prefix', 'hint', 'anstex' ] # bank['Find the point on the plane $$ closest to the point $$.']=['ans','prefix','hint','anstex'] probtex = random.choice(bank.keys()) ans_set = bank[probtex] ans = ans_set[0] prefix = ans_set[1] hint = ans_set[2] if len(ans_set) == 3: if prefix != '': prefix += ' ' anstex = 'The answer is %s$%s$.' % (prefix, toTEX(ans)) else: anstex = ans_set[3] # Extrema if type == 4: pass # Multiple Integrals if type1 == 5 or type1 == 6 or type1 == 7: if type1 == 5: rando = random.randint(1, 4) if rando == 1: type2 = 'triple' else: type2 = 'double' elif type1 == 6: # polar type2 = 'polar' elif type1 == 7: # cylindrical integrals type2 = 'sphercyn' intprob = integral(type2) probtex = intprob.problem ans = intprob.ans anstex = 'The answer is $%s$.' % toTEX(ans) prefix = '' hint = '' # Divergence and Curl if type1 == 8: dc = partial.divcurl() subtype = random.randint(1, 2) if subtype == 1: dc.prob = 'divergence' ans = dc.div anstex = 'The divergence is $' + toTEX(ans) + '$.' if subtype == 2: dc.prob = 'curl' ans = '<%s,%s,%s>' % (dc.curl[0], dc.curl[1], dc.curl[2]) anstex = 'The curl is $ \left\langle %s, \ %s, \ %s \\right\\rangle $.' % ( toTEX(dc.curl[0]), toTEX(dc.curl[1]), toTEX(dc.curl[2])) dcftex = [] for i in range(3): dcftex.append(toTEX(dc.f[i])) probtex = 'Find the ' + dc.prob + ' of the field described by $ \left\langle %s,%s,%s \\right\\rangle $.' % tuple( dcftex) prefix = '' hint = '' # Line Integrals if type1 == 9: bank = {} # answer, prefix, hint # circle x,y bank[ 'Evaluate the integral $\int_C{xy^2 \ ds}$ where $C$ is the path from $(2,0)$ to $(0,2)$ clockwise on $x^2+y^2=4$.'] = [ '16/3', '', '' ] bank[ 'Evaluate the integral $\int_C{xy \ ds}$ where $C$ is the clockwise path from $\\theta=0$ to $\\theta=\pi/2$ on the unit circle.'] = [ '1/2', '', '' ] bank[ 'Evaluate the integral $\int_C{\\frac{1}{x^2} \ ds}$ where $C$ is the clockwise path from $\\theta=0$ to $\\theta=\pi/4$ on the unit circle.'] = [ '1', '', '' ] bank['Evaluate the integral $\int_C{\\frac{y}{x}\cdot \\frac{1}{x^2} \ ds}$ where $C$ is the clockwise path from $\\theta=0$ to $\\theta=\pi/3$ on the unit circle.'] = [ '1', '', 'After substituting $x(t)=\cos(t)$ and $y(t)=\sin(t)$, you can put the integrand in the form $\sec^2(t)\\tan(t)$, or $\sin(t) / \cos^3(t)$, either of which can be integrated with $u$-substitution.' ] # line segment bank[ 'Evaluate the integral $\int_C{x-y^2z \ ds}$ where $C$ is the line segment from $(0,0,0)$ to $(2,1,2)$.'] = [ '3/2', '', '' ] bank[ 'Evaluate the integral $\int_C{\pi\cdot\sin(\pi x)-xy \ ds}$ where $C$ is the line segment from $(0,0)$ to $(3,4)$.'] = [ '-50/3', '', '' ] bank[ 'Evaluate the integral $\int_C{xy+z \ ds}$ where $C$ is the line segment from $(-2,-1,0)$ to $(1,3,12)$.'] = [ '169/2', '', '' ] bank[ 'Evaluate the integral $\int_C{\\frac{x}{y}+z \ ds}$ where $C$ is the line segment from $(1,2,1)$ to $(3,6,5)$.'] = [ '21', '', '' ] bank[ 'Evaluate the integral $\int_C{\\frac{z}{xy} \ ds}$ where $C$ is the line segment from $(1,2,3)$ to $(2,3,5)$.'] = [ 'sqrt(6)*ln(3)', '', '' ] bank[ 'Evaluate the integral $\int_C{x\cdot\sin(y) \ ds}$ where $C$ is the line segment from $(0,0)$ to $(1,\pi)$.'] = [ '1/pi*sqrt(pi^2 + 1)', '', '' ] # more complex bank[ 'Evaluate the integral $\int_C{ds}$ where $C$ is the path from $(0,0)$ to $(1,1)$ on $y=x^4$.'] = [ '(17^(3/2)-1)/144', '', '' ] """ master_bank['Find the arc length of the curve $y=.75*x$ from $x=0$ to $x=5$.']=['','6.25',''] master_bank['Find the arc length of the curve $y=(x+5)^{3/2}$ from $x=0$ to $x=8$.']=['','988/27',''] master_bank['Find the arc length of the curve $y=\sinh(x)$ from $x=0$ to $x=1$.']=['','(e^2-1)/(2*e)',''] master_bank['Find the arc length of the parametric curve $x=\cos(t)$ $y=\sin(t)$ from $t=0$ to $t=\pi$']=['','pi',''] master_bank['Find the arc length of the parametric curve $x=t^{3/2}$ $y=t$ from $t=0$ to $t=1$']=['','61/27',''] master_bank['Find the arc length of the parametric curve $x=3*t^2$ $y=1/2*t^3$ from $t=0$ to $t=3$']=['','30.5',''] master_bank['Find the arc length of the parametric curve $x=t^3$ $y=t^{4.5}$ from $t=0$ to $t=1$']=['','1.43971',''] """ # helix bank[ 'Evaluate the integral $\int_C{ xy^2+z \ ds}$ where $C$ is the path along the helix $\\vec{r}(t)=\langle\cos(t), \sin(t), t \\rangle$ for $t=[0,2\pi]$.'] = [ '2*sqrt(2)*pi^2', '', 'You may need to use the identity $\sin^2(x)+\cos^2(x)=1$.' ] bank[ 'Evaluate the integral $\int_C{\displaystyle\\frac{x^2z}{1-y^2} \ ds}$ where $C$ is the path along the helix $\\vec{r}(t)=\langle\cos(t), \sin(t), t \\rangle$ for $t=[0,2\pi]$.'] = [ '2*sqrt(2)*pi^2', '', 'You may need to use the identity $\sin^2(x)+\cos^2(x)=1$.' ] bank['Evaluate the integral $\int_C{xy+z \ ds}$ where $C$ is the path along the helix $\\vec{r}(t)=\langle\cos(t), \sin(t), t/2 \\rangle$ for $t=[0,4\pi]$.'] = [ '2*sqrt(5)*pi^2', '', 'You may need to use the identity $\sin^2(x)+\cos^2(x)=1$ and you will need integration by parts.' ] bank['Evaluate the integral $\int_C{x^2 \ ds}$ where $C$ is the path along the helix $\\vec{r}(t)=\langle\cos(t), \sin(t), 2t \\rangle$ for $t=[0,2\pi]$.'] = [ 'pi*sqrt(5)', '', 'You may need to use the identity $\sin^2(x)+\cos^2(x)=1$ and $\cos^2(t)=1/2(\cos(2t)+1)$.' ] # split integrals intdx+intdy+intdz probtex = random.choice(bank.keys()) ans_set = bank[probtex] ans = ans_set[0] prefix = ans_set[1] hint = ans_set[2] anstex = 'The answer is %s $%s$.' % (prefix, toTEX(ans)) probtex = probtex.replace('\int', '\displaystyle\int') # Work, Circulation, Flux if type1 == 10: pass # Potential Functions if type1 == 11: subtype = random.randint(1, 2) if subtype == 1: # (2 variables) grad = partial.partial(2, 'mixed') func = 'f(x,y)' probtex = 'Given the conservative vector field $\\vec{F}=\left(%s\\right)\hat{i}+\left(%s\\right)\hat{j}$, find the potential function $f(x,y)$.' % ( toTEX(grad.fx), toTEX(grad.fy)) if subtype == 2: # (3 variables) grad = partial.partial(3, 'dummy') func = 'f(x,y,z)' probtex = 'Given the conservative vector field $\\vec{F}=\left(%s\\right)\hat{i}+\left(%s\\right)\hat{j}+\left(%s\\right)\hat{k}$, find the potential function $f(x,y,z)$.' % ( toTEX(grad.fx), toTEX(grad.fy), toTEX(grad.fz)) prefix = '$' + func + '=$' suffix = ' $+c$ ' ans = grad.f anstex = 'The answer is %s $%s$.' % (prefix, toTEX(grad.f)) hint = '' if type1 != 11: suffix = '' print probtex print ans print anstex print prefix print suffix print hint
def main(): options = sys.argv[1] # php issues # options='00101111' options = options[4:8] + options[0:4] if int(options[0:4]) == 0: options = '1' + options[1:] if int(options[4:8]) == 0: options = options[:4] + '1' + options[5:] # type 1 is functions, type 2 is derivative type pick1 = [] for i in range(4): if options[i] == '1': pick1.append(i) # makes poly/trig/trans 2x as likely as hypinv for i in range(3): if options[i] == '1': pick1.append(i) pick2 = [] for i in range(4): if options[i + 4] == '1': pick2.append(i) type1 = pick1[random.randrange(0, len(pick1))] type2 = pick2[random.randrange(0, len(pick2))] # type1=1 # type2=0 # options[0]=poly # options[1]=trig # options[2]=trans # options[3]=hypinv # options[4]=basic # options[5]=chain # options[6]=product # options[7]=implicit master_bank = {} # print options poly = {} if type1 == 0 and type2 == 0: poly['x'] = [ '1', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^2'] = [ '2*x', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^3'] = [ '3*x^2', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^4'] = [ '4*x^3', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^5'] = [ '5*x^4', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^6'] = [ '6*x^5', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^pi'] = [ 'pi*x^(pi-1)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^e'] = [ 'e*x^(e-1)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] # fraction poly['x^(1/2)'] = [ '1/2*x^(-1/2)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^(1/3)'] = [ '1/3*x^(-2/3)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^(7/3)'] = [ '7/3*x^(4/3)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^(-1/2)'] = [ '-1/2*x^(-3/2)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^(-1/3)'] = [ '-1/3*x^(-4/3)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] # 1/over poly['1/x'] = [ '-1/x^2', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['1/x^2'] = [ '-2/x^3', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['1/x^1.3'] = [ '-1.3*x^(-2.3)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^100'] = [ '100*x^99', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] # decimal poly['x^1.2'] = [ '1.2*x^(.2)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^.1'] = [ '.1*x^(-.9)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] # combination poly['x^3+x^(1/3)'] = [ '3*x^2+1/3*x^(-2/3)', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x+1/x'] = [ '1-1/x^2', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] poly['x^2+2*x+1'] = [ '2*x+2', 'Use the <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=1" target="_blank">Power rule</a> for derivatives.' ] master_bank.update(poly) trig = {} if type1 == 1 and type2 == 0: # options[1]=='1' and options[4]=='1': trig['sin(x)'] = [ 'cos(x)', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=3" target="_blank">this</a> table for trigonometric derivatives.' ] trig['cos(x)'] = [ '-sin(x)', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=3" target="_blank">this</a> table for trigonometric derivatives.' ] trig['tan(x)'] = [ 'sec(x)^2', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=3" target="_blank">this</a> table for trigonometric derivatives.' ] trig['sec(x)'] = [ 'sec(x)*tan(x)', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=3" target="_blank">this</a> table for trigonometric derivatives.' ] trig['csc(x)'] = [ '-csc(x)*cot(x)', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=3" target="_blank">this</a> table for trigonometric derivatives.' ] trig['cot(x)'] = [ '-csc(x)^2', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=3" target="_blank">this</a> table for trigonometric derivatives.' ] master_bank.update(trig) trans = {} if type1 == 2 and type2 == 0: trans = master_bank trans['e^x'] = [ 'e^x', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=4" target="_blank">this</a> rule for exponential derivatives.' ] trans['ln(x)'] = [ '1/x', 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/basicrules&page_id=4" target="_blank">this</a> rule for logarthmic derivatives.' ] master_bank.update(trans) hypinv = {} if type1 == 3 and type2 == 0: hypinv['asin(x)'] = ['1/(1-x^2)^(1/2)', ''] hypinv['acos(x)'] = ['-1/(1-x^2)^(1/2)', ''] hypinv['atan(x)'] = ['1/(1+x^2)', ''] hypinv['asec(x)'] = ['1/(x*(1-x^2)^(1/2))', ''] hypinv['acsc(x)'] = ['-1/(x*(1-x^2)^(1/2))', ''] hypinv['acot(x)'] = ['-1/(1+x^2)', ''] hypinv['sinh(x)'] = ['cosh(x)', ''] hypinv['cosh(x)'] = ['sinh(x)', ''] hypinv['tanh(x)'] = ['sech(x)^2', ''] hypinv['sech(x)'] = ['-sech(x)*tanh(x)', ''] hypinv['csch(x)'] = ['-csch(x)*coth(x)', ''] hypinv['coth(x)'] = ['-csch(x)^2', ''] master_bank.update(hypinv) # poly(poly) chain = {} if type1 == 0 and type2 == 1: chain['(3*x-1)^3'] = ['9*(3*x - 1)^2', ''] chain['(5*x-3)^10'] = ['50*(5*x - 3)^9', ''] chain['(2*x^2-7*x+1)^3'] = ['3*(4*x-7)*(2*x^2-7*x+1)^2', ''] chain['1/(3*x^2+1)'] = ['-(6*x)/(3*x^2 + 1)^2', ''] chain['2/(x^5-x^2)^3'] = ['(6*(2*x - 5*x^4))/(x^2 - x^5)^4', ''] chain['(x^2-1)^3.1'] = ['6.2*x*(x^2-1)^(2.1)', ''] # trig(trig) if type1 == 1 and type2 == 1: chain['sin(sin(x))'] = ['cos(x)*cos(sin(x))', ''] chain['sin(cos(x))'] = ['-sin(x)*cos(cos(x))', ''] chain['sin(tan(x))'] = ['sec(x)^2*cos(tan(x))', ''] chain['sin(sec(x))'] = ['sec(x)*tan(x)*cos(sec(x))', ''] chain['sin(csc(x))'] = ['-csc(x)*cot(x)*cos(csc(x))', ''] chain['sin(cot(x))'] = ['-csc(x)^2*cos(cot(x))', ''] chain['cos(cos(x))'] = ['sin(x)*sin(cos(x))', ''] chain['cos(sin(x))'] = ['-cos(x)*sin(sin(x))', ''] chain['cos(tan(x))'] = ['-sec(x)^2*sin(tan(x))', ''] chain['cos(sec(x))'] = ['-sec(x)*tan(x)*sin(sec(x))', ''] chain['cos(csc(x))'] = ['csc(x)*cot(x)*sin(csc(x))', ''] chain['cos(cot(x))'] = ['csc(x)^2*sin(cot(x))', ''] chain['tan(tan(x))'] = ['sec(x)^2*sec(tan(x))^2', ''] chain['tan(sec(x))'] = ['sec(x)*tan(x)*sec(sec(x))*tan(sec(x))', ''] chain['tan(csc(x))'] = ['csc(x)*cot(x)*csc(csc(x))*cot(csc(x))', ''] chain['tan(cot(x))'] = ['csc(x)^2*csc(cot(x))^2', ''] # ln(ln) if type1 == 2 and type2 == 1: chain['ln(ln(x))'] = ['1/(x*ln(x))', ''] chain['e^(e^x)'] = ['e^x*e^(e^x)', ''] chain['2^(2^x)'] = ['ln(2)^2*2^x*2^(2^x)', ''] # ln(poly) if options[0] == '1' and options[2] == '1' and type2 == 1: chain['ln(2*x)'] = ['1/x', ''] chain['ln(x^2)'] = ['2/x', ''] chain['ln(x^3)'] = ['3/x', ''] chain['ln(3*x^2+2*x)'] = ['(6*x+2)/(3*x^2 + 2*x)', ''] chain['ln((x-1)^2)'] = ['2/(x-1)', ''] chain['ln(1/x)'] = ['-1/x', ''] # poly(ln) chain['ln(x)^2'] = ['2*ln(x)/x', ''] chain['ln(x)^3'] = ['3*ln(x)^2/x', ''] chain['1/ln(x)'] = ['-1/(x*ln(x)^2)', ''] chain['1/ln(x)^2'] = ['-2/(x*ln(x)^3)', ''] chain['ln(x)^1.3'] = ['ln(x)^.3/x', ''] if options[1] == '1' and options[2] == '1' and type2 == 1: # ln(trig) chain['ln(sin(x))'] = ['cot(x)', ''] chain['ln(cos(x))'] = ['-tan(x)', ''] chain['e^(sin(x))'] = ['cos(x)*e^(sin(x))', ''] chain['e^(sin(x)^2)'] = ['2*sin(x)cos(x)*e^(sin(x)^2)', ''] chain['e^(cos(x))'] = ['-cos(x)*e^(cos(x))', ''] chain['2^(sin(x))'] = ['ln(2)*cos(x)*2^(sin(x))', ''] # trig(ln) chain['sin(ln(x))'] = ['cos(ln(x))/x', ''] chain['sin(e^x)'] = ['e^x*cos(e^x)', ''] chain['sin(2^x)'] = ['ln(2)*2^x*cos(2^x)', ''] if options[0] == '1' and options[1] == '1' and type2 == 1: # trig(poly) chain['sin(x+1/x)'] = ['-cos(x + 1/x)*(1/x^2 - 1)', ''] chain['sin(x^2)'] = ['2*x*2)', ''] chain['sin(x^(1/2))'] = ['-1/(2*x^(1/2)*cos(x^(1/2)', ''] chain['sin(x^3+x)'] = ['(3*x^2+1)*cos(x^3+x)', ''] chain['sin(x^4)'] = ['4*x^3*cos(x^4)', ''] chain['cos(x^2)'] = ['-2*x*sin(x^2)', ''] chain['cos(x^3)'] = ['-3*x^2*sin(x^3)', ''] chain['cos(x^4+1/x)'] = ['-(4*x^3-1/x^2)*sin(x^4+1/x)', ''] chain['tan(x+1)'] = ['sec(x+1)^2', ''] chain['sec(x^(1/2))'] = ['1/(2*x^(1/2))*sec(x^(1/2))*tan(x^(1/2))', ''] chain['csc(1-x^2)'] = ['2*x*csc(1-x^2)*cot(1-x^2)', ''] chain['cot(3*x^3)'] = ['-9*x^2*csc(3*x^3)^2', ''] # poly(trig) chain['sin(x)^2'] = ['2*x*cos(x^2)', ''] if (int(options[0:3]) == 111) and type2 == 1: # trig(trig+ln, trig+poly, ln+poly) chain['sin(ln(x)+x^2)'] = ['(1/x+2*x)*cos(ln(x)+x^2)', ''] # ln(trig+ln, trig+poly, ln+poly) chain['ln(sin(x)+x)'] = ['(cos(x)+1)/(sin(x)+x)', ''] # poly(trig+ln, trig+poly, ln+poly) chain['(3*sin(x)+ln(x))^2'] = ['2*(3*cos(x)+1/x)*(3*sin(x)+ln(x))', ''] # trig(poly(poly)) chain['sin((3*x-2)^2)'] = ['2*(3*x-2)*cos((3*x-2)^2)', ''] chain['sin((2*x+7)^3)'] = ['3*(2*x+7)^2*cos((2*x+7)^3)', ''] # ln(poly(poly)) chain['ln((3-2*x)^2)'] = ['(8*x - 12)/(2*x - 3)^2', ''] chain['ln(3-2*x)^2'] = ['(4*ln(3 - 2*x))/(2*x - 3)', ''] # 3 same chain['ln(ln(ln(x)))'] = ['1/(x*ln(ln(x))*ln(x))', ''] chain['e^(e^(e^x))'] = ['e^x*e^(e^x)*e^(e^(e^x))', ''] chain['sin(sin(sin(x)))'] = ['cos(x)*cos(sin(x))*cos(sin(sin(x)))', ''] if options[3] == '1' and type2 == 1: chain['sinh(cosh(x))'] = ['cosh(cosh(x))*sinh(x)', ''] chain['cosh(sinh(x))'] = ['sinh(sinh(x))*cosh(x)', ''] chain['sinh(sinh(x))'] = ['cosh(sinh(x))*cosh(x)', ''] chain['cosh(cosh(x))'] = ['sinh(cosh(x))*sinh(x)', ''] master_bank.update(chain) product = {} if type1 == 2 and type2 == 2: # if options[2]=='1' and options[6]=='1': # ln*ln product['ln(x)*ln(2*x)'] = ['(ln(x)+ln(2*x))/x', ''] product['ln(x^3+1)*ln(2*x)'] = [ 'ln(x^3+1)/x+(3*x^2*ln(2*x))/(x^3+1)', '' ] product['ln(3*x)*e^(2*x^3)'] = ['e^(2*x^3)*(6*x^2*ln(3*x)+1/x)', ''] product['e^x*ln(2*x)'] = ['(ln(2*x)+1/x)*e^x', ''] if type1 == 0 and type2 == 2: # if options[0]=='1' and options[6]=='1': # poly*poly product['(3*x^7+5*x^2)*(x^2+6*x^3)'] = [ '180*x^9+27*x^8+150*x^4+20*x^3', '' ] product['(x+1)*(x^4+5*x)'] = ['5*x^4+4*x^3+10*x+5', ''] product['(2*x^2+1)*(5*x^3+1)'] = ['50*x^4 + 15*x^2 + 4*x', ''] product['(1-x^2)*(2*x^5-1)'] = ['-14*x^6+10*x^4+2*x', ''] product['(2*x^2-3*x+1)*(5*x^2-4*x)'] = ['40*x^3-69*x^2+34*x-4', ''] product['(3*x^2+1)*(x+7)'] = ['9*x^2+42*x+1', ''] product['(3*x^5+4)*(x^10-5*x^2)'] = [ '-15*x^4*(5*x^2-x^10)-(10*x-10*x^9)*(3*x^5+4)', '' ] product['(x+1)*(x-1)'] = ['2*x', ''] if type1 == 1 and type2 == 2: # if options[1]=='1' and options[6]=='1': # trig*trig product['sin(x)*cos(x)'] = ['cos(x)^2 - sin(x)^2', ''] product['sin(x)*tan(x)'] = ['cos(x)*tan(x) + sin(x)*(sec(x)^2)', ''] product['sin(x)*sec(x)'] = ['tan(x)', ''] product['sin(x)*csc(x)'] = ['0', ''] product['sin(x)*cot(x)'] = ['-sin(x)', ''] product['cos(x)*tan(x)'] = ['cos(x)', ''] product['cos(x)*sec(x)'] = ['0', ''] product['cos(x)*csc(x)'] = ['tan(x)', ''] product['cos(x)*cot(x)'] = ['-cos(x)*(2+cot(x)^2)', ''] product['tan(x)*sec(x)'] = ['-(cos(x)^2 - 2)/cos(x)^3', ''] product['tan(x)*csc(x)'] = ['sin(x)/cos(x)^2', ''] product['tan(x)*cot(x)'] = ['0', ''] product['sec(x)*csc(x)'] = ['1/cos(x)^2 - 1/sin(x)^2', ''] product['sec(x)*cot(x)'] = ['-cos(x)/sin(x)^2', ''] product['csc(x)*cot(x)'] = ['(sin(x)^2 - 2)/sin(x)^3', ''] if options[0] == '1' and options[1] == '1' and type2 == 2: # if options[0]=='1' and options[1]=='1' and options[6]=='1': # trig*poly product['x*sin(x)'] = ['x*cos(x)+sin(x)', ''] product['x^2*sin(x)'] = ['x^2*cos(x)+2*x*sin(x)', ''] product['x*cos(x)'] = ['cos(x)-x*sin(x)', ''] product['x^2*cos(x)'] = ['2*x*cos(x)-x^2*sin(x)', ''] product['x*tan(x)'] = ['tan(x)+sec(x)^2', ''] product['x*sec(x)'] = ['sec(x)+x*sec(x)*tan(x)', ''] product['x*csc(x)'] = ['csc(x)-x*csc(x)*cot(x)', ''] product['x*cot(x)'] = ['cot(x)-x*csc(x)^2', ''] if options[1] == '1' and options[2] == '1' and type2 == 2: # ln*trig product['ln(x)*sin(x)'] = ['ln(x)*cos(x)+sin(x)/x', ''] product['ln(x)*cos(x)'] = ['-ln(x)*sin(x)+cos(x)/x', ''] product['e^x*sin(x)'] = ['e^x*(sin(x)+cos(x))', ''] product['e^x*cos(x)'] = ['e^x*(-sin(x)+cos(x))', ''] if options[0] == '1' and options[2] == '1' and type2 == 2: # poly*ln product['x*ln(x)'] = ['ln(x)+1', ''] product['x^2*ln(x)'] = ['2*x*ln(x)+x', ''] product['x^3*ln(x)'] = ['3*x^2*ln(x)+x^2', ''] product['x*e^x'] = ['(x+1)*e^x', ''] product['x^2*e^x'] = ['(x^2+2*x)*e^x', ''] product['x^3*e^x'] = ['(x^3+3*x^2)*e^x', ''] # poly^3 # trig^3 # ln^3 # ln^2* poly or trig # poly^2*trig or ln # trig^2* ln or poly if options[0] == '1' and options[1] == '1' and options[ 2] == '1' and type2 == 2: # poly*trig*ln product['(x+1)*ln(x)*sin(x)'] = [ 'ln(x)*sin(x)+cos(x)*ln(x)*(x+1)+(sin(x)*(x+1))/x', '' ] if options[3] == '1' and type2 == 2: product['sinh(x)*cosh(x)'] = ['cosh(x)^2+sinh(x)^2', ''] product['sinh(x)*(sinh(x)^2+cosh(x))'] = [ 'sinh(x)*(sinh(x) + 2*cosh(x)*sinh(x)) + cosh(x)*(sinh(x)^2 + cosh(x))', '' ] product['cosh(x)*(sinh(x)+2)'] = ['cosh(x)^2+sinh(x)^2+2*sinh(x)', ''] quotient = {} if type1 == 2 and type2 == 2: # if options[2]=='1' and options[6]=='1': # ln*ln quotient['\displaystyle\\frac{ln(x)}{ln(2*x)}'] = [ 'ln(2)', '(x*ln(2*x)^2)', '' ] quotient['\displaystyle\\frac{ln(x^3+1)}{ln(3*x)}'] = [ '((3*x^2*ln(3*x))/(x^3 - 1) - ln(x^3 - 1)/x)', '(ln(3*x)^2)', '' ] # quotient['\displaystyle\\frac{ln(3*x)*e^(2*x^3)}']=['exp(2*x^3)*(6*x^2*ln(3*x)+1/x)',''] # quotient['\displaystyle\\frac{e^x*ln(2*x)}']=['(ln(2*x)+1/x)*e^x',''] if type1 == 0 and type2 == 2: # if options[0]=='1' and options[6]=='1': # poly*poly quotient['\displaystyle\\frac{7*x^4 + x^3 - 3}{x^2 - 1}'] = [ '(x^2 - 1)*(28*x^3 + 3*x^2) - 2*x*(7*x^4 + x^3 - 3)', '(x^2 - 1)^2', '' ] quotient['\displaystyle\\frac{x^2 + x}{x - 1}'] = [ '(2*x + 1)*(x - 1) - x - x^2', '(x - 1)^2', '' ] quotient['\displaystyle\\frac{x}{x^2 - 1/x}'] = [ 'x^2 - 1/x - x*(2*x + 1/x^2)', '(1/x - x^2)^2', '' ] quotient['\displaystyle\\frac{x + 3}{1 - x}'] = ['4', '(x - 1)^2', ''] quotient['\displaystyle\\frac{x^4 + 2*x + 1}{1 - x^3}'] = [ '3*x^2*(x^4 + 2*x + 1) - (x^3 - 1)*(4*x^3 + 2)', '(x^3 - 1)^2', '' ] quotient['\displaystyle\\frac{x^2 + 2*x + 1}{x + 3}'] = [ '(2*x + 2)*(x + 3) - 2*x - x^2 - 1', '(x + 3)^2', '' ] if type1 == 1 and type2 == 2: # if options[1]=='1' and options[6]=='1': # trig*trig quotient['\displaystyle\\frac{cos(x)}{sin(x) - 1}'] = [ '- cos(x)^2 - sin(x)*(sin(x) - 1)', '(sin(x) - 1)^2', '' ] quotient['\displaystyle\\frac{sin(x)}{sin(x) + 1}'] = [ 'cos(x)*(sin(x) + 1) - cos(x)*sin(x)', '(sin(x) + 1)^2', '' ] quotient['\displaystyle\\frac{tan(x)}{sin(x) - cos(x)}'] = [ '- tan(x)*(cos(x) + sin(x)) - (cos(x) - sin(x))*(tan(x)^2 + 1)', '(cos(x) - sin(x))^2', '' ] quotient['\displaystyle\\frac{sin(x) - cos(x)}{cos(x) + sin(x)}'] = [ '2', '(cos(x) + sin(x))^2', '' ] if options[0] == '1' and options[1] == '1' and type2 == 2: # if options[0]=='1' and options[1]=='1' and options[6]=='1': # trig*poly quotient['\displaystyle\\frac{sin(x)}{x}'] = [ 'x*cos(x) - sin(x)', 'x^2', '' ] quotient['\displaystyle\\frac{tan(x)}{x}'] = [ 'x*sec(x)^2 - tan(x)', 'x^2', '' ] quotient['\displaystyle\\frac{cos(x)}{x^2 + 3}'] = [ '- sin(x)*(x^2 + 3) - 2*x*cos(x)', '(x^2 + 3)^2', '' ] quotient['\displaystyle\\frac{x + sin(x)}{x^2 - 1}'] = [ '(x^2 - 1)*(cos(x) + 1) - 2*x*(x + sin(x))', '(x^2 - 1)^2', '' ] quotient['\displaystyle\\frac{x - cos(x)}{x^2 + x}'] = [ '(sin(x) + 1)*(x^2 + x) - (x - cos(x))*(2*x + 1)', '(x^2 + x)^2', '' ] quotient['\displaystyle\\frac{x}{sin(x)}'] = [ 'sin(x) - x*cos(x)', 'sin(x)^2', '' ] quotient['\displaystyle\\frac{x}{x + cos(x)}'] = [ 'x + cos(x) + x*(sin(x) - 1)', '(x + cos(x))^2', '' ] # quotient['\displaystyle\\frac{x^2 }{tan(x) - x^3}']=['2*x*(tan(x) - x^3) - x^2*(- 3*x^2 + tan(x)^2 + 1)','(tan(x) - x^3)^2',''] if options[1] == '1' and options[2] == '1' and type2 == 2: # ln*trig quotient['\displaystyle\\frac{sin(x)}{e^(x) - 1}'] = [ 'cos(x)*(e^(x) - 1) - e^(x)*sin(x)', '(e^(x) - 1)^2', '' ] quotient['\displaystyle\\frac{tan(x)}{ln(x)}'] = [ 'ln(x)*(tan(x)^2 + 1) - tan(x)/x', 'ln(x)^2', '' ] quotient['\displaystyle\\frac{sin(x) + tan(x)}{e^x+ln(x)}'] = [ '(e^x + ln(x))*(sec(x)^2 + cos(x))-(e^x + 1/x)*(sin(x)+tan(x))', '(e^x + ln(x))^2', '' ] quotient['\displaystyle\\frac{ln(x)}{cos(x)}'] = [ 'cos(x)/x + ln(x)*sin(x)', 'cos(x)^2', '' ] quotient['\displaystyle\\frac{cos(x) + e^(x)}{ln(x)}'] = [ 'ln(x)*(e^(x) - sin(x)) - (cos(x) + e^(x))/x', 'ln(x)^2', '' ] if options[0] == '1' and options[2] == '1' and type2 == 2: # poly*ln quotient['\displaystyle\\frac{ln(x)}{x}'] = ['1 - ln(x)', 'x^2', ''] quotient['\displaystyle\\frac{ln(x)}{x^2 + 1}'] = [ '(x^2 + 1)/x - 2*x*ln(x)', '(x^2 + 1)^2', '' ] quotient['\displaystyle\\frac{x}{e^(x) + 1}'] = [ 'e^(x) - x*e^(x) + 1', '(e^(x) + 1)^2', '' ] quotient['\displaystyle\\frac{ln(x)}{e^(x) + ln(x)}'] = [ '(e^(x) + ln(x))/x - ln(x)*(e^(x) + 1/x)', '(e^(x) + ln(x))^2', '' ] # poly^3 # trig^3 # ln^3 # ln^2* poly or trig # poly^2*trig or ln if options[3] == '1' and type2 == 2: product['sinh(x)*cosh(x)'] = ['cosh(x)^2+sinh(x)^2', ''] product['sinh(x)*(sinh(x)^2+cosh(x))'] = [ 'sinh(x)*(sinh(x) + 2*cosh(x)*sinh(x)) + cosh(x)*(sinh(x)^2 + cosh(x))', '' ] product['cosh(x)*(sinh(x)+2)'] = ['cosh(x)^2+sinh(x)^2+2*sinh(x)', ''] master_bank.update(quotient) master_bank.update(product) # implicit={} if type2 == 3: if int(options[0:3]) == 111: implicit = partial.partial(2, 'mixed') else: if type1 == 0: # poly implicit = partial.partial(2, 'poly') if type1 == 1: # trig implicit = partial.partial(2, 'trig') if type1 == 2: # trans implicit = partial.partial(2, 'trans') if type1 == 3: # hypinv implicit = partial.partial(2, 'hypinv') # master_bank.update(implicit) # print len(master_bank) if type2 != 3: rand1 = random.randrange(0, len(master_bank)) f = master_bank.keys()[rand1] if len(master_bank[f]) == 3: ans = '(%s)/(%s)' % (master_bank[f][0], master_bank[f][1]) anstex = 'The answer is $f\'(x)=\displaystyle\\frac{%s}{%s}$' % ( toTEX(master_bank[f][0]), toTEX(master_bank[f][1])) else: ans = master_bank[f][0] anstex = 'The answer is $f\'(x)=' + toTEX(ans) + '$' probtex = 'Given the function $f(x)=' + toTEX( f) + '$, find the derivative $f\'(x)$' prefix = '$f\'(x)=$' hint = '' else: f = implicit.f ans = implicit.yx hint = '' probtex = 'Given the equation $' + frac(toTEX(f)) + '=0$, find $y\'.$' prefix = '$y\'=$' anstex = 'The answer is $y\'=' + frac(toTEX(ans)) + '$' suffix = '' if type2 == 1: hint = 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/chainrule" target="_blank">Chain Rule</a>.' elif type2 == 2 and len(master_bank[f]) == 3: hint = 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/productrule" target="_blank">Product Rule or the Quotient Rule</a>.' elif type2 == 2 and len(master_bank[f]) < 3: hint = 'Use <a class="hintlink" href="http://www.calcta.com/tutorial.php?page=derivative/productrule" target="_blank">Product Rule</a>.' print probtex print ans print anstex print prefix print suffix print hint
def test_with_many_arguments(self): template = "{0} {1} and {2} and {red} {green} and {blue}" with_four_args = partial(template.format, 1, 2, 3, 4) with_kwargs_too = partial(with_four_args, red=4, green=5, blue=6) self.assertEqual(with_kwargs_too(), "1 2 and 3 and 4 5 and 6")
def register(self, entry_name, constructor, *args, **kargs): ''' register a constructor ''' if self.is_registered(entry_name): raise ValueError('Duplicate %s' % entry_name) self.registered[entry_name] = partial(constructor, *args, **kargs)
def register(self, methodName, constructor, *args, **kargs): ''' register a constructor ''' if self.is_registered(methodName): raise ValueError(methodName) setattr(self, methodName, partial(constructor, *args, **kargs))
def register(self, entry_name, constructor, *args, **kargs): ''' register a constructor ''' if self.is_registered(entry_name): raise ValueError( 'Duplicate %s' % entry_name ) self.registered[entry_name] = partial(constructor, *args, **kargs)
def register(self, methodName, constructor, *args, **kargs): ''' register a constructor ''' if self.is_registered(methodName): raise ValueError( methodName ) setattr(self, methodName, partial(constructor, *args, **kargs) )