Term

class zixy.container.terms.Term(data: TermData[ImplT, SpecT, CoeffT], indexer: int | None = None)[source]

Bases: ViewableItem[TermData[ImplT, SpecT, CoeffT]], Generic[ImplT, SpecT, CoeffT], StringRepresentable

A term consisting of a component and a coefficient.

A single term consisting of a component and a coefficient that may be an owning instance referencing the sole element in an owned TermData instance, or a view on an element in another collection.

__eq__(other: object) bool[source]

Return whether self and other are equal.

__init__(data: TermData[ImplT, SpecT, CoeffT], indexer: int | None = None)[source]

Initialize the term.

Parameters:
  • data – Raw term data object, of which self views one.

  • indexer – Index of the term within data that self views.

__neg__() Self[source]

Return the negation of self.

__pos__() Self[source]

Return self.

__repr__() str[source]

Return a string representation of self.

aliases(other: Term[Any, Any, Any]) bool[source]

Determine whether self is a view of the same component as other.

clear() None[source]

Set the value of the component to zero and the coefficient to unity.

Note

This method operates in-place.

clone() Self[source]

Return a deep copy of self.

property cmpnt: Cmpnt[ImplT, SpecT]

Get a view on the component of self.

property cmpnt_type: type[Cmpnt[ImplT, SpecT]]

Get the component type of self.

cmpnts_type: type[Cmpnts[ImplT, SpecT]]
property coeff: CoeffT

Get a copy of the coefficient of self.

coeff_type: type[CoeffT]
property coeffs_type: type[Coeffs[CoeffT]]

Get the coefficient container type of self.

classmethod from_cmpnt_coeff(cmpnt: Cmpnt[ImplT, SpecT], coeff: CoeffT) Self[source]

Factory to make an instance of cls from a component and a coefficient.

Parameters:
  • cmpnt – Component to copy from.

  • coeff – Coefficient scaling the cmpnt in the new instance.

Returns:

An instance of cls with the given component and coefficient.

classmethod from_str(source: str, *args: Any, **kwargs: Any) Self[source]

Create an instance of cls from a string.

Parameters:
  • source – String to parse.

  • *args – Positional arguments to forward to the component constructor.

  • **kwargs – Keyword arguments to forward to the component constructor.

Returns:

An instance of cls parsed from source.

into(t: type[OutT]) OutT

Clone self into a new related container of type t.

Parameters:

t – Type of the new container to create.

Returns:

A new instance of t containing the same data as self.

is_owning() bool

Check if self is owning (i.e. not a view).

classmethod parse(source: str) Self

Parse a string into an instance of cls.

Deprecated:

use from_str() instead.

Parameters:

source – String to parse.

Returns:

An instance of cls parsed from source.

set(source: Self | Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT], CoeffT | None]) None[source]

Set the value of the term.

Parameters:

source – Specification for the new value.

Note

This method operates in-place.

to_str() str

Return the canonical string representation of self.