3
$\begingroup$

Is there a way to use symbolic indices on symbolic vectors? The most barebones example I can think of is the following:

aV = Array[a,3];
aV[[m]]

which evaluates to a warning:

{a[1], a[2], a[3]}[[m]]
Part::pkspec1: The expression m cannot be used as a part specification.

Instead, the behaviour I would like to see is that this simply evaluates to the symbolic expression

a[m]

Having this functionality for symbolic indexation would be useful for many more complicated contexts to derive symbolic expressions, and Integration into the Indexed function would also help keep expressions readable.

To add another less barebones example, here I calculate a general cross product between vectors $b_l$ and $b_m$ in $\mathbb{R}^3$:

Nb = 7 ; (*length of list of R3 vectors b_i, not important*)
bV = Array[b, {Nb, 3}];
stdbasis = IdentityMatrix[3]; (* standard basis vectors in R3*)
crossProductFormula[l_, m_] = 
 Sum[stdbasis[[i]]*LeviCivitaTensor[3][[i, j, k]]*bV[[l, j]]*bV[[m, k]], {i, 3}, {j, 3}, {k, 3}]

The function works for specific l and m inputs, but it would be nice if it could generate a readable symbolic expression.

$\endgroup$
2
  • $\begingroup$ What would your "readable symbolic expression" look like? $\endgroup$
    – lericr
    Aug 3, 2023 at 20:17
  • $\begingroup$ Perhaps you could use Association $\endgroup$
    – MelaGo
    Aug 3, 2023 at 21:01

2 Answers 2

3
$\begingroup$

Will this solve your first question?

aV[m_] := Array[a, 3][[m]]

Let us check:

aV[1]

(* a[1] *)

Sum[aV[m], {m, 1, 3}]



  (* a[1] + a[2] + a[3]  *)

??

Otherwise you could have define like this:

Subscript[aW, m_] := Array[a, 3][[m]];

Subscript[aW, 2]

(* a[2] *)

Sum[\!\(
\*SubsuperscriptBox[\(aW\), \(m\), \(2\)], \({m, 1, 3}\)\)]

    
   (* a[1]^2 + a[2]^2 + a[3]^2  *)

??

$\endgroup$
3
  • $\begingroup$ Unfortunately it doesn't, since I explicitly would want an expression that works with a symbolic index: in your examples, you always give m an explicit integer value, whereas I would want the indexing to work for symbolic inputs, i.e. aV[m] should return a[m] or a_m, where both a and m are symbolic. $\endgroup$
    – ertl
    Aug 5, 2023 at 15:28
  • 1
    $\begingroup$ As much as I understand you, you are looking for a possibility to make symbolic operations with indexed tensors, right? I am also looking for such an approach, but up to now, did not see a satisfactory one. $\endgroup$ Aug 5, 2023 at 21:28
  • $\begingroup$ Yes! I ended up defining a wrapper function that wraps 2D arrays and produces the desired behavior, but it would be nice to have a general abstract array class that generalizes to higher dimensions, and even symbolic sizes. Honestly somewhat surprised this does not exist yet! $\endgroup$
    – ertl
    Aug 7, 2023 at 15:15
0
$\begingroup$

I found a solution to the second example in this question which involves defining the arrays in question as functions:

basis[i_] := KroneckerDelta[#, i] & /@ Range[3];
bs[i_, j_] := Indexed[b, {i, j}]

However, this is not entirely satisfactory since the function 'bs' now does not have specific dimensions, and hence we cannot retrieve a symbolic row or column like $b_{l:}$ and $b_{m:}$. Further, Mathematica would not know how to, say, take the dot product of these two arrays unless we explicitly define it as a sum of precisely indexed elements.

$\endgroup$
3
  • 1
    $\begingroup$ What would it mean to "retrieve a symbolic row or colulmn"? $\endgroup$
    – lericr
    Aug 3, 2023 at 20:18
  • $\begingroup$ For example, say you have a two dimensional array like aV = Array[Indexed[a, {#1, #2}] &, {3, 3}]. Then I would like to be able to retrieve an arbitrary column m (m symbolic), such that aV[All,m] gives {a_1m, a_2m, a_3m} as output. It is implicit here that while m is symbolic, it is a valid index. $\endgroup$
    – ertl
    Aug 5, 2023 at 15:31
  • $\begingroup$ You could define a function to do that, but I'm not understanding what the use case would be. If all you want are purely symbolic expressions, then just build functions to generate those--there's no need to create an actual matrix that has special behavior with respect to Part. $\endgroup$
    – lericr
    Aug 6, 2023 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.