proofs/warmup.bend checks
raw source on the hub · import bend-ta@0.1.0.0/proofs/warmup.bend as Warmup
8 imports
import Base import bend-mathlib@0.8.1.0/nat.bend as MNat import bend-mathlib@0.8.1.0/u32.bend as MU32 import ../src/core/ema.bend as Ema import ../src/core/sma.bend as Sma import ./configuration.bend as Configuration import ../src/core/window.bend as Window import ../src/core/rolling.bend as Rolling
Laws
law ema_live_one provedsource · line 30 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-mul:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @alpha:N -> @previous:N -> @price:N -> {0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.next(N, from_u32, add, sub, mul, div, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.Live{1, alpha, previous}, price) == (0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.Live{1, alpha, price}, Some{price}) : Pair(0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.State<N>, Maybe<&2, N>)}
law ema_first_one provedsource · line 45 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-mul:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @price:N -> {0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.next(N, from_u32, add, sub, mul, div, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.init(N, from_u32, div, 1), price) == (0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.Live{1, div(from_u32(2), from_u32(2)), price}, Some{price}) : Pair(0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.State<N>, Maybe<&2, N>)}
Definitions
def bounded source · line 11 · raw
@period:U32 -> @-m:Nat -> @em:{Nat.pow(2n, 32n) == m : Nat} -> 0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(U32.to_nat(period), m)
def add_one source · line 17 · raw
@+n:Nat -> {Nat.add(n, 1n) == 1n+n : Nat}
def increment_aux source · line 20 · raw
@+seen:U32 -> @+period:U32 -> @+m:Nat -> @em:{Nat.pow(2n, 32n) == m : Nat} -> @hp:0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(U32.to_nat(period), m) -> @before:0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(U32.to_nat(seen), U32.to_nat(period)) -> {U32.to_nat(U32.add(seen, 1)) == 1n+U32.to_nat(seen) : Nat}
def increment source · line 26 · raw
@+seen:U32 -> @+period:U32 -> @before:0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(U32.to_nat(seen), U32.to_nat(period)) -> {U32.to_nat(U32.add(seen, 1)) == 1n+U32.to_nat(seen) : Nat}
def is_some source · line 58 · raw
@-N:Data -> @value:Maybe<&2, N> -> Bool
def warm source · line 63 · raw
@-N:Data -> @-S:Type -> @-step:(@_:S -> @_:N -> Pair(S, Maybe<&2, N>)) -> @remaining:Nat -> @-prices:(@_:Nat -> N) -> @-offset:Nat -> @-state:S -> Type
def lt_ne source · line 73 · raw
@+a:Nat -> @+b:Nat -> @h:0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(a, b) -> {Nat.is_eq(a, b) == False{} : Bool}
def eq_check source · line 80 · raw
@+a:U32 -> @+b:U32 -> @e:{U32.to_nat(a) == U32.to_nat(b) : Nat} -> {U32.is_eq(a, b) == True{} : Bool}
def lt_check source · line 83 · raw
@+a:U32 -> @+b:U32 -> @h:0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(U32.to_nat(a), U32.to_nat(b)) -> {U32.is_eq(a, b) == False{} : Bool}
def seen_zero source · line 86 · raw
@+seen:U32 -> @h:{U32.is_zero(seen) == True{} : Bool} -> {U32.to_nat(seen) == 0n : Nat}
def scheduled_before source · line 89 · raw
@+seen:U32 -> @+period:U32 -> @+rest:Nat -> @e:{Nat.add(U32.to_nat(seen), 1n+rest) == U32.to_nat(period) : Nat} -> 0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(U32.to_nat(seen), U32.to_nat(period))
def scheduled_next source · line 93 · raw
@+seen:U32 -> @+period:U32 -> @+rest:Nat -> @+e:{Nat.add(U32.to_nat(seen), 1n+rest) == U32.to_nat(period) : Nat} -> {Nat.add(U32.to_nat(U32.add(seen, 1)), rest) == U32.to_nat(period) : Nat}
def scheduled_first source · line 97 · raw
@+seen:U32 -> @+period:U32 -> @+rest:Nat -> @e:{Nat.add(U32.to_nat(seen), 1n+rest) == U32.to_nat(period) : Nat} -> @zero:{U32.to_nat(seen) == 0n : Nat} -> {Nat.add(1n, rest) == U32.to_nat(period) : Nat}
def equal_u32 source · line 100 · raw
@+a:U32 -> @+b:U32 -> @e:{U32.to_nat(a) == U32.to_nat(b) : Nat} -> {a == b : U32}
def eq_comm_u32 source · line 117 · raw
@+a:U32 -> @+b:U32 -> {U32.is_eq(a, b) == U32.is_eq(b, a) : Bool}
def unadd_zero source · line 120 · raw
@+n:Nat -> @+p:Nat -> @e:{Nat.add(n, 0n) == p : Nat} -> {n == p : Nat}
def and_left source · line 156 · raw
@a:Bool -> @b:Bool -> @h:{Bool.and(a, b) == True{} : Bool} -> {a == True{} : Bool}
def positive source · line 163 · raw
@+period:U32 -> @valid:{0xbb55196063fb99add8900a97dfe6ee2d/proofs/configuration.domain(period) == True{} : Bool} -> 0x8ae61ec3a6615abd35f196c07232ad28/nat.lt(0n, U32.to_nat(period))
def lookback_schedule source · line 167 · raw
@+period:U32 -> @valid:{0xbb55196063fb99add8900a97dfe6ee2d/proofs/configuration.domain(period) == True{} : Bool} -> {1n+U32.to_nat(U32.sub(period, 1)) == U32.to_nat(period) : Nat}
def warm_shape source · line 178 · raw
@-N:Data -> @-S:Type -> @-step:(@_:S -> @_:N -> Pair(S, Maybe<&2, N>)) -> @remaining:Nat -> @-prices:(@_:Nat -> N) -> @-offset:Nat -> @-state:S -> Type
def warm_shape_after source · line 188 · raw
@-N:Data -> @-S:Type -> @-step:(@_:S -> @_:N -> Pair(S, Maybe<&2, N>)) -> @remaining:Nat -> @-prices:(@_:Nat -> N) -> @-offset:Nat -> @-result:Pair(S, Maybe<&2, N>) -> Type
def min_left source · line 212 · raw
@+a:U32 -> @+b:U32 -> @h:0x8ae61ec3a6615abd35f196c07232ad28/nat.le(U32.to_nat(a), U32.to_nat(b)) -> {U32.min(a, b) == a : U32}
Templates
template ema_first_step source · line 103 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-mul:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @+period:U32 -> @+seen:U32 -> @+alpha:N -> @+origin:N -> @+sum:N -> @+price:N -> @+ready:Bool -> @first:{U32.is_zero(seen) == True{} : Bool} -> @test:{U32.is_eq(period, 1) == ready : Bool} -> {0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.next(N, from_u32, add, sub, mul, div, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.Seed{period, seen, alpha, origin, sum}, price) == 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.seed.finish(N, from_u32, add, div, period, 1, alpha, price, from_u32(0), ready) : Pair(0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.State<N>, Maybe<&2, N>)}
template ema_later_step source · line 110 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-mul:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @+period:U32 -> @+seen:U32 -> @+alpha:N -> @+origin:N -> @+sum:N -> @+price:N -> @+ready:Bool -> @first:{U32.is_zero(seen) == False{} : Bool} -> @test:{U32.is_eq(U32.add(seen, 1), period) == ready : Bool} -> {0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.next(N, from_u32, add, sub, mul, div, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.Seed{period, seen, alpha, origin, sum}, price) == 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.seed.finish(N, from_u32, add, div, period, U32.add(seen, 1), alpha, origin, add(sum, sub(price, origin)), ready) : Pair(0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.State<N>, Maybe<&2, N>)}
template seed_mean source · line 123 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @+period:U32 -> @+origin:N -> @sum:N -> N
template ema_warming source · line 126 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-mul:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @-D:Data -> @-sample:(@_:D -> @_:Nat -> N) -> @remaining:Nat -> @first:Bool -> @+data:D -> @+offset:Nat -> @+period:U32 -> @+seen:U32 -> @+alpha:N -> @+origin:N -> @+sum:N -> @+schedule:{Nat.add(U32.to_nat(seen), 1n+remaining) == U32.to_nat(period) : Nat} -> @+first_test:{U32.is_zero(seen) == first : Bool} -> warm(N, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.State<N>, s => x => 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.next(N, from_u32, add, sub, mul, div, s, x), remaining, at => sample(data, at), offset, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.Seed{period, seen, alpha, origin, sum})
template ema_initial_warmup source · line 171 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-mul:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @-D:Data -> @-sample:(@_:D -> @_:Nat -> N) -> @+period:U32 -> @data:D -> @valid:{0xbb55196063fb99add8900a97dfe6ee2d/proofs/configuration.domain(period) == True{} : Bool} -> warm(N, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.State<N>, s => x => 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.next(N, from_u32, add, sub, mul, div, s, x), U32.to_nat(U32.sub(period, 1)), at => sample(data, at), 0n, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.init(N, from_u32, div, period))
template warm_exact_shape source · line 198 · raw
@-N:Data -> @-S:Type -> @-step:(@_:S -> @_:N -> Pair(S, Maybe<&2, N>)) -> @remaining:Nat -> @-prices:(@_:Nat -> N) -> @-offset:Nat -> @-state:S -> @witness:warm(N, S, step, remaining, prices, offset, state) -> warm_shape(N, S, step, remaining, prices, offset, state)
template sma_pending source · line 215 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @+period:U32 -> @+size:U32 -> @+pos:U32 -> @+total:0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.Total<N> -> @+price:N -> @-buffer:Array<N> -> @-old:N -> @+old_test:{U32.is_eq(size, period) == False{} : Bool} -> @+new_test:{U32.is_eq(U32.add(size, 1), period) == False{} : Bool} -> @+minimum:{U32.min(U32.add(size, 1), period) == U32.add(size, 1) : U32} -> {0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.emit(N, from_u32, div, period, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.pushed(N, add, sub, total, price, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/window.push.result(N, period, size, pos, (buffer, old)))) == (0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.Sma{period, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.Sum{0xbb55196063fb99add8900a97dfe6ee2d/src/core/window.Window{buffer, period, U32.add(size, 1), U32.mod(U32.add(pos, 1), period)}, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.accumulate(N, add, sub, total, price)}}, None{}) : Pair(0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.State<N>, Maybe<&2, N>)}
template sma_rebuilt_ready source · line 228 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-div:(@_:N -> @_:N -> N) -> @period:U32 -> @result:Pair(0xbb55196063fb99add8900a97dfe6ee2d/src/core/window.State<N>, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.Total<N>) -> {is_some(N, Pair.snd(0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.State<N>, Maybe<&2, N>, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.emit(N, from_u32, div, period, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.rebuild.emit(N, result)))) == True{} : Bool}
template sma_boundary_rebuild source · line 235 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @cycled:Bool -> @+period:U32 -> @+pos:U32 -> @+zero:N -> @+total:0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.Total<N> -> @+price:N -> @buffer:Array<N> -> {is_some(N, Pair.snd(0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.State<N>, Maybe<&2, N>, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.emit(N, from_u32, div, period, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.advance(N, add, sub, zero, total, price, None{}, (0xbb55196063fb99add8900a97dfe6ee2d/src/core/window.Window{buffer, period, period, pos}, cycled))))) == True{} : Bool}
template sma_ready source · line 246 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @+period:U32 -> @+size:U32 -> @+pos:U32 -> @+total:0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.Total<N> -> @+price:N -> @buffer:Array<N> -> @-old:N -> @old_test:{U32.is_eq(size, period) == False{} : Bool} -> @minimum:{U32.min(U32.add(size, 1), period) == period : U32} -> {is_some(N, Pair.snd(0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.State<N>, Maybe<&2, N>, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.emit(N, from_u32, div, period, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.pushed(N, add, sub, total, price, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/window.push.result(N, period, size, pos, (buffer, old)))))) == True{} : Bool}
template shape_from_after source · line 257 · raw
@-N:Data -> @-S:Type -> @-step:(@_:S -> @_:N -> Pair(S, Maybe<&2, N>)) -> @remaining:Nat -> @-prices:(@_:Nat -> N) -> @-offset:Nat -> @-state:S -> @proof:warm_shape_after(N, S, step, remaining, prices, offset, step(state, prices(offset))) -> warm_shape(N, S, step, remaining, prices, offset, state)
template sma_warming_step source · line 266 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @-D:Data -> @-sample:(@_:D -> @_:Nat -> N) -> @remaining:Nat -> @+data:D -> @+offset:Nat -> @+period:U32 -> @+size:U32 -> @+pos:U32 -> @+total:0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.Total<N> -> @+price:N -> @result:Pair(Array<N>, N) -> @+schedule:{Nat.add(U32.to_nat(size), 1n+remaining) == U32.to_nat(period) : Nat} -> warm_shape_after(N, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.State<N>, s => x => 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.next(N, from_u32, add, sub, div, s, x), remaining, at => sample(data, at), offset, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.emit(N, from_u32, div, period, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/rolling.pushed(N, add, sub, total, price, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/window.push.result(N, period, size, pos, result))))
template sma_initial_warmup source · line 291 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @-D:Data -> @-sample:(@_:D -> @_:Nat -> N) -> @+period:U32 -> @+data:D -> @depth:Nat -> @valid:{0xbb55196063fb99add8900a97dfe6ee2d/proofs/configuration.domain(period) == True{} : Bool} -> warm_shape(N, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.State<N>, s => x => 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.next(N, from_u32, add, sub, div, s, x), U32.to_nat(U32.sub(period, 1)), at => sample(data, at), 0n, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/sma.init(N, from_u32, period, depth))
template ema_initial_warmup_shape source · line 299 · raw
@-N:Data -> @-from_u32:(@_:U32 -> N) -> @-add:(@_:N -> @_:N -> N) -> @-sub:(@_:N -> @_:N -> N) -> @-mul:(@_:N -> @_:N -> N) -> @-div:(@_:N -> @_:N -> N) -> @-D:Data -> @-sample:(@_:D -> @_:Nat -> N) -> @+period:U32 -> @+data:D -> @valid:{0xbb55196063fb99add8900a97dfe6ee2d/proofs/configuration.domain(period) == True{} : Bool} -> warm_shape(N, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.State<N>, s => x => 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.next(N, from_u32, add, sub, mul, div, s, x), U32.to_nat(U32.sub(period, 1)), at => sample(data, at), 0n, 0xbb55196063fb99add8900a97dfe6ee2d/src/core/ema.init(N, from_u32, div, period))