13.20.3 Tensor Contraction Dimension Check
Tensor Contraction Dimension Check verifies the validity of tensor contractions by ensuring dimension consistency in algebraic operations.
Tensor Contraction Dimension Check is the verification test confirming that every index proposed for contraction ranges over exactly the same dimension on both sides of the operation, ensuring that the sum defining the contraction is well posed before any component values are computed or any further simplification is attempted.
Definition
For a contraction pairing an upper index of tensor with a lower index of tensor , the dimension check requires:
If this equality fails, the proposed contraction is not defined, since the summation implied by the repeated index has no consistent range to iterate over.
Why the Check Is Necessary
Well-Posedness of the Sum
The Einstein summation convention presumes a single shared range for a repeated index; if the two occurrences of that index actually belong to spaces of different dimension, there is no coherent range over which to sum, and any numerical value produced by ignoring this mismatch would not correspond to any valid tensor operation.
Silent Failure Risk
Because contraction notation does not visually distinguish indices of different dimension using the same symbol, an unchecked mismatch can be carried silently through a long expression, producing a result that appears syntactically valid but corresponds to no well-defined mathematical object.
Procedure
Step One: Record Axis Dimensions
For each tensor participating in the contraction, record the dimension associated with every one of its axes, distinguishing axes by their position, not merely by their index label.
Step Two: Match Contracted Pairs
For every pair of indices proposed for contraction, compare the recorded dimensions of the two axes involved.
Step Three: Flag Mismatches
If any pair fails to match, the contraction is rejected before proceeding, and the mismatched pair is reported so that the source of the inconsistency, such as an incorrectly transposed tensor or an error in an earlier step, can be located.
Relation to Cost Index Range
The dimension check relies on the same notion of per-index range size used in the cost index range, confirming before any cost estimate or numerical computation is undertaken that the contracted index's range is consistent across both participating tensors, rather than merely assuming a single uniform dimension for the entire expression.
Diagram
Placement Within the Verification Procedure
The dimension check is typically the first test applied in the broader tensor contraction verification procedure, since it establishes the basic well-posedness of the operation before any subsequent test, such as index consistency or component-level spot checking, can meaningfully be applied to the result.