NSC9 commited on
Commit
c80632c
1 Parent(s): 3d79cbe

Delete notebook.ipynb

Browse files
Files changed (1) hide show
  1. notebook.ipynb +0 -279
notebook.ipynb DELETED
@@ -1,279 +0,0 @@
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
- "# recent change: Added useful links, Added plaintext version of expressions for easy copy/paste to a solver."
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), f(a)-g(a)*h(a),f(a)/(g(a)-h(a)), f(a)/(-g(a)+h(a)),\n",
70
- " f(a)+g(a)+h(a), f(a)-g(a)-h(a),f(a)+g(a)-h(a), f(a)-g(a)+h(a),\n",
71
- " (f(a)*g(a))/h(a), f(a)/(g(a)*h(a)),f(g(h(a))),f(h(a))+g(a),f(h(a))-g(a),\n",
72
- " f(h(a))/g(a),f(a)/g(h(a)),f(h(a))*g(a),f(a)*h(a)*g(a)]\n",
73
- " operation = operations[random.randrange(0,len(operations))]\n",
74
- " return [[[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
75
- " [random.randrange(0,len(funs))].replace(h, i) for i in funs][random.randrange(0,len(funs))]\n",
76
- " return random_math(a)\n",
77
- "def imain(a):\n",
78
- " def random_math2(a): \n",
79
- " funs = [power,scalar,addSUBTR,power,scalar,addSUBTR,ln,exp,sin,cos,tan,sqrt] \n",
80
- " operations = [f(g(a)),f(a)+g(a),f(a)-g(a),f(a)/g(a),f(a)*g(a),\n",
81
- " f(g(a))**2,2*f(a)+g(a),2*f(a)-g(a),2*f(a)/g(a),2*f(a)*g(a)]\n",
82
- " operation = operations[random.randrange(0,len(operations))]\n",
83
- " return [[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
84
- " [random.randrange(0,len(funs))]\n",
85
- " return random_math2(a)"
86
- ]
87
- },
88
- {
89
- "cell_type": "code",
90
- "execution_count": 8,
91
- "id": "5ddcf6a5",
92
- "metadata": {
93
- "scrolled": false
94
- },
95
- "outputs": [
96
- {
97
- "data": {
98
- "text/latex": [
99
- "$\\displaystyle a' = \\frac{d}{d \\theta} \\left(- 3 \\theta + \\tan{\\left(\\theta \\right)} - 14\\right)$"
100
- ],
101
- "text/plain": [
102
- "Eq(a', Derivative(-3*theta + tan(theta) - 14, theta))"
103
- ]
104
- },
105
- "metadata": {},
106
- "output_type": "display_data"
107
- },
108
- {
109
- "data": {
110
- "text/latex": [
111
- "$\\displaystyle B = \\int 3 \\log{\\left(x \\right)}\\, dx$"
112
- ],
113
- "text/plain": [
114
- "Eq(B, Integral(3*log(x), x))"
115
- ]
116
- },
117
- "metadata": {},
118
- "output_type": "display_data"
119
- }
120
- ],
121
- "source": [
122
- "derror = True\n",
123
- "def dtest():\n",
124
- " global setup1\n",
125
- " global derror\n",
126
- " global practice1\n",
127
- " a = random_variable(i)\n",
128
- " setup1 = dmain(a)\n",
129
- " practice1 = Derivative(setup1,a) \n",
130
- " p1eq = TR22(Eq(practice1,practice1.doit(),evaluate=False))\n",
131
- " if any(kw in str(setup1) for kw in keywords2):\n",
132
- " setup1 = setup1.replace(a,theta)\n",
133
- " practice1 = Derivative(setup1,theta) \n",
134
- " p1eq = TR22(Eq(practice1,practice1.doit(),evaluate=False))\n",
135
- " if p1eq.rhs != 0 and not any(kw in str(p1eq) for kw in dkeywords):\n",
136
- " derror = False\n",
137
- " return p1eq\n",
138
- "while derror == True: \n",
139
- " output1 = dtest()\n",
140
- "ierror = True\n",
141
- "def itest():\n",
142
- " global ierror\n",
143
- " global practice2\n",
144
- " global setup2\n",
145
- " a = random_variable(i)\n",
146
- " setup2 = imain(a)\n",
147
- " practice2 = Integral(setup2,a) \n",
148
- " p2eq = TR22(Eq(practice2,practice2.doit(),evaluate=False))\n",
149
- " if str(factor_terms(p2eq.lhs)) != str(factor_terms(p2eq.rhs)) and not any(kw in str(p2eq) for kw in ikeywords)\\\n",
150
- " and str(p2eq.lhs) != str(-p2eq.rhs): \n",
151
- " if any(kw in str(setup2) for kw in keywords2):\n",
152
- " setup2 = setup2.replace(a,theta)\n",
153
- " practice2 = Integral(setup2,theta) \n",
154
- " p2eq = TR22(Eq(practice2,practice2.doit(),evaluate=False))\n",
155
- " ierror = False\n",
156
- " return p2eq\n",
157
- "while ierror == True:\n",
158
- " output2 = itest()\n",
159
- "a1 = Symbol(\"a'\")\n",
160
- "B = Symbol('B')\n",
161
- "eq1 = Eq(a1,nsimplify(output1.lhs))\n",
162
- "eq2 = Eq(B,nsimplify(output2.lhs))\n",
163
- "eq3 = Eq(a1,nsimplify(output1.rhs))\n",
164
- "eq4 = Eq(B,nsimplify(output2.rhs))\n",
165
- "def lhs():\n",
166
- " display(eq1,eq2) \n",
167
- " return\n",
168
- "def rhs():\n",
169
- " return display(eq3,eq4)\n",
170
- "lhs()"
171
- ]
172
- },
173
- {
174
- "cell_type": "markdown",
175
- "id": "2393180e",
176
- "metadata": {},
177
- "source": [
178
- "___________________________________________________________________________________________________________________\n",
179
- "If LaTeX display breaks, refresh the page. Runtime is under a second if you run the Jupyter-Notebook locally.\n",
180
- "\n",
181
- "**Created by GitHub.com/NSC9 - https://nsc9.github.io/ - MIT License - v7.5**\n",
182
- "\n",
183
- "Latest version source code: https://github.com/NSC9/Sample_of_Work/tree/Main/Artificial_Calculus_Teacher\n",
184
- "\n",
185
- "Donate by sending Bitcoin (BTC) to address: **bc1qtawr2gw52ftufzu0r3r20pnj3vmynssxs0mjl4**\n",
186
- "\n"
187
- ]
188
- },
189
- {
190
- "cell_type": "code",
191
- "execution_count": 9,
192
- "id": "15c3f34f",
193
- "metadata": {},
194
- "outputs": [
195
- {
196
- "name": "stdout",
197
- "output_type": "stream",
198
- "text": [
199
- "Derivative(-3*theta + tan(theta) - 14, theta)\n",
200
- "Integral(3*log(x), x)\n"
201
- ]
202
- }
203
- ],
204
- "source": [
205
- "print(eq1.rhs)\n",
206
- "print(eq2.rhs)"
207
- ]
208
- },
209
- {
210
- "cell_type": "markdown",
211
- "id": "30b55c90",
212
- "metadata": {},
213
- "source": [
214
- "https://www.derivative-calculator.net/\n",
215
- "\n",
216
- "https://www.integral-calculator.com/\n",
217
- "___________________________________________________________________________________________________________________\n",
218
- "\n",
219
- "# Answers:"
220
- ]
221
- },
222
- {
223
- "cell_type": "code",
224
- "execution_count": 10,
225
- "id": "fbec286d",
226
- "metadata": {},
227
- "outputs": [
228
- {
229
- "data": {
230
- "text/latex": [
231
- "$\\displaystyle a' = \\sec^{2}{\\left(\\theta \\right)} - 3$"
232
- ],
233
- "text/plain": [
234
- "Eq(a', sec(theta)**2 - 3)"
235
- ]
236
- },
237
- "metadata": {},
238
- "output_type": "display_data"
239
- },
240
- {
241
- "data": {
242
- "text/latex": [
243
- "$\\displaystyle B = 3 x \\log{\\left(x \\right)} - 3 x$"
244
- ],
245
- "text/plain": [
246
- "Eq(B, 3*x*log(x) - 3*x)"
247
- ]
248
- },
249
- "metadata": {},
250
- "output_type": "display_data"
251
- }
252
- ],
253
- "source": [
254
- "rhs()"
255
- ]
256
- }
257
- ],
258
- "metadata": {
259
- "kernelspec": {
260
- "display_name": "Python 3 (ipykernel)",
261
- "language": "python",
262
- "name": "python3"
263
- },
264
- "language_info": {
265
- "codemirror_mode": {
266
- "name": "ipython",
267
- "version": 3
268
- },
269
- "file_extension": ".py",
270
- "mimetype": "text/x-python",
271
- "name": "python",
272
- "nbconvert_exporter": "python",
273
- "pygments_lexer": "ipython3",
274
- "version": "3.8.10"
275
- }
276
- },
277
- "nbformat": 4,
278
- "nbformat_minor": 5
279
- }