C’est une pipe for Maxima


I really love the pipe operator $>$ introduced into R by the package magrittr.  Not least because of the reference to the piece pictured here — “The Treachery of Images” by the Belgian surrealist painter René Magritte.

I don’t know yet whether this will be a really useful Maxima feature, but it is easy enough to make a simple pipe operation using infix():

"%>%" (a,b):=b(a);


Notice the 2nd and 3rd arguments of infix() control the precedence of operations (the left and right hand binding powers lbp and rbp).  We want to set those values lower than lbp and rbp for multiplication * in 2*%pi  and for for addition + in 1+%i (which by default in Maxima have lbp=180 and rbp=180).  Here’s the maxima document that gives the details about operators and binding power.

To make the pipe idea slightly more powerful so as to work with functions like integrate() and diff() which require more than one argument, we could try something like this, which makes use of the matlab-like find() I wrote about recently.

"%>%" (a,b):=block([i,bb],
 if atom(b) then 
 else (


Note that we’ve introduced the convention that the piped expression is referred to as %P, and that we call functions using a lisp-like construction where diff(%P,x) becomes [diff,%P,x].


4 thoughts on “C’est une pipe for Maxima”

  1. Great post! I had the idea for the pipe operator a couple years ago and it is indeed very convenient. But I never took the time to implement it for n-ary functions. Now I know how 🙂 My operator is |> which I find more readable than %>%.


    1. I agree, the pipe is a great idea, but something nicer to look and easier to type than %>% would be nice (I’m too used to the simple vertical pipe | used in bash).

      |> works (and I think is the same way Julia does it).


  2. How do I format my comments with italics, fixed-width fonts, etc. in this blog? I’ve tried the usual conventions (*xxx*, > xxx, SPC SPC SPC SPC xxx, Ctrl-I, , etc.) and none of them seem to work (at least not while I’m composing — test below to see what happens when posted).

    > test
    | test


    1. Ah! They come out when posted. Could you share a link to the documentation on which codes are supported?

      This is a test.

      This is a test.
      And some indentation.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: