
(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 -2.9e+154)
(* x z)
(if (<= x -6e-26)
(* y x)
(if (<= x 2.7e-95) (* 5.0 z) (if (<= x 4.5e+194) (* y x) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.9e+154) {
tmp = x * z;
} else if (x <= -6e-26) {
tmp = y * x;
} else if (x <= 2.7e-95) {
tmp = 5.0 * z;
} else if (x <= 4.5e+194) {
tmp = y * x;
} else {
tmp = 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 <= (-2.9d+154)) then
tmp = x * z
else if (x <= (-6d-26)) then
tmp = y * x
else if (x <= 2.7d-95) then
tmp = 5.0d0 * z
else if (x <= 4.5d+194) then
tmp = y * x
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.9e+154) {
tmp = x * z;
} else if (x <= -6e-26) {
tmp = y * x;
} else if (x <= 2.7e-95) {
tmp = 5.0 * z;
} else if (x <= 4.5e+194) {
tmp = y * x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.9e+154: tmp = x * z elif x <= -6e-26: tmp = y * x elif x <= 2.7e-95: tmp = 5.0 * z elif x <= 4.5e+194: tmp = y * x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.9e+154) tmp = Float64(x * z); elseif (x <= -6e-26) tmp = Float64(y * x); elseif (x <= 2.7e-95) tmp = Float64(5.0 * z); elseif (x <= 4.5e+194) tmp = Float64(y * x); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.9e+154) tmp = x * z; elseif (x <= -6e-26) tmp = y * x; elseif (x <= 2.7e-95) tmp = 5.0 * z; elseif (x <= 4.5e+194) tmp = y * x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.9e+154], N[(x * z), $MachinePrecision], If[LessEqual[x, -6e-26], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.7e-95], N[(5.0 * z), $MachinePrecision], If[LessEqual[x, 4.5e+194], N[(y * x), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+154}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-26}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-95}:\\
\;\;\;\;5 \cdot z\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+194}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.89999999999999979e154 or 4.4999999999999998e194 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6466.8
Applied rewrites66.8%
Taylor expanded in x around inf
Applied rewrites66.8%
if -2.89999999999999979e154 < x < -6.00000000000000023e-26 or 2.7e-95 < x < 4.4999999999999998e194Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6465.4
Applied rewrites65.4%
if -6.00000000000000023e-26 < x < 2.7e-95Initial program 99.8%
Taylor expanded in x around 0
lower-*.f6479.0
Applied rewrites79.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-26) (not (<= x 2.7e-95))) (* (+ y z) x) (fma z 5.0 (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-26) || !(x <= 2.7e-95)) {
tmp = (y + z) * x;
} else {
tmp = fma(z, 5.0, (x * z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -6e-26) || !(x <= 2.7e-95)) tmp = Float64(Float64(y + z) * x); else tmp = fma(z, 5.0, Float64(x * z)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-26], N[Not[LessEqual[x, 2.7e-95]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(z * 5.0 + N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-26} \lor \neg \left(x \leq 2.7 \cdot 10^{-95}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
\end{array}
\end{array}
if x < -6.00000000000000023e-26 or 2.7e-95 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f6498.0
Applied rewrites98.0%
Taylor expanded in x around -inf
distribute-lft-inN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-+.f6493.9
Applied rewrites93.9%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
distribute-lft-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*l*N/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-+.f6493.9
Applied rewrites93.9%
if -6.00000000000000023e-26 < x < 2.7e-95Initial program 99.8%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6479.0
Applied rewrites79.0%
Applied rewrites79.0%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (<= x -6e-26) (fma z x (* x y)) (if (<= x 2.7e-95) (fma z 5.0 (* x z)) (* (+ y z) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e-26) {
tmp = fma(z, x, (x * y));
} else if (x <= 2.7e-95) {
tmp = fma(z, 5.0, (x * z));
} else {
tmp = (y + z) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6e-26) tmp = fma(z, x, Float64(x * y)); elseif (x <= 2.7e-95) tmp = fma(z, 5.0, Float64(x * z)); else tmp = Float64(Float64(y + z) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6e-26], N[(z * x + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.7e-95], N[(z * 5.0 + N[(x * z), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-26}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x \cdot y\right)\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-95}:\\
\;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot x\\
\end{array}
\end{array}
if x < -6.00000000000000023e-26Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around -inf
distribute-lft-inN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-+.f6498.1
Applied rewrites98.1%
Applied rewrites98.2%
if -6.00000000000000023e-26 < x < 2.7e-95Initial program 99.8%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6479.0
Applied rewrites79.0%
Applied rewrites79.0%
if 2.7e-95 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f6496.4
Applied rewrites96.4%
Taylor expanded in x around -inf
distribute-lft-inN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-+.f6490.4
Applied rewrites90.4%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
distribute-lft-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*l*N/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-+.f6490.4
Applied rewrites90.4%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-26) (not (<= x 2.7e-95))) (* (+ y z) x) (* 5.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-26) || !(x <= 2.7e-95)) {
tmp = (y + z) * 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 <= (-6d-26)) .or. (.not. (x <= 2.7d-95))) then
tmp = (y + z) * 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 <= -6e-26) || !(x <= 2.7e-95)) {
tmp = (y + z) * x;
} else {
tmp = 5.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-26) or not (x <= 2.7e-95): tmp = (y + z) * x else: tmp = 5.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-26) || !(x <= 2.7e-95)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(5.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e-26) || ~((x <= 2.7e-95))) tmp = (y + z) * x; else tmp = 5.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-26], N[Not[LessEqual[x, 2.7e-95]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-26} \lor \neg \left(x \leq 2.7 \cdot 10^{-95}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;5 \cdot z\\
\end{array}
\end{array}
if x < -6.00000000000000023e-26 or 2.7e-95 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-*.f6498.0
Applied rewrites98.0%
Taylor expanded in x around -inf
distribute-lft-inN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-+.f6493.9
Applied rewrites93.9%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
distribute-lft-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*l*N/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-+.f6493.9
Applied rewrites93.9%
if -6.00000000000000023e-26 < x < 2.7e-95Initial program 99.8%
Taylor expanded in x around 0
lower-*.f6479.0
Applied rewrites79.0%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.8e-122) (not (<= z 3.2e-96))) (* (+ 5.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.8e-122) || !(z <= 3.2e-96)) {
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 <= (-6.8d-122)) .or. (.not. (z <= 3.2d-96))) 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 <= -6.8e-122) || !(z <= 3.2e-96)) {
tmp = (5.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.8e-122) or not (z <= 3.2e-96): tmp = (5.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.8e-122) || !(z <= 3.2e-96)) 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 <= -6.8e-122) || ~((z <= 3.2e-96))) tmp = (5.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.8e-122], N[Not[LessEqual[z, 3.2e-96]], $MachinePrecision]], N[(N[(5.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{-122} \lor \neg \left(z \leq 3.2 \cdot 10^{-96}\right):\\
\;\;\;\;\left(5 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -6.7999999999999996e-122 or 3.20000000000000012e-96 < z Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6478.7
Applied rewrites78.7%
if -6.7999999999999996e-122 < z < 3.20000000000000012e-96Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6473.0
Applied rewrites73.0%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.0) (not (<= x 3500.0))) (* x z) (* 5.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.0) || !(x <= 3500.0)) {
tmp = x * z;
} 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 <= (-5.0d0)) .or. (.not. (x <= 3500.0d0))) then
tmp = x * z
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 <= -5.0) || !(x <= 3500.0)) {
tmp = x * z;
} else {
tmp = 5.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.0) or not (x <= 3500.0): tmp = x * z else: tmp = 5.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.0) || !(x <= 3500.0)) tmp = Float64(x * z); else tmp = Float64(5.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.0) || ~((x <= 3500.0))) tmp = x * z; else tmp = 5.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.0], N[Not[LessEqual[x, 3500.0]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \lor \neg \left(x \leq 3500\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;5 \cdot z\\
\end{array}
\end{array}
if x < -5 or 3500 < x Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6449.0
Applied rewrites49.0%
Taylor expanded in x around inf
Applied rewrites48.4%
if -5 < x < 3500Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6471.6
Applied rewrites71.6%
Final simplification59.9%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return x * 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 = x * z
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6460.8
Applied rewrites60.8%
Taylor expanded in x around inf
Applied rewrites26.2%
(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 2024363
(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)))