-
Notifications
You must be signed in to change notification settings - Fork 0
/
avd.f90
1888 lines (1599 loc) · 55.3 KB
/
avd.f90
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! Created by on 28/02/2020.
! Compile with default real set to 8 bytes (-r8 on ifort)
module AVD
integer, parameter, private :: sin_f = 1
integer, parameter, private :: cos_f = 2
integer, parameter, private :: tan_f = 3
integer, parameter, private :: sinh_f = 4
integer, parameter, private :: cosh_f = 5
integer, parameter, private :: tanh_f = 6
integer, parameter, private :: asin_f = 7
integer, parameter, private :: acos_f = 8
integer, parameter, private :: atan_f = 9
integer, parameter, private :: exp_f = 10
integer, parameter, private :: log_f = 11
integer, parameter, private :: log10_f = 12
integer, parameter, private :: sqrt_f = 13
abstract interface
pure function gen(x) result(r)
real(8) :: r
real(8), intent(in) :: x
end function gen
end interface
type f_map_t
procedure(gen), nopass, pointer :: f_ptr => null()
end type f_map_t
type(f_map_t), target :: f_map(0:4,13)
type :: avd_b
real(8) :: v
contains
end type avd_b
type, extends(avd_b) :: avd_d1
real(8) :: d1 = 1
contains
procedure :: set_from_avd1
generic, public :: assignment(=) => set_from_avd1
procedure :: avd1_equals_avd1
generic, public :: operator(==) => avd1_equals_avd1
procedure, public :: as_string => as_string_d1
end type avd_d1
type, extends(avd_d1) :: avd_d2
real(8) :: d2 = 0
contains
procedure :: set_from_avd2
generic, public :: assignment(=) => set_from_avd2
procedure :: avd2_equals_avd2
generic, public :: operator(==) => avd2_equals_avd2
procedure, public :: as_string => as_string_d2
procedure, public :: print => print_avd_d2
end type avd_d2
type, extends(avd_d2) :: avd_d3
real(8) :: d3 = 0
contains
procedure :: avd3_equals_avd3
generic, public :: operator(==) => avd3_equals_avd3
procedure, public :: as_string => as_string_d3
end type avd_d3
type, extends(avd_d3) :: avd_d4
real(8) :: d4 = 0
contains
procedure :: avd4_equals_avd4
generic, public :: operator(==) => avd4_equals_avd4
procedure, public :: as_string => as_string_d4
end type avd_d4
interface assignment(=)
module procedure :: set_d1_from_d2, set_d2_from_d3, set_d3_from_d4, set_v
end interface
interface operator(**)
module procedure :: d0_pow_i, d0_pow_r
module procedure :: d1_pow_i, d1_pow_r
module procedure :: d2_pow_i, d2_pow_r
module procedure :: d3_pow_i, d3_pow_r
module procedure :: d4_pow_i, d4_pow_r
end interface
interface operator(+)
module procedure :: d0_plus_i, d0_plus_r, i_plus_d0, r_plus_d0, d0_plus_d0
module procedure :: d1_plus_i, d1_plus_r, i_plus_d1, r_plus_d1, d1_plus_d1
module procedure :: d2_plus_i, d2_plus_r, i_plus_d2, r_plus_d2, d2_plus_d2
module procedure :: d3_plus_i, d3_plus_r, i_plus_d3, r_plus_d3, d3_plus_d3
module procedure :: d4_plus_i, d4_plus_r, i_plus_d4, r_plus_d4, d4_plus_d4
end interface
interface operator(-)
module procedure :: minus_d0, minus_d1, minus_d2 , minus_d3, minus_d4
module procedure :: d0_minus_i, d0_minus_r, i_minus_d0, r_minus_d0, d0_minus_d0
module procedure :: d1_minus_i, d1_minus_r, i_minus_d1, r_minus_d1, d1_minus_d1
module procedure :: d2_minus_i, d2_minus_r, i_minus_d2, r_minus_d2, d2_minus_d2
module procedure :: d3_minus_i, d3_minus_r, i_minus_d3, r_minus_d3, d3_minus_d3
module procedure :: d4_minus_i, d4_minus_r, i_minus_d4, r_minus_d4, d4_minus_d4
end interface
interface operator(*)
module procedure :: d0_times_i, d0_times_r, i_times_d0, r_times_d0, d0_times_d0
module procedure :: d1_times_i, d1_times_r, i_times_d1, r_times_d1, d1_times_d1
module procedure :: d2_times_i, d2_times_r, i_times_d2, r_times_d2, d2_times_d2
module procedure :: d3_times_i, d3_times_r, i_times_d3, r_times_d3, d3_times_d3
module procedure :: d4_times_i, d4_times_r, i_times_d4, r_times_d4, d4_times_d4
end interface
interface operator( / )
module function d0_over_i(obj, a) result(r)
type(avd_b) :: r
type(avd_b), intent(in) :: obj
integer, intent(in) :: a
end function d0_over_i
module function d0_over_r(obj, a) result(r)
type(avd_b) :: r
type(avd_b), intent(in) :: obj
real(8), intent(in) :: a
end function d0_over_r
module function i_over_d0(a, obj) result(r)
type(avd_b) :: r
type(avd_b), intent(in) :: obj
integer, intent(in) :: a
end function i_over_d0
module function r_over_d0(a, obj) result(r)
type(avd_b) :: r
type(avd_b), intent(in) :: obj
real(8), intent(in) :: a
end function r_over_d0
module function d1_over_i(obj, a) result(r)
type(avd_d1) :: r
type(avd_d1), intent(in) :: obj
integer, intent(in) :: a
end function d1_over_i
module function d1_over_r(obj, a) result(r)
type(avd_d1) :: r
type(avd_d1), intent(in) :: obj
real(8), intent(in) :: a
end function d1_over_r
module function i_over_d1(a, obj) result(r)
type(avd_d1) :: r
type(avd_d1), intent(in) :: obj
integer, intent(in) :: a
end function i_over_d1
module function r_over_d1(a, obj) result(r)
type(avd_d1) :: r
type(avd_d1), intent(in) :: obj
real(8), intent(in) :: a
end function r_over_d1
module function d2_over_i(obj, a) result(r)
type(avd_d2) :: r
type(avd_d2), intent(in) :: obj
integer, intent(in) :: a
end function d2_over_i
module function d2_over_r(obj, a) result(r)
type(avd_d2) :: r
type(avd_d2), intent(in) :: obj
real(8), intent(in) :: a
end function d2_over_r
module function i_over_d2(a, obj) result(r)
type(avd_d2) :: r
type(avd_d2), intent(in) :: obj
integer, intent(in) :: a
end function i_over_d2
module function r_over_d2(a, obj) result(r)
type(avd_d2) :: r
type(avd_d2), intent(in) :: obj
real(8), intent(in) :: a
end function r_over_d2
module function d3_over_i(obj, a) result(r)
type(avd_d3) :: r
type(avd_d3), intent(in) :: obj
integer, intent(in) :: a
end function d3_over_i
module function d3_over_r(obj, a) result(r)
type(avd_d3) :: r
type(avd_d3), intent(in) :: obj
real(8), intent(in) :: a
end function d3_over_r
module function i_over_d3(a, obj) result(r)
type(avd_d3) :: r
type(avd_d3), intent(in) :: obj
integer, intent(in) :: a
end function i_over_d3
module function r_over_d3(a, obj) result(r)
type(avd_d3) :: r
type(avd_d3), intent(in) :: obj
real(8), intent(in) :: a
end function r_over_d3
module function d4_over_i(obj, a) result(r)
type(avd_d4) :: r
type(avd_d4), intent(in) :: obj
integer, intent(in) :: a
end function d4_over_i
module function d4_over_r(obj, a) result(r)
type(avd_d4) :: r
type(avd_d4), intent(in) :: obj
real(8), intent(in) :: a
end function d4_over_r
module function i_over_d4(a, obj) result(r)
type(avd_d4) :: r
type(avd_d4), intent(in) :: obj
integer, intent(in) :: a
end function i_over_d4
module function r_over_d4(a, obj) result(r)
type(avd_d4) :: r
type(avd_d4), intent(in) :: obj
real(8), intent(in) :: a
end function r_over_d4
module function d4_over_d4(a, b) result(r)
type(avd_d4) :: r
type(avd_d4), intent(in) :: a, b
end function d4_over_d4
end interface
interface sin
module procedure :: sin_d0, sin_d1, sin_d2, sin_d3, sin_d4
end interface
interface cos
module procedure :: cos_d0, cos_d1, cos_d2, cos_d3, cos_d4
end interface
interface sinh
module procedure :: sinh_d0, sinh_d1, sinh_d2, sinh_d3, sinh_d4
end interface
interface cosh
module procedure :: cosh_d0, cosh_d1, cosh_d2, cosh_d3, cosh_d4
end interface
interface tanh
module procedure :: tanh_d0, tanh_d1, tanh_d2, tanh_d3, tanh_d4
end interface
interface tan
module procedure :: tan_d0, tan_d1, tan_d2, tan_d3, tan_d4
end interface
interface sqrt
module procedure :: sqrt_d0, sqrt_d1, sqrt_d2, sqrt_d3, sqrt_d4
end interface
interface exp
module procedure :: exp_d0, exp_d1, exp_d2, exp_d3, exp_d4
end interface
interface log
module procedure :: log_d0, log_d1, log_d2, log_d3, log_d4
end interface
interface log10
module procedure :: log10_d0, log10_d1, log10_d2, log10_d3, log10_d4
end interface
contains
subroutine init
f_map(0,sin_f)%f_ptr => d0_sin
f_map(1,sin_f)%f_ptr => d1_sin
f_map(2,sin_f)%f_ptr => d2_sin
f_map(3,sin_f)%f_ptr => d3_sin
f_map(4,sin_f)%f_ptr => d4_sin
f_map(0,cos_f)%f_ptr => d0_cos
f_map(1,cos_f)%f_ptr => d1_cos
f_map(2,cos_f)%f_ptr => d2_cos
f_map(3,cos_f)%f_ptr => d3_cos
f_map(4,cos_f)%f_ptr => d4_cos
f_map(0,tan_f)%f_ptr => d0_tan
f_map(1,tan_f)%f_ptr => d1_tan
f_map(2,tan_f)%f_ptr => d2_tan
f_map(3,tan_f)%f_ptr => d3_tan
f_map(4,tan_f)%f_ptr => d4_tan
f_map(0,sinh_f)%f_ptr => d0_sinh
f_map(1,sinh_f)%f_ptr => d1_sinh
f_map(2,sinh_f)%f_ptr => d2_sinh
f_map(3,sinh_f)%f_ptr => d3_sinh
f_map(4,sinh_f)%f_ptr => d4_sinh
f_map(0,cosh_f)%f_ptr => d0_cosh
f_map(1,cosh_f)%f_ptr => d1_cosh
f_map(2,cosh_f)%f_ptr => d2_cosh
f_map(3,cosh_f)%f_ptr => d3_cosh
f_map(4,cosh_f)%f_ptr => d4_cosh
f_map(0,tanh_f)%f_ptr => d0_tanh
f_map(1,tanh_f)%f_ptr => d1_tanh
f_map(2,tanh_f)%f_ptr => d2_tanh
f_map(3,tanh_f)%f_ptr => d3_tanh
f_map(4,tanh_f)%f_ptr => d4_tanh
f_map(0,sqrt_f)%f_ptr => d0_sqrt
f_map(1,sqrt_f)%f_ptr => d1_sqrt
f_map(2,sqrt_f)%f_ptr => d2_sqrt
f_map(3,sqrt_f)%f_ptr => d3_sqrt
f_map(4,sqrt_f)%f_ptr => d4_sqrt
f_map(0,exp_f)%f_ptr => d0_exp
f_map(1,exp_f)%f_ptr => d1_exp
f_map(2,exp_f)%f_ptr => d2_exp
f_map(3,exp_f)%f_ptr => d3_exp
f_map(4,exp_f)%f_ptr => d4_exp
f_map(0,log_f)%f_ptr => d0_log
f_map(1,log_f)%f_ptr => d1_log
f_map(2,log_f)%f_ptr => d2_log
f_map(3,log_f)%f_ptr => d3_log
f_map(4,log_f)%f_ptr => d4_log
f_map(0,log10_f)%f_ptr => d0_log10
f_map(1,log10_f)%f_ptr => d1_log10
f_map(2,log10_f)%f_ptr => d2_log10
f_map(3,log10_f)%f_ptr => d3_log10
f_map(4,log10_f)%f_ptr => d4_log10
end subroutine init
pure function d0_times_d0(a, b) result(r)
type(avd_b) :: r
type(avd_b), intent(in) :: a, b
r%v = a%v * b%v
end function d0_times_d0
pure function d1_times_d1(a, b) result(r)
type(avd_d1) :: r
type(avd_d1), intent(in) :: a, b
r%avd_b = a%avd_b * b%avd_b
associate(u=>a%v, du=>a%d1, v=>b%v, dv=>b%d1)
r%d1 = u*dv + v*du
end associate
end function d1_times_d1
pure function d2_times_d2(a, b) result(r)
type(avd_d2) :: r
type(avd_d2), intent(in) :: a, b
r%avd_d1 = a%avd_d1 * b%avd_d1
associate(u=>a%v, du=>a%d1, d2u=>a%d2, v=>b%v, dv=>b%d1, d2v=>b%d2)
r%d2 = u*d2v + 2*du*dv + d2u*v
end associate
end function d2_times_d2
pure function d3_times_d3(a, b) result(r)
type(avd_d3) :: r
type(avd_d3), intent(in) :: a, b
r%avd_d2 = a%avd_d2 * b%avd_d2
associate(u=>a%v, du=>a%d1, d2u=>a%d2, d3u=>a%d3, v=>b%v, dv=>b%d1, d2v=>b%d2, d3v=>b%d3)
r%d3 = u*d3v + 3*du*d2v + 3*d2u*dv + d3u*v
end associate
end function d3_times_d3
pure function d4_times_d4(a, b) result(r)
type(avd_d4) :: r
type(avd_d4), intent(in) :: a, b
r%avd_d3 = a%avd_d3 * b%avd_d3
associate(u=>a%v, du=>a%d1, d2u=>a%d2, d3u=>a%d3, d4u=>a%d4, v=>b%v, dv=>b%d1, d2v=>b%d2, d3v=>b%d3, d4v=>b%d4)
r%d4 = u*d4v + 4*du*d3v + 6*d2u*d2v + 4*d3u*dv + d4u*v
end associate
end function d4_times_d4
pure function d0_sin(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sin(x)
end function d0_sin
pure function d1_sin(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = cos(x)
end function d1_sin
pure function d2_sin(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -sin(x)
end function d2_sin
pure function d3_sin(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -cos(x)
end function d3_sin
pure function d4_sin(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = d0_sin(x)
end function d4_sin
pure function d0_cos(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = cos(x)
end function d0_cos
pure function d1_cos(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -sin(x)
end function d1_cos
pure function d2_cos(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -cos(x)
end function d2_cos
pure function d3_cos(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sin(x)
end function d3_cos
pure function d4_cos(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = d0_cos(x)
end function d4_cos
pure function d0_sinh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sinh(x)
end function d0_sinh
pure function d1_sinh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = cosh(x)
end function d1_sinh
pure function d2_sinh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sinh(x)
end function d2_sinh
pure function d3_sinh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = cosh(x)
end function d3_sinh
pure function d4_sinh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sinh(x)
end function d4_sinh
pure function d0_cosh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = cosh(x)
end function d0_cosh
pure function d1_cosh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sinh(x)
end function d1_cosh
pure function d2_cosh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = cosh(x)
end function d2_cosh
pure function d3_cosh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sinh(x)
end function d3_cosh
pure function d4_cosh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = cosh(x)
end function d4_cosh
pure function d0_tanh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = tanh(x)
end function d0_tanh
pure function d1_tanh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = 1 - tanh(x)**2
end function d1_tanh
pure function d2_tanh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -2*d0_tanh(x)*d1_tanh(x)
end function d2_tanh
pure function d3_tanh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -2*(d1_tanh(x)**2 + d0_tanh(x)*d2_tanh(x))
end function d3_tanh
pure function d4_tanh(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -2*(3*d1_tanh(x)*d2_tanh(x) + d0_tanh(x)*d3_tanh(x))
end function d4_tanh
pure function d0_sqrt(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = sqrt(x)
end function d0_sqrt
pure function d1_sqrt(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = 0.5*x**(-0.5)
end function d1_sqrt
pure function d2_sqrt(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8), parameter :: c = (0.5)*(-0.5)
r = c*x**(-1.5)
end function d2_sqrt
pure function d3_sqrt(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8), parameter :: c = (0.5)*(-0.5)*(-1.5)
r = c*x**(-2.5)
end function d3_sqrt
pure function d4_sqrt(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8), parameter :: c = (0.5)*(-0.5)*(-1.5)*(-2.5)
r = c*x**(-3.5)
end function d4_sqrt
pure function d0_tan(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = tan(x)
end function d0_tan
pure function d1_tan(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8) :: y
y = tan(x)
r = 1 + y**2
end function d1_tan
pure function d2_tan(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8) :: y
y = tan(x)
r = 2*y*d1_tan(x)
end function d2_tan
pure function d3_tan(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8) :: y
y = tan(x)
r = 2*d1_tan(x)**2 + 2*y*d2_tan(x)
end function d3_tan
pure function d4_tan(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8) :: y
y = tan(x)
r = 4*d1_tan(x)*d2_tan(x) + 2*(d1_tan(x)*d2_tan(x)+y*d3_tan(x))
end function d4_tan
pure function d0_exp(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = exp(x)
end function d0_exp
pure function d1_exp(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = exp(x)
end function d1_exp
pure function d2_exp(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = exp(x)
end function d2_exp
pure function d3_exp(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = exp(x)
end function d3_exp
pure function d4_exp(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = exp(x)
end function d4_exp
pure function d0_log(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = log(x)
end function d0_log
pure function d1_log(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = 1/x
end function d1_log
pure function d2_log(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -1/x**2
end function d2_log
pure function d3_log(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = 2/x**3
end function d3_log
pure function d4_log(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = -6/x**4
end function d4_log
pure function d0_log10(x) result(r)
real(8) :: r
real(8), intent(in) :: x
r = log10(x)
end function d0_log10
pure function d1_log10(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8), parameter :: b = 1/log(10.0)
r = b/x
end function d1_log10
pure function d2_log10(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8), parameter :: b = 1/log(10.0)
r = -b/x**2
end function d2_log10
pure function d3_log10(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8), parameter :: b = 1/log(10.0)
r = 2*b/x**3
end function d3_log10
pure function d4_log10(x) result(r)
real(8) :: r
real(8), intent(in) :: x
real(8), parameter :: b = 1/log(10.0)
r = -6*b/x**4
end function d4_log10
pure function Q0_f(ft, av) result(r)
type(avd_b) :: r
integer, intent(in) :: ft
type(avd_b), intent(in) :: av
r%v = f_map(0,ft)%f_ptr(av%v)
end function Q0_f
pure function Q1_f(ft, av) result(r)
type(avd_d1) :: r
integer, intent(in) :: ft
type(avd_d1), intent(in) :: av
procedure(gen), pointer :: f1
r%avd_b = Q0_f(ft, avd_b(av%v))
f1 => f_map(1,ft)%f_ptr
associate(g1=>av%d1, x=>av%v)
r%d1 = f1(x)*av%d1
end associate
end function Q1_f
pure function Q2_f(ft, av) result(r)
type(avd_d2) :: r
integer, intent(in) :: ft
type(avd_d2), intent(in) :: av
procedure(gen), pointer :: f1, f2
r%avd_d1 = Q1_f(ft, avd_d1(av%v, av%d1))
f1 => f_map(1,ft)%f_ptr
f2 => f_map(2,ft)%f_ptr
associate(g1=>av%d1, g2=>av%d2, x=>av%v)
r%d2 = f2(x)*g1**2 + f1(x)*g2
end associate
end function Q2_f
pure function Q3_f(ft, av) result(r)
type(avd_d3) :: r
integer, intent(in) :: ft
type(avd_d3), intent(in) :: av
procedure(gen), pointer :: f1, f2, f3
r%avd_d2 = Q2_f(ft, avd_d2(av%v, av%d1, av%d2))
f1 => f_map(1,ft)%f_ptr
f2 => f_map(2,ft)%f_ptr
f3 => f_map(3,ft)%f_ptr
associate(g1=>av%d1, g2=>av%d2, g3=>av%d3, x=>av%v)
r%d3 = f3(x)*g1**3 + 3*g1*g2*f2(x) + f1(x)*g3
end associate
end function Q3_f
pure function Q4_f(ft, av) result(r)
type(avd_d4) :: r
integer, intent(in) :: ft
type(avd_d4), intent(in) :: av
procedure(gen), pointer :: f1, f2, f3, f4
r%avd_d3 = Q3_f(ft, avd_d3(av%v, av%d1, av%d2, av%d3))
f1 => f_map(1,ft)%f_ptr
f2 => f_map(2,ft)%f_ptr
f3 => f_map(3,ft)%f_ptr
f4 => f_map(4,ft)%f_ptr
associate(g1=>av%d1, g2=>av%d2, g3=>av%d3, g4=>av%d4, x=>av%v)
r%d4 = g4*f1(x) + 4*g3*g1*f2(x) + 3*g2**2*f2(x) + 6*g1**2*g2*f3(x) + g1**4*f4(x)
end associate
end function Q4_f
pure function sin_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r%v = sin(obj%v)
end function sin_d0
pure function sin_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) :: r
r = Q1_f(sin_f, obj)
end function sin_d1
pure function sin_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(sin_f,obj)
end function sin_d2
pure function sin_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(sin_f,obj)
end function sin_d3
pure function sin_d4(obj) result(r)
type(avd_d4), intent(in) :: obj
type(avd_d4) ::r
r = Q4_f(sin_f,obj)
end function sin_d4
pure function cos_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r%v = cos(obj%v)
end function cos_d0
pure function cos_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) ::r
r = Q1_f(cos_f,obj)
end function cos_d1
pure function cos_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(cos_f,obj)
end function cos_d2
pure function cos_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(cos_f,obj)
end function cos_d3
pure function cos_d4(obj) result(r)
type(avd_d4), intent(in) :: obj
type(avd_d4) ::r
r = Q4_f(cos_f,obj)
end function cos_d4
pure function tan_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r = tan(obj%v)
end function tan_d0
pure function tan_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) ::r
r = Q1_f(tan_f,obj)
end function tan_d1
pure function tan_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(tan_f,obj)
end function tan_d2
pure function tan_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(tan_f,obj)
end function tan_d3
pure function tan_d4(obj) result(r)
type(avd_d4), intent(in) :: obj
type(avd_d4) ::r
r = Q4_f(tan_f,obj)
end function tan_d4
pure function sqrt_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r%v = sqrt(obj%v)
end function sqrt_d0
pure function sqrt_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) ::r
r = Q1_f(sqrt_f,obj)
end function sqrt_d1
pure function sqrt_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(sqrt_f,obj)
end function sqrt_d2
pure function sqrt_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(sqrt_f,obj)
end function sqrt_d3
pure function sqrt_d4(obj) result(r)
type(avd_d4), intent(in) :: obj
type(avd_d4) ::r
r = Q4_f(sqrt_f,obj)
end function sqrt_d4
pure function sinh_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r%v = sinh(obj%v)
end function sinh_d0
pure function sinh_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) :: r
r = Q1_f(sinh_f, obj)
end function sinh_d1
pure function sinh_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(sinh_f,obj)
end function sinh_d2
pure function sinh_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(sinh_f,obj)
end function sinh_d3
pure function sinh_d4(obj) result(r)
type(avd_d4), intent(in) :: obj
type(avd_d4) ::r
r = Q4_f(sinh_f,obj)
end function sinh_d4
pure function cosh_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r%v = cosh(obj%v)
end function cosh_d0
pure function cosh_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) :: r
r = Q1_f(cosh_f, obj)
end function cosh_d1
pure function cosh_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(cosh_f,obj)
end function cosh_d2
pure function cosh_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(cosh_f,obj)
end function cosh_d3
pure function cosh_d4(obj) result(r)
type(avd_d4), intent(in) :: obj
type(avd_d4) ::r
r = Q4_f(cosh_f,obj)
end function cosh_d4
pure function tanh_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r%v = tanh(obj%v)
end function tanh_d0
pure function tanh_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) :: r
r = Q1_f(tanh_f, obj)
end function tanh_d1
pure function tanh_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(tanh_f,obj)
end function tanh_d2
pure function tanh_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(tanh_f,obj)
end function tanh_d3
pure function tanh_d4(obj) result(r)
type(avd_d4), intent(in) :: obj
type(avd_d4) ::r
r = Q4_f(tanh_f,obj)
end function tanh_d4
pure function exp_d0(obj) result(r)
type(avd_b), intent(in) :: obj
type(avd_b) ::r
r%v = exp(obj%v)
end function exp_d0
pure function exp_d1(obj) result(r)
type(avd_d1), intent(in) :: obj
type(avd_d1) ::r
r = Q1_f(exp_f,obj)
end function exp_d1
pure function exp_d2(obj) result(r)
type(avd_d2), intent(in) :: obj
type(avd_d2) ::r
r = Q2_f(exp_f,obj)
end function exp_d2
pure function exp_d3(obj) result(r)
type(avd_d3), intent(in) :: obj
type(avd_d3) ::r
r = Q3_f(exp_f,obj)