KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > Supernumber


1 package JSci.maths;
2
3 import JSci.maths.groups.AbelianGroup;
4 import JSci.maths.fields.Ring;
5
6 /**
7 * The Supernumber class encapsulates supernumbers.
8 * They are actually implemented as elements of the Grassmann algebra <img border=0 alt="Lambda" SRC="doc-files/ulambda.gif"><sub>4</sub>
9 * rather than the full <img border=0 alt="Lambda" SRC="doc-files/ulambda.gif"><sub><img border=0 alt="infinity" SRC="doc-files/infinity.gif"></sub>.
10 * @jsci.planetmath Supernumber
11 * @version 0.1
12 * @author Mark Hale
13 */

14 public final class Supernumber implements Ring.Member {
15         private final int N=4;
16         private Complex body=Complex.ZERO;
17         private Complex soul1[]={Complex.ZERO,Complex.ZERO,Complex.ZERO,Complex.ZERO};
18         private Complex soul2[]={Complex.ZERO,Complex.ZERO,Complex.ZERO,Complex.ZERO,Complex.ZERO,Complex.ZERO};
19         private Complex soul3[]={Complex.ZERO,Complex.ZERO,Complex.ZERO,Complex.ZERO};
20         private Complex soul4=Complex.ZERO;
21         /**
22         * Constructs a supernumber.
23         */

24         public Supernumber() {}
25         /**
26         * Returns a string representing the value of this supernumber.
27         */

28         public String JavaDoc toString() {
29                 final StringBuffer JavaDoc buf=new StringBuffer JavaDoc(100);
30                 buf.append("(").append(body.toString()).append(")1+\n(");
31                 buf.append(soul1[0].toString()).append(", ");
32                 buf.append(soul1[1].toString()).append(", ");
33                 buf.append(soul1[2].toString()).append(", ");
34                 buf.append(soul1[3].toString()).append(")S1+\n(");
35                 buf.append(soul2[0].toString()).append(", ");
36                 buf.append(soul2[1].toString()).append(", ");
37                 buf.append(soul2[2].toString()).append(", ");
38                 buf.append(soul2[3].toString()).append(", ");
39                 buf.append(soul2[4].toString()).append(", ");
40                 buf.append(soul2[5].toString()).append(")S2+\n(");
41                 buf.append(soul3[0].toString()).append(", ");
42                 buf.append(soul3[1].toString()).append(", ");
43                 buf.append(soul3[2].toString()).append(", ");
44                 buf.append(soul3[3].toString()).append(")S3+\n(");
45                 buf.append(soul4.toString()).append(")S4");
46                 return buf.toString();
47         }
48         /**
49         * Returns the body (rank 0) of this supernumber.
50         */

51         public Complex getBody() {
52                 return body;
53         }
54         /**
55         * Sets the body (rank 0) of this supernumber.
56         */

57         public void setBody(final Complex b) {
58                 body=b;
59         }
60         /**
61         * Returns the a-number soul (rank 1) of this supernumber.
62         */

63         public Complex getSoul1(final int i) {
64                 return soul1[i];
65         }
66         /**
67         * Sets the a-number soul (rank 1) of this supernumber.
68         */

69         public void setSoul1(final int i,final Complex s) {
70                 soul1[i]=s;
71         }
72         /**
73         * Returns the c-number soul (rank 2) of this supernumber.
74         */

75         public Complex getSoul2(final int i) {
76                 return soul2[i];
77         }
78         /**
79         * Sets the c-number soul (rank 2) of this supernumber.
80         */

81         public void setSoul2(final int i,final Complex s) {
82                 soul2[i]=s;
83         }
84         /**
85         * Returns the a-number soul (rank 3) of this supernumber.
86         */

87         public Complex getSoul3(final int i) {
88                 return soul3[i];
89         }
90         /**
91         * Sets the a-number soul (rank 3) of this supernumber.
92         */

93         public void setSoul3(final int i,final Complex s) {
94                 soul3[i]=s;
95         }
96         /**
97         * Returns the c-number soul (rank 4) of this supernumber.
98         */

99         public Complex getSoul4() {
100                 return soul4;
101         }
102         /**
103         * Sets the c-number soul (rank 4) of this supernumber.
104         */

105         public void setSoul4(final Complex s) {
106                 soul4=s;
107         }
108         /**
109         * Returns the dimension.
110         */

111         public int dimension() {
112                 return 1<<N;
113         }
114     public Object JavaDoc getSet() {
115         throw new RuntimeException JavaDoc("Not yet implemented: file bug report");
116     }
117         /**
118         * Returns the negative of this number.
119         */

120         public AbelianGroup.Member negate() {
121                 Supernumber ans=new Supernumber();
122                 ans.body=(Complex)body.negate();
123                 ans.soul4=(Complex)soul4.negate();
124                 for(int i=0;i<N;i++) {
125                         ans.soul1[i]=(Complex)soul1[i].negate();
126                         ans.soul3[i]=(Complex)soul3[i].negate();
127                 }
128                 for(int i=0;i<soul2.length;i++)
129                         ans.soul2[i]=(Complex)soul2[i].negate();
130                 return ans;
131         }
132
133 // ADDITION
134

135         /**
136         * Returns the addition of this number and another.
137         */

138         public AbelianGroup.Member add(final AbelianGroup.Member z) {
139                 if(z instanceof Supernumber)
140                         return add((Supernumber)z);
141                 else
142                         throw new IllegalArgumentException JavaDoc("Member class not recognised by this method.");
143         }
144         /**
145         * Returns the addition of this supernumber and another.
146         * @param z a supernumber
147         */

148         public Supernumber add(Supernumber z) {
149                 Supernumber ans=new Supernumber();
150                 ans.body=body.add(z.body);
151                 ans.soul4=soul4.add(z.soul4);
152                 for(int i=0;i<N;i++) {
153                         ans.soul1[i]=soul1[i].add(z.soul1[i]);
154                         ans.soul3[i]=soul3[i].add(z.soul3[i]);
155                 }
156                 for(int i=0;i<soul2.length;i++)
157                         ans.soul2[i]=soul2[i].add(z.soul2[i]);
158                 return ans;
159         }
160
161 // SUBTRACTION
162

163         /**
164         * Returns the subtraction of this number and another.
165         */

166         public AbelianGroup.Member subtract(final AbelianGroup.Member z) {
167                 if(z instanceof Supernumber)
168                         return subtract((Supernumber)z);
169                 else
170                         throw new IllegalArgumentException JavaDoc("Member class not recognised by this method.");
171         }
172         /**
173         * Returns the subtraction of this supernumber and another.
174         * @param z a supernumber
175         */

176         public Supernumber subtract(Supernumber z) {
177                 Supernumber ans=new Supernumber();
178                 ans.body=body.subtract(z.body);
179                 ans.soul4=soul4.subtract(z.soul4);
180                 for(int i=0;i<N;i++) {
181                         ans.soul1[i]=soul1[i].subtract(z.soul1[i]);
182                         ans.soul3[i]=soul3[i].subtract(z.soul3[i]);
183                 }
184                 for(int i=0;i<soul2.length;i++)
185                         ans.soul2[i]=soul2[i].subtract(z.soul2[i]);
186                 return ans;
187         }
188
189 // MULTIPLICATION
190

191         /**
192         * Returns the multiplication of this number and another.
193         */

194         public Ring.Member multiply(final Ring.Member z) {
195                 if(z instanceof Supernumber)
196                         return multiply((Supernumber)z);
197                 else
198                         throw new IllegalArgumentException JavaDoc("Member class not recognised by this method.");
199         }
200         /**
201         * Returns the multiplication of this supernumber and another.
202         * @param z a supernumber
203         */

204         public Supernumber multiply(Supernumber z) {
205                 Supernumber ans=new Supernumber();
206                 ans.body=body.multiply(z.body);
207                 ans.soul4=(body.multiply(z.soul4))
208                         .add(soul1[0].multiply(z.soul3[1])).subtract(soul1[1].multiply(z.soul3[2]))
209                         .add(soul1[2].multiply(z.soul3[3])).subtract(soul1[3].multiply(z.soul3[0]))
210                                 .add(soul2[0].multiply(z.soul2[2])).subtract(soul2[1].multiply(z.soul2[3]))
211                                 .add(soul2[2].multiply(z.soul2[0])).subtract(soul2[3].multiply(z.soul2[1]))
212                                 .subtract(soul2[4].multiply(z.soul2[5])).subtract(soul2[5].multiply(z.soul2[4]))
213                         .add(soul3[0].multiply(z.soul1[3])).subtract(soul3[3].multiply(z.soul1[2]))
214                         .add(soul3[2].multiply(z.soul1[1])).subtract(soul3[1].multiply(z.soul1[0]))
215                         .add(soul4.multiply(z.body));
216                 for(int i=0;i<N;i++)
217                         ans.soul1[i]=body.multiply(z.soul1[i]).add(soul1[i].multiply(z.body));
218                 ans.soul2[0]=(body.multiply(z.soul2[0]))
219                         .add(soul1[0].multiply(z.soul1[1])).subtract(soul1[1].multiply(z.soul1[0]))
220                         .add(soul2[0].multiply(z.body));
221                 ans.soul2[1]=(body.multiply(z.soul2[1]))
222                         .add(soul1[1].multiply(z.soul1[2])).subtract(soul1[2].multiply(z.soul1[1]))
223                         .add(soul2[1].multiply(z.body));
224                 ans.soul2[2]=(body.multiply(z.soul2[2]))
225                         .add(soul1[2].multiply(z.soul1[3])).subtract(soul1[3].multiply(z.soul1[2]))
226                         .add(soul2[2].multiply(z.body));
227                 ans.soul2[3]=(body.multiply(z.soul2[3]))
228                         .add(soul1[3].multiply(z.soul1[0])).subtract(soul1[0].multiply(z.soul1[3]))
229                         .add(soul2[3].multiply(z.body));
230                 ans.soul2[4]=(body.multiply(z.soul2[4]))
231                         .add(soul1[0].multiply(z.soul1[2])).subtract(soul1[2].multiply(z.soul1[0]))
232                         .add(soul2[4].multiply(z.body));
233                 ans.soul2[5]=(body.multiply(z.soul2[5]))
234                         .add(soul1[1].multiply(z.soul1[3])).subtract(soul1[3].multiply(z.soul1[1]))
235                         .add(soul2[5].multiply(z.body));
236                 ans.soul3[0]=(body.multiply(z.soul3[0]))
237                         .add(soul1[0].multiply(z.soul2[1])).subtract(soul1[1].multiply(z.soul2[4]))
238                         .add(soul1[2].multiply(z.soul2[0])).add(soul2[0].multiply(z.soul1[2]))
239                         .subtract(soul2[4].multiply(z.soul1[1])).add(soul2[1].multiply(z.soul1[0]))
240                         .add(soul3[0].multiply(z.body));
241                 ans.soul3[1]=(body.multiply(z.soul3[1]))
242                         .add(soul1[1].multiply(z.soul2[2])).subtract(soul1[2].multiply(z.soul2[5]))
243                         .add(soul1[3].multiply(z.soul2[1])).add(soul2[1].multiply(z.soul1[3]))
244                         .subtract(soul2[5].multiply(z.soul1[2])).add(soul2[2].multiply(z.soul1[1]))
245                         .add(soul3[1].multiply(z.body));
246                 ans.soul3[2]=(body.multiply(z.soul3[2]))
247                         .add(soul1[2].multiply(z.soul2[3])).add(soul1[3].multiply(z.soul2[4]))
248                         .add(soul1[0].multiply(z.soul2[2])).add(soul2[2].multiply(z.soul1[0]))
249                         .add(soul2[4].multiply(z.soul1[3])).add(soul2[3].multiply(z.soul1[2]))
250                         .add(soul3[2].multiply(z.body));
251                 ans.soul3[3]=(body.multiply(z.soul3[3]))
252                         .add(soul1[3].multiply(z.soul2[0])).add(soul1[0].multiply(z.soul2[5]))
253                         .add(soul1[1].multiply(z.soul2[3])).add(soul2[3].multiply(z.soul1[1]))
254                         .add(soul2[5].multiply(z.soul1[0])).add(soul2[0].multiply(z.soul1[3]))
255                         .add(soul3[3].multiply(z.body));
256                 return ans;
257         }
258 }
259
260
Popular Tags