1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
;;; Copyright (c) 2026 Nicholas Vermeulen
;;; SPDX-License-Identifier: AGPL-3.0-or-later
;; classify.lisp — a classifier whose predictions are PROVEN to respect a
;; declared logical invariant over the ENTIRE finite feature domain, using
;; std.lisp's `implies` / `logic-loss` to GUIDE fitting and check-exhaustive to
;; CERTIFY the result. Pure Lisp, zero interpreter changes.
;;
;; The deliverable: "a classification model that respects logical invariants."
;; The Rusty angle is the gap between GUIDED and PROVEN. logic-loss (std.lisp,
;; crisp) is a penalty that biases parameter selection toward the invariant;
;; but a fit that is 100% accurate on the training data can still VIOLATE the
;; invariant off-distribution. Only running the invariant over every point of
;; the finite feature domain — check-exhaustive — certifies that zero
;; violations remain.
;;
;; The example is hierarchical labels: `dog` and `mammal`, features
;; (fur bark) ∈ {0,1}². Invariant: (implies dog mammal) — a dog is a mammal.
;; The training set contains no furless barker (0 1), so an independent
;; best-fit that keys `dog` on bark alone is DATA-PERFECT yet predicts
;; dog-but-not-mammal at (0 1). Adding logic-loss over the whole domain forces
;; a `dog` rule that also requires fur — still data-perfect, and now the
;; exhaustive check returns 'verified.
;;
;; CLAIM DISCIPLINE: "the classifier respects the declared invariant at EVERY
;; point of the declared finite feature domain." NOT "a good classifier",
;; nothing about accuracy or generalization beyond the declared domain, and
;; "guided by logic-loss" is never conflated with "proven" — the proof is the
;; check-exhaustive verdict, not the training.
;; ── Features & finite domain ────────────────────────────────────────────────
;; ── Model = (mammal-rule dog-rule); a rule = (name predicate) ───────────────
;; ── The invariant: (implies dog mammal) — from std.lisp ─────────────────────
;; logic-loss (std.lisp) = 0 when the invariant holds at x, else 1.
;; PROOF: the invariant holds at EVERY point of the finite feature domain.
;; ── Candidate rule pools ────────────────────────────────────────────────────
;; ── Training data: (features desired-mammal desired-dog) ────────────────────
;; NOTE the absence of any (0 1) row — no furless barker is ever observed.
; rock: neither
;; ── Losses ──────────────────────────────────────────────────────────────────
;; # of training points a rule misclassifies for a given label column.
;; ── Independent best fit (data accuracy only — invariant-blind) ─────────────
;; ── Logic-guided fit: data-loss + λ·logic-cost over the whole domain ────────
;; total training misclassifications (both labels) — for reporting accuracy.