Mathematica 9 is now available
 Documentation / Mathematica / Built-in Functions / Programming / Attributes  /
Flat

  • Flat is an attribute that can be assigned to a symbol f to indicate that all expressions involving nested functions f should be flattened out. This property is accounted for in pattern matching.
  • Flat corresponds to the mathematical property of associativity.
  • For a symbol f with attribute Flat, f [ f [ a , b ], f [ c ]] is automatically reduced to f [ a , b , c ].
  • Functions like Plus, Times and Dot are Flat.
  • For a Flat function f, the variables x and y in the pattern f [x_, y_] can correspond to any sequence of arguments.
  • The Flat attribute must be assigned before defining any values for a Flat function.
  • See the Mathematica book: Section 2.3.7Section 2.5.3.
  • See also: Orderless, OneIdentity.

    Further Examples

    Normally, functions that you define do not have any special attributes.

    In[1]:=

    Global`f

    Nothing special happens with this nest of f's.

    In[2]:=

    Out[2]=

    By assigning the attribute Flat to a function, you are specifying that all nestings of the functions should be flattened out.

    In[3]:=

    In[4]:=

    Out[4]=

    This is how to bring back the old behavior.

    In[5]:=



    Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
    THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
    SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.