File: powers.cdb

package info (click to toggle)
cadabra 1.46-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,244 kB
  • sloc: cpp: 33,188; ansic: 2,724; makefile: 329; yacc: 180; sh: 157; python: 45; lex: 38; lisp: 19
file content (125 lines) | stat: -rw-r--r-- 2,370 bytes parent folder | download | duplicates (6)
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

# Tests of the ** operator and routines to collect exponents.

obj1:= sin(x) b sin(x) c sin(x)**3 d;
@collect_factors!(%);
tst1:= sin(x)**5 b c d - @(obj1);
@collect_terms!(%);
@assert(tst1);


obj2:= A_{m n} b A_{m n};
@collect_factors!(%);
tst2:= A_{m n} b A_{m n} - @(obj2);
@collect_terms!(%);
@assert(tst2);


obj3:= a**(2+3b) c a**(sin(x));
@collect_factors!(%);
tst3:= a**((2 + 3 * b) + sin(x)) * c - @(obj3);
@collect_terms!(%);
@assert(tst3);

tst4:= x**2;
@substitute!(%)( x-> 0);
@assert(tst4);

obj5:= p**2 p**{-1};
@collect_factors!(%);
tst5:= p - @(obj5);
@collect_terms!(%);
@assert(tst5);

obj6:= 3 p**2 p**{-2} * h_{m n} * h^{m n};
@collect_factors!(%);
tst6:= 3 h_{m n} h^{m n} - @(obj6);
@collect_terms!(%);
@assert(tst6);

obj7:= 3 p p**{-1} * h_{m n} * h^{m n};
@collect_factors!(%);
tst7:= 3 h_{m n} h^{m n} - @(obj7);
@collect_terms!(%);
@assert(tst7);

# Test 8: Catch powers <=1.
@reset.
obj8:= A**(-1);
@expand_power!(%);
tst8:= A**(-1) - @(obj8);
@collect_terms!(%);
@assert(tst8);

# Test 8b: Catch non-integer powers.
@reset.
obj8b:= A**(3/2);
@expand_power!(%);
tst8b:= A**(3/2) - @(obj8b);
@collect_terms!(%);
@assert(tst8b);


# Test 9: nested powers and so on
#
@reset.
obj9:= b**2 c**3 e;
@substitute!(%)(b -> 2*B*C, c -> (2*A*C + B**2), e -> A**2 );
# max9:= expand( @(obj9) );
@expand_power!(obj9);
@distribute!(%);
@prodsort!(%);
@collect_terms!(%);
@collect_factors!(%);
# @maxima(max9);
tst9:= 4 A**2 B**8 C**2 + 24 A**3 B**6 C**3 + 48 A**4 B**4 C**4 + 32 A**5 B**2 C**5 - @(obj9);
@collect_terms!(%);
@assert(tst9);

# Test 10: non-commuting factors
#
@reset.
{A,B,C,D,E}::NonCommuting.
obj10:= A B D q E B A q;
@collect_factors!(%);
tst10:= A B D q**2 E B A - @(obj10);
@collect_terms!(%);
@assert(tst10);

# Test 11: multipliers inside pow
#
@reset.
obj11a:= x**2;
@substitute!(%)( x -> -u );
@expand_power!(%);
@collect_factors!(%);
tst11a:= u**2 - @(obj11a);
@collect_terms!(%);
@assert(tst11a);

@reset.
obj11b:= x**3;
@substitute!(%)( x -> - 3 u );
@expand_power!(%);
@collect_factors!(%);
tst11b:= - 27 u**3 - @(obj11b);
@collect_terms!(%);
@assert(tst11b);

@reset.
obj11c:= x**{m} x**{-m};
@collect_factors!(%);
tst11c:= 1 - @(obj11c);
@collect_terms!(%);
@assert(tst11c);

@reset.
obj11d:= x**2 - x**{2};
@collect_terms!(%);
@assert(obj11d);

@reset.
obj11e:= x**{-2} - x**{(-2)};
@collect_terms!(%);
@assert(obj11e);