Sorry to ask this twice. I thought I could get away with just a0 + a1 e1 + a2 e2 + a3 e1 e2, but for my application I can’t. I can generate a + a{1} e1 + a{2} e2 + a{12} e12 (subscripted), but that’s as close as I can come. Also my method for this is clumsy.

This is the case I call n = 2 because of only e1 and e2, but I need to be able to do this for any n. n = 3 would have additional terms like e1 e3, e2 e3, and e1 e2 e3.

I formerly learned in this forum how to generate the expression for “e” using Subsets function:

If I could just generate an expression for “a” with the above desired subscripts I could then take the dot product to generate the desired expression. Or, if someone could show me how to convert an expression a{1} into a1 (using subscripts on both) I would also be done.

=================

=================

2 Answers

2

=================

Clear[a, e]

Format[a[n_]] := Subscript[a, n]

Format[e[n_]] := Subscript[e, n]

n = 2;

aArray = a /@ FromDigits /@ Subsets[Range[n]];

eArray = e /@ FromDigits /@ Subsets[Range[n]];

aArray.eArray /. {a[0] :> a[“”], e[0] :> 1}

Manipulate[

aArray = a /@ FromDigits /@ Subsets[Range[n]];

eArray = e /@ FromDigits /@ Subsets[Range[n]];

aArray.eArray /. {a[0] :> a[“”], e[0] :> 1},

{{n, 2}, Range[5]}]

The following uses Subscript[a, 1, 2] for a12a_{12} so it looks like a1,2a_{1,2}:

a + Total[Subscript[a, ##] * Subscript[e, ##] & @@@ Rest[Subsets[Range[2]]]]

## is shorthand for SlotSequence, @@@ is shorthand for Apply at level 1.

Thank you both. I just had a blind spot (too close to the rest of my problem). I just woke up (middle of the night) and realized I also could have generated aArray exactly as eArray was generated, and then multiplied them. I’ll select one of your answers as the best one tomorrow (when I’m awake). Both of your answers are very slick and compact.

– matrixbud

Sep 6 at 8:17