View Javadoc
1   /*
2    * Licensed to the Hipparchus project under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The Hipparchus project licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.hipparchus.analysis.differentiation;
18  
19  import org.hipparchus.Field;
20  import org.hipparchus.CalculusFieldElement;
21  import org.hipparchus.CalculusFieldElementAbstractTest;
22  import org.hipparchus.analysis.FieldUnivariateFunction;
23  import org.hipparchus.exception.LocalizedCoreFormats;
24  import org.hipparchus.exception.MathIllegalArgumentException;
25  import org.hipparchus.util.FastMath;
26  import org.hipparchus.util.FieldSinCos;
27  import org.hipparchus.util.MathArrays;
28  import org.junit.Assert;
29  import org.junit.Test;
30  
31  /**
32   * Test for class {@link FieldUnivariateDerivative2}.
33   */
34  public abstract class FieldUnivariateDerivative2AbstractTest<T extends CalculusFieldElement<T>>
35      extends CalculusFieldElementAbstractTest<FieldUnivariateDerivative2<T>> {
36  
37      protected abstract Field<T> getValueField();
38  
39      protected FieldUnivariateDerivative2<T> build(double value) {
40          final Field<T> valueField = getValueField();
41          return new FieldUnivariateDerivative2<>(valueField.getZero().newInstance(value),
42                                                  valueField.getOne(),
43                                                  valueField.getZero());
44      }
45  
46      protected T buildScalar(double value) {
47          return getValueField().getZero().newInstance(value);
48      }
49  
50      private int getMaxOrder() {
51          return 2;
52      }
53  
54      protected FieldUnivariateDerivative2<T> build(final double f0, final double f1, final double f2) {
55          T prototype = build(0.0).getValue();
56          return new FieldUnivariateDerivative2<>(prototype.newInstance(f0),
57                                                  prototype.newInstance(f1),
58                                                  prototype.newInstance(f2));
59      }
60  
61      @Test
62      public void testFieldAdd() {
63          check(build(1.0, 1.0, 1.0).add(buildScalar(5.0)), 6.0, 1.0, 1.0);
64      }
65  
66      @Test
67      public void testFieldSubtract() {
68          check(build(1.0, 1.0, 1.0).subtract(buildScalar(5.0)), -4.0, 1.0, 1.0);
69      }
70  
71      @Test
72      public void testFieldMultiply() {
73          check(build(1.0, 1.0, 1.0).multiply(buildScalar(5.0)), 5.0, 5.0, 5.0);
74      }
75  
76      @Test
77      public void testFieldDivide() {
78          check(build(1.0, 1.0, 1.0).divide(buildScalar(5.0)), 0.2, 0.2, 0.2);
79      }
80  
81      @Test
82      public void testOrder() {
83          Assert.assertEquals(getMaxOrder(), build(0).getOrder());
84      }
85  
86      @Test
87      public void testNewInstance() {
88          FieldUnivariateDerivative2<T> ud = build(5.25);
89          Assert.assertEquals(5.25, ud.getValue().getReal(), 1.0e-15);
90          Assert.assertEquals(1.0,  ud.getDerivative(1).getReal(), 1.0e-15);
91          FieldUnivariateDerivative2<T> newInstance = ud.newInstance(7.5);
92          Assert.assertEquals(7.5, newInstance.getValue().getReal(), 1.0e-15);
93          Assert.assertEquals(0.0, newInstance.getDerivative(1).getReal(), 1.0e-15);
94      }
95  
96      @Test
97      public void testGetPartialDerivative() {
98          try {
99              build(3.0).getPartialDerivative(0, 1);
100             Assert.fail("an exception should have been thrown");
101         } catch( MathIllegalArgumentException miae) {
102             Assert.assertEquals(LocalizedCoreFormats.DIMENSIONS_MISMATCH, miae.getSpecifier());
103             Assert.assertEquals(2, ((Integer) miae.getParts()[0]).intValue());
104             Assert.assertEquals(1, ((Integer) miae.getParts()[1]).intValue());
105         }
106     }
107 
108     @Test
109     public void testGetDerivative() {
110         FieldUnivariateDerivative2<T> x  = build(3.0);
111         FieldUnivariateDerivative2<T> ud = x.square();
112         try {
113             ud.getDerivative(-1);
114             Assert.fail("an exception should have been thrown");
115         } catch (MathIllegalArgumentException miae) {
116             Assert.assertEquals(LocalizedCoreFormats.DERIVATION_ORDER_NOT_ALLOWED, miae.getSpecifier());
117         }
118         Assert.assertEquals(9.0, ud.getValue().getReal(), 1.0e-15);
119         Assert.assertEquals(9.0, ud.getDerivative(0).getReal(), 1.0e-15);
120         Assert.assertEquals(6.0, ud.getDerivative(1).getReal(), 1.0e-15);
121         for (int n = 2; n <= getMaxOrder(); ++n) {
122             Assert.assertEquals(n == 2 ? 2.0 : 0.0, ud.getDerivative(n).getReal(), 1.0e-15);
123         }
124         try {
125             ud.getDerivative(getMaxOrder() + 1);
126             Assert.fail("an exception should have been thrown");
127         } catch (MathIllegalArgumentException miae) {
128             Assert.assertEquals(LocalizedCoreFormats.DERIVATION_ORDER_NOT_ALLOWED, miae.getSpecifier());
129         }
130     }
131 
132     @Test
133     public void testGetFreeParameters() {
134         Assert.assertEquals(1, build(3.0).getFreeParameters());
135     }
136 
137     protected void checkAgainstDS(final double x, final FieldUnivariateFunction f) {
138         final FieldUnivariateDerivative2<T> xUD = build(x);
139         final FieldUnivariateDerivative2<T> yUD = f.value(xUD);
140         final FieldDerivativeStructure<T> yDS = f.value(xUD.toDerivativeStructure());
141         for (int i = 0; i <= yUD.getOrder(); ++i) {
142             Assert.assertEquals(yDS.getPartialDerivative(i).getReal(),
143                                 yUD.getDerivative(i).getReal(),
144                                 4.0e-14* FastMath.abs(yDS.getPartialDerivative(i).getReal()));
145         }
146     }
147 
148     @Test
149     public void testArithmeticVsDS() {
150         for (double x = -1.25; x < 1.25; x+= 0.5) {
151             checkAgainstDS(x,
152                            new FieldUnivariateFunction() {
153                                public <S extends CalculusFieldElement<S>> S value(S x) {
154                                    final S y = x.add(3).multiply(x).subtract(5).multiply(0.5);
155                                    return y.negate().divide(4).divide(x).add(y).subtract(x).multiply(2).reciprocal();
156                                }
157                            });
158         }
159     }
160 
161     @Test
162     public void testCopySignField() {
163 
164         FieldUnivariateDerivative2<T> minusOne = build(-1.0);
165         Assert.assertEquals(+1.0, minusOne.copySign(buildScalar(+1.0)).getReal(), 1.0e-15);
166         Assert.assertEquals(-1.0, minusOne.copySign(buildScalar(-1.0)).getReal(), 1.0e-15);
167         Assert.assertEquals(+1.0, minusOne.copySign(buildScalar(+0.0)).getReal(), 1.0e-15);
168         Assert.assertEquals(-1.0, minusOne.copySign(buildScalar(-0.0)).getReal(), 1.0e-15);
169         Assert.assertEquals(+1.0, minusOne.copySign(buildScalar(Double.NaN)).getReal(), 1.0e-15);
170 
171         FieldUnivariateDerivative2<T> plusOne = build(1.0);
172         Assert.assertEquals(+1.0, plusOne.copySign(buildScalar(+1.0)).getReal(), 1.0e-15);
173         Assert.assertEquals(-1.0, plusOne.copySign(buildScalar(-1.0)).getReal(), 1.0e-15);
174         Assert.assertEquals(+1.0, plusOne.copySign(buildScalar(+0.0)).getReal(), 1.0e-15);
175         Assert.assertEquals(-1.0, plusOne.copySign(buildScalar(-0.0)).getReal(), 1.0e-15);
176         Assert.assertEquals(+1.0, plusOne.copySign(buildScalar(Double.NaN)).getReal(), 1.0e-15);
177 
178     }
179 
180     @Test
181     public void testRemainderField() {
182         double epsilon = 2.0e-15;
183         for (double x = -1.7; x < 2; x += 0.2) {
184             FieldUnivariateDerivative2<T> dsX = build(x);
185             for (double y = -1.7; y < 2; y += 0.2) {
186                 FieldUnivariateDerivative2<T> remainder = dsX.remainder(buildScalar(y));
187                 FieldUnivariateDerivative2<T> ref = dsX.subtract(x - FastMath.IEEEremainder(x, y));
188                 FieldUnivariateDerivative2<T> zero = remainder.subtract(ref);
189                 Assert.assertEquals(0, zero.getFirstDerivative().getReal(), epsilon);
190                 Assert.assertEquals(0, zero.getSecondDerivative().getReal(), epsilon);
191             }
192         }
193     }
194 
195     @Test
196     public void testRemainderDoubleVsDS() {
197         for (double x = -1.25; x < 1.25; x+= 0.5) {
198             checkAgainstDS(x,
199                            new FieldUnivariateFunction() {
200                                public <S extends CalculusFieldElement<S>> S value(S x) {
201                                    return x.remainder(0.5);
202                                }
203                            });
204         }
205     }
206 
207     @Test
208     public void testRemainderUdVsDS() {
209         for (double x = -1.25; x < 1.25; x+= 0.5) {
210             checkAgainstDS(x,
211                            new FieldUnivariateFunction() {
212                               public <S extends CalculusFieldElement<S>> S value(S x) {
213                                   return x.remainder(x.divide(0.7));
214                               }
215                            });
216         }
217     }
218 
219     @Test
220     public void testAbsVsDS() {
221         for (double x = -1.25; x < 1.25; x+= 0.5) {
222             checkAgainstDS(x,
223                            new FieldUnivariateFunction() {
224                                public <S extends CalculusFieldElement<S>> S value(S x) {
225                                    return x.abs();
226                                }
227                            });
228         }
229     }
230 
231     @Test
232     public void testScalbVsDS() {
233         for (int n = -4; n < 4; ++n) {
234             final int theN = n;
235             for (double x = -1.25; x < 1.25; x+= 0.5) {
236                 checkAgainstDS(x,
237                                new FieldUnivariateFunction() {
238                                    public <S extends CalculusFieldElement<S>> S value(S x) {
239                                        return x.scalb(theN);
240                                    }
241                                });
242             }
243         }
244     }
245 
246     @Test
247     public void testUlpVsDS() {
248         for (double x = -1.25; x < 1.25; x+= 0.0001) {
249             checkAgainstDS(x,
250                            new FieldUnivariateFunction() {
251                                public <S extends CalculusFieldElement<S>> S value(S x) {
252                                    return x.ulp();
253                                }
254                            });
255         }
256     }
257 
258     @Test
259     public void testHypotVsDS() {
260         for (double x = -3.25; x < 3.25; x+= 0.5) {
261             checkAgainstDS(x,
262                            new FieldUnivariateFunction() {
263                                public <S extends CalculusFieldElement<S>> S value(S x) {
264                                    return x.cos().multiply(5).hypot(x.sin().multiply(2));
265                                }
266                            });
267         }
268     }
269 
270     @Test
271     public void testAtan2VsDS() {
272         for (double x = -3.25; x < 3.25; x+= 0.5) {
273             checkAgainstDS(x,
274                            new FieldUnivariateFunction() {
275                                public <S extends CalculusFieldElement<S>> S value(S x) {
276                                    return x.cos().multiply(5).atan2(x.sin().multiply(2));
277                                }
278                            });
279         }
280     }
281 
282     @Test
283     public void testPowersVsDS() {
284         for (double x = -3.25; x < 3.25; x+= 0.5) {
285             checkAgainstDS(x,
286                            new FieldUnivariateFunction() {
287                                public <S extends CalculusFieldElement<S>> S value(S x) {
288                                    final FieldSinCos<S> sc = x.sinCos();
289                                    return x.pow(3.2).add(x.pow(2)).subtract(sc.cos().abs().pow(sc.sin()));
290                                }
291                            });
292         }
293     }
294 
295     @Test
296     public void testSqrtVsDS() {
297         for (double x = 0.001; x < 3.25; x+= 0.5) {
298             checkAgainstDS(x,
299                     new FieldUnivariateFunction() {
300                         public <S extends CalculusFieldElement<S>> S value(S x) {
301                             return x.sqrt();
302                         }
303                     });
304         }
305     }
306 
307     @Test
308     public void testCbrtVsDS() {
309         for (double x = 0.001; x < 3.25; x+= 0.5) {
310             checkAgainstDS(x,
311                     new FieldUnivariateFunction() {
312                         public <S extends CalculusFieldElement<S>> S value(S x) {
313                             return x.cbrt();
314                         }
315                     });
316         }
317     }
318 
319     @Test
320     public void testRootsVsDS() {
321         for (double x = 0.001; x < 3.25; x+= 0.5) {
322             checkAgainstDS(x,
323                            new FieldUnivariateFunction() {
324                                public <S extends CalculusFieldElement<S>> S value(S x) {
325                                    return x.rootN(5);//x.sqrt().add(x.cbrt()).subtract(x.rootN(5));
326                                }
327                            });
328         }
329     }
330 
331     @Test
332     public void testExpsLogsVsDS() {
333         for (double x = 2.5; x < 3.25; x+= 0.125) {
334             checkAgainstDS(x,
335                            new FieldUnivariateFunction() {
336                                public <S extends CalculusFieldElement<S>> S value(S x) {
337                                    return x.exp().add(x.multiply(0.5).expm1()).log().log10().log1p();
338                                }
339                            });
340         }
341     }
342 
343     @Test
344     public void testTrigonometryVsDS() {
345         for (double x = -3.25; x < 3.25; x+= 0.5) {
346             checkAgainstDS(x,
347                            new FieldUnivariateFunction() {
348                                public <S extends CalculusFieldElement<S>> S value(S x) {
349                                    return x.cos().multiply(x.sin()).atan().divide(12).asin().multiply(0.1).acos().tan();
350                                }
351                            });
352         }
353     }
354 
355     @Test
356     public void testHyperbolicVsDS() {
357         for (double x = -1.25; x < 1.25; x+= 0.5) {
358             checkAgainstDS(x,
359                            new FieldUnivariateFunction() {
360                                public <S extends CalculusFieldElement<S>> S value(S x) {
361                                    return x.cosh().multiply(x.sinh()).multiply(12).abs().acosh().asinh().divide(7).tanh().multiply(0.1).atanh();
362                                }
363                            });
364         }
365     }
366 
367     @Test
368     public void testConvertersVsDS() {
369         for (double x = -1.25; x < 1.25; x+= 0.5) {
370             checkAgainstDS(x,
371                            new FieldUnivariateFunction() {
372                                public <S extends CalculusFieldElement<S>> S value(S x) {
373                                    return x.multiply(5).toDegrees().subtract(x).toRadians();
374                                }
375                            });
376         }
377     }
378 
379     @Test
380     public void testLinearCombination2D2FVsDS() {
381         for (double x = -1.25; x < 1.25; x+= 0.5) {
382             checkAgainstDS(x,
383                            new FieldUnivariateFunction() {
384                                public <S extends CalculusFieldElement<S>> S value(S x) {
385                                    return x.linearCombination(1.0, x.multiply(0.9),
386                                                               2.0, x.multiply(0.8));
387                                }
388                            });
389         }
390     }
391 
392     @Test
393     public void testLinearCombination2F2FVsDS() {
394         for (double x = -1.25; x < 1.25; x+= 0.5) {
395             checkAgainstDS(x,
396                            new FieldUnivariateFunction() {
397                                public <S extends CalculusFieldElement<S>> S value(S x) {
398                                    return x.linearCombination(x.add(1), x.multiply(0.9),
399                                                               x.add(2), x.multiply(0.8));
400                                }
401                            });
402         }
403     }
404 
405     @Test
406     public void testLinearCombination3D3FVsDS() {
407         for (double x = -1.25; x < 1.25; x+= 0.5) {
408             checkAgainstDS(x,
409                            new FieldUnivariateFunction() {
410                                public <S extends CalculusFieldElement<S>> S value(S x) {
411                                    return x.linearCombination(1.0, x.multiply(0.9),
412                                                               2.0, x.multiply(0.8),
413                                                               3.0, x.multiply(0.7));
414                                }
415                            });
416         }
417     }
418 
419     @Test
420     public void testLinearCombination3F3FVsDS() {
421         for (double x = -1.25; x < 1.25; x+= 0.5) {
422             checkAgainstDS(x,
423                            new FieldUnivariateFunction() {
424                                public <S extends CalculusFieldElement<S>> S value(S x) {
425                                    return x.linearCombination(x.add(1), x.multiply(0.9),
426                                                               x.add(2), x.multiply(0.8),
427                                                               x.add(3), x.multiply(0.7));
428                                }
429                            });
430         }
431     }
432 
433     @Test
434     public void testLinearCombination4D4FVsDS() {
435         for (double x = -1.25; x < 1.25; x+= 0.5) {
436             checkAgainstDS(x,
437                            new FieldUnivariateFunction() {
438                                public <S extends CalculusFieldElement<S>> S value(S x) {
439                                    return x.linearCombination(1.0, x.multiply(0.9),
440                                                               2.0, x.multiply(0.8),
441                                                               3.0, x.multiply(0.7),
442                                                               4.0, x.multiply(0.6));
443                                }
444                            });
445         }
446     }
447 
448     @Test
449     public void testLinearCombination4F4FVsDS() {
450         for (double x = -1.25; x < 1.25; x+= 0.5) {
451             checkAgainstDS(x,
452                            new FieldUnivariateFunction() {
453                                public <S extends CalculusFieldElement<S>> S value(S x) {
454                                    return x.linearCombination(x.add(1), x.multiply(0.9),
455                                                               x.add(2), x.multiply(0.8),
456                                                               x.add(3), x.multiply(0.7),
457                                                               x.add(4), x.multiply(0.6));
458                                }
459                            });
460         }
461     }
462 
463     @Test
464     public void testLinearCombinationnDnFVsDS() {
465         for (double x = -1.25; x < 1.25; x+= 0.5) {
466             checkAgainstDS(x,
467                            new FieldUnivariateFunction() {
468                                public <S extends CalculusFieldElement<S>> S value(S x) {
469                                    final S[] b = MathArrays.buildArray(x.getField(), 4);
470                                    b[0] = x.add(0.9);
471                                    b[1] = x.add(0.8);
472                                    b[2] = x.add(0.7);
473                                    b[3] = x.add(0.6);
474                                    return x.linearCombination(new double[] { 1, 2, 3, 4 }, b);
475                                }
476                            });
477         }
478     }
479 
480     @Test
481     public void testLinearCombinationnFnFVsDS() {
482         for (double x = -1.25; x < 1.25; x+= 0.5) {
483             checkAgainstDS(x,
484                            new FieldUnivariateFunction() {
485                                public <S extends CalculusFieldElement<S>> S value(S x) {
486                                    final S[] a = MathArrays.buildArray(x.getField(), 4);
487                                    a[0] = x.add(1);
488                                    a[1] = x.add(2);
489                                    a[2] = x.add(3);
490                                    a[3] = x.add(4);
491                                    final S[] b = MathArrays.buildArray(x.getField(), 4);
492                                    b[0] = x.add(0.9);
493                                    b[1] = x.add(0.8);
494                                    b[2] = x.add(0.7);
495                                    b[3] = x.add(0.6);
496                                    return x.linearCombination(a, b);
497                                }
498                            });
499         }
500     }
501 
502     @Test
503     public void testLinearCombinationField() {
504         final T[] a = MathArrays.buildArray(getValueField(), 3);
505         a[0] = buildScalar(-1321008684645961.0 / 268435456.0);
506         a[1] = buildScalar(-5774608829631843.0 / 268435456.0);
507         a[2] = buildScalar(-7645843051051357.0 / 8589934592.0);
508         final FieldUnivariateDerivative2<T>[] b = MathArrays.buildArray(FieldUnivariateDerivative2Field.getUnivariateDerivative2Field(getValueField()), 3);
509         b[0] = build(-5712344449280879.0 / 2097152.0);
510         b[1] = build(-4550117129121957.0 / 2097152.0);
511         b[2] = build(8846951984510141.0 / 131072.0);
512 
513         final FieldUnivariateDerivative2<T> abSumInline = b[0].linearCombination(a[0], b[0],
514                                                                                  a[1], b[1],
515                                                                                  a[2], b[2]);
516         final FieldUnivariateDerivative2<T> abSumArray = b[0].linearCombination(a, b);
517         Assert.assertEquals(abSumInline.getReal(), abSumArray.getReal(), 3.0e-8);
518         Assert.assertEquals(-1.8551294182586248737720779899, abSumInline.getReal(), 5.0e-8);
519         Assert.assertEquals(abSumInline.getFirstDerivative().getReal(), abSumArray.getFirstDerivative().getReal(), 3.0e-8);
520         Assert.assertEquals(abSumInline.getSecondDerivative().getReal(), abSumArray.getSecondDerivative().getReal(), 3.0e-8);
521     }
522 
523     @Test
524     public void testGetFirstAndSecondDerivative() {
525         FieldUnivariateDerivative2<T> ud2 = build(-0.5, 2.5, 4.5);
526         Assert.assertEquals(-0.5, ud2.getReal(), 1.0e-15);
527         Assert.assertEquals(-0.5, ud2.getValue().getReal(), 1.0e-15);
528         Assert.assertEquals(+2.5, ud2.getFirstDerivative().getReal(), 1.0e-15);
529         Assert.assertEquals(+4.5, ud2.getSecondDerivative().getReal(), 1.0e-15);
530     }
531 
532     @Test
533     public void testConversion() {
534         FieldUnivariateDerivative2<T> udA = build(-0.5, 2.5, 4.5);
535         FieldDerivativeStructure<T> ds = udA.toDerivativeStructure();
536         Assert.assertEquals(1, ds.getFreeParameters());
537         Assert.assertEquals(2, ds.getOrder());
538         Assert.assertEquals(-0.5, ds.getValue().getReal(), 1.0e-15);
539         Assert.assertEquals(-0.5, ds.getPartialDerivative(0).getReal(), 1.0e-15);
540         Assert.assertEquals( 2.5, ds.getPartialDerivative(1).getReal(), 1.0e-15);
541         Assert.assertEquals( 4.5, ds.getPartialDerivative(2).getReal(), 1.0e-15);
542         FieldUnivariateDerivative2<T> udB = new FieldUnivariateDerivative2<>(ds);
543         Assert.assertNotSame(udA, udB);
544         Assert.assertEquals(udA, udB);
545         try {
546             new FieldUnivariateDerivative2<>(new FDSFactory<>(getValueField(), 2, 2).variable(0, 1.0));
547             Assert.fail("an exception should have been thrown");
548         } catch (MathIllegalArgumentException miae) {
549             Assert.assertEquals(LocalizedCoreFormats.DIMENSIONS_MISMATCH, miae.getSpecifier());
550         }
551         try {
552             new FieldUnivariateDerivative2<>(new FDSFactory<>(getValueField(), 1, 1).variable(0, 1.0));
553             Assert.fail("an exception should have been thrown");
554         } catch (MathIllegalArgumentException miae) {
555             Assert.assertEquals(LocalizedCoreFormats.DIMENSIONS_MISMATCH, miae.getSpecifier());
556         }
557     }
558 
559     @Test
560     public void testDoublePow() {
561         Assert.assertSame(build(3).getField().getZero(), FieldUnivariateDerivative2.pow(0.0, build(1.5)));
562         FieldUnivariateDerivative2<T> ud = FieldUnivariateDerivative2.pow(2.0, build(1.5));
563         DSFactory factory = new DSFactory(1, 2);
564         DerivativeStructure ds = factory.constant(2.0).pow(factory.variable(0, 1.5));
565         Assert.assertEquals(ds.getValue(), ud.getValue().getReal(), 1.0e-15);
566         Assert.assertEquals(ds.getPartialDerivative(1), ud.getFirstDerivative().getReal(), 1.0e-15);
567         Assert.assertEquals(ds.getPartialDerivative(2), ud.getSecondDerivative().getReal(), 1.0e-15);
568     }
569 
570     @Test
571     public void testTaylor() {
572         Assert.assertEquals(-0.125, build(1, -3, 4).taylor(0.75).getReal(), 1.0e-15);
573         Assert.assertEquals(-0.125, build(1, -3, 4).taylor(getValueField().getZero().newInstance(0.75)).getReal(), 1.0e-15);
574     }
575 
576     @Test
577     public void testHashcode() {
578         Assert.assertEquals(-1025507011, build(2, 1, -1).hashCode());
579     }
580 
581     @Test
582     public void testEquals() {
583         FieldUnivariateDerivative2<T> ud2 = build(12, -34, 56);
584         Assert.assertEquals(ud2, ud2);
585         Assert.assertNotEquals(ud2, "");
586         Assert.assertEquals(ud2, build(12, -34, 56));
587         Assert.assertNotEquals(ud2, build(21, -34, 56));
588         Assert.assertNotEquals(ud2, build(12, -43, 56));
589         Assert.assertNotEquals(ud2, build(12, -34, 65));
590         Assert.assertNotEquals(ud2, build(21, -43, 65));
591     }
592 
593     @Test
594     public void testRunTimeClass() {
595         Field<FieldUnivariateDerivative2<T>> field = build(0.0).getField();
596         Assert.assertEquals(FieldUnivariateDerivative2.class, field.getRuntimeClass());
597     }
598 
599     private void check(FieldUnivariateDerivative2<T> ud2, double value,
600                        double derivative1, double derivative2) {
601 
602         // check value
603         Assert.assertEquals(value, ud2.getReal(), 1.0e-15);
604 
605         // check derivatives
606         Assert.assertEquals(derivative1, ud2.getFirstDerivative().getReal(), 1.0e-15);
607         Assert.assertEquals(derivative2, ud2.getSecondDerivative().getReal(), 1.0e-15);
608 
609     }
610 
611 }