Talk:Hofstadter Figure-Figure sequences: Difference between revisions

m
(→‎timings for the REXX solutions: updated program and its timing, removed an old spurious timing.)
m (→‎timings for the REXX solutions: changed verb tense.)
 
(8 intermediate revisions by 3 users not shown)
Line 18:
:::Not really, this aspect of the definition is present in the references too. I suspect that it may be a part of the original description cited as: D. Hofstadter, "Gödel, Escher, Bach", p. 73, but I don't have it to hand at the moment to check. When I first saw their definition I found it confusing at first too, but that is what made it interesting when trying to code it.
 
::: When I had finished the Python version I checked it with tables of the first 1000 values refered to from Sloane: [http://oeis.org/A005228/b005228.txt here] for R and [http://oeis.org/A005228A030124/b005228b030124.txt here] for S, although the table for S has an off-by-one error. --[[User:Paddy3118|Paddy3118]] 18:31, 22 October 2011 (UTC)
 
::: Another ref. with a similar definition: [http://books.google.co.uk/books?id=aFDWuZZslUUC&pg=PA1385&dq=%22Figure-Figure+sequences%22+Hofstadter,+%22G%C3%B6del,+Escher,+Bach%22,+p.+73&hl=en&ei=cw2jTt7OBMiA8gOD78zYBQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CDEQ6AEwAA#v=onepage&q&f=false CRC concise encyclopedia of mathematics By Eric W. Weisstein pp 1385]. --[[User:Paddy3118|Paddy3118]] 18:40, 22 October 2011 (UTC)
Line 32:
 
==timings for the REXX solutions==
I normally don't includinginclude timings for the REXX solutions that I post, but when I saw the 2<sup>nd</sup> REXX example's timings, <br>
 
I normally don't including timings for the REXX solutions that I post, but when I saw the 2<sup>nd</sup> REXX example's timings, <br>
I decided to go back and include the timings here as the REXX 2<sup>nd</sup> example's timings seemed a bit high.
 
<br>I didn't expect a difference of threeseveral orders of magnitude.
<lang rexx>/*REXX pgmprogram calculates &and verifies the Hofstadter Figure-FigureFigure─Figure sequences. */
call time 'Reset████████████████████████████████████████████████████████████████████████████████'
call time 'Reset'
parse arg x hightop bot . /*obtain anyoptional C.L.arguments specifications.from the CL*/
if x=='' | x=="," then x= 10; if high=='' then high=1000 /*Not specified? Then use the defaults?default.*/
if bottop=='' | top=="," then bottop=401000 /* " " " /* " " " */
lowif bot==1;'' | if x<0bot=="," then lowbot=abs(x) 40 /*only show" " " " " a single " │X│ value.*/
r.low=01; r.1=1; rr.=r.; if x<0 rr.1then low=1abs(x) /*initializeonly display a thesingle R│X│ & RRvalue? arrays.*/
sr.=0; sr.1=2 1; rr.=r.; rr.1=1; s.=r.; s.1=2 /*initialize the R, RR, " " and S arrayarrays. */
exiterrs=0 /*stickthe number aof forkerrors infound it, we're(so donefar).*/
errs=0; $.=0
do i=low to abs(x) /*showdisplay the 1st first X values of R & S .*/
say right('R('i") =",20) right(ffrFFR(i),7), right('S('i") /*show=",20) nice*/right(FFS(i),7)
right('S('i") =",20) right(ffs(i),7)end /* R & S i*/
end /*i [↑] list the 1st X Fig─Fig numbers.*/
if x<1 then exit /*if X xisn't ≤ 0positive, then we're all done.*/
$.=0 /*initialize the memoization ($) array.*/
 
do m=1 for bot; r=ffrFFR(m); $.r=1; end /*calculate 1stthe first forty 40 R values.*/
end /*m*/ /* [↑] ($.) is used for memoization. */
 
@='duplicate number in R and S lists:' /* [↓] calc.check 1stfor 960duplicate #s Sin R values.& S*/
do n=1 for hightop-bot; s=ffsFFS(n); if $.s /*calculate thenthe callvalue of FFS(n). sErr @ s; $.s=1; end*/
do v=1 for high; if \$.vs then call sErr ser 'missingduplicate number in R and S lists:' vs; end$.s=1
 
end /*n*/ /* [] verifycalculate the 1st all960 1≤#≤1kS presentvalues.*/
/* [↓] check for missing values in R│S*/
do v=1 for high; if \$.v then call sErr 'missing R │ S:' v; end
do v=1 for top; if \$.v then call ser 'missing R │ S:' v
say 'took' format(time('Elapsed'),,2) "seconds."
end /*v*/ /* [↑] are all 1≤ numbers ≤1k present?*/
say
if errs==0 then say 'verification completed for all numbers from 1 ──►' hightop " [inclusive]."
else say 'verification failed with' errs "errors."
say 'and took' format(time('Elapsed█████████████████████████████████████████████████████████████████'),,2) "seconds."
exit /*stick a fork in it, we're done.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────FFR subroutine──────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffr: procedure expose r. s. rr.; parse arg n
ifFFR: r.n\==0 thenprocedure returnexpose r.n rr. s.; parse arg n /*Defined?obtain the Thennumber returnfrom the valuearguments.*/
_=ffr(n-1) + ffs(n-1) if r.n\==0 then return r.n /*calculate the FFR value /*R.n defined? Then return the value.*/
r.n=_; rr._=FFR(n-1;) + FFS(n-1) return _ /*assigncalculate the FFR value toand R &FFS RR; returnvalues.*/
r.n=_; rr._=1; return _ /*assign the value to R & RR; return.*/
/*──────────────────────────────────FFS subroutine──────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
ffs: procedure expose r. s. rr.; parse arg n /*search for ¬null R│S #.*/
ifFFS: s.n==0procedure thenexpose r. dos. k=1rr.; parse forarg n /*search for not null /*R [↓]or S 1st IF is a shortnumber. circuit*/
if s.n==0 then do k=1 for n if s.k\==0 then if r.k\==0 then iterate /* [↓] 1st IF is a SHORT CIRCUIT. */
call ffr k if s.k\==0 then if r.k\==0 then iterate /*define R.k via FFR/*are both subroutinedefined?*/
km= call FFR k-1; _=s.km+1 /*thedefine next R.k S via number,the FFR possibly. subroutine*/
_ km=_+rr._k-1; _=s.k=_km+1 /*definecalc. anthe element ofnext S arraynumber, possibly.*/
end _=_+rr._; s.k=_ /*kdefine an element of the S array. */
return s.n end /*return the value to the invokerk*/
return s.n /*return S.n value to the invoker. */
/*──────────────────────────────────SERR subroutine─────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sErrser: errs=errs+1; say '***error***!' arg(1); return</lang>
'''output''' &nbsp; when using the defaultsdefault inputs:
<pre>
R(1) = 1 S(1) = 2
Line 92 ⟶ 93:
R(9) = 56 S(9) = 13
R(10) = 69 S(10) = 14
took 0.22 seconds.
 
verification completed for all numbers from 1 ──► 1000 [inclusive].
 
and took 0.22 seconds.
</pre>
The (above) example was run under Windows 7 on aan HPair-gap boxPC (3.2GHz2 GHz) using Regina REXX version 3.9.1.
<br><br>
 
==Formulae hidden to most browsers by under-tested cosmetic edits at 18:19, 28 August 2016 ==
 
Under-tested cosmetic edits made to the task page at 18:19, 28 August 2016, including the injection of spaces around expressions in &lt;math&gt; tags, have left some or all of the task description formulae completely invisible to all browsers which display the graphic file version of formulae rather than processing the MathML (this is, in fact, the majority of browsers). The MediaWiki processor does not currently expect such spaces, and generates syntactically ill-formed HTML if they are introduced. Other aspects of these cosmetic edits may further compound the problem. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 19:50, 22 September 2016 (UTC)
 
: Visibility of formulae now restored for mainstream browsers like Chrome, IE Edge, Safari, Opera etc [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 12:59, 21 November 2016 (UTC)