Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
158 lines (142 loc) · 3.45 KB

File metadata and controls

158 lines (142 loc) · 3.45 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package symjava.symbolic;
import java.util.ArrayList;
import java.util.List;
import symjava.symbolic.utils.Utils;
public class Derivative extends Func {
Func func = null;
List<Expr> dxyz = new ArrayList<Expr>();
public Derivative(Func f, Expr x) {
super("", f.args);
//Member variable 'expr' in func here is the expression after taking derivative
if(f.expr != null)
this.expr = f.expr.diff(x);
this.func = f;
this.dxyz.add(x);
this.label = "D" + f.label + "D" + getDxyzLabel();
this.sortKey = label;
}
public Derivative(Derivative df, Expr x) {
super("", df.args);
if(df.expr != null)
this.expr = df.expr.diff(x);
this.func = df.func;
this.dxyz.addAll(df.dxyz);
this.dxyz.add(x);
this.label = df.label + x.label;
this.sortKey = label;
}
public Derivative(Func f, Expr[] xs) {
super("", f.args);
if(f.expr != null) {
this.expr = f.expr;
for(Expr x : xs)
this.expr = this.expr.diff(x);
}
this.func = f;
for(Expr x : xs)
this.dxyz.add(x);
this.label = "D" + f.label + "D" + getDxyzLabel();
this.sortKey = label;
}
// public Derivative(Derivative other) {
// super("", other.args);
// this.expr = other.expr;
// this.dxyz.addAll(other.dxyz);
// this.func = other.func;
// this.label = other.label;
// this.sortKey = other.sortKey;
// }
public static Expr simplifiedIns(Func f, Expr x) {
if(f.expr == null)
return new Derivative(f, x);
return f.expr.diff(x);
}
protected String getDxyzLabel() {
StringBuilder sb = new StringBuilder();
for(Expr e : dxyz) {
sb.append(e.toString());
}
return sb.toString();
}
@Override
public Expr diff(Expr expr) {
if(this.expr != null)
return this.expr.diff(expr);
else if(Utils.symCompare(this, expr)) {
return Symbol.C1;
} else if(!this.containsArg(expr) && expr instanceof Symbol) {
return Symbol.C0;
}
return new Derivative(this, expr);
}
@Override
public Expr simplify() {
if(this.expr != null) {
return this.expr.simplify();
}
return this;
}
@Override
public boolean symEquals(Expr other) {
if(other instanceof Derivative) {
Derivative o = (Derivative)other;
Boolean rlt = Utils.symCompareNull(this.expr, o.expr);
if(rlt != null && rlt == false)
return false;
if(!this.label.equals(o.label))
return false;
if(this.args.length != o.args.length)
return false;
for(int i=0; i<this.args.length; i++) {
if(!Utils.symCompare(this.args[i],o.args[i]))
return false;
}
if(this.dxyz.size() != o.dxyz.size())
return false;
for(int i=0; i<this.dxyz.size(); i++) {
if(!Utils.symCompare(this.dxyz.get(i), o.dxyz.get(i)))
return false;
}
return true;
}
return false;
}
@Override
public void flattenAdd(List<Expr> outList) {
if(expr != null)
expr.flattenAdd(outList);
else
outList.add(this);
}
@Override
public void flattenMultiply(List<Expr> outList) {
if(expr != null)
expr.flattenMultiply(outList);
else
outList.add(this);
}
@Override
public Expr subs(Expr from, Expr to) {
if(Utils.symCompare(this, from)) {
return to;
} else if(expr != null) {
return expr.subs(from, to);
} else if(Utils.symCompare(func, from)) {
if(to instanceof Func) {
Derivative rlt = new Derivative((Func)to,
this.dxyz.toArray(new Expr[0])
);
return rlt;
} else {
Expr diffExpr = to;
for(Expr x : dxyz)
diffExpr = diffExpr.diff(x);
return diffExpr;
}
}
return this;
}
public Func getFunc() {
return func;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.