Computable analysis · TaylorPolynomialValues · fd889115 k1
Definitionliuyao_ca_fd889115_k1_Analysis_TaylorPolynomialValuesca-fd889115-k1
Private dependency for the Distribution Theory mission. Module ComputableAnalysis/TaylorPolynomialValues.lean from the frozen computable-analysis foundation with kernel-checked rational decision proofs.
Definition code
import Definitions.Def_liuyao_ca_fd889115_k1_Analysis_GeometricTaylorData
import Definitions.Def_liuyao_ca_fd889115_k1_Analysis_FTCRealCalculus
set_option autoImplicit true
/-! Finite real polynomials for the coefficients generated by geometric FTC.
There is no infinite series definition or analytic identification here. -/
namespace ComputableAnalysis.TaylorPolynomialValues
open ComputableCoefficient RealApproximationOrder RawLimit GeometricTrig
set_option maxHeartbeats 600000
def power (X : Value) : Nat → Value
| 0 => Value.rational 1
| n+1 => Value.mul (power X n) X
theorem power_sample (X : Value) (n : Nat) (s : RealCompute.Certified → Rat) :
(power X n).sample s=(X.sample s)^n := by
induction n with
| zero => simp only [power,Value.rational,Rat.pow_zero]
| succ n ih => simp only [power,Value.mul,ih,Rat.pow_succ]
theorem power_congr {X Y : Value} (h : X.real.preferred.Equiv Y.real.preferred) (n : Nat) :
(power X n).real.preferred.Equiv (power Y n).real.preferred := by
induction n with
| zero => exact RealCompute.equiv_refl _ (RealCompute.ofRat_valid 1)
| succ n ih =>
exact RealCompute.mul_equiv (power X n).real.valid (power Y n).real.valid
X.real.valid Y.real.valid ih h
def phase (n : Nat) (cosine : Bool) : Rat :=
if n%4=0 then (if cosine then 1 else 0)
else if n%4=1 then (if cosine then 0 else 1)
else if n%4=2 then (if cosine then -1 else 0)
else (if cosine then 0 else -1)
theorem phase_succ (n : Nat) (cosine : Bool) :
phase (n+1) cosine=if cosine then -(phase n false) else phase n true := by
have hn : n%4=0 ∨ n%4=1 ∨ n%4=2 ∨ n%4=3 := by omega
rcases hn with hn | hn | hn | hn
· have hm : (n+1)%4=1 := by omega
cases cosine <;> simp [phase,hn,hm] <;> decide +kernel
· have hm : (n+1)%4=2 := by omega
cases cosine <;> simp [phase,hn,hm] <;> decide +kernel
· have hm : (n+1)%4=3 := by omega
cases cosine <;> simp [phase,hn,hm] <;> decide +kernel
· have hm : (n+1)%4=0 := by omega
cases cosine <;> simp [phase,hn,hm] <;> decide +kernel
def angular (X : Value) : Value := Value.mul piValue X
def coefficient (n : Nat) (cosine : Bool) (Z : Value) : Value := scale (phase n cosine) (power Z n)
def term (n : Nat) (cosine : Bool) (Z : Value) : Value := scale (1/factorialRat n) (coefficient n cosine Z)
def sumPrefix (cosine : Bool) (Z : Value) : Nat → Value
| 0 => Value.rational 0
| n+1 => Value.add (sumPrefix cosine Z n) (term n cosine Z)
theorem coefficient_congr {X Y : Value} (h : X.real.preferred.Equiv Y.real.preferred) (n : Nat) (cosine : Bool) :
(coefficient n cosine X).real.preferred.Equiv (coefficient n cosine Y).real.preferred :=
RealCompute.scaleRat_equiv (power_congr h n)
theorem partial_congr {X Y : Value} (h : X.real.preferred.Equiv Y.real.preferred) (N : Nat) (cosine : Bool) :
(sumPrefix cosine X N).real.preferred.Equiv (sumPrefix cosine Y N).real.preferred := by
induction N with
| zero => exact RealCompute.equiv_refl _ (RealCompute.ofRat_valid 0)
| succ n ih =>
exact RealCompute.add_equiv (sumPrefix cosine X n).real.valid (sumPrefix cosine Y n).real.valid
(term n cosine X).real.valid (term n cosine Y).real.valid ih
(RealCompute.scaleRat_equiv (coefficient_congr h n cosine))
theorem angular_congr {X Y : Value} (h : X.real.preferred.Equiv Y.real.preferred) :
(angular X).real.preferred.Equiv (angular Y).real.preferred :=
RealCompute.mul_equiv pi_valid pi_valid X.real.valid Y.real.valid (RealCompute.equiv_refl _ pi_valid) h
/-- Semantic interval scaling, with the sign handled by rational arithmetic. -/
theorem interval_scale {x : RealCompute} {I : QInterval} (h : InInterval x I) (c : Rat) :
InInterval (RealCompute.scaleRat c x) (QInterval.scaleRat c I) := by
by_cases hc : 0≤c
· constructor
· intro i j
have hh := Rat.mul_le_mul_of_nonneg_left (h.1 0 j) hc
simpa only [RealCompute.scaleRatCompute,RealCompute.scaleRat,RealCompute.ofRat,QInterval.scaleRat,if_pos hc] using hh
· intro i j
have hh := Rat.mul_le_mul_of_nonneg_left (h.2 i 0) hc
simpa only [RealCompute.scaleRatCompute,RealCompute.scaleRat,RealCompute.ofRat,QInterval.scaleRat,if_pos hc] using hh
· have hn : c≤0 := by grind only
constructor
· intro i j
have hh := rat_mul_le_mul_of_nonpos_left (h.2 j 0) hn
simpa only [RealCompute.scaleRatCompute,RealCompute.scaleRat,RealCompute.ofRat,QInterval.scaleRat,if_neg hc] using hh
· intro i j
have hh := rat_mul_le_mul_of_nonpos_left (h.1 0 i) hn
simpa only [RealCompute.scaleRatCompute,RealCompute.scaleRat,RealCompute.ofRat,QInterval.scaleRat,if_neg hc] using hh
theorem interval_sub {x y : RealCompute} {I J : QInterval} (hx : InInterval x I) (hy : InInterval y J) :
InInterval (x-y) {lo := I.lo-J.hi,hi := I.hi-J.lo} := by
constructor
· intro i j; exact RealCompute.le_sub_le_sub hx.1 hy.2 i j
· intro i j; exact RealCompute.le_sub_le_sub hx.2 hy.1 i j
theorem power_image {X Y : Value} {n : Nat} (h : InInterval X.real.preferred (Y.real.compute n)) (N : Nat) :
InInterval (power X N).real.preferred ((power Y N).real.compute n) := by
induction N with
| zero => exact RealIntervalImage.current (x := RealCompute.ofRat 1) (RealCompute.ofRat_valid 1) n
| succ N ih => exact RealIntervalImage.mul (power X N).real.valid X.real.valid ih h
theorem partial_image {X Y : Value} {n : Nat} (h : InInterval X.real.preferred (Y.real.compute n))
(N : Nat) (cosine : Bool) :
InInterval (sumPrefix cosine X N).real.preferred ((sumPrefix cosine Y N).real.compute n) := by
induction N with
| zero => exact RealIntervalImage.current (x := RealCompute.ofRat 0) (RealCompute.ofRat_valid 0) n
| succ N ih =>
have ht := interval_scale (interval_scale (power_image h N) (phase N cosine)) (1/factorialRat N)
exact RealIntervalImage.add (sumPrefix cosine X N).real.valid (term N cosine X).real.valid ih ht
theorem angular_image {A : RealCompute} (hA : A.Valid) (q : Rat) (n : Nat)
(hq : (A.compute n).lo≤q ∧ q≤(A.compute n).hi) :
InInterval (angular (Value.rational q)).real.preferred
((angular (parameter A hA)).real.compute n) := by
have h : InInterval (RealCompute.ofRat q) (A.compute n) :=
⟨fun _ _ => hq.1,fun _ _ => hq.2⟩
exact RealIntervalImage.mul (x := pi) (y := RealCompute.ofRat q) pi_valid (RealCompute.ofRat_valid q) (RealIntervalImage.current pi_valid n) h
end ComputableAnalysis.TaylorPolynomialValues