Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /MLRISC/releases/release-110.84/library/probability.sml
ViewVC logotype

Diff of /MLRISC/releases/release-110.84/library/probability.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1135, Tue Mar 12 16:09:26 2002 UTC revision 1136, Tue Mar 12 19:44:02 2002 UTC
# Line 13  Line 13 
13      exception BadProb      exception BadProb
14    
15      val never : prob    (* 0% probability *)      val never : prob    (* 0% probability *)
16        val unlikely : prob (* very close to 0% *)
17        val likely : prob   (* very close to 100% *)
18      val always : prob   (* 100% probability *)      val always : prob   (* 100% probability *)
19    
20      val prob : (int * int) -> prob      val prob : (int * int) -> prob
# Line 45  Line 47 
47      exception BadProb      exception BadProb
48    
49      val never = PROB(0w0, 0w0)      val never = PROB(0w0, 0w0)
50        val unlikely = PROB(0w1, 0w1000)
51        val likely = PROB(0w999, 0w1000)
52      val always = PROB(0w1, 0w1)      val always = PROB(0w1, 0w1)
53    
54    (* Fast GCD on words.  This algorithm is based on the following    (* Fast GCD on words.  This algorithm is based on the following
# Line 74  Line 78 
78        | normalize (n, d) = (case Word.compare(n, d)        | normalize (n, d) = (case Word.compare(n, d)
79             of LESS => (case gcd(n, d)             of LESS => (case gcd(n, d)
80                   of 0w1 => PROB(n, d)                   of 0w1 => PROB(n, d)
81                    | g => PROB(Word.div(n, g), g)                    | g => PROB(Word.div(n, g), Word.div(d, g))
82                  (* end case *))                  (* end case *))
83              | EQUAL => always              | EQUAL => always
84              | GREATER => raise BadProb              | GREATER => raise BadProb
# Line 99  Line 103 
103      fun divide (PROB(n, d), m) = if (m <= 0)      fun divide (PROB(n, d), m) = if (m <= 0)
104            then raise BadProb            then raise BadProb
105            else if (n = 0w0) then never            else if (n = 0w0) then never
106            else normalize(d, n * Word.fromInt m)            else normalize(n, d * Word.fromInt m)
107    
108      fun percent n =      fun percent n =
109            if (n < 0) then raise BadProb            if (n < 0) then raise BadProb

Legend:
Removed from v.1135  
changed lines
  Added in v.1136

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0