
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return x * (1.0 - (x * 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 = x * (1.0d0 - (x * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot \left(1 - x \cdot y\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return x * (1.0 - (x * 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 = x * (1.0d0 - (x * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot \left(1 - x \cdot y\right)
(FPCore (x y) :precision binary64 (- x (* (* y x) x)))
double code(double x, double y) {
return x - ((y * x) * 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 = x - ((y * x) * x)
end function
public static double code(double x, double y) {
return x - ((y * x) * x);
}
def code(x, y): return x - ((y * x) * x)
function code(x, y) return Float64(x - Float64(Float64(y * x) * x)) end
function tmp = code(x, y) tmp = x - ((y * x) * x); end
code[x_, y_] := N[(x - N[(N[(y * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
x - \left(y \cdot x\right) \cdot x
Initial program 99.9%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-rgt-inN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
fp-cancel-sub-signN/A
*-lft-identityN/A
lower--.f64N/A
remove-double-negN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
remove-double-neg99.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9%
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (- 1.0 (* x y)))) (t_1 (* (* (- x) y) x))) (if (<= t_0 -1e+100) t_1 (if (<= t_0 2e+66) (* x 1.0) t_1))))
double code(double x, double y) {
double t_0 = x * (1.0 - (x * y));
double t_1 = (-x * y) * x;
double tmp;
if (t_0 <= -1e+100) {
tmp = t_1;
} else if (t_0 <= 2e+66) {
tmp = x * 1.0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x * (1.0d0 - (x * y))
t_1 = (-x * y) * x
if (t_0 <= (-1d+100)) then
tmp = t_1
else if (t_0 <= 2d+66) then
tmp = x * 1.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (1.0 - (x * y));
double t_1 = (-x * y) * x;
double tmp;
if (t_0 <= -1e+100) {
tmp = t_1;
} else if (t_0 <= 2e+66) {
tmp = x * 1.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = x * (1.0 - (x * y)) t_1 = (-x * y) * x tmp = 0 if t_0 <= -1e+100: tmp = t_1 elif t_0 <= 2e+66: tmp = x * 1.0 else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(x * Float64(1.0 - Float64(x * y))) t_1 = Float64(Float64(Float64(-x) * y) * x) tmp = 0.0 if (t_0 <= -1e+100) tmp = t_1; elseif (t_0 <= 2e+66) tmp = Float64(x * 1.0); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (1.0 - (x * y)); t_1 = (-x * y) * x; tmp = 0.0; if (t_0 <= -1e+100) tmp = t_1; elseif (t_0 <= 2e+66) tmp = x * 1.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-x) * y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+100], t$95$1, If[LessEqual[t$95$0, 2e+66], N[(x * 1.0), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
t_0 := x \cdot \left(1 - x \cdot y\right)\\
t_1 := \left(\left(-x\right) \cdot y\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+100}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+66}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 x y))) < -1e100 or 1.9999999999999999e66 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 x y))) Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6446.3%
Applied rewrites46.3%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-neg-outN/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
lower-neg.f6451.9%
Applied rewrites51.9%
if -1e100 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 x y))) < 1.9999999999999999e66Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites50.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (- 1.0 (* x y)))) (t_1 (* (* (- x) x) y))) (if (<= t_0 -1e+100) t_1 (if (<= t_0 2e+66) (* x 1.0) t_1))))
double code(double x, double y) {
double t_0 = x * (1.0 - (x * y));
double t_1 = (-x * x) * y;
double tmp;
if (t_0 <= -1e+100) {
tmp = t_1;
} else if (t_0 <= 2e+66) {
tmp = x * 1.0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x * (1.0d0 - (x * y))
t_1 = (-x * x) * y
if (t_0 <= (-1d+100)) then
tmp = t_1
else if (t_0 <= 2d+66) then
tmp = x * 1.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (1.0 - (x * y));
double t_1 = (-x * x) * y;
double tmp;
if (t_0 <= -1e+100) {
tmp = t_1;
} else if (t_0 <= 2e+66) {
tmp = x * 1.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = x * (1.0 - (x * y)) t_1 = (-x * x) * y tmp = 0 if t_0 <= -1e+100: tmp = t_1 elif t_0 <= 2e+66: tmp = x * 1.0 else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(x * Float64(1.0 - Float64(x * y))) t_1 = Float64(Float64(Float64(-x) * x) * y) tmp = 0.0 if (t_0 <= -1e+100) tmp = t_1; elseif (t_0 <= 2e+66) tmp = Float64(x * 1.0); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (1.0 - (x * y)); t_1 = (-x * x) * y; tmp = 0.0; if (t_0 <= -1e+100) tmp = t_1; elseif (t_0 <= 2e+66) tmp = x * 1.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-x) * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+100], t$95$1, If[LessEqual[t$95$0, 2e+66], N[(x * 1.0), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
t_0 := x \cdot \left(1 - x \cdot y\right)\\
t_1 := \left(\left(-x\right) \cdot x\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+100}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+66}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 x y))) < -1e100 or 1.9999999999999999e66 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 x y))) Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6446.3%
Applied rewrites46.3%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
lower-neg.f6446.3%
Applied rewrites46.3%
if -1e100 < (*.f64 x (-.f64 #s(literal 1 binary64) (*.f64 x y))) < 1.9999999999999999e66Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites50.4%
(FPCore (x y) :precision binary64 (* x 1.0))
double code(double x, double y) {
return x * 1.0;
}
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 = x * 1.0d0
end function
public static double code(double x, double y) {
return x * 1.0;
}
def code(x, y): return x * 1.0
function code(x, y) return Float64(x * 1.0) end
function tmp = code(x, y) tmp = x * 1.0; end
code[x_, y_] := N[(x * 1.0), $MachinePrecision]
x \cdot 1
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites50.4%
herbie shell --seed 2025258
(FPCore (x y)
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, A"
:precision binary64
(* x (- 1.0 (* x y))))