Calculus and Algebra with Symbolic Arrays
Calculus and Algebra with Symbolic Arrays
Adam Strzeboński, Wolfram Research
ABSTRACT
ABSTRACT
This talk discusses Wolfram Language functionality for computation with symbolic arrays. It includes symbolic representation of arrays, transforming and simplifying symbolic array expressions and computation of derivatives of array functions with respect to symbolic array variables, as well as support for array variables in several symbolic computation functions.
Symbolic Arrays
Symbolic Arrays
NonThreadable Attribute
NonThreadable Attribute
Attribute that prevents threading of listable functions. It is given to symbols that may be used to construct expressions that represent arrays:
In[]:=
First/@Select[ToExpression[#,InputForm,Hold]&/@Names["System`*"],MemberQ[Attributes@@#,NonThreadable]&]
Out[]=
{Adjugate,ArraySymbol,ConjugateTranspose,Cross,Differences,DrazinInverse,Eigenvalues,Eigenvectors,GPUArray,IdentityMatrix,Inverse,KroneckerProduct,LeastSquares,LinearSolve,MatrixExp,MatrixFunction,MatrixLog,MatrixPower,MatrixSymbol,Minors,NullSpace,NumericArray,PseudoInverse,Ratios,RowReduce,SymbolicDeltaProductArray,SymbolicIdentityArray,SymbolicOnesArray,SymbolicZerosArray,Tabular,TabularRow,TensorContract,TensorProduct,TensorTranspose,TensorWedge,Transpose,UnitVector,VectorSymbol}
Symbolic Array Variables
Symbolic Array Variables
• VectorSymbol
• MatrixSymbol
• ArraySymbol
Special Arrays
Special Arrays
• SymbolicZerosArray
• SymbolicOnesArray
• SymbolicIdentityArray
• SymbolicDeltaProductArray
Symbolic Array Calculus
Symbolic Array Calculus
D works with symbolic array functions and variables.
Symbolic Array Transformations
Symbolic Array Transformations
• ArrayExpand
• ArraySimplify
• ComponentExpand
• TensorExpand
• TensorReduce
Symbolic Array Variables and Threading
Symbolic Array Variables and Threading
A long-standing difficulty with using symbolic vector, matrix and array variables was that evaluation of arithmetic operations treated symbolic expressions as scalars and threaded them into list arguments:
In[]:=
x+{1,2}
Out[]=
{1+x,2+x}
For instance, we would like to set up a convex optimization constraint . Because of threading, we could not do it directly:
a.x+b0
In[]:=
a={{1,2},{1,0}};b={-3,1};a.x+b0
Out[]=
{-3+{{1,2},{1,0}}.x,1+{{1,2},{1,0}}.x}0
In[]:=
Inactive[Plus][a.x,b]0
Out[]=
{{1,2},{1,0}}.x+{-3,1}0
In[]:=
ConvexOptimization[{1,1}.x,%,x]
Out[]=
{x{-1.,2.}}
NonThreadable Attribute
NonThreadable Attribute
The NonThreadable attribute specifies that a symbol and expressions that have this symbol as the head should not be threaded into lists:
In[]:=
SetAttributes[sym,NonThreadable]
In[]:=
sym+{1,2}
Out[]=
sym+{1,2}
In[]:=
sym[1,2,3]+{1,2,3}
Out[]=
{1,2,3}+sym[1,2,3]
Most standard built-in functions that produce array results have the NonThreadable attribute:
In[]:=
Inverse[mat]+{{1,2},{3,4}}
Out[]=
-1
mat
Symbolic Array Variables
Symbolic Array Variables
VectorSymbol, MatrixSymbol and ArraySymbol are objects that can be used for symbolic representation of vectors, matrices and arrays:
In[]:=
v=VectorSymbol["v",2]
Out[]=
⇀
v
The objects have the NonThreadable attribute:
Now we can set up the convex optimization constraint directly:
Array variables can be used in solvers:
Symbolic Array Expressions
Symbolic Array Expressions
Represent a matrix:
Construct a symbolic array expression:
Represent an array of depth 3:
Array Derivatives
Array Derivatives
Derivative of a vector-valued function wrt. a scalar variable:
Derivative of a vector-valued function wrt. a vector variable:
Derivative of a vector-valued function wrt. a matrix variable:
Derivative of a matrix-valued function wrt. a matrix variable:
Specify the domain of a vector variable:
Variance is differentiable only for real vectors:
Chain Rule and ArrayDot
Chain Rule and ArrayDot
Derivative of a composition of symbolic array-valued functions wrt. an array variable:
Example: Taylor Approximations
Example: Taylor Approximations
Simplify the result with ArraySimplify (coming in the next version):
ArrayExpand
ArrayExpand
ArrayExpand expands out symbolic array operations. The function makes use of multi-linearity of array operations, as well as of numerous array, matrix and vector operation identities:
Example: Formula Derivation
Example: Formula Derivation
Derive a formula for the gradient of the least-squares cost function (example from Mathematica Stack Exchange post):
Define the cost function:
Compute the gradient:
Simplify the gradient:
ComponentExpand
ComponentExpand
ComponentExpand expands out symbolic array expressions in terms of indexed components:
Thank you for listening!
Thank you for listening!