{ "metadata": { "kernelspec": { "name": "python", "display_name": "Python (Pyodide)", "language": "python" }, "language_info": { "codemirror_mode": { "name": "python", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8" } }, "nbformat_minor": 4, "nbformat": 4, "cells": [ { "cell_type": "code", "source": "import micropip\n\n# Manually install deps as pyodide doesn't support llvmlite\nfor pkg in (\n \"mpmath\",\n \"numpy<1.27\",\n \"palettable\",\n \"Pillow\",\n \"pint\",\n \"python-dateutil\",\n \"requests\",\n \"setuptools\",\n \"sympy<1.13\",\n \"Mathics-Scanner==1.3.1\",\n # Optional\n \"ipywidgets\",\n \"lxml\",\n \"pyocr\",\n \"scikit-image\",\n \"unidecode\",\n \"wordcloud\",\n):\n print(\"Installing\", pkg)\n await micropip.install(pkg)\n\nawait micropip.install(\"Mathics3==7.0.0\", deps=False)\nawait micropip.install(\"pymathics-graph==7.0.0\")\n\nfrom io import BytesIO\nimport json\nimport math\nfrom matplotlib import pyplot\nimport networkx as nx\nimport random\nfrom typing import Callable\n\nfrom mathics.core.atoms import SymbolString\nfrom mathics.core.expression import BoxError, Expression\nfrom mathics.core.symbols import Symbol\nfrom mathics.core.systemsymbols import (\n SymbolCompiledFunction,\n SymbolFullForm,\n SymbolGraphics,\n SymbolGraphics3D,\n SymbolInputForm,\n SymbolMathMLForm,\n SymbolOutputForm,\n SymbolStandardForm,\n SymbolTeXForm,\n)\nfrom mathics.session import get_settings_value\nfrom mathics.core.definitions import Definitions, autoload_files\nfrom mathics.core.evaluation import Evaluation, Output\nfrom mathics.core.load_builtin import import_and_load_builtins\nfrom mathics.core.definitions import Definitions\nfrom mathics.core.evaluation import Message, Result\nfrom mathics.settings import TIMEOUT, default_pymathics_modules\n\n# From mathics-django\n\nPyMathicsGraph = Symbol(\"Pymathics`Graph\")\n\nFORM_TO_FORMAT = {\n \"System`MathMLForm\": \"xml\",\n \"System`TeXForm\": \"tex\",\n \"System`FullForm\": \"text\",\n \"System`OutputForm\": \"text\",\n}\n\n\ndef format_output(obj, expr, format=None):\n \"\"\"\n Handle unformatted output using the *specific* capabilities of mathics-django.\n\n evaluation.py format_output() from which this was derived is similar but\n it can't make use of a front-ends specific capabilities.\n \"\"\"\n\n def eval_boxes(result, fn: Callable, obj, **options):\n options[\"evaluation\"] = obj\n try:\n boxes = fn(**options)\n except BoxError:\n boxes = None\n if not hasattr(obj, \"seen_box_error\"):\n obj.seen_box_error = True\n obj.message(\n \"General\",\n \"notboxes\",\n Expression(SymbolFullForm, result).evaluate(obj),\n )\n\n return boxes\n\n if format is None:\n format = obj.format\n\n if isinstance(format, dict):\n return dict((k, obj.format_output(expr, f)) for k, f in format.items())\n\n # For some expressions, we want formatting to be different.\n # In particular for FullForm output, we don't want MathML, we want\n # plain-ol' text so we can cut and paste that.\n\n expr_type = expr.get_head_name()\n expr_head = expr.get_head()\n if expr_head in (SymbolMathMLForm, SymbolTeXForm):\n # For these forms, we strip off the outer \"Form\" part\n format = FORM_TO_FORMAT[expr_type]\n elements = expr.get_elements()\n if len(elements) == 1:\n expr = elements[0]\n\n if expr_head in (SymbolFullForm, SymbolOutputForm):\n result = expr.elements[0].format(obj, expr_type)\n return result.boxes_to_text()\n elif expr_head is SymbolGraphics:\n result = Expression(SymbolStandardForm, expr).format(\n obj, SymbolMathMLForm\n )\n\n # This part was derived from and the same as evaluation.py format_output.\n\n use_quotes = get_settings_value(obj.definitions, \"Settings`$QuotedStrings\")\n\n if format == \"text\":\n result = expr.format(obj, SymbolOutputForm)\n result = eval_boxes(result, result.boxes_to_text, obj)\n\n if use_quotes:\n result = '\"' + result + '\"'\n\n return result\n elif format == \"xml\":\n result = Expression(SymbolStandardForm, expr).format(\n obj, SymbolMathMLForm\n )\n elif format == \"tex\":\n result = Expression(SymbolStandardForm, expr).format(\n obj, SymbolTeXForm\n )\n elif format == \"unformatted\":\n if expr_head is PyMathicsGraph and hasattr(expr, \"G\"):\n return format_graph(expr.G)\n if expr_head is SymbolCompiledFunction:\n result = expr.format(obj, SymbolOutputForm)\n elif expr_head is SymbolString:\n result = expr.format(obj, SymbolInputForm)\n result = result.boxes_to_text()\n\n if not use_quotes:\n # Substring without the quotes\n result = result[1:-1]\n\n return result\n elif expr_head is SymbolGraphics3D:\n form_expr = Expression(SymbolStandardForm, expr)\n result = form_expr.format(obj, SymbolStandardForm)\n return eval_boxes(result, result.boxes_to_json, obj)\n elif expr_head is SymbolGraphics:\n form_expr = Expression(SymbolStandardForm, expr)\n result = form_expr.format(obj, SymbolStandardForm)\n return eval_boxes(result, result.boxes_to_svg, obj)\n else:\n result = Expression(SymbolStandardForm, expr).format(\n obj, SymbolTeXForm\n )\n return (\n r\"\\[\" + eval_boxes(result, result.boxes_to_text, obj) + r\"\\]\"\n )\n else:\n raise ValueError\n\n if result is None:\n return f\"Error in evaluating {expr}\"\n return eval_boxes(result, result.boxes_to_text, obj)\n\n\ncached_pair = None\n\n\ndef hierarchy_pos(\n G, root=None, width=1.0, vert_gap=0.2, vert_loc=0, leaf_vs_root_factor=0.5\n):\n \"\"\"Position nodes in tree layout. The root is at the top.\n\n Based on Joel's answer at https://stackoverflow.com/a/29597209/2966723,\n but with some modifications.\n\n There are two basic approaches we think of to allocate the horizontal\n location of a node.\n\n - Top down: we allocate horizontal space to a node. Then its ``k``\n descendants split up that horizontal space equally. This tends to result\n in overlapping nodes when some have many descendants.\n - Bottom up: we allocate horizontal space to each leaf node. A node at a\n higher level gets the entire space allocated to its descendant leaves.\n Based on this, leaf nodes at higher levels get the same space as leaf\n nodes very deep in the tree.\n\n We use use both of these approaches simultaneously with ``leaf_vs_root_factor``\n determining how much of the horizontal space is based on the bottom up\n or top down approaches. ``0`` gives pure bottom up, while 1 gives pure top\n down.\n\n From EoN (Epidemics on Networks): a fast, flexible Python package\n for simulation, analytic approximation, and analysis of epidemics\n on networks\n https://joss.theoj.org/papers/10.21105/joss.01731\n\n :Arguments:\n\n Parameters\n ----------\n G : NetworkX graph or list of nodes\n A position will be assigned to every node in G.\n The graph must be a tree.\n\n root : the root node of the tree\n\n - if the tree is directed and this is not given, the root will be found and used\n - if the tree is directed and this is given, then the positions will be\n just for the descendants of this node.\n - if the tree is undirected and not given, then a random choice will be used.\n\n width : horizontal space allocated for this branch - avoids overlap with other branches\n\n vert_gap : gap between levels of hierarchy\n\n vert_loc : vertical location of root\n\n leaf_vs_root_factor : used in calculating the _x_ coordinate of a leaf\n\n xcenter : horizontal location of root\n\n Examples\n --------\n >>> G = nx.binomial_tree(3)\n >>> nx.draw(G, pos=nx.hierarchy_layout(G, root=0))\n\n As the number of nodes gets large, the node size and node labels\n may need to be adjusted. The following shows how the minimum\n separation between nodes can be used to adjust node sizes.\n\n >>> G = nx.full_rary_tree(2, 127)\n >>> pos, min_sep = nx.hierarchy_layout_with_min_sep(G, root=0)\n >>> nx.draw(G, pos=pos, node_size=min_sep * 1500)\n\n Also see the NetworkX drawing examples at\n https://networkx.org/documentation/latest/auto_examples/index.html\n\n \"\"\"\n if not nx.is_tree(G):\n raise TypeError(\n \"cannot use hierarchy_pos on a graph that is not a tree\"\n )\n\n global cached_pair\n if cached_pair is not None:\n return cached_pair\n\n # These get swapped if tree edge directions point to the root.\n descendants = nx.descendants\n out_degree = G.out_degree if hasattr(G, \"out_degree\") else G.degree\n neighbors = G.neighbors\n\n if root is None:\n if isinstance(G, nx.DiGraph):\n zero_outs = [n for n in G.out_degree() if n[1] == 0]\n if len(zero_outs) == 1 and len(G) > 2:\n # We unequivocally have a directed that points from leave to the root.\n # The case where we have a one or two node graph is ambiguous.\n root = list(nx.topological_sort(G))[-1]\n # Swap motion functions\n descendants = nx.ancestors\n out_degree = G.in_degree\n neighbors = G.predecessors\n else:\n root = next(\n iter(nx.topological_sort(G))\n ) # allows back compatibility with nx version 1.11\n # root = next(nx.topological_sort(G))\n else:\n root = random.choice(list(G.nodes))\n\n def _hierarchy_pos(\n G,\n root,\n leftmost,\n width,\n leafdx=0.2,\n vert_gap=0.2,\n vert_loc=0,\n xcenter=0.5,\n rootpos=None,\n leafpos=None,\n parent=None,\n ):\n \"\"\"\n see hierarchy_pos docstring for most arguments\n\n pos: a dict saying where all nodes go if they have been assigned\n parent: parent of this branch. - only affects it if non-directed\n\n \"\"\"\n\n if rootpos is None:\n rootpos = {root: (xcenter, vert_loc)}\n else:\n rootpos[root] = (xcenter, vert_loc)\n if leafpos is None:\n leafpos = {}\n\n children = list(neighbors(root))\n leaf_count = 0\n if not isinstance(G, nx.DiGraph) and parent is not None:\n children.remove(parent)\n if len(children) != 0:\n rootdx = width / len(children)\n nextx = xcenter - width / 2 - rootdx / 2\n for child in children:\n nextx += rootdx\n rootpos, leafpos, newleaves = _hierarchy_pos(\n G,\n child,\n leftmost + leaf_count * leafdx,\n width=rootdx,\n leafdx=leafdx,\n vert_gap=vert_gap,\n vert_loc=vert_loc - vert_gap,\n xcenter=nextx,\n rootpos=rootpos,\n leafpos=leafpos,\n parent=root,\n )\n leaf_count += newleaves\n\n leftmostchild = min(\n (x for x, y in [leafpos[child] for child in children])\n )\n rightmostchild = max(\n (x for x, y in [leafpos[child] for child in children])\n )\n leafpos[root] = ((leftmostchild + rightmostchild) / 2, vert_loc)\n else:\n leaf_count = 1\n leafpos[root] = (leftmost, vert_loc)\n # pos[root] = (leftmost + (leaf_count-1)*dx/2., vert_loc)\n # print(leaf_count)\n return rootpos, leafpos, leaf_count\n\n xcenter = width / 2.0\n if isinstance(G, nx.DiGraph):\n leafcount = len(\n [node for node in descendants(G, root) if out_degree(node) == 0]\n )\n elif isinstance(G, nx.Graph):\n leafcount = len(\n [\n node\n for node in nx.node_connected_component(G, root)\n if G.degree(node) == 1 and node != root\n ]\n )\n\n rootpos, leafpos, leaf_count = _hierarchy_pos(\n G,\n root,\n 0,\n width,\n leafdx=width * 1.0 / leafcount,\n vert_gap=vert_gap,\n vert_loc=vert_loc,\n xcenter=xcenter,\n )\n pos = {}\n for node in rootpos:\n pos[node] = (\n leaf_vs_root_factor * leafpos[node][0]\n + (1 - leaf_vs_root_factor) * rootpos[node][0],\n leafpos[node][1],\n )\n # pos = {node:(leaf_vs_root_factor*x1+(1-leaf_vs_root_factor)*x2, y1) for ((x1,y1), (x2,y2)) in (leafpos[node], rootpos[node]) for node in rootpos}\n xmax = max(x for x, y in pos.values())\n y_list = {}\n for node in pos:\n x, y = pos[node] = (pos[node][0] * width / xmax, pos[node][1])\n y_list[y] = y_list.get(y, set([]))\n y_list[y].add(x)\n\n min_sep = xmax\n for y in y_list.keys():\n x_list = sorted(y_list[y])\n n = len(x_list) - 1\n if n <= 0:\n continue\n min_sep = min(\n [x_list[i + 1] - x_list[i] for i in range(n)] + [min_sep]\n )\n cached_pair = pos, min_sep\n return cached_pair\n\n\nnode_size = 300 # this is networkx's default size\n\n\ndef tree_layout(G):\n global node_size\n root = G.root if hasattr(G, \"root\") else None\n pos, min_sep = hierarchy_pos(G, root=root)\n node_size = min_sep * 2000\n return pos\n\n\ndef spiral_equidistant_layout(G, *args, **kwargs):\n return nx.spiral_layout(G, equidistant=True, *args, **kwargs)\n\n\nNETWORKX_LAYOUTS = {\n \"circular\": nx.circular_layout,\n \"kamada_kawai\": nx.kamada_kawai_layout,\n \"multipartite\": nx.multipartite_layout,\n \"planar\": nx.planar_layout,\n \"random\": nx.random_layout,\n \"shell\": nx.shell_layout,\n \"spectral\": nx.spectral_layout,\n \"spiral\": nx.spiral_layout,\n \"spiral_equidistant\": spiral_equidistant_layout,\n \"spring\": nx.spring_layout,\n \"tree\": tree_layout,\n}\n\nLAYOUT_DENSITY_EXPONENT = {\n \"circular\": 0.9,\n \"spiral_equidistant\": 0.7,\n \"spiral\": 0.6,\n}\n\n\ndef clamp(value, min=-math.inf, max=math.inf):\n if value <= min:\n return min\n if value >= max:\n return max\n return value\n\n\nDEFAULT_NODE_SIZE = 300.0\nDEFAULT_POINT_SIZE = 16\n\n\ndef harmonize_parameters(G, draw_options: dict):\n global node_size\n graph_layout = G.graph_layout if hasattr(G, \"graph_layout\") else \"\"\n\n if graph_layout == \"tree\":\n # Call this to compute node_size. Cache the\n # results\n tree_layout(G)\n draw_options[\"node_size\"] = node_size\n elif graph_layout in [\"circular\", \"spiral\", \"spiral_equidistant\"]:\n exponent = LAYOUT_DENSITY_EXPONENT[graph_layout]\n node_size = draw_options[\"node_size\"] = (2 * DEFAULT_NODE_SIZE) / (\n len(G) + 1\n ) ** exponent\n # print(\"XX\", node_size, exponent)\n\n if draw_options.get(\"with_labels\", False):\n draw_options[\"edgecolors\"] = draw_options.get(\"edgecolors\", \"black\")\n draw_options[\"node_color\"] = draw_options.get(\"node_color\", \"white\")\n\n if \"width\" not in draw_options:\n width = clamp(node_size / DEFAULT_NODE_SIZE, min=0.15)\n draw_options[\"width\"] = width\n\n if \"font_size\" not in draw_options:\n # FIXME: should also take into consideration max width of label.\n font_size = clamp(\n int((node_size * DEFAULT_POINT_SIZE) / DEFAULT_NODE_SIZE),\n min=1,\n max=18,\n )\n draw_options[\"font_size\"] = font_size\n\n\ndef format_graph(G) -> str:\n \"\"\"\n Format a networkx graph using nx.draw (using matplotlib) and\n return a SVG string that encodes the graph.\n \"\"\"\n\n global node_size\n global cached_pair\n\n # Make sure we close any previous graph before starting to create\n # new graph.\n pyplot.close()\n\n pyplot.switch_backend(\"AGG\")\n cached_pair = None\n\n graph_layout = G.graph_layout if hasattr(G, \"graph_layout\") else None\n node_shape = G.node_shape if hasattr(G, \"node_shape\") else \"o\"\n\n node_size = DEFAULT_NODE_SIZE\n draw_options = {\n \"node_size\": node_size,\n \"node_shape\": node_shape,\n # \"with_labels\": vertex_labels # Set below\n # \"font_size\": 12, # Harmonized\n # \"node_color\": \"white\", # Set below\n # \"edgecolors\": \"black\", # Set below\n # \"width\": 5, # Marmonized\n }\n\n vertex_labels = G.vertex_labels if hasattr(G, \"vertex_labels\") else False\n if vertex_labels:\n draw_options[\"with_labels\"] = bool(vertex_labels)\n\n if hasattr(G, \"title\") and G.title:\n fig, ax = pyplot.subplots() # Create a figure and an axes\n ax.set_title(G.title)\n\n layout_fn = None\n if graph_layout:\n if not isinstance(graph_layout, str):\n graph_layout = graph_layout.get_string_value()\n layout_fn = NETWORKX_LAYOUTS.get(graph_layout, None)\n if graph_layout in [\"circular\", \"spiral\", \"spiral_equidistant\"]:\n pyplot.axes().set_aspect(\"equal\")\n\n harmonize_parameters(G, draw_options)\n\n if layout_fn:\n nx.draw(G, pos=layout_fn(G), **draw_options)\n else:\n nx.draw_shell(G, **draw_options)\n\n # pyplot.tight_layout()\n svg_graph_xml = get_graph()\n svg_str = svg_graph_xml[svg_graph_xml.find(\" str:\n \"\"\"\n Retrieves SVG XML from what has already been stored the matplotlib buffer\n pyplot. Return the XML SVG string.\n \"\"\"\n\n buffer = BytesIO()\n pyplot.savefig(buffer, format=\"svg\")\n buffer.seek(0)\n graph_svg = buffer.getvalue()\n buffer.close()\n\n # TODO: In the future if probably want to base64 encode.\n # Use: base64.b64encode(some piece of image_svg)\n return graph_svg.decode(\"utf-8\")\n\n\nimport_and_load_builtins()\n\ndefinitions = Definitions(add_builtin=True)\n# We set the formatter to \"unformatted\" so that we can use\n# our own custom formatter that understand better how to format\n# in the context of mathics-django.\n# Previously, one specific format, like \"xml\" had to fit all.\nevaluation = Evaluation(definitions, format=\"unformatted\")\nevaluation.format_output = lambda expr, format: format_output(\n evaluation, expr, format\n)\n\n\nfrom IPython.display import HTML, Math\n\n\ndef eval_mathics(query):\n data = evaluation.parse_evaluate(query).get_data()\n result = data[\"result\"].strip()\n if result.startswith(\"\", \"\")\n result = result.replace(\"\", \"\")\n return HTML(result)\n if data[\"form\"] == \"TeXForm\":\n return Math(result)\n if result.startswith(r\"\\[\"):\n result = result.replace(r\"\\[\", \"\")\n result = result.replace(r\"\\]\", \"\")\n return Math(result)\n if result.startswith('{\"elements\":'):\n return json.loads(result)\n return result\n\n\nprint(eval_mathics('LoadModule[\"pymathics.graph\"]'))", "metadata": { "trusted": true }, "outputs": [ { "name": "stdout", "text": "Installing mpmath\nInstalling numpy<1.27\nInstalling palettable\nInstalling Pillow\nInstalling pint\nInstalling python-dateutil\nInstalling requests\nInstalling setuptools\nInstalling sympy<1.13\nInstalling Mathics-Scanner==1.3.1\nInstalling ipywidgets\nInstalling lxml\nInstalling pyocr\nInstalling scikit-image\nInstalling unidecode\nInstalling wordcloud\ncannot import name 'CompileError' from 'mathics.core.convert.function' (/lib/python3.12/site-packages/mathics/core/convert/function.py)\n Not able to load mathics.builtin.compilation. Check your installation.\n mathics.builtin loads from /lib/python3.12/site-packages/mathics/core/load\n", "output_type": "stream" }, { "name": "stderr", "text": "/lib/python3.12/site-packages/mathics/builtin/quantum_mechanics/angular.py:89: SyntaxWarning: invalid escape sequence '\\['\n \"\"\"\n", "output_type": "stream" }, { "name": "stdout", "text": "pymathics.graph\n", "output_type": "stream" } ], "execution_count": 1 }, { "cell_type": "code", "source": "eval_mathics(\"ArcCos[0]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 2, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle \\frac{π}{2}$" }, "metadata": {} } ], "execution_count": 2 }, { "cell_type": "code", "source": "eval_mathics(\n \"Graphics[Table[{Hue[h, s], Disk[{12h, 8s}]}, {h, 0, 1, 1/6}, {s, 0, 1, 1/4}]]\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 3, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 3 }, { "cell_type": "code", "source": "eval_mathics(\"Plot[{Sin[x], Cos[x], x ^ 2}, {x, -1, 1}]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 4, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n\n\n-1.0\n-0.5\n0.5\n1.0\n\n\n\n\n-0.5\n0.5\n1.0\n\n\n" }, "metadata": {} } ], "execution_count": 4 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n f[x_] := 4 x / (x ^ 2 + 3 x + 5);\n {f'[x], f''[x], f'''[x]} // Together\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 5, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle \\left\\{\\frac{-4 \\left(-5+x^2\\right)}{{\\left(5+3 x+x^2\\right)}^2},\\frac{8 \\left(-15-15 x+x^3\\right)}{{\\left(5+3 x+x^2\\right)}^3},\\frac{-24 \\left(-20-60 x-30 x^2+x^4\\right)}{{\\left(5+3 x+x^2\\right)}^4}\\right\\}$" }, "metadata": {} } ], "execution_count": 5 }, { "cell_type": "code", "source": "eval_mathics(\n \"Graphics[Table[{EdgeForm[{GrayLevel[0, 0.5]}], Hue[(-11+q+10r)/72, 1, 1, 0.6], Disk[(8-r){Cos[2Pi q/12], Sin[2Pi q/12]}, (8-r)/3]}, {r, 6}, {q, 12}]]\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 6, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 6 }, { "cell_type": "code", "source": "eval_mathics('ColorNegate[Import[\"ExampleData/sunflowers.jpg\"]] // MathMLForm')", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 7, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "
" }, "metadata": {} } ], "execution_count": 7 }, { "cell_type": "code", "source": "eval_mathics('DominantColors[Import[\"ExampleData/hedy.tif\"]] // MathMLForm')", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 8, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "
{ , , }" }, "metadata": {} } ], "execution_count": 8 }, { "cell_type": "code", "source": "eval_mathics(\n 'Graphics[Table[{AbsoluteThickness[t], Line[{{20 t, 10}, {20 t, 80}}], Text[ToString[t]<>\"pt\", {20 t, 0}]}, {t, 0, 10}]]'\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 9, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n0pt\n\n\n1pt\n\n\n2pt\n\n\n3pt\n\n\n4pt\n\n\n5pt\n\n\n6pt\n\n\n7pt\n\n\n8pt\n\n\n9pt\n\n\n10pt\n" }, "metadata": {} } ], "execution_count": 9 }, { "cell_type": "code", "source": "eval_mathics(\n \"Table[Graphics[{Circle[], Arrow[Table[{Cos[phi],Sin[phi]},{phi,0,2*Pi,Pi/2}],{d, d}]}],{d,0,2,0.5}] // MathMLForm\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 10, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "
{ , , , , }" }, "metadata": {} } ], "execution_count": 10 }, { "cell_type": "code", "source": "eval_mathics(\n \"Table[Style[Graphics[{EdgeForm[{Black}], RGBColor[r,g,b], Rectangle[]}], ImageSizeMultipliers->{0.2, 1}], {r,0,1,1/2}, {g,0,1,1/2}, {b,0,1,1/2}] // TableForm // MathMLForm\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 11, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 11 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n collatz[1] := 1;\n collatz[x_ ? EvenQ] := x / 2;\n collatz[x_] := 3 x + 1;\n list = FixedPointList[collatz, 14];\n ListLinePlot[list]\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 12, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n5\n10\n15\n\n\n\n\n10\n20\n30\n40\n50\n\n\n" }, "metadata": {} } ], "execution_count": 12 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n vertices = {{0,0}, {1,0}, {.5, .5 Sqrt[3]}};\n points = NestList[.5(vertices[[ RandomInteger[{1,3}] ]] + #)&, {0.,0.}, 1000];\n Graphics[Point[points], ImageSize->Large]\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 13, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n" }, "metadata": {} } ], "execution_count": 13 }, { "cell_type": "code", "source": "eval_mathics(\"ListLinePlot[Table[Sin[x], {x, -5, 5, 0.2}], Filling->Axis]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 14, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n \n\n\n\n10\n20\n30\n40\n50\n\n\n\n\n-1.0\n-0.5\n0.5\n1.0\n\n\n" }, "metadata": {} } ], "execution_count": 14 }, { "cell_type": "code", "source": "eval_mathics(\"DensityPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}, Mesh->Full]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 15, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n<--DensityPlot-->\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 15 }, { "cell_type": "code", "source": "eval_mathics(\"ParametricPlot[{Sin[u], Cos[3 u]}, {u, 0, 2 Pi}]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 16, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n-1.0\n-0.5\n0.5\n1.0\n\n\n\n\n-1.0\n-0.5\n0.5\n1.0\n\n\n" }, "metadata": {} } ], "execution_count": 16 }, { "cell_type": "code", "source": "eval_mathics(\"Clear[t]; PolarPlot[{1, 1 + Sin[20 t] / 5}, {t, 0, 2 Pi}]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 17, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n-1.0\n-0.5\n0.5\n1.0\n\n\n\n\n-1.0\n-0.5\n0.5\n1.0\n\n\n" }, "metadata": {} } ], "execution_count": 17 }, { "cell_type": "code", "source": "eval_mathics(\n 'WordCloud[StringSplit[Import[\"ExampleData/EinsteinSzilLetter.txt\", CharacterEncoding->\"UTF8\"]]] // MathMLForm'\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 18, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "
" }, "metadata": {} } ], "execution_count": 18 }, { "cell_type": "code", "source": "eval_mathics('EdgeDetect[Import[\"ExampleData/hedy.tif\"], 5] // MathMLForm')", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 19, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "
" }, "metadata": {} } ], "execution_count": 19 }, { "cell_type": "code", "source": "eval_mathics(\"Apart[1 / (x^2 - y^2), x]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 20, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle -\\frac{1}{2 y \\left(x+y\\right)}+\\frac{1}{2 y \\left(x-y\\right)}$" }, "metadata": {} } ], "execution_count": 20 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n With[{f = {Cos[x] + Sin[x], Sin[x]}}, \n Graphics[\n Table[{Hue[t/(2 Pi), 1, .8], Line[{f, Normalize[D[f, x]] + f}]} /. \n x -> t, {t, 0, 2 Pi, .1}]]]\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 21, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 21 }, { "cell_type": "code", "source": "eval_mathics(\"Integrate[Sin[x] ^ 5, x]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 22, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle \\text{Cos}\\left[x\\right] \\left(-1-\\frac{\\text{Cos}\\left[x\\right]^4}{5}+\\frac{2 \\text{Cos}\\left[x\\right]^2}{3}\\right)$" }, "metadata": {} } ], "execution_count": 22 }, { "cell_type": "code", "source": "eval_mathics(\"Series[Exp[x-y], {x, 0, 2}, {y, 0, 2}]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 23, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle \\left(1-y+\\frac{1}{2} y^2+O\\left[y\\right]^3\\right)+\\left(1-y+\\frac{1}{2} y^2+O\\left[y\\right]^3\\right) x+\\left(\\frac{1}{2}+\\left(-\\frac{1}{2}\\right) y+\\frac{1}{4} y^2+O\\left[y\\right]^3\\right) x^2+O\\left[x\\right]^3$" }, "metadata": {} } ], "execution_count": 23 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n Graphics[\n Table[{EdgeForm[Black], Hue[RandomReal[]], \n Disk[RandomReal[4, {2}], RandomReal[1]]}, {40}]]\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 24, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 24 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n Graphics[\n Table[{Hue[t/15, 1, .9, .3], \n Disk[{Cos[2 Pi t/15], Sin[2 Pi t/15]}]}, {t, 15}]]\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 25, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 25 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n Graphics[{Red, Disk[{0, 0}, 2, {0, Pi}], Blue, \n Disk[{0, 0}, 2, {Pi, 2 Pi}], Red, Disk[{-1, 0}, 1], Blue, \n Disk[{1, 0}, 1]}, ImageSize -> 150]\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 26, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n" }, "metadata": {} } ], "execution_count": 26 }, { "cell_type": "code", "source": "eval_mathics(\n \"Solve[{3 x ^ 2 - 3 y == 0, 3 y ^ 2 - 3 x == 0}, {x, y}] // Simplify\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 27, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle \\left\\{\\left\\{x→0,y→0\\right\\},\\left\\{x→1,y→1\\right\\},\\left\\{x→-\\frac{1}{2}+\\frac{I}{2} \\sqrt{3},y→-\\frac{1}{2}-\\frac{I}{2} \\sqrt{3}\\right\\},\\left\\{x→-\\frac{1}{2}-\\frac{I}{2} \\sqrt{3},y→-\\frac{1}{2}+\\frac{I}{2} \\sqrt{3}\\right\\}\\right\\}$" }, "metadata": {} } ], "execution_count": 27 }, { "cell_type": "code", "source": "eval_mathics(\"Graphics[Line[AnglePath[RandomReal[{-1, 1}, {100}]]]]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 28, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n" }, "metadata": {} } ], "execution_count": 28 }, { "cell_type": "code", "source": "eval_mathics(\"Nest[Subsuperscript[#,#,#]&,0,5]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 29, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle {{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}_{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}^{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}}_{{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}_{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}^{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}}^{{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}_{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}^{{{0_0^0}_{0_0^0}^{0_0^0}}_{{0_0^0}_{0_0^0}^{0_0^0}}^{{0_0^0}_{0_0^0}^{0_0^0}}}}$" }, "metadata": {} } ], "execution_count": 29 }, { "cell_type": "code", "source": "eval_mathics(\n \"\"\"\n lindenmayer[i_, b_, h_, j_, r_, n_] :=\n (a = h; p = j; s = k = {}; t = Flatten;\n (Switch[#,\n 6, s = {a, p, s},\n 8, {a, p, s} = s,\n _C, k = {k, Line@{p, p += {Cos@a, Sin@a}}}];\n If[# < 9, a += I^# b ]) & /@ t@Nest[# /. r &, i, n];\n Graphics@t@k);\n lindenmayer[{C[1], X}, Pi/2, 0, {0, 0}, {X -> {X, 4, Y, C[1]}, Y -> {C[1], X, 2, Y}}, 10]\n \"\"\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 30, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "metadata": {} } ], "execution_count": 30 }, { "cell_type": "code", "source": "eval_mathics(\"CompleteGraph@20\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 31, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n \n \n \n 2024-09-28T17:11:58.635000\n image/svg+xml\n \n \n Matplotlib v3.5.2, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n" }, "metadata": {} } ], "execution_count": 31 }, { "cell_type": "code", "source": "eval_mathics('ListPlot[Table[ElementData[z, \"AtomicWeight\"], {z, 118}]]')", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 32, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n20\n40\n60\n80\n100\n120\n\n\n\n\n50\n100\n150\n200\n250\n\n\n" }, "metadata": {} } ], "execution_count": 32 }, { "cell_type": "code", "source": "eval_mathics(\n \"Clear[a]; RSolve[{a[n + 2] == a[n], a[0] == 1, a[1] == 4}, a, n]\"\n)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 33, "output_type": "execute_result", "data": { "text/plain": "", "text/latex": "$\\displaystyle \\left\\{\\left\\{a→\\left(\\text{Function}\\left[\\left\\{n\\right\\},\\frac{5}{2}-\\frac{3 \\left(-1\\right){}^{\\wedge}n}{2}\\right]\\right)\\right\\}\\right\\}$" }, "metadata": {} } ], "execution_count": 33 }, { "cell_type": "code", "source": "eval_mathics(\"BinomialTree[3, DirectedEdges->True]\")", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 34, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n \n \n \n 2024-09-28T17:11:58.972000\n image/svg+xml\n \n \n Matplotlib v3.5.2, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n" }, "metadata": {} } ], "execution_count": 34 }, { "cell_type": "code", "source": "eval_mathics('GraphData[\"PappusGraph\"]')", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 35, "output_type": "execute_result", "data": { "text/plain": "", "text/html": "\n \n \n \n \n 2024-09-28T17:11:59.059000\n image/svg+xml\n \n \n Matplotlib v3.5.2, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n" }, "metadata": {} } ], "execution_count": 35 } ] }