-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from google/develop
v0.0.7
- Loading branch information
Showing
4 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import math\n", | ||
"import latexify" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"-1.0\n", | ||
"\\mathrm{solve}(a, b, c)\\triangleq \\frac{-b + \\sqrt{b^{2} - 4ac}}{2a}\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/latex": [ | ||
"$$ \\displaystyle \\mathrm{solve}(a, b, c)\\triangleq \\frac{-b + \\sqrt{b^{2} - 4ac}}{2a} $$" | ||
], | ||
"text/plain": [ | ||
"<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c803100>" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"@latexify.with_latex\n", | ||
"def solve(a, b, c):\n", | ||
" return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)\n", | ||
"\n", | ||
"print(solve(1, 4, 3))\n", | ||
"print(solve)\n", | ||
"print()\n", | ||
"solve" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/latex": [ | ||
"$$ \\displaystyle \\mathrm{sinc}(x)\\triangleq \\left\\{ \\begin{array}{ll} 1, & \\mathrm{if} \\ x=0 \\\\ \\frac{\\sin{\\left({x}\\right)}}{x}, & \\mathrm{otherwise} \\end{array} \\right. $$" | ||
], | ||
"text/plain": [ | ||
"<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c84eaf0>" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"@latexify.with_latex\n", | ||
"def sinc(x):\n", | ||
" if x == 0:\n", | ||
" return 1\n", | ||
" else:\n", | ||
" return math.sin(x) / x\n", | ||
"\n", | ||
"sinc" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/latex": [ | ||
"$$ \\displaystyle \\mathrm{fib}(x)\\triangleq \\left\\{ \\begin{array}{ll} 1, & \\mathrm{if} \\ x=0 \\\\ 1, & \\mathrm{if} \\ x=1 \\\\ \\mathrm{fib}\\left(x - 1\\right) + \\mathrm{fib}\\left(x - 2\\right), & \\mathrm{otherwise} \\end{array} \\right. $$" | ||
], | ||
"text/plain": [ | ||
"<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c85ab50>" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Elif or nested else-if are unrolled.\n", | ||
"@latexify.with_latex\n", | ||
"def fib(x):\n", | ||
" if x == 0:\n", | ||
" return 1\n", | ||
" elif x == 1:\n", | ||
" return 1\n", | ||
" else:\n", | ||
" return fib(x-1) + fib(x-2)\n", | ||
"\n", | ||
"fib" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/latex": [ | ||
"$$ \\displaystyle \\mathrm{greek}({\\alpha}, {\\beta}, {\\gamma}, {\\Omega})\\triangleq {\\alpha}{\\beta} + \\Gamma\\left({{\\gamma}}\\right) + {\\Omega} $$" | ||
], | ||
"text/plain": [ | ||
"<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c85ae20>" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Some math symbols are converted automatically.\n", | ||
"@latexify.with_latex\n", | ||
"def greek(alpha, beta, gamma, Omega):\n", | ||
" return alpha * beta + math.gamma(gamma) + Omega\n", | ||
"\n", | ||
"greek" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters