
(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 (* 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*95.1%
distribute-frac-neg95.1%
distribute-frac-neg295.1%
remove-double-neg95.1%
div-sub95.1%
*-inverses95.1%
Simplified95.1%
Final simplification95.1%
(FPCore (x y z)
:precision binary64
(if (<= y -1.4e-19)
x
(if (or (<= y -4.4e-139) (and (not (<= y -2e-170)) (<= y 3.1e+112)))
(/ (- z) (/ y x))
x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-19) {
tmp = x;
} else if ((y <= -4.4e-139) || (!(y <= -2e-170) && (y <= 3.1e+112))) {
tmp = -z / (y / x);
} 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 (y <= (-1.4d-19)) then
tmp = x
else if ((y <= (-4.4d-139)) .or. (.not. (y <= (-2d-170))) .and. (y <= 3.1d+112)) then
tmp = -z / (y / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-19) {
tmp = x;
} else if ((y <= -4.4e-139) || (!(y <= -2e-170) && (y <= 3.1e+112))) {
tmp = -z / (y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.4e-19: tmp = x elif (y <= -4.4e-139) or (not (y <= -2e-170) and (y <= 3.1e+112)): tmp = -z / (y / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.4e-19) tmp = x; elseif ((y <= -4.4e-139) || (!(y <= -2e-170) && (y <= 3.1e+112))) tmp = Float64(Float64(-z) / Float64(y / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.4e-19) tmp = x; elseif ((y <= -4.4e-139) || (~((y <= -2e-170)) && (y <= 3.1e+112))) tmp = -z / (y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-19], x, If[Or[LessEqual[y, -4.4e-139], And[N[Not[LessEqual[y, -2e-170]], $MachinePrecision], LessEqual[y, 3.1e+112]]], N[((-z) / N[(y / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -4.4 \cdot 10^{-139} \lor \neg \left(y \leq -2 \cdot 10^{-170}\right) \land y \leq 3.1 \cdot 10^{+112}:\\
\;\;\;\;\frac{-z}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.40000000000000001e-19 or -4.40000000000000021e-139 < y < -1.99999999999999997e-170 or 3.09999999999999983e112 < y Initial program 76.6%
remove-double-neg76.6%
distribute-frac-neg276.6%
distribute-frac-neg76.6%
distribute-rgt-neg-in76.6%
associate-/l*99.9%
distribute-frac-neg99.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
Taylor expanded in z around 0 81.0%
if -1.40000000000000001e-19 < y < -4.40000000000000021e-139 or -1.99999999999999997e-170 < y < 3.09999999999999983e112Initial program 89.1%
remove-double-neg89.1%
distribute-frac-neg289.1%
distribute-frac-neg89.1%
distribute-rgt-neg-in89.1%
associate-/l*90.7%
distribute-frac-neg90.7%
distribute-frac-neg290.7%
remove-double-neg90.7%
div-sub90.8%
*-inverses90.8%
Simplified90.8%
Taylor expanded in z around inf 66.9%
mul-1-neg66.9%
distribute-frac-neg266.9%
Simplified66.9%
distribute-frac-neg266.9%
distribute-rgt-neg-out66.9%
add-sqr-sqrt37.3%
sqrt-unprod28.6%
sqr-neg28.6%
sqrt-unprod0.7%
add-sqr-sqrt1.9%
associate-*r/2.0%
frac-2neg2.0%
*-commutative2.0%
distribute-rgt-neg-out2.0%
remove-double-neg2.0%
associate-*r/1.9%
clear-num1.9%
un-div-inv1.9%
frac-2neg1.9%
add-sqr-sqrt0.8%
sqrt-unprod30.8%
sqr-neg30.8%
sqrt-unprod40.4%
add-sqr-sqrt72.3%
remove-double-neg72.3%
Applied egg-rr72.3%
Final simplification76.4%
(FPCore (x y z)
:precision binary64
(if (<= y -3.8e-21)
x
(if (<= y -4.4e-139)
(/ (* z (- x)) y)
(if (<= y -2e-170) x (if (<= y 7.4e+111) (/ (- z) (/ y x)) x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-21) {
tmp = x;
} else if (y <= -4.4e-139) {
tmp = (z * -x) / y;
} else if (y <= -2e-170) {
tmp = x;
} else if (y <= 7.4e+111) {
tmp = -z / (y / x);
} 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 (y <= (-3.8d-21)) then
tmp = x
else if (y <= (-4.4d-139)) then
tmp = (z * -x) / y
else if (y <= (-2d-170)) then
tmp = x
else if (y <= 7.4d+111) then
tmp = -z / (y / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-21) {
tmp = x;
} else if (y <= -4.4e-139) {
tmp = (z * -x) / y;
} else if (y <= -2e-170) {
tmp = x;
} else if (y <= 7.4e+111) {
tmp = -z / (y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e-21: tmp = x elif y <= -4.4e-139: tmp = (z * -x) / y elif y <= -2e-170: tmp = x elif y <= 7.4e+111: tmp = -z / (y / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e-21) tmp = x; elseif (y <= -4.4e-139) tmp = Float64(Float64(z * Float64(-x)) / y); elseif (y <= -2e-170) tmp = x; elseif (y <= 7.4e+111) tmp = Float64(Float64(-z) / Float64(y / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e-21) tmp = x; elseif (y <= -4.4e-139) tmp = (z * -x) / y; elseif (y <= -2e-170) tmp = x; elseif (y <= 7.4e+111) tmp = -z / (y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e-21], x, If[LessEqual[y, -4.4e-139], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, -2e-170], x, If[LessEqual[y, 7.4e+111], N[((-z) / N[(y / x), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-21}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -4.4 \cdot 10^{-139}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{elif}\;y \leq -2 \cdot 10^{-170}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{+111}:\\
\;\;\;\;\frac{-z}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.7999999999999998e-21 or -4.40000000000000021e-139 < y < -1.99999999999999997e-170 or 7.4000000000000005e111 < y Initial program 76.6%
remove-double-neg76.6%
distribute-frac-neg276.6%
distribute-frac-neg76.6%
distribute-rgt-neg-in76.6%
associate-/l*99.9%
distribute-frac-neg99.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
Taylor expanded in z around 0 81.0%
if -3.7999999999999998e-21 < y < -4.40000000000000021e-139Initial program 96.4%
Taylor expanded in y around 0 63.8%
associate-*r*63.8%
mul-1-neg63.8%
Simplified63.8%
if -1.99999999999999997e-170 < y < 7.4000000000000005e111Initial program 87.3%
remove-double-neg87.3%
distribute-frac-neg287.3%
distribute-frac-neg87.3%
distribute-rgt-neg-in87.3%
associate-/l*88.6%
distribute-frac-neg88.6%
distribute-frac-neg288.6%
remove-double-neg88.6%
div-sub88.6%
*-inverses88.6%
Simplified88.6%
Taylor expanded in z around inf 67.7%
mul-1-neg67.7%
distribute-frac-neg267.7%
Simplified67.7%
distribute-frac-neg267.7%
distribute-rgt-neg-out67.7%
add-sqr-sqrt46.2%
sqrt-unprod35.0%
sqr-neg35.0%
sqrt-unprod0.5%
add-sqr-sqrt1.9%
associate-*r/2.0%
frac-2neg2.0%
*-commutative2.0%
distribute-rgt-neg-out2.0%
remove-double-neg2.0%
associate-*r/1.9%
clear-num1.9%
un-div-inv1.9%
frac-2neg1.9%
add-sqr-sqrt0.5%
sqrt-unprod37.7%
sqr-neg37.7%
sqrt-unprod50.1%
add-sqr-sqrt74.3%
remove-double-neg74.3%
Applied egg-rr74.3%
Final simplification76.4%
(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*95.1%
distribute-frac-neg95.1%
distribute-frac-neg295.1%
remove-double-neg95.1%
div-sub95.1%
*-inverses95.1%
Simplified95.1%
Taylor expanded in z around 0 51.8%
Final simplification51.8%
(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 2024071
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:alt
(if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))
(/ (* x (- y z)) y))