File: selecting.cdb

package info (click to toggle)
cadabra2 2.4.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,796 kB
  • sloc: ansic: 133,450; cpp: 92,064; python: 1,530; javascript: 203; sh: 184; xml: 182; objc: 53; makefile: 51
file content (174 lines) | stat: -rw-r--r-- 4,160 bytes parent folder | download | duplicates (2)
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

def test01():
    __cdbkernel__=create_scope()
    ex:= A + B D G + C D A;
    zoom(_, $D Q??$)
    substitute(_, $A = Q$)
    unzoom(_)
    tst:= A + B D G + C D Q - @(ex);
    assert(tst==0)
    print("Test 01a passed")
    ex:= A + B D G + C D A;
    zoom(_, $D Q??$)
    substitute(_, $D = 0$)
    unzoom(_)
    tst:= A - @(ex);
    assert(tst==0)
    print("Test 01b passed")
    ex:= R = \int{A + B D G + C D A}{x};
    zoom(_, $D Q??$)
    substitute(_, $A = Q$)
    unzoom(_)
    tst:= ( R = \int{A + B D G + C D Q}{x} ) - @(ex);
    print("Test 01c passed")
    ex:= R = \int{A + B D G + C D A}{x};
    zoom(_, $D Q??$)
    substitute(_, $A = 0$)
    unzoom(_)
    tst:= ( R = \int{A + B D G}{x} ) - @(ex);
    assert(tst== $0 = 0$)
    print("Test 01d passed")
    ex:= R + S = \int{A + B D G + C D A}{x};
    zoom(_, $D Q??$)
    substitute(_, $A = 0$)
    unzoom(_)
    tst:= ( R + S = \int{A + B D G}{x} ) - @(ex);
    assert(tst== $0 = 0$)
    print("Test 01e passed")

test01()

# def test02():
#     __cdbkernel__=create_scope()
# a:= A,B,C;
# b:= D,E,F;
# c:= Q;
# d:= R+S;
# ex1=a+b
# ex2=a+c
# ex3=c+a
# ex4=a+d
# tst1:= {A,B,C,D,E,F};
# tst2:= {A,B,C,Q};
# tst3:= {Q,A,B,C};
# tst4:= {A,B,C,R+S};
# assert(tst1==ex1)
# assert(tst2==ex2)
# assert(tst3==ex3)
# assert(tst4==ex4)
#     print("Test 02 passed")
# 
# test02()

def test03():
    # zoom should also work to select terms in an integral
    # and then replace them later.
    __cdbkernel__=create_scope()
    ex:= 5\int{A+3 B M + C N+D}{dx};
    zoom(_, $B Q??$)
    substitute(_, $B->2 P$)
    unzoom(_)
    tst:= 5\int{A + 6 P M + C N + D}{dx} - @(ex);
    assert(tst==0)
    print("Test 03 passed")

test03()

def test04():
    # zoom should also work to select terms in an integral
    # and then replace them later.
    __cdbkernel__=create_scope()
    ex:= 5\int{A+3 B M + C N+D}{dx};
    zoom(_, $B Q??$)
    substitute(_, $B->0$)
    unzoom(_)
    tst:= 5\int{A + C N + D}{dx} - @(ex);
    assert(tst==0)
    print("Test 04 passed")

test04()

def test05():
    __cdbkernel__=create_scope()
    \partial{#}::PartialDerivative;
    ex:=\int{A_{i} h_{j} + \partial_{i}{B_{j}} D }{x};
    zoom(_, $\partial_{i}{B_{j}} Q??$)
    substitute(_, $D -> E$)
    unzoom(_)
    tst:=\int{A_{i} h_{j} + \partial_{i}{B_{j}} E}{x} - @(ex);
    assert(tst==0)
    print("Test 05 passed")

test05()


# ex:= \sin( 3 \int{ A E + B_{m} C^{m} + Q D }{x} ) + \cos( \int{ A K + B E }{x} );
# zoom(_, $A Q??$);
# substitute(_, $E->1$);
# tst:= \sin( 3 \int{ A + B_{m} C^{m} + Q D }{x} ) + \cos( \int{ A K + B E }{x} ) - @(ex);

def test06():
    __cdbkernel__=create_scope()
    \partial{#}::PartialDerivative;
    ex:=  \int{ 3 A_{i j} + 2 \partial_{i}{\partial_{j}{h}}}{x};
    zoom(_, $A_{i j}$)
    substitute(_,$A_{i j} -> B_{i j}$)
    unzoom(_)
    tst:= \int{ 3 B_{i j} + 2 \partial_{i}{\partial_{j}{h}}}{x} - @(ex);
    assert(tst==0)
    print("Test 06 passed")

test06()

def test07():
    __cdbkernel__=create_scope()
    \partial{#}::PartialDerivative;
    ex:=  \int{ 3 h A_{i j} + 2 \partial_{i}{\partial_{j}{h}}}{x};
    zoom(_, $A_{i j} Q??$)
    substitute(_,$A_{i j} -> B_{i j}$)
    integrate_by_parts(_, $h$)  
    unzoom(_)
    tst:= \int{ 3 h B_{i j} + 2 \partial_{i}{\partial_{j}{h}}}{x} - @(ex);
    assert(tst==0)
    print("Test 07 passed")

test07()

def test08():
    __cdbkernel__=create_scope()
    ex:= A + B D + E B + C Q + D;
    cp1:= @(ex);        
    zoom(ex, $B Q??$)
    cp2:= @(ex);        
    zoom(ex, $E Q??$)
    unzoom(ex)
    tst:= @(cp2) - @(ex);
    assert(tst==0)
    print("Test 08a passed")
    unzoom(ex)
    tst:= @(cp1) - @(ex);
    assert(tst==0)
    print("Test 08b passed")
    ex:= A + B D + E B + C Q + D;
    cp1:= @(ex)        
    zoom(ex, $B Q??$)
    cp2:= @(ex)        
    zoom(ex, $E Q??$)
    unzoom(ex, repeat=True)
    tst:= @(cp1) - @(ex);
    assert(tst==0)
    print("Test 08c passed")

test08()        
            
        
#def test08():

# 
# \epsilon::Weight(label=field, value=1);
# Exp:=\epsilon**4+\epsilon*(\epsilon**3+5);
# zoom(_, $\epsilon * A??$);
# distribute(_);
# unzoom(_);
# drop_weight(_, $field=4$);