​
Slide
1
of
14

Calculus and Algebra with Symbolic Arrays

Adam Strzeboński, Wolfram Research​​
​
​
Slide
2
of
14

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.
​
Slide
3
of
14

Symbolic Arrays

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

• VectorSymbol
• MatrixSymbol
• ArraySymbol

Special Arrays

• SymbolicZerosArray
• SymbolicOnesArray
• SymbolicIdentityArray
• SymbolicDeltaProductArray

Symbolic Array Calculus

D works with symbolic array functions and variables.

Symbolic Array Transformations

• ArrayExpand
• ArraySimplify
• ComponentExpand
• TensorExpand
• TensorReduce
​
Slide
4
of
14

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
a.x+b0
. Because of threading, we could not do it directly:
In[]:=
a={{1,2},{1,0}};​​b={-3,1};​​a.x+b0
Out[]=
{-3+{{1,2},{1,0}}.x,1+{{1,2},{1,0}}.x}0
As suggested in the documentation of ConvexOptimization, we needed to use Inactive
[Plus]
:
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.}}
​
Slide
5
of
14

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
+{{1,2},{3,4}}
​
Slide
6
of
14

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:
​
Slide
7
of
14

Symbolic Array Expressions

Represent a matrix:
Construct a symbolic array expression:
Represent an array of depth 3:
Adding one results in SymbolicOnesArray:
With numeric dimensions, Normal gives an explicit array:
​
Slide
8
of
14

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:
​
Slide
9
of
14

Chain Rule and ArrayDot

Derivative of a composition of symbolic array-valued functions wrt. an array variable:
​
Slide
10
of
14

Example: Taylor Approximations

Simplify the result with ArraySimplify (coming in the next version):
​
Slide
11
of
14

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:
​
Slide
12
of
14

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:
​
Slide
13
of
14

ComponentExpand

ComponentExpand expands out symbolic array expressions in terms of indexed components:
​
Slide
14
of
14

Thank you for listening!