
(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 5 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 (* 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 83.2%
remove-double-neg83.2%
distribute-frac-neg283.2%
distribute-frac-neg83.2%
distribute-rgt-neg-in83.2%
associate-/l*97.6%
distribute-frac-neg97.6%
distribute-frac-neg297.6%
remove-double-neg97.6%
div-sub97.7%
*-inverses97.7%
Simplified97.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -205.0) (not (<= z 1.4e-77))) (* x (/ z (- y))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -205.0) || !(z <= 1.4e-77)) {
tmp = x * (z / -y);
} else {
tmp = 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 ((z <= (-205.0d0)) .or. (.not. (z <= 1.4d-77))) then
tmp = x * (z / -y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -205.0) || !(z <= 1.4e-77)) {
tmp = x * (z / -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -205.0) or not (z <= 1.4e-77): tmp = x * (z / -y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -205.0) || !(z <= 1.4e-77)) tmp = Float64(x * Float64(z / Float64(-y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -205.0) || ~((z <= 1.4e-77))) tmp = x * (z / -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -205.0], N[Not[LessEqual[z, 1.4e-77]], $MachinePrecision]], N[(x * N[(z / (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -205 \lor \neg \left(z \leq 1.4 \cdot 10^{-77}\right):\\
\;\;\;\;x \cdot \frac{z}{-y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -205 or 1.4e-77 < z Initial program 87.3%
remove-double-neg87.3%
distribute-frac-neg287.3%
distribute-frac-neg87.3%
distribute-rgt-neg-in87.3%
associate-/l*95.9%
distribute-frac-neg95.9%
distribute-frac-neg295.9%
remove-double-neg95.9%
div-sub95.9%
*-inverses95.9%
Simplified95.9%
Taylor expanded in z around inf 70.9%
mul-1-neg70.9%
distribute-frac-neg270.9%
associate-*r/70.3%
Simplified70.3%
if -205 < z < 1.4e-77Initial program 77.6%
remove-double-neg77.6%
distribute-frac-neg277.6%
distribute-frac-neg77.6%
distribute-rgt-neg-in77.6%
associate-/l*100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in z around 0 81.9%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.4) (/ (* z (- x)) y) (if (<= z 7.2e-78) x (* x (/ z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4) {
tmp = (z * -x) / y;
} else if (z <= 7.2e-78) {
tmp = x;
} else {
tmp = x * (z / -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 <= (-1.4d0)) then
tmp = (z * -x) / y
else if (z <= 7.2d-78) then
tmp = x
else
tmp = x * (z / -y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.4) {
tmp = (z * -x) / y;
} else if (z <= 7.2e-78) {
tmp = x;
} else {
tmp = x * (z / -y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4: tmp = (z * -x) / y elif z <= 7.2e-78: tmp = x else: tmp = x * (z / -y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4) tmp = Float64(Float64(z * Float64(-x)) / y); elseif (z <= 7.2e-78) tmp = x; else tmp = Float64(x * Float64(z / Float64(-y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4) tmp = (z * -x) / y; elseif (z <= 7.2e-78) tmp = x; else tmp = x * (z / -y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[z, 7.2e-78], x, N[(x * N[(z / (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{-78}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{z}{-y}\\
\end{array}
\end{array}
if z < -1.3999999999999999Initial program 88.2%
remove-double-neg88.2%
distribute-frac-neg288.2%
distribute-frac-neg88.2%
distribute-rgt-neg-in88.2%
associate-/l*95.4%
distribute-frac-neg95.4%
distribute-frac-neg295.4%
remove-double-neg95.4%
div-sub95.4%
*-inverses95.4%
Simplified95.4%
Taylor expanded in z around inf 78.2%
associate-*r/78.2%
associate-*r*78.2%
mul-1-neg78.2%
Simplified78.2%
if -1.3999999999999999 < z < 7.2000000000000005e-78Initial program 77.6%
remove-double-neg77.6%
distribute-frac-neg277.6%
distribute-frac-neg77.6%
distribute-rgt-neg-in77.6%
associate-/l*100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in z around 0 81.9%
if 7.2000000000000005e-78 < z Initial program 86.5%
remove-double-neg86.5%
distribute-frac-neg286.5%
distribute-frac-neg86.5%
distribute-rgt-neg-in86.5%
associate-/l*96.3%
distribute-frac-neg96.3%
distribute-frac-neg296.3%
remove-double-neg96.3%
div-sub96.3%
*-inverses96.3%
Simplified96.3%
Taylor expanded in z around inf 65.2%
mul-1-neg65.2%
distribute-frac-neg265.2%
associate-*r/67.5%
Simplified67.5%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (<= z -28.0) (/ z (/ y (- x))) (if (<= z 1.4e-77) x (* x (/ z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -28.0) {
tmp = z / (y / -x);
} else if (z <= 1.4e-77) {
tmp = x;
} else {
tmp = x * (z / -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 <= (-28.0d0)) then
tmp = z / (y / -x)
else if (z <= 1.4d-77) then
tmp = x
else
tmp = x * (z / -y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -28.0) {
tmp = z / (y / -x);
} else if (z <= 1.4e-77) {
tmp = x;
} else {
tmp = x * (z / -y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -28.0: tmp = z / (y / -x) elif z <= 1.4e-77: tmp = x else: tmp = x * (z / -y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -28.0) tmp = Float64(z / Float64(y / Float64(-x))); elseif (z <= 1.4e-77) tmp = x; else tmp = Float64(x * Float64(z / Float64(-y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -28.0) tmp = z / (y / -x); elseif (z <= 1.4e-77) tmp = x; else tmp = x * (z / -y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -28.0], N[(z / N[(y / (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.4e-77], x, N[(x * N[(z / (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -28:\\
\;\;\;\;\frac{z}{\frac{y}{-x}}\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{-77}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{z}{-y}\\
\end{array}
\end{array}
if z < -28Initial program 88.2%
remove-double-neg88.2%
distribute-frac-neg288.2%
distribute-frac-neg88.2%
distribute-rgt-neg-in88.2%
associate-/l*95.4%
distribute-frac-neg95.4%
distribute-frac-neg295.4%
remove-double-neg95.4%
div-sub95.4%
*-inverses95.4%
Simplified95.4%
Taylor expanded in z around inf 78.2%
associate-*r/78.2%
associate-*r*78.2%
mul-1-neg78.2%
Simplified78.2%
div-inv78.1%
*-commutative78.1%
associate-*l*73.7%
add-sqr-sqrt34.4%
sqrt-unprod29.4%
sqr-neg29.4%
sqrt-unprod0.7%
add-sqr-sqrt1.3%
*-commutative1.3%
associate-*l/1.3%
*-un-lft-identity1.3%
Applied egg-rr1.3%
associate-*r/1.2%
add-sqr-sqrt0.7%
sqrt-unprod33.3%
sqr-neg33.3%
sqrt-unprod39.9%
add-sqr-sqrt78.2%
clear-num78.1%
metadata-eval78.1%
distribute-neg-frac78.1%
associate-/l/73.9%
frac-2neg73.9%
associate-/r/73.7%
associate-*l/73.9%
neg-mul-173.9%
Applied egg-rr73.9%
if -28 < z < 1.4e-77Initial program 77.6%
remove-double-neg77.6%
distribute-frac-neg277.6%
distribute-frac-neg77.6%
distribute-rgt-neg-in77.6%
associate-/l*100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in z around 0 81.9%
if 1.4e-77 < z Initial program 86.5%
remove-double-neg86.5%
distribute-frac-neg286.5%
distribute-frac-neg86.5%
distribute-rgt-neg-in86.5%
associate-/l*96.3%
distribute-frac-neg96.3%
distribute-frac-neg296.3%
remove-double-neg96.3%
div-sub96.3%
*-inverses96.3%
Simplified96.3%
Taylor expanded in z around inf 65.2%
mul-1-neg65.2%
distribute-frac-neg265.2%
associate-*r/67.5%
Simplified67.5%
Final simplification75.3%
(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 83.2%
remove-double-neg83.2%
distribute-frac-neg283.2%
distribute-frac-neg83.2%
distribute-rgt-neg-in83.2%
associate-/l*97.6%
distribute-frac-neg97.6%
distribute-frac-neg297.6%
remove-double-neg97.6%
div-sub97.7%
*-inverses97.7%
Simplified97.7%
Taylor expanded in z around 0 50.6%
(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 2024137
(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))