Entropy: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,954: | Line 1,954: | ||
1234567890abcdefghijklmnopqrstuvwxyz : 5.169925</pre> |
1234567890abcdefghijklmnopqrstuvwxyz : 5.169925</pre> |
||
=={{header|PicoLisp}}== |
|||
PicoLisp only supports fixed point arithmetic, but it does have the ability to call libc transcendental functions (for log) |
|||
<lang PicoLisp> |
|||
(scl 8) |
|||
(load "@lib/math.l") |
|||
(setq LN2 0.693147180559945309417) |
|||
(de freq-table (Str) |
|||
(let Map NIL |
|||
(for Ch (chop Str) |
|||
(if (assoc Ch Map) |
|||
(con @ (inc (cdr @))) |
|||
(setq Map (cons (cons Ch 1) Map)))) |
|||
Map)) |
|||
(de entropy (Str) |
|||
(let ( |
|||
Sz (length Str) |
|||
S 0 |
|||
) |
|||
(for Counts (freq-table Str) |
|||
(let R (*/ (cdr Counts) 1. Sz) |
|||
(setq S (- S (*/ R (log R) 1.))))) |
|||
(*/ S 1. LN2))) |
|||
</lang> |
|||
{{Out}} |
|||
<pre> |
|||
: (format (entropy "1223334444") *Scl) |
|||
-> "1.84643934" |
|||
</pre> |
|||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
<lang pli>*process source xref attributes or(!); |
<lang pli>*process source xref attributes or(!); |