--- title: "Probability" id: 60606 type: "computer_media" slug: "probability" url: "http://localhost/computer_media/probability/" markdown_url: "http://localhost/computer_media/probability.md" published_at: "2025-09-23T19:26:11+00:00" modified_at: "2026-04-01T19:00:00+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2019/02/20230809-041332.jpg" excerpt: "Enter event counts and time, and this Poisson probability calculator displays normalised percentage chances for up to 12 occurrences per time unit." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Mathematics" slug: "mathematics" taxonomy: "genre" url: "http://localhost/type/mathematics/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Probability%20%281983%29%28TS1000%29%28US%29%28Program%29.zip" mediadate: "1983" article_media: - id: 8621 title: "Program Printout: Probability" type: "article" url: "http://localhost/article/program-printout-probability/" media_type_tags: "Mathematics" --- # Probability This program computes a Poisson probability distribution for a user-defined number of occurrence categories (3 to 12) per unit of time. The user supplies the maximum occurrences per time unit, the total number of occurrences, and the total time; from these the mean rate D = B/C is derived. The program approximates e using the classic limit (1 + 1/B)^B rather than a built-in constant, then computes each Poisson term P(k) = e^(−D) · D^k / k! up to the chosen maximum. A correction factor N is formed by summing all computed terms so that the displayed percentages are normalised to the truncated distribution, and each percentage is rounded to two decimal places using the INT(x + 0.5) idiom. A running total is printed at the end of line 570 as a checksum. *** ## Program Structure The program is divided into four broad phases: 1. **Initialisation (lines 9–22):**`CLEAR` and zeroing of all accumulator variables (`S` through `BB`). 2. **Input (lines 25–95):** Three prompts collect the maximum occurrence count `A` (range 3–12), total occurrences `B`, and total time `C`. 3. **Computation (lines 100–366):** Mean rate, Poisson terms, normalisation sum, and rounded percentage values are calculated. 4. **Output (lines 370–570):** String labels are assigned and all results printed in a single long `PRINT` statement. ## Mathematical Approach The Poisson probability mass function P(k) = e−λ · λk / k! is computed term by term. The mean rate λ is `D = B/C`. Rather than using a stored constant for *e*, line 110 uses: `LET E=(1+(1/B))**B` This is the well-known limit definition of *e*, evaluated with `B` (total occurrences) as the large integer — a reasonable approximation when `B` is large, but it introduces compounding error for small `B`. The base probability `F = 1/E^D` (line 120) is e−D, and each subsequent term multiplies by powers of `D` divided by the factorial of k, hard-coded through 12! = 479001600 (line 237). ## Normalisation and Rounding Because the distribution is truncated at the user-chosen maximum, the sum of all computed raw probabilities `N` (line 255) will be less than 1.0 unless the tail beyond `A` is negligible. Each percentage is corrected by dividing by `N` before rounding: `LET PP=(INT (P*10000/N+0.5))/100` This is the standard Sinclair BASIC round-to-two-decimal-places idiom: multiply by 100× the desired precision, add 0.5, truncate with `INT`, then divide back. The final item in the `PRINT` at line 570 sums all percentage values as a checksum; due to rounding it may not equal exactly 100. ## Conditional Term Computation Lines 160–237 use a staircase of `IF A>=n THEN LET …` guards so that only terms up to the user-requested maximum are computed. Variables for unused terms remain at zero (set at lines 11–22), which is essential because they all enter the normalisation sum `N` at line 255 regardless. ## Variable Naming | Variable(s) | Role | | --- | --- | | `A` | Maximum occurrence count (3–12) | | `B` | Total occurrences (also used in e approximation) | | `C` | Total time units | | `D` | Mean rate λ = B/C | | `E` | Approximation of e | | `F` | e−D (base Poisson factor) | | `P`–`BB` | Raw Poisson probabilities for k = 0 … 12 | | `N` | Normalisation sum of raw probabilities | | `PP`–`BBB` | Rounded percentage values for k = 0 … 12 | | `A$`–`M$` | Label strings “0 OCCURRENCES” … “12 OCCURRENCES” | The program exhausts all single-letter numeric variables and must fall back to two-letter names (`AA`, `BB`) for k = 11 and k = 12, and three-letter names (`AAA`, `BBB`) for the corresponding percentages. ## Notable Techniques and Anomalies - The *e* approximation at line 110 reuses the input value `B` as the iteration count. This is unconventional and ties numerical accuracy to the data rather than using a fixed large integer or a stored constant. - Line 32 warns “RANGE ALLOWED 3 TO 12” but there is no validation; entering `A < 3` merely computes a reduced distribution (only k = 0, 1, 2 are always computed unconditionally via `P`, `Q`, `R`). Entering `A > 12` is silently ignored, capping results at 12. - All 13 labels and values are printed in one very long `PRINT` statement at line 570, which is syntactically valid but unusual and makes the line difficult to edit in the BASIC editor. - The `REM` at line 252 is the only comment in the program, labelling the normalisation step as a “CORRECTION FACTOR”. - Factorial denominators are entered as literal integers (e.g., `39916800` for 11!, `479001600` for 12!), which is correct but would overflow a 32-bit integer — here they are used as floating-point literals, so precision is adequate. ## Source Code ``` 9 CLEAR 10 PRINT " LONG TERM PROBABILITY STUDY" 11 LET S=0 12 LET T=0 13 LET U=0 14 LET V=0 15 LET W=0 16 LET X=0 17 LET Y=0 18 LET Z=0 20 LET AA=0 22 LET BB=0 25 PRINT 30 PRINT "INPUT THE MAXIMUM OCCURRENCES IN ANY ONE UNIT OF TIME " 31 PRINT 32 PRINT " RANGE ALLOWED 3 TO 12" 40 INPUT A 45 CLS 50 PRINT "INPUT TOTAL OCCURENCES" 60 INPUT B 70 PRINT 80 PRINT "INPUT TOTAL TIME" 90 INPUT C 95 CLS 100 LET D=B/C 110 LET E=(1+(1/B))**B 120 LET F=1/(E**D) 130 LET P=F 140 LET Q=D*F 150 LET R=D**2/2*F 160 IF A>=3 THEN LET S=D**3/6*F 170 IF A>=4 THEN LET T=D**4/24*F 180 IF A>=5 THEN LET U=D**5/120*F 190 IF A>=6 THEN LET V=D**6/720*F 200 IF A>=7 THEN LET W=D**7/5040*F 210 IF A>=8 THEN LET X=D**8/40320*F 220 IF A>=9 THEN LET Y=D**9/362880*F 230 IF A>=10 THEN LET Z=D**10/3628800*F 233 IF A>=11 THEN LET AA=D**11/39916800*F 237 IF A=12 THEN LET BB=D**12/479001600*F 240 PRINT "PROBABILITY OF","PERCENT" 250 PRINT 252 REM CORRECTION FACTOR 255 LET N=P+Q+R+S+T+U+V+W+X+Y+Z+AA+BB 260 LET PP=(INT (P*10000/N+0.5))/100 270 LET QQ=(INT (Q*10000/N+0.5))/100 280 LET RR=(INT (R*10000/N+0.5))/100 290 LET SS=(INT (S*10000/N+0.5))/100 300 LET TT=(INT (T*10000/N+0.5))/100 310 LET UU=(INT (U*10000/N+0.5))/100 320 LET VV=(INT (V*10000/N+0.5))/100 330 LET WW=(INT (W*10000/N+0.5))/100 340 LET XX=(INT (X*10000/N+0.5))/100 350 LET YY=(INT (Y*10000/N+0.5))/100 360 LET ZZ=(INT (Z*10000/N+0.5))/100 363 LET AAA=(INT (AA*10000/N+0.5))/100 366 LET BBB=(INT (BB*10000/N+0.5))/100 370 LET A$="0 OCCURRENCES" 380 LET B$="1 """ 390 LET C$="2 """ 400 LET D$="3 """ 410 LET E$="4 """ 420 LET F$="5 """ 430 LET G$="6 """ 440 LET H$="7 """ 450 LET I$="8 """ 451 LET J$="9 """ 452 LET K$="10 """ 455 LET L$="11 """ 457 LET M$="12 """ 570 PRINT A$,PP,B$,QQ,C$,RR,D$,SS,E$,TT,F$,UU,G$,VV,H$,WW,I$,XX,J$,YY,K$,ZZ,L$,AAA,M$,BBB,,,,PP+QQ+RR+SS+TT+UU+VV+WW+XX+YY+ZZ+AAA+BBB ```