# PPM: two kinds of exclusion

This original worked example separates a coding decision from a model update.
It uses exact rational arithmetic on two hypothetical context tables, not
a compressed file or a measured corpus. Model, tests and results are adjacent.

## Frozen example

Alphabet: a, b, c, d. The current longer context is a; its counts are a:3,b:1.
The shorter empty context has a:5,b:2,c:1. Each step's escape count is the
number of distinct symbols in that context BEFORE coding exclusion.

| Next symbol | Coding exclusion | Event probabilities | Product |
| --- | --- | --- | --- |
| a | on or off | 3/6 | 1/2 |
| c | on | 2/6, 1/4 | 1/12 |
| c | off | 2/6, 1/11 | 1/33 |
| d | on | 2/6, 3/4, 1 | 1/4 |
| d | off | 2/6, 3/11, 1/4 | 1/44 |

The lower-context escape count stays 3 after a and b are excluded. Replacing
it with 1 would silently define a different estimator. The final uniform
fallback covers the remaining alphabet.

After coding a, update exclusion changes only the longer-context a count,
from 3 to 4. Full updating also changes the empty-context a count from 5 to 6.
This does not change the already completed coding event, but affects future
predictions. Coding c or d updates both context tables under either policy.

## Reproduce

Use Python 3.10 or later, standard library only:

```sh
python3 -B model.py --check
python3 -B -m unittest discover -s . -p test_model.py
python3 -B -O -m unittest discover -s . -p test_model.py
```

The tests include 729 two-context snapshots and 512 local distributions.
A reserved unseen d makes the exclusion-enabled path mass sum to one in that
grid. Without coding exclusion, canonical paths can leave unused code space;
do not normalize their products and then call it the same coding scheme.

## Scope and sources

This is a probability/update model, not a complete PPMC encoder, archive format,
random-access design or historical reproduction. It omits finite-precision
arithmetic coding, termination, model rescaling and memory management.
There is no speed, byte-size or compression-ratio measurement.

Mechanism references:
[Moffat 1990, sections II-III](https://cs.nyu.edu/home/people/in_memoriam/roweis/csc310-2006/extras/implementing_ppm.pdf) and
[Cleary and Teahan 1997, section 2](https://www.cs.ucf.edu/courses/cap5015/Cleary.pdf).
Both distinguish event probabilities from complete implementation choices.
See [the PPM record](https://hesela.dev/terms/prediction-by-partial-matching/)
for related concepts and the source bibliography.
