MindFormal v1.0.0One Mind

MindFormal.Tools.RationalExpr

02.20: the general builder's arithmetic. A fixed expression language over named variables with rational constants (sum, product, positive part, absolute value, reciprocal), read in the reals and computed in the rationals; box arithmetic giving an expression's range and Lipschitz constant over a box of its variables; polynomials with rational coefficients in Horner form, their derivatives and bounds; and rational upper bounds for the exponential on [0,1] and for Grönwall's bound. Every computation here reduces in the kernel. Pure arithmetic, no mind.

inductive MindFormal.RExpr (V : Type u) :

02.20: an expression over variables V with rational constants: sums, products, the positive part, the absolute value and the reciprocal.

Instances For
    theorem MindFormal.RExpr.evalQ_cast {V : Type u} (ρ : V → ℚ) (e : RExpr V) :
    ↑(evalQ ρ e) = eval (fun (v : V) => ↑(ρ v)) e

    02.20: the rational computation is the real reading at rational points.

    def MindFormal.RExpr.sub {V : Type u} (a b : RExpr V) :

    02.20: a difference.

    Equations
    Instances For
      def MindFormal.RExpr.smul {V : Type u} (c : ℚ) (a : RExpr V) :

      02.20: a rational multiple.

      Equations
      Instances For
        def MindFormal.RExpr.minC {V : Type u} (a : RExpr V) (c : ℚ) :

        02.20: the smaller of an expression and a rational cap, as a − [a − c]₊.

        Equations
        Instances For
          def MindFormal.RExpr.sumL {V : Type u} {α : Type u_1} (L : List α) (f : α → RExpr V) :

          02.20: a finite sum over a list of indices.

          Equations
          Instances For
            @[simp]
            theorem MindFormal.RExpr.eval_sub {V : Type u} (ρ : V → ℝ) (a b : RExpr V) :
            eval ρ (a.sub b) = eval ρ a - eval ρ b
            @[simp]
            theorem MindFormal.RExpr.eval_minC {V : Type u} (ρ : V → ℝ) (a : RExpr V) (c : ℚ) :
            eval ρ (a.minC c) = min (eval ρ a) ↑c
            @[simp]
            theorem MindFormal.RExpr.eval_sumL {V : Type u} {α : Type u_1} (ρ : V → ℝ) (L : List α) (f : α → RExpr V) :
            eval ρ (sumL L f) = (List.map (fun (x : α) => eval ρ (f x)) L).sum
            theorem MindFormal.RExpr.list_sum_eq_sum {α : Type u_1} [Fintype α] {L : List α} (hn : L.Nodup) (hc : ∀ (a : α), a ∈ L) (f : α → ℝ) :
            (List.map f L).sum = ∑ a : α, f a

            02.20: a sum over a list that lists every element of a finite type once is the sum over the type.

            02.20: an enclosure of an expression over a box: whether it is defined (every reciprocal's argument bounded away from zero), its range [lo,hi], and its Lipschitz constant in the largest change of any variable.

            Instances For

              02.20: the largest magnitude in an enclosure's range.

              Equations
              Instances For

                02.20: the sum rule.

                Equations
                Instances For

                  02.20: the product rule: the range from the four corner products, the Lipschitz constant |a|·L_b + |b|·L_a.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    02.20: the positive part keeps the Lipschitz constant.

                    Equations
                    Instances For

                      02.20: the absolute value keeps the Lipschitz constant.

                      Equations
                      Instances For

                        02.20: the reciprocal, defined when the range lies above zero, with constant L/lo².

                        Equations
                        Instances For
                          def MindFormal.RExpr.bound {V : Type u} (B : V → ℚ × ℚ) :
                          RExpr V → Enc

                          02.20: box arithmetic. Each variable ranges over its box [lo,hi] with Lipschitz constant one.

                          Equations
                          Instances For
                            def MindFormal.RExpr.InBox {V : Type u} (B : V → ℚ × ℚ) (ρ : V → ℝ) :

                            02.20: a real point lies in a rational box.

                            Equations
                            Instances For
                              theorem MindFormal.RExpr.mul_mem_corners {a b c d x y : ℝ} (hx : a ≤ x ∧ x ≤ b) (hy : c ≤ y ∧ y ≤ d) :
                              min (min (a * c) (a * d)) (min (b * c) (b * d)) ≤ x * y ∧ x * y ≤ max (max (a * c) (a * d)) (max (b * c) (b * d))
                              theorem MindFormal.RExpr.abs_le_mag {lo hi : ℚ} {x : ℝ} (h : ↑lo ≤ x ∧ x ≤ ↑hi) :
                              |x| ≤ ↑(max (-lo) hi)
                              theorem MindFormal.RExpr.bound_sound {V : Type u} (B : V → ℚ × ℚ) (e : RExpr V) (h : (bound B e).ok = true) :
                              (∀ (ρ : V → ℝ), InBox B ρ → ↑(bound B e).lo ≤ eval ρ e ∧ eval ρ e ≤ ↑(bound B e).hi) ∧ ∀ (ρ ρ' : V → ℝ) (δ : ℝ), InBox B ρ → InBox B ρ' → (∀ (v : V), |ρ v - ρ' v| ≤ δ) → |eval ρ e - eval ρ' e| ≤ ↑(bound B e).lip * δ

                              02.20: box arithmetic is sound. If the enclosure is defined, every point of the box reads into its range, and two points of the box whose variables differ by at most δ read at most lip·δ apart.

                              Polynomials with rational coefficients, c₀ + x(c₁ + x(c₂ + …)).

                              def MindFormal.qeval (cs : List ℚ) (x : ℚ) :

                              02.20: a polynomial computed exactly in the rationals.

                              Equations
                              Instances For
                                noncomputable def MindFormal.reval :
                                List ℚ → ℝ → ℝ

                                02.20: a polynomial read in the reals.

                                Equations
                                Instances For

                                  02.20: coefficientwise sum.

                                  Equations
                                  Instances For

                                    02.20: the derivative's coefficients: (c + x·p)' = p + x·p'.

                                    Equations
                                    Instances For
                                      def MindFormal.pabs (cs : List ℚ) (h : ℚ) :

                                      02.20: the coefficients' absolute values read at h, a bound for |x| ≤ h.

                                      Equations
                                      Instances For
                                        theorem MindFormal.reval_cast (cs : List ℚ) (x : ℚ) :
                                        reval cs ↑x = ↑(qeval cs x)

                                        02.20: the rational computation is the real reading at rational points.

                                        theorem MindFormal.reval_padd (a b : List ℚ) (x : ℝ) :
                                        reval (padd a b) x = reval a x + reval b x
                                        theorem MindFormal.reval_hasDerivAt (cs : List ℚ) (x : ℝ) :
                                        HasDerivAt (reval cs) (reval (pderiv cs) x) x

                                        02.20: the polynomial has the derivative pderiv computes.

                                        theorem MindFormal.pabs_nonneg (cs : List ℚ) {h : ℚ} (hh : 0 ≤ h) :
                                        0 ≤ pabs cs h
                                        theorem MindFormal.abs_reval_le (cs : List ℚ) {h : ℚ} {x : ℝ} (hh : 0 ≤ h) (hx : |x| ≤ ↑h) :
                                        |reval cs x| ≤ ↑(pabs cs h)

                                        02.20: |p(x)| ≤ pabs p h for |x| ≤ h.

                                        theorem MindFormal.reval_sub_le (cs : List ℚ) {h : ℚ} {x y : ℝ} (hx : x ∈ Set.Icc 0 ↑h) (hy : y ∈ Set.Icc 0 ↑h) :
                                        |reval cs y - reval cs x| ≤ ↑(pabs (pderiv cs) h) * |y - x|

                                        02.20: on [0,h] a polynomial moves by at most pabs p' h times the time elapsed (the mean value theorem).

                                        The exponential and Grönwall's bound, from above in the rationals.

                                        02.20: a rational upper bound for exp y on [0,1]: eight Taylor terms and Mathlib's remainder.

                                        Equations
                                        Instances For
                                          theorem MindFormal.exp_le_expUpper {y : ℚ} (h0 : 0 ≤ y) (h1 : y ≤ 1) :
                                          Real.exp ↑y ≤ ↑(expUpper y)
                                          theorem MindFormal.gronwallBound_le_upper {δ K ε E h x : ℝ} (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (hK : 0 < K) (hx : x ∈ Set.Icc 0 h) (hE : Real.exp (K * h) ≤ E) :
                                          gronwallBound δ K ε x ≤ δ * E + ε / K * (E - 1)

                                          02.20: on [0,h] Grönwall's bound is at most δE + (ε/K)(E−1) when E ≥ exp(Kh), K > 0.