File size: 4,225 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import Mathlib

namespace OAI

namespace RationalHitting

universe u

inductive Formula (n : β„•) where
  | var : Fin n β†’ Formula n
  | const : β„š β†’ Formula n
  | add : Formula n β†’ Formula n β†’ Formula n
  | mul : Formula n β†’ Formula n β†’ Formula n
  | inv : Formula n β†’ Formula n
  deriving DecidableEq

namespace Formula

def size {n : β„•} : Formula n β†’ β„•
  | .var _ | .const _ => 1
  | .add f g | .mul f g => f.size + g.size + 1
  | .inv f => f.size + 1

/-- Evaluation in any rational algebra; a unary inverse requires an actual
    two-sided inverse of the evaluated operand, not a totalized inverse. -/
inductive Eval {n : β„•} {R : Type u} [Ring R]
    (c : β„š β†’+* R) (X : Fin n β†’ R) : Formula n β†’ R β†’ Prop where
  | var (i) : Eval c X (.var i) (X i)
  | const (a) : Eval c X (.const a) (c a)
  | add {f g a b} : Eval c X f a β†’ Eval c X g b β†’ Eval c X (.add f g) (a + b)
  | mul {f g a b} : Eval c X f a β†’ Eval c X g b β†’ Eval c X (.mul f g) (a * b)
  | inv {f a b} : Eval c X f a β†’ a * b = 1 β†’ b * a = 1 β†’ Eval c X (.inv f) b

end Formula

abbrev Mat (d : β„•) := Matrix (Fin d) (Fin d) β„š
abbrev Tuple (n d : β„•) := Fin n β†’ Mat d

def Evaluates {n d : β„•} (f : Formula n) (X : Tuple n d) (v : Mat d) : Prop :=
  f.Eval (algebraMap β„š (Mat d)) X v

def Admissible {n : β„•} (f : Formula n) : Prop :=
  βˆƒ d, 0 < d ∧ βˆƒ (X : Tuple n d), βˆƒ v, Evaluates f X v

def Nonzero {n : β„•} (f : Formula n) : Prop :=
  βˆƒ d, 0 < d ∧ βˆƒ (X : Tuple n d), βˆƒ v, Evaluates f X v ∧ v β‰  0

/-- All output tuples have one common positive dimension. -/
structure Output (n : β„•) where
  dimension : β„•
  dimension_pos : 0 < dimension
  tuples : List (Tuple n dimension)

/-- Little-endian unsigned binary, prefixed by a unary bit-length and a zero
    terminator. This is a self-delimiting binary encoding, including zero. -/
def encodeNat (a : β„•) : List Bool :=
  let ds := (Nat.digits 2 a).map (fun b => b != 0)
  List.replicate ds.length true ++ [false] ++ ds

/-- Sign bit, binary numerator magnitude, and positive binary denominator.
    Rat.num and Rat.den are the canonical reduced numerator and denominator. -/
def encodeRat (a : β„š) : List Bool :=
  [decide (a.num < 0)] ++ encodeNat a.num.natAbs ++ encodeNat a.den

def encodeTuple {n d : β„•} (X : Tuple n d) : List Bool :=
  (List.finRange n).flatMap fun i =>
    (List.finRange d).flatMap fun j =>
      (List.finRange d).flatMap fun k => encodeRat (X i j k)

def encodeOutput {n : β„•} (H : Output n) : List Bool :=
  encodeNat H.dimension ++ encodeNat H.tuples.length ++ H.tuples.flatMap encodeTuple

/-- 0 is blank, 1 and 2 are the two literal binary digits, 3 is work space.
    Fixed finite tape alphabet and finite state space; no advice or oracle. -/
abbrev Alphabet := Fin 4
abbrev Machine (m : β„•) := Turing.TM0.Machine Alphabet (Fin (m + 1))
abbrev Config (m : β„•) := Turing.TM0.Cfg Alphabet (Fin (m + 1))

def tapeBit (b : Bool) : Alphabet := if b then 2 else 1

def unaryInput (n s : β„•) : List Alphabet :=
  List.replicate n 2 ++ [1] ++ List.replicate s 2

/-- Exactly t ordinary deterministic TM0 transitions. -/
def run {m : β„•} (G : Machine m) : β„• β†’ Config m β†’ Option (Config m)
  | 0, a => some a
  | t + 1, a => (Turing.TM0.step G a).bind (run G t)

def OutputsWithin {m n : β„•} (G : Machine m) (s bound : β„•) (H : Output n) : Prop :=
  βˆƒ t ≀ bound, βˆƒ a : Config m,
    run G t (Turing.TM0.init (unaryInput n s)) = some a ∧
    Turing.TM0.step G a = none ∧
    a.Tape.rightβ‚€ = Turing.ListBlank.mk ((encodeOutput H).map tapeBit)

def Hits {n : β„•} (s : β„•) (H : Output n) : Prop :=
  βˆ€ f : Formula n, f.size ≀ s β†’ Admissible f β†’ Nonzero f β†’
    βˆƒ X ∈ H.tuples, βˆƒ v, Evaluates f X v ∧ IsUnit v

/-- A fixed polynomial bound on bit time, full binary output length,
and common positive dimension. -/
def MainStatement : Prop :=
  βˆƒ (m : β„•) (G : Machine m) (C k : β„•), 0 < C ∧ 0 < k ∧
    βˆ€ n s : β„•, 1 ≀ n β†’ 1 ≀ s β†’ βˆƒ H : Output n,
      H.dimension ≀ C * (n + s + 1) ^ k ∧
      (encodeOutput H).length ≀ C * (n + s + 1) ^ k ∧
      OutputsWithin G s (C * (n + s + 1) ^ k) H ∧ Hits s H

end RationalHitting

end OAI