
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z): return (x * (y + z)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (y + z)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z): return (x * (y + z)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (y + z)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}
(FPCore (x y z) :precision binary64 (fma z 5.0 (* (+ z y) x)))
double code(double x, double y, double z) {
return fma(z, 5.0, ((z + y) * x));
}
function code(x, y, z) return fma(z, 5.0, Float64(Float64(z + y) * x)) end
code[x_, y_, z_] := N[(z * 5.0 + N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, 5, \left(z + y\right) \cdot x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -4e+137)
(* y x)
(if (<= x -3.1e+51)
(* x z)
(if (<= x -4.5e-78)
(* y x)
(if (<= x 5.0) (* 5.0 z) (if (<= x 1.45e+134) (* x z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4e+137) {
tmp = y * x;
} else if (x <= -3.1e+51) {
tmp = x * z;
} else if (x <= -4.5e-78) {
tmp = y * x;
} else if (x <= 5.0) {
tmp = 5.0 * z;
} else if (x <= 1.45e+134) {
tmp = x * z;
} else {
tmp = y * x;
}
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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-4d+137)) then
tmp = y * x
else if (x <= (-3.1d+51)) then
tmp = x * z
else if (x <= (-4.5d-78)) then
tmp = y * x
else if (x <= 5.0d0) then
tmp = 5.0d0 * z
else if (x <= 1.45d+134) then
tmp = x * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4e+137) {
tmp = y * x;
} else if (x <= -3.1e+51) {
tmp = x * z;
} else if (x <= -4.5e-78) {
tmp = y * x;
} else if (x <= 5.0) {
tmp = 5.0 * z;
} else if (x <= 1.45e+134) {
tmp = x * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4e+137: tmp = y * x elif x <= -3.1e+51: tmp = x * z elif x <= -4.5e-78: tmp = y * x elif x <= 5.0: tmp = 5.0 * z elif x <= 1.45e+134: tmp = x * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4e+137) tmp = Float64(y * x); elseif (x <= -3.1e+51) tmp = Float64(x * z); elseif (x <= -4.5e-78) tmp = Float64(y * x); elseif (x <= 5.0) tmp = Float64(5.0 * z); elseif (x <= 1.45e+134) tmp = Float64(x * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4e+137) tmp = y * x; elseif (x <= -3.1e+51) tmp = x * z; elseif (x <= -4.5e-78) tmp = y * x; elseif (x <= 5.0) tmp = 5.0 * z; elseif (x <= 1.45e+134) tmp = x * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4e+137], N[(y * x), $MachinePrecision], If[LessEqual[x, -3.1e+51], N[(x * z), $MachinePrecision], If[LessEqual[x, -4.5e-78], N[(y * x), $MachinePrecision], If[LessEqual[x, 5.0], N[(5.0 * z), $MachinePrecision], If[LessEqual[x, 1.45e+134], N[(x * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+137}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -3.1 \cdot 10^{+51}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -4.5 \cdot 10^{-78}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 5:\\
\;\;\;\;5 \cdot z\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+134}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -4.0000000000000001e137 or -3.10000000000000011e51 < x < -4.5e-78 or 1.45000000000000006e134 < x Initial program 99.9%
Taylor expanded in y around inf
Applied rewrites60.1%
if -4.0000000000000001e137 < x < -3.10000000000000011e51 or 5 < x < 1.45000000000000006e134Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites73.1%
Taylor expanded in x around inf
Applied rewrites70.7%
if -4.5e-78 < x < 5Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites81.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -19000000000000.0) (not (<= x 5.0))) (* (+ z y) x) (+ (* x y) (* z 5.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -19000000000000.0) || !(x <= 5.0)) {
tmp = (z + y) * x;
} else {
tmp = (x * y) + (z * 5.0);
}
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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-19000000000000.0d0)) .or. (.not. (x <= 5.0d0))) then
tmp = (z + y) * x
else
tmp = (x * y) + (z * 5.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -19000000000000.0) || !(x <= 5.0)) {
tmp = (z + y) * x;
} else {
tmp = (x * y) + (z * 5.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -19000000000000.0) or not (x <= 5.0): tmp = (z + y) * x else: tmp = (x * y) + (z * 5.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -19000000000000.0) || !(x <= 5.0)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(x * y) + Float64(z * 5.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -19000000000000.0) || ~((x <= 5.0))) tmp = (z + y) * x; else tmp = (x * y) + (z * 5.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -19000000000000.0], N[Not[LessEqual[x, 5.0]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -19000000000000 \lor \neg \left(x \leq 5\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + z \cdot 5\\
\end{array}
\end{array}
if x < -1.9e13 or 5 < x Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites99.0%
if -1.9e13 < x < 5Initial program 99.8%
Taylor expanded in y around inf
Applied rewrites97.6%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -19000000000000.0) (not (<= x 5.0))) (* (+ z y) x) (fma z 5.0 (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -19000000000000.0) || !(x <= 5.0)) {
tmp = (z + y) * x;
} else {
tmp = fma(z, 5.0, (y * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -19000000000000.0) || !(x <= 5.0)) tmp = Float64(Float64(z + y) * x); else tmp = fma(z, 5.0, Float64(y * x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -19000000000000.0], N[Not[LessEqual[x, 5.0]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(z * 5.0 + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -19000000000000 \lor \neg \left(x \leq 5\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, y \cdot x\right)\\
\end{array}
\end{array}
if x < -1.9e13 or 5 < x Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites99.0%
if -1.9e13 < x < 5Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites97.5%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-78) (not (<= x 410000000.0))) (* (+ z y) x) (* (+ 5.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-78) || !(x <= 410000000.0)) {
tmp = (z + y) * x;
} else {
tmp = (5.0 + x) * z;
}
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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-4.5d-78)) .or. (.not. (x <= 410000000.0d0))) then
tmp = (z + y) * x
else
tmp = (5.0d0 + x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-78) || !(x <= 410000000.0)) {
tmp = (z + y) * x;
} else {
tmp = (5.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-78) or not (x <= 410000000.0): tmp = (z + y) * x else: tmp = (5.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-78) || !(x <= 410000000.0)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(5.0 + x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e-78) || ~((x <= 410000000.0))) tmp = (z + y) * x; else tmp = (5.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-78], N[Not[LessEqual[x, 410000000.0]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-78} \lor \neg \left(x \leq 410000000\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -4.5e-78 or 4.1e8 < x Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites93.4%
if -4.5e-78 < x < 4.1e8Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites82.5%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.05e-9) (not (<= z 1.8e-144))) (* (+ 5.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-9) || !(z <= 1.8e-144)) {
tmp = (5.0 + x) * z;
} else {
tmp = y * x;
}
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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.05d-9)) .or. (.not. (z <= 1.8d-144))) then
tmp = (5.0d0 + x) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-9) || !(z <= 1.8e-144)) {
tmp = (5.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.05e-9) or not (z <= 1.8e-144): tmp = (5.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.05e-9) || !(z <= 1.8e-144)) tmp = Float64(Float64(5.0 + x) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.05e-9) || ~((z <= 1.8e-144))) tmp = (5.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.05e-9], N[Not[LessEqual[z, 1.8e-144]], $MachinePrecision]], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-9} \lor \neg \left(z \leq 1.8 \cdot 10^{-144}\right):\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -1.0500000000000001e-9 or 1.8e-144 < z Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites84.1%
if -1.0500000000000001e-9 < z < 1.8e-144Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites71.7%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-78) (not (<= x 4e-12))) (* y x) (* 5.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-78) || !(x <= 4e-12)) {
tmp = y * x;
} else {
tmp = 5.0 * z;
}
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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-4.5d-78)) .or. (.not. (x <= 4d-12))) then
tmp = y * x
else
tmp = 5.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-78) || !(x <= 4e-12)) {
tmp = y * x;
} else {
tmp = 5.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-78) or not (x <= 4e-12): tmp = y * x else: tmp = 5.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-78) || !(x <= 4e-12)) tmp = Float64(y * x); else tmp = Float64(5.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e-78) || ~((x <= 4e-12))) tmp = y * x; else tmp = 5.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-78], N[Not[LessEqual[x, 4e-12]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-78} \lor \neg \left(x \leq 4 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;5 \cdot z\\
\end{array}
\end{array}
if x < -4.5e-78 or 3.99999999999999992e-12 < x Initial program 99.9%
Taylor expanded in y around inf
Applied rewrites50.2%
if -4.5e-78 < x < 3.99999999999999992e-12Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites82.6%
Final simplification62.9%
(FPCore (x y z) :precision binary64 (* 5.0 z))
double code(double x, double y, double z) {
return 5.0 * z;
}
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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 5.0d0 * z
end function
public static double code(double x, double y, double z) {
return 5.0 * z;
}
def code(x, y, z): return 5.0 * z
function code(x, y, z) return Float64(5.0 * z) end
function tmp = code(x, y, z) tmp = 5.0 * z; end
code[x_, y_, z_] := N[(5.0 * z), $MachinePrecision]
\begin{array}{l}
\\
5 \cdot z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites37.0%
(FPCore (x y z) :precision binary64 (+ (* (+ x 5.0) z) (* x y)))
double code(double x, double y, double z) {
return ((x + 5.0) * z) + (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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x + 5.0d0) * z) + (x * y)
end function
public static double code(double x, double y, double z) {
return ((x + 5.0) * z) + (x * y);
}
def code(x, y, z): return ((x + 5.0) * z) + (x * y)
function code(x, y, z) return Float64(Float64(Float64(x + 5.0) * z) + Float64(x * y)) end
function tmp = code(x, y, z) tmp = ((x + 5.0) * z) + (x * y); end
code[x_, y_, z_] := N[(N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 5\right) \cdot z + x \cdot y
\end{array}
herbie shell --seed 2025021
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:alt
(! :herbie-platform default (+ (* (+ x 5) z) (* x y)))
(+ (* x (+ y z)) (* z 5.0)))