1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.special.elliptic.carlson;
18
19 import org.hipparchus.util.FastMath;
20 import org.hipparchus.util.MathArrays;
21
22
23
24
25 class RfRealDuplication extends RealDuplication {
26
27
28 static final int AGM_MAX = 32;
29
30
31 static final double CONSTANT = 240240;
32
33
34 static final double E2 = -24024;
35
36
37 static final double E3 = 17160;
38
39
40 static final double E2_E2 = 10010;
41
42
43 static final double E2_E3 = -16380;
44
45
46 static final double E3_E3 = 6930;
47
48
49 static final double E2_E2_E2 = -5775;
50
51
52 static final double DENOMINATOR = 240240;
53
54
55
56
57
58
59 RfRealDuplication(final double x, final double y, final double z) {
60 super(x, y, z);
61 }
62
63
64 @Override
65 protected void initialMeanPoint(final double[] va) {
66 va[3] = (va[0] + va[1] + va[2]) / 3.0;
67 }
68
69
70 @Override
71 protected double convergenceCriterion(final double r, final double max) {
72 return max / FastMath.sqrt(FastMath.sqrt(FastMath.sqrt(r * 3.0)));
73 }
74
75
76 @Override
77 protected void update(final int m, final double[] vaM, final double[] sqrtM, final double fourM) {
78
79
80 final double lambdaA = sqrtM[0] * sqrtM[1];
81 final double lambdaB = sqrtM[0] * sqrtM[2];
82 final double lambdaC = sqrtM[1] * sqrtM[2];
83
84
85 vaM[0] = MathArrays.linearCombination(0.25, vaM[0], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
86 vaM[1] = MathArrays.linearCombination(0.25, vaM[1], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
87 vaM[2] = MathArrays.linearCombination(0.25, vaM[2], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
88 vaM[3] = MathArrays.linearCombination(0.25, vaM[3], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
89
90 }
91
92
93 @Override
94 protected double evaluate(final double[] va0, final double aM, final double fourM) {
95
96
97 final double inv = 1.0 / (aM * fourM);
98 final double bigX = (va0[3] - va0[0]) * inv;
99 final double bigY = (va0[3] - va0[1]) * inv;
100 final double bigZ = -(bigX + bigY);
101
102
103 final double e2 = bigX * bigY - bigZ * bigZ;
104 final double e3 = bigX * bigY * bigZ;
105
106 final double e2e2 = e2 * e2;
107 final double e2e3 = e2 * e3;
108 final double e3e3 = e3 * e3;
109 final double e2e2e2 = e2e2 * e2;
110
111
112
113 final double poly = (e2e2e2 * E2_E2_E2 +
114 e3e3 * E3_E3 +
115 e2e3 * E2_E3 +
116 e2e2 * E2_E2 +
117 e3 * E3 +
118 e2 * E2 +
119 CONSTANT) /
120 DENOMINATOR;
121 return poly / FastMath.sqrt(aM);
122
123 }
124
125
126 @Override
127 public double integral() {
128 final double x = getVi(0);
129 final double y = getVi(1);
130 final double z = getVi(2);
131 if (x == 0) {
132 return completeIntegral(y, z);
133 } else if (y == 0) {
134 return completeIntegral(x, z);
135 } else if (z == 0) {
136 return completeIntegral(x, y);
137 } else {
138 return super.integral();
139 }
140 }
141
142
143
144
145
146
147 private double completeIntegral(final double x, final double y) {
148
149 double xM = FastMath.sqrt(x);
150 double yM = FastMath.sqrt(y);
151
152
153 for (int i = 1; i < AGM_MAX; ++i) {
154
155 final double xM1 = xM;
156 final double yM1 = yM;
157
158
159 xM = (xM1 + yM1) * 0.5;
160
161
162 yM = FastMath.sqrt(xM1 * yM1);
163
164
165 if (FastMath.abs(xM - yM) <= 4 * FastMath.ulp(xM)) {
166
167 break;
168 }
169
170 }
171
172 return FastMath.PI / (xM + yM);
173
174 }
175
176 }