Qyxo-Zhaenivoth-Guard / source /docs /PUBLIC_INTERFACE.md
PureOne's picture
Publish Qyxo-Zhaenivoth Guard v1.0.0 research release
25c6e75 verified
|
Raw History Blame Contribute Delete
7.17 kB

Public API and streaming command contract

PreparedBank

PreparedBank(value_lower, value_upper=None, *, backend='auto',
             base_numerator=0, base_denominator=0)
bank.evaluate(mass_lower, mass_upper, threshold, *, relation='<=',
              base_numerator=None, base_denominator=None,
              witness=False, exact_margins=False)

Prepare static values once. Shapes are (M,) for scalar values or (M,P) for P coordinates. Absent value_upper means fixed values. Mass bounds are vectors of length M. Scalar thresholds broadcast to all coordinates; vector thresholds must have exactly P entries. A length-one vector is not a scalar for P>1. Python numeric iterables and ordinary real numeric NumPy arrays are accepted; booleans, strings, complex and nonfinite numeric inputs are rejected. Numeric values convert to finite binary64 before the mathematical contract applies.

Masses and the base denominator are nonnegative, lower bounds must not exceed upper bounds and every evaluated box needs D0 + sum(mass_lower) > 0 exactly. Signed values and base numerators are allowed. Base numerator can be a scalar or length-P vector. A zero-row bank requires a strictly positive base denominator; its coordinate count is inferred from the base numerator. Python None base overrides retain bank defaults; per-call overrides never modify those defaults.

Backend Selection and guarantee
exact Standard-library integer arithmetic over the exact converted binary64 values
filtered Requires NumPy; accepted separated signs require the explicit IEEE/NumPy premises in FILTER_THEORY; unsafe/ambiguous cases fall back to integer arithmetic
auto Chooses filtered if NumPy is available, otherwise exact, once at construction; inspect bank.backend

Importing qzguard does not import NumPy. Applications with a fixed numerical contract should choose a backend explicitly. The CLI default is exact.

Evaluation outputs

Field/method Meaning
guaranteed Tuple of universal inclusive-predicate booleans, one per coordinate
all_guaranteed All coordinate predicates are guaranteed
counterexample_exists Coordinatewise negation of guaranteed
backend Selected bank backend
relation, thresholds Requested relation and converted threshold snapshot
modes Per-coordinate decision routes, filtered or exact
support_interval Optional outward floating enclosures of centered supports; not weighted-average intervals or exact margins
exact_result Exact result if already computed or explicitly requested; otherwise None
.exact(witness=False) Explicitly compute exact rational supports and optional separate-coordinate counterexamples

False means a violating configuration exists in the declared independent box. It does not mean every configuration violates the threshold. For relaxed boxes, a counterexample can be impossible under correlations omitted from the model. Different coordinates can require different witnesses. A support-attaining witness is not necessarily a ratio-extremizing witness.

witness=True forces exact work. exact_margins=True also charges exact work; if the original sign was filtered, modes still describes that sign decision. If one coordinate needs fallback, the current filter computes all exact coordinates. Route counts are not operation counts. Each Evaluation retains its mass snapshot: release old results in a long-running stream rather than accumulating O(number_of_results * M * P) state.

For one unchanged box and many thresholds, use NormalizedBox.enclose() once and guard_from_bounds() for subsequent thresholds. PreparedBank is designed for new mass boxes. No claim covers concurrency of lazy exact-cache requests; separate snapshots/processes provide an uncomplicated application boundary.

CLI

qzguard --version
qzguard doctor --backend exact
qzguard demo --backend filtered
qzguard check --input examples/json/check.json
qzguard check --bank examples/json/bank_exact.json \
  --updates examples/json/updates.jsonl --output answers.jsonl
qzguard check --bank examples/json/bank_fast.json --updates - \
  --exact-margins --witness

The source equivalents are python START_HERE.py ... and python -m qzguard ... from the release root. Installed equivalents work outside that root.

A bank is one strict JSON object with required value_lower and optional value_upper, backend, base_numerator, base_denominator. Each update is one strict JSON object with required mass_lower, mass_upper, threshold and optional relation, base overrides, witness, exact_margins, id. relation defaults to <=; flags must be actual booleans. id is returned unchanged for valid updates. With --input, combine bank and update fields in one object. --backend overrides the input choice. --witness and --exact-margins enable details for all updates.

Duplicate keys, unknown fields, nonfinite JSON numbers, numeric strings and booleans in numeric fields are rejected. Omit optional fields to retain defaults; explicit JSON null in numeric fields is invalid. Blank JSONL lines are skipped. The bank is prepared once for the stream; each line replaces only masses and optionally bases. Standard input uses -; bank and updates cannot both consume stdin. Output cannot alias an input file.

Successful records contain status='ok', backend, numerical_contract, a feasible-set label, dimensions, relation, thresholds, booleans, route counts and the optional identifier. The feasible-set label is:

{"semantics":"universal_over_independent_box"}

JSONL records also carry the source line number. Filtered results include support_interval. Exact detail requests add support, decision_margins, counters and optionally witnesses. Decision margins are signed so nonnegative means the requested relation is guaranteed; support is the raw centered support.

Arbitrary-size rational components use decimal strings:

{"numerator":"100","denominator":"101"}

This avoids silent integer loss in JavaScript consumers. Outward support infinities use the strings "-inf" and "inf"; inputs must still be finite. No NaN/Infinity JSON extension is emitted.

Valid false decisions return exit code 0. Invalid streamed lines emit explicit status='error' records, processing continues, and the command returns code 2. A fatal input/import/file error reports a concise message on stderr and returns 2. Doctor returns 1 if its deterministic checks fail. Summaries go to stderr; JSON results alone go to stdout or the requested output. Fatal setup errors are checked before creating/truncating output; successful --output operations replace that file. A stream containing errors can therefore leave partial results, clearly labeled by status and exit code.

doctor checks format and deterministic basic/boundary fixtures. It does not prove that an arbitrary CPU/compiler runtime fulfills every filter premise. The full test suite and research evidence are bundled separately from the installed wheel.