BroadcastFunction
Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.
BroadcastFunction
class BroadcastFunctionA unary function applied independently to each tensor component.
Calling it on a TensorExpression preserves the tensor interface. Calling it on Tensor or TensorNetwork creates a lazy network. Scalar inputs produce ordinary Symbolica Expressions. Register numerical behavior separately in a TensorFunctionLibrary.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import BroadcastFunction
conjugated = BroadcastFunction.conj()(tensor)
conjugated.shape
(2, 2)Methods
| Name | Description |
|---|---|
__call__ |
Apply this unary function to a scalar or to every tensor component. |
__new__ |
Register a Symbolica function for elementwise tensor application. |
__repr__ |
Return a readable object description for inspection. |
__str__ |
Return a readable text representation. |
conj |
Return the built-in elementwise complex-conjugation function. |
get_tags |
List the tags attached to the registered function. |
has_tag |
Check whether the registered function carries a tag. |
to_expression |
Return this function name as a Symbolica symbol. |
__call__
BroadcastFunction.__call__(arg: Tensor | TensorNetwork) -> TensorNetwork
BroadcastFunction.__call__(arg: TensorExpression) -> TensorExpression
BroadcastFunction.__call__(arg: _ScalarInput) -> ExpressionApply this unary function to a scalar or to every tensor component.
Parameters
arg(scalar expression, TensorExpression, Tensor, or TensorNetwork) Value to transform independently at each component.
Returns
Expression, TensorExpression, or TensorNetworkScalar inputs return Expression; symbolic tensors retain TensorExpression; component-bearing inputs return TensorNetwork.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import BroadcastFunction
result = BroadcastFunction.conj()(tensor).to_tensor()
result.shape
(2, 2)__new__
BroadcastFunction.__new__(
name: builtins.str,
*,
is_symmetric: typing.Optional[builtins.bool] = None,
is_antisymmetric: typing.Optional[builtins.bool] = None,
is_cyclesymmetric: typing.Optional[builtins.bool] = None,
is_linear: typing.Optional[builtins.bool] = None,
is_flat: typing.Optional[builtins.bool] = None,
is_scalar: typing.Optional[builtins.bool] = None,
is_real: typing.Optional[builtins.bool] = None,
is_integer: typing.Optional[builtins.bool] = None,
is_positive: typing.Optional[builtins.bool] = None,
tags: typing.Optional[typing.Sequence[builtins.str]] = None,
aliases: typing.Optional[typing.Sequence[builtins.str]] = None,
normalization: typing.Optional[symbolica.core.Transformer | typing.Callable[[symbolica.core.Expression], symbolica.core.Expression]] = None,
print: typing.Optional[typing.Any] = None,
derivative: typing.Optional[typing.Any] = None,
series: typing.Optional[typing.Any] = None,
eval: typing.Optional[typing.Any] = None,
data: typing.Optional[_ScalarInput | str | dict | list | bytes] = None,
) -> BroadcastFunctionRegister a Symbolica function for elementwise tensor application.
Parameters
name(str) Registered unary function name. It receives the broadcast tag and cannot also be a tensor head.is_symmetric, is_antisymmetric, is_cyclesymmetric(bool, optional) Symmetry of the function arguments under all permutations, signed permutations, or cyclic rotations. These affect scalar arguments as well as index arguments. Repeated arguments in an antisymmetric call make that call zero.is_linear(bool, optional) Distribute the function over sums in its arguments.is_flat(bool, optional) Flatten nested calls with the same head.is_scalar(bool, optional) Declare calls scalar for Symbolica’s algebra. The broadcast acts on scalar component values.is_real, is_integer, is_positive(bool, optional) Assumptions used by Symbolica for the registered symbol.tags(sequence of str, optional) Additional Symbolica tags; Spenso’s required tags are included automatically.aliases(sequence of str, optional) Additional names for the same Symbolica symbol.normalization(Transformer or callable, optional) Normalize a newly constructed call. A callable receives an Expression and returns its normalized Expression; tensor interfaces must remain valid.print(callable, optional) Symbolica custom-print callback for the complete function call. Returning None selects standard printing.derivative, series, eval(callable, optional) Symbolica callbacks for differentiation, series expansion, and numerical evaluation. Their arguments and results followsymbolica.S.data(object, optional) Symbolica user data attached to the symbol, such as a dict, list, or bytes.
Returns
BroadcastFunctionCallable wrapper with tensor-aware result types.
Examples
from symbolica.community.tensor import BroadcastFunction, TensorExpression
function = BroadcastFunction("elementwise")
applied = function(TensorExpression(2))
applied.is_scalar
True__repr__
BroadcastFunction.__repr__() -> builtins.strReturn a readable object description for inspection.
Examples
from symbolica.community import tensor as sp
conjugate = sp.BroadcastFunction.conj()
text = repr(conjugate)__str__
BroadcastFunction.__str__() -> builtins.strReturn a readable text representation.
Examples
from symbolica.community import tensor as sp
conjugate = sp.BroadcastFunction.conj()
text = str(conjugate)conj
BroadcastFunction.conj() -> BroadcastFunctionReturn the built-in elementwise complex-conjugation function.
Returns
BroadcastFunctionRegistered conjugation, with a built-in numerical implementation.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
from symbolica.community.tensor import Tensor
tensor = Tensor.dense(A, [1.0, 2.0, 3.0, 4.0])
from symbolica.community.tensor import BroadcastFunction
BroadcastFunction.conj()(tensor).to_tensor()[0, 1]
2.0has_tag
BroadcastFunction.has_tag(tag: builtins.str) -> builtins.boolCheck whether the registered function carries a tag.
Parameters
tag(str) Exact tag name. An unqualified name also matches its “python::” form.
Returns
boolWhether the tag is present.
Examples
from symbolica.community.tensor import BroadcastFunction
name = BroadcastFunction("tagged_BroadcastFunction", tags=["example::example"])
name.has_tag("example::example")
Trueto_expression
BroadcastFunction.to_expression() -> ExpressionReturn this function name as a Symbolica symbol.
Returns
ExpressionThe bare function head, without arguments or tensor structure.
Examples
from symbolica.community.tensor import BroadcastFunction
name = BroadcastFunction("tagged_BroadcastFunction", tags=["example::example"])
head = name.to_expression()