
(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 7 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 (<= x 8.6e-112) (- x (/ (* x z) y)) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= 8.6e-112) {
tmp = x - ((x * z) / y);
} else {
tmp = x - (x / (y / z));
}
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 (x <= 8.6d-112) then
tmp = x - ((x * z) / y)
else
tmp = x - (x / (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 8.6e-112) {
tmp = x - ((x * z) / y);
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 8.6e-112: tmp = x - ((x * z) / y) else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 8.6e-112) tmp = Float64(x - Float64(Float64(x * z) / y)); else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 8.6e-112) tmp = x - ((x * z) / y); else tmp = x - (x / (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 8.6e-112], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.6 \cdot 10^{-112}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if x < 8.5999999999999996e-112Initial program 90.5%
associate-*l/80.3%
distribute-rgt-out--76.5%
associate-*r/84.1%
associate-*l/92.0%
*-inverses92.0%
*-lft-identity92.0%
Simplified92.0%
Taylor expanded in z around 0 96.4%
if 8.5999999999999996e-112 < x Initial program 79.6%
associate-*l/88.7%
distribute-rgt-out--83.1%
associate-*r/70.7%
associate-*l/90.7%
*-inverses90.7%
*-lft-identity90.7%
Simplified90.7%
Taylor expanded in z around 0 92.8%
*-commutative92.8%
associate-/l*99.8%
Simplified99.8%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (<= y -5.9e-6) x (if (<= y 13500000000000.0) (* z (/ (- x) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.9e-6) {
tmp = x;
} else if (y <= 13500000000000.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 <= (-5.9d-6)) then
tmp = x
else if (y <= 13500000000000.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 <= -5.9e-6) {
tmp = x;
} else if (y <= 13500000000000.0) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.9e-6: tmp = x elif y <= 13500000000000.0: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.9e-6) tmp = x; elseif (y <= 13500000000000.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 <= -5.9e-6) tmp = x; elseif (y <= 13500000000000.0) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.9e-6], x, If[LessEqual[y, 13500000000000.0], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.9 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 13500000000000:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.90000000000000026e-6 or 1.35e13 < y Initial program 76.0%
associate-*l/78.8%
distribute-rgt-out--78.8%
associate-*r/72.2%
associate-*l/96.3%
*-inverses96.3%
*-lft-identity96.3%
Simplified96.3%
Taylor expanded in z around 0 82.3%
if -5.90000000000000026e-6 < y < 1.35e13Initial program 96.2%
associate-*l/87.4%
distribute-rgt-out--78.9%
associate-*r/85.7%
associate-*l/87.2%
*-inverses87.2%
*-lft-identity87.2%
Simplified87.2%
Taylor expanded in z around 0 96.9%
Taylor expanded in z around inf 82.1%
associate-*r/77.6%
neg-mul-177.6%
distribute-rgt-neg-in77.6%
distribute-frac-neg77.6%
Simplified77.6%
Final simplification79.8%
(FPCore (x y z) :precision binary64 (if (<= y -3.3e-7) x (if (<= y 31000000000000.0) (/ (- z) (/ y x)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.3e-7) {
tmp = x;
} else if (y <= 31000000000000.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 <= (-3.3d-7)) then
tmp = x
else if (y <= 31000000000000.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 <= -3.3e-7) {
tmp = x;
} else if (y <= 31000000000000.0) {
tmp = -z / (y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.3e-7: tmp = x elif y <= 31000000000000.0: tmp = -z / (y / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.3e-7) tmp = x; elseif (y <= 31000000000000.0) 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.3e-7) tmp = x; elseif (y <= 31000000000000.0) tmp = -z / (y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.3e-7], x, If[LessEqual[y, 31000000000000.0], N[((-z) / N[(y / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 31000000000000:\\
\;\;\;\;\frac{-z}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.3000000000000002e-7 or 3.1e13 < y Initial program 76.0%
associate-*l/78.8%
distribute-rgt-out--78.8%
associate-*r/72.2%
associate-*l/96.3%
*-inverses96.3%
*-lft-identity96.3%
Simplified96.3%
Taylor expanded in z around 0 82.3%
if -3.3000000000000002e-7 < y < 3.1e13Initial program 96.2%
associate-*l/87.4%
distribute-rgt-out--78.9%
associate-*r/85.7%
associate-*l/87.2%
*-inverses87.2%
*-lft-identity87.2%
Simplified87.2%
Taylor expanded in z around inf 82.1%
mul-1-neg82.1%
associate-*l/73.2%
distribute-rgt-neg-in73.2%
Simplified73.2%
distribute-rgt-neg-out73.2%
associate-*l/82.1%
associate-/l*79.0%
distribute-neg-frac79.0%
Applied egg-rr79.0%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (<= y -0.054) x (if (<= y 3100000000000.0) (/ (* z (- x)) y) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.054) {
tmp = x;
} else if (y <= 3100000000000.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.054d0)) then
tmp = x
else if (y <= 3100000000000.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.054) {
tmp = x;
} else if (y <= 3100000000000.0) {
tmp = (z * -x) / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.054: tmp = x elif y <= 3100000000000.0: tmp = (z * -x) / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.054) tmp = x; elseif (y <= 3100000000000.0) tmp = Float64(Float64(z * Float64(-x)) / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.054) tmp = x; elseif (y <= 3100000000000.0) tmp = (z * -x) / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.054], x, If[LessEqual[y, 3100000000000.0], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.054:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3100000000000:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.0539999999999999994 or 3.1e12 < y Initial program 76.0%
associate-*l/78.8%
distribute-rgt-out--78.8%
associate-*r/72.2%
associate-*l/96.3%
*-inverses96.3%
*-lft-identity96.3%
Simplified96.3%
Taylor expanded in z around 0 82.3%
if -0.0539999999999999994 < y < 3.1e12Initial program 96.2%
associate-*l/87.4%
distribute-rgt-out--78.9%
associate-*r/85.7%
associate-*l/87.2%
*-inverses87.2%
*-lft-identity87.2%
Simplified87.2%
Taylor expanded in z around inf 82.1%
associate-*r/82.1%
neg-mul-182.1%
distribute-rgt-neg-in82.1%
Simplified82.1%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (<= z 1.7e+225) (- x (/ x (/ y z))) (/ (* z (- x)) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.7e+225) {
tmp = x - (x / (y / z));
} else {
tmp = (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 <= 1.7d+225) then
tmp = x - (x / (y / z))
else
tmp = (z * -x) / y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.7e+225) {
tmp = x - (x / (y / z));
} else {
tmp = (z * -x) / y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.7e+225: tmp = x - (x / (y / z)) else: tmp = (z * -x) / y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.7e+225) tmp = Float64(x - Float64(x / Float64(y / z))); else tmp = Float64(Float64(z * Float64(-x)) / y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.7e+225) tmp = x - (x / (y / z)); else tmp = (z * -x) / y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.7e+225], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.7 \cdot 10^{+225}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\end{array}
\end{array}
if z < 1.70000000000000009e225Initial program 86.2%
associate-*l/82.6%
distribute-rgt-out--78.7%
associate-*r/79.1%
associate-*l/91.6%
*-inverses91.6%
*-lft-identity91.6%
Simplified91.6%
Taylor expanded in z around 0 95.1%
*-commutative95.1%
associate-/l*97.3%
Simplified97.3%
if 1.70000000000000009e225 < z Initial program 90.6%
associate-*l/90.8%
distribute-rgt-out--81.3%
associate-*r/81.6%
associate-*l/90.8%
*-inverses90.8%
*-lft-identity90.8%
Simplified90.8%
Taylor expanded in z around inf 90.8%
associate-*r/90.8%
neg-mul-190.8%
distribute-rgt-neg-in90.8%
Simplified90.8%
Final simplification96.8%
(FPCore (x y z) :precision binary64 (- x (* z (/ x y))))
double code(double x, double y, double z) {
return x - (z * (x / 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 - (z * (x / y))
end function
public static double code(double x, double y, double z) {
return x - (z * (x / y));
}
def code(x, y, z): return x - (z * (x / y))
function code(x, y, z) return Float64(x - Float64(z * Float64(x / y))) end
function tmp = code(x, y, z) tmp = x - (z * (x / y)); end
code[x_, y_, z_] := N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot \frac{x}{y}
\end{array}
Initial program 86.6%
associate-*l/83.3%
distribute-rgt-out--78.9%
associate-*r/79.3%
associate-*l/91.5%
*-inverses91.5%
*-lft-identity91.5%
Simplified91.5%
Final simplification91.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 86.6%
associate-*l/83.3%
distribute-rgt-out--78.9%
associate-*r/79.3%
associate-*l/91.5%
*-inverses91.5%
*-lft-identity91.5%
Simplified91.5%
Taylor expanded in z around 0 47.9%
Final simplification47.9%
(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 2023176
(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))