File size: 28,618 Bytes
3277efa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
import OAI.SetTheory.PartitionPrinciple.Geometry.GroundCompressionOrigins
import OAI.SetTheory.PartitionPrinciple.Transfinite.GroundBatchBirths

namespace OAI

open scoped ZFSet


namespace PartitionPilot.Forcing
universe u

noncomputable def firstAppearanceBirth (U T Ps stamps oldBirth : ZFSet.{u}) : ZFSet.{u} :=
  ZFSet.sep (fun z => z ∈ oldBirth ∨ ∃ n ∈ ZFSet.omega, ∃ D E x t,
    z = ZFSet.pair x t ∧ ZFSet.pair n D ∈ Ps ∧ ZFSet.pair (insert n n) E ∈ Ps ∧
      ZFSet.pair n t ∈ stamps ∧ x ∈ E ∧ x ∉ D) (ZFSet.prod U T)

theorem firstAppearanceBirth_subset (U T Ps stamps oldBirth : ZFSet.{u}) :
    firstAppearanceBirth U T Ps stamps oldBirth ⊆ ZFSet.prod U T :=
  fun _ h => (ZFSet.mem_sep.1 h).1

theorem pair_mem_firstAppearanceBirth (U T Ps stamps oldBirth x t : ZFSet.{u}) :
    ZFSet.pair x t ∈ firstAppearanceBirth U T Ps stamps oldBirth ↔
      x ∈ U ∧ t ∈ T ∧ (ZFSet.pair x t ∈ oldBirth ∨ ∃ n ∈ ZFSet.omega, ∃ D E,
        ZFSet.pair n D ∈ Ps ∧ ZFSet.pair (insert n n) E ∈ Ps ∧
          ZFSet.pair n t ∈ stamps ∧ x ∈ E ∧ x ∉ D) := by
  rw [firstAppearanceBirth, ZFSet.mem_sep, ZFSet.pair_mem_prod]
  constructor
  · rintro ⟨⟨hx, ht⟩, old | ⟨n, hn, D, E, y, s, equal, before, after, stamp, fresh⟩⟩
    · exact ⟨hx, ht, Or.inl old⟩
    · obtain ⟨rfl, rfl⟩ := ZFSet.pair_inj.1 equal
      exact ⟨hx, ht, Or.inr ⟨n, hn, D, E, before, after, stamp, fresh⟩⟩
  · rintro ⟨hx, ht, old | ⟨n, hn, D, E, before, after, stamp, fresh⟩⟩
    · exact ⟨⟨hx, ht⟩, Or.inl old⟩
    · exact ⟨⟨hx, ht⟩, Or.inr ⟨n, hn, D, E, x, t, rfl, before, after, stamp, fresh⟩⟩

theorem firstAppearanceBirth_nat_iff {U T Ps stamps oldBirth : ZFSet.{u}}
    (P stamp : Nat → ZFSet.{u})
    (domains : ∀ n D, ZFSet.pair (natSetCode n) D ∈ Ps ↔ D = P n)
    (times : ∀ n t, ZFSet.pair (natSetCode n) t ∈ stamps ↔ t = stamp n)
    (x t : ZFSet.{u}) :
    ZFSet.pair x t ∈ firstAppearanceBirth U T Ps stamps oldBirth ↔
      x ∈ U ∧ t ∈ T ∧ (ZFSet.pair x t ∈ oldBirth ∨
        ∃ n, x ∈ P (n + 1) ∧ x ∉ P n ∧ t = stamp n) := by
  rw [pair_mem_firstAppearanceBirth]
  apply and_congr_right
  intro _
  apply and_congr_right
  intro _
  apply or_congr Iff.rfl
  constructor
  · rintro ⟨n, hn, D, E, before, after, stampEntry, hx, outside⟩
    obtain ⟨k, rfl⟩ := (mem_omega_iff_natSetCode n).1 hn
    have oldEq := (domains k D).1 before
    have newEq := (domains (k + 1) E).1 after
    exact ⟨k, newEq ▸ hx, oldEq ▸ outside, (times k t).1 stampEntry⟩
  · rintro ⟨n, hx, outside, equal⟩
    exact ⟨natSetCode n, natSetCode_mem_omega n, P n, P (n + 1),
      (domains n _).2 rfl, (domains (n + 1) _).2 rfl, (times n t).2 equal, hx, outside⟩

theorem firstAppearanceBirth_natValue_iff {U T Ps stamps oldBirth : ZFSet.{u}}
    (domains : FunctionGraphOn ZFSet.omega Ps) (times : FunctionGraphOn ZFSet.omega stamps)
    (x t : ZFSet.{u}) :
    ZFSet.pair x t ∈ firstAppearanceBirth U T Ps stamps oldBirth ↔
      x ∈ U ∧ t ∈ T ∧ (ZFSet.pair x t ∈ oldBirth ∨
        ∃ n, x ∈ domains.natValue (n + 1) ∧ x ∉ domains.natValue n ∧ t = times.natValue n) :=
  firstAppearanceBirth_nat_iff domains.natValue times.natValue
    domains.natValue_entry_iff times.natValue_entry_iff x t

theorem firstAppearanceBirth_old_subset {U T Ps stamps oldBirth : ZFSet.{u}}
    (shape : oldBirth ⊆ ZFSet.prod U T) :
    oldBirth ⊆ firstAppearanceBirth U T Ps stamps oldBirth :=
  fun _ entry => ZFSet.mem_sep.2 ⟨shape entry, Or.inl entry⟩

end PartitionPilot.Forcing



namespace PartitionPilot.Forcing
open SetFormula
universe u

namespace BoundedFormula

def firstAppearanceBirthEntryFormula {k} (z omega u t domains stamps old bound : Fin k) :
    BoundedFormula k :=
  disj (.mem z old)
    (exMem omega (exMem omega.succ (exMem bound.succ.succ
      (exMem bound.succ.succ.succ (exMem u.succ.succ.succ.succ
        (exMem t.succ.succ.succ.succ.succ
          (.conj (orderedPairFormula z.succ.succ.succ.succ.succ.succ 1 0)
            (.conj (successorFormula 4 5)
              (.conj (pairMembershipFormula 5 3 domains.succ.succ.succ.succ.succ.succ)
                (.conj (pairMembershipFormula 4 2 domains.succ.succ.succ.succ.succ.succ)
                  (.conj (pairMembershipFormula 5 0 stamps.succ.succ.succ.succ.succ.succ)
                    (.conj (.mem 1 2) (.neg (.mem 1 3))))))))))))))

theorem truth_firstAppearanceBirthEntryFormula {k}
    (z omega u t domains stamps old bound : Fin k) (env : Fin k → ZFSet.{u}) :
    Truth (firstAppearanceBirthEntryFormula z omega u t domains stamps old bound) env ↔
      env z ∈ env old ∨ ∃ n ∈ env omega, ∃ m ∈ env omega,
        ∃ D ∈ env bound, ∃ E ∈ env bound, ∃ x ∈ env u, ∃ a ∈ env t,
          env z = ZFSet.pair x a ∧ m = insert n n ∧ ZFSet.pair n D ∈ env domains ∧
            ZFSet.pair m E ∈ env domains ∧ ZFSet.pair n a ∈ env stamps ∧ x ∈ E ∧ x ∉ D := by
  simp only [firstAppearanceBirthEntryFormula, truth_disj, truth_exMem, Truth,
    truth_orderedPairFormula, truth_successorFormula, truth_pairMembershipFormula]
  rfl

end BoundedFormula

namespace TransitiveGround
variable (M : TransitiveGround.{u})

theorem firstAppearanceBirth_mem
    (pairing : Realize M.sets SetFormula.pairing Fin.elim0)
    (unions : Realize M.sets SetFormula.union Fin.elim0)
    (powers : Realize M.sets powerSet Fin.elim0) (separation : SeparationSchema M.sets)
    {U T Ps stamps oldBirth : ZFSet.{u}}
    (hω : (ZFSet.omega : ZFSet.{u}) ∈ M.sets)
    (hU : U ∈ M.sets) (hT : T ∈ M.sets) (hPs : Ps ∈ M.sets)
    (hStamps : stamps ∈ M.sets) (hOld : oldBirth ∈ M.sets) :
    firstAppearanceBirth U T Ps stamps oldBirth ∈ M.sets := by
  have hBound := M.union_mem unions (M.union_mem unions hPs)
  let params := extend ZFSet.omega (extend U (extend T (extend Ps (extend stamps
    (extend oldBirth (extend (⋃₀ ⋃₀ Ps) Fin.elim0))))))
  have selected := M.bounded_separation_mem separation
    (BoundedFormula.firstAppearanceBirthEntryFormula 0 1 2 3 4 5 6 7) params
    (Fin.cases hω (Fin.cases hU (Fin.cases hT (Fin.cases hPs (Fin.cases hStamps
      (Fin.cases hOld (Fin.cases hBound (fun i => Fin.elim0 i))))))))
    (M.prod_mem pairing unions powers separation hU hT)
  have equal : ZFSet.sep (fun z => BoundedFormula.Truth
      (BoundedFormula.firstAppearanceBirthEntryFormula 0 1 2 3 4 5 6 7) (extend z params))
      (ZFSet.prod U T) = firstAppearanceBirth U T Ps stamps oldBirth := by
    apply ZFSet.ext
    intro z
    rw [ZFSet.mem_sep, firstAppearanceBirth, ZFSet.mem_sep,
      BoundedFormula.truth_firstAppearanceBirthEntryFormula]
    change (_ ∧ (z ∈ oldBirth ∨ _)) ↔ _
    apply and_congr_right
    intro bound
    apply or_congr Iff.rfl
    constructor
    · rintro ⟨n, hn, m, _, D, _, E, _, x, _, t, _, pair, successor, before, after, stamp, fresh⟩
      rw [successor] at after
      exact ⟨n, hn, D, E, x, t, pair, before, after, stamp, fresh⟩
    · rintro ⟨n, hn, D, E, x, t, rfl, before, after, stamp, fresh⟩
      have successorMem : insert n n ∈ ZFSet.omega := by
        obtain ⟨j, rfl⟩ := (mem_omega_iff_natSetCode n).1 hn
        exact natSetCode_mem_omega (j + 1)
      have points := ZFSet.pair_mem_prod.1 bound
      exact ⟨n, hn, insert n n, successorMem, D, pair_second_mem_doubleUnion before,
        E, pair_second_mem_doubleUnion after, x, points.1, t, points.2,
        rfl, rfl, before, after, stamp, fresh⟩
  exact equal ▸ selected

end TransitiveGround
end PartitionPilot.Forcing



namespace PartitionPilot.Forcing
universe u

structure NatBirthExtensionCode (P stamp : Nat → ZFSet.{u}) (old birth : ZFSet.{u}) : Prop where
  shape : ∀ z ∈ birth, ∃ x t, z = ZFSet.pair x t
  entries : ∀ x t, ZFSet.pair x t ∈ birth ↔
    ZFSet.pair x t ∈ old ∨ ∃ n, x ∈ P (n + 1) ∧ x ∉ P n ∧ t = stamp n

namespace NatBirthExtensionCode
variable {P stamp : Nat → ZFSet.{u}} {old birth U T : ZFSet.{u}}

theorem first_appearance_unique (mono : ∀ n m, n ≤ m → P n ⊆ P m)
    {n m : Nat} {x : ZFSet.{u}} (hn : x ∈ P (n + 1)) (notN : x ∉ P n)
    (hm : x ∈ P (m + 1)) (notM : x ∉ P m) : n = m := by
  rcases lt_trichotomy n m with before | equal | after
  · exact False.elim (notM (mono (n + 1) m (Nat.succ_le_of_lt before) hn))
  · exact equal
  · exact False.elim (notN (mono (m + 1) n (Nat.succ_le_of_lt after) hm))

theorem first_appearance_exists (carrier : NatUnionCode P U) {x : ZFSet.{u}}
    (hx : x ∈ U) (outside : x ∉ P 0) : ∃ n, x ∈ P (n + 1) ∧ x ∉ P n := by
  obtain ⟨n, hn⟩ := (carrier x).1 hx
  induction n with
  | zero => exact False.elim (outside hn)
  | succ n ih =>
    by_cases before : x ∈ P n
    · exact ih before
    · exact ⟨n, hn, before⟩

variable (code : NatBirthExtensionCode P stamp old birth)
include code

theorem function (carrier : NatUnionCode P U)
    (mono : ∀ n m, n ≤ m → P n ⊆ P m)
    (born : ZFSet.IsFunc (P 0) T old) (stamps : ∀ n, stamp n ∈ T) :
    ZFSet.IsFunc U T birth := by
  constructor
  · intro z hz
    obtain ⟨x, t, rfl⟩ := code.shape z hz
    rcases (code.entries x t).1 hz with oldEntry | ⟨n, hn, _, rfl⟩
    · have bounds := ZFSet.pair_mem_prod.1 (born.1 oldEntry)
      exact ZFSet.pair_mem_prod.2 ⟨carrier.subset 0 bounds.1, bounds.2⟩
    · exact ZFSet.pair_mem_prod.2 ⟨carrier.subset (n + 1) hn, stamps n⟩
  · intro x hx
    by_cases original : x ∈ P 0
    · obtain ⟨t, oldEntry, unique⟩ := born.2 x original
      refine ⟨t, (code.entries x t).2 (Or.inl oldEntry), ?_⟩
      intro s entry
      rcases (code.entries x s).1 entry with before | ⟨n, _, outside, _⟩
      · exact unique s before
      · exact False.elim (outside (mono 0 n (Nat.zero_le n) original))
    · obtain ⟨n, hn, outside⟩ := first_appearance_exists carrier hx original
      refine ⟨stamp n, (code.entries x (stamp n)).2 (Or.inr ⟨n, hn, outside, rfl⟩), ?_⟩
      intro s entry
      rcases (code.entries x s).1 entry with before | ⟨m, hm, notM, equal⟩
      · exact False.elim (original (ZFSet.pair_mem_prod.1 (born.1 before)).1)
      · rw [first_appearance_unique mono hm notM hn outside] at equal
        exact equal

theorem old_entry_iff (mono : ∀ n m, n ≤ m → P n ⊆ P m)
    {x t : ZFSet.{u}} (hx : x ∈ P 0) :
    ZFSet.pair x t ∈ birth ↔ ZFSet.pair x t ∈ old := by
  rw [code.entries]
  constructor
  · rintro (entry | ⟨n, _, outside, _⟩)
    · exact entry
    · exact False.elim (outside (mono 0 n (Nat.zero_le n) hx))
  · exact Or.inl

theorem restriction_zero (mono : ∀ n m, n ≤ m → P n ⊆ P m)
    (born : ZFSet.IsFunc (P 0) T old) : graphRestriction (P 0) birth = old := by
  apply ZFSet.ext
  intro z
  constructor
  · intro hz
    obtain ⟨x, hx, t, rfl, entry⟩ := mem_graphRestriction.1 hz
    exact (code.old_entry_iff mono hx).1 entry
  · intro hz
    obtain ⟨x, hx, t, _, rfl⟩ := ZFSet.mem_prod.1 (born.1 hz)
    exact pair_mem_graphRestriction.2 ⟨(code.old_entry_iff mono hx).2 hz, hx⟩

theorem restriction_function (carrier : NatUnionCode P U)
    (mono : ∀ n m, n ≤ m → P n ⊆ P m)
    (born : ZFSet.IsFunc (P 0) T old) (stamps : ∀ n, stamp n ∈ T) (n : Nat) :
    ZFSet.IsFunc (P n) T (graphRestriction (P n) birth) := by
  have full := code.function carrier mono born stamps
  refine ⟨?_, ?_⟩
  · intro z hz
    obtain ⟨x, hx, t, rfl, entry⟩ := mem_graphRestriction.1 hz
    exact ZFSet.pair_mem_prod.2 ⟨hx, (ZFSet.pair_mem_prod.1 (full.1 entry)).2⟩
  · intro x hx
    obtain ⟨t, entry, unique⟩ := full.2 x (carrier.subset n hx)
    exact ⟨t, pair_mem_graphRestriction.2 ⟨entry, hx⟩,
      fun s hs => unique s (pair_mem_graphRestriction.1 hs).1⟩

theorem restriction_union (carrier : NatUnionCode P U)
    (born : ZFSet.IsFunc (P 0) T old) :
    NatUnionCode (fun n => graphRestriction (P n) birth) birth := by
  intro z
  constructor
  · intro hz
    obtain ⟨x, t, rfl⟩ := code.shape z hz
    have hx : x ∈ U := by
      rcases (code.entries x t).1 hz with original | ⟨n, hn, _, _⟩
      · exact carrier.subset 0 (ZFSet.pair_mem_prod.1 (born.1 original)).1
      · exact carrier.subset (n + 1) hn
    obtain ⟨n, hn⟩ := (carrier x).1 hx
    exact ⟨n, pair_mem_graphRestriction.2 ⟨hz, hn⟩⟩
  · rintro ⟨n, hn⟩
    exact graphRestriction_subset (P n) birth hn

end NatBirthExtensionCode

end PartitionPilot.Forcing



namespace PartitionPilot.Forcing
open SetFormula
universe u

theorem firstAppearanceBirth_code {U T Ps stamps oldBirth : ZFSet.{u}}
    (P stamp : Nat → ZFSet.{u})
    (domains : ∀ n D, ZFSet.pair (natSetCode n) D ∈ Ps ↔ D = P n)
    (times : ∀ n t, ZFSet.pair (natSetCode n) t ∈ stamps ↔ t = stamp n)
    (carrier : NatUnionCode P U) (born : ZFSet.IsFunc (P 0) T oldBirth)
    (inRange : ∀ n, stamp n ∈ T) :
    NatBirthExtensionCode P stamp oldBirth (firstAppearanceBirth U T Ps stamps oldBirth) := by
  constructor
  · intro z entry
    obtain ⟨x, _, t, _, equal⟩ :=
      ZFSet.mem_prod.1 (firstAppearanceBirth_subset U T Ps stamps oldBirth entry)
    exact ⟨x, t, equal⟩
  · intro x t
    rw [firstAppearanceBirth_nat_iff P stamp domains times]
    constructor
    · exact fun entry => entry.2.2
    · intro entry
      have bounds : x ∈ U ∧ t ∈ T := by
        rcases entry with before | ⟨n, hx, _, rfl⟩
        · have oldBounds := ZFSet.pair_mem_prod.1 (born.1 before)
          exact ⟨carrier.subset 0 oldBounds.1, oldBounds.2⟩
        · exact ⟨carrier.subset (n + 1) hx, inRange n⟩
      exact ⟨bounds.1, bounds.2, entry⟩

namespace TransitiveGround
variable (M : TransitiveGround.{u})

theorem exists_groundFirstAppearanceBirth
    (pairing : Realize M.sets SetFormula.pairing Fin.elim0)
    (unions : Realize M.sets SetFormula.union Fin.elim0)
    (powers : Realize M.sets powerSet Fin.elim0) (separation : SeparationSchema M.sets)
    {U T Ps stamps oldBirth : ZFSet.{u}}
    (hω : (ZFSet.omega : ZFSet.{u}) ∈ M.sets)
    (hU : U ∈ M.sets) (hT : T ∈ M.sets) (hPs : Ps ∈ M.sets)
    (hStamps : stamps ∈ M.sets) (hOld : oldBirth ∈ M.sets)
    (P stamp : Nat → ZFSet.{u})
    (domains : ∀ n D, ZFSet.pair (natSetCode n) D ∈ Ps ↔ D = P n)
    (times : ∀ n t, ZFSet.pair (natSetCode n) t ∈ stamps ↔ t = stamp n)
    (carrier : NatUnionCode P U) (born : ZFSet.IsFunc (P 0) T oldBirth)
    (inRange : ∀ n, stamp n ∈ T) :
    ∃ birth ∈ M.sets, birth = firstAppearanceBirth U T Ps stamps oldBirth ∧
      NatBirthExtensionCode P stamp oldBirth birth :=
  ⟨firstAppearanceBirth U T Ps stamps oldBirth,
    M.firstAppearanceBirth_mem pairing unions powers separation hω hU hT hPs hStamps hOld,
    rfl, firstAppearanceBirth_code P stamp domains times carrier born inRange⟩

end TransitiveGround

end PartitionPilot.Forcing



namespace PartitionPilot.Forcing.NatBirthExtensionCode
universe u
variable {P stamp : Nat → ZFSet.{u}} {old birth T : ZFSet.{u}}
variable (code : NatBirthExtensionCode P stamp old birth)
variable (mono : ∀ n m, n ≤ m → P n ⊆ P m)
variable (born : ZFSet.IsFunc (P 0) T old)
include code

omit code in
include mono in
theorem restriction_mono {n m : Nat} (before : n ≤ m) :
    graphRestriction (P n) birth ⊆ graphRestriction (P m) birth := by
  intro z hz
  obtain ⟨x, hx, t, rfl, entry⟩ := mem_graphRestriction.1 hz
  exact pair_mem_graphRestriction.2 ⟨entry, mono n m before hx⟩

include mono born in
theorem restriction_step (n : Nat) {N : ZFSet.{u}}
    (next : P (n + 1) = taggedExtension (P n) N) :
    graphRestriction (P (n + 1)) birth = taggedBirth (P n) N (graphRestriction (P n) birth) (stamp n) := by
  apply ZFSet.ext
  intro z
  constructor
  · intro hz
    obtain ⟨x, hx, t, rfl, entry⟩ := mem_graphRestriction.1 hz
    apply (pair_mem_taggedBirth _ _ _ _ _ _).2
    by_cases oldPoint : x ∈ P n
    · exact Or.inl (pair_mem_graphRestriction.2 ⟨entry, oldPoint⟩)
    · have fresh : x ∈ ZFSet.prod {P n} N := by
        rw [next] at hx
        exact (ZFSet.mem_union.1 hx).resolve_left oldPoint
      rcases (code.entries x t).1 entry with original | ⟨m, hm, notM, equal⟩
      · exact False.elim (oldPoint (mono 0 n (Nat.zero_le n)
          (ZFSet.pair_mem_prod.1 (born.1 original)).1))
      · have same := first_appearance_unique mono hm notM hx oldPoint
        exact Or.inr ⟨fresh, same ▸ equal⟩
  · intro hz
    rcases ZFSet.mem_union.1 hz with original | fresh
    · obtain ⟨x, hx, t, rfl, entry⟩ := mem_graphRestriction.1 original
      exact pair_mem_graphRestriction.2 ⟨entry, mono n (n + 1) (Nat.le_succ n) hx⟩
    · obtain ⟨x, hx, t, ht, rfl⟩ := ZFSet.mem_prod.1 fresh
      obtain rfl := ZFSet.mem_singleton.1 ht
      have current : x ∈ P (n + 1) := by
        rw [next]
        exact ZFSet.mem_union.2 (Or.inr hx)
      have outside : x ∉ P n := fun h => taggedExtension_disjoint (P n) N x h hx
      exact pair_mem_graphRestriction.2
        ⟨(code.entries x (stamp n)).2 (Or.inr ⟨n, current, outside, rfl⟩), current⟩

include mono in
theorem restriction_bound
    (oldBound : ∀ n x t, ZFSet.pair x t ∈ old → t ∈ stamp n)
    (stampBefore : ∀ n m, n < m → stamp n ∈ stamp m)
    (n : Nat) {x t : ZFSet.{u}} (entry : ZFSet.pair x t ∈ graphRestriction (P n) birth) :
    t ∈ stamp n := by
  obtain ⟨entry, hx⟩ := pair_mem_graphRestriction.1 entry
  rcases (code.entries x t).1 entry with original | ⟨m, _, notM, rfl⟩
  · exact oldBound n x t original
  · exact stampBefore m n (lt_of_not_ge (fun h => notM (mono n m h hx)))

include mono born in
theorem earlier_fiber
    (stampMono : ∀ n m, n ≤ m → stamp n ⊆ stamp m)
    (n : Nat) {x t : ZFSet.{u}} (before : t ∈ stamp n)
    (entry : ZFSet.pair x t ∈ birth) :
    x ∈ P n ∧ ZFSet.pair x t ∈ graphRestriction (P n) birth := by
  have hx : x ∈ P n := by
    rcases (code.entries x t).1 entry with original | ⟨m, hm, _, rfl⟩
    · exact mono 0 n (Nat.zero_le n) (ZFSet.pair_mem_prod.1 (born.1 original)).1
    · have smaller : m < n := lt_of_not_ge
        (fun h => ZFSet.mem_irrefl (stamp m) (stampMono n m h before))
      exact mono (m + 1) n (Nat.succ_le_of_lt smaller) hm
  exact ⟨hx, pair_mem_graphRestriction.2 ⟨entry, hx⟩⟩

end PartitionPilot.Forcing.NatBirthExtensionCode



namespace PartitionPilot.Forcing.GroundCompressionState
open SetFormula
universe u
variable {M : TransitiveGround.{u}}
variable {P0 r0 μ0 A0 τ I Sources Reps G m inv one T Filters : ZFSet.{u}}
variable {seed : FixedCompressionSeed P0 r0 μ0 A0 τ I Sources Reps G m inv one T Filters}
variable (state : GroundCompressionState M seed)
variable (data : GroundCompressionUnionData M state.data I Sources Reps G m one T)
variable (pairing : Realize M.sets SetFormula.pairing Fin.elim0)
variable (unions : Realize M.sets SetFormula.union Fin.elim0)
variable (powers : Realize M.sets powerSet Fin.elim0) (separation : SeparationSchema M.sets)
variable (hI : I ∈ M.sets) (hSources : Sources ∈ M.sets) (hReps : Reps ∈ M.sets)
variable (hG : G ∈ M.sets) (hT : T ∈ M.sets)
variable {base stamps limit old birth : ZFSet.{u}}
variable (code : NatBirthExtensionCode (fun n => (state.data.iterate M I Sources Reps G T n).D)
    (compressionStamp base) old birth)
variable (born : ZFSet.IsFunc state.data.D limit old)
variable (times : CompressionStampCode base stamps limit)
include pairing unions powers separation hI hSources hReps hG hT code

include data born times in
theorem canonical_birth_function (n : Nat) :
    ZFSet.IsFunc (state.data.iterate M I Sources Reps G T n).D limit
      (graphRestriction (state.data.iterate M I Sources Reps G T n).D birth) :=
  code.restriction_function (data.fieldUnion 0)
    (fun _ _ h => (state.canonical_iterate_graphs_mono pairing unions powers separation
      hI hSources hReps hG hT h).1) born times.stamp_mem_limit n

include born in
theorem canonical_birth_step (n : Nat) :
    graphRestriction (state.data.iterate M I Sources Reps G T (n + 1)).D birth =
      taggedBirth (state.data.iterate M I Sources Reps G T n).D
        (state.data.iterate M I Sources Reps G T n).fresh
        (graphRestriction (state.data.iterate M I Sources Reps G T n).D birth)
        (compressionStamp base n) :=
  code.restriction_step
    (fun _ _ h => (state.canonical_iterate_graphs_mono pairing unions powers separation
      hI hSources hReps hG hT h).1) born n rfl

theorem canonical_birth_before_stamp
    (oldBound : ∀ x t, ZFSet.pair x t ∈ old → t ∈ base ∨ t = base)
    (n : Nat) {x t : ZFSet.{u}}
    (entry : ZFSet.pair x t ∈ graphRestriction (state.data.iterate M I Sources Reps G T n).D birth) :
    t ∈ compressionStamp base n :=
  code.restriction_bound
    (fun _ _ h => (state.canonical_iterate_graphs_mono pairing unions powers separation
      hI hSources hReps hG hT h).1)
    (fun n x t h => compressionStamp_old_mem (oldBound x t h) n)
    (fun n k h => (compressionStamp_mem_iff base n k).2 h) n entry

include data born times in
theorem canonical_birth_oldMeet
    (oldBound : ∀ x t, ZFSet.pair x t ∈ old → t ∈ base ∨ t = base)
    (oldMeet : OldMeetCode state.data.rD state.data.μD old) (n : Nat) :
    OldMeetCode (state.data.iterate M I Sources Reps G T n).rD
      (state.data.iterate M I Sources Reps G T n).μD
      (graphRestriction (state.data.iterate M I Sources Reps G T n).D birth) := by
  induction n with
  | zero =>
    rw [code.restriction_zero
      (fun _ _ h => (state.canonical_iterate_graphs_mono pairing unions powers separation
        hI hSources hReps hG hT h).1) born]
    exact oldMeet
  | succ n ih =>
    obtain ⟨current, equal⟩ := state.canonical_iterate_valid pairing unions powers separation
      hI hSources hReps hG hT n
    have finite : ZFSet.IsFunc current.data.D limit
        (graphRestriction (state.data.iterate M I Sources Reps G T n).D birth) := by
      simpa only [equal] using state.canonical_birth_function data pairing unions powers separation
        hI hSources hReps hG hT code born times n
    have oldLaw : OldMeetCode current.data.rD current.data.μD
        (graphRestriction (state.data.iterate M I Sources Reps G T n).D birth) := by
      simpa only [equal] using ih
    have earlier (x t : ZFSet.{u})
        (h : ZFSet.pair x t ∈ graphRestriction (state.data.iterate M I Sources Reps G T n).D birth) :=
      state.canonical_birth_before_stamp pairing unions powers separation
        hI hSources hReps hG hT code oldBound n h
    have result := current.batch.batchBirth_oldMeet finite earlier oldLaw
    change OldMeetCode current.data.currentOrder current.data.currentMeet
      (taggedBirth current.data.D current.data.fresh
        (graphRestriction (state.data.iterate M I Sources Reps G T n).D birth)
        (compressionStamp base n)) at result
    rw [state.canonical_birth_step pairing unions powers separation hI hSources hReps hG hT code born n]
    simpa only [equal, RecursiveStateData.iterate_succ, RecursiveStateData.successor] using result

end PartitionPilot.Forcing.GroundCompressionState



namespace PartitionPilot.Forcing.GroundCompressionState
open SetFormula
universe u
variable {M : TransitiveGround.{u}}
variable {P0 r0 μ0 A0 τ I Sources Reps G m inv one T Filters : ZFSet.{u}}
variable {seed : FixedCompressionSeed P0 r0 μ0 A0 τ I Sources Reps G m inv one T Filters}
variable (state : GroundCompressionState M seed)
variable (data : GroundCompressionUnionData M state.data I Sources Reps G m one T)
variable (pairing : Realize M.sets SetFormula.pairing Fin.elim0)
variable (unions : Realize M.sets SetFormula.union Fin.elim0)
variable (powers : Realize M.sets powerSet Fin.elim0) (separation : SeparationSchema M.sets)
variable (hI : I ∈ M.sets) (hSources : Sources ∈ M.sets) (hReps : Reps ∈ M.sets)
variable (hG : G ∈ M.sets) (hT : T ∈ M.sets)
variable {base stamps limit old birth : ZFSet.{u}}
variable (code : NatBirthExtensionCode (fun n => (state.data.iterate M I Sources Reps G T n).D)
    (compressionStamp base) old birth)
variable (born : ZFSet.IsFunc state.data.D limit old)
variable {Space sourceOrder sourceMeet : ZFSet.{u} → ZFSet.{u}}
include pairing unions powers separation hI hSources hReps hG hT code born

noncomputable def canonical_birth_layer_to_union (n : Nat) {t : ZFSet.{u}}
    (before : t ∈ compressionStamp base n)
    (layer : CodedGrowthLayer M Space sourceOrder sourceMeet
      (state.data.iterate M I Sources Reps G T n).D
      (state.data.iterate M I Sources Reps G T n).rD
      (state.data.iterate M I Sources Reps G T n).μD
      (graphRestriction (state.data.iterate M I Sources Reps G T n).D birth) t) :
    CodedGrowthLayer M Space sourceOrder sourceMeet
      (data.fields 0) (data.fields 1) (data.fields 2) birth t := by
  have mono := fun n k h => (state.canonical_iterate_graphs_mono pairing unions powers separation
    hI hSources hReps hG hT (n := n) (k := k) h).1
  have ground : (state.data.iterate M I Sources Reps G T n).D ∈ M.sets := by
    obtain ⟨current, equal⟩ := state.canonical_iterate_valid pairing unions powers separation
      hI hSources hReps hG hT n
    rw [← equal]
    exact current.ground.carrier
  exact layer.of_literal_extension separation ground
    ((data.fieldUnion 0).subset n) ((data.fieldUnion 1).subset n)
    ((data.fieldUnion 2).subset n)
    (graphRestriction_subset (state.data.iterate M I Sources Reps G T n).D birth)
    (fun _ _ entry => code.earlier_fiber mono born
      (fun _ _ h => compressionStamp_subset base h) n before entry)

noncomputable def prior_birth_layer_to_union {t : ZFSet.{u}} (priorTime : t ∈ base ∨ t = base)
    (layer : CodedGrowthLayer M Space sourceOrder sourceMeet
      state.data.D state.data.rD state.data.μD old t) :
    CodedGrowthLayer M Space sourceOrder sourceMeet
      (data.fields 0) (data.fields 1) (data.fields 2) birth t := by
  have mono := fun n k h => (state.canonical_iterate_graphs_mono pairing unions powers separation
    hI hSources hReps hG hT (n := n) (k := k) h).1
  have zero := code.restriction_zero mono born
  apply state.canonical_birth_layer_to_union data pairing unions powers separation
    hI hSources hReps hG hT code born 0 (compressionStamp_old_mem priorTime 0)
  rw [zero]
  simpa only [RecursiveStateData.iterate_zero] using layer

def limit_birth_layer_empty (times : CompressionStampCode base stamps limit) :
    CodedGrowthLayer M Space sourceOrder sourceMeet
      (data.fields 0) (data.fields 1) (data.fields 2) birth limit := by
  have mono := fun n k h => (state.canonical_iterate_graphs_mono pairing unions powers separation
    hI hSources hReps hG hT (n := n) (k := k) h).1
  have function := code.function (data.fieldUnion 0) mono born times.stamp_mem_limit
  exact .empty_at_birth_bound ⟨data.fields 0, data.ground 0⟩
    (fun _ _ entry => (ZFSet.pair_mem_prod.1 (function.1 entry)).2)

end PartitionPilot.Forcing.GroundCompressionState



namespace PartitionPilot.Forcing
universe u

structure GroundCompressionBirthData (M : TransitiveGround.{u}) (initial : RecursiveStateData.{u})
    (I Sources Reps G m one T : ZFSet.{u})
    (data : GroundCompressionUnionData M initial I Sources Reps G m one T)
    (base old : ZFSet.{u}) where
  stamps : ZFSet.{u}
  stamps_ground : stamps ∈ M.sets
  limit : ZFSet.{u}
  limit_ground : limit ∈ M.sets
  times : CompressionStampCode base stamps limit
  birth : ZFSet.{u}
  birth_ground : birth ∈ M.sets
  extension : NatBirthExtensionCode (fun n => (initial.iterate M I Sources Reps G T n).D)
    (compressionStamp base) old birth
  family : ZFSet.{u}
  family_ground : family ∈ M.sets
  family_function : FunctionGraphOn ZFSet.omega family
  family_entries : ∀ n b, ZFSet.pair (natSetCode n) b ∈ family ↔
    b = graphRestriction (initial.iterate M I Sources Reps G T n).D birth
  initial_function : ZFSet.IsFunc initial.D limit old
  initial_bound : ∀ x t, ZFSet.pair x t ∈ old → t ∈ base ∨ t = base
  function : ZFSet.IsFunc (data.fields 0) limit birth
  original : graphRestriction initial.D birth = old
  finite_old_meet : ∀ n, OldMeetCode (initial.iterate M I Sources Reps G T n).rD
    (initial.iterate M I Sources Reps G T n).μD
    (graphRestriction (initial.iterate M I Sources Reps G T n).D birth)
  old_meet : OldMeetCode (data.fields 1) (data.fields 2) birth
  no_limit_birth : ∀ x, ZFSet.pair x limit ∉ birth

end PartitionPilot.Forcing

end OAI