NSC9 commited on
Commit
e8b9960
·
1 Parent(s): d42a1f3

Upload Artificial_Calc_Teacher_v2.0.ipynb

Browse files
Files changed (1) hide show
  1. Artificial_Calc_Teacher_v2.0.ipynb +230 -0
Artificial_Calc_Teacher_v2.0.ipynb ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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\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: title, removed cbrt"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 5,
28
+ "id": "108761f9",
29
+ "metadata": {
30
+ "scrolled": false
31
+ },
32
+ "outputs": [
33
+ {
34
+ "name": "stdout",
35
+ "output_type": "stream",
36
+ "text": [
37
+ "Solve\n"
38
+ ]
39
+ },
40
+ {
41
+ "data": {
42
+ "text/latex": [
43
+ "$\\displaystyle \\frac{d}{d x} \\left(x + 2\\right) \\tan{\\left(x \\right)}$"
44
+ ],
45
+ "text/plain": [
46
+ "Derivative((x + 2)*tan(x), x)"
47
+ ]
48
+ },
49
+ "metadata": {},
50
+ "output_type": "display_data"
51
+ },
52
+ {
53
+ "data": {
54
+ "text/latex": [
55
+ "$\\displaystyle \\int \\left(\\sqrt{x} + 2 x\\right)\\, dx$"
56
+ ],
57
+ "text/plain": [
58
+ "Integral(sqrt(x) + 2*x, x)"
59
+ ]
60
+ },
61
+ "metadata": {},
62
+ "output_type": "display_data"
63
+ },
64
+ {
65
+ "name": "stdout",
66
+ "output_type": "stream",
67
+ "text": [
68
+ "\n",
69
+ "\n",
70
+ "\n",
71
+ "\n",
72
+ "\n",
73
+ "\n",
74
+ "\n",
75
+ "\n",
76
+ "\n",
77
+ "\n",
78
+ "\n",
79
+ "\n",
80
+ "\n",
81
+ "\n",
82
+ "\n",
83
+ "\n",
84
+ "Solutions:\n"
85
+ ]
86
+ },
87
+ {
88
+ "data": {
89
+ "text/latex": [
90
+ "$\\displaystyle \\frac{d}{d x} \\left(x + 2\\right) \\tan{\\left(x \\right)} = \\left(x + 2\\right) \\sec^{2}{\\left(x \\right)} + \\tan{\\left(x \\right)}$"
91
+ ],
92
+ "text/plain": [
93
+ "Eq(Derivative((x + 2)*tan(x), x), (x + 2)*sec(x)**2 + tan(x))"
94
+ ]
95
+ },
96
+ "metadata": {},
97
+ "output_type": "display_data"
98
+ },
99
+ {
100
+ "data": {
101
+ "text/latex": [
102
+ "$\\displaystyle \\int \\left(\\sqrt{x} + 2 x\\right)\\, dx = \\frac{2 x^{\\frac{3}{2}}}{3} + x^{2}$"
103
+ ],
104
+ "text/plain": [
105
+ "Eq(Integral(sqrt(x) + 2*x, x), 2*x**(3/2)/3 + x**2)"
106
+ ]
107
+ },
108
+ "metadata": {},
109
+ "output_type": "display_data"
110
+ },
111
+ {
112
+ "name": "stdout",
113
+ "output_type": "stream",
114
+ "text": [
115
+ "-----------------------------------------------------------------------------------------------------------\n"
116
+ ]
117
+ }
118
+ ],
119
+ "source": [
120
+ "from sympy.simplify.fu import TR22\n",
121
+ "from sympy import sin,cos,ln,exp,tan,Function,Derivative,Eq,Integral\n",
122
+ "from sympy import factor_terms,simplify, sqrt\n",
123
+ "from sympy.abc import x\n",
124
+ "import random\n",
125
+ "f = Function('f')\n",
126
+ "g = Function('g')\n",
127
+ "h = Function('h')\n",
128
+ "def random_math(x):\n",
129
+ " allowed_values = list(range(2, 6))\n",
130
+ " random_value = random.choice(allowed_values)\n",
131
+ " random_value\n",
132
+ " def power_function(x): \n",
133
+ " return x**random_value\n",
134
+ " def scalar_function(x):\n",
135
+ " return x*random_value\n",
136
+ " def addSUBTR_function(x): \n",
137
+ " return x+random_value\n",
138
+ " funs = [sin,power_function,ln,exp,cos,tan,sqrt,\n",
139
+ " scalar_function,addSUBTR_function] \n",
140
+ " operations = [f(g(x)),f(x)+g(x),f(x)-g(x),f(x)/g(x),f(x)*g(x), f(x)/g(x)/h(x),\n",
141
+ " f(g(h(x))),f(h(x))+g(x),f(h(x))-g(x),f(h(x))/g(x),f(x)/g(h(x)),f(h(x))*g(x), f(x)*g(x)*h(x)]\n",
142
+ " operation = operations[random.randrange(0,len(operations))]\n",
143
+ " return [[[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
144
+ "[random.randrange(0,len(funs))].replace(h, i) for i in funs][random.randrange(0,len(funs))]\n",
145
+ "\n",
146
+ "def random_math2(x):\n",
147
+ " allowed_values = list(range(2, 6))\n",
148
+ " random_value = random.choice(allowed_values)\n",
149
+ " random_value\n",
150
+ " def power_function(x): \n",
151
+ " return x**random_value\n",
152
+ " def scalar_function(x):\n",
153
+ " return x*random_value\n",
154
+ " def addSUBTR_function(x): \n",
155
+ " return x+random_value\n",
156
+ " \n",
157
+ " funs = [sin,power_function,ln,exp,cos,tan,sqrt,\n",
158
+ " scalar_function,addSUBTR_function] \n",
159
+ " operations = [f(g(x)),f(x)+g(x),f(x)-g(x),f(x)/g(x),f(x)*g(x)]\n",
160
+ " operation = operations[random.randrange(0,len(operations))]\n",
161
+ " return [[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
162
+ "[random.randrange(0,len(funs))]\n",
163
+ "setup1 = random_math(x)\n",
164
+ "setup2 = random_math2(x)\n",
165
+ "practice1 = Derivative(simplify(setup1),x)\n",
166
+ "practice2 = Integral(simplify(setup2),x)\n",
167
+ "p1eq = Eq(practice1,practice1.doit(),evaluate=False)\n",
168
+ "p2eq = Eq(practice2,practice2.doit().simplify(),evaluate=False)\n",
169
+ "print(\"Solve\")\n",
170
+ "display(p1eq.lhs)\n",
171
+ "if str(factor_terms(p2eq.lhs)) != str(p2eq.rhs): \n",
172
+ " if str(p2eq).find(\"Ei\") == -1 and str(p2eq).find(\"gamma\") == -1 and str(p2eq).find(\"Piecewise\") == -1\\\n",
173
+ " and str(p2eq).find(\"li\") == -1 and str(p2eq).find(\"erf\") == -1 and str(p2eq).find(\"atan\") == -1\\\n",
174
+ " and str(p2eq).find(\"Si\") == -1 and str(p2eq).find(\"Ci\") == -1 and str(p2eq).find(\"hyper\") == -1\\\n",
175
+ " and str(p2eq).find(\"fresnel\") == -1 and str(p2eq).find(\"Li\") == -1: \n",
176
+ " display(p2eq.lhs)\n",
177
+ " else:\n",
178
+ " print(\"Error: Complex Integral\")\n",
179
+ " pass\n",
180
+ "\n",
181
+ "else:\n",
182
+ " print(\"Error: Impossible Integral\") \n",
183
+ " pass\n",
184
+ " \n",
185
+ "for i in range(0,6):\n",
186
+ " print(\"\\n\")\n",
187
+ "print(\"Solutions:\")\n",
188
+ "display(TR22(p1eq))\n",
189
+ "display(TR22(p2eq))\n",
190
+ "print(\" \")\n",
191
+ "print(\" \")"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "id": "b3f5b9fb",
197
+ "metadata": {},
198
+ "source": [
199
+ "If LaTeX display breaks, refresh the page and run again.\n",
200
+ "\n",
201
+ "Helpful resources: https://www.derivative-calculator.net/ & https://www.integral-calculator.com/ \n",
202
+ "\n",
203
+ "**Made by github.com/nsc9 - MIT License**\n",
204
+ "\n",
205
+ "Donate by sending Bitcoin (BTC) to address: **bc1qtawr2gw52ftufzu0r3r20pnj3vmynssxs0mjl4**"
206
+ ]
207
+ }
208
+ ],
209
+ "metadata": {
210
+ "kernelspec": {
211
+ "display_name": "Python 3 (ipykernel)",
212
+ "language": "python",
213
+ "name": "python3"
214
+ },
215
+ "language_info": {
216
+ "codemirror_mode": {
217
+ "name": "ipython",
218
+ "version": 3
219
+ },
220
+ "file_extension": ".py",
221
+ "mimetype": "text/x-python",
222
+ "name": "python",
223
+ "nbconvert_exporter": "python",
224
+ "pygments_lexer": "ipython3",
225
+ "version": "3.8.10"
226
+ }
227
+ },
228
+ "nbformat": 4,
229
+ "nbformat_minor": 5
230
+ }