File size: 3,587 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
import Mathlib.Algebra.Field.ZMod
import OAI.NumberTheory.Ostmann.Construction.TransferHistoryUniqueness
import OAI.NumberTheory.Ostmann.Characters.TreeCoordinates

namespace OAI

/-! # The actual integer pivot gives the spectator's rational reconstruction -/

namespace Ostmann

theorem ValidTransferNode.spectator_composite_reconstruction {State : Type*}
    {sys : TransferHistorySystem State} {Οƒ : State} {s v w : β„€} {P : β„•}
    (h : ValidTransferNode sys Οƒ s v w P) {q : β„•} [Fact q.Prime]
    (u : (ZMod q)Λ£) (hs : (s : ZMod q) β‰  0) :
    reconstructedEntry (s : ZMod q) (v : ZMod q) (w : ZMod q) u
      (sys.leftProduct Οƒ : ZMod q) (sys.rightProduct Οƒ : ZMod q) = (P : ZMod q) / u := by
  have hr : (v : ZMod q) * sys.rightProduct Οƒ - (w : ZMod q) * sys.leftProduct Οƒ =
      (s : ZMod q) * P := by
    have hz := congrArg (fun z : β„€ => (z : ZMod q)) h.relation
    simpa only [Int.cast_sub, Int.cast_mul, Int.cast_natCast] using hz
  unfold reconstructedEntry
  rw [hr]
  field_simp

theorem ValidTransferNode.spectator_composite_zero_iff {State : Type*}
    {sys : TransferHistorySystem State} {Οƒ : State} {s v w : β„€} {P : β„•}
    (h : ValidTransferNode sys Οƒ s v w P) {q : β„•} [Fact q.Prime]
    (u : (ZMod q)Λ£) (hs : (s : ZMod q) β‰  0) :
    reconstructedEntry (s : ZMod q) (v : ZMod q) (w : ZMod q) u
      (sys.leftProduct Οƒ : ZMod q) (sys.rightProduct Οƒ : ZMod q) = 0 ↔ q ∣ P := by
  rw [h.spectator_composite_reconstruction u hs, div_eq_zero_iff,
    or_iff_left (Units.ne_zero u), ZMod.natCast_eq_zero_iff]

theorem spectator_frequency_ne_zero {q : β„•} [Fact q.Prime] (s : β„€)
    (hs : s β‰  0) (hsmall : s.natAbs < q) : (s : ZMod q) β‰  0 := by
  intro hz
  have hd : q ∣ s.natAbs := Int.natCast_dvd.mp ((ZMod.intCast_zmod_eq_zero_iff_dvd s q).mp hz)
  exact (not_le_of_gt hsmall) (Nat.le_of_dvd (Int.natAbs_pos.mpr hs) hd)

theorem ValidTransferNode.spectator_reconstruction {State : Type*}
    {sys : TransferHistorySystem State} {Οƒ : State} {s v w : β„€} {P : β„•}
    (h : ValidTransferNode sys Οƒ s v w P) {q : β„•} [Fact q.Prime]
    (u p : β„•) (hP : P = u * p) (hs : (s : ZMod q) β‰  0) (hu : (u : ZMod q) β‰  0) :
    reconstructedEntry (s : ZMod q) (v : ZMod q) (w : ZMod q) (u : ZMod q)
      (sys.leftProduct Οƒ : ZMod q) (sys.rightProduct Οƒ : ZMod q) = (p : ZMod q) := by
  have hr : (v : ZMod q) * sys.rightProduct Οƒ - (w : ZMod q) * sys.leftProduct Οƒ =
      (s : ZMod q) * (u * p) := by
    have hi := h.relation
    rw [hP] at hi
    have hz := congrArg (fun z : β„€ => (z : ZMod q)) hi
    simpa only [Int.cast_sub, Int.cast_mul, Int.cast_natCast, Nat.cast_mul] using hz
  unfold reconstructedEntry
  apply (div_eq_iff (mul_ne_zero hs hu)).mpr
  rw [hr]
  ring

theorem ValidTransferNode.spectator_zero_iff {State : Type*}
    {sys : TransferHistorySystem State} {Οƒ : State} {s v w : β„€} {P : β„•}
    (h : ValidTransferNode sys Οƒ s v w P) {q : β„•} [Fact q.Prime]
    (u p : β„•) (hP : P = u * p) (hs : (s : ZMod q) β‰  0) (hu : (u : ZMod q) β‰  0) :
    reconstructedEntry (s : ZMod q) (v : ZMod q) (w : ZMod q) (u : ZMod q)
      (sys.leftProduct Οƒ : ZMod q) (sys.rightProduct Οƒ : ZMod q) = 0 ↔ q ∣ p := by
  rw [h.spectator_reconstruction u p hP hs hu, ZMod.natCast_eq_zero_iff]

theorem spectator_child_argument {q : β„•} [Fact q.Prime] (s : β„€) (D H : ZMod q)
    (u p P : β„•) (hP : P = u * p) :
    childArgument (s : ZMod q) D (u : ZMod q) H (p : ZMod q) =
      (s : ZMod q) / (D * (P : ZMod q) * H) := by
  rw [hP, Nat.cast_mul]
  unfold childArgument
  congr 1
  ring

end Ostmann

end OAI