math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /FieldConstruction /ConstructionLabels.lean
Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/ConstructionLabels.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/ConstructionLabels.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/ConstructionLabels.lean
-
curl -L -o ConstructionLabels.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/ConstructionLabels.lean
13.7 kB
| import OAI.LinearAlgebra.MatrixMultiplication.FieldConstruction.ScheduledYield | |
| import OAI.LinearAlgebra.MatrixMultiplication.FieldConstruction.ScheduledPositivity | |
| import OAI.LinearAlgebra.MatrixMultiplication.FieldConstruction.TerminalRates | |
| import OAI.LinearAlgebra.MatrixMultiplication.Entropy.FloorExponentialRates | |
| namespace OAI | |
| /-! Tensor extraction over arbitrary fields and its asymptotic rate. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.AllFieldConstructionRates | |
| open MatrixMultiplication.Foundation AllFieldHistory AllFieldScheduledYield | |
| open AllFieldActiveLaws Filter | |
| open scoped BigOperators Topology Classical | |
| variable {K : β} | |
| def denominator (allocation : Allocation) : β := populationLength (K := K) allocation 1 | |
| theorem denominator_pos (allocation : Allocation) : 0 < denominator (K := K) allocation := | |
| AllFieldPopulationCounts.blockLength_pos _ (by decide) | |
| theorem population_length (allocation : Allocation) (m : β) : | |
| populationLength (K := K) allocation m = m * denominator (K := K) allocation := | |
| populationLength_dilation allocation m | |
| theorem populationLength_tendsto (allocation : Allocation) : | |
| Tendsto (populationLength (K := K) allocation) atTop atTop := by | |
| apply tendsto_atTop.mpr | |
| intro b | |
| filter_upwards [eventually_ge_atTop b] with m hm | |
| rw [population_length] | |
| exact hm.trans (by simpa using Nat.mul_le_mul_left m (denominator_pos allocation)) | |
| abbrev Slot (K : β) := Unit β (Fin (K + 2) Γ Placement) | |
| def capacity (allocation : Allocation) : Slot K β β | |
| | .inl _ => (K : β) * AllFieldInitialEntropy.nativeH0 | |
| | .inr p => Staggering.minCapacity | |
| (physicalTickCapacity allocation p.1.val (workCapacity (K := K)) p.2) | |
| def selectionRate (allocation : Allocation) (Ξ΄ : β) (slot : Slot K) : β := | |
| (denominator (K := K) allocation : β) * capacity allocation slot - Ξ΄ | |
| def initialCount (allocation : Allocation) (Ξ΄ : β) (m : β) : β := | |
| FloorExponentialRates.count (selectionRate (K := K) allocation Ξ΄ (.inl ())) m | |
| def groupCount (allocation : Allocation) (Ξ΄ : β) (m : β) | |
| (tick : Fin (K + 2)) (Ο : Placement) : β := | |
| FloorExponentialRates.count (selectionRate allocation Ξ΄ (.inr (tick, Ο))) m | |
| theorem initialCount_eq (allocation : Allocation) (Ξ΄ : β) (m : β) : | |
| initialCount (K := K) allocation Ξ΄ m = | |
| βReal.exp ((m : β) * ((populationLength (K := K) allocation 1 : β) * | |
| ((K : β) * AllFieldInitialEntropy.nativeH0) - Ξ΄))ββ := rfl | |
| theorem groupCount_eq_native (allocation : Allocation) (Ξ΄ : β) (m : β) | |
| (tick : Fin (K + 2)) (Ο : Placement) : | |
| groupCount allocation Ξ΄ m tick Ο = | |
| βReal.exp ((m : β) * ((populationLength (K := K) allocation 1 : β) * | |
| ((1 / 6 : β) * Staggering.minCapacity (FiniteSchedule.tickCapacity K | |
| AllFieldNativeCapacity.nativeLA AllFieldNativeCapacity.nativeLB | |
| (AllFieldNativeCapacity.nativeLC (fun i => (allocation.mass i : β))) tick.val)) - Ξ΄))ββ := by | |
| unfold groupCount FloorExponentialRates.count selectionRate | |
| simp only [capacity, physical_order_native_capacity, | |
| PhysicalOrders.minCapacity_mul _ _ (by norm_num : (0 : β) β€ 1 / 6)] | |
| rfl | |
| abbrev SelectedLabels (allocation : Allocation) (Ξ΄ : β) (m : β) := | |
| Fin (initialCount (K := K) allocation Ξ΄ m) Γ | |
| β tick : Fin (K + 2), β Ο : Placement, Fin (groupCount allocation Ξ΄ m tick Ο) | |
| theorem card_selected (allocation : Allocation) (Ξ΄ : β) (m : β) : | |
| Fintype.card (SelectedLabels (K := K) allocation Ξ΄ m) = | |
| initialCount (K := K) allocation Ξ΄ m * | |
| β tick : Fin (K + 2), β Ο : Placement, groupCount allocation Ξ΄ m tick Ο := by | |
| simp only [SelectedLabels, Fintype.card_prod, Fintype.card_pi, Fintype.card_fin] | |
| theorem card_selected_product (allocation : Allocation) (Ξ΄ : β) (m : β) : | |
| Fintype.card (SelectedLabels (K := K) allocation Ξ΄ m) = | |
| (β slot : Slot K, FloorExponentialRates.count (selectionRate allocation Ξ΄ slot) m) := by | |
| rw [card_selected] | |
| simp [Slot, initialCount, groupCount, Fintype.prod_sum_type, Fintype.prod_prod_type] | |
| theorem card_selected_from_factors | |
| (Initial : Type*) [Fintype Initial] | |
| (Groups : Fin (K + 2) β Placement β Type*) [β tick Ο, Fintype (Groups tick Ο)] | |
| (allocation : Allocation) (Ξ΄ : β) (m : β) | |
| (hI : Fintype.card Initial = initialCount (K := K) allocation Ξ΄ m) | |
| (hG : β tick Ο, Fintype.card (Groups tick Ο) = groupCount allocation Ξ΄ m tick Ο) : | |
| Fintype.card (Initial Γ β tick Ο, Groups tick Ο) = | |
| Fintype.card (SelectedLabels (K := K) allocation Ξ΄ m) := by | |
| simp only [Fintype.card_prod, Fintype.card_pi, hI, hG, Fintype.card_fin] | |
| theorem slot_card : Fintype.card (Slot K) = 1 + 6 * (K + 2) := by | |
| simp [Slot, Placement, Fintype.card_perm, Nat.factorial_succ] | |
| omega | |
| theorem sum_capacity (allocation : Allocation) : | |
| (β slot : Slot K, capacity allocation slot) = | |
| (K : β) * AllFieldInitialEntropy.nativeH0 + physicalYield K allocation := by | |
| simp only [Slot, Fintype.sum_sum_type, capacity, Fintype.sum_unique, | |
| Fintype.sum_prod_type] | |
| congr 1 | |
| exact Fin.sum_univ_eq_sum_range (fun tick : β => | |
| β Ο : Placement, Staggering.minCapacity | |
| (physicalTickCapacity allocation tick (workCapacity (K := K)) Ο)) (K + 2) | |
| theorem sum_selectionRate (allocation : Allocation) (Ξ΄ : β) : | |
| (β slot : Slot K, selectionRate allocation Ξ΄ slot) = | |
| (denominator (K := K) allocation : β) * | |
| ((K : β) * AllFieldInitialEntropy.nativeH0 + physicalYield K allocation) - | |
| (1 + 6 * (K + 2) : β) * Ξ΄ := by | |
| simp only [selectionRate, Finset.sum_sub_distrib, β Finset.mul_sum, | |
| Finset.sum_const, Finset.card_univ, nsmul_eq_mul, slot_card, sum_capacity] | |
| theorem selected_pos (allocation : Allocation) (Ξ΄ : β) | |
| (hΞ΄ : β slot : Slot K, Ξ΄ β€ (denominator (K := K) allocation : β) * | |
| capacity allocation slot) (m : β) : | |
| 0 < Fintype.card (SelectedLabels (K := K) allocation Ξ΄ m) := by | |
| rw [card_selected_product] | |
| exact Finset.prod_pos fun slot _ => | |
| FloorExponentialRates.count_pos (sub_nonneg.mpr (hΞ΄ slot)) m | |
| theorem selected_rate (hK : 0 < K) (allocation : Allocation) (Ξ΄ : β) | |
| (hΞ΄ : β slot : Slot K, Ξ΄ β€ (denominator (K := K) allocation : β) * | |
| capacity allocation slot) : | |
| Tendsto (fun m : β => Real.log (Fintype.card | |
| (SelectedLabels (K := K) allocation Ξ΄ m) : β) / | |
| ((K : β) * populationLength (K := K) allocation m)) atTop | |
| (π (AllFieldInitialEntropy.nativeH0 + physicalYield K allocation / K - | |
| (1 + 6 * (K + 2) : β) * Ξ΄ / | |
| ((K : β) * denominator (K := K) allocation))) := by | |
| have h := (FloorExponentialRates.tendsto_log_prod_count_div_nat | |
| (selectionRate (K := K) allocation Ξ΄) (fun slot => sub_nonneg.mpr (hΞ΄ slot))).div_const | |
| ((K : β) * denominator (K := K) allocation) | |
| rw [sum_selectionRate] at h | |
| have hk : (K : β) β 0 := Nat.cast_ne_zero.mpr hK.ne' | |
| have hd : (denominator (K := K) allocation : β) β 0 := | |
| Nat.cast_ne_zero.mpr (denominator_pos allocation).ne' | |
| have hr : ((denominator (K := K) allocation : β) * | |
| ((K : β) * AllFieldInitialEntropy.nativeH0 + physicalYield K allocation) - | |
| (1 + 6 * (K + 2) : β) * Ξ΄) / ((K : β) * denominator (K := K) allocation) = | |
| AllFieldInitialEntropy.nativeH0 + physicalYield K allocation / K - | |
| (1 + 6 * (K + 2) : β) * Ξ΄ / | |
| ((K : β) * denominator (K := K) allocation) := by | |
| field_simp [hk, hd] | |
| rw [hr] at h | |
| apply h.congr | |
| intro m | |
| rw [card_selected_product, population_length, Nat.cast_mul] | |
| ring | |
| theorem exists_positive_slack (allocation : Allocation) | |
| (hcap : β slot : Slot K, 0 < capacity allocation slot) : | |
| β Ξ· : β, 0 < Ξ· β§ β Ξ΄ : β, Ξ΄ β€ Ξ· β β slot : Slot K, | |
| Ξ΄ β€ (denominator (K := K) allocation : β) * capacity allocation slot := by | |
| let Ξ· := Finset.univ.inf' (show (Finset.univ : Finset (Slot K)).Nonempty from | |
| β¨.inl (), Finset.mem_univ _β©) | |
| (fun slot => (denominator (K := K) allocation : β) * capacity allocation slot) | |
| refine β¨Ξ·, ?_, ?_β© | |
| Β· apply (Finset.lt_inf'_iff _).mpr | |
| intro slot _ | |
| exact mul_pos (Nat.cast_pos.mpr (denominator_pos allocation)) (hcap slot) | |
| Β· intro Ξ΄ hΞ΄ slot | |
| exact hΞ΄.trans (Finset.inf'_le _ (Finset.mem_univ slot)) | |
| theorem exists_slack_for_loss (hK : 0 < K) (allocation : Allocation) | |
| (hcap : β slot : Slot K, 0 < capacity allocation slot) | |
| {Ξ· : β} (hΞ· : 0 < Ξ·) : | |
| β Ξ΄ : β, 0 < Ξ΄ β§ | |
| (β slot : Slot K, Ξ΄ β€ (denominator (K := K) allocation : β) * | |
| capacity allocation slot) β§ | |
| (1 + 6 * (K + 2) : β) * Ξ΄ / | |
| ((K : β) * denominator (K := K) allocation) < Ξ· := by | |
| obtain β¨bound, hbound, hslotsβ© := exists_positive_slack allocation hcap | |
| have hk : (0 : β) < K := Nat.cast_pos.mpr hK | |
| have hd : (0 : β) < denominator (K := K) allocation := | |
| Nat.cast_pos.mpr (denominator_pos allocation) | |
| have hc : (0 : β) < (1 + 6 * (K + 2) : β) := by positivity | |
| let target := Ξ· * ((K : β) * denominator (K := K) allocation) / | |
| (1 + 6 * (K + 2) : β) | |
| have ht : 0 < target := div_pos (mul_pos hΞ· (mul_pos hk hd)) hc | |
| let Ξ΄ := min bound target / 2 | |
| have hm : 0 < min bound target := lt_min hbound ht | |
| have hΞ΄ : 0 < Ξ΄ := div_pos hm (by norm_num) | |
| have hΞ΄min : Ξ΄ < min bound target := by dsimp [Ξ΄]; linarith | |
| refine β¨Ξ΄, hΞ΄, hslots Ξ΄ (hΞ΄min.le.trans (min_le_left _ _)), ?_β© | |
| apply (div_lt_iffβ (mul_pos hk hd)).mpr | |
| have hsmall := (lt_div_iffβ hc).mp (hΞ΄min.trans_le (min_le_right bound target)) | |
| change Ξ΄ * ((1 + 6 * (K + 2) : β) : β) < | |
| Ξ· * ((K : β) * denominator (K := K) allocation) at hsmall | |
| simpa only [mul_comm Ξ΄] using hsmall | |
| theorem capacity_pos_of_native (hK : 2 β€ K) (allocation : Allocation) | |
| (ha : β i, 0 < AllFieldNativeCapacity.nativeLA i) | |
| (hb : β i, 0 < AllFieldNativeCapacity.nativeLB i) | |
| (hc : β i, 0 < AllFieldNativeCapacity.nativeLC | |
| (fun j => (allocation.mass j : β)) i) (slot : Slot K) : | |
| 0 < capacity allocation slot := by | |
| cases slot with | |
| | inl u => exact AllFieldScheduledPositivity.initial_capacity_pos K (by omega) | |
| | inr p => | |
| exact AllFieldScheduledPositivity.physical_order_capacity_pos K p.1.val hK | |
| p.1.isLt allocation p.2 ha hb hc | |
| theorem eventually_capacity_pos (hK : 2 β€ K) (allocation : β β Allocation) | |
| (h : β i, Tendsto (fun j => ((allocation j).mass i : β)) atTop | |
| (π (AllFieldNativeCapacity.nativeLambda i))) | |
| (ha : β i, 0 < AllFieldNativeCapacity.nativeLA i) | |
| (hb : β i, 0 < AllFieldNativeCapacity.nativeLB i) | |
| (hc : β i, 0 < AllFieldNativeCapacity.nativeLC AllFieldNativeCapacity.nativeLambda i) : | |
| βαΆ j in atTop, β slot : Slot K, 0 < capacity (allocation j) slot := by | |
| filter_upwards [AllFieldScheduledPositivity.eventually_physical_order_capacity_pos | |
| K hK allocation h ha hb hc] with j hj | |
| intro slot | |
| cases slot with | |
| | inl u => exact AllFieldScheduledPositivity.initial_capacity_pos K (by omega) | |
| | inr p => exact hj p.1.val p.1.isLt p.2 | |
| theorem terminalDilation_mul_one (K m : β) : | |
| AllFieldTerminalRates.terminalDilation K m = | |
| m * AllFieldTerminalRates.terminalDilation K 1 := by | |
| simp only [AllFieldTerminalRates.terminalDilation, | |
| AllFieldTerminalPopulations.dilation, one_mul] | |
| theorem terminalDilation_tendsto (K : β) : | |
| Tendsto (AllFieldTerminalRates.terminalDilation K) atTop atTop := by | |
| apply tendsto_atTop.mpr | |
| intro b | |
| filter_upwards [eventually_ge_atTop b] with m hm | |
| rw [terminalDilation_mul_one] | |
| have hD := AllFieldTerminalRates.terminalDilation_pos (K := K) (m := 1) (by decide) | |
| have hmul : m β€ m * AllFieldTerminalRates.terminalDilation K 1 := by | |
| simpa using Nat.mul_le_mul_left m hD | |
| exact hm.trans hmul | |
| theorem terminal_denominator (allocation : Allocation) : | |
| AllFieldTerminalRates.terminalLength allocation K 1 = | |
| AllFieldTerminalRates.terminalDilation K 1 * denominator (K := K) allocation := | |
| population_length allocation _ | |
| theorem selected_terminal_rate (hK : 0 < K) (allocation : Allocation) (Ξ΄ : β) | |
| (hΞ΄ : β slot : Slot K, Ξ΄ β€ (denominator (K := K) allocation : β) * | |
| capacity allocation slot) : | |
| Tendsto (fun m : β => Real.log (Fintype.card | |
| (SelectedLabels (K := K) allocation Ξ΄ (AllFieldTerminalRates.terminalDilation K m)) : β) / | |
| ((K : β) * AllFieldTerminalRates.terminalLength allocation K m)) atTop | |
| (π (AllFieldInitialEntropy.nativeH0 + physicalYield K allocation / K - | |
| (1 + 6 * (K + 2) : β) * Ξ΄ / | |
| ((K : β) * denominator (K := K) allocation))) := | |
| (selected_rate hK allocation Ξ΄ hΞ΄).comp (terminalDilation_tendsto K) | |
| theorem selected_terminal_rate_of_cardinality | |
| (Labels : β β Type*) [β m, Fintype (Labels m)] | |
| (hK : 0 < K) (allocation : Allocation) (Ξ΄ : β) | |
| (hΞ΄ : β slot : Slot K, Ξ΄ β€ (denominator (K := K) allocation : β) * | |
| capacity allocation slot) | |
| (cards : βαΆ m : β in atTop, Fintype.card (Labels m) = Fintype.card | |
| (SelectedLabels (K := K) allocation Ξ΄ (AllFieldTerminalRates.terminalDilation K m))) : | |
| Tendsto (fun m : β => Real.log (Fintype.card (Labels m) : β) / | |
| ((K : β) * AllFieldTerminalRates.terminalLength allocation K m)) atTop | |
| (π (AllFieldInitialEntropy.nativeH0 + physicalYield K allocation / K - | |
| (1 + 6 * (K + 2) : β) * Ξ΄ / | |
| ((K : β) * denominator (K := K) allocation))) := by | |
| apply (selected_terminal_rate hK allocation Ξ΄ hΞ΄).congr' | |
| filter_upwards [cards] with m hm | |
| rw [hm] | |
| end MatrixMultiplication.AllFieldConstructionRates | |
| end | |
| end OAI | |