
(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 (/ 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 84.2%
associate-*l/87.3%
Simplified87.3%
associate-/r/97.3%
Applied egg-rr97.3%
Final simplification97.3%
(FPCore (x y z)
:precision binary64
(if (<= y -2e-25)
x
(if (or (<= y -4.3e-95) (and (not (<= y -1.25e-146)) (<= y 9.5e-103)))
(* x (/ (- z) y))
x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-25) {
tmp = x;
} else if ((y <= -4.3e-95) || (!(y <= -1.25e-146) && (y <= 9.5e-103))) {
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 <= (-2d-25)) then
tmp = x
else if ((y <= (-4.3d-95)) .or. (.not. (y <= (-1.25d-146))) .and. (y <= 9.5d-103)) 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 <= -2e-25) {
tmp = x;
} else if ((y <= -4.3e-95) || (!(y <= -1.25e-146) && (y <= 9.5e-103))) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e-25: tmp = x elif (y <= -4.3e-95) or (not (y <= -1.25e-146) and (y <= 9.5e-103)): tmp = x * (-z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e-25) tmp = x; elseif ((y <= -4.3e-95) || (!(y <= -1.25e-146) && (y <= 9.5e-103))) tmp = Float64(x * Float64(Float64(-z) / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e-25) tmp = x; elseif ((y <= -4.3e-95) || (~((y <= -1.25e-146)) && (y <= 9.5e-103))) tmp = x * (-z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e-25], x, If[Or[LessEqual[y, -4.3e-95], And[N[Not[LessEqual[y, -1.25e-146]], $MachinePrecision], LessEqual[y, 9.5e-103]]], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -4.3 \cdot 10^{-95} \lor \neg \left(y \leq -1.25 \cdot 10^{-146}\right) \land y \leq 9.5 \cdot 10^{-103}:\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.00000000000000008e-25 or -4.29999999999999997e-95 < y < -1.24999999999999989e-146 or 9.50000000000000065e-103 < y Initial program 80.5%
*-commutative80.5%
associate-*l/99.3%
*-commutative99.3%
div-sub99.3%
*-inverses99.3%
Simplified99.3%
Taylor expanded in z around 0 78.3%
if -2.00000000000000008e-25 < y < -4.29999999999999997e-95 or -1.24999999999999989e-146 < y < 9.50000000000000065e-103Initial program 90.8%
*-commutative90.8%
associate-*l/92.7%
*-commutative92.7%
div-sub92.8%
*-inverses92.8%
Simplified92.8%
Taylor expanded in z around inf 78.0%
associate-*r/78.0%
mul-1-neg78.0%
distribute-rgt-neg-out78.0%
associate-*r/76.6%
Simplified76.6%
Final simplification77.7%
(FPCore (x y z)
:precision binary64
(if (<= y -8.5e-26)
x
(if (<= y -1.95e-95)
(* x (/ (- z) y))
(if (<= y -1.25e-146) x (if (<= y 1.1e-100) (* z (/ (- x) y)) x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e-26) {
tmp = x;
} else if (y <= -1.95e-95) {
tmp = x * (-z / y);
} else if (y <= -1.25e-146) {
tmp = x;
} else if (y <= 1.1e-100) {
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 <= (-8.5d-26)) then
tmp = x
else if (y <= (-1.95d-95)) then
tmp = x * (-z / y)
else if (y <= (-1.25d-146)) then
tmp = x
else if (y <= 1.1d-100) 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 <= -8.5e-26) {
tmp = x;
} else if (y <= -1.95e-95) {
tmp = x * (-z / y);
} else if (y <= -1.25e-146) {
tmp = x;
} else if (y <= 1.1e-100) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.5e-26: tmp = x elif y <= -1.95e-95: tmp = x * (-z / y) elif y <= -1.25e-146: tmp = x elif y <= 1.1e-100: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.5e-26) tmp = x; elseif (y <= -1.95e-95) tmp = Float64(x * Float64(Float64(-z) / y)); elseif (y <= -1.25e-146) tmp = x; elseif (y <= 1.1e-100) 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 <= -8.5e-26) tmp = x; elseif (y <= -1.95e-95) tmp = x * (-z / y); elseif (y <= -1.25e-146) tmp = x; elseif (y <= 1.1e-100) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.5e-26], x, If[LessEqual[y, -1.95e-95], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -1.25e-146], x, If[LessEqual[y, 1.1e-100], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -1.95 \cdot 10^{-95}:\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-146}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-100}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.50000000000000004e-26 or -1.95e-95 < y < -1.24999999999999989e-146 or 1.09999999999999995e-100 < y Initial program 80.5%
*-commutative80.5%
associate-*l/99.3%
*-commutative99.3%
div-sub99.3%
*-inverses99.3%
Simplified99.3%
Taylor expanded in z around 0 78.3%
if -8.50000000000000004e-26 < y < -1.95e-95Initial program 99.6%
*-commutative99.6%
associate-*l/99.9%
*-commutative99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
Taylor expanded in z around inf 72.1%
associate-*r/72.1%
mul-1-neg72.1%
distribute-rgt-neg-out72.1%
associate-*r/72.5%
Simplified72.5%
if -1.24999999999999989e-146 < y < 1.09999999999999995e-100Initial program 89.3%
*-commutative89.3%
associate-*l/91.5%
*-commutative91.5%
div-sub91.5%
*-inverses91.5%
Simplified91.5%
Taylor expanded in z around inf 79.0%
mul-1-neg79.0%
*-commutative79.0%
associate-*r/82.6%
distribute-lft-neg-out82.6%
Simplified82.6%
Final simplification79.3%
(FPCore (x y z)
:precision binary64
(if (<= y -1.45e-25)
x
(if (<= y -6.2e-96)
(/ x (/ (- y) z))
(if (<= y -1.25e-146) x (if (<= y 1.1e-99) (* z (/ (- x) y)) x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.45e-25) {
tmp = x;
} else if (y <= -6.2e-96) {
tmp = x / (-y / z);
} else if (y <= -1.25e-146) {
tmp = x;
} else if (y <= 1.1e-99) {
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 <= (-1.45d-25)) then
tmp = x
else if (y <= (-6.2d-96)) then
tmp = x / (-y / z)
else if (y <= (-1.25d-146)) then
tmp = x
else if (y <= 1.1d-99) 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 <= -1.45e-25) {
tmp = x;
} else if (y <= -6.2e-96) {
tmp = x / (-y / z);
} else if (y <= -1.25e-146) {
tmp = x;
} else if (y <= 1.1e-99) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.45e-25: tmp = x elif y <= -6.2e-96: tmp = x / (-y / z) elif y <= -1.25e-146: tmp = x elif y <= 1.1e-99: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.45e-25) tmp = x; elseif (y <= -6.2e-96) tmp = Float64(x / Float64(Float64(-y) / z)); elseif (y <= -1.25e-146) tmp = x; elseif (y <= 1.1e-99) 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 <= -1.45e-25) tmp = x; elseif (y <= -6.2e-96) tmp = x / (-y / z); elseif (y <= -1.25e-146) tmp = x; elseif (y <= 1.1e-99) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.45e-25], x, If[LessEqual[y, -6.2e-96], N[(x / N[((-y) / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -1.25e-146], x, If[LessEqual[y, 1.1e-99], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -6.2 \cdot 10^{-96}:\\
\;\;\;\;\frac{x}{\frac{-y}{z}}\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-146}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-99}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.45e-25 or -6.1999999999999998e-96 < y < -1.24999999999999989e-146 or 1.10000000000000002e-99 < y Initial program 80.5%
*-commutative80.5%
associate-*l/99.3%
*-commutative99.3%
div-sub99.3%
*-inverses99.3%
Simplified99.3%
Taylor expanded in z around 0 78.3%
if -1.45e-25 < y < -6.1999999999999998e-96Initial program 99.6%
associate-*l/99.8%
Simplified99.8%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 72.6%
associate-*r/72.6%
neg-mul-172.6%
Simplified72.6%
if -1.24999999999999989e-146 < y < 1.10000000000000002e-99Initial program 89.3%
*-commutative89.3%
associate-*l/91.5%
*-commutative91.5%
div-sub91.5%
*-inverses91.5%
Simplified91.5%
Taylor expanded in z around inf 79.0%
mul-1-neg79.0%
*-commutative79.0%
associate-*r/82.6%
distribute-lft-neg-out82.6%
Simplified82.6%
Final simplification79.3%
(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.2%
*-commutative84.2%
associate-*l/97.0%
*-commutative97.0%
div-sub97.0%
*-inverses97.0%
Simplified97.0%
Final simplification97.0%
(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.2%
*-commutative84.2%
associate-*l/97.0%
*-commutative97.0%
div-sub97.0%
*-inverses97.0%
Simplified97.0%
Taylor expanded in z around 0 56.0%
Final simplification56.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 2023331
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:herbie-target
(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))