Secret Santa – Generating ‘valid’ permutations

What you’re looking for is called a derangement (another lovely Latinate word to know, like exsanguination and defenestration). The fraction of all permutations which are derangements approaches 1/e = approx 36.8% — so if you are generating random permutations, just keep generating them, and there’s a very high probability that you’ll find one within 5 … Read more

Currying with Mathematica

I don’t think there is any way to have attributes apply to the later parts of such an “upvalue” pattern definition. One alternative is to use pure functions with attributes. Not as convenient as pattern matching, but when you evaluate f[2+2][8/4], it actually gives a result Curry would have liked. (“Function” is Mathematica’s “lambda”, if … Read more

Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc etc

These are pretty tricky constructs, and it’s tough to give clear explanations; they aren’t as straightforward as Lisp macros (or, for that matter, the relationship between Lisp’s QUOTE and EVAL). However, there’s a good, lengthy discussion available in the form of notes from Robby Villegas’s 1999 talk “Unevaluated Expressions” on Wolfram’s website. Defer is omitted … Read more

How to determine PlotRange to include all of graphics?

I can suggest the following Ticks hack: pl = Plot[Sin[x], {x, 0, 10}]; Reap[Rasterize[Show[pl, Ticks -> {Sow[{##}] &, Sow[{##}] &}, ImageSize -> 0], ImageResolution -> 1]][[2, 1]] => {{-0.208333, 10.2083}, {-1.04167, 1.04167}} The trick is that real PlotRange is determined by the FrontEnd, not by the Kernel. So we must force the FrontEnd to render … Read more

Customizing Mathematica shortcuts

Here is a nice article. Also, FROM HERE (unchecked) Question: How do I modify the front end to add new keyboard shortcuts? Answer: (mathgroup May 2005, trevor baca:) I’ve been mucking around in KeyEventTranslations.tr setting up keyboard shortcuts recently and i’ve learned that front end tokens are pretty cool. this wolfram page gives pretty good … Read more

Simple programming techniques / tricks in Mathematica for making graphics for the math book? [closed]

Here is a simple/basic way to do the first one: Graphics[{ (* The dashed circle segment *) { Dashing[{.04, .01}], Darker[Orange], AbsoluteThickness[2], Circle[{0, 0}, 1, {1, 2 \[Pi]}] }, (* The solid circle segment *) { Orange, AbsoluteThickness[2], Circle[{0, 0}, 1, {0, 1}] }, (* The radial lines and the small circle segment *) Line[{{0, … Read more

How to plot a gene graph for a DNA sequence say ATGCCGCTGCGC?

I did not previously know of Mark McClure’s blog about Chaos Game representation of gene sequences, but it reminded me of an article by Jose Manuel GutiĆ©rrez (The Mathematica Journal Vol 9 Issue 2), which also gives a chaos game algorithm for an IFS using (the four bases of) DNA sequences. A detailed description may … Read more