pplonski NSC9 commited on
Commit
9457cfd
0 Parent(s):

Duplicate from NSC9/Artificial_Calculus_Teacher

Browse files

Co-authored-by: Nick <NSC9@users.noreply.huggingface.co>

Files changed (5) hide show
  1. .gitattributes +31 -0
  2. Artificial_Calc_Teacher_v7.8.ipynb +319 -0
  3. README.md +13 -0
  4. app.py +6 -0
  5. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.npz filter=lfs diff=lfs merge=lfs -text
14
+ *.onnx filter=lfs diff=lfs merge=lfs -text
15
+ *.ot filter=lfs diff=lfs merge=lfs -text
16
+ *.parquet filter=lfs diff=lfs merge=lfs -text
17
+ *.pickle filter=lfs diff=lfs merge=lfs -text
18
+ *.pkl filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pt filter=lfs diff=lfs merge=lfs -text
21
+ *.pth filter=lfs diff=lfs merge=lfs -text
22
+ *.rar filter=lfs diff=lfs merge=lfs -text
23
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
25
+ *.tflite filter=lfs diff=lfs merge=lfs -text
26
+ *.tgz filter=lfs diff=lfs merge=lfs -text
27
+ *.wasm filter=lfs diff=lfs merge=lfs -text
28
+ *.xz filter=lfs diff=lfs merge=lfs -text
29
+ *.zip filter=lfs diff=lfs merge=lfs -text
30
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
31
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Artificial_Calc_Teacher_v7.8.ipynb ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "eefbb211",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import mercury as mr\n",
11
+ " \n",
12
+ "# set Application parameters\n",
13
+ "app = mr.App(title=\"Calculus Problem Generator\",\n",
14
+ " description=\"Generates expressions which students can apply differential and integral calculus to.\",\n",
15
+ " show_code=False,\n",
16
+ " show_prompt=False,\n",
17
+ " continuous_update=False,\n",
18
+ " static_notebook=False,\n",
19
+ " show_sidebar=False,\n",
20
+ " full_screen=True,\n",
21
+ " allow_download=False)"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 1,
27
+ "id": "c5197005",
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": [
31
+ "# changelog: hiding download button, shortening code"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "markdown",
36
+ "id": "6bdf2faf",
37
+ "metadata": {},
38
+ "source": [
39
+ "# Solve with pen and paper:"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "execution_count": 1,
45
+ "id": "108761f9",
46
+ "metadata": {
47
+ "scrolled": false
48
+ },
49
+ "outputs": [
50
+ {
51
+ "data": {
52
+ "text/latex": [
53
+ "$\\displaystyle \\frac{d}{d x} \\left(\\sqrt{x} - \\frac{3}{x^{3}}\\right) e^{x} = ?$"
54
+ ],
55
+ "text/plain": [
56
+ "Eq(Derivative((sqrt(x) - 3/x**3)*exp(x), x), ?)"
57
+ ]
58
+ },
59
+ "metadata": {},
60
+ "output_type": "display_data"
61
+ },
62
+ {
63
+ "data": {
64
+ "text/latex": [
65
+ "$\\displaystyle \\int \\left(\\sqrt{v} + e^{v}\\right)\\, dv = ?$"
66
+ ],
67
+ "text/plain": [
68
+ "Eq(Integral(sqrt(v) + exp(v), v), ?)"
69
+ ]
70
+ },
71
+ "metadata": {},
72
+ "output_type": "display_data"
73
+ },
74
+ {
75
+ "name": "stdout",
76
+ "output_type": "stream",
77
+ "text": [
78
+ "\n",
79
+ "\n",
80
+ "\n",
81
+ "\n",
82
+ "\n",
83
+ "\n"
84
+ ]
85
+ },
86
+ {
87
+ "data": {
88
+ "text/latex": [
89
+ "$\\displaystyle \\frac{d}{d x} \\left(\\sqrt{x} - \\frac{3}{x^{3}}\\right) e^{x} = \\left(\\frac{9}{x^{4}} + \\frac{1}{2 \\sqrt{x}}\\right) e^{x} + \\left(\\sqrt{x} - \\frac{3}{x^{3}}\\right) e^{x}$"
90
+ ],
91
+ "text/plain": [
92
+ "Eq(Derivative((sqrt(x) - 3/x**3)*exp(x), x), (9/x**4 + 1/(2*sqrt(x)))*exp(x) + (sqrt(x) - 3/x**3)*exp(x))"
93
+ ]
94
+ },
95
+ "metadata": {},
96
+ "output_type": "display_data"
97
+ },
98
+ {
99
+ "data": {
100
+ "text/latex": [
101
+ "$\\displaystyle \\int \\left(\\sqrt{v} + e^{v}\\right)\\, dv = \\frac{2 v^{\\frac{3}{2}}}{3} + e^{v}$"
102
+ ],
103
+ "text/plain": [
104
+ "Eq(Integral(sqrt(v) + exp(v), v), 2*v**(3/2)/3 + exp(v))"
105
+ ]
106
+ },
107
+ "metadata": {},
108
+ "output_type": "display_data"
109
+ }
110
+ ],
111
+ "source": [
112
+ "from sympy.simplify.fu import TR22,TR2i\n",
113
+ "from sympy import *\n",
114
+ "from sympy.abc import theta\n",
115
+ "import random\n",
116
+ "f = Function('f')\n",
117
+ "g = Function('g')\n",
118
+ "h = Function('h')\n",
119
+ "theta = Symbol('theta')\n",
120
+ "i = 0\n",
121
+ "dkeywords = {\"polylog\",\"Ei\",\"gamma\",\"Piecewise\",\"li\",\"erf\",\"Si\",\"Ci\",\"hyper\",\"fresnel\",\"Li\",\"expint\",\"zoo\",\n",
122
+ "\"nan\",\"oo\",\"abs\",\"re\",\"EulerGamma\", \"sinh\",\"tanh\", \"cosh\",'sign','abs','atan','csc','asin'} \n",
123
+ "ikeywords = {\"polylog\",\"Ei\",\"gamma\",\"Piecewise\", \"li\", \"erf\", \"atan\", \"Si\", \"Ci\", \"hyper\", \"fresnel\", \"Li\", \n",
124
+ "\"expint\",\"zoo\", \"nan\", \"oo\",\"EulerGamma\",\"sinh\",\"csc\",\"asin\"}\n",
125
+ "keywords2 = {\"sin\",\"cos\",\"tan\"}\n",
126
+ "def random_variable(i):\n",
127
+ " return Symbol(random.choice([i for i in ['v','t','x','z','y']]), real=True)\n",
128
+ "def random_value(i):\n",
129
+ " return random.choice([i for i in range(-10,10) if i not in [0]])\n",
130
+ "def power(a): \n",
131
+ " return random_value(i)*a**int(random_value(i)/2)\n",
132
+ "def scalar(a): \n",
133
+ " return a*random_value(i) + random_value(i)\n",
134
+ "def addSUBTR(a): \n",
135
+ " return a+random_value(i)\n",
136
+ "def dmain(a):\n",
137
+ " def random_math(a): \n",
138
+ " funs = [power,scalar,addSUBTR,power,scalar,addSUBTR,ln,exp,sin,cos,tan,sqrt] \n",
139
+ " operations = [f(a)+g(a)+h(a),\n",
140
+ " f(a)+g(a)-h(a),\n",
141
+ " f(a)+g(a)*h(a),\n",
142
+ " f(a)+g(a)/h(a),\n",
143
+ " \n",
144
+ " f(a)-g(a)+h(a),\n",
145
+ " f(a)-g(a)-h(a),\n",
146
+ " f(a)-g(a)*h(a),\n",
147
+ " f(a)-g(a)/h(a),\n",
148
+ "\n",
149
+ " f(a)*g(a)+h(a),\n",
150
+ " f(a)*g(a)-h(a),\n",
151
+ " f(a)*g(a)*h(a),\n",
152
+ " f(a)*g(a)/h(a), \n",
153
+ " \n",
154
+ " f(a)/g(a)+h(a),\n",
155
+ " f(a)/g(a)-h(a),\n",
156
+ " f(a)/g(a)*h(a),\n",
157
+ " f(a)/g(a)/h(a), \n",
158
+ "\n",
159
+ " f(a)* ( g(a)+h(a) ),\n",
160
+ " f(a)* ( g(a)-h(a) ),\n",
161
+ " f(a)/ ( g(a)+h(a) ),\n",
162
+ " f(a)/ ( g(a)-h(a) ),\n",
163
+ " \n",
164
+ " f(g(h(a))),\n",
165
+ " f(h(a))+g(a),\n",
166
+ " f(h(a))-g(a),\n",
167
+ " f(h(a))*g(a),\n",
168
+ " f(h(a))/g(a),\n",
169
+ " f(a)/g(h(a))]\n",
170
+ " operation = operations[random.randrange(0,len(operations))]\n",
171
+ " return [[[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
172
+ " [random.randrange(0,len(funs))].replace(h, i) for i in funs][random.randrange(0,len(funs))]\n",
173
+ " return random_math(a)\n",
174
+ "def imain(a):\n",
175
+ " def random_math2(a): \n",
176
+ " funs = [power,scalar,addSUBTR,power,scalar,addSUBTR,ln,exp,sin,cos,tan,sqrt] \n",
177
+ " operations = [f(g(a)),f(a)+g(a),f(a)-g(a),f(a)/g(a),f(a)*g(a)]\n",
178
+ " operation = operations[random.randrange(0,len(operations))]\n",
179
+ " return [[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
180
+ " [random.randrange(0,len(funs))]\n",
181
+ " return random_math2(a)\n",
182
+ "derror = True\n",
183
+ "def dtest():\n",
184
+ " global setup1\n",
185
+ " global derror\n",
186
+ " global practice1\n",
187
+ " a = random_variable(i)\n",
188
+ " setup1 = dmain(a)\n",
189
+ " practice1 = Derivative(setup1,a) \n",
190
+ " p1eq = TR22(Eq(practice1,practice1.doit(),evaluate=False))\n",
191
+ " if any(kw in str(setup1) for kw in keywords2):\n",
192
+ " setup1 = setup1.replace(a,theta)\n",
193
+ " practice1 = Derivative(setup1,theta) \n",
194
+ " p1eq = TR22(Eq(practice1,practice1.doit(),evaluate=False))\n",
195
+ " if p1eq.rhs != 0 and not any(kw in str(p1eq) for kw in dkeywords):\n",
196
+ " derror = False\n",
197
+ " return p1eq\n",
198
+ "while derror == True: \n",
199
+ " output1 = dtest()\n",
200
+ "ierror = True\n",
201
+ "def itest():\n",
202
+ " global ierror\n",
203
+ " global practice2\n",
204
+ " global setup2\n",
205
+ " a = random_variable(i)\n",
206
+ " setup2 = imain(a)\n",
207
+ " practice2 = Integral(setup2,a) \n",
208
+ " p2eq = TR22(Eq(practice2,practice2.doit(),evaluate=False))\n",
209
+ " if str(factor_terms(p2eq.lhs)) != str(factor_terms(p2eq.rhs)) and not any(kw in str(p2eq) for kw in ikeywords)\\\n",
210
+ " and str(p2eq.lhs) != str(-p2eq.rhs): \n",
211
+ " if any(kw in str(setup2) for kw in keywords2):\n",
212
+ " setup2 = setup2.replace(a,theta)\n",
213
+ " practice2 = Integral(setup2,theta) \n",
214
+ " p2eq = TR22(Eq(practice2,practice2.doit(),evaluate=False))\n",
215
+ " ierror = False\n",
216
+ " return p2eq\n",
217
+ "while ierror == True:\n",
218
+ " output2 = itest()\n",
219
+ "questionmark = Symbol('?')\n",
220
+ "def lhs():\n",
221
+ " return display(Eq(nsimplify(output1.lhs),questionmark),Eq(nsimplify(output2.lhs),questionmark)) \n",
222
+ "def rhs():\n",
223
+ " return display(Eq(nsimplify(output1.lhs),nsimplify(output1.rhs)),Eq(nsimplify(output2.lhs),nsimplify(output2.rhs)))\n",
224
+ "lhs()\n",
225
+ "print(\"\\n\")\n",
226
+ "print(\"\\n\")\n",
227
+ "print(\"\\n\")\n",
228
+ "rhs()"
229
+ ]
230
+ },
231
+ {
232
+ "cell_type": "markdown",
233
+ "id": "2393180e",
234
+ "metadata": {},
235
+ "source": [
236
+ "___________________________________________________________________________________________________________________\n",
237
+ "\n",
238
+ "___________________________________________________________________________________________________________________\n",
239
+ "\n",
240
+ "___________________________________________________________________________________________________________________\n",
241
+ "Refresh the webpage to generate a new problem to solve.\n",
242
+ "\n",
243
+ "**Created by GitHub.com/NSC9 - Live @ https://nsc9.github.io/ - MIT License - v7.8**\n",
244
+ "\n",
245
+ "Latest version source code: https://github.com/NSC9/Sample_of_Work/tree/Main/Artificial_Calculus_Teacher\n",
246
+ "\n",
247
+ "# Donate by sending Bitcoin (BTC) to the address: **bc1qtawr2gw52ftufzu0r3r20pnj3vmynssxs0mjl4**\n",
248
+ "\n"
249
+ ]
250
+ },
251
+ {
252
+ "cell_type": "code",
253
+ "execution_count": 4,
254
+ "id": "15c3f34f",
255
+ "metadata": {},
256
+ "outputs": [
257
+ {
258
+ "name": "stdout",
259
+ "output_type": "stream",
260
+ "text": [
261
+ "\n",
262
+ "\n",
263
+ "Differentiate: (y + 8)*exp(-y) + exp(y)\n",
264
+ "Integrate: -3/(4*z**4)\n",
265
+ "\n",
266
+ "(Plaintext expressions are for easy copy/pasting into linked calculator websites for comparing answers.)\n"
267
+ ]
268
+ }
269
+ ],
270
+ "source": [
271
+ "print(\"\\n\")\n",
272
+ "keywords3 = {\"theta\"}\n",
273
+ "if any(kw in str(nsimplify(output1.lhs)) for kw in keywords3):\n",
274
+ " print(\"Differentiate:\",str(nsimplify(output1.lhs))[11:-8])\n",
275
+ " p1 = str(nsimplify(output1.lhs))[11:-8]\n",
276
+ "else:\n",
277
+ " print(\"Differentiate:\",str(nsimplify(output1.lhs))[11:-4])\n",
278
+ " p1 = str(nsimplify(output1.lhs))[11:-4]\n",
279
+ " \n",
280
+ "if any(kw in str(nsimplify(output2.lhs)) for kw in keywords3):\n",
281
+ " print(\"Integrate:\",str(nsimplify(output2.lhs))[9:-8])\n",
282
+ " p2 = str(nsimplify(output2.lhs))[9:-8]\n",
283
+ "else:\n",
284
+ " print(\"Integrate:\",str(nsimplify(output2.lhs))[9:-4]) \n",
285
+ " p2 = str(nsimplify(output2.lhs))[9:-4]\n",
286
+ "print(\"\\n(Plaintext expressions are for easy copy/pasting into linked calculator websites for comparing answers.)\")"
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "markdown",
291
+ "id": "30b55c90",
292
+ "metadata": {},
293
+ "source": [
294
+ "https://www.derivative-calculator.net/ -- https://www.integral-calculator.com/"
295
+ ]
296
+ }
297
+ ],
298
+ "metadata": {
299
+ "kernelspec": {
300
+ "display_name": "Python 3 (ipykernel)",
301
+ "language": "python",
302
+ "name": "python3"
303
+ },
304
+ "language_info": {
305
+ "codemirror_mode": {
306
+ "name": "ipython",
307
+ "version": 3
308
+ },
309
+ "file_extension": ".py",
310
+ "mimetype": "text/x-python",
311
+ "name": "python",
312
+ "nbconvert_exporter": "python",
313
+ "pygments_lexer": "ipython3",
314
+ "version": "3.10.6"
315
+ }
316
+ },
317
+ "nbformat": 4,
318
+ "nbformat_minor": 5
319
+ }
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Calculus Problem Generator
3
+ colorFrom: blue
4
+ colorTo: purple
5
+ sdk: gradio
6
+ sdk_version: 3.1.1
7
+ app_file: app.py
8
+ pinned: false
9
+ license: mit
10
+ duplicated_from: NSC9/Artificial_Calculus_Teacher
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import os
2
+ from subprocess import Popen
3
+
4
+ command = ["mercury", "run", f"0.0.0.0:{os.environ.get('PORT', 7860)}"]
5
+ worker = Popen(command)
6
+ worker.wait()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ mercury>=2.2.6
2
+ sympy