1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.analysis.differentiation;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.util.FastMath;
21 import org.hipparchus.util.FieldSinCos;
22 import org.hipparchus.util.FieldSinhCosh;
23
24
25
26
27
28
29
30
31
32
33 public interface FieldDerivative1<S extends CalculusFieldElement<S>, T extends FieldDerivative<S, T>>
34 extends FieldDerivative<S, T> {
35
36
37 @Override
38 default int getOrder() {
39 return 1;
40 }
41
42
43
44
45
46
47 T compose(S f0, S f1);
48
49
50 @Override
51 default T square() {
52 final S f0 = getValue();
53 return compose(f0.square(), f0.multiply(2));
54 }
55
56
57 @Override
58 default T reciprocal() {
59 final S inv1 = getValue().reciprocal();
60 final S inv2 = inv1.square().negate();
61 return compose(inv1, inv2);
62 }
63
64
65 @Override
66 default T exp() {
67 final S exp = getValue().exp();
68 return compose(exp, exp);
69 }
70
71
72 @Override
73 default T sqrt() {
74 final S s = getValue().sqrt();
75 return compose(s, s.add(s).reciprocal());
76 }
77
78
79 @Override
80 default T cbrt() {
81 final S c = getValue().cbrt();
82 return compose(c, c.square().multiply(3).reciprocal());
83 }
84
85
86 @Override
87 default T expm1() {
88 final S exp = FastMath.exp(getValue());
89 final S expM1 = FastMath.expm1(getValue());
90 return compose(expM1, exp);
91 }
92
93
94 @Override
95 default T log() {
96 return compose(getValue().log(), getValue().reciprocal());
97 }
98
99
100 @Override
101 default T log1p() {
102 return compose(getValue().log1p(), getValue().add(1).reciprocal());
103 }
104
105
106 @Override
107 default T log10() {
108 return compose(getValue().log10(), getValue().multiply(FastMath.log(10.0)).reciprocal());
109 }
110
111
112 @Override
113 default T cos() {
114 final FieldSinCos<S> sinCos = getValue().sinCos();
115 return compose(sinCos.cos(), sinCos.sin().negate());
116 }
117
118
119 @Override
120 default T sin() {
121 final FieldSinCos<S> sinCos = getValue().sinCos();
122 return compose(sinCos.sin(), sinCos.cos());
123 }
124
125
126 @Override
127 default FieldSinCos<T> sinCos() {
128 final FieldSinCos<S> sinCos = getValue().sinCos();
129 return new FieldSinCos<>(compose(sinCos.sin(), sinCos.cos()),
130 compose(sinCos.cos(), sinCos.sin().negate()));
131 }
132
133
134 @Override
135 default T tan() {
136 final S tan = getValue().tan();
137 return compose(tan, tan.multiply(tan).add(1));
138 }
139
140
141 @Override
142 default T acos() {
143 return compose(getValue().acos(), getValue().square().negate().add(1).sqrt().reciprocal().negate());
144 }
145
146
147 @Override
148 default T asin() {
149 return compose(getValue().asin(), getValue().square().negate().add(1).sqrt().reciprocal());
150 }
151
152
153 @Override
154 default T atan() {
155 return compose(getValue().atan(), getValue().square().add(1).reciprocal());
156 }
157
158
159 @Override
160 default T cosh() {
161 final FieldSinhCosh<S> sinhCosh = getValue().sinhCosh();
162 return compose(sinhCosh.cosh(), sinhCosh.sinh());
163 }
164
165
166 @Override
167 default T sinh() {
168 final FieldSinhCosh<S> sinhCosh = getValue().sinhCosh();
169 return compose(sinhCosh.sinh(), sinhCosh.cosh());
170 }
171
172
173 @Override
174 default FieldSinhCosh<T> sinhCosh() {
175 final FieldSinhCosh<S> sinhCosh = getValue().sinhCosh();
176 return new FieldSinhCosh<>(compose(sinhCosh.sinh(), sinhCosh.cosh()),
177 compose(sinhCosh.cosh(), sinhCosh.sinh()));
178 }
179
180
181 @Override
182 default T tanh() {
183 final S tanh = getValue().tanh();
184 return compose(tanh, tanh.multiply(tanh).negate().add(1));
185 }
186
187
188 @Override
189 default T acosh() {
190 return compose(getValue().acosh(), getValue().square().subtract(1).sqrt().reciprocal());
191 }
192
193
194 @Override
195 default T asinh() {
196 return compose(getValue().asinh(), getValue().square().add(1).sqrt().reciprocal());
197 }
198
199
200 @Override
201 default T atanh() {
202 return compose(getValue().atanh(), getValue().square().negate().add(1).reciprocal());
203 }
204
205 }