-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecomega.mac
189 lines (157 loc) · 5 KB
/
specomega.mac
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
Lambert W package
@depends 'clifford
**********************************
* @license This library is free software you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
load(operpart);
alias(W, lambert_w);
alias(WW,generalized_lambert_w);
matchdeclare([%y], all);
matchdeclare([%yy], lambda([u], freeof(%e, u) and u#0));
/**/
matchdeclare([%a, %b], true);
defrule(%wexp2, exp(W(%y)), %y/W(%y));
defrule(%wexp1, exp(-W(%y)), W(%y)/%y);
defrule(%wexp12, exp(-%a*W(%y)), W(%y)^%a/%y^%a);
defrule(%wexp11, exp(%b-W(%y)), exp(%b)/%y*W(%y));
defrule(%wexp1, exp(-W(%y)), W(%y)/%y);
defrule(%wexp21, exp(%b+W(%y)), exp(%b)*%y/W(%y));
defrule(%wlog1, log(W(%y)), log(%y)-W(%y));
defrule(%olog2, log(omega(%y)), %y-omega(%y));
defrule(%wexp3, W(exp(%y)), omega(%y));
defrule(%wexp31, W(exp(%y)*%a), omega(%y+log(%a)));
omsubst1(expr):=apply1(expr, %wexp3, %wexp31) ;
/* pattern matchdeing */
defmatch (logm1, %a+%b*log(%y));
defmatch (logm2, %b*log(%y));
defmatch (expm1, %a+%b*exp((%y)));
defmatch (expm2, %b*exp((%y)));
defmatch (omlogm1, %b*omega(log(%y) +%y));
defmatch (omlogm2, %a+%b*omega(log(%y) +%y));
defmatch (wexpm1, %b*W(exp(%y)*%yy));
defmatch (wexpm2, %a+%b*W(exp(%y)*%yy));
defmatch (wexpm3, %b*(%a+W(exp(%y)*%yy)));
lamiter(expr, y):=subst(W(y)=exp(-W(y))/y, expr);
lamsubst(expr, y):=subst( y=W(y)*exp(W(y)), expr);
/**
Omega function
*/
gradef(omega(x), omega(x)/(1+omega(x)));
omsubst(expr, y):=subst( omega(y)=WW('k, exp(y)), expr);
sgn(x):=block(
if atom(x) then 'sgn(x)
else if op(x)="-" then -1 else 1
);
indefsubst(iexpr, ilim):=block([a,b],
[a,b]:ilim,
subst(nounify(integrate)= lambda ([u,v], 'integrate(u,v,a,b) ), iexpr)
);
imrew(wexpr, x):=block([ret, %b, %yy, %y, sol ],
if op(wexpr)="=" then
ret: rhs(wexpr) else ret:wexpr, display(ret),
wexpm1(ret),
display( %b, %yy, %y),
ret:exp(%y)*%yy=-1/%e,
sol: solve(ret, x),
[ sol, ret]
);
lamsolve(expr, x):=block([ %a, %b, %y, aa, bb, cc, eq1:x=aa*W(cc)+bb, ret, eq2, sol1:-1, logexpand:all, expr1, l, r],
if freeof(x, expr) then return([]),
if op(expr)="=" then
expr1:rhs(expr)-lhs(expr) else expr1:expr,
ret:expand(subst(eq1, expr1)),
[l,r]:partbyvar(ret, W),
/*display(l,r),*/
/* logarithm case */
if listp(logm1( r)) then sol1:sol1+1 else if listp(logm2( r)) then sol1:sol1+1 ,
if sol1<0 then return(sol1),
display(ret, %a, %b, %y),
sol1:solve(subst(W(cc)=0, %y), bb),
ret:subst(sol1, ret),
ret:expand(apply1(ret, %wlog1), 0),
eq2:ratcoeff( (ret), W(cc)),
/*display(ret, eq2),*/
sol1:cons(solve(eq2,aa)[1],sol1),
ret:expand(subst(sol1, ret),0),
eq2: solve(ret, cc)[1],
if emptyp(eq2) then return(eq2),
eq2: factor(eq2),
sol1:cons(eq2, sol1),
eq2:subst(sol1, eq1),
[eq2, sol1 ]
);
lamsolve2(expr, x):=block([ %a, %b, %y, aa, bb, cc, eq1:x=aa*W(cc)+bb, ret, eq2, sol1:-1, logexpand:all, expr1, l, r, n],
if freeof(x, expr) then return([]),
if op(expr)="=" then
expr1:rhs(expr)-lhs(expr) else expr1:expr,
n:hipow(expr1,x),
ret:expand(subst(eq1, expr1)),
[l,r]:partbyvar(ret, W),
display(l,r),
/* exponential case */
if listp(expm1( r)) then sol1:sol1+1 else if listp(expm2( r)) then sol1:sol1+1 ,
if sol1<0 then return(sol1),
display(ret, %a, %b, %y),
eq2:ratcoeff( %y, W(cc))=-n,
sol1:solve(eq2, aa),
display(sol1),
eq2:solve(l, bb)[1],
sol1:cons(eq2, sol1),
ret: (subst(sol1, ret)),
ret:expand(apply1(ret, %wexp11, %wexp21, %wexp1, %wexp12), 0),
eq2:solve(ret, cc),
eq2:sublist(eq2, lambda([u], freeof(W,u) )),
display(ret, eq2),
if emptyp(eq2) then return(eq2),
sol1:cons(eq2[1], sol1),
eq2:subst(sol1, eq1),
[eq2, sol1]
);
omsimp1(expr):=block([ %a, %b, %y, ret:[], expr1],
if mapatom(expr) then return(expr)
else
if op(expr)="=" then
ret: map (omsimp1, expr)
else (
if listp(omlogm2( expr)) then
ret:%a+%y*%b
else (
ret:omlogm1( expr),
if not listp(ret) then ret:expr else ret:%y*%b
)
),
display(ret, %a, %b, %y),
ret
);
wsimp1(expr):=block([ %a, %b, %y, ret:[], aa, bb, expr1],
if mapatom(expr) then return(expr)
else
if op(expr)="=" then
ret: map (wsimp1, expr)
else (
if listp(wexpm2( expr)) then
if ratsimp(%y-%yy)=0 then ret:%a+%y*%b else ret:expr
elseif listp(wexpm3( expr)) then
if ratsimp(%y-%yy)=0 then ret:%a*%b+%y*%b else ret:expr
else (
ret:wexpm1( expr),
if not listp(ret) then ret:expr else
ret: %y*%b
)
),
display(ret, %a, %b, %y, %yy),
ret
);