Archives for mathematica

Clojuratica announced

Life is sweet. Yesterday a friend came by. He had purchased a Macbook Pro, and wanted to me his Levovo T60 that he no longer needed. Today Garth Sheldon-Coulson announced Clojuratica, an interface between Clojure and Mathematica. This is the stuff that software dreams are made of.

Rebinding Mathematica keys

Out of the box, Mathematica expects the user to press the SHIFT-RETURN to trigger the evaluation of an expression. Because of my hard-wired emacs reflexes, I frequently type CONTROL-RETURN instead. Today I finally did something about that. I rebound the SHIFT-RETURN sequence.
Mathematica does not make that easy to do. I found nothing [...]

Too lazy to flip coins

I was helping my daughter with some math homework; one of the problems was to flip three coins and tabulate the number of heads over the course of eighty trials. This struck me as excessively tedious, so I suggested we write a computer simulation instead.
Here it is, in its full glory:
coin := Random[Integer, {0, 1}]
flips [...]

x + x = 2x

This post is the second in a series. The first is here. The plan for this post is to introduce just enough notation to define some functions in the Mathematica language, and then use Mathematica to solve a not-entirely-trivial problem.
The central idiom in functional programming is applying a function f to an argument x. [...]

The unknown functional language

Functional languages are experiencing something of a renaissance, or so I gather from reading reddit and the blogs. I have been known to dabble in lisp, erlang, and haskell. Each is beautiful language in its own way. But when I actually want to get something done, not just play, I turn to either python or [...]

Euler 100

Euler Project problems can be addictive. This one gave me fits.

If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs, P(BB) = (15/21)×(14/20) = 1/2.
The next such arrangement, [...]

Euler 183

I have not worked a Euler Project problem in some time. Here’s problem 183:

Let N be a positive integer and let N be split into k equal parts, r = N/k, so that N = r + r + … + r.
Let P be the product of these parts, P = r × [...]

generating random permutations

I want to consider the simulation of dealing a deck of cards. The deck is simply the list of integers D = [1,2,...,52]. Dealing the cards amounts to generating a random permutation of D.
Here’s how I would do it in java.
public class Shuffle {
private static java.util.Random rand = new java.util.Random();
[...]