Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit ae7295a

Browse files
committed
Merge remote-tracking branch 'origin/main' into sympy
2 parents 41e8372 + 16321c2 commit ae7295a

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

book/08/sympy.ipynb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,37 @@
409409
"cell_type": "markdown",
410410
"metadata": {},
411411
"source": [
412-
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy; Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. "
412+
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy, however; consider this example:"
413+
]
414+
},
415+
{
416+
"cell_type": "code",
417+
"execution_count": null,
418+
"metadata": {},
419+
"outputs": [
420+
{
421+
"data": {
422+
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAVCAYAAADCUymGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD3klEQVRYCd2Y0VEbMRCGL4wL8FCC6YCECmJ3QEgFCR04kyf8xjgdABVkQgeQCojpwO4gHndA/k8naWRZd8Hn9RCyM3uSVtKvvdXuSnfV09NTZc0XFxcDa8zXgFd674PKmCaTyViQx8awrwVu4N8/6vsGz7AigZ8K60TlFyvMfeJIz4Hwg67vVF/Slvyx67qai4OtVF6DYWZgAfaF91PlW4D/dZKeGPdK5SjoqvpUdQw0Uv0+yLctNXemOe9VrixTBMpdbavMLuP1AkPx544Y6HuezhUW3rwS/0jlHerYAfzK0sBnUtCFRQeFuk4hauAuNNSkuXTO5+O5fcnx8E7k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+
"text/plain": [
427+
"x⋅(x + 2⋅y)"
428+
]
429+
},
430+
"metadata": {},
431+
"output_type": "display_data"
432+
}
433+
],
434+
"source": [
435+
"x*expr"
413436
]
414437
},
415438
{
416439
"cell_type": "markdown",
417440
"metadata": {},
418441
"source": [
419-
"A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
442+
"Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
420443
]
421444
},
422445
{

book/08/sympy_stripped.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
"cell_type": "markdown",
314314
"metadata": {},
315315
"source": [
316-
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy, however:"
316+
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy, however; consider this example:"
317317
]
318318
},
319319
{
@@ -344,14 +344,7 @@
344344
"cell_type": "markdown",
345345
"metadata": {},
346346
"source": [
347-
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy; Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. "
348-
]
349-
},
350-
{
351-
"cell_type": "markdown",
352-
"metadata": {},
353-
"source": [
354-
"A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
347+
"Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
355348
]
356349
},
357350
{
@@ -516,7 +509,13 @@
516509
"\n",
517510
"Create an expression for the normal distribution function:\n",
518511
"\n",
519-
"$$\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{\\frac{(x-\\mu)^2}{2\\sigma^2}}$$"
512+
"$$\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{\\frac{(x-\\mu)^2}{2\\sigma^2}}$$\n",
513+
"\n",
514+
"First define variables with:\n",
515+
"\n",
516+
"```python\n",
517+
"sym.var('x, sigma, mu')\n",
518+
"```"
520519
]
521520
},
522521
{
@@ -525,6 +524,7 @@
525524
"metadata": {},
526525
"outputs": [],
527526
"source": [
527+
"# define variables\n",
528528
"expr = \n",
529529
"expr #displays expression"
530530
]

0 commit comments

Comments
 (0)