12.8.2 Tensor Composition Codomain Matching
Tensor Composition Codomain Matching ensures compatibility between tensor operations by aligning output spaces for valid mathematical composition.
Tensor Composition Codomain Matching is the requirement that the resulting type produced by each individual operation within a composed tensor expression must exactly match the type expected by whatever subsequent operation will consume that result, ensuring that the output of one step is a valid input for the next.
The Requirement Within Composition
Output Type Feeding Into the Next Step
Within a composed expression, each operation, whether scalar multiplication, negation, addition, or subtraction, produces a resulting tensor of some definite type . Codomain matching requires that whenever this resulting tensor is passed forward into a further operation, its type coincides exactly with the type required by that next operation for its other operand.
Formal Illustration
Consider a composed expression such as . The addition produces a tensor of some type , matching the shared type of and . Codomain matching requires that also be of type , since the subsequent subtraction demands an operand of exactly that type in order to be defined.
Why Codomain Matching Is Necessary
Chained Operations Depend on Consistent Output Types
Because each tensor operation both consumes and produces tensors of specific types, a chain of operations only remains well defined if the type produced at each stage is exactly what the next stage requires. A mismatch at any link in this chain renders the entire subsequent computation undefined, regardless of how the expression is otherwise structured.
Distinguishing from Domain Matching
While domain matching concerns whether the tensors entering an operation share a common underlying vector space, codomain matching specifically concerns whether the type of tensor emerging from one operation aligns with what the next operation in the sequence is designed to accept. Both forms of matching must hold simultaneously for a composed expression to be entirely well defined.
Guaranteed Preservation Through Individual Operations
Operations That Preserve Type
Since scalar multiplication and negation both preserve the type of their single operand, any output produced by these operations automatically has a codomain identical to the type of their input, simplifying the task of tracking codomain matching through a chain involving only these operations.
Operations That Require Matching Types to Produce a Result
Addition and subtraction, by contrast, require their two operands to already share a common type before they can produce any output at all. The output of such an operation, once it succeeds, naturally carries that same shared type forward as its codomain for use in any subsequent step.
Consequence for Well-Formed Expressions
Verifying an Entire Expression Is Well Defined
A composed tensor expression is entirely well defined only when codomain matching holds at every single link connecting one operation's output to the next operation's required input, in addition to domain matching and the underlying same type and same space requirements at each individual addition or subtraction.
Guiding the Construction of Valid Expressions
When constructing a new composed expression from existing tensors, codomain matching serves as a guide for determining which combinations of operations are permissible, ensuring that intermediate results always have a type compatible with whatever further computation is intended.