# Thomas Sznigir # Experimental Math 2013 # Homework 1 Help:=proc() "S(n), FindUPi(L,i), FindUP(L)" end; # Problem 2 # Write a procedure S(n) that inputs a positive integer n, and outputs # the n-th Somos number, defined by the recurrence # S(n)*S(n+4) = S(n+1)*S(n+3) + S(n+2)^2 # with S(1)=1, S(2)=1, S(3)=1, S(4)=1 S:=proc(n) option remember; if n<=4 then 1 else (S(n-1)*S(n-3) + S(n-2)^2)/S(n-4) fi: end; # S(100) = 11254620211190522918587505038854079735085781984770090684874573 # 83081209014389975447649202847470803397649028346834774866733482518062371 # 87378393519418140863553947692267839180217047192175888151401408811182588 # 72414937589916237955964575517516612474588971325540777682152334672796111 # 41983233218869284945473025531264380269332131219867803913785103661820562 # 08364333632820941086849450357694748057218843196851672256371098273090597 # 870386 # Problem 3 # Write a procedure, FindUPi(L,i), that inputs a list of numbers, and a # positive integer i, and finds out whether there exists a list M of length # i, such that L ends with at least three repeated copies of M, or else # returns FAIL. FindUPi:=proc(L,i) if op(L[-i..-1])=op(L[-2*i..-i-1]) and op(L[-2*i..-i-1])=op(L[-3*i..-2*i-1]) then L[-i..-1] else FAIL fi: end; # Problem 4 # Write a procedure, FindUP(L), that inputs a list of numbers, and finds out # whether there exists a list M, such that L ends with at least three repeated # copies of M, or else returns FAIL. # This procedure calls FindUPi and iterates from i = 1 until i equals one-third the # length of the list. The reason is that a sublist cannot be repeated three times # if it is longer than that. It returns the first sublist found in this manner. FindUP:=proc(L) local result,i; for i from 1 to numelems(L)/3 do result:=FindUPi(L,i); if not result=FAIL then break fi: od: result end;