
(FPCore (x y z t) :precision binary64 (+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))
double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * ((((y + z) + z) + y) + t)) + (y * 5.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 5.0);
}
def code(x, y, z, t): return (x * ((((y + z) + z) + y) + t)) + (y * 5.0)
function code(x, y, z, t) return Float64(Float64(x * Float64(Float64(Float64(Float64(y + z) + z) + y) + t)) + Float64(y * 5.0)) end
function tmp = code(x, y, z, t) tmp = (x * ((((y + z) + z) + y) + t)) + (y * 5.0); end
code[x_, y_, z_, t_] := N[(N[(x * N[(N[(N[(N[(y + z), $MachinePrecision] + z), $MachinePrecision] + y), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision] + N[(y * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))
double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * ((((y + z) + z) + y) + t)) + (y * 5.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 5.0);
}
def code(x, y, z, t): return (x * ((((y + z) + z) + y) + t)) + (y * 5.0)
function code(x, y, z, t) return Float64(Float64(x * Float64(Float64(Float64(Float64(y + z) + z) + y) + t)) + Float64(y * 5.0)) end
function tmp = code(x, y, z, t) tmp = (x * ((((y + z) + z) + y) + t)) + (y * 5.0); end
code[x_, y_, z_, t_] := N[(N[(x * N[(N[(N[(N[(y + z), $MachinePrecision] + z), $MachinePrecision] + y), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision] + N[(y * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5
\end{array}
(FPCore (x y z t) :precision binary64 (fma y 5.0 (* (+ (+ (fma 2.0 z y) y) t) x)))
double code(double x, double y, double z, double t) {
return fma(y, 5.0, (((fma(2.0, z, y) + y) + t) * x));
}
function code(x, y, z, t) return fma(y, 5.0, Float64(Float64(Float64(fma(2.0, z, y) + y) + t) * x)) end
code[x_, y_, z_, t_] := N[(y * 5.0 + N[(N[(N[(N[(2.0 * z + y), $MachinePrecision] + y), $MachinePrecision] + t), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 5, \left(\left(\mathsf{fma}\left(2, z, y\right) + y\right) + t\right) \cdot x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (* z x) 2.0)) (t_2 (* (+ x x) y)))
(if (<= x -4.8e+226)
(* t x)
(if (<= x -1.2e+198)
t_2
(if (<= x -9.2e+62)
t_1
(if (<= x -2.5) t_2 (if (<= x 4.1e-22) (* 5.0 y) t_1)))))))
double code(double x, double y, double z, double t) {
double t_1 = (z * x) * 2.0;
double t_2 = (x + x) * y;
double tmp;
if (x <= -4.8e+226) {
tmp = t * x;
} else if (x <= -1.2e+198) {
tmp = t_2;
} else if (x <= -9.2e+62) {
tmp = t_1;
} else if (x <= -2.5) {
tmp = t_2;
} else if (x <= 4.1e-22) {
tmp = 5.0 * y;
} 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, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (z * x) * 2.0d0
t_2 = (x + x) * y
if (x <= (-4.8d+226)) then
tmp = t * x
else if (x <= (-1.2d+198)) then
tmp = t_2
else if (x <= (-9.2d+62)) then
tmp = t_1
else if (x <= (-2.5d0)) then
tmp = t_2
else if (x <= 4.1d-22) then
tmp = 5.0d0 * y
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (z * x) * 2.0;
double t_2 = (x + x) * y;
double tmp;
if (x <= -4.8e+226) {
tmp = t * x;
} else if (x <= -1.2e+198) {
tmp = t_2;
} else if (x <= -9.2e+62) {
tmp = t_1;
} else if (x <= -2.5) {
tmp = t_2;
} else if (x <= 4.1e-22) {
tmp = 5.0 * y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (z * x) * 2.0 t_2 = (x + x) * y tmp = 0 if x <= -4.8e+226: tmp = t * x elif x <= -1.2e+198: tmp = t_2 elif x <= -9.2e+62: tmp = t_1 elif x <= -2.5: tmp = t_2 elif x <= 4.1e-22: tmp = 5.0 * y else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z * x) * 2.0) t_2 = Float64(Float64(x + x) * y) tmp = 0.0 if (x <= -4.8e+226) tmp = Float64(t * x); elseif (x <= -1.2e+198) tmp = t_2; elseif (x <= -9.2e+62) tmp = t_1; elseif (x <= -2.5) tmp = t_2; elseif (x <= 4.1e-22) tmp = Float64(5.0 * y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z * x) * 2.0; t_2 = (x + x) * y; tmp = 0.0; if (x <= -4.8e+226) tmp = t * x; elseif (x <= -1.2e+198) tmp = t_2; elseif (x <= -9.2e+62) tmp = t_1; elseif (x <= -2.5) tmp = t_2; elseif (x <= 4.1e-22) tmp = 5.0 * y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * x), $MachinePrecision] * 2.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[x, -4.8e+226], N[(t * x), $MachinePrecision], If[LessEqual[x, -1.2e+198], t$95$2, If[LessEqual[x, -9.2e+62], t$95$1, If[LessEqual[x, -2.5], t$95$2, If[LessEqual[x, 4.1e-22], N[(5.0 * y), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(z \cdot x\right) \cdot 2\\
t_2 := \left(x + x\right) \cdot y\\
\mathbf{if}\;x \leq -4.8 \cdot 10^{+226}:\\
\;\;\;\;t \cdot x\\
\mathbf{elif}\;x \leq -1.2 \cdot 10^{+198}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq -9.2 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -2.5:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-22}:\\
\;\;\;\;5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -4.8e226Initial program 100.0%
Taylor expanded in t around inf
lower-*.f6459.2
Applied rewrites59.2%
if -4.8e226 < x < -1.2000000000000001e198 or -9.19999999999999936e62 < x < -2.5Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
associate-+l+N/A
+-commutativeN/A
count-2-revN/A
associate-+l+N/A
associate-+l+N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6469.4
Applied rewrites69.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6466.7
Applied rewrites66.7%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6466.7
Applied rewrites66.7%
if -1.2000000000000001e198 < x < -9.19999999999999936e62 or 4.0999999999999999e-22 < x Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6451.1
Applied rewrites51.1%
if -2.5 < x < 4.0999999999999999e-22Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6462.7
Applied rewrites62.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (fma 2.0 x 5.0) y)))
(if (<= y -2.5e-58)
t_1
(if (<= y 1.55e-124) (* (* z x) 2.0) (if (<= y 9e-35) (* t x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = fma(2.0, x, 5.0) * y;
double tmp;
if (y <= -2.5e-58) {
tmp = t_1;
} else if (y <= 1.55e-124) {
tmp = (z * x) * 2.0;
} else if (y <= 9e-35) {
tmp = t * x;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(fma(2.0, x, 5.0) * y) tmp = 0.0 if (y <= -2.5e-58) tmp = t_1; elseif (y <= 1.55e-124) tmp = Float64(Float64(z * x) * 2.0); elseif (y <= 9e-35) tmp = Float64(t * x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(2.0 * x + 5.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2.5e-58], t$95$1, If[LessEqual[y, 1.55e-124], N[(N[(z * x), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[y, 9e-35], N[(t * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(2, x, 5\right) \cdot y\\
\mathbf{if}\;y \leq -2.5 \cdot 10^{-58}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-124}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 2\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-35}:\\
\;\;\;\;t \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.49999999999999989e-58 or 9.0000000000000002e-35 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6476.9
Applied rewrites76.9%
if -2.49999999999999989e-58 < y < 1.5499999999999999e-124Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.9
Applied rewrites53.9%
if 1.5499999999999999e-124 < y < 9.0000000000000002e-35Initial program 99.9%
Taylor expanded in t around inf
lower-*.f6473.0
Applied rewrites73.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -0.46) (not (<= x 4.1e-22))) (* (fma 2.0 (+ z y) t) x) (+ (* x t) (* y 5.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -0.46) || !(x <= 4.1e-22)) {
tmp = fma(2.0, (z + y), t) * x;
} else {
tmp = (x * t) + (y * 5.0);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((x <= -0.46) || !(x <= 4.1e-22)) tmp = Float64(fma(2.0, Float64(z + y), t) * x); else tmp = Float64(Float64(x * t) + Float64(y * 5.0)); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -0.46], N[Not[LessEqual[x, 4.1e-22]], $MachinePrecision]], N[(N[(2.0 * N[(z + y), $MachinePrecision] + t), $MachinePrecision] * x), $MachinePrecision], N[(N[(x * t), $MachinePrecision] + N[(y * 5.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.46 \lor \neg \left(x \leq 4.1 \cdot 10^{-22}\right):\\
\;\;\;\;\mathsf{fma}\left(2, z + y, t\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot t + y \cdot 5\\
\end{array}
\end{array}
if x < -0.46000000000000002 or 4.0999999999999999e-22 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
if -0.46000000000000002 < x < 4.0999999999999999e-22Initial program 99.9%
Taylor expanded in t around inf
Applied rewrites83.2%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.1e+27) (not (<= y 1.15e+21))) (* (fma 2.0 x 5.0) y) (* (fma 2.0 z t) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.1e+27) || !(y <= 1.15e+21)) {
tmp = fma(2.0, x, 5.0) * y;
} else {
tmp = fma(2.0, z, t) * x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.1e+27) || !(y <= 1.15e+21)) tmp = Float64(fma(2.0, x, 5.0) * y); else tmp = Float64(fma(2.0, z, t) * x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.1e+27], N[Not[LessEqual[y, 1.15e+21]], $MachinePrecision]], N[(N[(2.0 * x + 5.0), $MachinePrecision] * y), $MachinePrecision], N[(N[(2.0 * z + t), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+27} \lor \neg \left(y \leq 1.15 \cdot 10^{+21}\right):\\
\;\;\;\;\mathsf{fma}\left(2, x, 5\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, z, t\right) \cdot x\\
\end{array}
\end{array}
if y < -4.1000000000000002e27 or 1.15e21 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6484.2
Applied rewrites84.2%
if -4.1000000000000002e27 < y < 1.15e21Initial program 99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6482.2
Applied rewrites82.2%
Final simplification83.1%
(FPCore (x y z t) :precision binary64 (if (<= x -4.8e+226) (* t x) (if (<= x -2.5) (* (+ x x) y) (if (<= x 5e-62) (* 5.0 y) (* t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4.8e+226) {
tmp = t * x;
} else if (x <= -2.5) {
tmp = (x + x) * y;
} else if (x <= 5e-62) {
tmp = 5.0 * y;
} else {
tmp = t * 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (x <= (-4.8d+226)) then
tmp = t * x
else if (x <= (-2.5d0)) then
tmp = (x + x) * y
else if (x <= 5d-62) then
tmp = 5.0d0 * y
else
tmp = t * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4.8e+226) {
tmp = t * x;
} else if (x <= -2.5) {
tmp = (x + x) * y;
} else if (x <= 5e-62) {
tmp = 5.0 * y;
} else {
tmp = t * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -4.8e+226: tmp = t * x elif x <= -2.5: tmp = (x + x) * y elif x <= 5e-62: tmp = 5.0 * y else: tmp = t * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -4.8e+226) tmp = Float64(t * x); elseif (x <= -2.5) tmp = Float64(Float64(x + x) * y); elseif (x <= 5e-62) tmp = Float64(5.0 * y); else tmp = Float64(t * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -4.8e+226) tmp = t * x; elseif (x <= -2.5) tmp = (x + x) * y; elseif (x <= 5e-62) tmp = 5.0 * y; else tmp = t * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -4.8e+226], N[(t * x), $MachinePrecision], If[LessEqual[x, -2.5], N[(N[(x + x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[x, 5e-62], N[(5.0 * y), $MachinePrecision], N[(t * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+226}:\\
\;\;\;\;t \cdot x\\
\mathbf{elif}\;x \leq -2.5:\\
\;\;\;\;\left(x + x\right) \cdot y\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-62}:\\
\;\;\;\;5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t \cdot x\\
\end{array}
\end{array}
if x < -4.8e226 or 5.0000000000000002e-62 < x Initial program 100.0%
Taylor expanded in t around inf
lower-*.f6442.1
Applied rewrites42.1%
if -4.8e226 < x < -2.5Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
associate-+l+N/A
+-commutativeN/A
count-2-revN/A
associate-+l+N/A
associate-+l+N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6441.4
Applied rewrites41.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6440.3
Applied rewrites40.3%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6440.3
Applied rewrites40.3%
if -2.5 < x < 5.0000000000000002e-62Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6464.3
Applied rewrites64.3%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.26e-14) (not (<= x 5e-62))) (* t x) (* 5.0 y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.26e-14) || !(x <= 5e-62)) {
tmp = t * x;
} else {
tmp = 5.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, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x <= (-1.26d-14)) .or. (.not. (x <= 5d-62))) then
tmp = t * x
else
tmp = 5.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.26e-14) || !(x <= 5e-62)) {
tmp = t * x;
} else {
tmp = 5.0 * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.26e-14) or not (x <= 5e-62): tmp = t * x else: tmp = 5.0 * y return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.26e-14) || !(x <= 5e-62)) tmp = Float64(t * x); else tmp = Float64(5.0 * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.26e-14) || ~((x <= 5e-62))) tmp = t * x; else tmp = 5.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.26e-14], N[Not[LessEqual[x, 5e-62]], $MachinePrecision]], N[(t * x), $MachinePrecision], N[(5.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.26 \cdot 10^{-14} \lor \neg \left(x \leq 5 \cdot 10^{-62}\right):\\
\;\;\;\;t \cdot x\\
\mathbf{else}:\\
\;\;\;\;5 \cdot y\\
\end{array}
\end{array}
if x < -1.25999999999999996e-14 or 5.0000000000000002e-62 < x Initial program 100.0%
Taylor expanded in t around inf
lower-*.f6437.0
Applied rewrites37.0%
if -1.25999999999999996e-14 < x < 5.0000000000000002e-62Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6465.9
Applied rewrites65.9%
Final simplification48.4%
(FPCore (x y z t) :precision binary64 (* 5.0 y))
double code(double x, double y, double z, double t) {
return 5.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, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 5.0d0 * y
end function
public static double code(double x, double y, double z, double t) {
return 5.0 * y;
}
def code(x, y, z, t): return 5.0 * y
function code(x, y, z, t) return Float64(5.0 * y) end
function tmp = code(x, y, z, t) tmp = 5.0 * y; end
code[x_, y_, z_, t_] := N[(5.0 * y), $MachinePrecision]
\begin{array}{l}
\\
5 \cdot y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6428.7
Applied rewrites28.7%
herbie shell --seed 2025064
(FPCore (x y z t)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, B"
:precision binary64
(+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))