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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "raw",
|
5 |
+
"id": "8c69730d",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"---\n",
|
9 |
+
"title: Calculus Problem Generator\n",
|
10 |
+
"description: Generates Derivative and Integral Expressions at https://nsc9.github.io/\n",
|
11 |
+
"show-code : False\n",
|
12 |
+
"---"
|
13 |
+
]
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"cell_type": "code",
|
17 |
+
"execution_count": 1,
|
18 |
+
"id": "c5197005",
|
19 |
+
"metadata": {},
|
20 |
+
"outputs": [],
|
21 |
+
"source": [
|
22 |
+
"# changelog: bug fixes and formatting"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "markdown",
|
27 |
+
"id": "6bdf2faf",
|
28 |
+
"metadata": {},
|
29 |
+
"source": [
|
30 |
+
"# Solve with pen and paper:"
|
31 |
+
]
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"cell_type": "code",
|
35 |
+
"execution_count": 2,
|
36 |
+
"id": "108761f9",
|
37 |
+
"metadata": {
|
38 |
+
"scrolled": false
|
39 |
+
},
|
40 |
+
"outputs": [],
|
41 |
+
"source": [
|
42 |
+
"from sympy.simplify.fu import TR22,TR2i\n",
|
43 |
+
"from sympy import ln,exp,Function,Derivative,Eq,Integral,factor_terms, sqrt, Symbol,Limit\n",
|
44 |
+
"from sympy import sin,cos,tan,Rational,nsimplify\n",
|
45 |
+
"import random\n",
|
46 |
+
"f = Function('f')\n",
|
47 |
+
"g = Function('g')\n",
|
48 |
+
"h = Function('h')\n",
|
49 |
+
"theta = Symbol('theta')\n",
|
50 |
+
"i = 0\n",
|
51 |
+
"dkeywords = {\"polylog\",\"Ei\",\"gamma\",\"Piecewise\",\"li\",\"erf\",\"Si\",\"Ci\",\"hyper\",\"fresnel\",\"Li\",\"expint\",\"zoo\",\n",
|
52 |
+
"\"nan\",\"oo\",\"abs\",\"re\",\"EulerGamma\", \"sinh\",\"tanh\", \"cosh\",'sign','abs','atan','csc','asin'} \n",
|
53 |
+
"ikeywords = {\"polylog\",\"Ei\",\"gamma\",\"Piecewise\", \"li\", \"erf\", \"atan\", \"Si\", \"Ci\", \"hyper\", \"fresnel\", \"Li\", \n",
|
54 |
+
"\"expint\",\"zoo\", \"nan\", \"oo\",\"EulerGamma\",\"sinh\",\"csc\",\"asin\"}\n",
|
55 |
+
"keywords2 = {\"sin\",\"cos\",\"tan\"}\n",
|
56 |
+
"def random_variable(i):\n",
|
57 |
+
" return Symbol(random.choice([i for i in ['v','t','x','z','y']]), real=True)\n",
|
58 |
+
"def random_value(i):\n",
|
59 |
+
" return random.choice([i for i in range(-10,10) if i not in [0]])\n",
|
60 |
+
"def power(a): \n",
|
61 |
+
" return random_value(i)*a**int(random_value(i)/2)\n",
|
62 |
+
"def scalar(a): \n",
|
63 |
+
" return a*random_value(i) + random_value(i)\n",
|
64 |
+
"def addSUBTR(a): \n",
|
65 |
+
" return a+random_value(i)\n",
|
66 |
+
"def dmain(a):\n",
|
67 |
+
" def random_math(a): \n",
|
68 |
+
" funs = [power,scalar,addSUBTR,power,scalar,addSUBTR,ln,exp,sin,cos,tan,sqrt] \n",
|
69 |
+
" operations = [f(a)+g(a)+h(a),\n",
|
70 |
+
" f(a)+g(a)-h(a),\n",
|
71 |
+
" f(a)+g(a)*h(a),\n",
|
72 |
+
" f(a)+g(a)/h(a),\n",
|
73 |
+
" \n",
|
74 |
+
" f(a)-g(a)+h(a),\n",
|
75 |
+
" f(a)-g(a)-h(a),\n",
|
76 |
+
" f(a)-g(a)*h(a),\n",
|
77 |
+
" f(a)-g(a)/h(a),\n",
|
78 |
+
"\n",
|
79 |
+
" f(a)*g(a)+h(a),\n",
|
80 |
+
" f(a)*g(a)-h(a),\n",
|
81 |
+
" f(a)*g(a)*h(a),\n",
|
82 |
+
" f(a)*g(a)/h(a), \n",
|
83 |
+
" \n",
|
84 |
+
" f(a)/g(a)+h(a),\n",
|
85 |
+
" f(a)/g(a)-h(a),\n",
|
86 |
+
" f(a)/g(a)*h(a),\n",
|
87 |
+
" f(a)/g(a)/h(a), \n",
|
88 |
+
"\n",
|
89 |
+
" f(a)* ( g(a)+h(a) ),\n",
|
90 |
+
" f(a)* ( g(a)-h(a) ),\n",
|
91 |
+
" f(a)/ ( g(a)+h(a) ),\n",
|
92 |
+
" f(a)/ ( g(a)-h(a) ),\n",
|
93 |
+
" \n",
|
94 |
+
" f(g(h(a))),\n",
|
95 |
+
" f(h(a))+g(a),\n",
|
96 |
+
" f(h(a))-g(a),\n",
|
97 |
+
" f(h(a))*g(a),\n",
|
98 |
+
" f(h(a))/g(a),\n",
|
99 |
+
" f(a)/g(h(a))]\n",
|
100 |
+
" operation = operations[random.randrange(0,len(operations))]\n",
|
101 |
+
" return [[[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
|
102 |
+
" [random.randrange(0,len(funs))].replace(h, i) for i in funs][random.randrange(0,len(funs))]\n",
|
103 |
+
" return random_math(a)\n",
|
104 |
+
"def imain(a):\n",
|
105 |
+
" def random_math2(a): \n",
|
106 |
+
" funs = [power,scalar,addSUBTR,power,scalar,addSUBTR,ln,exp,sin,cos,tan,sqrt] \n",
|
107 |
+
" operations = [f(g(a)),f(a)+g(a),f(a)-g(a),f(a)/g(a),f(a)*g(a)]\n",
|
108 |
+
" operation = operations[random.randrange(0,len(operations))]\n",
|
109 |
+
" return [[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
|
110 |
+
" [random.randrange(0,len(funs))]\n",
|
111 |
+
" return random_math2(a)"
|
112 |
+
]
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"cell_type": "code",
|
116 |
+
"execution_count": 25,
|
117 |
+
"id": "5ddcf6a5",
|
118 |
+
"metadata": {
|
119 |
+
"scrolled": false
|
120 |
+
},
|
121 |
+
"outputs": [
|
122 |
+
{
|
123 |
+
"data": {
|
124 |
+
"text/latex": [
|
125 |
+
"$\\displaystyle \\frac{d}{d x} \\left(\\sqrt{x} + \\frac{4 e^{x}}{x^{3}}\\right) = ?$"
|
126 |
+
],
|
127 |
+
"text/plain": [
|
128 |
+
"Eq(Derivative(sqrt(x) + 4*exp(x)/x**3, x), ?)"
|
129 |
+
]
|
130 |
+
},
|
131 |
+
"metadata": {},
|
132 |
+
"output_type": "display_data"
|
133 |
+
},
|
134 |
+
{
|
135 |
+
"data": {
|
136 |
+
"text/latex": [
|
137 |
+
"$\\displaystyle \\int \\left(- x + \\log{\\left(x \\right)} - 9\\right)\\, dx = ?$"
|
138 |
+
],
|
139 |
+
"text/plain": [
|
140 |
+
"Eq(Integral(-x + log(x) - 9, x), ?)"
|
141 |
+
]
|
142 |
+
},
|
143 |
+
"metadata": {},
|
144 |
+
"output_type": "display_data"
|
145 |
+
}
|
146 |
+
],
|
147 |
+
"source": [
|
148 |
+
"derror = True\n",
|
149 |
+
"def dtest():\n",
|
150 |
+
" global setup1\n",
|
151 |
+
" global derror\n",
|
152 |
+
" global practice1\n",
|
153 |
+
" a = random_variable(i)\n",
|
154 |
+
" setup1 = dmain(a)\n",
|
155 |
+
" practice1 = Derivative(setup1,a) \n",
|
156 |
+
" p1eq = TR22(Eq(practice1,practice1.doit(),evaluate=False))\n",
|
157 |
+
" if any(kw in str(setup1) for kw in keywords2):\n",
|
158 |
+
" setup1 = setup1.replace(a,theta)\n",
|
159 |
+
" practice1 = Derivative(setup1,theta) \n",
|
160 |
+
" p1eq = TR22(Eq(practice1,practice1.doit(),evaluate=False))\n",
|
161 |
+
" if p1eq.rhs != 0 and not any(kw in str(p1eq) for kw in dkeywords):\n",
|
162 |
+
" derror = False\n",
|
163 |
+
" return p1eq\n",
|
164 |
+
"while derror == True: \n",
|
165 |
+
" output1 = dtest()\n",
|
166 |
+
"ierror = True\n",
|
167 |
+
"def itest():\n",
|
168 |
+
" global ierror\n",
|
169 |
+
" global practice2\n",
|
170 |
+
" global setup2\n",
|
171 |
+
" a = random_variable(i)\n",
|
172 |
+
" setup2 = imain(a)\n",
|
173 |
+
" practice2 = Integral(setup2,a) \n",
|
174 |
+
" p2eq = TR22(Eq(practice2,practice2.doit(),evaluate=False))\n",
|
175 |
+
" if str(factor_terms(p2eq.lhs)) != str(factor_terms(p2eq.rhs)) and not any(kw in str(p2eq) for kw in ikeywords)\\\n",
|
176 |
+
" and str(p2eq.lhs) != str(-p2eq.rhs): \n",
|
177 |
+
" if any(kw in str(setup2) for kw in keywords2):\n",
|
178 |
+
" setup2 = setup2.replace(a,theta)\n",
|
179 |
+
" practice2 = Integral(setup2,theta) \n",
|
180 |
+
" p2eq = TR22(Eq(practice2,practice2.doit(),evaluate=False))\n",
|
181 |
+
" ierror = False\n",
|
182 |
+
" return p2eq\n",
|
183 |
+
"while ierror == True:\n",
|
184 |
+
" output2 = itest()\n",
|
185 |
+
"questionmark = Symbol('?')\n",
|
186 |
+
"def lhs():\n",
|
187 |
+
" return display(Eq(nsimplify(output1.lhs),questionmark),Eq(nsimplify(output2.lhs),questionmark)) \n",
|
188 |
+
"def rhs():\n",
|
189 |
+
" return display(Eq(nsimplify(output1.lhs),nsimplify(output1.rhs)),Eq(nsimplify(output2.lhs),nsimplify(output2.rhs)))\n",
|
190 |
+
"lhs()"
|
191 |
+
]
|
192 |
+
},
|
193 |
+
{
|
194 |
+
"cell_type": "markdown",
|
195 |
+
"id": "2393180e",
|
196 |
+
"metadata": {},
|
197 |
+
"source": [
|
198 |
+
"___________________________________________________________________________________________________________________\n",
|
199 |
+
"If LaTeX display breaks, refresh the page. Runtime is under a second if you run the Jupyter-Notebook locally.\n",
|
200 |
+
"\n",
|
201 |
+
"**Created by GitHub.com/NSC9 - https://nsc9.github.io/ - MIT License - v7.6**\n",
|
202 |
+
"\n",
|
203 |
+
"Latest version source code: https://github.com/NSC9/Sample_of_Work/tree/Main/Artificial_Calculus_Teacher\n",
|
204 |
+
"\n",
|
205 |
+
"Donate by sending Bitcoin (BTC) to address: **bc1qtawr2gw52ftufzu0r3r20pnj3vmynssxs0mjl4**\n",
|
206 |
+
"\n"
|
207 |
+
]
|
208 |
+
},
|
209 |
+
{
|
210 |
+
"cell_type": "code",
|
211 |
+
"execution_count": 26,
|
212 |
+
"id": "15c3f34f",
|
213 |
+
"metadata": {},
|
214 |
+
"outputs": [
|
215 |
+
{
|
216 |
+
"name": "stdout",
|
217 |
+
"output_type": "stream",
|
218 |
+
"text": [
|
219 |
+
"For easy copy/paste:\n",
|
220 |
+
"Derivative(sqrt(x) + 4*exp(x)/x**3, x)\n",
|
221 |
+
"Integral(-x + log(x) - 9, x)\n"
|
222 |
+
]
|
223 |
+
}
|
224 |
+
],
|
225 |
+
"source": [
|
226 |
+
"print(\"For easy copy/paste:\")\n",
|
227 |
+
"print(nsimplify(output1.lhs))\n",
|
228 |
+
"print(nsimplify(output2.lhs))"
|
229 |
+
]
|
230 |
+
},
|
231 |
+
{
|
232 |
+
"cell_type": "markdown",
|
233 |
+
"id": "30b55c90",
|
234 |
+
"metadata": {},
|
235 |
+
"source": [
|
236 |
+
"https://www.derivative-calculator.net/\n",
|
237 |
+
"\n",
|
238 |
+
"https://www.integral-calculator.com/\n",
|
239 |
+
"___________________________________________________________________________________________________________________\n",
|
240 |
+
"\n",
|
241 |
+
"# Answers:"
|
242 |
+
]
|
243 |
+
},
|
244 |
+
{
|
245 |
+
"cell_type": "code",
|
246 |
+
"execution_count": 27,
|
247 |
+
"id": "fbec286d",
|
248 |
+
"metadata": {},
|
249 |
+
"outputs": [
|
250 |
+
{
|
251 |
+
"data": {
|
252 |
+
"text/latex": [
|
253 |
+
"$\\displaystyle \\frac{d}{d x} \\left(\\sqrt{x} + \\frac{4 e^{x}}{x^{3}}\\right) = \\frac{4 e^{x}}{x^{3}} - \\frac{12 e^{x}}{x^{4}} + \\frac{1}{2 \\sqrt{x}}$"
|
254 |
+
],
|
255 |
+
"text/plain": [
|
256 |
+
"Eq(Derivative(sqrt(x) + 4*exp(x)/x**3, x), 4*exp(x)/x**3 - 12*exp(x)/x**4 + 1/(2*sqrt(x)))"
|
257 |
+
]
|
258 |
+
},
|
259 |
+
"metadata": {},
|
260 |
+
"output_type": "display_data"
|
261 |
+
},
|
262 |
+
{
|
263 |
+
"data": {
|
264 |
+
"text/latex": [
|
265 |
+
"$\\displaystyle \\int \\left(- x + \\log{\\left(x \\right)} - 9\\right)\\, dx = - \\frac{x^{2}}{2} + x \\log{\\left(x \\right)} - 10 x$"
|
266 |
+
],
|
267 |
+
"text/plain": [
|
268 |
+
"Eq(Integral(-x + log(x) - 9, x), -x**2/2 + x*log(x) - 10*x)"
|
269 |
+
]
|
270 |
+
},
|
271 |
+
"metadata": {},
|
272 |
+
"output_type": "display_data"
|
273 |
+
}
|
274 |
+
],
|
275 |
+
"source": [
|
276 |
+
"rhs()"
|
277 |
+
]
|
278 |
+
}
|
279 |
+
],
|
280 |
+
"metadata": {
|
281 |
+
"kernelspec": {
|
282 |
+
"display_name": "Python 3 (ipykernel)",
|
283 |
+
"language": "python",
|
284 |
+
"name": "python3"
|
285 |
+
},
|
286 |
+
"language_info": {
|
287 |
+
"codemirror_mode": {
|
288 |
+
"name": "ipython",
|
289 |
+
"version": 3
|
290 |
+
},
|
291 |
+
"file_extension": ".py",
|
292 |
+
"mimetype": "text/x-python",
|
293 |
+
"name": "python",
|
294 |
+
"nbconvert_exporter": "python",
|
295 |
+
"pygments_lexer": "ipython3",
|
296 |
+
"version": "3.8.10"
|
297 |
+
}
|
298 |
+
},
|
299 |
+
"nbformat": 4,
|
300 |
+
"nbformat_minor": 5
|
301 |
+
}
|