
(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 6 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 (if (<= z -8.8e+144) (/ (/ 1.0 y) (/ 1.0 (* x (- y z)))) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.8e+144) {
tmp = (1.0 / y) / (1.0 / (x * (y - z)));
} else {
tmp = x - (x / (y / z));
}
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 <= (-8.8d+144)) then
tmp = (1.0d0 / y) / (1.0d0 / (x * (y - z)))
else
tmp = x - (x / (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -8.8e+144) {
tmp = (1.0 / y) / (1.0 / (x * (y - z)));
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.8e+144: tmp = (1.0 / y) / (1.0 / (x * (y - z))) else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.8e+144) tmp = Float64(Float64(1.0 / y) / Float64(1.0 / Float64(x * Float64(y - z)))); else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.8e+144) tmp = (1.0 / y) / (1.0 / (x * (y - z))); else tmp = x - (x / (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.8e+144], N[(N[(1.0 / y), $MachinePrecision] / N[(1.0 / N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.8 \cdot 10^{+144}:\\
\;\;\;\;\frac{\frac{1}{y}}{\frac{1}{x \cdot \left(y - z\right)}}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if z < -8.79999999999999952e144Initial program 97.0%
associate-/l*N/A
*-lowering-*.f64N/A
div-subN/A
--lowering--.f64N/A
*-inversesN/A
/-lowering-/.f6483.4%
Simplified83.4%
*-inversesN/A
div-subN/A
associate-/l*N/A
clear-numN/A
div-invN/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
--lowering--.f6497.0%
Applied egg-rr97.0%
if -8.79999999999999952e144 < z Initial program 82.1%
associate-/l*N/A
*-lowering-*.f64N/A
div-subN/A
--lowering--.f64N/A
*-inversesN/A
/-lowering-/.f6497.7%
Simplified97.7%
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
clear-numN/A
distribute-neg-frac2N/A
un-div-invN/A
/-lowering-/.f64N/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6495.2%
Applied egg-rr95.2%
+-commutativeN/A
sub0-negN/A
distribute-frac-neg2N/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6498.0%
Applied egg-rr98.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.1e+154) (/ (* x (- y z)) y) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e+154) {
tmp = (x * (y - z)) / y;
} else {
tmp = x - (x / (y / z));
}
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 <= (-1.1d+154)) then
tmp = (x * (y - z)) / y
else
tmp = x - (x / (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e+154) {
tmp = (x * (y - z)) / y;
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.1e+154: tmp = (x * (y - z)) / y else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.1e+154) tmp = Float64(Float64(x * Float64(y - z)) / y); else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.1e+154) tmp = (x * (y - z)) / y; else tmp = x - (x / (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.1e+154], N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{+154}:\\
\;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if z < -1.1000000000000001e154Initial program 99.8%
if -1.1000000000000001e154 < z Initial program 82.1%
associate-/l*N/A
*-lowering-*.f64N/A
div-subN/A
--lowering--.f64N/A
*-inversesN/A
/-lowering-/.f6497.4%
Simplified97.4%
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
clear-numN/A
distribute-neg-frac2N/A
un-div-invN/A
/-lowering-/.f64N/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6494.5%
Applied egg-rr94.5%
+-commutativeN/A
sub0-negN/A
distribute-frac-neg2N/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6497.6%
Applied egg-rr97.6%
(FPCore (x y z) :precision binary64 (if (<= x 4e+33) x (* y (/ x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= 4e+33) {
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 <= 4d+33) 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 <= 4e+33) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 4e+33: tmp = x else: tmp = y * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 4e+33) 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 <= 4e+33) tmp = x; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 4e+33], x, N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{+33}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if x < 3.9999999999999998e33Initial program 86.5%
associate-/l*N/A
*-lowering-*.f64N/A
div-subN/A
--lowering--.f64N/A
*-inversesN/A
/-lowering-/.f6494.6%
Simplified94.6%
Taylor expanded in z around 0
Simplified49.4%
if 3.9999999999999998e33 < x Initial program 75.7%
Taylor expanded in y around inf
*-lowering-*.f6429.1%
Simplified29.1%
clear-numN/A
associate-/r/N/A
associate-*r*N/A
associate-/r/N/A
clear-numN/A
*-lft-identityN/A
*-lowering-*.f64N/A
*-lft-identityN/A
/-lowering-/.f6457.9%
Applied egg-rr57.9%
Final simplification51.3%
(FPCore (x y z) :precision binary64 (- x (/ x (/ y z))))
double code(double x, double y, double z) {
return x - (x / (y / z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x - (x / (y / z))
end function
public static double code(double x, double y, double z) {
return x - (x / (y / z));
}
def code(x, y, z): return x - (x / (y / z))
function code(x, y, z) return Float64(x - Float64(x / Float64(y / z))) end
function tmp = code(x, y, z) tmp = x - (x / (y / z)); end
code[x_, y_, z_] := N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{x}{\frac{y}{z}}
\end{array}
Initial program 84.0%
associate-/l*N/A
*-lowering-*.f64N/A
div-subN/A
--lowering--.f64N/A
*-inversesN/A
/-lowering-/.f6495.8%
Simplified95.8%
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
clear-numN/A
distribute-neg-frac2N/A
un-div-invN/A
/-lowering-/.f64N/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6492.8%
Applied egg-rr92.8%
+-commutativeN/A
sub0-negN/A
distribute-frac-neg2N/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6496.0%
Applied egg-rr96.0%
(FPCore (x y z) :precision binary64 (* x (- 1.0 (/ z y))))
double code(double x, double y, double z) {
return x * (1.0 - (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 * (1.0d0 - (z / y))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (z / y));
}
def code(x, y, z): return x * (1.0 - (z / y))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(z / y))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (z / y)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{z}{y}\right)
\end{array}
Initial program 84.0%
associate-/l*N/A
*-lowering-*.f64N/A
div-subN/A
--lowering--.f64N/A
*-inversesN/A
/-lowering-/.f6495.8%
Simplified95.8%
(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 84.0%
associate-/l*N/A
*-lowering-*.f64N/A
div-subN/A
--lowering--.f64N/A
*-inversesN/A
/-lowering-/.f6495.8%
Simplified95.8%
Taylor expanded in z around 0
Simplified49.7%
(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 2024160
(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))