Table of Contents

1. First Class Differential Equations2. Ordinary Differential Equations

3. Goal

4. Anti-Goals

5. Intuitions

6. Tools

7. Simple (est?) example of a differential

8. First fundamental theorem of calculus:

9. Second Fundamental Theorem of Calculus

10. A Little Algebra...

11. Expand...

12. As is lifting operations to streams.

13. Reformulate

14. Extrapolate...

15. Streams of Polynomials

16. And we can run it

17. A graph

18. Wait, what?

19. Is it any good?

20. Picard Iteration

21. Another example

22. (22)

23. TL;DL

24. Future work

Gershom Bazerman

OBT at POPL 2012

...

- x may be a vector
- no partial derivatives!

Develop a purely semantic account of approximate solutions to differential equations.

- Leave the numbers to the computers
- Use only high school calculus

- Choices should be as natural as possible
- Choices should preserve as much information as possible

```
type Step s = (s,TimeDelta)->s
run :: s -> Step s -> TimeDelta -> [(TimeDelta,s)]
```

- steps don't compose.
- Step /= run Step

- A differential equation is an instantaneous recurrence relation
- Like recurrence relations we have existance and uniqueness proofs
- Like recurrence relations these proofs derive from fix-point theorems
- C.f. "Calculus in coinductive form," Dusko Pavlovic and Martin H. Escardo.

```
class Analytic a where
integ :: a -> a
derive :: a -> a
```

```
class Sample a where
sampleAt :: a -> Double -> Double
```

```
newtype Poly = Poly [Double]
instance Num Poly where...
instance Fractional Poly where...
instance Analytic Poly where...
instance Sample Poly where...
c.f. Doug McIlroy
```

- i.e. F'(x) = f(x)
- i.e. diff . integrate = id

where is an indefinite integral (antiderivative) of .

Flip

Distinguish two Fs

- is of type Stream!

```
type TimeDelta = Double
data Stream a = Stream TimeDelta a (Stream a)
instance Sample a => Sample (Stream a) where ...
instance Num a => Num (Stream a) where...
instance Fractional a => Fractional (Stream a) where...
instance (Analytic a, Sample a) => Analytic (Stream a) where..
instance Sample a => Sample (Stream a) where...
```

```
applWith f a b = go a b
where go sx@(Stream dtx x nx) sy@(Stream dty y ny) =
case compare dtx dty of
EQ -> Stream dtx (f x y) $ go nx ny
GT -> Stream dty (f x y) $ go (sdrop dty sx) ny
LT -> Stream dtx (f x y) $ go nx (sdrop dtx sy)
```

c.f. Conal Elliot

- Pointwise functions lift functorially into linear operators

Given and taking , approximate

If is on polynomials

*and*is polynomial then*every term*is polynomial!is (approximately) a coinductively defined polynomial.

```
type PolySpline = Stream Poly
instance {Num, Fractional, Analytic} PolySpline where...
```

```
instance Num PolySpline where
fromInteger = pure . fromInteger
negate = fmap negate
(+) = applWith (+)
...
```

```
expFun = splice h initExpFun $
(integ expFun' .+ (initExpFun @> h))
`extrapForward` h
where
initExpFun = pure 1
expFun' = expFun
h = 0.01
```

```
-- expFun @> 1 = 2.71814
-- exp 1 = 2.71828
-- by comparison, rk3 at h of 0.01 = 2.69120
```

- We implemented a straightforward representation of analytic functions.
- We did a little math.
- A solver for differential equations emerged.

- Take , very carefully.
- The error goes to zero.
- I.e. our solver converges.
- In fact, the sequence goes to this:

- Gives existence and uniqueness of a solution by the Banach fixed point theorem.

.

.

```
springFun = ssplice 0.1 initSpringFun $
integ (integ springFun'') .+ (initSpringFun @> 0.1)
`trimmingTo` 2
`extrapForward` 0.1
where initSpringFun = pure 1
springFun'' = -1 * springFun
```

- Partial differential equations
- Delay differential equations

- A-Stability analysis
- Stiff differential equations and implicit methods

- ?
- profit!