forked from yuemingl/SymJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbol.java
More file actions
106 lines (87 loc) · 2.58 KB
/
Symbol.java
File metadata and controls
106 lines (87 loc) · 2.58 KB
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
package symjava.symbolic;
import symjava.symbolic.utils.Utils;
/**
* An object of Symbol has a string name which is its unique id.
* Two objects of Symbol with the same name are the same thing in SymJava.
* see method symEquals()
*
*/
public class Symbol extends Expr {
public static Symbol a = new Symbol("a");
public static Symbol b = new Symbol("b");
public static Symbol c = new Symbol("c");
public static Symbol d = new Symbol("d");
public static Symbol e = new Symbol("e");
public static Symbol f = new Symbol("f");
public static Symbol g = new Symbol("g");
public static Symbol h = new Symbol("h");
public static Symbol r = new Symbol("r");
public static Symbol s = new Symbol("s");
public static Symbol t = new Symbol("t");
public static Symbol u = new Symbol("u");
public static Symbol v = new Symbol("v");
public static Symbol w = new Symbol("w");
public static Symbol x = new Symbol("x");
public static Symbol y = new Symbol("y");
public static Symbol z = new Symbol("z");
public static Symbol phi = new Symbol("\\phi");
public static Symbol psi = new Symbol("\\psi");
public static Symbol chi = new Symbol("\\chi");
public static Symbol alpha = new Symbol("\\alpha");
public static Symbol beta = new Symbol("\\beta");
public static Symbol gamma = new Symbol("\\gamma");
public static SymInteger Cm2 = new SymInteger(-1);
public static SymInteger Cm1 = new SymInteger(-1);
public static SymInteger C0 = new SymInteger(0);
public static SymInteger C1 = new SymInteger(1);
public static SymInteger C2 = new SymInteger(2);
public static Infinity oo = new Infinity();
public Symbol(String name) {
this.label = name;
sortKey = label;
}
public String toString() {
return label;
}
@Override
public Expr subs(Expr from, Expr to) {
if(Utils.symCompare(this, from)) {
return to;
}
return this;
}
@Override
public Expr diff(Expr expr) {
if(this.symEquals(expr))
return C1;
return C0;
}
@Override
public Expr simplify() {
return this;
}
@Override
public boolean symEquals(Expr other) {
if(other instanceof Symbol)
return this.label.equals(other.label);
return false;
}
public String getPrefix() {
String[] ss = this.toString().split("_");
return ss[0];
}
public boolean containsSubIndex() {
String[] ss = this.toString().split("_");
if(ss.length == 2) {
return true;
}
return false;
}
public int getSubIndex() {
String[] ss = this.toString().split("_");
if(ss.length == 2) {
return Integer.valueOf(ss[1]);
}
throw new IllegalArgumentException(this.getLabel()+" contains no sub index.");
}
}