Display a linear combination: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: add spaces in output)
(change task description for better consistency between scalar indices and vector indices : indices begin at one, not zero)
Line 1: Line 1:
{{draft task}}
{{draft task}}


The purpose of this task is to display a finite [[wp:linear combination|linear combination]] in an infinite vector basis <math>(e_0, e_1,\ldots)</math>.
The purpose of this task is to display a finite [[wp:linear combination|linear combination]] in an infinite vector basis <math>(e_1, e_2,\ldots)</math>.


Write a function that, when given a finite list of scalars <math>(\alpha^1,\alpha^2,\ldots)</math>, creates a string representing the linear combination <math>\sum_i\alpha^i e_i</math>
Write a function that, when given a finite list of scalars <math>(\alpha^1,\alpha^2,\ldots)</math>, creates a string representing the linear combination <math>\sum_i\alpha^i e_i</math>
Line 7: Line 7:
Your output must comply to the following rules:
Your output must comply to the following rules:


* you don't show null terms, unless the whole combination is null. For instance while the output "0" is fine, "e(0) + 0*e(3)" or "0 + e(1)" are 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.
* you 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 scalars when they are equal to one or minus one. For instance the string "1*e(3)" is wrong.
* you don't prefix by '-' if it follows a preceding term. Instead you use subtraction. Thus "e(4) - e(5)" is correct while "e(4) + -e(5)" is wrong.
* you don't prefix by '-' if it follows a preceding term. Instead you use subtraction. Thus "e(4) - e(5)" is correct while "e(4) + -e(5)" is wrong.