Display a linear combination: Difference between revisions

Content added Content deleted
Line 39: Line 39:
{{trans|Python}}
{{trans|Python}}
<lang 11l>F linear(x)
<lang 11l>F linear(x)
V a = enumerate(x).filter2((i, v) -> v != 0).map((i, v) -> ‘#.e(#.0)’.format(I v == -1 {‘-’} E I v == 1 {‘’} E String(v)‘*’, i + 1))
V a = enumerate(x).filter2((i, v) -> v != 0).map2((i, v) -> ‘#.e(#.)’.format(I v == -1 {‘-’} E I v == 1 {‘’} E String(v)‘*’, i + 1))
R (I !a.empty {a} E [String(‘0’)]).join(‘ + ’).replace(‘ + -’, ‘ - ’)
R (I !a.empty {a} E [String(‘0’)]).join(‘ + ’).replace(‘ + -’, ‘ - ’)