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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "raw",
|
| 5 |
+
"id": "8c69730d",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"---\n",
|
| 9 |
+
"title: Artificial Calculus Teacher\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: removes custom_ln cause i don't like it"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"cell_type": "code",
|
| 27 |
+
"execution_count": 2,
|
| 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} x^{3} \\tan{\\left(x \\right)}$"
|
| 44 |
+
],
|
| 45 |
+
"text/plain": [
|
| 46 |
+
"Derivative(x**3*tan(x), x)"
|
| 47 |
+
]
|
| 48 |
+
},
|
| 49 |
+
"metadata": {},
|
| 50 |
+
"output_type": "display_data"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"data": {
|
| 54 |
+
"text/latex": [
|
| 55 |
+
"$\\displaystyle \\int \\left(\\sqrt[3]{x} - e^{x}\\right)\\, dx$"
|
| 56 |
+
],
|
| 57 |
+
"text/plain": [
|
| 58 |
+
"Integral(x**(1/3) - exp(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} x^{3} \\tan{\\left(x \\right)} = x^{3} \\sec^{2}{\\left(x \\right)} + 3 x^{2} \\tan{\\left(x \\right)}$"
|
| 91 |
+
],
|
| 92 |
+
"text/plain": [
|
| 93 |
+
"Eq(Derivative(x**3*tan(x), x), x**3*sec(x)**2 + 3*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[3]{x} - e^{x}\\right)\\, dx = \\frac{3 x^{\\frac{4}{3}}}{4} - e^{x}$"
|
| 103 |
+
],
|
| 104 |
+
"text/plain": [
|
| 105 |
+
"Eq(Integral(x**(1/3) - exp(x), x), 3*x**(4/3)/4 - exp(x))"
|
| 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,Rational\n",
|
| 122 |
+
"from sympy import factor_terms,simplify, sqrt, cbrt\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,cbrt,\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 |
+
" funs = [sin,power_function,ln,exp,cos,tan,sqrt,cbrt,\n",
|
| 157 |
+
" scalar_function,addSUBTR_function] \n",
|
| 158 |
+
" operations = [f(g(x)),f(x)+g(x),f(x)-g(x),f(x)/g(x),f(x)*g(x)]\n",
|
| 159 |
+
" operation = operations[random.randrange(0,len(operations))]\n",
|
| 160 |
+
" return [[operation.replace(f, i) for i in funs][random.randrange(0,len(funs))].replace(g, i) for i in funs]\\\n",
|
| 161 |
+
"[random.randrange(0,len(funs))]\n",
|
| 162 |
+
"setup1 = random_math(x)\n",
|
| 163 |
+
"setup2 = random_math2(x)\n",
|
| 164 |
+
"practice1 = Derivative(simplify(setup1),x)\n",
|
| 165 |
+
"practice2 = Integral(simplify(setup2),x)\n",
|
| 166 |
+
"p1eq = Eq(practice1,practice1.doit(),evaluate=False)\n",
|
| 167 |
+
"p2eq = Eq(practice2,practice2.doit().simplify(),evaluate=False)\n",
|
| 168 |
+
"print(\"Solve\")\n",
|
| 169 |
+
"display(p1eq.lhs)\n",
|
| 170 |
+
"if str(factor_terms(p2eq.lhs)) != str(p2eq.rhs): \n",
|
| 171 |
+
" if str(p2eq).find(\"Ei\") == -1 and str(p2eq).find(\"gamma\") == -1 and str(p2eq).find(\"Piecewise\") == -1\\\n",
|
| 172 |
+
" and str(p2eq).find(\"li\") == -1 and str(p2eq).find(\"erf\") == -1 and str(p2eq).find(\"atan\") == -1\\\n",
|
| 173 |
+
" and str(p2eq).find(\"Si\") == -1 and str(p2eq).find(\"Ci\") == -1 and str(p2eq).find(\"hyper\") == -1\\\n",
|
| 174 |
+
" and str(p2eq).find(\"fresnel\") == -1 and str(p2eq).find(\"Li\") == -1: \n",
|
| 175 |
+
" display(p2eq.lhs)\n",
|
| 176 |
+
" else:\n",
|
| 177 |
+
" print(\"Error: Complex Integral\")\n",
|
| 178 |
+
" pass\n",
|
| 179 |
+
"\n",
|
| 180 |
+
"else:\n",
|
| 181 |
+
" print(\"Error: Impossible Integral\") \n",
|
| 182 |
+
" pass\n",
|
| 183 |
+
" \n",
|
| 184 |
+
"for i in range(0,8):\n",
|
| 185 |
+
" print(\"\\n\")\n",
|
| 186 |
+
"print(\"Solutions:\")\n",
|
| 187 |
+
"display(TR22(p1eq))\n",
|
| 188 |
+
"display(TR22(p2eq))\n",
|
| 189 |
+
"print(\"-----------------------------------------------------------------------------------------------------------\")"
|
| 190 |
+
]
|
| 191 |
+
},
|
| 192 |
+
{
|
| 193 |
+
"cell_type": "markdown",
|
| 194 |
+
"id": "b3f5b9fb",
|
| 195 |
+
"metadata": {},
|
| 196 |
+
"source": [
|
| 197 |
+
"If LaTeX display breaks, refresh the page and run again.\n",
|
| 198 |
+
"\n",
|
| 199 |
+
"Helpful resources: https://www.derivative-calculator.net/ & https://www.integral-calculator.com/ \n",
|
| 200 |
+
"\n",
|
| 201 |
+
"**Made by github.com/nsc9 - MIT License**\n",
|
| 202 |
+
"\n",
|
| 203 |
+
"Donate by sending Bitcoin (BTC) to address: **bc1qtawr2gw52ftufzu0r3r20pnj3vmynssxs0mjl4**"
|
| 204 |
+
]
|
| 205 |
+
}
|
| 206 |
+
],
|
| 207 |
+
"metadata": {
|
| 208 |
+
"kernelspec": {
|
| 209 |
+
"display_name": "Python 3 (ipykernel)",
|
| 210 |
+
"language": "python",
|
| 211 |
+
"name": "python3"
|
| 212 |
+
},
|
| 213 |
+
"language_info": {
|
| 214 |
+
"codemirror_mode": {
|
| 215 |
+
"name": "ipython",
|
| 216 |
+
"version": 3
|
| 217 |
+
},
|
| 218 |
+
"file_extension": ".py",
|
| 219 |
+
"mimetype": "text/x-python",
|
| 220 |
+
"name": "python",
|
| 221 |
+
"nbconvert_exporter": "python",
|
| 222 |
+
"pygments_lexer": "ipython3",
|
| 223 |
+
"version": "3.8.10"
|
| 224 |
+
}
|
| 225 |
+
},
|
| 226 |
+
"nbformat": 4,
|
| 227 |
+
"nbformat_minor": 5
|
| 228 |
+
}
|