
(FPCore (x y) :precision binary64 (- 1 (log (- 1 (/ (- x y) (- 1 y))))))
double code(double x, double y) {
return 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))
end function
public static double code(double x, double y) {
return 1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))));
}
def code(x, y): return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
function code(x, y) return Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y))))) end
function tmp = code(x, y) tmp = 1.0 - log((1.0 - ((x - y) / (1.0 - y)))); end
code[x_, y_] := N[(1 - N[Log[N[(1 - N[(N[(x - y), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- 1 (log (- 1 (/ (- x y) (- 1 y))))))
double code(double x, double y) {
return 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))
end function
public static double code(double x, double y) {
return 1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))));
}
def code(x, y): return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
function code(x, y) return Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y))))) end
function tmp = code(x, y) tmp = 1.0 - log((1.0 - ((x - y) / (1.0 - y)))); end
code[x_, y_] := N[(1 - N[Log[N[(1 - N[(N[(x - y), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
(FPCore (x y) :precision binary64 (if (<= (- 1 (log (- 1 (/ (- x y) (- 1 y))))) 15) (- 1 (log (/ (- (- y x) (- y 1)) (- 1 y)))) (- 1 (log (/ (- x 1) y)))))
double code(double x, double y) {
double tmp;
if ((1.0 - log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0) {
tmp = 1.0 - log((((y - x) - (y - 1.0)) / (1.0 - y)));
} else {
tmp = 1.0 - log(((x - 1.0) / y));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((1.0d0 - log((1.0d0 - ((x - y) / (1.0d0 - y))))) <= 15.0d0) then
tmp = 1.0d0 - log((((y - x) - (y - 1.0d0)) / (1.0d0 - y)))
else
tmp = 1.0d0 - log(((x - 1.0d0) / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0) {
tmp = 1.0 - Math.log((((y - x) - (y - 1.0)) / (1.0 - y)));
} else {
tmp = 1.0 - Math.log(((x - 1.0) / y));
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0: tmp = 1.0 - math.log((((y - x) - (y - 1.0)) / (1.0 - y))) else: tmp = 1.0 - math.log(((x - 1.0) / y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y))))) <= 15.0) tmp = Float64(1.0 - log(Float64(Float64(Float64(y - x) - Float64(y - 1.0)) / Float64(1.0 - y)))); else tmp = Float64(1.0 - log(Float64(Float64(x - 1.0) / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((1.0 - log((1.0 - ((x - y) / (1.0 - y))))) <= 15.0) tmp = 1.0 - log((((y - x) - (y - 1.0)) / (1.0 - y))); else tmp = 1.0 - log(((x - 1.0) / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(1 - N[Log[N[(1 - N[(N[(x - y), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 15], N[(1 - N[Log[N[(N[(N[(y - x), $MachinePrecision] - N[(y - 1), $MachinePrecision]), $MachinePrecision] / N[(1 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1 - N[Log[N[(N[(x - 1), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 15:\\
\;\;\;\;1 - \log \left(\frac{\left(y - x\right) - \left(y - 1\right)}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{x - 1}{y}\right)\\
\end{array}
if (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) < 15Initial program 71.8%
lift--.f64N/A
lift-/.f64N/A
sub-to-fractionN/A
frac-2negN/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
sub-negate-revN/A
frac-2neg-revN/A
*-lft-identityN/A
sub-negate-revN/A
*-lft-identityN/A
*-lft-identityN/A
sub-flip-reverseN/A
distribute-neg-inN/A
remove-double-negN/A
*-lft-identityN/A
add-flip-revN/A
sub-negate-revN/A
Applied rewrites72.1%
if 15 < (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) Initial program 71.8%
Taylor expanded in y around -inf
lower-*.f64N/A
lower-/.f64N/A
lower--.f6441.2%
Applied rewrites41.2%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6441.2%
Applied rewrites41.2%
(FPCore (x y) :precision binary64 (if (<= (- 1 (log (- 1 (/ (- x y) (- 1 y))))) 15) (- 1 (30-log1z0 (/ (- y x) (- y 1)))) (- 1 (log (/ (- x 1) y)))))
\begin{array}{l}
\mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 15:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{x - 1}{y}\right)\\
\end{array}
if (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) < 15Initial program 71.8%
lift-log.f64N/A
lift--.f64N/A
lower-30-log1z070.9%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6470.9%
Applied rewrites70.9%
if 15 < (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) Initial program 71.8%
Taylor expanded in y around -inf
lower-*.f64N/A
lower-/.f64N/A
lower--.f6441.2%
Applied rewrites41.2%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6441.2%
Applied rewrites41.2%
(FPCore (x y) :precision binary64 (if (<= (- 1 (log (- 1 (/ (- x y) (- 1 y))))) 30) (- 1 (30-log1z0 (/ (- y x) (- y 1)))) (- 1 (log (/ -1 y)))))
\begin{array}{l}
\mathbf{if}\;1 - \log \left(1 - \frac{x - y}{1 - y}\right) \leq 30:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\
\end{array}
if (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) < 30Initial program 71.8%
lift-log.f64N/A
lift--.f64N/A
lower-30-log1z070.9%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6470.9%
Applied rewrites70.9%
if 30 < (-.f64 #s(literal 1 binary64) (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y))))) Initial program 71.8%
Taylor expanded in y around -inf
lower-*.f64N/A
lower-/.f64N/A
lower--.f6441.2%
Applied rewrites41.2%
Taylor expanded in x around 0
lower-/.f6422.7%
Applied rewrites22.7%
(FPCore (x y) :precision binary64 (if (<= (log (- 1 (/ (- x y) (- 1 y)))) (- INFINITY)) (- 1 (30-log1z0 (/ x (- 1 y)))) (- 1 (30-log1z0 (/ (- y x) (- y 1))))))
\begin{array}{l}
\mathbf{if}\;\log \left(1 - \frac{x - y}{1 - y}\right) \leq -\infty:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \mathsf{30\_log1z0}\left(\left(\frac{y - x}{y - 1}\right)\right)\\
\end{array}
if (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)))) < -inf.0Initial program 71.8%
Taylor expanded in x around inf
lower-/.f64N/A
lower--.f6472.8%
Applied rewrites72.8%
lift-log.f64N/A
lift--.f64N/A
lower-30-log1z072.8%
Applied rewrites72.8%
if -inf.0 < (log.f64 (-.f64 #s(literal 1 binary64) (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)))) Initial program 71.8%
lift-log.f64N/A
lift--.f64N/A
lower-30-log1z070.9%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6470.9%
Applied rewrites70.9%
(FPCore (x y) :precision binary64 (- 1 (30-log1z0 (/ x (- 1 y)))))
1 - \mathsf{30\_log1z0}\left(\left(\frac{x}{1 - y}\right)\right)
Initial program 71.8%
Taylor expanded in x around inf
lower-/.f64N/A
lower--.f6472.8%
Applied rewrites72.8%
lift-log.f64N/A
lift--.f64N/A
lower-30-log1z072.8%
Applied rewrites72.8%
(FPCore (x y) :precision binary64 (- 1 (30-log1z0 x)))
1 - \mathsf{30\_log1z0}\left(x\right)
Initial program 71.8%
Taylor expanded in y around 0
lower-30-log1z062.3%
Applied rewrites62.3%
(FPCore (x y) :precision binary64 (- 1 (- x)))
double code(double x, double y) {
return 1.0 - -x;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - -x
end function
public static double code(double x, double y) {
return 1.0 - -x;
}
def code(x, y): return 1.0 - -x
function code(x, y) return Float64(1.0 - Float64(-x)) end
function tmp = code(x, y) tmp = 1.0 - -x; end
code[x_, y_] := N[(1 - (-x)), $MachinePrecision]
1 - \left(-x\right)
Initial program 71.8%
Taylor expanded in y around 0
lower-30-log1z062.3%
Applied rewrites62.3%
Taylor expanded in x around 0
lower-*.f6442.7%
Applied rewrites42.7%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6442.7%
Applied rewrites42.7%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"
:precision binary64
(- 1 (log (- 1 (/ (- x y) (- 1 y))))))