
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y - z)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y - z)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (* (- 1.0 (/ z y)) x))
double code(double x, double y, double z) {
return (1.0 - (z / y)) * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 - (z / y)) * x
end function
public static double code(double x, double y, double z) {
return (1.0 - (z / y)) * x;
}
def code(x, y, z): return (1.0 - (z / y)) * x
function code(x, y, z) return Float64(Float64(1.0 - Float64(z / y)) * x) end
function tmp = code(x, y, z) tmp = (1.0 - (z / y)) * x; end
code[x_, y_, z_] := N[(N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - \frac{z}{y}\right) \cdot x
\end{array}
Initial program 87.0%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f6498.4%
Applied egg-rr98.4%
(FPCore (x y z) :precision binary64 (if (<= x 5e+72) x (/ y (/ y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= 5e+72) {
tmp = x;
} else {
tmp = y / (y / x);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= 5d+72) then
tmp = x
else
tmp = y / (y / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 5e+72) {
tmp = x;
} else {
tmp = y / (y / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 5e+72: tmp = x else: tmp = y / (y / x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 5e+72) tmp = x; else tmp = Float64(y / Float64(y / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 5e+72) tmp = x; else tmp = y / (y / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 5e+72], x, N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+72}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\end{array}
\end{array}
if x < 4.99999999999999992e72Initial program 90.1%
Taylor expanded in y around inf
Simplified54.5%
if 4.99999999999999992e72 < x Initial program 75.2%
Taylor expanded in y around inf
*-lowering-*.f6432.1%
Simplified32.1%
clear-numN/A
associate-/r*N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f6462.5%
Applied egg-rr62.5%
(FPCore (x y z) :precision binary64 (if (<= x 1e+32) x (* y (/ x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= 1e+32) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= 1d+32) then
tmp = x
else
tmp = y * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 1e+32) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1e+32: tmp = x else: tmp = y * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1e+32) tmp = x; else tmp = Float64(y * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 1e+32) tmp = x; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1e+32], x, N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+32}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if x < 1.00000000000000005e32Initial program 89.7%
Taylor expanded in y around inf
Simplified55.1%
if 1.00000000000000005e32 < x Initial program 78.4%
Taylor expanded in y around inf
*-lowering-*.f6433.1%
Simplified33.1%
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6459.5%
Applied egg-rr59.5%
Final simplification56.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 87.0%
Taylor expanded in y around inf
Simplified54.0%
(FPCore (x y z) :precision binary64 (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z < -2.060202331921739e+104) {
tmp = x - ((z * x) / y);
} else if (z < 1.6939766013828526e+213) {
tmp = x / (y / (y - z));
} else {
tmp = (y - z) * (x / y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z < (-2.060202331921739d+104)) then
tmp = x - ((z * x) / y)
else if (z < 1.6939766013828526d+213) then
tmp = x / (y / (y - z))
else
tmp = (y - z) * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z < -2.060202331921739e+104) {
tmp = x - ((z * x) / y);
} else if (z < 1.6939766013828526e+213) {
tmp = x / (y / (y - z));
} else {
tmp = (y - z) * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z < -2.060202331921739e+104: tmp = x - ((z * x) / y) elif z < 1.6939766013828526e+213: tmp = x / (y / (y - z)) else: tmp = (y - z) * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z < -2.060202331921739e+104) tmp = Float64(x - Float64(Float64(z * x) / y)); elseif (z < 1.6939766013828526e+213) tmp = Float64(x / Float64(y / Float64(y - z))); else tmp = Float64(Float64(y - z) * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z < -2.060202331921739e+104) tmp = x - ((z * x) / y); elseif (z < 1.6939766013828526e+213) tmp = x / (y / (y - z)); else tmp = (y - z) * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Less[z, -2.060202331921739e+104], N[(x - N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[Less[z, 1.6939766013828526e+213], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z < -2.060202331921739 \cdot 10^{+104}:\\
\;\;\;\;x - \frac{z \cdot x}{y}\\
\mathbf{elif}\;z < 1.6939766013828526 \cdot 10^{+213}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\
\end{array}
\end{array}
herbie shell --seed 2024192
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (if (< z -206020233192173900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- x (/ (* z x) y)) (if (< z 1693976601382852600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ x (/ y (- y z))) (* (- y z) (/ x y)))))
(/ (* x (- y z)) y))