automatic asymptotics in isabelle/hol *-0 · list datatype exp : basis!type where

150
Automatic Asymptotics in Isabelle/HOL Manuel Eberl Technische Universität München 5 July 2017

Upload: dodat

Post on 17-Jul-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Automatic Asymptotics in Isabelle/HOL

Manuel Eberl

Technische Universität München

5 July 2017

Page 2: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in IsabelleI Filters to describe ‘neighbourhoods’ and thereby limits

limx→∞

f (x) = c = filterlim f (nhds c) at_top

I Landau symbols to relate functions w. r. t. asymptoticbehaviour

(λx . x) ∈ O(λx . x ∗ ln x)(λx . x2) ∈ O [at 0](λx . x)

What does ‘QuickSort needs O(|xs|2) comparisons’mean?

qs_cost ∈ O [length going_to at_top](λxs. (length xs)2)

Page 3: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in IsabelleI Filters to describe ‘neighbourhoods’ and thereby limits

limx→∞

f (x) = c = filterlim f (nhds c) at_top

I Landau symbols to relate functions w. r. t. asymptoticbehaviour

(λx . x) ∈ O(λx . x ∗ ln x)(λx . x2) ∈ O [at 0](λx . x)

What does ‘QuickSort needs O(|xs|2) comparisons’mean?

qs_cost ∈ O [length going_to at_top](λxs. (length xs)2)

Page 4: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in IsabelleI Filters to describe ‘neighbourhoods’ and thereby limits

limx→∞

f (x) = c = filterlim f (nhds c) at_top

I Landau symbols to relate functions w. r. t. asymptoticbehaviour

(λx . x) ∈ O(λx . x ∗ ln x)(λx . x2) ∈ O [at 0](λx . x)

What does ‘QuickSort needs O(|xs|2) comparisons’mean?

qs_cost ∈ O [length going_to at_top](λxs. (length xs)2)

Page 5: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in IsabelleI Filters to describe ‘neighbourhoods’ and thereby limits

limx→∞

f (x) = c = filterlim f (nhds c) at_top

I Landau symbols to relate functions w. r. t. asymptoticbehaviour

(λx . x) ∈ O(λx . x ∗ ln x)

(λx . x2) ∈ O [at 0](λx . x)

What does ‘QuickSort needs O(|xs|2) comparisons’mean?

qs_cost ∈ O [length going_to at_top](λxs. (length xs)2)

Page 6: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in IsabelleI Filters to describe ‘neighbourhoods’ and thereby limits

limx→∞

f (x) = c = filterlim f (nhds c) at_top

I Landau symbols to relate functions w. r. t. asymptoticbehaviour

(λx . x) ∈ O(λx . x ∗ ln x)(λx . x2) ∈ O [at 0](λx . x)

What does ‘QuickSort needs O(|xs|2) comparisons’mean?

qs_cost ∈ O [length going_to at_top](λxs. (length xs)2)

Page 7: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in IsabelleI Filters to describe ‘neighbourhoods’ and thereby limits

limx→∞

f (x) = c = filterlim f (nhds c) at_top

I Landau symbols to relate functions w. r. t. asymptoticbehaviour

(λx . x) ∈ O(λx . x ∗ ln x)(λx . x2) ∈ O [at 0](λx . x)

What does ‘QuickSort needs O(|xs|2) comparisons’mean?

qs_cost ∈ O [length going_to at_top](λxs. (length xs)2)

Page 8: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in IsabelleI Filters to describe ‘neighbourhoods’ and thereby limits

limx→∞

f (x) = c = filterlim f (nhds c) at_top

I Landau symbols to relate functions w. r. t. asymptoticbehaviour

(λx . x) ∈ O(λx . x ∗ ln x)(λx . x2) ∈ O [at 0](λx . x)

What does ‘QuickSort needs O(|xs|2) comparisons’mean?

qs_cost ∈ O [length going_to at_top](λxs. (length xs)2)

Page 9: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in Isabelle

I Some automation to do ‘obvious’ simplifications

if g ∈ o(f ) : O(λx . f x + g x) O(f )

(λx . f x ∗ h x) ∈ O(λx . g x ∗ h x) f ∈ O(g)

(λx . xa ∗ (ln x)b) ∈ O(λx . xc ∗ (ln x)d )

a < c ∨ (a = c ∧ b ≤ d)

Things like (λx . 2 ∗ x + x ∗ ln ln x) ∈ O(λx . x ∗ ln x) getproven automatically.

Page 10: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in Isabelle

I Some automation to do ‘obvious’ simplifications

if g ∈ o(f ) : O(λx . f x + g x) O(f )

(λx . f x ∗ h x) ∈ O(λx . g x ∗ h x) f ∈ O(g)

(λx . xa ∗ (ln x)b) ∈ O(λx . xc ∗ (ln x)d )

a < c ∨ (a = c ∧ b ≤ d)

Things like (λx . 2 ∗ x + x ∗ ln ln x) ∈ O(λx . x ∗ ln x) getproven automatically.

Page 11: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in Isabelle

I Some automation to do ‘obvious’ simplifications

if g ∈ o(f ) : O(λx . f x + g x) O(f )

(λx . f x ∗ h x) ∈ O(λx . g x ∗ h x) f ∈ O(g)

(λx . xa ∗ (ln x)b) ∈ O(λx . xc ∗ (ln x)d )

a < c ∨ (a = c ∧ b ≤ d)

Things like (λx . 2 ∗ x + x ∗ ln ln x) ∈ O(λx . x ∗ ln x) getproven automatically.

Page 12: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in Isabelle

I Some automation to do ‘obvious’ simplifications

if g ∈ o(f ) : O(λx . f x + g x) O(f )

(λx . f x ∗ h x) ∈ O(λx . g x ∗ h x) f ∈ O(g)

(λx . xa ∗ (ln x)b) ∈ O(λx . xc ∗ (ln x)d )

a < c ∨ (a = c ∧ b ≤ d)

Things like (λx . 2 ∗ x + x ∗ ln ln x) ∈ O(λx . x ∗ ln x) getproven automatically.

Page 13: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotics in Isabelle

I Some automation to do ‘obvious’ simplifications

if g ∈ o(f ) : O(λx . f x + g x) O(f )

(λx . f x ∗ h x) ∈ O(λx . g x ∗ h x) f ∈ O(g)

(λx . xa ∗ (ln x)b) ∈ O(λx . xc ∗ (ln x)d )

a < c ∨ (a = c ∧ b ≤ d)

Things like (λx . 2 ∗ x + x ∗ ln ln x) ∈ O(λx . x ∗ ln x) getproven automatically.

Page 14: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Some Applications

A few things that I have done with this:

I Akra–Bazzi theorem (divide & conquer recurrences)I Euler–MacLaurin formulaI Asymptotics of factorial, Γ, ψ(n), erf, Hn

I Average-case complexity of QuickSortI Ω(n log n) lower bound for comparison sortsI Average number of integer divisors/co-primes/square-free

integers

Page 15: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Some Applications

A few things that I have done with this:I Akra–Bazzi theorem (divide & conquer recurrences)

I Euler–MacLaurin formulaI Asymptotics of factorial, Γ, ψ(n), erf, Hn

I Average-case complexity of QuickSortI Ω(n log n) lower bound for comparison sortsI Average number of integer divisors/co-primes/square-free

integers

Page 16: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Some Applications

A few things that I have done with this:I Akra–Bazzi theorem (divide & conquer recurrences)I Euler–MacLaurin formula

I Asymptotics of factorial, Γ, ψ(n), erf, Hn

I Average-case complexity of QuickSortI Ω(n log n) lower bound for comparison sortsI Average number of integer divisors/co-primes/square-free

integers

Page 17: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Some Applications

A few things that I have done with this:I Akra–Bazzi theorem (divide & conquer recurrences)I Euler–MacLaurin formulaI Asymptotics of factorial, Γ, ψ(n), erf, Hn

I Average-case complexity of QuickSortI Ω(n log n) lower bound for comparison sortsI Average number of integer divisors/co-primes/square-free

integers

Page 18: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Some Applications

A few things that I have done with this:I Akra–Bazzi theorem (divide & conquer recurrences)I Euler–MacLaurin formulaI Asymptotics of factorial, Γ, ψ(n), erf, Hn

I Average-case complexity of QuickSort

I Ω(n log n) lower bound for comparison sortsI Average number of integer divisors/co-primes/square-free

integers

Page 19: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Some Applications

A few things that I have done with this:I Akra–Bazzi theorem (divide & conquer recurrences)I Euler–MacLaurin formulaI Asymptotics of factorial, Γ, ψ(n), erf, Hn

I Average-case complexity of QuickSortI Ω(n log n) lower bound for comparison sorts

I Average number of integer divisors/co-primes/square-freeintegers

Page 20: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Some Applications

A few things that I have done with this:I Akra–Bazzi theorem (divide & conquer recurrences)I Euler–MacLaurin formulaI Asymptotics of factorial, Γ, ψ(n), erf, Hn

I Average-case complexity of QuickSortI Ω(n log n) lower bound for comparison sortsI Average number of integer divisors/co-primes/square-free

integers

Page 21: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Problem: Asymptotics in Isabelle are ugly to prove!

Example: Lemma required for Akra–Bazzi

limx→∞

(1− 1

b log1+ε x

)p1+

1

logε/2(bx + x

log1+ε x

)−

(1+

1logε/2 x

)= 0+

Original author: ‘Trivial, just Taylor-expand it!’In Isabelle: 700 lines of messy proofs

Page 22: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Problem: Asymptotics in Isabelle are ugly to prove!

Example: Lemma required for Akra–Bazzi

limx→∞

(1− 1

b log1+ε x

)p1+

1

logε/2(bx + x

log1+ε x

)−

(1+

1logε/2 x

)= 0+

Original author: ‘Trivial, just Taylor-expand it!’In Isabelle: 700 lines of messy proofs

Page 23: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Problem: Asymptotics in Isabelle are ugly to prove!

Example: Lemma required for Akra–Bazzi

limx→∞

(1− 1

b log1+ε x

)p1+

1

logε/2(bx + x

log1+ε x

)−

(1+

1logε/2 x

)= 0+

Original author: ‘Trivial, just Taylor-expand it!’

In Isabelle: 700 lines of messy proofs

Page 24: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Problem: Asymptotics in Isabelle are ugly to prove!

Example: Lemma required for Akra–Bazzi

limx→∞

(1− 1

b log1+ε x

)p1+

1

logε/2(bx + x

log1+ε x

)−

(1+

1logε/2 x

)= 0+

Original author: ‘Trivial, just Taylor-expand it!’In Isabelle: 700 lines of messy proofs

Page 25: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

lemma akra_bazzi_aux:filterlim(λx . (1− 1/(b ∗ ln x ˆ(1+ ε)) ˆ p) ∗

(1+ ln (b ∗ x + x/ln x ˆ(1+ ε)) ˆ(−ε/2))−(1+ ln x ˆ(−ε/2)))

(at_right 0) at_top

by magic

This is what we would like to have.

Computer Algebra Systems can do this (sort of)

So why can’t we?

Page 26: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

lemma akra_bazzi_aux:filterlim(λx . (1− 1/(b ∗ ln x ˆ(1+ ε)) ˆ p) ∗

(1+ ln (b ∗ x + x/ln x ˆ(1+ ε)) ˆ(−ε/2))−(1+ ln x ˆ(−ε/2)))

(at_right 0) at_topby magic

This is what we would like to have.

Computer Algebra Systems can do this (sort of)

So why can’t we?

Page 27: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

lemma akra_bazzi_aux:filterlim(λx . (1− 1/(b ∗ ln x ˆ(1+ ε)) ˆ p) ∗

(1+ ln (b ∗ x + x/ln x ˆ(1+ ε)) ˆ(−ε/2))−(1+ ln x ˆ(−ε/2)))

(at_right 0) at_topby magic

This is what we would like to have.

Computer Algebra Systems can do this (sort of)

So why can’t we?

Page 28: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

lemma akra_bazzi_aux:filterlim(λx . (1− 1/(b ∗ ln x ˆ(1+ ε)) ˆ p) ∗

(1+ ln (b ∗ x + x/ln x ˆ(1+ ε)) ˆ(−ε/2))−(1+ ln x ˆ(−ε/2)))

(at_right 0) at_topby magic

This is what we would like to have.

Computer Algebra Systems can do this (sort of)

So why can’t we?

Page 29: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions

Disclaimer:I None of this was invented by me.I I will not show actual Isabelle code for better readability.

Page 30: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions

Disclaimer:I None of this was invented by me.

I I will not show actual Isabelle code for better readability.

Page 31: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions

Disclaimer:I None of this was invented by me.I I will not show actual Isabelle code for better readability.

Page 32: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Related Work

I Asymptotic Expansions of exp–log Functions byRichardson, Salvy, Shackell, van der Hoeven

I On Computing Limits in a Symbolic Manipulation Systemby Gruntz

Page 33: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

We’re looking for a compositional approach:

Given the limits of f (x) and g(x), what is the limit off (x) g(x)? (for ∈ +,−, ·,/)

If the limits are ∈ R: Obvious.

But: ∞−∞ =? 0 ·∞ =?

We need to track more information than just the limit!

We need the full asymptotic information

Page 34: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

We’re looking for a compositional approach:

Given the limits of f (x) and g(x), what is the limit off (x) g(x)? (for ∈ +,−, ·,/)

If the limits are ∈ R: Obvious.

But: ∞−∞ =? 0 ·∞ =?

We need to track more information than just the limit!

We need the full asymptotic information

Page 35: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

We’re looking for a compositional approach:

Given the limits of f (x) and g(x), what is the limit off (x) g(x)? (for ∈ +,−, ·,/)

If the limits are ∈ R: Obvious.

But: ∞−∞ =? 0 ·∞ =?

We need to track more information than just the limit!

We need the full asymptotic information

Page 36: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

We’re looking for a compositional approach:

Given the limits of f (x) and g(x), what is the limit off (x) g(x)? (for ∈ +,−, ·,/)

If the limits are ∈ R: Obvious.

But: ∞−∞ =? 0 ·∞ =?

We need to track more information than just the limit!

We need the full asymptotic information

Page 37: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsFor x → 0, we have:

ex ∼ 1+ x + 12x

2 + 16x

3 + . . .

11+ x

∼ 1− x + x2 − x3 + . . .

This means: Cutting off f (x) ∼ a0(x) + a1(x) + . . . at terman yields error O(an+1(x)).

Expansions contain the full asymptotic information.

They can be added/subtracted/multiplied/divided.

Limits can simply be ‘read off’

Page 38: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsFor x → 0, we have:

ex ∼ 1+ x + 12x

2 + 16x

3 + . . .

11+ x

∼ 1− x + x2 − x3 + . . .

This means: Cutting off f (x) ∼ a0(x) + a1(x) + . . . at terman yields error O(an+1(x)).

Expansions contain the full asymptotic information.

They can be added/subtracted/multiplied/divided.

Limits can simply be ‘read off’

Page 39: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsFor x → 0, we have:

ex ∼ 1+ x + 12x

2 + 16x

3 + . . .

11+ x

∼ 1− x + x2 − x3 + . . .

This means: Cutting off f (x) ∼ a0(x) + a1(x) + . . . at terman yields error O(an+1(x)).

Expansions contain the full asymptotic information.

They can be added/subtracted/multiplied/divided.

Limits can simply be ‘read off’

Page 40: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsFor x → 0, we have:

ex ∼ 1+ x + 12x

2 + 16x

3 + . . .

11+ x

∼ 1− x + x2 − x3 + . . .

This means: Cutting off f (x) ∼ a0(x) + a1(x) + . . . at terman yields error O(an+1(x)).

Expansions contain the full asymptotic information.

They can be added/subtracted/multiplied/divided.

Limits can simply be ‘read off’

Page 41: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsFor x → 0, we have:

ex ∼ 1+ x + 12x

2 + 16x

3 + . . .

11+ x

∼ 1− x + x2 − x3 + . . .

This means: Cutting off f (x) ∼ a0(x) + a1(x) + . . . at terman yields error O(an+1(x)).

Expansions contain the full asymptotic information.

They can be added/subtracted/multiplied/divided.

Limits can simply be ‘read off’

Page 42: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions

Not all functions have such easy expansions!e. g. exp (at ±∞) and ln (at ∞, 0)

Solution: later

For now, we only consider expansions of the form

f (x) ∼ c0xe0 + c1x

e1 + . . .

where e0 > e1 > . . .

Page 43: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions

Not all functions have such easy expansions!e. g. exp (at ±∞) and ln (at ∞, 0)

Solution: later

For now, we only consider expansions of the form

f (x) ∼ c0xe0 + c1x

e1 + . . .

where e0 > e1 > . . .

Page 44: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions

Not all functions have such easy expansions!e. g. exp (at ±∞) and ln (at ∞, 0)

Solution: later

For now, we only consider expansions of the form

f (x) ∼ c0xe0 + c1x

e1 + . . .

where e0 > e1 > . . .

Page 45: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsHow can one do concrete operations on these expansions?

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

(+) : Exp→ Exp→ Exp[] + ys = ysxs + [] = xs((c1, e1) :: xs) + ((c2, e2) :: ys)| e1 == e2 = (c1 + c2, e1) :: xs+ ys| e1 < e2 = (c1, e1) :: xs+ ((c2, e2) :: ys)| e1 > e2 = (c2, e2) :: ((c1, e1) :: xs) + ys

Page 46: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsHow can one do concrete operations on these expansions?

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

(+) : Exp→ Exp→ Exp[] + ys = ysxs + [] = xs((c1, e1) :: xs) + ((c2, e2) :: ys)| e1 == e2 = (c1 + c2, e1) :: xs+ ys| e1 < e2 = (c1, e1) :: xs+ ((c2, e2) :: ys)| e1 > e2 = (c2, e2) :: ((c1, e1) :: xs) + ys

Page 47: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsHow can one do concrete operations on these expansions?

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

(+) : Exp→ Exp→ Exp[] + ys = ysxs + [] = xs((c1, e1) :: xs) + ((c2, e2) :: ys)| e1 == e2 = (c1 + c2, e1) :: xs+ ys| e1 < e2 = (c1, e1) :: xs+ ((c2, e2) :: ys)| e1 > e2 = (c2, e2) :: ((c1, e1) :: xs) + ys

Page 48: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsHow can one do concrete operations on these expansions?

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

(+) : Exp→ Exp→ Exp[] + ys = ysxs + [] = xs

((c1, e1) :: xs) + ((c2, e2) :: ys)| e1 == e2 = (c1 + c2, e1) :: xs+ ys| e1 < e2 = (c1, e1) :: xs+ ((c2, e2) :: ys)| e1 > e2 = (c2, e2) :: ((c1, e1) :: xs) + ys

Page 49: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic ExpansionsHow can one do concrete operations on these expansions?

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

(+) : Exp→ Exp→ Exp[] + ys = ysxs + [] = xs((c1, e1) :: xs) + ((c2, e2) :: ys)| e1 == e2 = (c1 + c2, e1) :: xs+ ys| e1 < e2 = (c1, e1) :: xs+ ((c2, e2) :: ys)| e1 > e2 = (c2, e2) :: ((c1, e1) :: xs) + ys

Page 50: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Multiplication

Multiplication with ‘atomic’ factor c ′xe′:

scale : R→ R→ Exp→ Expscale c ′ e ′ xs = [(c ∗ c ′, e + e ′) | (c , e)← xs]

Multiplication of two expansions:(∗) : Exp→ Exp→ Expxs ∗ [] = [][] ∗ ys = []((c1, e1) :: xs) ∗ ((c2, e2) :: ys) =

(c1 ∗ c2, e1 + e2) :: scale c1 e1 ys+ xs ∗ ((c2, e2) :: ys)

Page 51: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Multiplication

Multiplication with ‘atomic’ factor c ′xe′:

scale : R→ R→ Exp→ Expscale c ′ e ′ xs = [(c ∗ c ′, e + e ′) | (c , e)← xs]

Multiplication of two expansions:(∗) : Exp→ Exp→ Expxs ∗ [] = [][] ∗ ys = []

((c1, e1) :: xs) ∗ ((c2, e2) :: ys) =(c1 ∗ c2, e1 + e2) :: scale c1 e1 ys+ xs ∗ ((c2, e2) :: ys)

Page 52: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Multiplication

Multiplication with ‘atomic’ factor c ′xe′:

scale : R→ R→ Exp→ Expscale c ′ e ′ xs = [(c ∗ c ′, e + e ′) | (c , e)← xs]

Multiplication of two expansions:(∗) : Exp→ Exp→ Expxs ∗ [] = [][] ∗ ys = []((c1, e1) :: xs) ∗ ((c2, e2) :: ys) =

(c1 ∗ c2, e1 + e2) :: scale c1 e1 ys+ xs ∗ ((c2, e2) :: ys)

Page 53: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Power SeriesMany functions have local power series expansions:

g(x) =∞

∑n=0

cnxn (for |x | < R)

e. g. cn := 1/n! for the exponential function.

If f (x)→ 0, one can substitute f into g :

g(f (x)) =∞

∑n=0

cnf (x)n = c0 + f (x)

∑n=0

cn+1f (x)n

powser : R llist→ Exp→ Exppowser (c :: cs) xs = (c , 0) :: xs ∗ powser cs xs

Page 54: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Power SeriesMany functions have local power series expansions:

g(x) =∞

∑n=0

cnxn (for |x | < R)

e. g. cn := 1/n! for the exponential function.

If f (x)→ 0, one can substitute f into g :

g(f (x)) =∞

∑n=0

cnf (x)n

= c0 + f (x)∞

∑n=0

cn+1f (x)n

powser : R llist→ Exp→ Exppowser (c :: cs) xs = (c , 0) :: xs ∗ powser cs xs

Page 55: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Power SeriesMany functions have local power series expansions:

g(x) =∞

∑n=0

cnxn (for |x | < R)

e. g. cn := 1/n! for the exponential function.

If f (x)→ 0, one can substitute f into g :

g(f (x)) =∞

∑n=0

cnf (x)n = c0 + f (x)

∑n=0

cn+1f (x)n

powser : R llist→ Exp→ Exppowser (c :: cs) xs = (c , 0) :: xs ∗ powser cs xs

Page 56: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Power SeriesMany functions have local power series expansions:

g(x) =∞

∑n=0

cnxn (for |x | < R)

e. g. cn := 1/n! for the exponential function.

If f (x)→ 0, one can substitute f into g :

g(f (x)) =∞

∑n=0

cnf (x)n = c0 + f (x)

∑n=0

cn+1f (x)n

powser : R llist→ Exp→ Exppowser (c :: cs) xs = (c , 0) :: xs ∗ powser cs xs

Page 57: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – ReciprocalConsider f (x) with expansion (c , e) :: xs where c 6= 0, i. e.

f (x) = c xe + g(x)

= c xe(1+ c−1x−eg(x))

where g(x) expands to xs.

Then:

f −1(x) ∼ c−1x−e (1+ c−1x−eg(x))−1

Note the geometric series:

(1+ x)−1 =∞

∑n=0

(−1)nxn

Therefore:inv ((c , e) :: xs) = scale (1/c) (−e)

(powser (cycle [1,−1]) (scale (1/c) (−e) xs))

Page 58: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – ReciprocalConsider f (x) with expansion (c , e) :: xs where c 6= 0, i. e.

f (x) = c xe + g(x) = c xe(1+ c−1x−eg(x))

where g(x) expands to xs.

Then:

f −1(x) ∼ c−1x−e (1+ c−1x−eg(x))−1

Note the geometric series:

(1+ x)−1 =∞

∑n=0

(−1)nxn

Therefore:inv ((c , e) :: xs) = scale (1/c) (−e)

(powser (cycle [1,−1]) (scale (1/c) (−e) xs))

Page 59: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – ReciprocalConsider f (x) with expansion (c , e) :: xs where c 6= 0, i. e.

f (x) = c xe + g(x) = c xe(1+ c−1x−eg(x))

where g(x) expands to xs. Then:

f −1(x) ∼ c−1x−e (1+ c−1x−eg(x))−1

Note the geometric series:

(1+ x)−1 =∞

∑n=0

(−1)nxn

Therefore:inv ((c , e) :: xs) = scale (1/c) (−e)

(powser (cycle [1,−1]) (scale (1/c) (−e) xs))

Page 60: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – ReciprocalConsider f (x) with expansion (c , e) :: xs where c 6= 0, i. e.

f (x) = c xe + g(x) = c xe(1+ c−1x−eg(x))

where g(x) expands to xs. Then:

f −1(x) ∼ c−1x−e (1+ c−1x−eg(x))−1

Note the geometric series:

(1+ x)−1 =∞

∑n=0

(−1)nxn

Therefore:inv ((c , e) :: xs) = scale (1/c) (−e)

(powser (cycle [1,−1]) (scale (1/c) (−e) xs))

Page 61: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – ReciprocalConsider f (x) with expansion (c , e) :: xs where c 6= 0, i. e.

f (x) = c xe + g(x) = c xe(1+ c−1x−eg(x))

where g(x) expands to xs. Then:

f −1(x) ∼ c−1x−e (1+ c−1x−eg(x))−1

Note the geometric series:

(1+ x)−1 =∞

∑n=0

(−1)nxn

Therefore:inv ((c , e) :: xs) = scale (1/c) (−e)

(powser (cycle [1,−1]) (scale (1/c) (−e) xs))

Page 62: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsProblem: Remember: ln x and exp x have no power seriesexpansion for x → ∞!

Solution: Allow not only powers of x , but products of powersof an asymptotic basis.

Example: (ex , x , ln x) is an asymptotic basis and generatesmonomials eaxxb lnc x

e4x + 2x3 ln x∧= [1 · (4, 0, 0), 2 · (0, 3, 1)]

Alternative hierarchical view: Coefficients of an expansionw. r. t. basis b :: bs are functions, each of which has anexpansion w. r. t. bs.

e4x + 2x3 ln x∧= [(4, (0, (0, 1))), (0, (3, (1, 2)))

Page 63: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsProblem: Remember: ln x and exp x have no power seriesexpansion for x → ∞!

Solution: Allow not only powers of x , but products of powersof an asymptotic basis.

Example: (ex , x , ln x) is an asymptotic basis and generatesmonomials eaxxb lnc x

e4x + 2x3 ln x∧= [1 · (4, 0, 0), 2 · (0, 3, 1)]

Alternative hierarchical view: Coefficients of an expansionw. r. t. basis b :: bs are functions, each of which has anexpansion w. r. t. bs.

e4x + 2x3 ln x∧= [(4, (0, (0, 1))), (0, (3, (1, 2)))

Page 64: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsProblem: Remember: ln x and exp x have no power seriesexpansion for x → ∞!

Solution: Allow not only powers of x , but products of powersof an asymptotic basis.

Example: (ex , x , ln x) is an asymptotic basis and generatesmonomials eaxxb lnc x

e4x + 2x3 ln x∧= [1 · (4, 0, 0), 2 · (0, 3, 1)]

Alternative hierarchical view: Coefficients of an expansionw. r. t. basis b :: bs are functions, each of which has anexpansion w. r. t. bs.

e4x + 2x3 ln x∧= [(4, (0, (0, 1))), (0, (3, (1, 2)))

Page 65: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsProblem: Remember: ln x and exp x have no power seriesexpansion for x → ∞!

Solution: Allow not only powers of x , but products of powersof an asymptotic basis.

Example: (ex , x , ln x) is an asymptotic basis and generatesmonomials eaxxb lnc x

e4x + 2x3 ln x∧= [1 · (4, 0, 0), 2 · (0, 3, 1)]

Alternative hierarchical view: Coefficients of an expansionw. r. t. basis b :: bs are functions, each of which has anexpansion w. r. t. bs.

e4x + 2x3 ln x∧= [(4, (0, (0, 1))), (0, (3, (1, 2)))

Page 66: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsProblem: Remember: ln x and exp x have no power seriesexpansion for x → ∞!

Solution: Allow not only powers of x , but products of powersof an asymptotic basis.

Example: (ex , x , ln x) is an asymptotic basis and generatesmonomials eaxxb lnc x

e4x + 2x3 ln x∧= [1 · (4, 0, 0), 2 · (0, 3, 1)]

Alternative hierarchical view: Coefficients of an expansionw. r. t. basis b :: bs are functions, each of which has anexpansion w. r. t. bs.

e4x + 2x3 ln x∧= [(4, (0, (0, 1))), (0, (3, (1, 2)))

Page 67: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operations

Reading off limits is still easy:

f (x) ∼ c · b1(x)e1 . . . bn(x)en + . . .

Just determine first non-zero ei :I Limit is 0 if ei < 0I Limit is sgn(c) ·∞ if ei > 0I Limit is c if all ei = 0

Page 68: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operations

Reading off limits is still easy:

f (x) ∼ c · b1(x)e1 . . . bn(x)en + . . .

Just determine first non-zero ei :

I Limit is 0 if ei < 0I Limit is sgn(c) ·∞ if ei > 0I Limit is c if all ei = 0

Page 69: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operations

Reading off limits is still easy:

f (x) ∼ c · b1(x)e1 . . . bn(x)en + . . .

Just determine first non-zero ei :I Limit is 0 if ei < 0

I Limit is sgn(c) ·∞ if ei > 0I Limit is c if all ei = 0

Page 70: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operations

Reading off limits is still easy:

f (x) ∼ c · b1(x)e1 . . . bn(x)en + . . .

Just determine first non-zero ei :I Limit is 0 if ei < 0I Limit is sgn(c) ·∞ if ei > 0

I Limit is c if all ei = 0

Page 71: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operations

Reading off limits is still easy:

f (x) ∼ c · b1(x)e1 . . . bn(x)en + . . .

Just determine first non-zero ei :I Limit is 0 if ei < 0I Limit is sgn(c) ·∞ if ei > 0I Limit is c if all ei = 0

Page 72: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsBefore:

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

Now:type Basis = (R→ R) listdatatype Exp : Basis→ Type whereConst : R→ Exp []Exp : (Exp bs×R) llist→ Exp (b :: bs)

negate : Exp bs→ Exp bsnegate (Const c) = −cnegate (Exp xs) = Exp [(negate c , e) | (c , e)← xs]

Page 73: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsBefore:

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

Now:type Basis = (R→ R) list

datatype Exp : Basis→ Type whereConst : R→ Exp []Exp : (Exp bs×R) llist→ Exp (b :: bs)

negate : Exp bs→ Exp bsnegate (Const c) = −cnegate (Exp xs) = Exp [(negate c , e) | (c , e)← xs]

Page 74: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsBefore:

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

Now:type Basis = (R→ R) listdatatype Exp : Basis→ Type whereConst : R→ Exp []Exp : (Exp bs×R) llist→ Exp (b :: bs)

negate : Exp bs→ Exp bsnegate (Const c) = −cnegate (Exp xs) = Exp [(negate c , e) | (c , e)← xs]

Page 75: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsBefore:

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

Now:type Basis = (R→ R) listdatatype Exp : Basis→ Type whereConst : R→ Exp []Exp : (Exp bs×R) llist→ Exp (b :: bs)

negate : Exp bs→ Exp bsnegate (Const c) = −c

negate (Exp xs) = Exp [(negate c , e) | (c , e)← xs]

Page 76: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Other operationsBefore:

type Exp = (R×R) llist

negate : Exp→ Expnegate xs = [(−c , e) | (c , e)← xs]

Now:type Basis = (R→ R) listdatatype Exp : Basis→ Type whereConst : R→ Exp []Exp : (Exp bs×R) llist→ Exp (b :: bs)

negate : Exp bs→ Exp bsnegate (Const c) = −cnegate (Exp xs) = Exp [(negate c , e) | (c , e)← xs]

Page 77: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – LogarithmSame trick as before: Given

f (x) = c(x) xe + g(x) with g(x) ∼ xs

we rearrange

ln(f (x)) = ln(c(x) xe(1+ c(x)−1x−eg(x)))

= ln c(x) + e ln x + ln(1+ c(x)−1x−eg(x)

)and t 7→ ln(1+ t) has a power series expansion. :)

We might have to add ln x to our basis!

Page 78: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – LogarithmSame trick as before: Given

f (x) = c(x) xe + g(x) with g(x) ∼ xs

we rearrange

ln(f (x)) = ln(c(x) xe(1+ c(x)−1x−eg(x)))

= ln c(x) + e ln x + ln(1+ c(x)−1x−eg(x)

)and t 7→ ln(1+ t) has a power series expansion. :)

We might have to add ln x to our basis!

Page 79: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – LogarithmSame trick as before: Given

f (x) = c(x) xe + g(x) with g(x) ∼ xs

we rearrange

ln(f (x)) = ln(c(x) xe(1+ c(x)−1x−eg(x)))

= ln c(x) + e ln x + ln(1+ c(x)−1x−eg(x)

)

and t 7→ ln(1+ t) has a power series expansion. :)

We might have to add ln x to our basis!

Page 80: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – LogarithmSame trick as before: Given

f (x) = c(x) xe + g(x) with g(x) ∼ xs

we rearrange

ln(f (x)) = ln(c(x) xe(1+ c(x)−1x−eg(x)))

= ln c(x) + e ln x + ln(1+ c(x)−1x−eg(x)

)and t 7→ ln(1+ t) has a power series expansion. :)

We might have to add ln x to our basis!

Page 81: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – LogarithmSame trick as before: Given

f (x) = c(x) xe + g(x) with g(x) ∼ xs

we rearrange

ln(f (x)) = ln(c(x) xe(1+ c(x)−1x−eg(x)))

= ln c(x) + e ln x + ln(1+ c(x)−1x−eg(x)

)and t 7→ ln(1+ t) has a power series expansion. :)

We might have to add ln x to our basis!

Page 82: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Exponential

Exponential is much more complicated – too complicated forthese slides.

I Lots of case distinctionsI Can introduce ugly new basis elements like exp(x + 1/x)I Lots of opportunities for implementation bugsI Luckily, the Isabelle kernel caught them, of course. :)

Page 83: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Exponential

Exponential is much more complicated – too complicated forthese slides.I Lots of case distinctions

I Can introduce ugly new basis elements like exp(x + 1/x)I Lots of opportunities for implementation bugsI Luckily, the Isabelle kernel caught them, of course. :)

Page 84: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Exponential

Exponential is much more complicated – too complicated forthese slides.I Lots of case distinctionsI Can introduce ugly new basis elements like exp(x + 1/x)

I Lots of opportunities for implementation bugsI Luckily, the Isabelle kernel caught them, of course. :)

Page 85: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Exponential

Exponential is much more complicated – too complicated forthese slides.I Lots of case distinctionsI Can introduce ugly new basis elements like exp(x + 1/x)I Lots of opportunities for implementation bugs

I Luckily, the Isabelle kernel caught them, of course. :)

Page 86: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Asymptotic Expansions – Exponential

Exponential is much more complicated – too complicated forthese slides.I Lots of case distinctionsI Can introduce ugly new basis elements like exp(x + 1/x)I Lots of opportunities for implementation bugsI Luckily, the Isabelle kernel caught them, of course. :)

Page 87: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

What this looks like in Isabelle

Type α ms for multiseries with coefficients of type α

datatype α ms = MS ”(α× real) llist” ”real⇒ real”

E.g. expansion of order 3 would be ‘real ms ms ms’.

Operations on ms are defined with corecursion,proven correct with coinduction

How do we turn this into a proof method?

Page 88: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

What this looks like in Isabelle

Type α ms for multiseries with coefficients of type α

datatype α ms = MS ”(α× real) llist” ”real⇒ real”

E.g. expansion of order 3 would be ‘real ms ms ms’.

Operations on ms are defined with corecursion,proven correct with coinduction

How do we turn this into a proof method?

Page 89: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

What this looks like in Isabelle

Type α ms for multiseries with coefficients of type α

datatype α ms = MS ”(α× real) llist” ”real⇒ real”

E.g. expansion of order 3 would be ‘real ms ms ms’.

Operations on ms are defined with corecursion,proven correct with coinduction

How do we turn this into a proof method?

Page 90: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Computing Expansionsin Isabelle

Page 91: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

So far, we can write down expansions as HOL terms

– but how do we evaluate them?

Isabelle has tools to evaluate terms strictly, but we need lazyevaluation.

I had to implement lazy evaluation of HOL terms.

Page 92: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

So far, we can write down expansions as HOL terms– but how do we evaluate them?

Isabelle has tools to evaluate terms strictly, but we need lazyevaluation.

I had to implement lazy evaluation of HOL terms.

Page 93: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

So far, we can write down expansions as HOL terms– but how do we evaluate them?

Isabelle has tools to evaluate terms strictly, but we need lazyevaluation.

I had to implement lazy evaluation of HOL terms.

Page 94: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

So far, we can write down expansions as HOL terms– but how do we evaluate them?

Isabelle has tools to evaluate terms strictly, but we need lazyevaluation.

I had to implement lazy evaluation of HOL terms.

Page 95: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

EvaluationLazy evaluation framework:I set of supported (co-)datatypes and their constructors

I set of supported functionsI set of function equations of the form f (r , s, t) = . . .

The framework canI determine whether a pattern matches a term (modulo

rewriting)I bring a term into head-normal formI produce an Isabelle theorem of the form

original term = reduced termDoes not support sharing

Page 96: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

EvaluationLazy evaluation framework:I set of supported (co-)datatypes and their constructorsI set of supported functions

I set of function equations of the form f (r , s, t) = . . .The framework canI determine whether a pattern matches a term (modulo

rewriting)I bring a term into head-normal formI produce an Isabelle theorem of the form

original term = reduced termDoes not support sharing

Page 97: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

EvaluationLazy evaluation framework:I set of supported (co-)datatypes and their constructorsI set of supported functionsI set of function equations of the form f (r , s, t) = . . .

The framework canI determine whether a pattern matches a term (modulo

rewriting)I bring a term into head-normal formI produce an Isabelle theorem of the form

original term = reduced termDoes not support sharing

Page 98: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

EvaluationLazy evaluation framework:I set of supported (co-)datatypes and their constructorsI set of supported functionsI set of function equations of the form f (r , s, t) = . . .

The framework canI determine whether a pattern matches a term (modulo

rewriting)

I bring a term into head-normal formI produce an Isabelle theorem of the form

original term = reduced termDoes not support sharing

Page 99: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

EvaluationLazy evaluation framework:I set of supported (co-)datatypes and their constructorsI set of supported functionsI set of function equations of the form f (r , s, t) = . . .

The framework canI determine whether a pattern matches a term (modulo

rewriting)I bring a term into head-normal form

I produce an Isabelle theorem of the formoriginal term = reduced term

Does not support sharing

Page 100: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

EvaluationLazy evaluation framework:I set of supported (co-)datatypes and their constructorsI set of supported functionsI set of function equations of the form f (r , s, t) = . . .

The framework canI determine whether a pattern matches a term (modulo

rewriting)I bring a term into head-normal formI produce an Isabelle theorem of the form

original term = reduced termDoes not support sharing

Page 101: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Problem:I Addition of expansions involves comparisons of real

numbers

I ‘Trimming’ expansions involves zeroness tests of realfunctions

I Both of these are difficult or even undecidable

Page 102: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Problem:I Addition of expansions involves comparisons of real

numbersI ‘Trimming’ expansions involves zeroness tests of real

functions

I Both of these are difficult or even undecidable

Page 103: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Problem:I Addition of expansions involves comparisons of real

numbersI ‘Trimming’ expansions involves zeroness tests of real

functionsI Both of these are difficult or even undecidable

Page 104: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Solution: Heuristic approach using Isabelle’s automation

I Use automation to determine signs – might failI Use automation to determine if function is identically zero

– might cause non-terminationI User may have to supply additional facts

This works surprisingly well

Additional backends (user input/Mathematica/Maple) possible

Page 105: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Solution: Heuristic approach using Isabelle’s automationI Use automation to determine signs – might fail

I Use automation to determine if function is identically zero– might cause non-termination

I User may have to supply additional facts

This works surprisingly well

Additional backends (user input/Mathematica/Maple) possible

Page 106: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Solution: Heuristic approach using Isabelle’s automationI Use automation to determine signs – might failI Use automation to determine if function is identically zero

– might cause non-termination

I User may have to supply additional facts

This works surprisingly well

Additional backends (user input/Mathematica/Maple) possible

Page 107: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Solution: Heuristic approach using Isabelle’s automationI Use automation to determine signs – might failI Use automation to determine if function is identically zero

– might cause non-terminationI User may have to supply additional facts

This works surprisingly well

Additional backends (user input/Mathematica/Maple) possible

Page 108: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Solution: Heuristic approach using Isabelle’s automationI Use automation to determine signs – might failI Use automation to determine if function is identically zero

– might cause non-terminationI User may have to supply additional facts

This works surprisingly well

Additional backends (user input/Mathematica/Maple) possible

Page 109: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Evaluation

Solution: Heuristic approach using Isabelle’s automationI Use automation to determine signs – might failI Use automation to determine if function is identically zero

– might cause non-terminationI User may have to supply additional facts

This works surprisingly well

Additional backends (user input/Mathematica/Maple) possible

Page 110: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

At this point, we have all the ingredients:I Parse and pre-process input expression

I Compute expansions bottom-upI Use evaluation framework to trim expansions/determine

signs whenever necessaryI In the end: Trim expansion to determine leading term

Page 111: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

At this point, we have all the ingredients:I Parse and pre-process input expressionI Compute expansions bottom-up

I Use evaluation framework to trim expansions/determinesigns whenever necessary

I In the end: Trim expansion to determine leading term

Page 112: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

At this point, we have all the ingredients:I Parse and pre-process input expressionI Compute expansions bottom-upI Use evaluation framework to trim expansions/determine

signs whenever necessary

I In the end: Trim expansion to determine leading term

Page 113: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

At this point, we have all the ingredients:I Parse and pre-process input expressionI Compute expansions bottom-upI Use evaluation framework to trim expansions/determine

signs whenever necessaryI In the end: Trim expansion to determine leading term

Page 114: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

With some pre-processing, we can automatically provestatements of the formI f (x) −→ c

I f (x) ∼ g(x)

I f (x) ∈ L(g(x)) for any Landau symbol Las x → l for l ∈ R∪ ±∞

f and g can be built from + − · / ln exp min max ˆ | · | n√·

without restrictions

sin, cos, tan at finite points also possible.

Page 115: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

With some pre-processing, we can automatically provestatements of the formI f (x) −→ c

I f (x) ∼ g(x)

I f (x) ∈ L(g(x)) for any Landau symbol Las x → l for l ∈ R∪ ±∞

f and g can be built from + − · / ln exp min max ˆ | · | n√·

without restrictions

sin, cos, tan at finite points also possible.

Page 116: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

With some pre-processing, we can automatically provestatements of the formI f (x) −→ c

I f (x) ∼ g(x)

I f (x) ∈ L(g(x)) for any Landau symbol Las x → l for l ∈ R∪ ±∞

f and g can be built from + − · / ln exp min max ˆ | · | n√·

without restrictions

sin, cos, tan at finite points also possible.

Page 117: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

Examplelemma (λn. (1+ 1/n) ˆ n) −→ exp 1

by exp_log_asymptotics

Examplelemma ((λx . (1+ y/x) ˆ x) −→ exp y) at_topproof (cases y = 0)

case Falsethus ?thesis by exp_log_asymptotics

qed simp_all

Page 118: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof method

Examplelemma (λn. (1+ 1/n) ˆ n) −→ exp 1

by exp_log_asymptotics

Examplelemma ((λx . (1+ y/x) ˆ x) −→ exp y) at_topproof (cases y = 0)

case Falsethus ?thesis by exp_log_asymptotics

qed simp_all

Page 119: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof methodExamplelemma

assumes c > 1 and k > 0shows (λn. n ˆ k) ∈ o(λn. c ˆ n)

using assms by exp_log_asymptotics

Examplelemma akra_bazzi_aux:

assumes b ∈ 0< ..<1 and ε > 0shows filterlim (λx .

(1− H/(b ∗ ln x ˆ(1+ ε))) ˆ p ∗(1+ ln (b ∗ x +H ∗ x/ln x ˆ(1+ ε)) ˆ(−ε/2))−(1+ ln x ˆ(−ε/2)))

(at_right 0) at_topby (exp_log_asymptotics simp: mult_neg_pos)

Page 120: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof methodExamplelemma

assumes c > 1 and k > 0shows (λn. n ˆ k) ∈ o(λn. c ˆ n)

using assms by exp_log_asymptotics

Examplelemma akra_bazzi_aux:

assumes b ∈ 0< ..<1 and ε > 0shows filterlim (λx .

(1− H/(b ∗ ln x ˆ(1+ ε))) ˆ p ∗(1+ ln (b ∗ x +H ∗ x/ln x ˆ(1+ ε)) ˆ(−ε/2))−(1+ ln x ˆ(−ε/2)))

(at_right 0) at_top

by (exp_log_asymptotics simp: mult_neg_pos)

Page 121: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Proof methodExamplelemma

assumes c > 1 and k > 0shows (λn. n ˆ k) ∈ o(λn. c ˆ n)

using assms by exp_log_asymptotics

Examplelemma akra_bazzi_aux:

assumes b ∈ 0< ..<1 and ε > 0shows filterlim (λx .

(1− H/(b ∗ ln x ˆ(1+ ε))) ˆ p ∗(1+ ln (b ∗ x +H ∗ x/ln x ˆ(1+ ε)) ˆ(−ε/2))−(1+ ln x ˆ(−ε/2)))

(at_right 0) at_topby (exp_log_asymptotics simp: mult_neg_pos)

Page 122: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

What works well:I Surprisingly, all examples I tried take no more than a few

seconds

I Algorithm copes very well with free variables that don’taffect result

Problems:I If several cancellations occur, performance gets very badI Getting zeroness/sign tests to work can be trial & errorI Case distinctions have to be done manuallyI Somewhat ‘ad-hoc’ formalisation

Page 123: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

What works well:I Surprisingly, all examples I tried take no more than a few

secondsI Algorithm copes very well with free variables that don’t

affect result

Problems:I If several cancellations occur, performance gets very badI Getting zeroness/sign tests to work can be trial & errorI Case distinctions have to be done manuallyI Somewhat ‘ad-hoc’ formalisation

Page 124: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

What works well:I Surprisingly, all examples I tried take no more than a few

secondsI Algorithm copes very well with free variables that don’t

affect resultProblems:I If several cancellations occur, performance gets very bad

I Getting zeroness/sign tests to work can be trial & errorI Case distinctions have to be done manuallyI Somewhat ‘ad-hoc’ formalisation

Page 125: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

What works well:I Surprisingly, all examples I tried take no more than a few

secondsI Algorithm copes very well with free variables that don’t

affect resultProblems:I If several cancellations occur, performance gets very badI Getting zeroness/sign tests to work can be trial & error

I Case distinctions have to be done manuallyI Somewhat ‘ad-hoc’ formalisation

Page 126: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

What works well:I Surprisingly, all examples I tried take no more than a few

secondsI Algorithm copes very well with free variables that don’t

affect resultProblems:I If several cancellations occur, performance gets very badI Getting zeroness/sign tests to work can be trial & errorI Case distinctions have to be done manually

I Somewhat ‘ad-hoc’ formalisation

Page 127: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

What works well:I Surprisingly, all examples I tried take no more than a few

secondsI Algorithm copes very well with free variables that don’t

affect resultProblems:I If several cancellations occur, performance gets very badI Getting zeroness/sign tests to work can be trial & errorI Case distinctions have to be done manuallyI Somewhat ‘ad-hoc’ formalisation

Page 128: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

I 5000 lines of Isabelle theory

I 3000 lines of (untrusted) ML codeI About 5 months of work so farI Implementation was tricky to get right

Page 129: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

I 5000 lines of Isabelle theoryI 3000 lines of (untrusted) ML code

I About 5 months of work so farI Implementation was tricky to get right

Page 130: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

I 5000 lines of Isabelle theoryI 3000 lines of (untrusted) ML codeI About 5 months of work so far

I Implementation was tricky to get right

Page 131: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Discussion

I 5000 lines of Isabelle theoryI 3000 lines of (untrusted) ML codeI About 5 months of work so farI Implementation was tricky to get right

Page 132: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs

Similar algorithm by Gruntz in Maple in 1996

(is now part of Mathematica)

Back then, all CASs gave wrong resultsfor many of his test cases!

Nowadays, most of them work

Page 133: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs

Similar algorithm by Gruntz in Maple in 1996(is now part of Mathematica)

Back then, all CASs gave wrong resultsfor many of his test cases!

Nowadays, most of them work

Page 134: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs

Similar algorithm by Gruntz in Maple in 1996(is now part of Mathematica)

Back then, all CASs gave wrong resultsfor many of his test cases!

Nowadays, most of them work

Page 135: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs

Similar algorithm by Gruntz in Maple in 1996(is now part of Mathematica)

Back then, all CASs gave wrong resultsfor many of his test cases!

Nowadays, most of them work

Page 136: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs23 test cases lie in the fragment we support

All of them work automaticallyMaximum time: 1.726 s; Median: 0.311 s

Mathematica and Maple do all of themvery quickly and correctly

Maxima, Sage, and SymPy fail on some of them

Maxima and Sage take very long for some of themand give wrong result for this:

exp

(log log

(x + e log x log log x

)log log log (ex + x + ln x)

)−→ e

Page 137: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs23 test cases lie in the fragment we support

All of them work automatically

Maximum time: 1.726 s; Median: 0.311 s

Mathematica and Maple do all of themvery quickly and correctly

Maxima, Sage, and SymPy fail on some of them

Maxima and Sage take very long for some of themand give wrong result for this:

exp

(log log

(x + e log x log log x

)log log log (ex + x + ln x)

)−→ e

Page 138: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs23 test cases lie in the fragment we support

All of them work automaticallyMaximum time: 1.726 s; Median: 0.311 s

Mathematica and Maple do all of themvery quickly and correctly

Maxima, Sage, and SymPy fail on some of them

Maxima and Sage take very long for some of themand give wrong result for this:

exp

(log log

(x + e log x log log x

)log log log (ex + x + ln x)

)−→ e

Page 139: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs23 test cases lie in the fragment we support

All of them work automaticallyMaximum time: 1.726 s; Median: 0.311 s

Mathematica and Maple do all of themvery quickly and correctly

Maxima, Sage, and SymPy fail on some of them

Maxima and Sage take very long for some of themand give wrong result for this:

exp

(log log

(x + e log x log log x

)log log log (ex + x + ln x)

)−→ e

Page 140: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs23 test cases lie in the fragment we support

All of them work automaticallyMaximum time: 1.726 s; Median: 0.311 s

Mathematica and Maple do all of themvery quickly and correctly

Maxima, Sage, and SymPy fail on some of them

Maxima and Sage take very long for some of themand give wrong result for this:

exp

(log log

(x + e log x log log x

)log log log (ex + x + ln x)

)−→ e

Page 141: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASs23 test cases lie in the fragment we support

All of them work automaticallyMaximum time: 1.726 s; Median: 0.311 s

Mathematica and Maple do all of themvery quickly and correctly

Maxima, Sage, and SymPy fail on some of them

Maxima and Sage take very long for some of themand give wrong result for this:

exp

(log log

(x + e log x log log x

)log log log (ex + x + ln x)

)−→ e

Page 142: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASsHow well are we doing?

Surprisingly, we are not that much slower (sometimes evenfaster) than Maple/Mathematica on many examples

Also: All CASs seem to fail on the Akra–Bazzi example assoon as variables are involved

In general, of course, Mathematica/Maple are much better inboth scope and speed

But: you have to trust the implementations.

Isabelle still isn’t a CAS – but we’re getting there.

Page 143: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASsHow well are we doing?

Surprisingly, we are not that much slower (sometimes evenfaster) than Maple/Mathematica on many examples

Also: All CASs seem to fail on the Akra–Bazzi example assoon as variables are involved

In general, of course, Mathematica/Maple are much better inboth scope and speed

But: you have to trust the implementations.

Isabelle still isn’t a CAS – but we’re getting there.

Page 144: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASsHow well are we doing?

Surprisingly, we are not that much slower (sometimes evenfaster) than Maple/Mathematica on many examples

Also: All CASs seem to fail on the Akra–Bazzi example assoon as variables are involved

In general, of course, Mathematica/Maple are much better inboth scope and speed

But: you have to trust the implementations.

Isabelle still isn’t a CAS – but we’re getting there.

Page 145: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASsHow well are we doing?

Surprisingly, we are not that much slower (sometimes evenfaster) than Maple/Mathematica on many examples

Also: All CASs seem to fail on the Akra–Bazzi example assoon as variables are involved

In general, of course, Mathematica/Maple are much better inboth scope and speed

But: you have to trust the implementations.

Isabelle still isn’t a CAS – but we’re getting there.

Page 146: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Comparison to CASsHow well are we doing?

Surprisingly, we are not that much slower (sometimes evenfaster) than Maple/Mathematica on many examples

Also: All CASs seem to fail on the Akra–Bazzi example assoon as variables are involved

In general, of course, Mathematica/Maple are much better inboth scope and speed

But: you have to trust the implementations.

Isabelle still isn’t a CAS – but we’re getting there.

Page 147: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Future Work

I Incomplete support for Γ, ψ(n), arctan

I Cannot handle oscillating functions or complex-valuedasymptotics

I User interaction for zeroness tests could be improved

Page 148: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Future Work

I Incomplete support for Γ, ψ(n), arctanI Cannot handle oscillating functions or complex-valued

asymptotics

I User interaction for zeroness tests could be improved

Page 149: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Future Work

I Incomplete support for Γ, ψ(n), arctanI Cannot handle oscillating functions or complex-valued

asymptoticsI User interaction for zeroness tests could be improved

Page 150: Automatic Asymptotics in Isabelle/HOL *-0 · list datatype Exp : Basis!Type where

Questions? Demo?