Recipes and witness accounting

A natural circuit is translated into a model-evaluation recipe: every variable and node gets a point code, natural variables get the natural template, constants get fixed-scalar templates, and additions, multiplications and power calls get the corresponding templates.

DefinitionTranslation of a natural circuit into a model-evaluation recipe#✓

Natural circuits. A natural circuit has \(k\) inputs, a list of explicit variables \((i_0,\kappa_0),(i_1,\kappa_1),\dots\) (variable index and kind, the inputs first with indices \(0,\dots,k-1\)), a node list whose nodes are \(\mathrm{const}\ c\), \(\mathrm{var}\ i\), \(\mathrm{add}\ j\ j'\), \(\mathrm{mul}\ j\ j'\) or \(\mathrm{call}\ (a,b,c)\ w\) (a call of the power template on three earlier nodes with a private block of \(79\) variables at \(w\)), and a root node. The power template is itself a natural circuit with \(3\) inputs, \(79\) witnesses, no calls, and explicit variables \(0,\dots,81\).

Translation. Fix the operation templates \(\nu=\mathtt{natural}\), \(\alpha=\mathtt{raw\_add}\), \(\mu=\mathtt{multiply}\) with witness counts \(140604\), \(6\), \(35134\). The translation of a natural circuit with \(k\) inputs, in mode \(\mathrm{value}\) or \(\mathrm{zero}\), with or without natural constraints on the inputs, and with an optional power recipe \(\pi\), is the model-evaluation recipe with \(p=5(k+[\mathrm{value}])\) parameters built by one allocation counter starting at \(p\):

  1. the generator indices \(g_0,g_1,g_2\) take the next three variables;
  2. for each explicit variable in list order: an input \(i\) gets the point reference \(5i\) (inside the parameters), any other variable gets a fresh point (five variables); then, unless it is an input and inputs are unconstrained, a natural block of \(140604\) variables is taken; the row records the reference and the natural start (or none);
  3. each node \(j\) in order gets a point reference \(\mathrm{pt}(j)\): \(\mathrm{var}\ i\) the reference of \(i\); \(\mathrm{const}\ 0\), \(1\), \(-1\) the references \(-1\), \(-2\), \(-3\); any other constant \(c\) (the translation is defined only when every such constant is an integer \(c\ge2\), which holds for both circuits translated here), at its first occurrence in this circuit, a fresh point followed by a block of \(1\), recording the constant definition \((S_{\mathrm{integer\_constant}_h},\text{point},\text{start})\) where \(\mathrm{integer\_constant}_h=c\) (a new index \(h\) is created when \(c\) has not occurred in any earlier translation), and later occurrences reuse that point; \(\mathrm{add}\ j_1\ j_2\) and \(\mathrm{mul}\ j_1\ j_2\) nodes a fresh point followed by a block of \(6\) or \(35134\), recording the operation \((0\text{ or }1,\ \mathrm{pt}(j_1),\ \mathrm{pt}(j_2),\ \text{point},\ \text{start})\); a \(\mathrm{call}\ (a,b,c)\ w\) a fresh point followed by a block of the witness count of \(\pi\), recording \((2,\mathrm{pt}(a),\mathrm{pt}(b),\mathrm{pt}(c),\text{point},\text{start})\); the source block at \(w\) is not used;
  4. the root equality is \((\mathrm{pt}(\mathrm{root}),5k)\) in value mode and \((\mathrm{pt}(\mathrm{root}),-1)\) in zero mode;
  5. the variable count is the final counter.

The polynomial of the result is given by the semantics of model-evaluation recipes: the three generator constraints, the natural calls, the constant definitions (each a fixed-scalar template on \((\mathrm{ref}(-2),\text{point})\)), the operation calls and the five root differences, squared and summed.

Equivalently, the translation takes the table of nontrivial constants as an argument, listed in order of first occurrence across the translations: \((4,2,3)\) for power_value and \((4,2,3,c_3,1399)\) for precision, a constant \(c\) using the fixed-scalar template of its position in the table.

This is a definition. The arithmetic meaning (every node point is the code of the node's signed integer value) is the compiler chapter's rational translation statement.

ZInQ.Syntax.translate · 18 lines
def translate (consts : List ℤ) (N : NatCircuit) (mode : OutputMode) (natInputs : Bool)
    (power : Option (ℕ × ℕ)) : ModelRecipe :=
  let p := trParams N.inputCount mode
  let s := trState consts N mode natInputs power
  { parameterCount := p
    variableCount := s.next
    generator := ![p, p + 1, p + 2]
    sources := s.sources
    constants := s.constants
    operations := s.operations
    rootEq := (s.nodePts.getD N.root (-4),
      match mode with
      | .value => ((5 * N.inputCount : ℕ) : ℤ)
      | .zero => -1)
    natural := 12
    addition := 1
    multiplication := 11
    power := power.map Prod.fst }
theorem translate_variableCount (consts : List ℤ) (N : NatCircuit) (mode : OutputMode)
    (natInputs : Bool) (power : Option (ℕ × ℕ)) :
    (translate consts N mode natInputs power).variableCount =
      trParams N.inputCount mode + 3 +
        (N.explicitVars.map (varCost N.inputCount natInputs)).sum +
        (N.nodes.map (nodeCost ((power.map Prod.snd).getD 0))).sum +
        6 * (N.nodes.filterMap nontrivialConst).toFinset.card
Uses 6 · Used by 10

TheoremWitness scope of constructed templates and recipes#✓

Call an existential polynomial \(\tau\) with \(p\) parameters and \(v\) variables in scope if \([\![\tau]\!]=\kappa(\varphi)\) for a formula \(\varphi\) such that

  1. every call atom of \(\varphi\) with callee witness count \(m\) and witness start \(w\) satisfies \(p\le w\) and \(w+m\le v\), and its callee has all its variables below its variable count;
  2. the blocks \([w,w+m)\) of the call atoms are pairwise disjoint;
  3. no variable of a block occurs in a parameter polynomial of any call atom or in any atom \(a\doteq b\) or \(\langle f\rangle\) of \(\varphi\);
  4. every variable occurring in \(\kappa(\varphi)\) has index below \(v\).

Then \(\mathrm{Rel}_\tau(a)\) holds exactly when \(\varphi^\ast\) holds at some assignment extending \(a\), and every variable of \([\![\tau]\!]\) has index below \(v\).

Every template of the library is in scope (with \(\varphi=\bigwedge(E_1,\dots,E_r,\varphi_0)\) for its construction). A composition recipe is in scope when its call arguments lie below a bound \(B\ge p\), its calls start at or above \(B\), and its call blocks are pairwise disjoint; the five composition recipes of the specification satisfy this with \(B=51\) (close), \(11\) (main), \(6\) (value_union, value, integers): their blocks are allocated one after another above the parameters and fresh ranges. The model-evaluation translation of a well-formed natural circuit is in scope. Hence every recipe of the specification is in scope.

Proof sketch. For a template, the list of call blocks of its construction is computed from the counter and checked to be separated and above \(p\); the parameter polynomials and atoms are checked to use only variables below \(v\) outside the blocks; constant variables are allocated by the counter. A construction may use a call atom twice, so this check is made per template. For a composition recipe the arguments are parameters or fresh-range variables below \(B\) and the blocks lie at or above \(B\). For the translation every reference, generator variable and block is allocated by its counter. The relational form is the private-witness lemma.

structure Formula.InScope (φ : Formula) (p v : ℕ) : Prop where
  /-- The scope facts of the compiler chapter. -/
  scopedIn : Translation.ScopedIn φ p v
  /-- The blocks end at or below the variable count. -/
  inside : ∀ b ∈ φ.blocks, b.1 + b.2 ≤ v
def ExPoly.WitnessScope (τ : ExPoly) : Prop :=
  ∃ φ : Formula, τ.poly = φ.compile ∧ φ.InScope τ.params τ.varCount
theorem rel_iff {τ : ExPoly} {φ : Formula} (hφ : τ.poly = φ.compile)
    (hs : φ.InScope τ.params τ.varCount) (a : Fin τ.params → ℚ) :
    τ.Rel a ↔ ∃ x : ℕ → ℚ, (∀ i : Fin τ.params, x i = a i) ∧ φ.Lift x
Sources
Uses 4 · Used by 7

DefinitionThe template library#✓

The template library is the list of \(23\) templates, in this order (index: name): \(0\) \(\mathtt{member}\), \(1\) \(\mathtt{raw\_add}\), \(2\) \(\mathtt{raw\_z}\), \(3\) \(\mathtt{raw\_inverse\_x}\), \(4\) \(\mathtt{log25}\), \(5\) \(\mathtt{pole}\), \(6\) \(\mathtt{test\_group}\), \(7\) \(\mathtt{slope}\), \(8\) \(\mathtt{height\_certificate}\), \(9\) \(\mathtt{multiply.scalar}=S_{c_*}\), \(10\) \(\mathtt{multiply.guard}\), \(11\) \(\mathtt{multiply}\), \(12\) \(\mathtt{natural}\), \(13\) \(\mathtt{value.signed\_encode}\), \(14\) \(\mathtt{value.abs}\), \(15\) \(\mathtt{value.close\_coordinates}\), \(16\) \(\mathtt{value.test}\), \(17\) \(\mathtt{value.exceptions}\), and \(18+k\) \(\mathtt{scalar.integer\_constant}_k=S_{\mathrm{integer\_constant}_k}\) for \(k=0,\dots,4\).

The constants \(\mathrm{integer\_constant}_k\) are the distinct integer constants other than \(0,1,-1\) met by the model-evaluation translation, numbered in the order in which they are first met: first in the power template, then in the precision circuit. They are \(4,2,3,c_3,1399\), where \(c_3\) is the program literal of the natural precision polynomial. Equivalently, the list \((4,2,3,c_3,1399)\) is fixed in advance and the translation looks up each constant's index in it; the shape of the natural precision circuit shows that these five values are exactly the constants met, in order of first occurrence.

Every call in a template refers to a template of smaller index, so the library is denoted in this order. The parameter and witness counts are as follows. The manuscript's table also lists the root node index of each template's node list (\(149,308,68,54,229,106,515,2681,260,136,22,83,79,138,23,271,775,487\) and \(136\) for each scalar-constant template); these are properties of the node encoding, checked by the external comparison with the saved specification, and play no role in the proof.

Index Template Parameters Witnesses
0 member 5 7
1 raw_add 15 6
2 raw_z 7 1
3 raw_inverse_x 7 0
4 log25 4 0
5 pole 1 11
6 test_group 44 162
7 slope 22 1,298
8 height_certificate 36 35,106
9 multiply.scalar 10 1
10 multiply.guard 15 1
11 multiply 15 35,134
12 natural 5 140,604
13 value.signed_encode 10 140,654
14 value.abs 2 4
15 value.close_coordinates 16 53
16 value.test 11 35,282
17 value.exceptions 6 406
18-22 scalar.integer_constant_0..4 10 1

This is a definition.

noncomputable def templateLibrary (I : Constructors E) (cstar ell T c3 : ℤ) : List ExPoly :=
  [memberTemplate, rawAddTemplate, rawZTemplate, rawInverseXTemplate, log25Template, poleTemplate,
    testGroupTemplate, slopeTemplate, heightTemplate, scalarTemplate I cstar, guardTemplate I T,
    multiplyTemplate I cstar ell T, naturalTemplate I cstar ell T,
    signedEncodeTemplate I cstar ell T, absTemplate, closeTemplate,
    valueTestTemplate I cstar ell T, exceptionsTemplate] ++
  (integerConstants c3).map (scalarTemplate I)
theorem templateLibrary_witnesses : (templateLibrary I cstar ell T c3).map ExPoly.witnesses =
    [7, 6, 1, 0, 0, 11, 162, 1298, 35106, 1, 1, 35134, 140604, 140654, 4, 53, 35282, 406,
      1, 1, 1, 1, 1]
theorem templateLibrary_wf : ∀ τ ∈ templateLibrary I cstar ell T c3, τ.WF
Uses 19 · Used by 4 · Informal links 2

The power-value and precision recipes, the five composition recipes that assemble the value relation and the root, and the accounting of \(P_*\) use the compiler's natural circuits, so they are in the chapter on the outer recipes and their translation.

The witness counts follow from the template counts, the shape of the natural circuit (proved in the compiler chapter: shape of the natural precision circuit) and explicit arithmetic; the root has one input and \(292{,}890{,}231{,}904\) witnesses.

TheoremParameter and witness counts of the templates#✓

The \(23\) templates of the library, as constructed, have the parameter and witness counts of the library table: \(\mathtt{member}\) \((5,7)\), \(\mathtt{raw\_add}\) \((15,6)\), \(\mathtt{raw\_z}\) \((7,1)\), \(\mathtt{raw\_inverse\_x}\) \((7,0)\), \(\mathtt{log25}\) \((4,0)\), \(\mathtt{pole}\) \((1,11)\), \(\mathtt{test\_group}\) \((44,162)\), \(\mathtt{slope}\) \((22,1298)\), \(\mathtt{height\_certificate}\) \((36,35106)\), \(\mathtt{multiply.scalar}\) \((10,1)\), \(\mathtt{multiply.guard}\) \((15,1)\), \(\mathtt{multiply}\) \((15,35134)\), \(\mathtt{natural}\) \((5,140604)\), \(\mathtt{value.signed\_encode}\) \((10,140654)\), \(\mathtt{value.abs}\) \((2,4)\), \(\mathtt{value.close\_coordinates}\) \((16,53)\), \(\mathtt{value.test}\) \((11,35282)\), \(\mathtt{value.exceptions}\) \((6,406)\) and \(\mathtt{scalar.integer\_constant}_k\) \((10,1)\) for \(k=0,\dots,4\).

This is a closed decidable statement about the constructed templates: run each construction's allocation counter. The counts do not depend on any fixed constant. By hand: \(162=40+4(7+6)+8\cdot7+2+12\); \(1298=7+6(24+162+24+3)+2+11\); \(35106=3\cdot11+9(3+3\cdot1298)\); \(35134=3+4\cdot6+35106+1\); \(140604=40+4\cdot35134+10+18\); \(140654=15+7+7+140604+6+3+6+6\); \(53=16+21+3+8+1+4\); \(35282=25+49+35134+12+20+6+5+2+12+3+2+1+11\); \(406=3+36\cdot11+7\).

theorem templateLibrary_params : (templateLibrary I cstar ell T c3).map ExPoly.params =
    [5, 15, 7, 7, 4, 1, 44, 22, 36, 10, 15, 15, 5, 10, 2, 16, 11, 6, 10, 10, 10, 10, 10]
theorem templateLibrary_witnesses : (templateLibrary I cstar ell T c3).map ExPoly.witnesses =
    [7, 6, 1, 0, 0, 11, 162, 1298, 35106, 1, 1, 35134, 140604, 140654, 4, 53, 35282, 406,
      1, 1, 1, 1, 1]
Sources
Uses 2 · Used by 1

TheoremThe witness-count arithmetic#✓

The following identities between explicit natural numbers hold: $\(3+79\,(5+140604)+3\,(5+1)+196\,(5+6)+190\,(5+35134)=17786698,\)$ $\(3+5\cdot140604+54051\,(5+140604)+4\,(5+1)+125327\,(5+6)+98382\,(5+35134)+15845\,(5+17786698)=292889492836,\)$ $\(8\cdot5+5\cdot140654+292889492836+53=292890196199,\)$ $\(5+292890196199+35282=292890231486,\qquad 406+292890231486=292890231892,\)$ $\(7+292890231892=292890231899,\qquad 5+292890231899=292890231904 .\)$ Adding the parameter counts gives the total variable counts \(17786718\), \(292889492861\), \(292890196210\), \(292890231492\), \(292890231898\), \(292890231905\) and \(292890231905\).

This is a closed decidable statement (integer arithmetic).

theorem witness_count_arith :
    3 + 79 * (5 + 140604) + 3 * (5 + 1) + 196 * (5 + 6) + 190 * (5 + 35134) = 17786698 ∧
      3 + 5 * 140604 + 54051 * (5 + 140604) + 4 * (5 + 1) + 125327 * (5 + 6) +
        98382 * (5 + 35134) + 15845 * (5 + 17786698) = 292889492836 ∧
      8 * 5 + 5 * 140654 + 292889492836 + 53 = 292890196199 ∧
      5 + 292890196199 + 35282 = 292890231486 ∧ 406 + 292890231486 = 292890231892 ∧
      7 + 292890231892 = 292890231899 ∧ 5 + 292890231899 = 292890231904
theorem variable_count_arith :
    17786698 + 20 = 17786718 ∧ 292889492836 + 25 = 292889492861 ∧
      292890196199 + 11 = 292890196210 ∧ 292890231486 + 6 = 292890231492 ∧
      292890231892 + 6 = 292890231898 ∧ 292890231899 + 6 = 292890231905 ∧
      292890231904 + 1 = 292890231905
Sources
Used by 1
5 fully proved

The dependency explorer needs JavaScript and its graph data.

Download the complete graph data.