ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_mathLog1p::getLog1p Interface Reference

Generate and return the expression log(1 + x) robustly (without numerical underflow). More...

Detailed Description

Generate and return the expression log(1 + x) robustly (without numerical underflow).

Parameters
[in]x: The input scalar, or array of arbitrary rank, shape, and size, of either
  • type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  • type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
representing the x value whose log(1 + x) is to be returned.
Returns
log1p : The output scalar (or array) of the same type and kind (and shape) as the input x representing log(1 + x) without underflow.


Possible calling interfaces

use pm_mathLog1p, only: getLog1p, selection
log1p = getLog1p(x)
log1p = getLog1p(x, control)
Generate and return the expression log(1 + x) robustly (without numerical underflow).
This module contains procedures and generic interfaces for computing log(1 + x) more precisely for ti...
Warning
The condition x > -1. must hold.
The condition x < huge(x) must hold.
When the input arguments are of type complex, these conditions must hold for the real components of the numbers.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Remarks
The procedures under discussion are elemental.
See also
getLog1p
get1mexp
getLogAddExp
getLogSubExp
getLogSumExp


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, RKH
4 use pm_io, only: display_type
5 use pm_mathLog1p, only: getLog1p
7
8 implicit none
9
10 real :: x, log1p(2)
11 real(RKH) :: log1p_ref
12 real(RKH), allocatable :: inaccuracy(:)
13 real, parameter :: EPS = epsilon(0.)
14 type(display_type) :: disp
15
16 disp = display_type(file = "main.out.F90")
17
18 call disp%skip()
19 call disp%show("x = .9")
20 x = .9
21 call disp%show("log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison")
22 log1p_ref = log(1._RKH + real(x, RKH))
23 call disp%show("log1p_ref")
24 call disp%show( log1p_ref )
25 call disp%show("log1p = [log(1. + x), getLog1p(x)]")
26 log1p = [log(1. + x), getLog1p(x)]
27 call disp%show("log1p")
28 call disp%show( log1p )
29 call disp%show("inaccuracy = abs(log1p_ref - log1p)")
30 inaccuracy = abs(log1p_ref - log1p)
31 call disp%show("inaccuracy")
32 call disp%show( inaccuracy )
33 call disp%show("getRankDense(inaccuracy)")
34 call disp%show( getRankDense(inaccuracy) )
35 call disp%skip()
36
37 call disp%skip()
38 call disp%show("x = EPS")
39 x = EPS
40 call disp%show("x")
41 call disp%show( x )
42 call disp%show("log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison")
43 log1p_ref = log(1._RKH + real(x, RKH))
44 call disp%show("log1p_ref")
45 call disp%show( log1p_ref )
46 call disp%show("log1p = [log(1. + x), getLog1p(x)]")
47 log1p = [log(1. + x), getLog1p(x)]
48 call disp%show("log1p")
49 call disp%show( log1p )
50 call disp%show("inaccuracy = abs(log1p_ref - log1p)")
51 inaccuracy = abs(log1p_ref - log1p)
52 call disp%show("inaccuracy")
53 call disp%show( inaccuracy )
54 call disp%show("getRankDense(inaccuracy)")
55 call disp%show( getRankDense(inaccuracy) )
56 call disp%skip()
57
58 call disp%skip()
59 call disp%show("x = EPS/2")
60 x = EPS/2
61 call disp%show("x")
62 call disp%show( x )
63 call disp%show("log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison")
64 log1p_ref = log(1._RKH + real(x, RKH))
65 call disp%show("log1p_ref")
66 call disp%show( log1p_ref )
67 call disp%show("log1p = [log(1. + x), getLog1p(x)]")
68 log1p = [log(1. + x), getLog1p(x)]
69 call disp%show("log1p")
70 call disp%show( log1p )
71 call disp%show("inaccuracy = abs(log1p_ref - log1p)")
72 inaccuracy = abs(log1p_ref - log1p)
73 call disp%show("inaccuracy")
74 call disp%show( inaccuracy )
75 call disp%show("getRankDense(inaccuracy)")
76 call disp%show( getRankDense(inaccuracy) )
77 call disp%skip()
78
79 call disp%skip()
80 call disp%show("x = -EPS/2")
81 x = -EPS/2
82 call disp%show("x")
83 call disp%show( x )
84 call disp%show("log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison")
85 log1p_ref = log(1._RKH + real(x, RKH))
86 call disp%show("log1p_ref")
87 call disp%show( log1p_ref )
88 call disp%show("log1p = [log(1. + x), getLog1p(x)]")
89 log1p = [log(1. + x), getLog1p(x)]
90 call disp%show("log1p")
91 call disp%show( log1p )
92 call disp%show("inaccuracy = abs(log1p_ref - log1p)")
93 inaccuracy = abs(log1p_ref - log1p)
94 call disp%show("inaccuracy")
95 call disp%show( inaccuracy )
96 call disp%show("getRankDense(inaccuracy)")
97 call disp%show( getRankDense(inaccuracy) )
98 call disp%skip()
99
100 call disp%skip()
101 call disp%show("x = sqrt(tiny(x))")
102 x = sqrt(tiny(x))
103 call disp%show("x")
104 call disp%show( x )
105 call disp%show("log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison")
106 log1p_ref = log(1._RKH + real(x, RKH))
107 call disp%show("log1p_ref")
108 call disp%show( log1p_ref )
109 call disp%show("log1p = [log(1. + x), getLog1p(x)]")
110 log1p = [log(1. + x), getLog1p(x)]
111 call disp%show("log1p")
112 call disp%show( log1p )
113 call disp%show("inaccuracy = abs(log1p_ref - log1p)")
114 inaccuracy = abs(log1p_ref - log1p)
115 call disp%show("inaccuracy")
116 call disp%show( inaccuracy )
117 call disp%show("getRankDense(inaccuracy)")
118 call disp%show( getRankDense(inaccuracy) )
119 call disp%skip()
120
121 call disp%skip()
122 call disp%show("x = -sqrt(tiny(x))")
123 x = -sqrt(tiny(x))
124 call disp%show("x")
125 call disp%show( x )
126 call disp%show("log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison")
127 log1p_ref = log(1._RKH + real(x, RKH))
128 call disp%show("log1p_ref")
129 call disp%show( log1p_ref )
130 call disp%show("log1p = [log(1. + x), getLog1p(x)]")
131 log1p = [log(1. + x), getLog1p(x)]
132 call disp%show("log1p")
133 call disp%show( log1p )
134 call disp%show("inaccuracy = abs(log1p_ref - log1p)")
135 inaccuracy = abs(log1p_ref - log1p)
136 call disp%show("inaccuracy")
137 call disp%show( inaccuracy )
138 call disp%show("getRankDense(inaccuracy)")
139 call disp%show( getRankDense(inaccuracy) )
140 call disp%skip()
141
142 call disp%skip()
143 call disp%show("tiny(0._RKH)")
144 call disp%show( tiny(0._RKH) )
145 call disp%show("[log(1._RKH + tiny(0._RKH)), getLog1p(tiny(0._RKH))]")
146 call disp%show( [log(1._RKH + tiny(0._RKH)), getLog1p(tiny(0._RKH))] )
147 call disp%skip()
148
149 call disp%skip()
150 call disp%show("tiny(0._RKH)")
151 call disp%show( tiny(0._RKH) )
152 call disp%show("[log(1._RKH - tiny(0._RKH)), getLog1p(-tiny(0._RKH))]")
153 call disp%show( [log(1._RKH - tiny(0._RKH)), getLog1p(-tiny(0._RKH))] )
154 call disp%skip()
155
156end program example
Generate and return the Dense rank of the input scalar string or contiguous array of rank 1 in ascend...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains procedures and generic interfaces for obtaining various rankings of elements of ...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2x = .9
3log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison
4log1p_ref
5+0.641853873624048428757248807764032325
6log1p = [log(1. + x), getLog1p(x)]
7log1p
8+0.641853869, +0.641853869
9inaccuracy = abs(log1p_ref - log1p)
10inaccuracy
11+0.466271420024162380776403232463151234E-8, +0.466271420024162380776403232463151234E-8
12getRankDense(inaccuracy)
13+1, +1
14
15
16x = EPS
17x
18+0.119209290E-6
19log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison
20log1p_ref
21+0.119209282445354457087579157062530716E-6
22log1p = [log(1. + x), getLog1p(x)]
23log1p
24+0.119209282E-6, +0.119209282E-6
25inaccuracy = abs(log1p_ref - log1p)
26inaccuracy
27+0.564688581015773773391555126390782510E-21, +0.564688581015773773391555126390782510E-21
28getRankDense(inaccuracy)
29+1, +1
30
31
32x = EPS/2
33x
34+0.596046448E-7
35log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison
36log1p_ref
37+0.596046429990338561858253177370804989E-7
38log1p = [log(1. + x), getLog1p(x)]
39log1p
40+0.00000000, +0.596046448E-7
41inaccuracy = abs(log1p_ref - log1p)
42inaccuracy
43+0.596046429990338561858253177370804989E-7, +0.177635676881417468226291950107140174E-14
44getRankDense(inaccuracy)
45+2, +1
46
47
48x = -EPS/2
49x
50-0.596046448E-7
51log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison
52log1p_ref
53-0.596046465517475349863325579799436107E-7
54log1p = [log(1. + x), getLog1p(x)]
55log1p
56-0.596046448E-7, -0.596046448E-7
57inaccuracy = abs(log1p_ref - log1p)
58inaccuracy
59+0.177635690998633255797994361065338507E-14, +0.177635690998633255797994361065338507E-14
60getRankDense(inaccuracy)
61+1, +1
62
63
64x = sqrt(tiny(x))
65x
66+0.108420217E-18
67log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison
68log1p_ref
69+0.108420217248550443394867808332882734E-18
70log1p = [log(1. + x), getLog1p(x)]
71log1p
72+0.00000000, +0.108420217E-18
73inaccuracy = abs(log1p_ref - log1p)
74inaccuracy
75+0.108420217248550443394867808332882734E-18, +0.587747175411143753984368268611122839E-38
76getRankDense(inaccuracy)
77+2, +1
78
79
80x = -sqrt(tiny(x))
81x
82-0.108420217E-18
83log1p_ref = log(1._RKH + real(x, RKH)) ! reference high-precision value for comparison
84log1p_ref
85-0.108420217248550443406622751841105609E-18
86log1p = [log(1. + x), getLog1p(x)]
87log1p
88+0.00000000, -0.108420217E-18
89inaccuracy = abs(log1p_ref - log1p)
90inaccuracy
91+0.108420217248550443406622751841105609E-18, +0.587747175411143753984368268611122839E-38
92getRankDense(inaccuracy)
93+2, +1
94
95
96tiny(0._RKH)
97+0.336210314311209350626267781732175260E-4931
98[log(1._RKH + tiny(0._RKH)), getLog1p(tiny(0._RKH))]
99+0.00000000000000000000000000000000000, +0.336210314311209350626267781732175260E-4931
100
101
102tiny(0._RKH)
103+0.336210314311209350626267781732175260E-4931
104[log(1._RKH - tiny(0._RKH)), getLog1p(-tiny(0._RKH))]
105+0.00000000000000000000000000000000000, -0.336210314311209350626267781732175260E-4931
106
107
Test:
test_pm_mathLog1p


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Thursday 1:45 AM, August 22, 2019, Dallas, TX

Definition at line 136 of file pm_mathLog1p.F90.


The documentation for this interface was generated from the following file: