Documentation

Examples.Ram.Composition

Linking two independent function modules between I/O adapters #

The increment and doubling modules each call function number zero in their own one-function table. Their proofs apply to arbitrary source states meeting the shared register interface. Composition relocates the second module and reuses both proofs; neither module knows the eventual function numbering.

Input decoding and output encoding are ordinary charged RAM read/write components. The shared interface holds one natural number in register zero, with an explicit word-fit condition. The legal domain prevents overflow in both arithmetic functions. The final result is the natural number 2 * (x + 1).

The size convention is explicitly the numeric magnitude size x = x. These are fixed-word RAM transition bounds, not claims about bit complexity. Polynomial certificates and their composition come from the public component API; the complete program additionally has the concrete bound of 55 steps. The four Ram.TotalComponent packages and their composition are defined from safe total contracts first. Separate time proofs then attach bounds to the same code.

Equations
Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      Equations
      Instances For
        Equations
        Instances For
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Each module has this same local main block; its function zero is resolved against that module's own declarations until Component.comp links them.

              Equations
              Instances For

                Reading establishes the shared representation without a time budget.

                Writing preserves the mathematical value without a time budget.

                The arithmetic result uses safe call and assignment rules, not a fuel calculation.

                Doubling has its own independent safe total proof over its local function table.

                The input adapter is packaged before its time analysis.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  The increment module has safe total correctness and output size, but no time field.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Doubling is packaged independently with the same shared representation.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      The output adapter also needs no time bound to expose its functional contract.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def Ram.Examples.Composition.totalPipeline :
                        TotalComponent inputInterface outputInterface ((fun (x : ℕ) => x) ∘ ((fun (x : ℕ) => 2 * x) ∘ fun (x : ℕ) => x + 1) ∘ fun (x : ℕ) => x) legal

                        Link the whole safe, terminating pipeline before choosing any instruction budget.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          This independent proof uses only its own function table. The function's assignment is proved by WP substitution and the call by the public call rule.

                          The second module also uses function zero, without referring to the increment module or its eventual position in the linked table.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  Restriction changes only the accepted inputs, not the independently proved increment program, its function table, or its correctness proof.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    def Ram.Examples.Composition.pipeline :
                                    PolyTimeComponent inputInterface outputInterface ((fun (x : ℕ) => x) ∘ ((fun (x : ℕ) => 2 * x) ∘ fun (x : ℕ) => x + 1) ∘ fun (x : ℕ) => x) legal

                                    The adapters and both function modules run in one persistent source state. Only the complete executable receives the prologue and final halt.

                                    Equations
                                    Instances For

                                      The resource-aware pipeline retains the independently composed functional program, its domain, all representations and every non-time guarantee.

                                      Analyze the linked functional pipeline by adding actual module costs. This proof is separate from the safe total composition above.

                                      Attaching the pipeline bound recovers the existing costed executable.

                                      The independently numbered functions are both present once.

                                      The second module's original call to zero has automatically become a call to one. No edit to double_contract was needed.

                                      theorem Ram.Examples.Composition.runs {w x : ℕ} (hx : legal w x) (hcode : 55 < 2 ^ w) :
                                      ∃ (finish : State w), TerminatesWithin pipeline.code 55 (State.initial [0, BitVec.ofNat w x]) finish ∧ finish.output = [BitVec.ofNat w (2 * (x + 1))] ∧ finish.input = []

                                      A full halted machine run, with the natural arithmetic answer encoded as one word. All four modules, the header read, and the halt are in this budget.

                                      theorem Ram.Examples.Composition.runs_polynomial :
                                      ∃ (c : ℕ) (k : ℕ), 0 < c ∧ ∀ (w x : ℕ), legal w x → 55 < 2 ^ w → ∃ (finish : State w), TerminatesWithin pipeline.code (c * (x + 1) ^ k) (State.initial [0, BitVec.ofNat w x]) finish ∧ finish.output = [BitVec.ofNat w (2 * (x + 1))] ∧ finish.input = []

                                      This certificate is obtained from PolyTimeComponent.comp and its polynomial closure theorem, not by proving the linked program from scratch.

                                      A fixed task specification, independent of any submitted code. Six-bit or larger words and the mathematical result range determine admissibility; there is no code-size filter in this definition.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        The certificate covers every legal input of the already fixed problem. The component export discharges code and stack capacity from the problem's word-width condition, without shrinking its admissible domain.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          theorem Ram.Examples.Composition.certificate_runs {w x : ℕ} (hx : problem.admissible w x) :
                                          ∃ (finish : State w), TerminatesWithin certificate.code 55 (State.initial [0, BitVec.ofNat w x]) finish ∧ finish.output = [BitVec.ofNat w (2 * (x + 1))] ∧ finish.input = []

                                          Users of the fixed certificate need only establish the published input conditions; there are no separate submission-dependent fit hypotheses.