Pensieve header: The package “Perm”, day 2.

Note. Just one hour today!

Topics (in no particular order). Whatever you may suggest; whatever comes to my mind; the Fibonacci numbers; the Catalan numbers; the Jones polynomial; a more efficient Jones algorithm; a riddle on spheres; Khovanov homology; Γ-calculus; the Hopf fibration; Hilbert’s 13th problem; non-commutative Gaussian elimination; free Lie algebras; the Baker-Campbell-Hausdorff formula; wacky numbers; an order 4 torus; the Schwarz Lantern; knot colourings; the Temperley-Lieb pairing; the dodecahedral link; sound experiments; barycentric subdivisions; some Peano curves; braid closures and Vogel’s algorithm; the insolubility of the quintic; phase portraits; the Mandelbrot set; shadows of the Cantor aerogel; quilt plots; some image transformations; De Bruijn graphs; the Riemann series theorem; finite type invariants and the Willerton fish; the Towers of Hanoi; Hochschild homology of (some) coalgebras; convolutions and image improvements; the 8-5-3 milk jug problem; a cow problem, a permutations package.

The 8-5-3 Milk Jug Problem

Problem. A Milk (chairman -> Chair, so milkman -> Milk) has three jugs of milk, one carrying 8 liters, one 5 liters, and one 3 liters. The 8 liter jug is full, the other two are empty. Can they measure 4 liters of milk?

Challenge. Draw the state graph of this problem (with spilling allowed and also without).

An NCGE Challenge

Update the NCGE program to contain “backtracking information”. Use it to find how to turn the lower face of a Rubik’s cube by turning all but the lower face of that cube.

The Mathematica Package Perm

Challenge. Re-implement permutations, though using the standard “list of images” notation for permutations: Perm[5,2,3,1,4], etc. Your package should know σ∘τ, (σ^(-1)), σ[[i]], Pivot[σ], IdentityPermutation[n], it should interact well with Cycles, and its internals should be hidden.

Some Early Definitions

Perm::usage = "Perm[5,2,3,1,4] means the permutation that maps 1->5, 2->2, 3->3, 4->1, 5->4.";

?Perm

PermutationQ[σ_Perm] := Sort[List@@σ]===Range[Length[σ]]

PermutationQ /@ {Perm[2,3,1], Perm[1,2,2]}

σ_Perm ∘ τ_Perm /; Length[σ]==Length[τ] :=σ[[List@@τ]];

Perm /:(((σ_Perm))^(-1)) /; PermutationQ[σ]:= (
τ=σ;
Do[τ[[σ[[i]]]]=i, {i,Length[σ]}];
τ
)

((Perm[2,3,1])^(-1))

Contexts

Every symbol used within a Mathematica session has a “context”.

?Context

?$Context

{Context[],$Context, cow=7, Context[cow], Context[Plus]}

{Horse`pig=8, pig, Horse`pig}

?Contexts

Contexts[] // Short

?$ContextPath

$ContextPath

PrependTo[$ContextPath, "Horse`"];

pig

Global`pig=9

pig

$ContextPath=Rest[$ContextPath]

pig

The Structure of Packages

?BeginPackage

?Begin

?End

?EndPackage

p=RandomPermutation[40]

Cycles2Perm[c_Cycles] := jksakjgsakjlfgadhjklf

Perm[c_Cycles] := sjkghjkasgjkhsa

Cycles[p_Perm] := jfjkhgaskjgjkasfd