
(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 (<= z 9.8e-178) (- x (/ (* z x) y)) (- x (* z (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 9.8e-178) {
tmp = x - ((z * x) / y);
} else {
tmp = x - (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 <= 9.8d-178) then
tmp = x - ((z * x) / y)
else
tmp = x - (z * (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 9.8e-178) {
tmp = x - ((z * x) / y);
} else {
tmp = x - (z * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 9.8e-178: tmp = x - ((z * x) / y) else: tmp = x - (z * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 9.8e-178) tmp = Float64(x - Float64(Float64(z * x) / y)); else tmp = Float64(x - Float64(z * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 9.8e-178) tmp = x - ((z * x) / y); else tmp = x - (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 9.8e-178], N[(x - N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 9.8 \cdot 10^{-178}:\\
\;\;\;\;x - \frac{z \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < 9.80000000000000041e-178Initial program 86.4%
associate-*l/80.1%
distribute-rgt-out--75.8%
associate-*r/80.5%
associate-*l/92.4%
*-inverses92.4%
*-lft-identity92.4%
Simplified92.4%
Taylor expanded in z around 0 95.2%
if 9.80000000000000041e-178 < z Initial program 88.4%
associate-*l/92.7%
distribute-rgt-out--85.1%
associate-*r/89.4%
associate-*l/99.9%
*-inverses99.9%
*-lft-identity99.9%
Simplified99.9%
Final simplification97.1%
(FPCore (x y z)
:precision binary64
(if (<= y -3.8e-45)
x
(if (or (<= y 2.1e-55) (and (not (<= y 4e-22)) (<= y 2.9e+23)))
(* z (/ (- x) y))
x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-45) {
tmp = x;
} else if ((y <= 2.1e-55) || (!(y <= 4e-22) && (y <= 2.9e+23))) {
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.8d-45)) then
tmp = x
else if ((y <= 2.1d-55) .or. (.not. (y <= 4d-22)) .and. (y <= 2.9d+23)) 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.8e-45) {
tmp = x;
} else if ((y <= 2.1e-55) || (!(y <= 4e-22) && (y <= 2.9e+23))) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e-45: tmp = x elif (y <= 2.1e-55) or (not (y <= 4e-22) and (y <= 2.9e+23)): tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e-45) tmp = x; elseif ((y <= 2.1e-55) || (!(y <= 4e-22) && (y <= 2.9e+23))) 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 <= -3.8e-45) tmp = x; elseif ((y <= 2.1e-55) || (~((y <= 4e-22)) && (y <= 2.9e+23))) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e-45], x, If[Or[LessEqual[y, 2.1e-55], And[N[Not[LessEqual[y, 4e-22]], $MachinePrecision], LessEqual[y, 2.9e+23]]], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-45}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-55} \lor \neg \left(y \leq 4 \cdot 10^{-22}\right) \land y \leq 2.9 \cdot 10^{+23}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.79999999999999997e-45 or 2.1000000000000002e-55 < y < 4.0000000000000002e-22 or 2.90000000000000013e23 < y Initial program 81.9%
associate-*l/79.3%
Simplified79.3%
Taylor expanded in y around inf 81.7%
if -3.79999999999999997e-45 < y < 2.1000000000000002e-55 or 4.0000000000000002e-22 < y < 2.90000000000000013e23Initial program 93.6%
associate-*l/92.5%
Simplified92.5%
Taylor expanded in y around 0 80.2%
*-commutative80.2%
associate-*r/80.2%
neg-mul-180.2%
distribute-rgt-neg-in80.2%
associate-*l/79.6%
Simplified79.6%
Final simplification80.8%
(FPCore (x y z)
:precision binary64
(if (<= y -2.25e-45)
x
(if (<= y 2.1e-55)
(/ (* z (- x)) y)
(if (<= y 1.35e-22) x (if (<= y 8.5e+22) (* z (/ (- x) y)) x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.25e-45) {
tmp = x;
} else if (y <= 2.1e-55) {
tmp = (z * -x) / y;
} else if (y <= 1.35e-22) {
tmp = x;
} else if (y <= 8.5e+22) {
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 <= (-2.25d-45)) then
tmp = x
else if (y <= 2.1d-55) then
tmp = (z * -x) / y
else if (y <= 1.35d-22) then
tmp = x
else if (y <= 8.5d+22) 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 <= -2.25e-45) {
tmp = x;
} else if (y <= 2.1e-55) {
tmp = (z * -x) / y;
} else if (y <= 1.35e-22) {
tmp = x;
} else if (y <= 8.5e+22) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.25e-45: tmp = x elif y <= 2.1e-55: tmp = (z * -x) / y elif y <= 1.35e-22: tmp = x elif y <= 8.5e+22: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.25e-45) tmp = x; elseif (y <= 2.1e-55) tmp = Float64(Float64(z * Float64(-x)) / y); elseif (y <= 1.35e-22) tmp = x; elseif (y <= 8.5e+22) 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 <= -2.25e-45) tmp = x; elseif (y <= 2.1e-55) tmp = (z * -x) / y; elseif (y <= 1.35e-22) tmp = x; elseif (y <= 8.5e+22) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.25e-45], x, If[LessEqual[y, 2.1e-55], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.35e-22], x, If[LessEqual[y, 8.5e+22], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{-45}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-55}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-22}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+22}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.2499999999999999e-45 or 2.1000000000000002e-55 < y < 1.3500000000000001e-22 or 8.49999999999999979e22 < y Initial program 81.9%
associate-*l/79.3%
Simplified79.3%
Taylor expanded in y around inf 81.7%
if -2.2499999999999999e-45 < y < 2.1000000000000002e-55Initial program 93.2%
Taylor expanded in y around 0 79.6%
mul-1-neg79.6%
distribute-rgt-neg-out79.6%
Simplified79.6%
if 1.3500000000000001e-22 < y < 8.49999999999999979e22Initial program 99.4%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in y around 0 87.8%
*-commutative87.8%
associate-*r/87.8%
neg-mul-187.8%
distribute-rgt-neg-in87.8%
associate-*l/88.2%
Simplified88.2%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (<= y -8.6e+188) x (if (<= y 2.05e+44) (* (/ x y) (- y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e+188) {
tmp = x;
} else if (y <= 2.05e+44) {
tmp = (x / y) * (y - z);
} 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.6d+188)) then
tmp = x
else if (y <= 2.05d+44) then
tmp = (x / y) * (y - z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e+188) {
tmp = x;
} else if (y <= 2.05e+44) {
tmp = (x / y) * (y - z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.6e+188: tmp = x elif y <= 2.05e+44: tmp = (x / y) * (y - z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.6e+188) tmp = x; elseif (y <= 2.05e+44) tmp = Float64(Float64(x / y) * Float64(y - z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.6e+188) tmp = x; elseif (y <= 2.05e+44) tmp = (x / y) * (y - z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.6e+188], x, If[LessEqual[y, 2.05e+44], N[(N[(x / y), $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{+188}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+44}:\\
\;\;\;\;\frac{x}{y} \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.5999999999999997e188 or 2.04999999999999982e44 < y Initial program 76.8%
associate-*l/68.8%
Simplified68.8%
Taylor expanded in y around inf 89.8%
if -8.5999999999999997e188 < y < 2.04999999999999982e44Initial program 92.3%
associate-*l/93.4%
Simplified93.4%
Final simplification92.2%
(FPCore (x y z) :precision binary64 (if (<= z 1.05e+34) x (* y (/ x y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.05e+34) {
tmp = x;
} else {
tmp = y * (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.05d+34) then
tmp = x
else
tmp = y * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.05e+34) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.05e+34: tmp = x else: tmp = y * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.05e+34) tmp = x; else tmp = Float64(y * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.05e+34) tmp = x; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.05e+34], x, N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.05 \cdot 10^{+34}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < 1.05000000000000009e34Initial program 87.7%
associate-*l/80.4%
Simplified80.4%
Taylor expanded in y around inf 62.9%
if 1.05000000000000009e34 < z Initial program 85.6%
Taylor expanded in y around inf 12.7%
associate-/l*28.7%
div-inv31.7%
clear-num31.7%
Applied egg-rr31.7%
Final simplification55.1%
(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 87.2%
associate-*l/85.3%
distribute-rgt-out--79.6%
associate-*r/84.1%
associate-*l/95.5%
*-inverses95.5%
*-lft-identity95.5%
Simplified95.5%
Final simplification95.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 87.2%
associate-*l/85.3%
Simplified85.3%
Taylor expanded in y around inf 53.2%
Final simplification53.2%
(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 2023257
(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))