Pete Corey Writing Work Contact

A Better Mandelbrot Iterator in J

Written by Pete Corey on Mar 18, 2019.

Nearly a year ago I wrote about using the J programming language to write a Mandelbrot fractal renderer. I proudly exclaimed that J could be used to “write out expressions like we’d write English sentences,” and immediately proceeded to write a nonsensical, overcomplicated solution.

My final solution bit off more than it needed to chew. The next verb we wrote both calculated the next value of iterating on the Mandelbrot formula and also managed appending that value to a list of previously calculated values.

I nonchalantly explained:

This expression is saying that next “is” (=:) the “first element of the array” ({.) “plus” (+) the “square of the last element of the array” (*:@:{:). That last verb combines the “square” (*:) and “last” ({:) verbs together with the “at” (@:) adverb.

Flows off the tongue, right?

My time spent using J to solve last year’s Advent of Code challenges has shown me that a much simpler solution exists, and it can flow out of you in a fluent way if you just stop fighting the language and relax a little.


Let’s refresh ourselves on Mandelbrot fractals before we dive in. The heart of the Mandelbrot fractal is this iterative equation:

The Mandelbrot set equation.

In English, the next value of z is some constant, c, plus the square of our previous value of z. To render a picture of the Mandelbrot fractal, we map some section of the complex plane onto the screen, so that every pixel maps to some value of c. We iterate on this equation until we decide that the values being calculated either remain small, or diverge to infinity. Every value of c that doesn’t diverge is part of the Mandelbrot set.

But let’s back up. We just said that “the next value of z is some constant, c, plus the square of our previous value of z”.

We can write that in J:

   +*:

And we can plug in example values for c (0.2j0.2) and z (0):

   0.2j0.2 (+*:) 0
0.2j0.2

Our next value of z is c (0.2j0.2) plus (+) the square (*:) of our previous value of z (0). Easy!


My previous solution built up an array of our iterated values of z by manually pulling c and previously iterated values off of the array and pushing new values onto the end. Is there a better way?

Absolutely. If I had read the documentation on the “power” verb (^:), I would have noticed that “boxing” (<) the number of times we want to apply our verb will return an array filled with the results of every intermediate application.

Put simply, we can repeatedly apply our iterator like so:

   0.2j0.2 (+*:)^:(<5) 0
0 0.2j0.2 0.2j0.28 0.1616j0.312 0.128771j0.300838

Lastly, it’s conceivable that we might want to switch the order of our inputs. Currently, our value for c is on the left and our initial value of z is on the right. If we’re applying this verb to an array of c values, we’d probably want c to be the right-hand argument and our initial z value to be a bound left-hand argument.

That’s a simple fix thanks to the “passive” verb (~):

   0 (+*:)^:(<5)~ 0.2j0.2
0 0.2j0.2 0.2j0.28 0.1616j0.312 0.128771j0.300838

We can even plot our iterations to make sure that everything looks as we’d expect.

Our plotted iteration for a C value of 0.2 + 0.2i.


I’m not going to lie and claim that J is an elegantly ergonomic language. In truth, it’s a weird one. But as I use J more and more, I’m finding that it has a certain charm. I’ll often be implementing some tedious solution for a problem in Javascript or Elixir and find myself fantasizing about how easily I could write an equivalent solution in J.

That said, I definitely haven’t found a shortcut for learning the language. Tricks like “reading and writing J like English” only really work at a hand-wavingly superficial level. I’ve found that learning J really just takes time, and as I spend more time with the language, I can feel myself “settling into it” and its unique ways of looking at computation.

If you’re interested in learning J, check out my previous articles on the subject and be sure to visit the JSoftware home page for books, guides, and documentation.

Secure Meteor is Live

Written by Pete Corey on Mar 4, 2019.

The big day is finally here. Secure Meteor is live and available for purchase!

Secure Meteor is the culmination of all of my work as a Meteor security professional. Between the years of 2014 and 2017 I completely immersed myself in the Meteor ecosystem and became increasingly focused on the unique security characteristics of Meteor applications. I wrote and spoke about Meteor security,built security-focused tools and packages for the Meteor ecosystem, and worked hands-on with talented teams to better secure their Meteor applications. Secure Meteor is the embodiment of everything I learned about Meteor security during that time.

It’s my goal that reading Secure Meteor will teach you the ins and outs of the various attack vectors present in your Meteor application, and will also teach you how to see your application through the eyes of a potential attacker.

Check out the Secure Meteor page for more details, samples chapters, and to snag your copy today!

On a personal note, it’s been over a year since I first announced and started working on Secure Meteor. There were many times over the past year when I never thought I’d finish. Writing a book has always been a personal goal of mine, and I couldn’t be more happy to have persevered and seen this project through to completion.

I deeply believe that Secure Meteor is a valuable addition to the Meteor community, and I’m happy to be giving back to a community that has given so much to me over the years.

Thanks for all of your support.

Secure Meteor Releasing Next Week!

Written by Pete Corey on Feb 25, 2019.

You may have noticed that I haven’t been doing much publicly in 2019. I haven’t released any new articles, I haven’t send out any newsletters, and I’ve been relatively quiet on Twitter.

Underneath the surface of this calm lake of inactivity, my little duck feet have been churning. I’ve been pursuing one of my main goals for the new year and working diligently to finish my first book, Secure Meteor. I’m excited to announce that I’ll be releasing Secure Meteor early next week!

Between the years of 2014 and 2017, I lived and breathed Meteor security. I spent those years writing and speaking about Meteor security, developing and deploying secure Meteor applications, working with amazing teams to better secure their Meteor applications, and building security-focused packages and tools for the Meteor ecosystem.

While Meteor doesn’t play as central of a role in my day-to-day development work today, it would be a shame to throw away all of the knowledge and expertise I built up around the ins-and-outs of securing Meteor applications.

Secure Meteor is an effort to capture and distill everything I’ve learned about Meteor security from my years of real-world Meteor security experience.

I’m happy to announce that over a year after originally announcing Secure Meteor, it’s ready to be released! The final product is one hundred ten pages of what I consider to be vitally important information on securing your Meteor application. If you are actively developing Meteor applications, or own a Meteor application living in production, Secure Meteor can help bring you understanding and peace of mind in the unforgiving world of software security.

Be sure to check out a few of the sample chapters to whet your whistle for next week’s release.

If you’re interested in the book, sign up for the Secure Meteor newsletter. Subscribers will be the first to know when Secure Meteor launches, and I might even offer them an initial discount for all of their support.

I couldn’t be more excited for next week. See you then!