Jump to content

Entropy: Difference between revisions

698 bytes added ,  4 years ago
No edit summary
Line 1,954:
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}}==
<lang pli>*process source xref attributes or(!);
357

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.