Sponsored links: Algebra eBooks
 

Help Index

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

The Maxima on-line user's manual

Algebra Calculator

Search:

Flatten Calculator

Flatten

Function: flatten (<expr>) Collects arguments of subexpressions which have the same operator as <expr> and constructs an expression from these collected arguments.

load(functs);
block([y:""], for i in (makelist(n, n, 1, 10)) do (y:flatten(append(makelist(i/100.0, i, i, i), [""]))), return(y));

Subexpressions in which the operator is different from the main operator of expr are copied without modification, even if they, in turn, contain some subexpressions in which the operator is the same as for expr.

It may be possible for flatten to construct expressions in which the number of arguments differs from the declared arguments for an operator; this may provoke an error message from the simplifier or evaluator. flatten does not try to detect such situations.

Expressions with special representations, for example, canonical rational expressions (CRE), cannot be flattened; in such cases, flatten returns its argument unchanged.

Examples:

Applied to a list, flatten gathers all list elements that are lists.

          (%i1) flatten ([a, b, [c, [d, e], f], [[g, h]], i, j]);
          (%o1)            [a, b, c, d, e, f, g, h, i, j]

Applied to a set, flatten gathers all members of set elements that are sets.

          (%i1) flatten ({a, {b}, {{c}}});
          (%o1)                       {a, b, c}
          (%i2) flatten ({a, {[a], {a}}});
          (%o2)                       {a, [a]}

flatten is similar to the effect of declaring the main operator n-ary. However, flatten has no effect on subexpressions which have an operator different from the main operator, while an n-ary declaration affects those.

          (%i1) expr: flatten (f (g (f (f (x)))));
          (%o1)                     f(g(f(f(x))))
          (%i2) declare (f, nary);
          (%o2)                         done
          (%i3) ev (expr);
          (%o3)                      f(g(f(x)))

flatten treats subscripted functions the same as any other operator.

          (%i1) flatten (f[5] (f[5] (x, y), z));
          (%o1)                      f (x, y, z)
                                      5

It may be possible for flatten to construct expressions in which the number of arguments differs from the declared arguments for an operator;

          (%i1) mod (5, mod (7, 4));
          (%o1)                   mod(5, mod(7, 4))
          (%i2) flatten (%);
          (%o2)                     mod(5, 7, 4)
          (%i3) %, nouns;
          Wrong number of arguments to mod
           -- an error.  Quitting.  To debug this try debugmode(true);

(%o1)                                true
(%i2) 

Flatten Example

Related Examples

flatten-map-solve

Polynom:a*x^3+b*x^2+c...

f(x):=''Polynom;

g1:f(-5)=0;

Calculate

flatten-map-solve

Polynom:a*x^3+b*x^2+c...

f(x):=''Polynom;

g1:f(-5)=0;

Calculate

flatten-part-solve

e1:ib = s*Cpi*(vb-ve);

e2:s*Cpi*(vb-ve) + gm...

part(flatten(solve([e...

Calculate

flatten-matrix

flatten(matrix([1,2,3...

flatten(matrix([1],[2...

Calculate

flatten

flatten([[2],2,3]);

Calculate

flatten-map-solve

Polynom:a*x^3+b*x^2+c...

f(x):=''Polynom;

g1:f(-5)=0;

Calculate

flatten-load-map

load(descriptive);

mean(map(rhs, flatten...

Calculate

flatten

flatten([[2,3],2,3]);

Calculate

flatten

flatten([[2],2,3]);

Calculate

flatten-genmatrix

f[i,j] := i+j;

m : genmatrix(f,1,4);

flatten(m);

Calculate