openAI-math-dataset / lean /OAI /MathematicalPhysics /NavierStokes /ShearFlows /ExpressionCompiler.lean
Download lean/OAI/MathematicalPhysics/NavierStokes/ShearFlows/ExpressionCompiler.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 11.6 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/MathematicalPhysics/NavierStokes/ShearFlows/ExpressionCompiler.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/MathematicalPhysics/NavierStokes/ShearFlows/ExpressionCompiler.lean
-
curl -L -o ExpressionCompiler.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/MathematicalPhysics/NavierStokes/ShearFlows/ExpressionCompiler.lean
11.6 kB
Lean 4 · 42
declarations statementsfull
def centerQ {n : ℕ} (R : RationalBox n) (j : Fin n) : ℚ := (R.lower j + R.upper j)/2 theorem centerQ_cast {n : ℕ} (R : RationalBox n) (j : Fin n) :
(R.centerQ j : ℝ) = R.center j := by simp [centerQ,center] def cutoff (L a b c d : ℚ) : PeriodicExpr := ⟨L,a,d,ProfileExpr.cutoff a b c d⟩ def potential (L a b c d p : ℚ) : PeriodicExpr := ⟨L,a,d,ProfileExpr.potential a b c d p⟩ def mask (L a b c d p : ℚ) : PeriodicExpr := (potential L a b c d p).diff theorem cutoff_valid {L a b c d : ℚ} (hL : 0<L) (hab : a<b) (hcd : c<d) :
(cutoff L a b c d).Valid := by proof · 4 lines
refine ⟨hL, ?_⟩
dsimp [cutoff]
rw [ProfileExpr.val_cutoff]
exact (closedCutoff_support (by exact_mod_cast hab) (by exact_mod_cast hcd)).trans Ioo_subset_Icc_selftheorem potential_valid {L a b c d p : ℚ} (hL : 0<L) (hab : a<b) (hcd : c<d) :
(potential L a b c d p).Valid := by proof · 4 lines
refine ⟨hL, ?_⟩
dsimp [potential]
rw [ProfileExpr.val_potential]
exact maskPotential_support (by exact_mod_cast hab) (by exact_mod_cast hcd) _theorem mask_valid {L a b c d p : ℚ} (hL : 0<L) (hab : a<b) (hcd : c<d) :
(mask L a b c d p).Valid := valid_diff (potential_valid hL hab hcd) theorem cutoff_val (L a b c d : ℚ) :
(cutoff L a b c d).val = circleCutoff L a b c d := by proof · 1 line
simp only [val,cutoff,ProfileExpr.val_cutoff,circleCutoff]theorem potential_val (L a b c d p : ℚ) :
(potential L a b c d p).val = periodize L (fun x => (x-(p : ℝ))*closedCutoff a b c d x) := by proof · 1 line
simp only [val,potential,ProfileExpr.val_potential]theorem mask_val {L a b c d p : ℚ} (hL : 0<L) (hab : a<b) (hcd : c<d) :
(mask L a b c d p).val = circleMask L a b c d p := by proof · 2 lines
rw [mask, val_diff (potential_valid hL hab hcd), potential_val] rfl
def pulse (j : Fin 7) : PeriodicExpr := body · 1 line
⟨1,stageStart j,stageFinish j,(ProfileExpr.ramp (stageStart j) (stageFinish j)).diff⟩theorem pulse_valid (j : Fin 7) : (pulse j).Valid := by proof · 4 lines
refine ⟨by norm_num [pulse], ?_⟩
dsimp [pulse]
rw [ProfileExpr.val_diff,ProfileExpr.val_ramp]
exact (smoothPulse_support (by exact_mod_cast (stage_intervals j).2.1)).trans Ioo_subset_Icc_selftheorem pulse_val (j : Fin 7) : (pulse j).val = periodPulse j := by proof · 1 line
simp only [pulse,val,ProfileExpr.val_diff,ProfileExpr.val_ramp,periodPulse,smoothPulse,Rat.cast_one]def planeMask (L : ℚ) (R : RationalBox 2) (r : ℚ) : FieldExpr := body · 6 lines
letI := neZeroTwo
letI := neZeroFour
.mul (.atom 1 (PeriodicExpr.mask L (R.lower 0-2*r) (R.lower 0-r)
(R.upper 0+r) (R.upper 0+2*r) (R.centerQ 0)))
(.atom 2 (PeriodicExpr.cutoff L (R.lower 1-2*r) (R.lower 1-r)
(R.upper 1+r) (R.upper 1+2*r)))theorem planeMask_valid {L r : ℚ} (hL : 0<L) (hr : 0<r) (R : RationalBox 2) :
(planeMask L R r).Valid := proof · 2 lines
⟨PeriodicExpr.mask_valid hL (by linarith) (by linarith),
PeriodicExpr.cutoff_valid hL (by linarith) (by linarith)⟩theorem planeMask_val {L r : ℚ} (hL : 0<L) (hr : 0<r) (R : RationalBox 2) (y : SpaceTime) :
(planeMask L R r).val y = planarMask L R r (horizontal y.2) := by proof · 4 lines
simp only [planeMask,val,PeriodicExpr.mask_val hL (by linarith : R.lower 0-2*r<R.lower 0-r)
(by linarith : R.upper 0+r<R.upper 0+2*r),PeriodicExpr.cutoff_val]
change circleMask _ _ _ _ _ _ (y.2 0) * circleCutoff _ _ _ _ _ (y.2 1) = _
simp [planarMask,RationalBox.centerQ_cast,horizontal]def heightExpr (d : Input) (i : Fin d.instructions.length) : FieldExpr := body · 3 lines
.atom 3 (PeriodicExpr.mask d.period (d.privateHeight i-2*d.heightRadius)
(d.privateHeight i-d.heightRadius) (d.privateHeight i+d.heightRadius)
(d.privateHeight i+2*d.heightRadius) (d.privateHeight i))def horizontalExpr (d : Input) (i : Fin d.instructions.length) (j : Fin 2) : FieldExpr := body · 4 lines
.atom j.castSucc.succ (PeriodicExpr.potential d.period
(d.horizontalBox.lower j-2*d.horizontalRadius) (d.horizontalBox.lower j-d.horizontalRadius)
(d.horizontalBox.upper j+d.horizontalRadius) (d.horizontalBox.upper j+2*d.horizontalRadius)
((d.sources i).centerQ j))def sourceExpr (d : Input) (i : Fin d.instructions.length) : FieldExpr := body · 1 line
FieldExpr.planeMask d.period (d.sources i) d.sourceRadiusdef targetExpr (d : Input) (i : Fin d.instructions.length) : FieldExpr := body · 1 line
FieldExpr.planeMask d.period (d.targets i) d.targetRadiustheorem heightExpr_valid {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) :
(d.heightExpr i).Valid := by proof · 2 lines
have hr : 0<d.heightRadius := div_pos (heightSpacing_pos hd) (by norm_num)
exact PeriodicExpr.mask_valid hd.period_pos (by linarith) (by linarith)theorem heightExpr_val {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) (y : SpaceTime) :
(d.heightExpr i).val y = d.heightMask i (y.2 2) := by proof · 6 lines
have hr : 0<d.heightRadius := div_pos (heightSpacing_pos hd) (by norm_num)
simp only [Input.heightExpr,FieldExpr.val,PeriodicExpr.mask_val hd.period_pos
(by linarith : d.privateHeight i-2*d.heightRadius<d.privateHeight i-d.heightRadius)
(by linarith : d.privateHeight i+d.heightRadius<d.privateHeight i+2*d.heightRadius)]
change circleMask _ _ _ _ _ _ (y.2 2) = _
simp [Input.heightMask]theorem horizontalExpr_valid {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) (j : Fin 2) :
(d.horizontalExpr i j).Valid := by proof · 2 lines
have hr := horizontalRadius_pos hd
exact PeriodicExpr.potential_valid hd.period_pos (by linarith) (by linarith)theorem horizontalExpr_val (d : Input) (i : Fin d.instructions.length) (j : Fin 2) (y : SpaceTime) :
(d.horizontalExpr i j).val y = d.horizontalProfile i j (y.2 j.castSucc) := by proof · 5 lines
simp only [Input.horizontalExpr,FieldExpr.val,PeriodicExpr.potential_val,
RationalBox.centerQ_cast,Input.horizontalProfile]
congr 1
push_cast
rfltheorem sourceExpr_valid {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) :
(d.sourceExpr i).Valid := FieldExpr.planeMask_valid hd.period_pos (sourceRadius_pos hd) _ theorem targetExpr_valid {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) :
(d.targetExpr i).Valid := FieldExpr.planeMask_valid hd.period_pos (targetRadius_pos hd) _ theorem sourceExpr_val {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) (y : SpaceTime) :
(d.sourceExpr i).val y = d.sourceMask i (horizontal y.2) := proof · 1 line
FieldExpr.planeMask_val hd.period_pos (sourceRadius_pos hd) _ _theorem targetExpr_val {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) (y : SpaceTime) :
(d.targetExpr i).val y = d.targetMask i (horizontal y.2) := proof · 1 line
FieldExpr.planeMask_val hd.period_pos (targetRadius_pos hd) _ _def along (e : FieldExpr) (j : Fin 3) : VelocityExpr := fun k => if k = j then e else .const 0 theorem along_valid {e : FieldExpr} (he : e.Valid) (j : Fin 3) : (e.along j).Valid := by proof · 5 lines
intro k dsimp [along] split_ifs · exact he · trivial
theorem along_val (e : FieldExpr) (j : Fin 3) (y : SpaceTime) :
(e.along j).val y = e.val y • basis j := by proof · 5 lines
ext k
dsimp [along,VelocityExpr.val]
split_ifs with h
· subst k; simp [basis]
· simp [val,basis,Pi.single_eq_of_ne h]theorem sum_ofFn_val {n : ℕ} (e : Fin n → FieldExpr) (y : SpaceTime) :
(sum (List.ofFn e)).val y = ∑ i, (e i).val y := by proof · 2 lines
rw [val_sum,List.map_ofFn,List.sum_ofFn]
rfltheorem sum_ofFn_valid {n : ℕ} (e : Fin n → FieldExpr) (he : ∀ i, (e i).Valid) :
(sum (List.ofFn e)).Valid := by proof · 4 lines
apply valid_sum
intro f hf
obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hf
exact he idef branchExpr (d : Input) (i : Fin d.instructions.length) : Fin 7 → VelocityExpr := body · 14 lines
letI := neZeroTwo
letI := neZeroThree
![(FieldExpr.mul (.const (d.privateHeight i-d.codingHeight)) (d.sourceExpr i)).along 2,
(FieldExpr.mul (.mul (.const (-(d.instructions.get i).factor)) (d.heightExpr i))
(d.horizontalExpr i 0)).along 1,
(FieldExpr.mul (.mul (.const ((d.instructions.get i).factor⁻¹-1)) (d.heightExpr i))
(d.horizontalExpr i 1)).along 0,
(FieldExpr.mul (d.heightExpr i) (d.horizontalExpr i 0)).along 1,
(FieldExpr.mul (.mul (.const ((d.instructions.get i).factor-1)) (d.heightExpr i))
(d.horizontalExpr i 1)).along 0,
(fun k => .mul (d.heightExpr i) (.const
(![ (d.targets i).centerQ 0-(d.sources i).centerQ 0,
(d.targets i).centerQ 1-(d.sources i).centerQ 1, 0] k))),
(FieldExpr.mul (.const (d.codingHeight-d.privateHeight i)) (d.targetExpr i)).along 2]def spatialExpr (d : Input) (j : Fin 7) : VelocityExpr := body · 1 line
fun k => FieldExpr.sum (List.ofFn (fun i => d.branchExpr i j k))def velocityExpr (d : Input) : VelocityExpr := fun k => body · 1 line
FieldExpr.sum (List.ofFn (fun j => .mul (.atom 0 (PeriodicExpr.pulse j)) (d.spatialExpr j k)))theorem branchExpr_valid {d : Input} (hd : ValidInput d) (i : Fin d.instructions.length) (j : Fin 7) :
(d.branchExpr i j).Valid := by proof · 13 lines
have hs := sourceExpr_valid hd i
have ht := targetExpr_valid hd i
have hz := heightExpr_valid hd i
have hx := horizontalExpr_valid hd i 0
have hy := horizontalExpr_valid hd i 1
fin_cases j <;> dsimp [Input.branchExpr]
· apply FieldExpr.along_valid; exact ⟨trivial,hs⟩
· apply FieldExpr.along_valid; exact ⟨⟨trivial,hz⟩,hx⟩
· apply FieldExpr.along_valid; exact ⟨⟨trivial,hz⟩,hy⟩
· apply FieldExpr.along_valid; exact ⟨hz,hx⟩
· apply FieldExpr.along_valid; exact ⟨⟨trivial,hz⟩,hy⟩
· intro k; exact ⟨hz,trivial⟩
· apply FieldExpr.along_valid; exact ⟨trivial,ht⟩theorem spatialExpr_valid {d : Input} (hd : ValidInput d) (j : Fin 7) :
(d.spatialExpr j).Valid := fun k => FieldExpr.sum_ofFn_valid _ (fun i => branchExpr_valid hd i j k) theorem velocityExpr_valid {d : Input} (hd : ValidInput d) : d.velocityExpr.Valid := by proof · 4 lines
intro k
apply FieldExpr.sum_ofFn_valid
intro j
exact ⟨PeriodicExpr.pulse_valid j, spatialExpr_valid hd j k⟩theorem spatialExpr_val {d : Input} (hd : ValidInput d) (j : Fin 7) (y : SpaceTime) :
(d.spatialExpr j).val y = d.spatialFields j y.2 := by proof · 18 lines
ext k
change (FieldExpr.sum _).val y = _
rw [FieldExpr.sum_ofFn_val]
fin_cases j <;> simp only [Input.spatialFields,sevenFields]
all_goals
simp only [Matrix.cons_val, Fin.reduceFinMk, Fin.isValue, Fin.zero_eta,
transverseSum,Finset.sum_apply]
apply Finset.sum_congr rfl
intro i _
fin_cases k <;>
simp [Input.branchExpr, FieldExpr.along, FieldExpr.val, sourceExpr_val hd,
targetExpr_val hd,heightExpr_val hd, horizontalExpr_val,
selectTwo, horizontal, basis, atHeight, RationalBox.centerQ_cast]
all_goals
left
congr 1
ext k
fin_cases k <;> rfltheorem velocityExpr_val {d : Input} (hd : ValidInput d) : d.velocityExpr.val = d.realizingVelocity := by proof · 9 lines
funext y k
change (FieldExpr.sum _).val y = _
rw [FieldExpr.sum_ofFn_val]
simp only [FieldExpr.val,PeriodicExpr.pulse_val]
change (∑ j, periodPulse j y.1 * (d.spatialExpr j).val y k) = _
simp only [Input.realizingVelocity,pulsedSum,Finset.sum_apply,Pi.smul_apply,smul_eq_mul]
apply Finset.sum_congr rfl
intro j _
rw [spatialExpr_val hd]Outline
- def
centerQ16 - theorem
centerQ_cast18 - def
cutoff24 - def
potential25 - def
mask26 - theorem
cutoff_valid28 - theorem
potential_valid35 - theorem
mask_valid42 - theorem
cutoff_val45 - theorem
potential_val49 - theorem
mask_val53 - def
pulse58 - theorem
pulse_valid61 - theorem
pulse_val67 - def
planeMask74 - theorem
planeMask_valid82 - theorem
planeMask_val87 - def
heightExpr98 - def
horizontalExpr103 - def
sourceExpr109 - def
targetExpr112 - theorem
heightExpr_valid117 - theorem
heightExpr_val122 - theorem
horizontalExpr_valid131 - theorem
horizontalExpr_val136 - theorem
sourceExpr_valid144 - theorem
targetExpr_valid147 - theorem
sourceExpr_val150 - theorem
targetExpr_val154 - def
along160 - theorem
along_valid162 - theorem
along_val169 - theorem
sum_ofFn_val177 - theorem
sum_ofFn_valid182 - def
branchExpr193 - def
spatialExpr209 - def
velocityExpr212 - theorem
branchExpr_valid217 - theorem
spatialExpr_valid233 - theorem
velocityExpr_valid236 - theorem
spatialExpr_val242 - theorem
velocityExpr_val263