{
	"cell_id": 17512074313060748460,
	"cells": [
		{
			"cell_id": 15247747989752233954,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 1213666910347544194,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\package{cdb.utils.node}{Helper functions for working with ExNode objects}\n\nThis package contains numerous helper functions for examining, querying and creating ExNode objects"
				}
			],
			"hidden": true,
			"source": "\\package{cdb.utils.node}{Helper functions for working with ExNode objects}\n\nThis package contains numerous helper functions for examining, querying and creating ExNode objects"
		},
		{
			"cell_id": 8707393970919064424,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 2302073851195842048,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{n_indices(ex_node: ExNode|Ex) -> int}{Return the number of first-level indices a node has}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{n_indices(ex_node: ExNode|Ex) -> int}{Return the number of first-level indices a node has}"
		},
		{
			"cell_id": 1753035616873629304,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def n_indices(ex_node):\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\treturn sum(1 for i in ex_node.indices())"
		},
		{
			"cell_id": 16050091017712825754,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 3758324614433019034,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{nth_index(ex_node: ExNode|Ex, n: int) -> ExNode}{Gets the nth index of an ExNode object}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{nth_index(ex_node: ExNode|Ex, n: int) -> ExNode}{Gets the nth index of an ExNode object}"
		},
		{
			"cell_id": 1668756240050354674,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def nth_index(ex_node, n):\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\tfor i, index in enumerate(ex_node.indices()):\n\t\tif i == n:\n\t\t\treturn index\n\traise IndexError"
		},
		{
			"cell_id": 14893455513982883060,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 5137071268020781653,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{n_args(ex_node: ExNode|Ex) -> int}{Returns the number of first-level arguments a node has}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{n_args(ex_node: ExNode|Ex) -> int}{Returns the number of first-level arguments a node has}"
		},
		{
			"cell_id": 4541113739588128532,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def n_args(ex_node):\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\treturn sum(1 for i in ex_node.args())"
		},
		{
			"cell_id": 1296289453444328705,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 10868576452574748356,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{nth_arg(ex_node: ExNode|Ex, n: int) -> ExNode}{Gets the nth first-level argument of an ExNode object}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{nth_arg(ex_node: ExNode|Ex, n: int) -> ExNode}{Gets the nth first-level argument of an ExNode object}"
		},
		{
			"cell_id": 12002362360129662198,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def nth_arg(ex_node, n):\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\tfor i, arg in enumerate(ex_node.args()):\n\t\tif i == n:\n\t\t\treturn arg\n\traise IndexError"
		},
		{
			"cell_id": 7867168225214081120,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 15318580960104441515,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{arg_tuple(ex_node: ExNode|Ex, n: int) -> tuple[ExNode]}{Returns a tuple containing the first n arguments of an ExNode object}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{arg_tuple(ex_node: ExNode|Ex, n: int) -> tuple[ExNode]}{Returns a tuple containing the first n arguments of an ExNode object}"
		},
		{
			"cell_id": 3905388232732922485,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def arg_tuple(ex_node, n):\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\treturn (nth_arg(ex_node, i)._latex_() for i in range(n))"
		},
		{
			"cell_id": 5580540595633524661,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 6477025559129691750,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{n_children(ex_node: ExNode|Ex) -> int}{Returns the number of first-level children a node has}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{n_children(ex_node: ExNode|Ex) -> int}{Returns the number of first-level children a node has}"
		},
		{
			"cell_id": 6625943265031471290,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def n_children(ex_node):\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\treturn sum(1 for i in ex_node.children())"
		},
		{
			"cell_id": 10470381271085779836,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 8350148697092125558,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{nth_child(ex_node: ExNode|Ex, n: int) -> ExNode}{Gets the nth first-level child of an ExNode object}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{nth_child(ex_node: ExNode|Ex, n: int) -> ExNode}{Gets the nth first-level child of an ExNode object}"
		},
		{
			"cell_id": 13783965533728989485,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def nth_child(ex_node, n):\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\n\tfor i, child in enumerate(ex_node.children()):\n\t\tif i == n:\n\t\t\treturn child\n\traise IndexError"
		},
		{
			"cell_id": 10765803096551983959,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 402856110058782620,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{child_tuple(ex_node : ExNode|Ex, n: int) -> tuple[ExNode]}{Returns a tuple containing the first n children of an ExNode object}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{child_tuple(ex_node : ExNode|Ex, n: int) -> tuple[ExNode]}{Returns a tuple containing the first n children of an ExNode object}"
		},
		{
			"cell_id": 6084336848221340877,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def child_tuple(ex_node, n):\n\t\"\"\"\"\"\"\n\tif type(ex_node) is Ex:\n\t\tex_node = ex_node.top()\n\n\treturn (nth_child(ex_node, i)._latex_() for i in range(n))"
		},
		{
			"cell_id": 14135986501232649833,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 13139998648599712246,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{empty_sum() -> Ex}{Returns an Ex object with just one \\textbackslash sum node with no children}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{empty_sum() -> Ex}{Returns an Ex object with just one \\textbackslash sum node with no children}"
		},
		{
			"cell_id": 13241820287247340496,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def empty_sum():\n\tex := a + b;\n\twhile n_children(ex.top()) != 0:\n\t\tnth_child(ex.top(), 0).erase()\n\treturn ex"
		},
		{
			"cell_id": 2942202388793883132,
			"cell_origin": "client",
			"cell_type": "latex",
			"cells": [
				{
					"cell_id": 18408345614398630523,
					"cell_origin": "client",
					"cell_type": "latex_view",
					"source": "\\algorithm{empty_product() -> Ex}{Returns an Ex object with just one \\textbackslash product node with no children}"
				}
			],
			"hidden": true,
			"source": "\\algorithm{empty_product() -> Ex}{Returns an Ex object with just one \\textbackslash product node with no children}"
		},
		{
			"cell_id": 7789116792134512028,
			"cell_origin": "client",
			"cell_type": "input",
			"source": "def empty_product():\n\tex := a * b;\n\twhile n_children(ex.top()) != 0:\n\t\tnth_child(ex.top(), 0).erase()\n\treturn ex"
		},
		{
			"cell_id": 6834160618828137935,
			"cell_origin": "client",
			"cell_type": "input",
			"cells": [
				{
					"cell_id": 10463424941420234170,
					"cell_origin": "server",
					"cell_type": "verbatim",
					"source": "\\begin{verbatim}a, b, c, d, e, f, g\\end{verbatim}"
				},
				{
					"cell_id": 4355001156256662151,
					"cell_origin": "server",
					"cell_type": "verbatim",
					"source": "\\begin{verbatim}(a, b, c, d)\\end{verbatim}"
				}
			],
			"ignore_on_import": true,
			"source": "ex1 = $a, b, c, d, e, f, g$\ndisplay(\", \".join(nth_arg(ex1, i)._latex_() for i in range(n_args(ex1))))\ndisplay('(' + \", \".join(arg_tuple(ex1, 4)) + ')')"
		},
		{
			"cell_id": 13524964813951039698,
			"cell_origin": "client",
			"cell_type": "input",
			"source": ""
		}
	],
	"description": "Cadabra JSON notebook format",
	"version": 1.0
}
