Talk:Entropy: Difference between revisions

3,158 bytes added ,  10 years ago
→‎REXX (log2): added some comments/answers to/for a multiple query, added an expatiated LOG2 function. -- ~~~~
m (→‎REXX (log2): correct indentation)
(→‎REXX (log2): added some comments/answers to/for a multiple query, added an expatiated LOG2 function. -- ~~~~)
Line 45:
"The LOG2 subroutine in only included here for functionality, not to document how to calculate LOG2 using REXX"
:: What's the difference and where is it / should it be documented?
 
::: Difference between what?
 
::: The LOG2 function should/could be documented in a Rosetta Code task that asks for a user-written version of LN/LOG2/LOG (as opposed to one that is a BIF).   Documenting a subroutine that is a BIF (built-in function) for most languages would just make the LOG2 function much too bulky and detract from the task's requirement:   ''solve the entropy problem''.   The REXX LOG2 function (which is a modified LN function) was originally written to be compact and written as a ''one-liner'' function, intended to be placed at the end of the program that it was needed (it, and another hundred or so subroutines/functions --- that's no exaggeration).   Strictly speaking, the   '''E'''   value was originally a function, but it was abbreviated here (about 80 decimal digits as a constant rather than a function call) to save even more space and complexity.   Also omitted were error checks that were in the original LN function, as well as   SIGNAL ON NOVALUE;   SIGNAL ON SYNTAX,   SIGNAL ON HALT, and the mechanism of issuing/displaying the error message(s) and the offending REXX statements.   At lot of crafting went into the writing of the original LN function (this was under CMS REXX and then ported to PC/REXX in 1989, as I recall).   PC/REXX has some restrictions on the number of symbols, the aggregate size of the values of the variables, and the size of the REXX program. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:47, 28 May 2013 (UTC)
 
:: Take 'my' (now corrected - thanks) log as an example --[[User:Walterpachl|Walterpachl]]
 
::: If this Rosetta Code task was to explain how LN (or LOG2) was calculated, that would be appropriate. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:47, 28 May 2013 (UTC)
 
::: Here's a version of the (REXX) LOG2 function, unrolled and expatiated: -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:47, 28 May 2013 (UTC)
<lang rexx>/*──────────────────────────────────LOG2 subroutine───────────────────────────*/
log2: procedure
parse arg x 1 xx
ig= x>1.5
is= 1 - 2*(ig\==1)
numeric digits digits()+5 /* [↓] precision of E must be > digits().*/
e=2.7182818284590452353602874713526624977572470936999595749669676277240766303535
ii=0
 
do while ig & xx>1.5 | \ig & xx<.5
 
_=e
do j=-1
iz=xx* _**-is
if j>=0 then if ig & iz<1 | \ig&iz>.5 then leave
_=_*_
izz=iz
end /*j*/
 
xx=izz
ii=ii + is* 2**j
end /*while*/
 
x=x * e**-ii -1
z=0
_=-1
p=z
 
do k=1
_=-_*x
z=z+_/k
if z=p then leave
p=z
end /*k*/
 
r=z+ii
 
if arg()==2 then return r
return r / log2(2,0)</lang>