
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - 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 + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - 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 + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -1e-16) (not (<= y 1e-40))) (fma (/ (- (/ x y) x) z) y y) (fma 1.0 y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1e-16) || !(y <= 1e-40)) {
tmp = fma((((x / y) - x) / z), y, y);
} else {
tmp = fma(1.0, y, (x / z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1e-16) || !(y <= 1e-40)) tmp = fma(Float64(Float64(Float64(x / y) - x) / z), y, y); else tmp = fma(1.0, y, Float64(x / z)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1e-16], N[Not[LessEqual[y, 1e-40]], $MachinePrecision]], N[(N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] / z), $MachinePrecision] * y + y), $MachinePrecision], N[(1.0 * y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-16} \lor \neg \left(y \leq 10^{-40}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{x}{y} - x}{z}, y, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, y, \frac{x}{z}\right)\\
\end{array}
\end{array}
if y < -9.9999999999999998e-17 or 9.9999999999999993e-41 < y Initial program 82.0%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6496.6
Applied rewrites96.6%
Taylor expanded in y around inf
Applied rewrites100.0%
if -9.9999999999999998e-17 < y < 9.9999999999999993e-41Initial program 99.9%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6496.2
Applied rewrites96.2%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y 3e-130) (fma (/ (- z x) z) y (/ x z)) (fma (/ (- (/ x y) x) z) y y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 3e-130) {
tmp = fma(((z - x) / z), y, (x / z));
} else {
tmp = fma((((x / y) - x) / z), y, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 3e-130) tmp = fma(Float64(Float64(z - x) / z), y, Float64(x / z)); else tmp = fma(Float64(Float64(Float64(x / y) - x) / z), y, y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 3e-130], N[(N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision] * y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] / z), $MachinePrecision] * y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-130}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - x}{z}, y, \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{x}{y} - x}{z}, y, y\right)\\
\end{array}
\end{array}
if y < 2.99999999999999986e-130Initial program 92.7%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6499.3
Applied rewrites99.3%
if 2.99999999999999986e-130 < y Initial program 84.0%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6492.0
Applied rewrites92.0%
Taylor expanded in y around inf
Applied rewrites99.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.45e+92) (fma (/ (- x) z) y y) (if (<= y 1e+16) (/ (fma (- z x) y x) z) (* (/ (- z x) z) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.45e+92) {
tmp = fma((-x / z), y, y);
} else if (y <= 1e+16) {
tmp = fma((z - x), y, x) / z;
} else {
tmp = ((z - x) / z) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.45e+92) tmp = fma(Float64(Float64(-x) / z), y, y); elseif (y <= 1e+16) tmp = Float64(fma(Float64(z - x), y, x) / z); else tmp = Float64(Float64(Float64(z - x) / z) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.45e+92], N[(N[((-x) / z), $MachinePrecision] * y + y), $MachinePrecision], If[LessEqual[y, 1e+16], N[(N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision] / z), $MachinePrecision], N[(N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+92}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-x}{z}, y, y\right)\\
\mathbf{elif}\;y \leq 10^{+16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(z - x, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{z - x}{z} \cdot y\\
\end{array}
\end{array}
if y < -1.45e92Initial program 75.1%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites100.0%
if -1.45e92 < y < 1e16Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
if 1e16 < y Initial program 77.6%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6494.4
Applied rewrites94.4%
Taylor expanded in y around inf
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -80000000000.0) (not (<= y 1.0))) (* (/ (- z x) z) y) (fma 1.0 y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -80000000000.0) || !(y <= 1.0)) {
tmp = ((z - x) / z) * y;
} else {
tmp = fma(1.0, y, (x / z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -80000000000.0) || !(y <= 1.0)) tmp = Float64(Float64(Float64(z - x) / z) * y); else tmp = fma(1.0, y, Float64(x / z)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -80000000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision] * y), $MachinePrecision], N[(1.0 * y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -80000000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{z - x}{z} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, y, \frac{x}{z}\right)\\
\end{array}
\end{array}
if y < -8e10 or 1 < y Initial program 79.9%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6497.0
Applied rewrites97.0%
Taylor expanded in y around inf
Applied rewrites99.5%
if -8e10 < y < 1Initial program 99.9%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6495.8
Applied rewrites95.8%
Taylor expanded in x around 0
Applied rewrites99.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= y -80000000000.0) (fma (/ (- x) z) y y) (if (<= y 1.0) (fma 1.0 y (/ x z)) (* (/ (- z x) z) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -80000000000.0) {
tmp = fma((-x / z), y, y);
} else if (y <= 1.0) {
tmp = fma(1.0, y, (x / z));
} else {
tmp = ((z - x) / z) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -80000000000.0) tmp = fma(Float64(Float64(-x) / z), y, y); elseif (y <= 1.0) tmp = fma(1.0, y, Float64(x / z)); else tmp = Float64(Float64(Float64(z - x) / z) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -80000000000.0], N[(N[((-x) / z), $MachinePrecision] * y + y), $MachinePrecision], If[LessEqual[y, 1.0], N[(1.0 * y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -80000000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{-x}{z}, y, y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(1, y, \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{z - x}{z} \cdot y\\
\end{array}
\end{array}
if y < -8e10Initial program 81.6%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites100.0%
if -8e10 < y < 1Initial program 99.9%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6495.8
Applied rewrites95.8%
Taylor expanded in x around 0
Applied rewrites99.0%
if 1 < y Initial program 78.5%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6494.6
Applied rewrites94.6%
Taylor expanded in y around inf
Applied rewrites99.0%
(FPCore (x y z) :precision binary64 (if (<= y 6.2e+174) (fma 1.0 y (/ x z)) (* (/ (- x) z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 6.2e+174) {
tmp = fma(1.0, y, (x / z));
} else {
tmp = (-x / z) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 6.2e+174) tmp = fma(1.0, y, Float64(x / z)); else tmp = Float64(Float64(Float64(-x) / z) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 6.2e+174], N[(1.0 * y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[((-x) / z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.2 \cdot 10^{+174}:\\
\;\;\;\;\mathsf{fma}\left(1, y, \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z} \cdot y\\
\end{array}
\end{array}
if y < 6.2e174Initial program 91.1%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6496.4
Applied rewrites96.4%
Taylor expanded in x around 0
Applied rewrites82.7%
if 6.2e174 < y Initial program 76.6%
Taylor expanded in x around inf
Applied rewrites66.5%
Taylor expanded in y around inf
Applied rewrites69.3%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e-47) y (if (<= y 1e-53) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-47) {
tmp = y;
} else if (y <= 1e-53) {
tmp = x / z;
} else {
tmp = 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-5.2d-47)) then
tmp = y
else if (y <= 1d-53) then
tmp = x / z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-47) {
tmp = y;
} else if (y <= 1e-53) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e-47: tmp = y elif y <= 1e-53: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e-47) tmp = y; elseif (y <= 1e-53) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e-47) tmp = y; elseif (y <= 1e-53) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e-47], y, If[LessEqual[y, 1e-53], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-47}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 10^{-53}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.2e-47 or 1.00000000000000003e-53 < y Initial program 83.0%
Taylor expanded in x around 0
Applied rewrites53.4%
if -5.2e-47 < y < 1.00000000000000003e-53Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites76.3%
Final simplification61.9%
(FPCore (x y z) :precision binary64 (fma 1.0 y (/ x z)))
double code(double x, double y, double z) {
return fma(1.0, y, (x / z));
}
function code(x, y, z) return fma(1.0, y, Float64(x / z)) end
code[x_, y_, z_] := N[(1.0 * y + N[(x / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, y, \frac{x}{z}\right)
\end{array}
Initial program 89.3%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6496.4
Applied rewrites96.4%
Taylor expanded in x around 0
Applied rewrites76.6%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return 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 = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 89.3%
Taylor expanded in x around 0
Applied rewrites43.5%
Final simplification43.5%
(FPCore (x y z) :precision binary64 (- (+ y (/ x z)) (/ y (/ z x))))
double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / 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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (x / z)) - (y / (z / x))
end function
public static double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
def code(x, y, z): return (y + (x / z)) - (y / (z / x))
function code(x, y, z) return Float64(Float64(y + Float64(x / z)) - Float64(y / Float64(z / x))) end
function tmp = code(x, y, z) tmp = (y + (x / z)) - (y / (z / x)); end
code[x_, y_, z_] := N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
\end{array}
herbie shell --seed 2025026
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:alt
(! :herbie-platform default (- (+ y (/ x z)) (/ y (/ z x))))
(/ (+ x (* y (- z x))) z))