
(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 -3.4e+261) (/ (* x (- z)) y) (* x (- 1.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.4e+261) {
tmp = (x * -z) / y;
} else {
tmp = x * (1.0 - (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 <= (-3.4d+261)) then
tmp = (x * -z) / y
else
tmp = x * (1.0d0 - (z / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.4e+261) {
tmp = (x * -z) / y;
} else {
tmp = x * (1.0 - (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.4e+261: tmp = (x * -z) / y else: tmp = x * (1.0 - (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.4e+261) tmp = Float64(Float64(x * Float64(-z)) / y); else tmp = Float64(x * Float64(1.0 - Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.4e+261) tmp = (x * -z) / y; else tmp = x * (1.0 - (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.4e+261], N[(N[(x * (-z)), $MachinePrecision] / y), $MachinePrecision], N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{+261}:\\
\;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\
\end{array}
\end{array}
if z < -3.4e261Initial program 99.7%
remove-double-neg99.7%
distribute-frac-neg299.7%
distribute-frac-neg99.7%
distribute-rgt-neg-in99.7%
associate-/l*66.6%
distribute-frac-neg66.6%
distribute-frac-neg266.6%
remove-double-neg66.6%
div-sub66.6%
*-inverses66.6%
Simplified66.6%
Taylor expanded in z around inf 99.7%
associate-*r/99.7%
associate-*r*99.7%
mul-1-neg99.7%
Simplified99.7%
if -3.4e261 < z Initial program 79.2%
remove-double-neg79.2%
distribute-frac-neg279.2%
distribute-frac-neg79.2%
distribute-rgt-neg-in79.2%
associate-/l*97.9%
distribute-frac-neg97.9%
distribute-frac-neg297.9%
remove-double-neg97.9%
div-sub97.9%
*-inverses97.9%
Simplified97.9%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (<= y -52000.0) x (if (<= y 750000000.0) (/ z (/ y (- x))) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -52000.0) {
tmp = x;
} else if (y <= 750000000.0) {
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 <= (-52000.0d0)) then
tmp = x
else if (y <= 750000000.0d0) 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 <= -52000.0) {
tmp = x;
} else if (y <= 750000000.0) {
tmp = z / (y / -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -52000.0: tmp = x elif y <= 750000000.0: tmp = z / (y / -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -52000.0) tmp = x; elseif (y <= 750000000.0) tmp = Float64(z / Float64(y / Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -52000.0) tmp = x; elseif (y <= 750000000.0) tmp = z / (y / -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -52000.0], x, If[LessEqual[y, 750000000.0], N[(z / N[(y / (-x)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -52000:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 750000000:\\
\;\;\;\;\frac{z}{\frac{y}{-x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -52000 or 7.5e8 < y Initial program 70.7%
remove-double-neg70.7%
distribute-frac-neg270.7%
distribute-frac-neg70.7%
distribute-rgt-neg-in70.7%
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.8%
if -52000 < y < 7.5e8Initial program 90.4%
remove-double-neg90.4%
distribute-frac-neg290.4%
distribute-frac-neg90.4%
distribute-rgt-neg-in90.4%
associate-/l*92.3%
distribute-frac-neg92.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
div-sub92.3%
*-inverses92.3%
Simplified92.3%
Taylor expanded in z around inf 70.3%
mul-1-neg70.3%
distribute-frac-neg270.3%
Simplified70.3%
distribute-frac-neg270.3%
distribute-rgt-neg-out70.3%
distribute-lft-neg-out70.3%
clear-num70.2%
un-div-inv70.9%
add-sqr-sqrt42.3%
sqrt-unprod32.6%
sqr-neg32.6%
sqrt-unprod1.1%
add-sqr-sqrt1.9%
Applied egg-rr1.9%
associate-/r/1.8%
*-commutative1.8%
Simplified1.8%
associate-*r/2.0%
clear-num2.0%
add-sqr-sqrt1.2%
sqrt-unprod20.5%
sqr-neg20.5%
sqrt-unprod29.1%
add-sqr-sqrt73.2%
*-commutative73.2%
associate-/l/70.9%
frac-2neg70.9%
metadata-eval70.9%
add-sqr-sqrt34.8%
sqrt-unprod31.4%
sqr-neg31.4%
sqrt-unprod0.8%
add-sqr-sqrt1.9%
distribute-neg-frac21.9%
distribute-frac-neg1.9%
distribute-frac-neg1.9%
remove-double-neg1.9%
distribute-frac-neg1.9%
associate-/l/2.0%
Applied egg-rr73.2%
Taylor expanded in y around 0 73.3%
associate-*r/70.3%
associate-*r*70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/r/76.0%
Simplified76.0%
(FPCore (x y z) :precision binary64 (if (<= y -0.002) x (if (<= y 3500000000.0) (* z (/ (- x) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.002) {
tmp = x;
} else if (y <= 3500000000.0) {
tmp = z * (-x / 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 (y <= (-0.002d0)) then
tmp = x
else if (y <= 3500000000.0d0) then
tmp = z * (-x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.002) {
tmp = x;
} else if (y <= 3500000000.0) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.002: tmp = x elif y <= 3500000000.0: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.002) tmp = x; elseif (y <= 3500000000.0) tmp = Float64(z * Float64(Float64(-x) / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.002) tmp = x; elseif (y <= 3500000000.0) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.002], x, If[LessEqual[y, 3500000000.0], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.002:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3500000000:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2e-3 or 3.5e9 < y Initial program 70.7%
remove-double-neg70.7%
distribute-frac-neg270.7%
distribute-frac-neg70.7%
distribute-rgt-neg-in70.7%
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.8%
if -2e-3 < y < 3.5e9Initial program 90.4%
remove-double-neg90.4%
distribute-frac-neg290.4%
distribute-frac-neg90.4%
distribute-rgt-neg-in90.4%
associate-/l*92.3%
distribute-frac-neg92.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
div-sub92.3%
*-inverses92.3%
Simplified92.3%
Taylor expanded in z around inf 73.3%
associate-*l/74.8%
associate-*l*74.8%
*-commutative74.8%
associate-*r/74.8%
mul-1-neg74.8%
Simplified74.8%
(FPCore (x y z) :precision binary64 (if (<= y -14.4) x (if (<= y 840000000.0) (* x (/ z (- y))) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -14.4) {
tmp = x;
} else if (y <= 840000000.0) {
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 (y <= (-14.4d0)) then
tmp = x
else if (y <= 840000000.0d0) 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 (y <= -14.4) {
tmp = x;
} else if (y <= 840000000.0) {
tmp = x * (z / -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -14.4: tmp = x elif y <= 840000000.0: tmp = x * (z / -y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -14.4) tmp = x; elseif (y <= 840000000.0) 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 (y <= -14.4) tmp = x; elseif (y <= 840000000.0) tmp = x * (z / -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -14.4], x, If[LessEqual[y, 840000000.0], N[(x * N[(z / (-y)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -14.4:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 840000000:\\
\;\;\;\;x \cdot \frac{z}{-y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -14.4000000000000004 or 8.4e8 < y Initial program 70.7%
remove-double-neg70.7%
distribute-frac-neg270.7%
distribute-frac-neg70.7%
distribute-rgt-neg-in70.7%
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.8%
if -14.4000000000000004 < y < 8.4e8Initial program 90.4%
remove-double-neg90.4%
distribute-frac-neg290.4%
distribute-frac-neg90.4%
distribute-rgt-neg-in90.4%
associate-/l*92.3%
distribute-frac-neg92.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
div-sub92.3%
*-inverses92.3%
Simplified92.3%
Taylor expanded in z around inf 70.3%
mul-1-neg70.3%
distribute-frac-neg270.3%
Simplified70.3%
(FPCore (x y z) :precision binary64 (/ x (/ y (- y z))))
double code(double x, double y, double z) {
return x / (y / (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 / (y / (y - z))
end function
public static double code(double x, double y, double z) {
return x / (y / (y - z));
}
def code(x, y, z): return x / (y / (y - z))
function code(x, y, z) return Float64(x / Float64(y / Float64(y - z))) end
function tmp = code(x, y, z) tmp = x / (y / (y - z)); end
code[x_, y_, z_] := N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{y}{y - z}}
\end{array}
Initial program 80.3%
remove-double-neg80.3%
distribute-frac-neg280.3%
distribute-frac-neg80.3%
distribute-rgt-neg-in80.3%
associate-/l*96.2%
distribute-frac-neg96.2%
distribute-frac-neg296.2%
remove-double-neg96.2%
div-sub96.2%
*-inverses96.2%
Simplified96.2%
*-inverses96.2%
div-sub96.2%
clear-num96.2%
un-div-inv96.5%
Applied egg-rr96.5%
(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 80.3%
remove-double-neg80.3%
distribute-frac-neg280.3%
distribute-frac-neg80.3%
distribute-rgt-neg-in80.3%
associate-/l*96.2%
distribute-frac-neg96.2%
distribute-frac-neg296.2%
remove-double-neg96.2%
div-sub96.2%
*-inverses96.2%
Simplified96.2%
Taylor expanded in z around 0 53.1%
(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 2024101
(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))