
(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 8 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 1.2e-254) (- x (/ (* x z) y)) (- x (/ z (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.2e-254) {
tmp = x - ((x * z) / y);
} else {
tmp = x - (z / (y / 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 (x <= 1.2d-254) then
tmp = x - ((x * z) / y)
else
tmp = x - (z / (y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 1.2e-254) {
tmp = x - ((x * z) / y);
} else {
tmp = x - (z / (y / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.2e-254: tmp = x - ((x * z) / y) else: tmp = x - (z / (y / x)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.2e-254) tmp = Float64(x - Float64(Float64(x * z) / y)); else tmp = Float64(x - Float64(z / Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 1.2e-254) tmp = x - ((x * z) / y); else tmp = x - (z / (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.2e-254], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.2 \cdot 10^{-254}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{\frac{y}{x}}\\
\end{array}
\end{array}
if x < 1.20000000000000001e-254Initial program 91.1%
associate-*l/81.4%
distribute-rgt-out--76.1%
associate-*r/82.9%
associate-*l/92.4%
*-inverses92.4%
*-lft-identity92.4%
Simplified92.4%
Taylor expanded in z around 0 97.6%
if 1.20000000000000001e-254 < x Initial program 88.4%
associate-*l/92.5%
distribute-rgt-out--87.6%
associate-*r/88.0%
associate-*l/97.7%
*-inverses97.7%
*-lft-identity97.7%
Simplified97.7%
clear-num97.6%
un-div-inv98.4%
Applied egg-rr98.4%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e-7) x (if (<= y 4.5e+53) (* x (/ (- z) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-7) {
tmp = x;
} else if (y <= 4.5e+53) {
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 <= (-5.2d-7)) then
tmp = x
else if (y <= 4.5d+53) 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 <= -5.2e-7) {
tmp = x;
} else if (y <= 4.5e+53) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e-7: tmp = x elif y <= 4.5e+53: tmp = x * (-z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e-7) tmp = x; elseif (y <= 4.5e+53) 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 <= -5.2e-7) tmp = x; elseif (y <= 4.5e+53) tmp = x * (-z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e-7], x, If[LessEqual[y, 4.5e+53], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+53}:\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.19999999999999998e-7 or 4.5000000000000002e53 < y Initial program 81.5%
Taylor expanded in y around inf 79.2%
if -5.19999999999999998e-7 < y < 4.5000000000000002e53Initial program 96.3%
Taylor expanded in y around 0 77.1%
mul-1-neg77.1%
associate-*l/69.5%
*-commutative69.5%
distribute-rgt-neg-in69.5%
distribute-frac-neg69.5%
Simplified69.5%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= y -5e-7) x (if (<= y 5.5e+49) (* z (/ (- x) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5e-7) {
tmp = x;
} else if (y <= 5.5e+49) {
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 <= (-5d-7)) then
tmp = x
else if (y <= 5.5d+49) 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 <= -5e-7) {
tmp = x;
} else if (y <= 5.5e+49) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5e-7: tmp = x elif y <= 5.5e+49: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5e-7) tmp = x; elseif (y <= 5.5e+49) 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 <= -5e-7) tmp = x; elseif (y <= 5.5e+49) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5e-7], x, If[LessEqual[y, 5.5e+49], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+49}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.99999999999999977e-7 or 5.50000000000000042e49 < y Initial program 81.5%
Taylor expanded in y around inf 79.2%
if -4.99999999999999977e-7 < y < 5.50000000000000042e49Initial program 96.3%
Taylor expanded in y around 0 77.1%
mul-1-neg77.1%
associate-*r/74.8%
*-commutative74.8%
distribute-rgt-neg-in74.8%
Simplified74.8%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (<= y -3.6e-7) x (if (<= y 6.5e+49) (/ (* z (- x)) y) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.6e-7) {
tmp = x;
} else if (y <= 6.5e+49) {
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 <= (-3.6d-7)) then
tmp = x
else if (y <= 6.5d+49) 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 <= -3.6e-7) {
tmp = x;
} else if (y <= 6.5e+49) {
tmp = (z * -x) / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.6e-7: tmp = x elif y <= 6.5e+49: tmp = (z * -x) / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.6e-7) tmp = x; elseif (y <= 6.5e+49) 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 <= -3.6e-7) tmp = x; elseif (y <= 6.5e+49) tmp = (z * -x) / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.6e-7], x, If[LessEqual[y, 6.5e+49], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+49}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.59999999999999994e-7 or 6.5000000000000005e49 < y Initial program 81.5%
Taylor expanded in y around inf 79.2%
if -3.59999999999999994e-7 < y < 6.5000000000000005e49Initial program 96.3%
Taylor expanded in y around 0 77.1%
associate-*r/77.1%
neg-mul-177.1%
distribute-rgt-neg-in77.1%
Simplified77.1%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (<= y -2e-92) x (if (<= y 1.08e-75) (* y (/ x y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-92) {
tmp = x;
} else if (y <= 1.08e-75) {
tmp = y * (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 <= (-2d-92)) then
tmp = x
else if (y <= 1.08d-75) then
tmp = y * (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 <= -2e-92) {
tmp = x;
} else if (y <= 1.08e-75) {
tmp = y * (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e-92: tmp = x elif y <= 1.08e-75: tmp = y * (x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e-92) tmp = x; elseif (y <= 1.08e-75) tmp = Float64(y * Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e-92) tmp = x; elseif (y <= 1.08e-75) tmp = y * (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e-92], x, If[LessEqual[y, 1.08e-75], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-92}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.08 \cdot 10^{-75}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.99999999999999998e-92 or 1.08e-75 < y Initial program 86.2%
Taylor expanded in y around inf 65.3%
if -1.99999999999999998e-92 < y < 1.08e-75Initial program 95.2%
Taylor expanded in y around inf 18.5%
associate-/l*29.7%
div-inv30.3%
clear-num30.4%
Applied egg-rr30.4%
Final simplification51.2%
(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 89.8%
associate-*l/86.8%
distribute-rgt-out--81.7%
associate-*r/85.3%
associate-*l/95.0%
*-inverses95.0%
*-lft-identity95.0%
Simplified95.0%
Final simplification95.0%
(FPCore (x y z) :precision binary64 (- x (/ z (/ y x))))
double code(double x, double y, double z) {
return x - (z / (y / 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 - (z / (y / x))
end function
public static double code(double x, double y, double z) {
return x - (z / (y / x));
}
def code(x, y, z): return x - (z / (y / x))
function code(x, y, z) return Float64(x - Float64(z / Float64(y / x))) end
function tmp = code(x, y, z) tmp = x - (z / (y / x)); end
code[x_, y_, z_] := N[(x - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{z}{\frac{y}{x}}
\end{array}
Initial program 89.8%
associate-*l/86.8%
distribute-rgt-out--81.7%
associate-*r/85.3%
associate-*l/95.0%
*-inverses95.0%
*-lft-identity95.0%
Simplified95.0%
clear-num94.9%
un-div-inv95.9%
Applied egg-rr95.9%
Final simplification95.9%
(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 89.8%
Taylor expanded in y around inf 47.6%
Final simplification47.6%
(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 2023221
(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))