Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CladDerivator.h
Go to the documentation of this file.
1/// \file CladDerivator.h
2///
3/// \brief The file is a bridge between ROOT and clad automatic differentiation
4/// plugin.
5///
6/// \author Vassil Vassilev <vvasilev@cern.ch>
7///
8/// \date July, 2018
9
10/*************************************************************************
11 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
12 * All rights reserved. *
13 * *
14 * For the licensing terms see $ROOTSYS/LICENSE. *
15 * For the list of contributors see $ROOTSYS/README/CREDITS. *
16 *************************************************************************/
17
18#ifndef CLAD_DERIVATOR
19#define CLAD_DERIVATOR
20
21#ifndef __CLING__
22 #error "This file must not be included by compiled programs."
23#endif //__CLING__
24
25#include <plugins/include/clad/Differentiator/Differentiator.h>
26#include "TMath.h"
27
29 template <typename T>
30 T Abs_darg0(T d) {
31 return (d < 0) ? -1 : 1;
32 }
33
34 template <typename T>
36 return 0;
37 }
38
39 template <typename T>
41 return -1./TMath::Sqrt(1 - d * d);
42 }
43
44 template <typename T>
46 return - d / (TMath::Sqrt(1 - d * d) * (1 - d * d));
47 }
48
49 template <typename T>
51 return 1. / TMath::Sqrt(d * d - 1);
52 }
53
54 template <typename T>
56 return - d / (TMath::Sqrt(d * d - 1) * (d * d - 1) * TMath::Sqrt(d * d + 1) * (d * d + 1));
57 }
58
59 template <typename T>
61 return 1. / TMath::Sqrt(1 - d * d);
62 }
63
64 template <typename T>
66 return d / (TMath::Sqrt(1 - d * d) * (1 - d * d));
67 }
68
69 template <typename T>
71 return 1. / TMath::Sqrt(d * d + 1);
72 }
73
74 template <typename T>
76 return -d / (TMath::Sqrt(d * d + 1) * (d * d + 1));
77 }
78
79 template <typename T>
81 return 1. / (d * d + 1);
82 }
83
84 template <typename T>
86 return -2. * d / ((d * d + 1) * (d * d + 1));
87 }
88
89 template <typename T>
91 return 1. / (1 - d * d);
92 }
93
94 template <typename T>
96 return 2. * d / ((1 - d * d) * (1 - d * d));
97 }
98
99 template <typename T>
101 return -TMath::Sin(d);
102 }
103
104 template <typename T>
106 return -TMath::Cos(d);
107 }
108
109 template <typename T>
111 return TMath::SinH(d);
112 }
113
114
115 template <typename T>
117 return TMath::CosH(d);
118 }
119
120 template <typename T>
122 return 2 * TMath::Exp(-d * d) / TMath::Sqrt(TMath::Pi());
123 }
124
125 template <typename T>
127 return -4 * TMath::Exp(-d * d) * d / TMath::Sqrt(TMath::Pi());
128 }
129
130 template <typename T>
132 return -Erf_darg0(d);
133 }
134
135 template <typename T>
137 return -Erf_darg0_darg0(d);
138 }
139
140 template <typename T>
142 return TMath::Exp(d);
143 }
144
145 template <typename T>
147 return TMath::Exp(d);
148 }
149
150 template <typename T>
151 T Hypot_darg0(T x, T y) {
152 return x / TMath::Hypot(x, y);
153 }
154
155 template <typename T>
157 return y * y / (TMath::Hypot(x, y) * (x * x + y * y));
158 }
159
160 template <typename T>
162 return x * y / (TMath::Hypot(x, y) * (x * x + y * y));
163 }
164
165 template <typename T>
166 T Hypot_darg1(T x, T y) {
167 return y / TMath::Hypot(x, y);
168 }
169
170 template <typename T>
172 return x * y / (TMath::Hypot(x, y) * (x * x + y * y));
173 }
174
175 template <typename T>
177 return x * x / (TMath::Hypot(x, y) * (x * x + y * y));
178 }
179
180 template <typename T>
181 void Hypot_grad(T x, T y, T* result) {
182 T h = TMath::Hypot(x, y);
183 result[0] += x / h;
184 result[1] += y / h;
185 }
186
187 template <typename T>
188 void Hypot_darg0_grad(T x, T y, T* result) {
189 T h = y / (TMath::Hypot(x, y) * (x * x + y * y));
190 result[0] += y * h;
191 result[1] += x * h;
192 }
193
194 template <typename T>
195 void Hypot_darg1_grad(T x, T y, T* result) {
196 T h = x / (TMath::Hypot(x, y) * (x * x + y * y));
197 result[0] += y * h;
198 result[1] += x * h;
199 }
200
201 template <typename T>
203 return 1. / d;
204 }
205
206 template <typename T>
208 return -1. / (d * d);
209 }
210
211 template <typename T>
213 return Log_darg0(d) / TMath::Ln10();
214 }
215
216 template <typename T>
218 return Log_darg0_darg0(d) / TMath::Ln10();
219 }
220
221 template <typename T>
223 return Log_darg0(d) / TMath::Log(2);
224 }
225
226 template <typename T>
228 return Log_darg0_darg0(d) / TMath::Log(2);
229 }
230
231 template <typename T>
232 T Max_darg0(T a, T b) {
233 return (a >= b) ? 1 : 0;
234 }
235
236 template <typename T>
238 return 0;
239 }
240
241 template <typename T>
243 return 0;
244 }
245
246 template <typename T>
247 T Max_darg1(T a, T b) {
248 return (a >= b) ? 0 : 1;
249 }
250
251 template <typename T>
253 return 0;
254 }
255
256 template <typename T>
258 return 0;
259 }
260
261 template <typename T>
262 void Max_grad(T a, T b, T* result) {
263 if (a >= b)
264 result[0] += 1;
265 else
266 result[1] += 1;
267 }
268
269 template <typename T>
270 void Max_darg0_grad(T a, T b, T* result) {
271 return;
272 }
273
274 template <typename T>
275 void Max_darg1_grad(T a, T b, T* result) {
276 return;
277 }
278
279 template <typename T>
280 T Min_darg0(T a, T b) {
281 return (a <= b) ? 1 : 0;
282 }
283
284 template <typename T>
286 return 0;
287 }
288
289 template <typename T>
291 return 0;
292 }
293
294 template <typename T>
295 T Min_darg1(T a, T b) {
296 return (a <= b) ? 0 : 1;
297 }
298
299 template <typename T>
301 return 0;
302 }
303
304 template <typename T>
306 return 0;
307 }
308
309 template <typename T>
310 void Min_grad(T a, T b, T* result) {
311 if (a <= b)
312 result[0] += 1;
313 else
314 result[1] += 1;
315 }
316
317 template <typename T>
318 void Min_darg0_grad(T a, T b, T* result) {
319 return;
320 }
321
322 template <typename T>
323 void Min_darg1_grad(T a, T b, T* result) {
324 return;
325 }
326
327 template <typename T>
328 T Power_darg0(T x, T y) {
329 return y * TMath::Power(x, y - 1);
330 }
331
332 template <typename T>
334 return y * (y - 1) * TMath::Power(x, y - 2);
335 }
336
337 template <typename T>
339 return TMath::Power(x, y - 1) * (y * TMath::Log(x) + 1);
340 }
341
342 template <typename T>
344 return TMath::Power(x, y) * TMath::Log(x);
345 }
346
347 template <typename T>
349 return TMath::Power(x, y - 1) * (y * TMath::Log(x) + 1);
350 }
351
352 template <typename T>
354 return TMath::Power(x, y) * TMath::Sq(TMath::Log(x));
355 }
356
357 template <typename T>
358 Double_t Power_grad(T x, T y, Double_t* result) {
359 T t = TMath::Power(x, y - 1);
360 result[0] += y * t;
361 result[1] += x * t * TMath::Log(x);
362 }
363
364 template <typename T>
366 T t = TMath::Power(x, y - 2);
367 result[0] += y * (y - 1) * t;
368 result[1] += x * t * (y * TMath::Log(x) + 1);
369 }
370
371 template <typename T>
373 T t = TMath::Power(x, y - 1);
374 result[0] += t * (y * TMath::Log(x) + 1);
375 result[1] += x * t * TMath::Sq(TMath::Log(x));
376 }
377
378 template <typename T>
380 return TMath::Cos(d);
381 }
382
383 template <typename T>
385 return -TMath::Sin(d);
386 }
387
388 template <typename T>
390 return TMath::CosH(d);
391 }
392
393 template <typename T>
395 return TMath::SinH(d);
396 }
397
398 template <typename T>
399 T Sq_darg0(T d) {
400 return 2 * d;
401 }
402
403 template <typename T>
405 return 2;
406 }
407
408 template <typename T>
410 return 0.5 / TMath::Sqrt(d);
411 }
412
413 template <typename T>
415 return 0.25 / (TMath::Sqrt(d) * d);
416 }
417
418 template <typename T>
420 return 1./ TMath::Sq(TMath::Cos(d));
421 }
422
423 template <typename T>
425 return 2. * TMath::Sin(d) / (TMath::Cos(d) * TMath::Cos(d) * TMath::Cos(d));
426 }
427
428 template <typename T>
430 return 1./ TMath::Sq(TMath::CosH(d));
431 }
432
433 template <typename T>
435 return -2. * TMath::SinH(d) / (TMath::CosH(d) * TMath::CosH(d) * TMath::CosH(d));
436 }
437}
438#endif // CLAD_DERIVATOR
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
double Double_t
Definition RtypesCore.h:59
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t CosH(Double_t)
Definition TMath.h:605
Double_t Exp(Double_t x)
Definition TMath.h:677
Double_t Log(Double_t x)
Definition TMath.h:710
Double_t Sq(Double_t x)
Definition TMath.h:637
Double_t Sqrt(Double_t x)
Definition TMath.h:641
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition TMath.h:685
constexpr Double_t Ln10()
Natural log of 10 (to convert log to ln)
Definition TMath.h:103
Double_t Hypot(Double_t x, Double_t y)
Definition TMath.cxx:57
Double_t Cos(Double_t)
Definition TMath.h:593
constexpr Double_t Pi()
Definition TMath.h:37
Double_t Sin(Double_t)
Definition TMath.h:589
Double_t SinH(Double_t)
Definition TMath.h:601
T Max_darg1_darg1(T a, T b)
Double_t Power_darg0_grad(T x, T y, Double_t *result)
Double_t Erfc_darg0_darg0(T d)
Double_t ATan_darg0(T d)
Double_t ASinH_darg0_darg0(T d)
Double_t ATan_darg0_darg0(T d)
Double_t Sqrt_darg0_darg0(T d)
Double_t Erfc_darg0(T d)
T Min_darg0(T a, T b)
Double_t ACosH_darg0(T d)
void Hypot_darg0_grad(T x, T y, T *result)
Double_t Log10_darg0(T d)
T Power_darg0_darg0(T x, T y)
Double_t Sqrt_darg0(T d)
void Min_grad(T a, T b, T *result)
T Power_darg0(T x, T y)
T Min_darg1_darg0(T a, T b)
Double_t Power_grad(T x, T y, Double_t *result)
T Min_darg0_darg0(T a, T b)
Double_t Log_darg0_darg0(T d)
T Hypot_darg0_darg1(T x, T y)
Double_t Log_darg0(T d)
Double_t Tan_darg0_darg0(T d)
Double_t SinH_darg0(T d)
Double_t TanH_darg0_darg0(T d)
T Hypot_darg0_darg0(T x, T y)
T Max_darg1_darg0(T a, T b)
Double_t Erf_darg0(T d)
void Hypot_grad(T x, T y, T *result)
T Max_darg0_darg1(T a, T b)
T Hypot_darg1(T x, T y)
void Max_darg1_grad(T a, T b, T *result)
Double_t ACosH_darg0_darg0(T d)
Double_t ATanH_darg0_darg0(T d)
void Min_darg1_grad(T a, T b, T *result)
Double_t Tan_darg0(T d)
Double_t Exp_darg0(T d)
Double_t Erf_darg0_darg0(T d)
Double_t Log2_darg0_darg0(T d)
Double_t Power_darg1_darg0(T x, T y)
void Max_grad(T a, T b, T *result)
Double_t Power_darg1_darg1(T x, T y)
Double_t Exp_darg0_darg0(T d)
void Max_darg0_grad(T a, T b, T *result)
Double_t ACos_darg0(T d)
Double_t ASinH_darg0(T d)
Double_t Log10_darg0_darg0(T d)
Double_t Log2_darg0(T d)
Double_t ACos_darg0_darg0(T d)
T Hypot_darg1_darg0(T x, T y)
T Max_darg0(T a, T b)
Double_t SinH_darg0_darg0(T d)
T Min_darg1(T a, T b)
Double_t Power_darg1_grad(T x, T y, Double_t *result)
Double_t Power_darg0_darg1(T x, T y)
Double_t ASin_darg0(T d)
Double_t ATanH_darg0(T d)
Double_t ASin_darg0_darg0(T d)
void Min_darg0_grad(T a, T b, T *result)
T Min_darg1_darg1(T a, T b)
Double_t Sin_darg0_darg0(T d)
T Min_darg0_darg1(T a, T b)
T Hypot_darg1_darg1(T x, T y)
T Max_darg0_darg0(T a, T b)
Double_t Power_darg1(T x, T y)
Double_t TanH_darg0(T d)
T Max_darg1(T a, T b)
Double_t Sin_darg0(T d)
void Hypot_darg1_grad(T x, T y, T *result)
T Hypot_darg0(T x, T y)