Flows.jl


In [1]:
using Flows


INFO: Recompiling stale cache file /home/hofi/.julia/lib/v0.4/Flows.ji for module Flows.

TimeExpression

TimeVariable


In [2]:
t = TimeVariable("t")


Out[2]:
$t$

In [3]:
typeof(t)


Out[3]:
Flows.TimeVariable

In [4]:
@t_vars s r τ


Out[4]:
(s,r,τ)

In [5]:
typeof(s)


Out[5]:
Flows.TimeVariable

TimeLinearCombination


In [6]:
ex = TimeLinearCombination(t,1,s,-2,r,3)


Out[6]:
$t-2s+3r$

The internal representation of a TimeLinearCombination is a list of (TimeExpression, coefficient)-pairs:


In [7]:
ex.terms


Out[7]:
3-element Array{Tuple{Flows.TimeExpression,Real},1}:
 (t,1) 
 (s,-2)
 (r,3) 

The operators +, -, * are overloaded. Therefore, the TimeLinearCombination ex from above can also be defined in the following way:


In [8]:
ex1 = t - 2s + 3r


Out[8]:
$t-2s+3r$

In [9]:
ex == ex1


Out[9]:
true

In [10]:
string(ex)


Out[10]:
"t-2s+3r"

In [11]:
t-2ex+11r-2(r-s)


Out[11]:
$-t+6s+3r$

In [12]:
ex-ex


Out[12]:
$0$

In [13]:
string(ex-ex)


Out[13]:
"t_zero"

t_zero

There is a predefined zero element t_zero which is implemented as an empty TimeLinearCombination:


In [14]:
ex-ex == t_zero


Out[14]:
true

In [15]:
typeof(t_zero)


Out[15]:
Flows.TimeLinearCombination

In [16]:
t_zero.terms


Out[16]:
0-element Array{Tuple{Flows.TimeExpression,Real},1}

coefficient


In [17]:
ex


Out[17]:
$t-2s+3r$

In [18]:
coefficient(ex,s)


Out[18]:
-2

substitute


In [19]:
substitute(ex,s,ex)


Out[19]:
$-t+4s-3r$

In [20]:
substitute(t,s,r)


Out[20]:
$t$

SpaceExpression

Here 'space' is ot necessarily physical space, but abstract (Banach) space on which functions (i.e. operators) and flows of differential equations are defined.

SpaceVariable


In [21]:
u = SpaceVariable("u")


Out[21]:
$u$

In [22]:
@x_vars v,w


Out[22]:
(v,w)

AutonomousFunction


In [23]:
@funs F,G,H


Out[23]:
(F,G,H)

In [24]:
typeof(G)


Out[24]:
Flows.VectorFieldVariable

AutonomousFunctionExpression


In [25]:
ex = AutonomousFunctionExpression(F,u)


Out[25]:
$F(u)$

In [26]:
ex1 = F(u)


Out[26]:
$F(u)$

In [27]:
string(ex1)


Out[27]:
"F(u)"

In [28]:
ex == ex1


Out[28]:
true

AutonomousFunctionExpression involving differentials:


In [29]:
ex = F(u,v)


Out[29]:
$F'(u)\cdot v$

In [30]:
string(ex)


Out[30]:
"F(u,v)"

In [31]:
ex = F(u,v,w)


Out[31]:
$F''(u)(v,w)$

In [32]:
string(ex)


Out[32]:
"F(u,v,w)"

FlowExpression


In [33]:
ex = FlowExpression(F, t, u, 0) # (the last argument 0 indicates that it is a 0th derivative w.r.t. time)


Out[33]:
$\mathcal{E}_{F}(t,u)$

In [34]:
ex1 = E(F,t,u)


Out[34]:
$\mathcal{E}_{F}(t,u)$

In [35]:
ex == ex1


Out[35]:
true

In [36]:
string(ex)


Out[36]:
"E(F,t,u)"

FlowExpression involving differentials:


In [37]:
ex = E(F,t,u,v)


Out[37]:
$\partial_{2}\mathcal{E}_{F}(t,u)\cdot v$

In [38]:
string(ex)


Out[38]:
"E(F,t,u,v)"

In [39]:
ex = E(F,t,u,v,w)


Out[39]:
$\partial_{2}^{2}\mathcal{E}_{F}(t,u)(v,w)$

In [40]:
string(ex)


Out[40]:
"E(F,t,u,v,w)"

NonAutonomousFunction


In [41]:
@nonautonomous_funs(S)


Out[41]:
(S,)

NonAutonomousFunctionExpression


In [42]:
ex = S(t,u)


Out[42]:
$S(t,u)$

In [43]:
string(ex)


Out[43]:
"S(t,u)"

In [44]:
ex = S(2,t,u,v)


Out[44]:
$\partial_{1}^{2}\partial_{2}S(t,u)\cdot v$

In [45]:
string(ex)


Out[45]:
"S(2,t,u,v)"

SpaceLinearCombinations


In [46]:
ex = -17E(F,t,u,v,w) + 2u + F(v,w)


Out[46]:
$F'(v)\cdot w+2u-17\partial_{2}^{2}\mathcal{E}_{F}(t,u)(v,w)$

In [47]:
ex-ex


Out[47]:
$0$

In [48]:
string(ex)


Out[48]:
"F(v,w)+2u-17E(F,t,u,v,w)"

x_zero


In [49]:
ex-ex == x_zero


Out[49]:
true

In [50]:
string(ex-ex)


Out[50]:
"x_zero"

differential


In [51]:
ex = F(G(u)) + E(F,t,u,w)


Out[51]:
$F(G(u))+\partial_{2}\mathcal{E}_{F}(t,u)\cdot w$

In [52]:
string(ex)


Out[52]:
"F(G(u))+E(F,t,u,w)"

We form the differential of the expression ex with respect to the variable u and apply it to the expression H(v). Note that the differntial is a linear map which has to be applied to something ("the slots have to be filled").


In [53]:
differential(ex, u, H(v))


Out[53]:
$F'(G(u))\cdot G'(u)\cdot H(v)+\partial_{2}^{2}\mathcal{E}_{F}(t,u)(w,H(v))$

In [54]:
ex = S(1,t-2s,2u+v)


Out[54]:
$\partial_{1}S(t-2s,v+2u)$

In [55]:
expand(differential(ex, u, w))


Out[55]:
$2\partial_{1}\partial_{2}S(t-2s,v+2u)\cdot w$

t_derivative


In [56]:
ex = E(F,t-2s,u+E(G,s,v))


Out[56]:
$\mathcal{E}_{F}(t-2s,\mathcal{E}_{G}(s,v)+u)$

In [57]:
t_derivative(ex, s)


Out[57]:
$-2F(\mathcal{E}_{F}(t-2s,\mathcal{E}_{G}(s,v)+u))+\partial_{2}\mathcal{E}_{F}(t-2s,\mathcal{E}_{G}(s,v)+u)\cdot G(\mathcal{E}_{G}(s,v))$

In [58]:
ex = S(2t,S(t,v))


Out[58]:
$S(2t,S(t,v))$

In [59]:
t_derivative(ex, t)


Out[59]:
$\partial_{2}S(2t,S(t,v))\cdot \partial_{1}S(t,v)+2\partial_{1}S(2t,S(t,v))$

expand


In [60]:
ex = E(F,t,u,2v+3w)


Out[60]:
$\partial_{2}\mathcal{E}_{F}(t,u)\cdot (3w+2v)$

In [61]:
Flows.expand(ex)


Out[61]:
$2\partial_{2}\mathcal{E}_{F}(t,u)\cdot v+3\partial_{2}\mathcal{E}_{F}(t,u)\cdot w$

In [62]:
ex = G(u, v+w, v+w)


Out[62]:
$G''(u)(w+v,w+v)$

In [63]:
Flows.expand(ex)


Out[63]:
$2G''(u)(w,v)+G''(u)(w,w)+G''(u)(v,v)$

In [64]:
ex = S(t,u,2v+3w)


Out[64]:
$\partial_{2}S(t,u)\cdot (3w+2v)$

In [65]:
expand(ex)


Out[65]:
$3\partial_{2}S(t,u)\cdot w+2\partial_{2}S(t,u)\cdot v$

reduce_order


In [66]:
ex = E(F,t,u,F(u))


Out[66]:
$\partial_{2}\mathcal{E}_{F}(t,u)\cdot F(u)$

In [67]:
reduce_order(ex)


Out[67]:
$F(\mathcal{E}_{F}(t,u))$

In [68]:
ex = E(F,t,u,F(u),v)


Out[68]:
$\partial_{2}^{2}\mathcal{E}_{F}(t,u)(F(u),v)$

In [69]:
reduce_order(ex)


Out[69]:
$-\partial_{2}\mathcal{E}_{F}(t,u)\cdot F'(u)\cdot v+F'(\mathcal{E}_{F}(t,u))\cdot \partial_{2}\mathcal{E}_{F}(t,u)\cdot v$

In [70]:
ex = E(F,t,u,F(u),v, w)


Out[70]:
$\partial_{2}^{3}\mathcal{E}_{F}(t,u)(F(u),v,w)$

In [71]:
reduce_order(ex)


Out[71]:
$-\partial_{2}^{2}\mathcal{E}_{F}(t,u)(F'(u)\cdot v,w)-\partial_{2}^{2}\mathcal{E}_{F}(t,u)(F'(u)\cdot w,v)+F'(\mathcal{E}_{F}(t,u))\cdot \partial_{2}^{2}\mathcal{E}_{F}(t,u)(v,w)-\partial_{2}\mathcal{E}_{F}(t,u)\cdot F''(u)(v,w)+F''(\mathcal{E}_{F}(t,u))(\partial_{2}\mathcal{E}_{F}(t,u)\cdot v,\partial_{2}\mathcal{E}_{F}(t,u)\cdot w)$

substitute


In [72]:
substitute(E(G,t,v), v, E(F,t,u))


Out[72]:
$\mathcal{E}_{G}(t,\mathcal{E}_{F}(t,u))$

Commutator $[F,G]$:


In [73]:
C_FG = F(u,G(u))-G(u,F(u))


Out[73]:
$-G'(u)\cdot F(u)+F'(u)\cdot G(u)$

Double commutator $[F,[F,G]]$ by substituting $G\to[F,G]$ in $[F,G]$:


In [74]:
expand(substitute(C_FG, G, C_FG, u))


Out[74]:
$G'(u)\cdot F'(u)\cdot F(u)-2F'(u)\cdot G'(u)\cdot F(u)-F''(u)(G(u),F(u))+F'(u)\cdot F'(u)\cdot G(u)+G''(u)(F(u),F(u))$

commutator


In [84]:
ex=commutator(F,G,u)


Out[84]:
$-G'(u)\cdot F(u)+F'(u)\cdot G(u)$

In [85]:
commutator(F,G,H,u)


Out[85]:
$H'(u)\cdot G'(u)\cdot F(u)+F'(u)\cdot (G'(u)\cdot H(u)-H'(u)\cdot G(u))+H''(u)(G(u),F(u))-G''(u)(H(u),F(u))-G'(u)\cdot H'(u)\cdot F(u)$

Verify Jacobi identity $[F,[G,H]]+[H,[F,G]]+[G,[H,F]]=0$:


In [86]:
expand(commutator(F,G,H,u)+commutator(G,H,F,u)+commutator(H,F,G,u))


Out[86]:
$0$

In [89]:
ex=expand(differential(ex,u,v))


Out[89]:
$F''(u)(G(u),v)-G'(u)\cdot F'(u)\cdot v+F'(u)\cdot G'(u)\cdot v-G''(u)(F(u),v)$

In [90]:
expand(differential(ex,u,w))


Out[90]:
$F''(u)(G'(u)\cdot v,w)+F'''(u)(G(u),v,w)-G''(u)(F'(u)\cdot v,w)+F''(u)(G'(u)\cdot w,v)+F'(u)\cdot G''(u)(w,v)-G''(u)(F'(u)\cdot w,v)-G'(u)\cdot F''(u)(v,w)-G'''(u)(F(u),v,w)$

In [ ]: