Task

Display a finite linear combination in an infinite vector basis 



(

e

1


,

e

2


,
…
)


{\displaystyle (e_{1},e_{2},\ldots )}

.

Write a function that, when given a finite list of scalars 



(

α

1


,

α

2


,
…
)


{\displaystyle (\alpha ^{1},\alpha ^{2},\ldots )}

, 
creates a string representing the linear combination 




∑

i



α

i



e

i




{\displaystyle \sum _{i}\alpha ^{i}e_{i}}

 in an explicit format often used in mathematics, that is:






α


i

1





e


i

1




±

|


α


i

2





|


e


i

2




±

|


α


i

3





|


e


i

3




±
…


{\displaystyle \alpha ^{i_{1}}e_{i_{1}}\pm |\alpha ^{i_{2}}|e_{i_{2}}\pm |\alpha ^{i_{3}}|e_{i_{3}}\pm \ldots }


where 




α


i

k




≠
0


{\displaystyle \alpha ^{i_{k}}\neq 0}







The output must comply to the following rules:

   don't show null terms, unless the whole combination is null. 
 e(1)     is fine,     e(1) + 0*e(3)     or     e(1) + 0     is wrong.
   don't show scalars when they are equal to one or minus one. 
 e(3)     is fine,     1*e(3)     is wrong.
   don't prefix by a minus sign if it follows a preceding term.   Instead you use subtraction. 
 e(4) - e(5)     is fine,     e(4) + -e(5)     is wrong.


Show here output for the following lists of scalars:

 1)    1,  2,  3
 2)    0,  1,  2,  3
 3)    1,  0,  3,  4
 4)    1,  2,  0
 5)    0,  0,  0
 6)    0
 7)    1,  1,  1
 8)   -1, -1, -1
 9)   -1, -2,  0, -3
10)   -1



/*REXX program displays a   finite liner combination   in an   infinite vector basis.   */
@.= .;           @.1  =    '  1,  2,  3     '    /*define a specific test case for build*/
                 @.2  =    '  0,  1,  2,  3 '    /*   "   "     "      "    "   "    "  */
                 @.3  =    '  1,  0,  3,  4 '    /*   "   "     "      "    "   "    "  */
                 @.4  =    '  1,  2,  0     '    /*   "   "     "      "    "   "    "  */
                 @.5  =    '  0,  0,  0     '    /*   "   "     "      "    "   "    "  */
                 @.6  =       0                  /*   "   "     "      "    "   "    "  */
                 @.7  =    '  1,  1,  1     '    /*   "   "     "      "    "   "    "  */
                 @.8  =    ' -1, -1, -1     '    /*   "   "     "      "    "   "    "  */
                 @.9  =    ' -1, -2,  0, -3 '    /*   "   "     "      "    "   "    "  */
                 @.10 =      -1                  /*   "   "     "      "    "   "    "  */
  do j=1  while  @.j\==.;        n= 0            /*process each vector; zero element cnt*/
  y= space( translate(@.j, ,',') )               /*elide commas and superfluous blanks. */
  $=                                             /*nullify  output  (liner combination).*/
       do k=1  for words(y);     #= word(y, k)   /* ◄───── process each of the elements.*/
       if #=0  then iterate;     a= abs(# / 1)   /*if the value is zero, then ignore it.*/
       if #<0  then s= '- '                      /*define the sign:   minus (-).        */
               else s= '+ '                      /*   "    "    "     plus  (+).        */
       n= n + 1                                  /*bump the number of elements in vector*/
       if n==1  then s= strip(s)                 /*if the 1st element used, remove blank*/
       if a\==1    then s= s  ||  a'*'           /*if multiplier is unity, then ignore #*/
       $= $  s'e('k")"                           /*construct a liner combination element*/
       end   /*k*/
  $= strip( strip($), 'L', "+")                  /*strip leading plus sign (1st element)*/
  if $==''  then $= 0                            /*handle special case of no elements.  */
  say right( space(@.j), 20)  ' ──► '   strip($) /*align the output for presentation.   */
  end       /*j*/                                /*stick a fork in it,  we're all done. */