-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexBinaryFunctions.pde
More file actions
77 lines (70 loc) · 2.25 KB
/
Copy pathComplexBinaryFunctions.pde
File metadata and controls
77 lines (70 loc) · 2.25 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
abstract class ComplexBinaryFunction implements ComplexFunction{
Complex defaultW;
ComplexBinaryFunction(){defaultW = new Complex(1,0);}
ComplexBinaryFunction(Complex _W){
defaultW = _W;
}
Complex f(Complex z){return f(z,defaultW);}
String menuName(){return name();}
abstract Complex f(Complex z,Complex w);
}
class C2Sum extends ComplexBinaryFunction{
C2Sum(){super();}
String name(){return "z + w";}
Complex f(Complex z, Complex w){return z.add(w);}
}
class C2Difference extends ComplexBinaryFunction{
C2Difference(){super();}
String name(){return "z - w";}
Complex f(Complex z, Complex w){return z.sub(w);}
}
class C2Product extends ComplexBinaryFunction{
C2Product(){super();}
String name(){return "zw";}
Complex f(Complex z, Complex w){return z.mult(w);}
}
class C2Quotient extends ComplexBinaryFunction{
C2Quotient(){super();}
String name(){return "z/w";}
Complex f(Complex z, Complex w){return z.divBy(w);}
}
class C2Power extends ComplexBinaryFunction{
C2Power(){super();}
String name(){return "z^w";}
Complex f(Complex z, Complex w){return z.raiseBy(w);}
}
class C2Root extends ComplexBinaryFunction{
C2Root(){super();}
String name(){return "z^(1/w)";}
Complex f(Complex z, Complex w){return z.root(w);}
}
class C2HermitianInnerProduct extends ComplexBinaryFunction{
C2HermitianInnerProduct(){super();}
String name(){return "<[1+i,1-i]|[z,w]>";}
Complex f(Complex z, Complex w){
return z.mult(new Complex(1,-1)).add(w.mult(new Complex(1,1)));
}
}
class C2Binomial extends ComplexBinaryFunction{
final int accuracy = 30;
ComplexFunction rGamma;
C2Binomial(){
rGamma = new CReciprocalGamma(accuracy);
}
String name(){return "Binomial: z choose w";}
Complex f(Complex z, Complex w){
final Complex gammaN = rGamma.f(z.add(1)).reciprocal();
final Complex gammaD1 = rGamma.f(w.add(1));
final Complex gammaD2 = rGamma.f(z.sub(w).add(1));
return gammaN.mult(gammaD1).mult(gammaD2);
}
}
class C2Chebyshev extends ComplexBinaryFunction{
C2Chebyshev(){super();}
String name(){return "Max(|z|,|w|)exp( i(arg(w) - arg(z)) )";}
Complex f(Complex z, Complex w){
double size = Math.max( z.mag(), w.mag() );
double phase = w.arg() - z.arg();
return fromPolar(size,phase);
}
}