#sleela 2.1 // 5/constraints.sleela -- the Constitution's congrains/limits applied to Lines. // // This is the shared constraint/theory layer carried by every churn relevance // set (/1 Longs, /2 Structures, /3 Facets, /4 Areas, /5 Lines). It encodes the // governing constraints from the repository's Constitution (see ../../README.md, // "The Constitution", and SHEET.sheet's `congrains` / `limits` / `system` // sections) and applies them to this set's magnitude -- here, a Line's value // (a count or a length). // // Two system invariants are always in force (conducted methods sysdepth()/ // degreemax() in the implementation): // DepthLimit : system depth <= 3024 // ComplexityDegree : connection order <= 4 // // A `Limit` is a bounding constraint from SHEET.sheet's `limits` section // (Bound / Threshold / Capacity ...). Here each Limit checks whether a Line's // value honors its bound. Failing a Limit does not delete data; it records that // the value falls outside the stated constraint. // // Discipline: constraints are stated so they can be checked and argued with. // A constraint is a modelling condition, not a claim about reality. import math; class Constraints { // --- system invariants (Article I of the Constitution) --- int depthLimit() { return 3024; } // maximum system depth int degreeMax() { return 4; } // maximum complexity degree // Article I -- the connect rule: connect(n) is permitted iff // n <= depthLimit() AND degree <= degreeMax(). boolean connectPermitted(int n, int degree) { if (n < 0) { return false; } if (n > depthLimit()) { return false; } if (degree > degreeMax()) { return false; } return true; } // --- Limit: Bound (an inclusive extent on a value) --- boolean withinBound(double value, double lo, double hi) { if (value < lo) { return false; } if (value > hi) { return false; } return true; } // --- Limit: Threshold (a boundary that changes behavior when crossed) --- boolean belowThreshold(double value, double threshold) { return value < threshold; } // --- Limit: Capacity (the maximum a container/resource may hold) --- boolean withinCapacity(double used, double capacity) { if (capacity < 0.0) { return false; } return used <= capacity; } // Report whether a Line's value honors a stated Bound [lo, hi]. void checkLine(String name, double value, double lo, double hi) { String verdict = "HOLDS"; if (!withinBound(value, lo, hi)) { verdict = "VIOLATES"; } print(" Bound[" + lo + ", " + hi + "] on " + name + " (value=" + value + "): " + verdict); } void main() { print("=== /5 constraints -- the Constitution applied to Lines ==="); print("System invariants: DepthLimit=" + depthLimit() + ", ComplexityDegree<=" + degreeMax() + "."); print(""); // A count is a non-negative Line, so its natural Bound floor is 0. Two // meaningful structural counts (states, senators) must honor their bounds. print("[limits] counts are non-negative Lines within a stated Bound"); checkLine("US states", 50.0, 0.0, 100.0); checkLine("US senators", 100.0, 0.0, 100.0); checkLine("dozen", 12.0, 0.0, 1000.0); // A deliberately impossible count, to show the Bound bites. checkLine("negative tally", -3.0, 0.0, 1000.0); print(""); // The DepthLimit itself is a Line: the maximum reachable system depth. // Any structural count must sit within it (a count cannot out-reach the // system that holds it). print("[capacity] structural counts vs the DepthLimit Line (3024)"); double depth = 3024.0; double houseAndSenate = 435.0 + 100.0; String cap = "WITHIN"; if (!withinCapacity(houseAndSenate, depth)) { cap = "OVER"; } print(" US voting Congress (435 House + 100 Senate) = " + houseAndSenate + " : " + cap + " the DepthLimit"); print(""); print("[threshold] a Line crosses a threshold when it grows past it"); print(" is a dozen (12) below the gross threshold (144)? " + belowThreshold(12.0, 144.0)); print(" is a gross (144) below the gross threshold (144)? " + belowThreshold(144.0, 144.0)); print(""); print("[invariant] the connect rule (n<=3024, degree<=4)"); print(" connect(3024, 4) permitted : " + connectPermitted(3024, 4)); print(" connect(3025, 4) permitted : " + connectPermitted(3025, 4)); print(" connect(100, 5) permitted : " + connectPermitted(100, 5)); print(""); print("Note: a constraint is a modelling condition to be checked and"); print("argued with, not a claim about reality. Failing a Limit records"); print("that a value falls outside a stated bound; it changes no data."); } }