Documentation

Complexity.Computability.Ram.Problem.Basic

Problem-owned specifications and submission certificates #

A track publishes one Problem and a requested bound. A submission supplies only code and a proof for those fixed parameters. In particular, input encoding, legal word widths, the size measure, and the observable answer are not fields of the submission.

This is a specification boundary, not a security mechanism: the problem author still has to choose an honest encoding and size measure. The general judgments in Complexity.Computability.Ram.Time.Basic remain useful without these packaging conventions.

Concrete budgets work for finite and infinite domains alike. The asymptotic track additionally requires legal inputs of arbitrarily large size, so a threshold cannot discard its entire domain.

structure Ram.Problem (Input : Type) :

All problem-specific choices are published before accepting submissions. encode is external input formatting, not computation charged to the program; it must not perform the work that the problem asks the program to do.

Instances For
    def Ram.Problem.Unbounded {Input : Type} (p : Problem Input) :

    The legal input family contains arbitrarily large problem sizes. Word width may grow with the input; one fixed finite width is usually insufficient.

    Equations
    Instances For
      theorem Ram.Problem.Unbounded.nonempty {Input : Type} {p : Problem Input} (h : p.Unbounded) :
      ∃ (w : ℕ) (input : Input), p.admissible w input
      theorem Ram.Problem.not_unbounded_of_bounded {Input : Type} {p : Problem Input} {limit : ℕ} (h : ∀ (w : ℕ) (input : Input), p.admissible w input → p.size input ≤ limit) :

      A size-bounded problem is perfectly suitable for concrete budgets, but cannot be presented as an unbounded asymptotic problem.

      structure Ram.Submission {Input : Type} (p : Problem Input) :

      Only code is chosen by a submission; p is the already published problem. The expected type at the acceptance site must use that specific p.

      Instances For
        def Ram.Submission.Correct {Input : Type} {p : Problem Input} (s : Submission p) :
        Equations
        Instances For
          def Ram.Submission.Within {Input : Type} {p : Problem Input} (s : Submission p) (bound : ℕ → ℕ) :
          Equations
          Instances For
            theorem Ram.Submission.Within.correct {Input : Type} {p : Problem Input} {s : Submission p} {bound : ℕ → ℕ} (h : s.Within bound) :
            structure Ram.Certificate {Input : Type} (p : Problem Input) (bound : ℕ → ℕ) extends Ram.Submission p :

            A concrete-budget submission, including termination and the answer on every legal input. Both the problem and required budget are fixed parameters.

            Instances For
              theorem Ram.Certificate.correct {Input✝ : Type} {p : Problem Input✝} {bound : ℕ → ℕ} (c : Certificate p bound) :
              theorem Ram.Certificate.runs {Input✝ : Type} {p : Problem Input✝} {bound : ℕ → ℕ} {w : ℕ} {input : Input✝} (c : Certificate p bound) (ha : p.admissible w input) :
              ∃ (finish : State w), TerminatesWithin c.code (bound (p.size input)) (State.initial (p.encode w input)) finish ∧ p.post w input finish

              The certificate exposes the same actual-machine judgment used by runners and the compiler; there is no separate evaluator or source-level cost table.

              def Ram.Certificate.weaken {Input✝ : Type} {p : Problem Input✝} {a b : ℕ → ℕ} (c : Certificate p a) (h : ∀ (n : ℕ), a n ≤ b n) :
              Equations
              Instances For
                structure Ram.AsymptoticProblem (Input : Type) extends Ram.Problem Input :

                An asymptotic task must establish that its legal size parameter really tends to infinity somewhere, rather than using a finite benchmark domain.

                Instances For
                  structure Ram.AsymptoticCertificate {Input : Type} (p : AsymptoticProblem Input) (growth : ℕ → ℕ) extends Ram.Submission p.toProblem :

                  Total correctness holds even below the asymptotic threshold. The growing legal input family is supplied by the problem, never by the submission.

                  Instances For
                    theorem Ram.AsymptoticCertificate.correct {Input✝ : Type} {p : AsymptoticProblem Input✝} {growth : ℕ → ℕ} (c : AsymptoticCertificate p growth) :
                    def Ram.AsymptoticCertificate.ofBound {Input : Type} {bound growth : ℕ → ℕ} {p : AsymptoticProblem Input} (c : Certificate p.toProblem bound) {constant threshold : ℕ} (hc : 0 < constant) (hb : ∀ (n : ℕ), threshold ≤ n → bound n ≤ constant * growth n) :

                    Reuse a proved concrete bound without reproving functional correctness.

                    Equations
                    Instances For
                      def Ram.AsymptoticCertificate.ofIsBigO {Input : Type} {p : AsymptoticProblem Input} {bound growth : ℕ → ℕ} (c : Certificate p.toProblem bound) (hO : (fun (n : ℕ) => ↑(bound n)) =O[Filter.atTop] fun (n : ℕ) => ↑(growth n)) :

                      Use mathlib's asymptotic analysis of a proved machine bound directly.

                      Equations
                      Instances For
                        @[simp]
                        theorem Ram.AsymptoticCertificate.ofIsBigO_code {Input : Type} {p : AsymptoticProblem Input} {bound growth : ℕ → ℕ} (c : Certificate p.toProblem bound) (hO : (fun (n : ℕ) => ↑(bound n)) =O[Filter.atTop] fun (n : ℕ) => ↑(growth n)) :
                        (ofIsBigO c hO).code = c.code
                        theorem Ram.TerminatesWithin.initial_pos {w : ℕ} {code : Code} {bound : ℕ} {input : List (Word w)} {finish : State w} (h : TerminatesWithin code bound (State.initial input) finish) :
                        0 < bound

                        Even the halt instruction costs one transition from the initial running state. This lower bound is independent of the problem's postcondition.

                        theorem Ram.AsymptoticProblem.not_bigO_zero {Input : Type} (p : AsymptoticProblem Input) (code : Code) :
                        ¬UniformBigO code p.encode p.admissible p.size p.post fun (x : ℕ) => 0

                        On a genuinely unbounded legal domain, O(0) cannot be certified by choosing a threshold beyond all inputs: some legal input crosses every one.

                        theorem Ram.AsymptoticCertificate.no_zero {Input✝ : Type} {p : AsymptoticProblem Input✝} (c : AsymptoticCertificate p fun (x : ℕ) => 0) :