-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
climoivre.mac
120 lines (106 loc) · 2.91 KB
/
climoivre.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
/*******************************
Clifford algebra --
a lightweight package for performing Geometric Algebra calculations
Clifford exponential simplifications
@version 1.1 Date 13 Jan 2021
- bugfix: nameclash between csign and maxima function. renamed to ssign
1.0 Date 26 Jan 2020
-conjsimp
-csign
-ceparse
-climoivre
@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
*/
if get('clifford,'version)=false then (
print("loading clifford"),
load("clifford"),
simp:false,
tellsimpafter(conjugate(rr),rr),
tellsimpafter(conjugate(aa), conjsimp(aa)),
defrule (rsimp1, conjugate(aa), conjsimp(aa) ),
simp:true
);
conjsimp(ab):=block([ sop, s ],
if mapatom(ab) or freeof(asymbol, ab) then conjugate(ab)
else (
sop:inop(ab),
s:inargs(ab),
s: map(conjugate, s),
substinpart(sop,s,0)
)
);
/*
syntactic sign
*/
ssign(expr):=
if expr =0 then 0
else
if atom (expr) then (if expr<0 then 'minus else 'plus)
else
if op(expr)="-" then 'minus else 'plus;
/* backward compatibility */
alias(csign, ssign);
/*
De Moivre argument
*/
ceparse(pp):=block([l,r,s, q:1, m, sop],
sop: inop(pp),
if sop = "+" then (
l:maplist(ceparse, pp),
substinpart(".", l, 0)
) else (
m:second(inargs(pp)),
[l,r]:oppart(m, lambda([u], freeof (asymbol, u)) ),
if _debug=true then display(l,r),
if r='nil then
q:exp(l)
else (
s: expand(r.r),
s: dotsimpc(s),
if l='nil then l:1,
if _debug=true then display(s),
if s<0 or ssign(s)=minus then q: cos(l)+r*sin(l),
if s>0 or ssign(s)=plus then q: cosh(l)+r*sinh(l),
if s=0 or ssign(s)=0 then q: 1+ r*l
),
q
)
);
/*
Clifford De Moivre
*/
climoivre(expr):=block([l, r, v, u, ret],
if freeof(%e, expr) then ret:expr
else (
if inop(expr)="^" then
ret:ceparse(expr)
elseif inop(expr)="." or inop(expr)="+" then
ret:map(climoivre, expr)
elseif inop(expr)="*" then (
[l,r]:oppart(expr, lambda([u], freeof (asymbol, u)) ),
if _debug=true then display(l,r),
if l='nil then l:1,
ret:l*climoivre(r)
) else (
[l,r]:oppart(expr, lambda([u], freeof (%e, u)) ),
if _debug=true then display(l,r),
if l='nil then l:1,
ret:l*ceparse(r)
)
),
ret
);