-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheetaoperator.py
83 lines (67 loc) · 2.02 KB
/
eetaoperator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
## Python 3
## Code to obtain symbolic E_{eta}[u](t,t0)
## u(t)=(u_0(t),\cdots, u_m(t))
## u_0(t)=1
## t0\in \mathbb{R}
## E_{x_{i_1}eta}[u](t,t0)=int^t_{t0} u_{i_1}(t)*E_{eta}[u](t,t0)dt
## Libraries
import math
import itertools
from sympy import *
t = Symbol('t')
# define input function
def u(t):
return 1,sin(t),cos(t)
# define eeta function for one word
def Eeta(eta,t0):
Eetatemp=1
for i in eta:
Eetatemp=integrate(u(t)[i]*Eetatemp,(t,t0,t))
return Eetatemp
# we can check with either a tuple or a list
# print(Eeta((1,),0))
# print(Eeta([1,1],0))
# define eeta function for a list of words
def Eetavec(etalist,t0):
Eetavectemp=[]
for i in etalist:
Eetavectemp.append(Eeta(i,t0))
return Eetavectemp
#Eetavec([[0,0],[1,0,0,1]],0)
# generate all possible words from the vocabulary generated by the m+1 letters, truncated to size J
def getalletas(m,J):
alletas=[]
vocabulary=list(range(m+1))
for i in list(range(1,J+1)):
alletas.append(itertools.product(vocabulary, repeat = i))
return alletas
#for i in getalletas(2,3):
# for j in i:
# print(j)
# generate all eeta functions for all words previously generated
# it is a list of lists where each one contains Eetas for all words of a fixed size
# [[Eetas words of size one],[Eetas words of size two],[Eetas words of size three],...]
def Eetafliess(J,t0):
m=len(u(t))-1
Eetafliesstmp=[]
for i in getalletas(m,J):
Eetafliesstmp.append(Eetavec(i,t0))
return Eetafliesstmp
# check
# Eetafliess(2,0)
# writes Eetafliess as only one list: [Eetas words of size one,Eetas words of size two,...]
def Eetafliessv(J,t0):
Eetafliessvtmp=[]
for i in Eetafliess(J,t0):
for j in i:
Eetafliessvtmp.append(j)
return Eetafliessvtmp
# example
v=Eetafliessv(2,0)
# evaluates Eetafliessv at a final point tf
def Eetafeval(v,tf):
Eetafevaltmp=[]
for i in v:
Eetafevaltmp.append(i.subs({t:tf}).evalf())
return Eetafevaltmp
print(Eetafeval(v,1))