Display a linear combination: Difference between revisions

m
used a larger font to make it easier to read the superscripts and symbols, added other whitespace and highlighting, re-did the examples with more whitespace, reduced some verbiage, added a ;Task; (bold) header, added whitespace before the TOC.
(Added Elixir)
m (used a larger font to make it easier to read the superscripts and symbols, added other whitespace and highlighting, re-did the examples with more whitespace, reduced some verbiage, added a ;Task; (bold) header, added whitespace before the TOC.)
Line 1:
{{draft task}}
 
;Task:
The purpose of this task is to displayDisplay a finite &nbsp; [[wp:linear combination|linear combination]] &nbsp; in an infinite vector basis &nbsp; <big><big><math> (e_1, e_2,\ldots)</math></big></big>.
 
Write a function that, &nbsp; when given a finite list of scalars &nbsp; <big><big><math> (\alpha^1,\alpha^2,\ldots) </math>, creates a string representing the linear combination <math/big>\sum_i\alpha^i e_i</mathbig> in an explicit format often used in mathematics, that is:
<br>creates a string representing the linear combination &nbsp; <big><big><math> \sum_i\alpha^i e_i </math></big></big> &nbsp; in an explicit format often used in mathematics, that is:
 
::: <big><big><math> \alpha^{i_1}e_{i_1}\pm|\alpha^{i_2}|e_{i_2}\pm|\alpha^{i_3}|e_{i_3}\pm\ldots </math></big></big>
:::::::: where <big><big><math> \alpha^{i_k}\neq 0 </math></big></big>
 
<br>
where <math>\alpha^{i_k}\neq 0</math>
In other words, and with examples and counter-examples, yourThe output must comply to the following rules:
 
* you&nbsp; don't show null terms, unless the whole combination is null. For instance while the output "0" is fine, "e(1) + 0*e(3)" or "0 + e(1)" are wrong.
In other words, and with examples and counter-examples, your output must comply to the following rules:
::::::: '''e(1)''' &nbsp; &nbsp; is fine, &nbsp; &nbsp; '''e(1) + 0*e(3)''' &nbsp; &nbsp; or &nbsp; &nbsp; '''e(1) + 0''' &nbsp; &nbsp; is wrong.
 
* you&nbsp; don't show scalars when they are equal to one or minus one. For instance the string "1*e(3)" is wrong.
* you don't show null terms, unless the whole combination is null. For instance while the output "0" is fine, "e(1) + 0*e(3)" or "0 + e(1)" are wrong.
::::::: '''e(3)''' &nbsp; &nbsp; is fine, &nbsp; &nbsp; '''1*e(3)''' &nbsp; &nbsp; is wrong.
* you don't show scalars when they are equal to one or minus one. For instance the string "1*e(3)" is wrong.
* you&nbsp; don't prefix by '-'a minus sign if it follows a preceding term. &nbsp; Instead you use subtraction. Thus "e(4) - e(5)" is correct while "e(4) + -e(5)" is wrong.
::::::: '''e(4) - e(5)''' &nbsp; &nbsp; is fine, &nbsp; &nbsp; '''e(4) + -e(5)''' &nbsp; &nbsp; is wrong.
 
<br>
Show here output for the following lists of scalars:
<pre>1) 1, 2, 3
2 1) 0, 1, 2, 3
3 2) 1, 0, 3 1, 4 2, 3
4 3) 1, 2, 0, 3, 4
5 4) 0 1, 0 2, 0
6 5) 0, 0, 0
7 6) 1, 1, 10
8 7) - 1, - 1, - 1
9 8) -1, -2, 01, -31
10 9) -1</pre>, -2, 0, -3
10) -1
</pre>
<br><br>
 
=={{header|EchoLisp}}==