HP Forums
(48G) 48G , 49G & 50G: Entropy calculation programme - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (48G) 48G , 49G & 50G: Entropy calculation programme (/thread-4075.html)



(48G) 48G , 49G & 50G: Entropy calculation programme - Gerald H - 06-04-2015 06:47 PM

A programme for the 48G ( and 49G, 49G+, 50G - no need to change anything) to calculate the entropy of a system given a list of the state probabilities - if the sum of probabilities is < 1 the programme adds one state with the missing probability.

eg For input

{ .1 .2 .3 }

the programme returns

{ .1 .2 .3}
:Extra-Prob: .4
:Ent: 1.84643934468

Code:
::
  CK1&Dispatch
  BINT5
  ::
    DUP
    DUPINCOMP
    DUP#0=case
    SETTYPEERR
    %0
    SWAP
    ZERO_DO
    SWAP
    DUPTYPEREAL?
    ::
      NcaseTYPEERR
      %+
    ;
    LOOP
    DUP
    %1
    %>
    caseSIZEERR
    %1
    SWAP
    %-
    DUPROT
    INNERCOMP
    %0
    SWAP1+
    ZERO_DO
    SWAP
    DUP%0=
    ITE
    DROP
    ::
      DUP
      %LN
      %2
      %LN
      %/
      %*
      %+
    ;
    LOOP
    %CHS
    '   
    ID Ent
    ID>TAG
    SWAP
    DUP%0=
    caseDROP
    '
    ID Extra-Prob
    ID>TAG
    SWAP
  ;
;