Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexOrientationRates.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexOrientationRates.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexOrientationRates.lean
-
curl -L -o ComplexOrientationRates.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexOrientationRates.lean
12.5 kB
| import Mathlib.Data.Fintype.Perm | |
| import Mathlib.Data.Fintype.BigOperators | |
| import Mathlib.Algebra.BigOperators.Field | |
| import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise | |
| import Mathlib.Analysis.SpecialFunctions.Log.Basic | |
| import Mathlib.Tactic.FieldSimp | |
| import Mathlib.Tactic.NormNum | |
| import Mathlib.Tactic.Ring | |
| namespace OAI | |
| /-! Finite entropy, rate estimates and ordered asymptotic limits. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.Foundation | |
| namespace OrientationRates | |
| open scoped BigOperators | |
| abbrev Orientation := Equiv.Perm (Fin 3) | |
| @[simp] theorem orientation_card : Fintype.card Orientation = 6 := by | |
| rw [Fintype.card_perm] | |
| decide | |
| def relativeOrientation (relative : Orientation) : Orientation β Orientation where | |
| toFun outer := outer * relative | |
| invFun original := original * relativeβ»ΒΉ | |
| left_inv outer := by simp [mul_assoc] | |
| right_inv original := by simp [mul_assoc] | |
| @[simp] theorem relativeOrientation_apply (relative outer : Orientation) : | |
| relativeOrientation relative outer = outer * relative := rfl | |
| theorem unique_outer_orientation (relative original : Orientation) : | |
| β! outer : Orientation, outer * relative = original := | |
| (relativeOrientation relative).bijective.existsUnique original | |
| theorem sum_relative_orientation {M : Type*} [AddCommMonoid M] | |
| (relative : Orientation) (value : Orientation β M) : | |
| (β outer, value (outer * relative)) = β original, value original := | |
| (relativeOrientation relative).sum_comp value | |
| theorem prod_relative_orientation {M : Type*} [CommMonoid M] | |
| (relative : Orientation) (value : Orientation β M) : | |
| (β outer, value (outer * relative)) = β original, value original := | |
| (relativeOrientation relative).prod_comp value | |
| theorem site_population_in_orientation {M : Type*} [AddCommMonoid M] | |
| (relative original : Orientation) (population : M) : | |
| (β outer : Orientation, | |
| if outer * relative = original then population else 0) = population := by | |
| classical | |
| rw [sum_relative_orientation relative | |
| (fun orientation => if orientation = original then population else 0)] | |
| simp | |
| theorem histogram_in_original_orientation {Site M : Type*} | |
| [Fintype Site] [AddCommMonoid M] | |
| (relative : Site β Orientation) (population : Site β M) | |
| (original : Orientation) : | |
| (β site, β outer : Orientation, | |
| if outer * relative site = original then population site else 0) = | |
| β site, population site := by | |
| classical | |
| apply Finset.sum_congr rfl | |
| intro site _ | |
| exact site_population_in_orientation (relative site) original (population site) | |
| theorem target_multiplicity (targetCount : β) : | |
| (β _ : Orientation, targetCount) = targetCount ^ 6 := by | |
| simp | |
| section FiniteRates | |
| variable {Node Grade : Type*} [Fintype Node] [Fintype Grade] | |
| def outputLaw (n : β) (population : Node β β) (law : Node β Grade β β) | |
| (grade : Grade) : β := | |
| (β node, population node * law node grade) / n | |
| def affineScore (offset : β) (coefficient law : Grade β β) : β := | |
| offset + β grade, coefficient grade * law grade | |
| def totalNodeUtility (population utility : Node β β) : β := | |
| β node, population node * utility node | |
| def totalCost (population : Node β β) (law : Node β Grade β β) | |
| (offset : β) (coefficient : Grade β β) (utility : Node β β) : β := | |
| β node, population node * (affineScore offset coefficient (law node) - utility node) | |
| omit [Fintype Grade] in | |
| theorem outputLaw_nonnegative (n : β) (population : Node β β) | |
| (law : Node β Grade β β) | |
| (hp : β node, 0 β€ population node) (hq : β node grade, 0 β€ law node grade) | |
| (grade : Grade) : 0 β€ outputLaw n population law grade := by | |
| apply div_nonneg | |
| Β· exact Finset.sum_nonneg fun node _ => mul_nonneg (hp node) (hq node grade) | |
| Β· exact Nat.cast_nonneg n | |
| theorem outputLaw_total (n : β) (hn : n β 0) (population : Node β β) | |
| (law : Node β Grade β β) | |
| (hp : β node, population node = (n : β)) | |
| (hq : β node, β grade, law node grade = 1) : | |
| β grade, outputLaw n population law grade = 1 := by | |
| have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn | |
| simp only [outputLaw, β Finset.sum_div] | |
| rw [Finset.sum_comm] | |
| simp only [β Finset.mul_sum, hq, mul_one, hp, div_self hn'] | |
| theorem weighted_affineScore (population : Node β β) (law : Node β Grade β β) | |
| (offset : β) (coefficient : Grade β β) : | |
| (β node, population node * affineScore offset coefficient (law node)) = | |
| (β node, population node) * offset + | |
| β grade, coefficient grade * (β node, population node * law node grade) := by | |
| simp only [affineScore, mul_add, Finset.sum_add_distrib, β Finset.sum_mul] | |
| congr 1 | |
| calc | |
| (β node, population node * β grade, coefficient grade * law node grade) = | |
| β node, β grade, coefficient grade * (population node * law node grade) := by | |
| apply Finset.sum_congr rfl | |
| intro node _ | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro grade _ | |
| ring | |
| _ = β grade, coefficient grade * β node, population node * law node grade := by | |
| rw [Finset.sum_comm] | |
| simp only [Finset.mul_sum] | |
| theorem weighted_affineScore_eq (n : β) (hn : n β 0) | |
| (population : Node β β) (law : Node β Grade β β) | |
| (hp : β node, population node = (n : β)) | |
| (offset : β) (coefficient : Grade β β) : | |
| (β node, population node * affineScore offset coefficient (law node)) = | |
| (n : β) * affineScore offset coefficient (outputLaw n population law) := by | |
| have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn | |
| rw [weighted_affineScore, hp] | |
| simp only [affineScore, outputLaw] | |
| conv_rhs => rw [mul_add, Finset.mul_sum] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro grade _ | |
| field_simp [hn'] | |
| theorem totalCost_eq (n : β) (hn : n β 0) | |
| (population : Node β β) (law : Node β Grade β β) | |
| (hp : β node, population node = (n : β)) | |
| (offset : β) (coefficient : Grade β β) (utility : Node β β) : | |
| totalCost population law offset coefficient utility = | |
| (n : β) * affineScore offset coefficient (outputLaw n population law) - | |
| totalNodeUtility population utility := by | |
| simp only [totalCost, mul_sub, Finset.sum_sub_distrib, totalNodeUtility] | |
| rw [weighted_affineScore_eq n hn population law hp] | |
| theorem utility_rate_identity (n : β) (hn : n β 0) | |
| (population : Node β β) (law : Node β Grade β β) | |
| (hp : β node, population node = (n : β)) | |
| (offset targetRate : β) (coefficient : Grade β β) (utility : Node β β) : | |
| (targetRate + totalNodeUtility population utility) / n = | |
| affineScore offset coefficient (outputLaw n population law) + | |
| (targetRate - totalCost population law offset coefficient utility) / n := by | |
| have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn | |
| rw [totalCost_eq n hn population law hp] | |
| field_simp [hn'] | |
| ring | |
| theorem finite_utility_bound (n : β) (hn : n β 0) | |
| (population : Node β β) (law : Node β Grade β β) | |
| (hp : β node, population node = (n : β)) | |
| (offset targetRate error actualUtility : β) | |
| (coefficient : Grade β β) (utility : Node β β) | |
| (construction : (targetRate + totalNodeUtility population utility) / n - error β€ | |
| actualUtility) : | |
| affineScore offset coefficient (outputLaw n population law) + | |
| (targetRate - totalCost population law offset coefficient utility) / n - error β€ | |
| actualUtility := by | |
| rwa [utility_rate_identity n hn population law hp offset targetRate coefficient utility] | |
| at construction | |
| end FiniteRates | |
| section PhysicalNormalization | |
| variable {Node : Type*} [Fintype Node] | |
| theorem log_resource_product (copies : Node β β) (resource : Node β β) | |
| (hresource : β node, resource node β 0) : | |
| Real.log (β node, resource node ^ copies node) = | |
| β node, (copies node : β) * Real.log (resource node) := by | |
| rw [Real.log_prod (s := Finset.univ) (f := fun node => resource node ^ copies node) | |
| (fun node _ => pow_ne_zero _ (hresource node))] | |
| simp only [Real.log_pow] | |
| theorem log_direct_multiplicity (targetCount : β) (htarget : targetCount β 0) | |
| (copies : Node β β) (labels : Node β β) (hlabels : β node, labels node β 0) : | |
| Real.log (targetCount ^ 6 * β node, labels node ^ copies node) = | |
| 6 * Real.log targetCount + β node, (copies node : β) * Real.log (labels node) := by | |
| have hprod : (β node, labels node ^ copies node) β 0 := | |
| Finset.prod_ne_zero_iff.mpr (fun node _ => pow_ne_zero _ (hlabels node)) | |
| rw [Real.log_mul (pow_ne_zero _ htarget) hprod, Real.log_pow, | |
| log_resource_product copies labels hlabels] | |
| norm_num | |
| theorem raw_utility_accounting (targetCount : β) (htarget : targetCount β 0) | |
| (copies : Node β β) (labels rank volume : Node β β) | |
| (hlabels : β node, labels node β 0) (hrank : β node, rank node β 0) | |
| (hvolume : β node, volume node β 0) (volumeWeight : β) : | |
| Real.log (targetCount ^ 6 * β node, labels node ^ copies node) - | |
| Real.log (β node, rank node ^ copies node) + | |
| volumeWeight * Real.log (β node, volume node ^ copies node) = | |
| 6 * Real.log targetCount + | |
| β node, (copies node : β) * | |
| (Real.log (labels node) - Real.log (rank node) + | |
| volumeWeight * Real.log (volume node)) := by | |
| rw [log_direct_multiplicity targetCount htarget copies labels hlabels, | |
| log_resource_product copies rank hrank, log_resource_product copies volume hvolume] | |
| simp only [mul_add, mul_sub, Finset.sum_add_distrib, Finset.sum_sub_distrib] | |
| rw [Finset.mul_sum] | |
| have hvolumeSum : | |
| (β node, volumeWeight * ((copies node : β) * Real.log (volume node))) = | |
| β node, (copies node : β) * (volumeWeight * Real.log (volume node)) := by | |
| apply Finset.sum_congr rfl | |
| intro node _ | |
| ring | |
| rw [hvolumeSum] | |
| ring | |
| theorem physical_rate_normalization (bank horizon : β) | |
| (hbank : bank β 0) (hhorizon : horizon β 0) | |
| (blockSize copies : Node β β) (hsize : β node, blockSize node β 0) | |
| (population rawNodeUtility : Node β β) (targetLog : β) | |
| (tiling : β node, (bank : β) * population node = | |
| (copies node : β) * blockSize node) : | |
| (6 * targetLog + β node, (copies node : β) * rawNodeUtility node) / | |
| (6 * bank * horizon) = | |
| (targetLog / bank + totalNodeUtility population | |
| (fun node => rawNodeUtility node / (6 * blockSize node))) / horizon := by | |
| have hbank' : (bank : β) β 0 := Nat.cast_ne_zero.mpr hbank | |
| have hhorizon' : (horizon : β) β 0 := Nat.cast_ne_zero.mpr hhorizon | |
| have hnode (node : Node) : | |
| population node * (rawNodeUtility node / (6 * blockSize node)) = | |
| (copies node : β) * rawNodeUtility node / (6 * bank) := by | |
| have hsize' : (blockSize node : β) β 0 := Nat.cast_ne_zero.mpr (hsize node) | |
| have hp : population node = (copies node : β) * blockSize node / bank := by | |
| apply (eq_div_iff hbank').mpr | |
| simpa only [mul_comm] using tiling node | |
| rw [hp] | |
| field_simp [hbank', hsize'] | |
| simp only [totalNodeUtility, hnode, β Finset.sum_div] | |
| field_simp [hbank', hhorizon'] | |
| theorem physical_cost_rate_identity {Grade : Type*} [Fintype Grade] | |
| (bank horizon : β) (hbank : bank β 0) (hhorizon : horizon β 0) | |
| (blockSize copies : Node β β) (hsize : β node, blockSize node β 0) | |
| (population rawNodeUtility : Node β β) (law : Node β Grade β β) | |
| (targetLog offset : β) (coefficient : Grade β β) | |
| (tiling : β node, (bank : β) * population node = | |
| (copies node : β) * blockSize node) | |
| (total : β node, population node = (horizon : β)) : | |
| (6 * targetLog + β node, (copies node : β) * rawNodeUtility node) / | |
| (6 * bank * horizon) = | |
| affineScore offset coefficient (outputLaw horizon population law) + | |
| (targetLog / bank - totalCost population law offset coefficient | |
| (fun node => rawNodeUtility node / (6 * blockSize node))) / horizon := by | |
| rw [physical_rate_normalization bank horizon hbank hhorizon blockSize copies | |
| hsize population rawNodeUtility targetLog tiling] | |
| exact utility_rate_identity horizon hhorizon population law total offset | |
| (targetLog / bank) coefficient (fun node => rawNodeUtility node / (6 * blockSize node)) | |
| end PhysicalNormalization | |
| end OrientationRates | |
| end MatrixMultiplication.Foundation | |
| end | |
| end OAI | |