Symbolic Tensor API
Detailed reference for the symbolic tensor operations API endpoint, including request formats, operations, and examples.
Endpoint Overview
The Symbolic Tensor API endpoint accepts requests to perform tensor calculations symbolically. Under the hood, it utilizes SymPy to manipulate tensor expressions. You can submit operations with symbolic tensor components (variables or symbolic expressions) and receive exact analytical results.
All requests and responses use JSON format. The symbolic API is designed for operations where you need exact mathematical expressions rather than numerical approximations.
Request Format
The JSON request to the symbolic endpoint should describe the tensor operation in a structured way. The core fields in the request are:
Required Fields
operation
(string): The type of tensor operation to perform (e.g., "add", "multiply", "contract", etc.)operands
(array): An array of tensor objects involved in the operation
Tensor Object Structure
name
(string, optional): A label for the tensor (e.g., "A", "B")shape
(array of integers): The dimensions of the tensor (e.g., [2, 2] for a 2×2 matrix)values
(nested array or null): The symbolic components of the tensor, represented as strings or null for fully symbolic
Optional Fields
options
(object): Additional parameters for specific operations (e.g., indices for contraction)
Supported Operations
The Symbolic Tensor API supports a variety of operations for tensor manipulation. Here are the primary operations:
add
Add two tensors of the same shape element-wise.
multiply
Multiply tensors using standard tensor multiplication rules.
contract
Contract (sum over) specified indices of a tensor.
substitute
Replace symbolic variables with other expressions or values.
differentiate
Compute symbolic derivatives of tensor expressions.
simplify
Simplify complex tensor expressions using algebraic rules.
Response Format
The response from the symbolic API will be a JSON object containing the result of the operation. The typical fields in the response include:
result
: The resulting tensor with its shape and symbolic valuesoperation
: Echo of the operation that was performedmessage
(optional): Human-readable message about the operationerror
(optional): Present only if an error occurred, with an explanation
Example Response
Error Handling
The API will perform validation on requests and return appropriate error responses when something goes wrong. Common error scenarios include:
400 Bad Request
Returned when the request is invalid or missing required fields:
Shape Mismatch
Returned when tensor shapes are incompatible for the requested operation:
Parsing Errors
Returned when symbolic expressions cannot be parsed correctly:
500 Internal Server Error
Returned when something unexpected goes wrong on the server. These errors should be reported to the iTensor team.
Example Use Cases
Verifying Mathematical Identities
Use the symbolic API to verify tensor identities by manipulating and simplifying complex expressions.
Deriving Formulas
Derive exact formulas for physics, engineering, or mathematical applications without numerical approximations.
Generating Computational Code
Generate symbolic expressions that can later be converted to optimized numerical code for specific applications.