
(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 86.0%
remove-double-neg86.0%
distribute-frac-neg286.0%
distribute-frac-neg86.0%
distribute-rgt-neg-in86.0%
associate-/l*97.7%
distribute-frac-neg97.7%
distribute-frac-neg297.7%
remove-double-neg97.7%
div-sub97.7%
*-inverses97.7%
Simplified97.7%
Final simplification97.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (/ z (- y)))))
(if (<= y -1.55e+65)
x
(if (<= y -2.85e-27)
t_0
(if (<= y -1.65e-112) (* y (/ x y)) (if (<= y 0.105) t_0 x))))))
double code(double x, double y, double z) {
double t_0 = x * (z / -y);
double tmp;
if (y <= -1.55e+65) {
tmp = x;
} else if (y <= -2.85e-27) {
tmp = t_0;
} else if (y <= -1.65e-112) {
tmp = y * (x / y);
} else if (y <= 0.105) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (z / -y)
if (y <= (-1.55d+65)) then
tmp = x
else if (y <= (-2.85d-27)) then
tmp = t_0
else if (y <= (-1.65d-112)) then
tmp = y * (x / y)
else if (y <= 0.105d0) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z / -y);
double tmp;
if (y <= -1.55e+65) {
tmp = x;
} else if (y <= -2.85e-27) {
tmp = t_0;
} else if (y <= -1.65e-112) {
tmp = y * (x / y);
} else if (y <= 0.105) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z / -y) tmp = 0 if y <= -1.55e+65: tmp = x elif y <= -2.85e-27: tmp = t_0 elif y <= -1.65e-112: tmp = y * (x / y) elif y <= 0.105: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z / Float64(-y))) tmp = 0.0 if (y <= -1.55e+65) tmp = x; elseif (y <= -2.85e-27) tmp = t_0; elseif (y <= -1.65e-112) tmp = Float64(y * Float64(x / y)); elseif (y <= 0.105) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z / -y); tmp = 0.0; if (y <= -1.55e+65) tmp = x; elseif (y <= -2.85e-27) tmp = t_0; elseif (y <= -1.65e-112) tmp = y * (x / y); elseif (y <= 0.105) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z / (-y)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.55e+65], x, If[LessEqual[y, -2.85e-27], t$95$0, If[LessEqual[y, -1.65e-112], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.105], t$95$0, x]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{z}{-y}\\
\mathbf{if}\;y \leq -1.55 \cdot 10^{+65}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -2.85 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.65 \cdot 10^{-112}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{elif}\;y \leq 0.105:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.54999999999999995e65 or 0.104999999999999996 < y Initial program 77.2%
remove-double-neg77.2%
distribute-frac-neg277.2%
distribute-frac-neg77.2%
distribute-rgt-neg-in77.2%
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 83.9%
if -1.54999999999999995e65 < y < -2.8499999999999998e-27 or -1.65e-112 < y < 0.104999999999999996Initial program 91.6%
associate-/l*95.3%
add-sqr-sqrt41.4%
associate-*l*41.4%
Applied egg-rr41.4%
Taylor expanded in y around 0 76.4%
mul-1-neg76.4%
distribute-frac-neg276.4%
associate-/l*78.4%
Simplified78.4%
if -2.8499999999999998e-27 < y < -1.65e-112Initial program 99.8%
Taylor expanded in y around inf 73.5%
*-commutative73.5%
associate-/l*77.1%
Applied egg-rr77.1%
Final simplification80.7%
(FPCore (x y z)
:precision binary64
(if (<= y -1.95e+65)
x
(if (<= y -2.15e-32)
(* x (/ z (- y)))
(if (<= y -1.6e-112)
(* y (/ x y))
(if (<= y 1750.0) (/ z (/ y (- x))) x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+65) {
tmp = x;
} else if (y <= -2.15e-32) {
tmp = x * (z / -y);
} else if (y <= -1.6e-112) {
tmp = y * (x / y);
} else if (y <= 1750.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 <= (-1.95d+65)) then
tmp = x
else if (y <= (-2.15d-32)) then
tmp = x * (z / -y)
else if (y <= (-1.6d-112)) then
tmp = y * (x / y)
else if (y <= 1750.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 <= -1.95e+65) {
tmp = x;
} else if (y <= -2.15e-32) {
tmp = x * (z / -y);
} else if (y <= -1.6e-112) {
tmp = y * (x / y);
} else if (y <= 1750.0) {
tmp = z / (y / -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.95e+65: tmp = x elif y <= -2.15e-32: tmp = x * (z / -y) elif y <= -1.6e-112: tmp = y * (x / y) elif y <= 1750.0: tmp = z / (y / -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+65) tmp = x; elseif (y <= -2.15e-32) tmp = Float64(x * Float64(z / Float64(-y))); elseif (y <= -1.6e-112) tmp = Float64(y * Float64(x / y)); elseif (y <= 1750.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 <= -1.95e+65) tmp = x; elseif (y <= -2.15e-32) tmp = x * (z / -y); elseif (y <= -1.6e-112) tmp = y * (x / y); elseif (y <= 1750.0) tmp = z / (y / -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+65], x, If[LessEqual[y, -2.15e-32], N[(x * N[(z / (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -1.6e-112], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1750.0], N[(z / N[(y / (-x)), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+65}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -2.15 \cdot 10^{-32}:\\
\;\;\;\;x \cdot \frac{z}{-y}\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{-112}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{elif}\;y \leq 1750:\\
\;\;\;\;\frac{z}{\frac{y}{-x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.9499999999999999e65 or 1750 < y Initial program 77.2%
remove-double-neg77.2%
distribute-frac-neg277.2%
distribute-frac-neg77.2%
distribute-rgt-neg-in77.2%
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 83.9%
if -1.9499999999999999e65 < y < -2.14999999999999995e-32Initial program 93.0%
associate-/l*99.9%
add-sqr-sqrt53.6%
associate-*l*53.6%
Applied egg-rr53.6%
Taylor expanded in y around 0 63.9%
mul-1-neg63.9%
distribute-frac-neg263.9%
associate-/l*70.7%
Simplified70.7%
if -2.14999999999999995e-32 < y < -1.59999999999999997e-112Initial program 99.8%
Taylor expanded in y around inf 73.5%
*-commutative73.5%
associate-/l*77.1%
Applied egg-rr77.1%
if -1.59999999999999997e-112 < y < 1750Initial program 91.4%
associate-/l*94.8%
add-sqr-sqrt39.9%
associate-*l*40.0%
Applied egg-rr40.0%
Taylor expanded in y around 0 77.8%
mul-1-neg77.8%
distribute-frac-neg277.8%
associate-/l*79.3%
Simplified79.3%
associate-*r/77.8%
add-sqr-sqrt26.8%
sqrt-unprod17.1%
sqr-neg17.1%
sqrt-unprod0.9%
add-sqr-sqrt1.5%
*-commutative1.5%
associate-*l/1.4%
associate-/r/1.4%
frac-2neg1.4%
distribute-neg-frac1.4%
add-sqr-sqrt0.6%
sqrt-unprod38.4%
sqr-neg38.4%
sqrt-unprod51.9%
add-sqr-sqrt80.7%
Applied egg-rr80.7%
Final simplification81.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 86.0%
remove-double-neg86.0%
distribute-frac-neg286.0%
distribute-frac-neg86.0%
distribute-rgt-neg-in86.0%
associate-/l*97.7%
distribute-frac-neg97.7%
distribute-frac-neg297.7%
remove-double-neg97.7%
div-sub97.7%
*-inverses97.7%
Simplified97.7%
Taylor expanded in z around 0 51.0%
Final simplification51.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 2024067
(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))