#!/usr/local/bin/maple # -*- maplev -*- # Nathaniel Shar # HW 11 # Experimental Mathematics # It is okay to link to this assignment on the course webpage. Help := proc(): print(`Curl(L), List23(n), RefinedLists(n), CurlSeq(init), MaxCurl(n), MuSeq()`): end: ############# # Problem 1 # ############# # Running MaxCurl(n) gives what the paper calls mu(n). Running # MuSeq() prints out MaxCurl(n) for n = 2, 3, ... # Results: I got up to n=19 in one hour, but the ssh connection died # before it finished (and the timing didn't seem to be # accurate). 19 is disappointingly small, but since the code is not # optimized and it's not running on a fast machine, it is perhaps to # be expected. # The results matched those in the paper. ############# # Produce the curling number of the list. Curl := proc(L) local n, tail, best, i: n := nops(L): best := 1: tail := []: for i from 1 to n/2 do: tail := [L[n-i+1], op(tail)]: if i<=n/4 and L[n-4*i+1..n-3*i] = L[n-3*i+1..n-2*i] and L[n-3*i+1..n-2*i] = L[n-2*i+1..n-i] and L[n-2*i+1..n-i] = L[n-i+1..n] then: return 4: elif i<=n/3 and L[n-3*i+1..n-2*i]= L[n-2*i+1..n-i] and L[n-2*i+1..n-i] = L[n-i+1..n] then: best := 3: elif L[n-2*i+1..n-i] = L[n-i+1..n] then: if best < 2 then: best := 2: fi: fi: od: return best: end: # Produces the lists of n 2s and 3s, and eliminates anything with # curling number 4. List23 := proc(n) local L, allLists, goodLists: option remember: if n = 0 then return [[]]: fi: goodLists := []: allLists := [seq([op(L), 2], L=List23(n-1)), seq([op(L), 3], L=List23(n-1))]: for L in allLists do: if Curl(L) < 4 then: goodLists := [op(goodLists), L]: fi: od: return goodLists: end: # Returns the lists that do not satisfy Curl(L[1..n-1]) = L[n]. RefinedLists := proc(n) local L, allLists, goodLists: allLists := List23(n): for L in allLists do: if Curl(L[1..n-1]) <> L[n] then: goodLists := [op(goodLists), L]: fi: od: return goodLists: end: # Repeatedly appends curling number until 1 is reached CurlSeq := proc(init) local L, c: L := init: while true do: c := Curl(L): if c = 1 then: return [nops(L), [op(L), c]]: else: L := [op(L), c]: fi: od: end: # Locates the sequence that grows to longest length with repeated # appending of curling number. MaxCurl := proc(n) local maximum, r, L: maximum := [0, []]: for L in RefinedLists(n) do: r := CurlSeq(L): if r[1] > maximum[1] then: maximum := r: fi: od: return maximum: end: # Generates the sequence mu(n) and prints out the values as they are # found MuSeq := proc() local i: i := 2: while true do: printf("%d: %s\n", i, convert(MaxCurl(i), string)): i := i+1: od: end: