Built with doc-gen4, running Lean4. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓to navigate, Ctrl+🖱️to focus. On Mac, use Cmdinstead of Ctrl.
import Mathlib
/-!
# Formal Calculus

We introduce formal structures for integration and differentiation. Properties should be added to make these mathematically sound. But correctness can be ensured temporarily by making sure individual definitions are correct.

## Formal Integrals
-/

/--
Integrability of `f`, i.e., given an interval `[a, b]`, we can compute the integral of `f` over that interval. Additivity over intervals is also required.
-/
class 
Integrable: {f : } → (integral : ) → (∀ (a b c : ), integral a c = integral a b + integral b c) → Integrable f
Integrable
(
f:
f
:
: Type
: Type
) where
integral: (f : ) → [self : Integrable f] →
integral
(
a:
a
b:
b
:
: Type
) :
: Type
interval_union: ∀ {f : } [self : Integrable f] (a b c : ), Integrable.integral f a c = Integrable.integral f a b + Integrable.integral f b c
interval_union
(
a:
a
b:
b
c:
c
:
: Type
) :
integral:
integral
a:
a
c:
c
=
integral:
integral
a:
a
b:
b
+
integral:
integral
b:
b
c:
c
/-- The integral of a function, with the typeclass derived -/ def
integral: (f : ) → [int : Integrable f] → (a b : ) → ?m.81 f a b
integral
(
f:
f
:
: Type
: Type
)[
int: Integrable f
int
:
Integrable: () → Type
Integrable
f:
f
] (
a:
a
b:
b
:
: Type
) :=
int: Integrable f
int
.
integral: (f : ) → [self : Integrable f] →
integral
a:
a
b:
b
/-- The integral over a single point is zero, proved as an illustration. -/ theorem
integral_point: ∀ (f : ) [int : Integrable f] (a : ), integral f a a = 0
integral_point
(
f:
f
:
: Type
: Type
)[
int: Integrable f
int
:
Integrable: () → Type
Integrable
f:
f
] (
a:
a
:
: Type
) :
integral: (f : ) → [int : Integrable f] →
integral
f:
f
a:
a
a:
a
=
0: ?m.169
0
:=

Goals accomplished! 🐙
f:

int: Integrable f

a:


integral f a a = 0
f:

int: Integrable f

a:


f:

int: Integrable f

a:


integral f a a = 0
f:

int: Integrable f

a:


integral f a a = 0
f:

int: Integrable f

a:


integral f a a = 0

Goals accomplished! 🐙
/-! As an exercise, prove that flip ends of an interval gives the negative of the integral. -/ /-! ## Formal Derivatives We define so called __one-jets__ as a value and a derivative at a point. A differentiable function has values a one-jet at each point. -/ /-- A _one-jet_ is a value and a derivative at a point. -/ structure
OneJet: Type
OneJet
where
value: OneJet
value
:
: Type
derivative: OneJet
derivative
:
: Type
/-- A differentiable function is a function that has a one-jet at each point. -/ structure
SmoothFunction: Type
SmoothFunction
where jet:
: Type
OneJet: Type
OneJet
/-- Derivative of a smooth function, i.e., the derivative of the one-jet at a point. -/ def
SmoothFunction.derivative: SmoothFunction
SmoothFunction.derivative
(f:
SmoothFunction: Type
SmoothFunction
) :
: Type
: Type
:= fun
x: ?m.863
x
f.jet (
x: ?m.863
x
) |>.
derivative: OneJet
derivative
/-- The value of a smooth function, i.e., the value of the one-jet at a point. -/ def
SmoothFunction.value: SmoothFunction
SmoothFunction.value
(f:
SmoothFunction: Type
SmoothFunction
) :
: Type
: Type
:= fun
x: ?m.922
x
f.jet (
x: ?m.922
x
) |>.
value: OneJet
value
/-- Integrable functions can be obtained from smooth functions via the fundamental theorem of calculus. -/ instance fundThm (f:
SmoothFunction: Type
SmoothFunction
) :
Integrable: () → Type
Integrable
(f.
derivative: SmoothFunction
derivative
) where integral (
a: ?m.980
a
b: ?m.983
b
) := f.
value: SmoothFunction
value
b: ?m.983
b
- f.
value: SmoothFunction
value
a: ?m.980
a
interval_union (
a: ?m.1034
a
b: ?m.1037
b
c: ?m.1040
c
) :=

Goals accomplished! 🐙
f: SmoothFunction

a, b, c:


(fun a b => SmoothFunction.value f b - SmoothFunction.value f a) a c = (fun a b => SmoothFunction.value f b - SmoothFunction.value f a) a b + (fun a b => SmoothFunction.value f b - SmoothFunction.value f a) b c

Goals accomplished! 🐙
/-! ## Constructions of smooth functions To use the above we need to construct a few smooth functions -/ namespace SmoothFunction /-- Constant functions as smooth functions. -/ def
constant: SmoothFunction
constant
(
c:
c
:
: Type
) :
SmoothFunction: Type
SmoothFunction
:= ⟨fun
_: ?m.1717
_
↦ ⟨
c:
c
,
0: ?m.1722
0
⟩⟩ /-- Sum of smooth functions. -/ def sum (f g :
SmoothFunction: Type
SmoothFunction
) :
SmoothFunction: Type
SmoothFunction
:= ⟨fun
x: ?m.1825
x
↦ ⟨f.
value: SmoothFunction
value
x: ?m.1825
x
+ g.
value: SmoothFunction
value
x: ?m.1825
x
, f.
derivative: SmoothFunction
derivative
x: ?m.1825
x
+ g.
derivative: SmoothFunction
derivative
x: ?m.1825
x
⟩⟩ /-- Product of smooth functions using Liebnitz rule. -/ def prod (f g :
SmoothFunction: Type
SmoothFunction
) :
SmoothFunction: Type
SmoothFunction
:= ⟨fun
x: ?m.2030
x
↦ ⟨f.
value: SmoothFunction
value
x: ?m.2030
x
* g.
value: SmoothFunction
value
x: ?m.2030
x
, f.
derivative: SmoothFunction
derivative
x: ?m.2030
x
* g.
value: SmoothFunction
value
x: ?m.2030
x
+ f.
value: SmoothFunction
value
x: ?m.2030
x
* g.
derivative: SmoothFunction
derivative
x: ?m.2030
x
⟩⟩ /-- Product of a scalar and a smooth function. -/ def
scalarProd: SmoothFunctionSmoothFunction
scalarProd
(
c:
c
:
: Type
) (f :
SmoothFunction: Type
SmoothFunction
) :
SmoothFunction: Type
SmoothFunction
:= ⟨fun
x: ?m.2363
x
↦ ⟨
c:
c
* f.
value: SmoothFunction
value
x: ?m.2363
x
,
c:
c
* f.
derivative: SmoothFunction
derivative
x: ?m.2363
x
⟩⟩ /-- Addition operation on smooth functions -/ instance :
Add: Type ?u.2547 → Type ?u.2547
Add
SmoothFunction: Type
SmoothFunction
:= ⟨sum⟩ /-- Multiplication operation on smooth functions -/ instance :
Mul: Type ?u.2621 → Type ?u.2621
Mul
SmoothFunction: Type
SmoothFunction
:= ⟨prod⟩ /-- Scalar multiplication for smooth functions -/ instance :
SMul: Type ?u.2696 → Type ?u.2695 → Type (max?u.2696?u.2695)
SMul
: Type
SmoothFunction: Type
SmoothFunction
:= ⟨
scalarProd: SmoothFunctionSmoothFunction
scalarProd
⟩ /-! This gives polynomial functions as a special case. As an exercise, prove that smooth functions form a Ring (indeed an Algebra over ℝ). We will define some polynomials as smooth functions as an example. -/ /-- The coordinate function -/ def x :
SmoothFunction: Type
SmoothFunction
:= ⟨fun
x: ?m.2774
x
↦ ⟨
x: ?m.2774
x
,
1: ?m.2779
1
⟩⟩ /-- The power function for a smooth function (automatic if ring is proved) -/ def pow (f:
SmoothFunction: Type
SmoothFunction
):
: Type
SmoothFunction: Type
SmoothFunction
|
0:
0
=>
constant: SmoothFunction
constant
1: ?m.2881
1
|
n:
n
+ 1 => f * (pow f
n:
n
) instance :
HPow: Type ?u.3296 → Type ?u.3295 → outParam (Type ?u.3294)Type (max(max?u.3296?u.3295)?u.3294)
HPow
SmoothFunction: Type
SmoothFunction
: Type
SmoothFunction: Type
SmoothFunction
:= ⟨powinstance :
Coe: Sort ?u.3386 → Sort ?u.3385 → Sort (max(max1?u.3386)?u.3385)
Coe
: Type
SmoothFunction: Type
SmoothFunction
:= ⟨
constant: SmoothFunction
constant
⟩ /-- A polynomial. We can have cleaner notation but the goal is to illustrate the construction -/ def
poly: ?m.3439
poly
:= (
2: ?m.3457
2
:
: Type
) • x + (
3: ?m.3520
3
:
: Type
) • x^
3: ?m.3539
3
+ (
7: ?m.4419
7
:
: Type
) end SmoothFunction