Cadabra
a field-theory motivated approach to computer algebra

cdb.utils.node

Helper functions for working with ExNode objects
This package contains numerous helper functions for examining, querying and creating ExNode objects

n_indices(ex_node: ExNode|Ex) -> int

Return the number of first-level indices a node has

nth_index(ex_node: ExNode|Ex, n: int) -> ExNode

Gets the nth index of an ExNode object

n_args(ex_node: ExNode|Ex) -> int

Returns the number of first-level arguments a node has

nth_arg(ex_node: ExNode|Ex, n: int) -> ExNode

Gets the nth first-level argument of an ExNode object

arg_tuple(ex_node: ExNode|Ex, n: int) -> tuple[ExNode]

Returns a tuple containing the first n arguments of an ExNode object

n_children(ex_node: ExNode|Ex) -> int

Returns the number of first-level children a node has

nth_child(ex_node: ExNode|Ex, n: int) -> ExNode

Gets the nth first-level child of an ExNode object

child_tuple(ex_node : ExNode|Ex, n: int) -> tuple[ExNode]

Returns a tuple containing the first n children of an ExNode object

empty_sum() -> Ex

Returns an Ex object with just one \textbackslash sum node with no children

empty_product() -> Ex

Returns an Ex object with just one \textbackslash product node with no children
ex1 = $a, b, c, d, e, f, g$ display(", ".join(nth_arg(ex1, i)._latex_() for i in range(n_args(ex1)))) display('(' + ", ".join(arg_tuple(ex1, 4)) + ')')
a, b, c, d, e, f, g
(a, b, c, d)
Copyright © 2001-2021 Kasper Peeters
Questions? info@cadabra.science