<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=The_Principia_Machina%2FTPC-PY%2Fcheck_draft.py</id>
	<title>The Principia Machina/TPC-PY/check draft.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=The_Principia_Machina%2FTPC-PY%2Fcheck_draft.py"/>
	<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;action=history"/>
	<updated>2026-10-21T10:19:23Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4805&amp;oldid=prev</id>
		<title>BFP Rauch: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4805&amp;oldid=prev"/>
		<updated>2026-09-30T02:11:02Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:11, 30 September 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4804&amp;oldid=prev</id>
		<title>BFP Rauch: TPC-PY source check_draft.py (0.6.0), SHA-256 a142a0dec39aa96f; conformed TPS 0.4.0; PROPOSED, not declared (TPC-PY 0.2.0)</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4804&amp;oldid=prev"/>
		<updated>2026-09-30T02:10:58Z</updated>

		<summary type="html">&lt;p&gt;TPC-PY source check_draft.py (0.6.0), SHA-256 a142a0dec39aa96f; conformed TPS 0.4.0; PROPOSED, not declared (TPC-PY 0.2.0)&lt;/p&gt;
&lt;a href=&quot;https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;amp;diff=4804&amp;amp;oldid=4027&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4027&amp;oldid=prev</id>
		<title>BFP Rauch: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4027&amp;oldid=prev"/>
		<updated>2026-09-28T04:32:52Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:32, 28 September 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4026&amp;oldid=prev</id>
		<title>BFP Rauch: TPC-PY source check_draft.py (0.5.0), SHA-256 dccc2b59a5d245af; conformed TPS 0.3.0; PROPOSED, not declared (CO-8)</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/check_draft.py&amp;diff=4026&amp;oldid=prev"/>
		<updated>2026-09-27T15:43:18Z</updated>

		<summary type="html">&lt;p&gt;TPC-PY source check_draft.py (0.5.0), SHA-256 dccc2b59a5d245af; conformed TPS 0.3.0; PROPOSED, not declared (CO-8)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;# -*- coding: utf-8 -*-&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
check_draft.py --- check a draft TFK on your own machine with TPC-PY&lt;br /&gt;
====================================================================&lt;br /&gt;
Advisory. TPX of record decides at the new-UWC gate; this tool runs&lt;br /&gt;
the same TPC functions ahead of it so an author sees every refusal before&lt;br /&gt;
submitting. Standard library only; Python 3.8+; written for Windows and&lt;br /&gt;
Linux. Run on Linux under Python 3.8.20, 3.10, 3.11, 3.12 and 3.13 over&lt;br /&gt;
the 11 examples and 86 research drafts, the output the same in each (K5,&lt;br /&gt;
2026-09-27); the Windows run is owed.&lt;br /&gt;
&lt;br /&gt;
    python3 check_draft.py my_draft.json          (Windows: py check_draft.py ...)&lt;br /&gt;
&lt;br /&gt;
The draft is one JSON object with up to three zones:&lt;br /&gt;
    {&amp;quot;TPK&amp;quot;: {...}, &amp;quot;TrM&amp;quot;: {...}, &amp;quot;TMS&amp;quot;: {...}}&lt;br /&gt;
Missing zones are reported and skipped. What it does, in the order TPX&lt;br /&gt;
does it (TPS 5.5; tpm_zone_schemas 0.3.0 with schema 0.5.0; tpm_units&lt;br /&gt;
0.2.0; tpm_kernel_tests 0.2.0; tpm_increment_8 0.1.0, the declared form;&lt;br /&gt;
D176.1 and D177.1, the ROLE fields, the TPK PARAMETERS part with&lt;br /&gt;
D_VARIABLES, the TMS switch STRUCTURE_CHECK and the D variable):&lt;br /&gt;
    1. reads the file as UTF-8 and refuses what is not RFC 8259 JSON&lt;br /&gt;
       (NaN, Infinity and -Infinity included), duplicate object keys (two&lt;br /&gt;
       readers could otherwise disagree on which value counts) and nesting&lt;br /&gt;
       deeper than MAX_DEPTH levels, before any TPC function runs;&lt;br /&gt;
    2. runs T1 on the TPK (units included: every UNIT parses and has the&lt;br /&gt;
       DIMENSION of what it measures; every EQUATION and CONDITION parses&lt;br /&gt;
       and names exactly its REFS; every LAW&amp;#039;s ROLE is in its grammar and&lt;br /&gt;
       EOM(&amp;lt;NAME&amp;gt;) names a DOF; a DOF&amp;#039;s ROLE is INPUT; D_VARIABLES is ONE&lt;br /&gt;
       or SEVERAL; every D variable is a DOF that no CONSTRAINT targets, and&lt;br /&gt;
       one only under ONE) and, if it passes, the kernel tests T2&lt;br /&gt;
       (the syntactic part), T5, T4 (over every LAW with an EQUATION) and&lt;br /&gt;
       T6 (over every BOUNDARY with a CONDITION); a law or boundary without&lt;br /&gt;
       a form is listed as an inspection, never silently passed;&lt;br /&gt;
    3. runs the structural check on the TrM against that TPK (a SIGNATURE&amp;#039;s&lt;br /&gt;
       FORM and IMAGE_FORM included) and, if both pass their structure, the&lt;br /&gt;
       isomorphism checks IC1-IC4 and CODOMAIN, IC4 (a) syntactically where a&lt;br /&gt;
       signature carries its forms, holding any untied DOF as a named gap;&lt;br /&gt;
    4. runs the structural check on the TMS, then each yardstick of a&lt;br /&gt;
       well-formed TMS through the SR9 harness (C1, C2, C4) on the&lt;br /&gt;
       synthetic record suite;&lt;br /&gt;
    5. if everything above passes, the final pass: T3 over the constraints&lt;br /&gt;
       and over the laws with an EQUATION (the ground fragment at depth 1),&lt;br /&gt;
       and IC2&amp;#039;s disposition under the TMS&amp;#039;s IC2_POLICY;&lt;br /&gt;
    6. if the final pass admits the draft, prints the structure check of&lt;br /&gt;
       its equations of motion (D176.1; tpc_eom): the EOM map (each DOF&lt;br /&gt;
       with its label and the law the matching gives it, the index and&lt;br /&gt;
       initial values of the determined part, the closed and invariant&lt;br /&gt;
       laws), the findings each with its question for the declaring&lt;br /&gt;
       authority, and the class the candidate certificate&amp;#039;s STRUCTURE line&lt;br /&gt;
       would carry. The map and the findings are shown whatever the TMS&amp;#039;s&lt;br /&gt;
       STRUCTURE_CHECK says (S26); the class line reads the switch, and&lt;br /&gt;
       under OFF the gate lists nothing for the declaring authority. A&lt;br /&gt;
       finding refuses nothing (D176.3), so it does not change the exit&lt;br /&gt;
       status;&lt;br /&gt;
    7. if the final pass admits the draft, prints D(TPK), D(TrM), D(TMS)&lt;br /&gt;
       and D(TFK), and lists the checks that stay inspections for the&lt;br /&gt;
       declaring authority.&lt;br /&gt;
Every problem is printed. Exit status 0 when all three zones are present&lt;br /&gt;
and every check passes (a named gap under IC2_POLICY GAP passes); 1 when a&lt;br /&gt;
zone is missing or a check refuses; 2 when the draft cannot be read or&lt;br /&gt;
cannot be checked to the end, and on a usage error. No input ends in a&lt;br /&gt;
traceback. The last line names the TPC-PY modules by their own versions: a&lt;br /&gt;
TPC-PY version exists only when the declaring authority declares one (TPS&lt;br /&gt;
5.11.9).&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
import json&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
HERE = os.path.dirname(os.path.abspath(__file__))&lt;br /&gt;
sys.path.insert(0, HERE)&lt;br /&gt;
&lt;br /&gt;
import tpc_zone as Z          # noqa: E402&lt;br /&gt;
import tpc_yardstick as Y     # noqa: E402&lt;br /&gt;
import tpc_units as U         # noqa: E402&lt;br /&gt;
import tpc_tests as K         # noqa: E402&lt;br /&gt;
import tpc_form as F          # noqa: E402&lt;br /&gt;
import tpc_eom as E           # noqa: E402&lt;br /&gt;
&lt;br /&gt;
CHECK_DRAFT_VERSION = &amp;quot;0.5.0&amp;quot;     # proposed MINOR: the structure check after the final pass (D176.1, S26)&lt;br /&gt;
&lt;br /&gt;
# The deepest draft the zone schemas admit nests 7 containers (the draft,&lt;br /&gt;
# TMS, YARDSTICKS, a yardstick, LIMITING, a limiting case, KEY); the&lt;br /&gt;
# examples reach 6. The loader refuses more before the JSON parser or any&lt;br /&gt;
# TPC function recurses into it.&lt;br /&gt;
MAX_DEPTH = 64&lt;br /&gt;
&lt;br /&gt;
# What no mechanical body reads (tpm_kernel_tests 0.2.0 sections 2, 12;&lt;br /&gt;
# tpm_increment_8 0.1.0). The per-entry inspections a draft owes because an&lt;br /&gt;
# entry carries no form are printed beside the checks, from the draft itself.&lt;br /&gt;
OWED_INSPECTIONS = [&lt;br /&gt;
    &amp;quot;T2 the semantic part: each ASSUMPTION states one claim (guide 3.6)&amp;quot;,&lt;br /&gt;
    &amp;quot;T3 over the assumptions, and over the laws beyond the ground fragment at depth 1, to depth S_MAX (guide 3.6)&amp;quot;,&lt;br /&gt;
    &amp;quot;T4, T6 and T3 over every law or boundary without a declared form, as listed beside the kernel tests (D108.1)&amp;quot;,&lt;br /&gt;
    &amp;quot;IC4 (a) that each SIGNATURE image holds in the environment, beyond the syntactic reading, and each borne law is expressible (guide 4.6)&amp;quot;,&lt;br /&gt;
    &amp;quot;IC5 falsifier invariance under the TRANSFORMATIONS (guide 4.6)&amp;quot;,&lt;br /&gt;
    &amp;quot;equivalence of environment quantities under the TRANSFORMATIONS (names are taken as written)&amp;quot;,&lt;br /&gt;
    &amp;quot;every STATEMENT, PROPOSITION, PREDICATE and IMAGE names only what its REFS or OVER list, and agrees with its declared form where one exists&amp;quot;,&lt;br /&gt;
]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class DuplicateKey(ValueError):&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _no_duplicates(pairs):&lt;br /&gt;
    d = {}&lt;br /&gt;
    for k, v in pairs:&lt;br /&gt;
        if k in d:&lt;br /&gt;
            raise DuplicateKey(&amp;quot;duplicate key &amp;quot; + Z._show(k))&lt;br /&gt;
        d[k] = v&lt;br /&gt;
    return d&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class NonJsonConstant(ValueError):&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _no_constant(token):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;json&amp;#039;s parse_constant hook: RFC 8259 has no NaN, Infinity or&lt;br /&gt;
    -Infinity, which Python&amp;#039;s json module would otherwise accept.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    raise NonJsonConstant(token)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _where(text, i):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;The position as json reports it: line, column, char.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    return &amp;quot;line %d column %d (char %d)&amp;quot; % (text.count(&amp;quot;\n&amp;quot;, 0, i) + 1, i - text.rfind(&amp;quot;\n&amp;quot;, 0, i), i)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _scan(text):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;One linear pass over the raw text, outside strings: [the index of&lt;br /&gt;
    the first bracket opened deeper than MAX_DEPTH, the index of the first&lt;br /&gt;
    N or I]. Either is None when absent. Outside strings in text JSON has&lt;br /&gt;
    read, an N or an I can only begin NaN or Infinity.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    depth, in_str, esc, const = 0, False, False, None&lt;br /&gt;
    for i, ch in enumerate(text):&lt;br /&gt;
        if in_str:&lt;br /&gt;
            if esc:&lt;br /&gt;
                esc = False&lt;br /&gt;
            elif ch == &amp;quot;\\&amp;quot;:&lt;br /&gt;
                esc = True&lt;br /&gt;
            elif ch == &amp;#039;&amp;quot;&amp;#039;:&lt;br /&gt;
                in_str = False&lt;br /&gt;
        elif ch == &amp;#039;&amp;quot;&amp;#039;:&lt;br /&gt;
            in_str = True&lt;br /&gt;
        elif ch == &amp;quot;[&amp;quot; or ch == &amp;quot;{&amp;quot;:&lt;br /&gt;
            depth += 1&lt;br /&gt;
            if depth &amp;gt; MAX_DEPTH:&lt;br /&gt;
                return [i, const]&lt;br /&gt;
        elif ch == &amp;quot;]&amp;quot; or ch == &amp;quot;}&amp;quot;:&lt;br /&gt;
            depth -= 1&lt;br /&gt;
        elif const is None and (ch == &amp;quot;N&amp;quot; or ch == &amp;quot;I&amp;quot;):&lt;br /&gt;
            const = i - 1 if i &amp;gt; 0 and text[i - 1] == &amp;quot;-&amp;quot; else i&lt;br /&gt;
    return [None, const]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def load_draft(path):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;The draft as a dict, or raises ValueError with a readable reason.&lt;br /&gt;
    utf-8-sig accepts the byte-order mark some Windows editors write. The&lt;br /&gt;
    nesting bound is checked on the raw text, so the parser never recurses&lt;br /&gt;
    past it; only the text before the first too-deep bracket is parsed,&lt;br /&gt;
    and a problem found there is reported first, as the file&amp;#039;s first.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    with open(path, &amp;quot;r&amp;quot;, encoding=&amp;quot;utf-8-sig&amp;quot;) as f:&lt;br /&gt;
        text = f.read()&lt;br /&gt;
    deep, const = _scan(text)&lt;br /&gt;
    try:&lt;br /&gt;
        draft = json.loads(text if deep is None else text[:deep],&lt;br /&gt;
                           object_pairs_hook=_no_duplicates, parse_constant=_no_constant)&lt;br /&gt;
    except NonJsonConstant as e:&lt;br /&gt;
        raise ValueError(&amp;quot;%s is not JSON (RFC 8259 has no NaN, Infinity or -Infinity)%s&amp;quot;&lt;br /&gt;
                         % (e, &amp;quot;&amp;quot; if const is None else &amp;quot;: &amp;quot; + _where(text, const)))&lt;br /&gt;
    except json.JSONDecodeError as e:&lt;br /&gt;
        if deep is None or e.pos &amp;lt; deep:&lt;br /&gt;
            raise&lt;br /&gt;
    except RecursionError:&lt;br /&gt;
        raise ValueError(&amp;quot;nesting deeper than the checker reads&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        if deep is not None:        # a whole value, then a bracket: what json calls extra data&lt;br /&gt;
            raise ValueError(&amp;quot;Extra data: &amp;quot; + _where(text, deep))&lt;br /&gt;
    if deep is not None:&lt;br /&gt;
        raise ValueError(&amp;quot;nesting deeper than the checker reads (more than %d levels): %s&amp;quot;&lt;br /&gt;
                         % (MAX_DEPTH, _where(text, deep)))&lt;br /&gt;
    if not isinstance(draft, dict):&lt;br /&gt;
        raise ValueError(&amp;quot;the draft must be one JSON object&amp;quot;)&lt;br /&gt;
    return draft&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _count(n, word):&lt;br /&gt;
    return &amp;quot;%d %s%s&amp;quot; % (n, word, &amp;quot;&amp;quot; if n == 1 else &amp;quot;s&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _result(out, label, passed, probs):&lt;br /&gt;
    if passed == &amp;quot;NO FORM&amp;quot;:&lt;br /&gt;
        out(&amp;quot;%s NO FORM (by inspection)&amp;quot; % label)&lt;br /&gt;
        return&lt;br /&gt;
    out(&amp;quot;%s %s&amp;quot; % (label, &amp;quot;PASS&amp;quot; if passed else &amp;quot;REFUSED, &amp;quot; + _count(len(probs), &amp;quot;problem&amp;quot;)))&lt;br /&gt;
    for p in probs:&lt;br /&gt;
        out(&amp;quot;       &amp;quot; + p)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _structure(draft, out):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;The structure check of the equations of motion, after the final pass&lt;br /&gt;
    (D176.1; S26): the map and the findings whatever the switch says, then&lt;br /&gt;
    the class, which reads the switch. Information: nothing here refuses.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    m = E.eom_map(draft)&lt;br /&gt;
    if m[0] != &amp;quot;OK&amp;quot;:&lt;br /&gt;
        out(&amp;quot;STRUCTURE not computed: &amp;quot; + m[1])&lt;br /&gt;
        return&lt;br /&gt;
    r = dict((row[0], row[1:]) for row in m[1])&lt;br /&gt;
    dv = r[&amp;quot;D_VARIABLES&amp;quot;][0]&lt;br /&gt;
    out(&amp;quot;STRUCTURE map (shown whatever STRUCTURE_CHECK says): analysis &amp;quot; + r[&amp;quot;ANALYSIS&amp;quot;][0]&lt;br /&gt;
        + (&amp;quot;; D variable&amp;quot; + (&amp;quot;s &amp;quot; if len(dv) != 1 else &amp;quot; &amp;quot;) + &amp;quot;, &amp;quot;.join(dv) if dv else &amp;quot;; no D variable&amp;quot;))&lt;br /&gt;
    for dof, label, law in r[&amp;quot;MAP&amp;quot;][0]:&lt;br /&gt;
        out(&amp;quot;     %s: %s%s&amp;quot; % (dof, label, &amp;quot; (LAW &amp;quot; + law + &amp;quot;)&amp;quot; if law else &amp;quot;&amp;quot;))&lt;br /&gt;
    if r[&amp;quot;INDEX&amp;quot;][0] == &amp;quot;NONE&amp;quot;:&lt;br /&gt;
        out(&amp;quot;     index and initial values: not computed&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        out(&amp;quot;     index %s, initial values %s (the determined part; information)&amp;quot; % (r[&amp;quot;INDEX&amp;quot;][0], r[&amp;quot;INITIAL_VALUES&amp;quot;][0]))&lt;br /&gt;
    if r[&amp;quot;CLOSED&amp;quot;][0]:&lt;br /&gt;
        out(&amp;quot;     closed: &amp;quot; + &amp;quot;, &amp;quot;.join(&amp;quot;%s (%s)&amp;quot; % (law, kind) for law, kind in r[&amp;quot;CLOSED&amp;quot;][0]))&lt;br /&gt;
    if r[&amp;quot;INVARIANT&amp;quot;][0]:&lt;br /&gt;
        out(&amp;quot;     invariant, outside the matching: &amp;quot; + &amp;quot;, &amp;quot;.join(r[&amp;quot;INVARIANT&amp;quot;][0]))&lt;br /&gt;
    f = E.eom_findings(draft)&lt;br /&gt;
    if f[0] != &amp;quot;OK&amp;quot;:&lt;br /&gt;
        out(&amp;quot;STRUCTURE findings not computed: &amp;quot; + f[1])&lt;br /&gt;
        return&lt;br /&gt;
    c = E.eom_class(draft)&lt;br /&gt;
    off = c[0] == &amp;quot;STRUCTURE&amp;quot; and len(c) &amp;gt; 2 and c[2] == [&amp;quot;CHECK OFF&amp;quot;]&lt;br /&gt;
    head = &amp;quot;STRUCTURE findings&amp;quot; + (&amp;quot; (information: under STRUCTURE_CHECK OFF the gate lists none)&amp;quot; if off else &amp;quot;&amp;quot;)&lt;br /&gt;
    out(head + &amp;quot;: &amp;quot; + (str(len(f[1])) if f[1] else &amp;quot;none&amp;quot;))&lt;br /&gt;
    for fd in f[1]:&lt;br /&gt;
        out(&amp;quot;       &amp;quot; + fd[0] + &amp;quot;: &amp;quot; + (fd[-1] + &amp;quot; (D variables &amp;quot; + &amp;quot;, &amp;quot;.join(fd[1]) + &amp;quot;)&amp;quot; if fd[0] == &amp;quot;PDE&amp;quot; else fd[-1]))&lt;br /&gt;
    if c[0] != &amp;quot;STRUCTURE&amp;quot;:&lt;br /&gt;
        out(&amp;quot;STRUCTURE class not computed: &amp;quot; + c[1])&lt;br /&gt;
    elif len(c) == 2:&lt;br /&gt;
        out(&amp;quot;STRUCTURE &amp;quot; + c[1])&lt;br /&gt;
    else:&lt;br /&gt;
        out(&amp;quot;STRUCTURE &amp;quot; + c[1] + &amp;quot;: &amp;quot; + &amp;quot;, &amp;quot;.join(c[2]))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def check(draft, out):&lt;br /&gt;
    ok = all(z in draft for z in (&amp;quot;TPK&amp;quot;, &amp;quot;TrM&amp;quot;, &amp;quot;TMS&amp;quot;))&lt;br /&gt;
    for k in sorted(draft):&lt;br /&gt;
        if k not in (&amp;quot;TPK&amp;quot;, &amp;quot;TrM&amp;quot;, &amp;quot;TMS&amp;quot;):&lt;br /&gt;
            out(&amp;quot;DRAFT: unknown zone &amp;quot; + Z._show(k))&lt;br /&gt;
            ok = False&lt;br /&gt;
    tpk, trm, tms = draft.get(&amp;quot;TPK&amp;quot;), draft.get(&amp;quot;TrM&amp;quot;), draft.get(&amp;quot;TMS&amp;quot;)&lt;br /&gt;
    t1_ok = kt_ok = trm_ok = ic_ok = tms_ok = False&lt;br /&gt;
    # the Prime Kernel: T1, then T2 and T5&lt;br /&gt;
    if &amp;quot;TPK&amp;quot; not in draft:&lt;br /&gt;
        out(&amp;quot;TPK  MISSING (not checked)&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        kt = K.kernel_tests(tpk)&lt;br /&gt;
        t1_ok = kt[1][0][1] is True&lt;br /&gt;
        _result(out, &amp;quot;TPK &amp;quot;, t1_ok, kt[1][0][2])&lt;br /&gt;
        if t1_ok:&lt;br /&gt;
            for name, passed, probs in kt[1][1:]:&lt;br /&gt;
                _result(out, &amp;quot;     &amp;quot; + name, passed if passed == &amp;quot;NO FORM&amp;quot; else passed is True, probs)&lt;br /&gt;
            for i in kt[2]:&lt;br /&gt;
                out(&amp;quot;     inspection &amp;quot; + i)&lt;br /&gt;
        kt_ok = kt[0] is True&lt;br /&gt;
        ok = ok and kt_ok&lt;br /&gt;
    # the Translation Manifold: structure, then IC1-IC4 and CODOMAIN&lt;br /&gt;
    if &amp;quot;TrM&amp;quot; not in draft:&lt;br /&gt;
        out(&amp;quot;TrM  MISSING (not checked)&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        r = Z.trm_well_formed(trm, draft.get(&amp;quot;TPK&amp;quot;, {}))&lt;br /&gt;
        trm_ok = r[0]&lt;br /&gt;
        _result(out, &amp;quot;TrM &amp;quot;, trm_ok, r[1])&lt;br /&gt;
        ok = ok and trm_ok&lt;br /&gt;
        if trm_ok and not t1_ok:&lt;br /&gt;
            out(&amp;quot;     IC1-IC4 not run: the TPK &amp;quot; + (&amp;quot;does not pass T1&amp;quot; if &amp;quot;TPK&amp;quot; in draft else &amp;quot;is missing&amp;quot;))&lt;br /&gt;
        elif trm_ok:&lt;br /&gt;
            ic = K.ic_checks(trm, tpk)&lt;br /&gt;
            if ic[0] == &amp;quot;REJECT&amp;quot;:&lt;br /&gt;
                _result(out, &amp;quot;     IC1-IC4&amp;quot;, False, ic[1])&lt;br /&gt;
            elif ic[0] == &amp;quot;GAP&amp;quot;:&lt;br /&gt;
                out(&amp;quot;     IC1-IC4 PASS with &amp;quot; + _count(len(ic[2]), &amp;quot;untied DOF&amp;quot;)&lt;br /&gt;
                    + &amp;quot;, held for the final pass&amp;quot;)&lt;br /&gt;
            elif ic[0] == &amp;quot;PASS&amp;quot;:&lt;br /&gt;
                out(&amp;quot;     IC1-IC4 PASS&amp;quot;)&lt;br /&gt;
            else:&lt;br /&gt;
                out(&amp;quot;     IC1-IC4 not run: &amp;quot; + &amp;quot;; &amp;quot;.join(ic[1]))&lt;br /&gt;
            if ic[0] == &amp;quot;REJECT&amp;quot; and ic[2]:&lt;br /&gt;
                out(&amp;quot;     and &amp;quot; + _count(len(ic[2]), &amp;quot;untied DOF&amp;quot;) + &amp;quot;, held for the final pass&amp;quot;)&lt;br /&gt;
            for g in (ic[2] if ic[0] in (&amp;quot;REJECT&amp;quot;, &amp;quot;GAP&amp;quot;) else []):&lt;br /&gt;
                out(&amp;quot;       &amp;quot; + g)&lt;br /&gt;
            if ic[0] != &amp;quot;NOT_RUN&amp;quot;:&lt;br /&gt;
                for u in F.ic4a_signature(trm, tpk)[2]:&lt;br /&gt;
                    out(&amp;quot;     inspection &amp;quot; + u)&lt;br /&gt;
                for sg in trm[&amp;quot;HEADER&amp;quot;].get(&amp;quot;SIGNATURE&amp;quot;, []):&lt;br /&gt;
                    if &amp;quot;FORM&amp;quot; not in sg:&lt;br /&gt;
                        out(&amp;quot;     inspection SIGNATURE:&amp;quot; + sg[&amp;quot;NAME&amp;quot;] + &amp;quot;: no FORM; IC4 (a) by inspection&amp;quot;)&lt;br /&gt;
            ic_ok = ic[0] in (&amp;quot;PASS&amp;quot;, &amp;quot;GAP&amp;quot;)&lt;br /&gt;
            ok = ok and ic_ok&lt;br /&gt;
    # the Measure Set: structure, then each yardstick through SR9&lt;br /&gt;
    if &amp;quot;TMS&amp;quot; not in draft:&lt;br /&gt;
        out(&amp;quot;TMS  MISSING (not checked)&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        r = Z.tms_well_formed(tms)&lt;br /&gt;
        tms_ok = r[0]&lt;br /&gt;
        _result(out, &amp;quot;TMS &amp;quot;, tms_ok, r[1])&lt;br /&gt;
        ok = ok and tms_ok&lt;br /&gt;
    if tms_ok:&lt;br /&gt;
        suite = json.load(open(os.path.join(HERE, &amp;quot;vectors&amp;quot;, &amp;quot;sr9_corpus.json&amp;quot;), encoding=&amp;quot;utf-8&amp;quot;))[&amp;quot;cases&amp;quot;][0][&amp;quot;input&amp;quot;][&amp;quot;suite&amp;quot;]&lt;br /&gt;
        for y in tms.get(&amp;quot;YARDSTICKS&amp;quot;, []):&lt;br /&gt;
            r = Y.yardstick_checks(tms, y[&amp;quot;NAME&amp;quot;], suite)&lt;br /&gt;
            if r[0] != &amp;quot;OK&amp;quot;:&lt;br /&gt;
                out(&amp;quot;YARDSTICK %s: REFUSED, %s&amp;quot; % (y[&amp;quot;NAME&amp;quot;], r[1]))&lt;br /&gt;
                ok = False&lt;br /&gt;
                continue&lt;br /&gt;
            c1, c2, c4 = r[1], r[2], r[3]&lt;br /&gt;
            line = &amp;quot;YARDSTICK %s: C1 %s, C2 %s, C4 %s&amp;quot; % (&lt;br /&gt;
                y[&amp;quot;NAME&amp;quot;], &amp;quot;pass&amp;quot; if c1[0] else &amp;quot;FAIL&amp;quot;, &amp;quot;pass&amp;quot; if c2[0] else &amp;quot;FAIL&amp;quot;, &amp;quot;pass&amp;quot; if c4[0] else &amp;quot;FAIL&amp;quot;)&lt;br /&gt;
            if c2[2]:&lt;br /&gt;
                line += &amp;quot;; exempt in a declared limiting DOMAIN: &amp;quot; + &amp;quot;, &amp;quot;.join(c2[2])&lt;br /&gt;
            out(line)&lt;br /&gt;
            for w in c1[1] + c2[1] + c4[1]:&lt;br /&gt;
                out(&amp;quot;       witness &amp;quot; + w)&lt;br /&gt;
            ok = ok and c1[0] and c2[0] and c4[0]&lt;br /&gt;
    # the final pass: T3 and IC2&amp;#039;s disposition&lt;br /&gt;
    if not all(z in draft for z in (&amp;quot;TPK&amp;quot;, &amp;quot;TrM&amp;quot;, &amp;quot;TMS&amp;quot;)):&lt;br /&gt;
        out(&amp;quot;FINAL not run: a zone is missing&amp;quot;)&lt;br /&gt;
    elif not ok:&lt;br /&gt;
        out(&amp;quot;FINAL not run: it runs once every check above passes&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        fin = K.final_checks(draft)&lt;br /&gt;
        if fin[0] == &amp;quot;PASS&amp;quot;:&lt;br /&gt;
            out(&amp;quot;FINAL T3 (constraints and laws) and IC2 PASS&amp;quot;)&lt;br /&gt;
        elif fin[0] == &amp;quot;GAP&amp;quot;:&lt;br /&gt;
            out(&amp;quot;FINAL T3 (constraints and laws) and IC2 PASS, admitted with &amp;quot; + _count(len(fin[2]), &amp;quot;named gap&amp;quot;)&lt;br /&gt;
                + &amp;quot; (IC2_POLICY GAP)&amp;quot;)&lt;br /&gt;
            for g in fin[2]:&lt;br /&gt;
                out(&amp;quot;       &amp;quot; + g)&lt;br /&gt;
        elif fin[0] == &amp;quot;REJECT&amp;quot;:&lt;br /&gt;
            _result(out, &amp;quot;FINAL T3 (constraints and laws) and IC2&amp;quot;, False, fin[1])&lt;br /&gt;
        else:&lt;br /&gt;
            out(&amp;quot;FINAL not run: &amp;quot; + &amp;quot;; &amp;quot;.join(fin[1]))&lt;br /&gt;
        ok = fin[0] in (&amp;quot;PASS&amp;quot;, &amp;quot;GAP&amp;quot;)&lt;br /&gt;
        if ok:&lt;br /&gt;
            _structure(draft, out)&lt;br /&gt;
    if ok:&lt;br /&gt;
        out(&amp;quot;&amp;quot;)&lt;br /&gt;
        out(&amp;quot;D(TPK) &amp;quot; + Z.d_tpk(tpk))&lt;br /&gt;
        out(&amp;quot;D(TrM) &amp;quot; + Z.d_trm(trm))&lt;br /&gt;
        out(&amp;quot;D(TMS) &amp;quot; + Z.d_tms(tms))&lt;br /&gt;
        out(&amp;quot;D(TFK) &amp;quot; + Z.d_tfk_of(draft))&lt;br /&gt;
        out(&amp;quot;&amp;quot;)&lt;br /&gt;
        out(&amp;quot;Inspections still owed to the declaring authority before declaring:&amp;quot;)&lt;br /&gt;
        for i in OWED_INSPECTIONS:&lt;br /&gt;
            out(&amp;quot;  - &amp;quot; + i)&lt;br /&gt;
    out(&amp;quot;&amp;quot;)&lt;br /&gt;
    out(&amp;quot;Advisory result (TPC-PY: tpc_zone %s, tpc_units %s, tpc_tests %s, tpc_form %s, tpc_eom %s; schema %s). &amp;quot;&lt;br /&gt;
        &amp;quot;TPX decides at the gate.&amp;quot; % (Z.TPC_ZONE_VERSION, U.TPC_UNITS_VERSION, K.TPC_TESTS_VERSION, F.TPC_FORM_VERSION,&lt;br /&gt;
                                      E.TPC_EOM_VERSION, Z.SCHEMA_VERSION))&lt;br /&gt;
    return ok&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main(argv):&lt;br /&gt;
    if hasattr(sys.stdout, &amp;quot;reconfigure&amp;quot;):&lt;br /&gt;
        sys.stdout.reconfigure(errors=&amp;quot;backslashreplace&amp;quot;)&lt;br /&gt;
    if len(argv) != 2:&lt;br /&gt;
        print(&amp;quot;usage: check_draft.py DRAFT.json&amp;quot;)&lt;br /&gt;
        return 2&lt;br /&gt;
    try:&lt;br /&gt;
        draft = load_draft(argv[1])&lt;br /&gt;
    except (OSError, ValueError) as e:&lt;br /&gt;
        print(&amp;quot;DRAFT: cannot be read: &amp;quot; + str(e))&lt;br /&gt;
        return 2&lt;br /&gt;
    except MemoryError:&lt;br /&gt;
        print(&amp;quot;DRAFT: cannot be read: the file does not fit in memory&amp;quot;)&lt;br /&gt;
        return 2&lt;br /&gt;
    try:&lt;br /&gt;
        return 0 if check(draft, print) else 1&lt;br /&gt;
    except RecursionError:&lt;br /&gt;
        print(&amp;quot;DRAFT: not checked to the end: a value nests deeper than TPC-PY&amp;#039;s checks read&amp;quot;&lt;br /&gt;
              &amp;quot; (RecursionError), such as a deeply nested EQUATION, CONDITION, FORM or IMAGE_FORM;&amp;quot;&lt;br /&gt;
              &amp;quot; TPX decides at the gate&amp;quot;)&lt;br /&gt;
        return 2&lt;br /&gt;
    except MemoryError:&lt;br /&gt;
        print(&amp;quot;DRAFT: not checked to the end: out of memory in the checks; TPX decides at the gate&amp;quot;)&lt;br /&gt;
        return 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(main(sys.argv))&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
</feed>