
(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 (- y z)) y) 1e+161) (/ x (/ y (- y z))) (- x (* z (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y - z)) / y) <= 1e+161) {
tmp = x / (y / (y - z));
} 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 (((x * (y - z)) / y) <= 1d+161) then
tmp = x / (y / (y - z))
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 (((x * (y - z)) / y) <= 1e+161) {
tmp = x / (y / (y - z));
} else {
tmp = x - (z * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * (y - z)) / y) <= 1e+161: tmp = x / (y / (y - z)) else: tmp = x - (z * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y - z)) / y) <= 1e+161) tmp = Float64(x / Float64(y / Float64(y - z))); else tmp = Float64(x - Float64(z * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * (y - z)) / y) <= 1e+161) tmp = x / (y / (y - z)); else tmp = x - (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], 1e+161], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 10^{+161}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (-.f64 y z)) y) < 1e161Initial program 84.5%
associate-*l/80.4%
Simplified80.4%
associate-/r/98.3%
Applied egg-rr98.3%
if 1e161 < (/.f64 (*.f64 x (-.f64 y z)) y) Initial program 77.1%
associate-*l/97.9%
distribute-rgt-out--91.8%
associate-*r/75.1%
associate-*l/98.0%
*-inverses98.0%
*-lft-identity98.0%
Simplified98.0%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (<= y -2.9e-53) x (if (<= y 0.014) (* (/ z y) (- x)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.9e-53) {
tmp = x;
} else if (y <= 0.014) {
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 <= (-2.9d-53)) then
tmp = x
else if (y <= 0.014d0) 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 <= -2.9e-53) {
tmp = x;
} else if (y <= 0.014) {
tmp = (z / y) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.9e-53: tmp = x elif y <= 0.014: tmp = (z / y) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.9e-53) tmp = x; elseif (y <= 0.014) tmp = Float64(Float64(z / y) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.9e-53) tmp = x; elseif (y <= 0.014) tmp = (z / y) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.9e-53], x, If[LessEqual[y, 0.014], N[(N[(z / y), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-53}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 0.014:\\
\;\;\;\;\frac{z}{y} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.8999999999999998e-53 or 0.0140000000000000003 < y Initial program 78.9%
associate-*l/73.5%
Simplified73.5%
Taylor expanded in y around inf 77.6%
if -2.8999999999999998e-53 < y < 0.0140000000000000003Initial program 87.7%
associate-*l/95.1%
Simplified95.1%
associate-/r/93.1%
Applied egg-rr93.1%
Taylor expanded in y around 0 75.8%
associate-*r/75.8%
neg-mul-175.8%
Simplified75.8%
frac-2neg75.8%
div-inv74.5%
distribute-neg-frac74.5%
remove-double-neg74.5%
add-sqr-sqrt41.5%
sqrt-prod29.1%
sqr-neg29.1%
sqrt-unprod0.8%
add-sqr-sqrt1.7%
clear-num1.7%
add-sqr-sqrt0.8%
sqrt-unprod29.1%
sqr-neg29.1%
sqrt-prod41.5%
add-sqr-sqrt74.6%
Applied egg-rr74.6%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= y -4.8e-56) x (if (<= y 0.044) (* z (/ (- x) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-56) {
tmp = x;
} else if (y <= 0.044) {
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 <= (-4.8d-56)) then
tmp = x
else if (y <= 0.044d0) 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 <= -4.8e-56) {
tmp = x;
} else if (y <= 0.044) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e-56: tmp = x elif y <= 0.044: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e-56) tmp = x; elseif (y <= 0.044) 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 <= -4.8e-56) tmp = x; elseif (y <= 0.044) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e-56], x, If[LessEqual[y, 0.044], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-56}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 0.044:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.80000000000000001e-56 or 0.043999999999999997 < y Initial program 78.9%
associate-*l/73.5%
Simplified73.5%
Taylor expanded in y around inf 77.6%
if -4.80000000000000001e-56 < y < 0.043999999999999997Initial program 87.7%
associate-*l/95.1%
Simplified95.1%
Taylor expanded in y around 0 74.7%
*-commutative74.7%
associate-*r/74.7%
neg-mul-174.7%
distribute-rgt-neg-in74.7%
associate-*l/80.4%
Simplified80.4%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.9e-55) x (if (<= y 5e-35) (/ z (/ (- y) x)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-55) {
tmp = x;
} else if (y <= 5e-35) {
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.9d-55)) then
tmp = x
else if (y <= 5d-35) 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.9e-55) {
tmp = x;
} else if (y <= 5e-35) {
tmp = z / (-y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e-55: tmp = x elif y <= 5e-35: tmp = z / (-y / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e-55) tmp = x; elseif (y <= 5e-35) tmp = Float64(z / Float64(Float64(-y) / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.9e-55) tmp = x; elseif (y <= 5e-35) tmp = z / (-y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e-55], x, If[LessEqual[y, 5e-35], N[(z / N[((-y) / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-55}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-35}:\\
\;\;\;\;\frac{z}{\frac{-y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.8999999999999998e-55 or 4.99999999999999964e-35 < y Initial program 79.8%
associate-*l/74.6%
Simplified74.6%
Taylor expanded in y around inf 76.5%
if -1.8999999999999998e-55 < y < 4.99999999999999964e-35Initial program 87.1%
associate-*l/94.9%
Simplified94.9%
Taylor expanded in y around 0 76.0%
*-commutative76.0%
associate-*r/76.0%
neg-mul-176.0%
distribute-rgt-neg-in76.0%
associate-*l/81.9%
Simplified81.9%
associate-*l/76.0%
distribute-rgt-neg-out76.0%
distribute-lft-neg-out76.0%
*-commutative76.0%
associate-/l*82.3%
frac-2neg82.3%
add-sqr-sqrt37.5%
sqrt-unprod26.9%
sqr-neg26.9%
sqrt-unprod0.8%
add-sqr-sqrt1.6%
add-sqr-sqrt1.0%
sqrt-unprod34.2%
sqr-neg34.2%
sqrt-unprod44.5%
add-sqr-sqrt82.3%
Applied egg-rr82.3%
Final simplification79.1%
(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 83.1%
associate-*l/83.7%
distribute-rgt-out--79.8%
associate-*r/83.9%
associate-*l/96.3%
*-inverses96.3%
*-lft-identity96.3%
Simplified96.3%
Taylor expanded in x around 0 95.8%
Final simplification95.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 83.1%
associate-*l/83.7%
distribute-rgt-out--79.8%
associate-*r/83.9%
associate-*l/96.3%
*-inverses96.3%
*-lft-identity96.3%
Simplified96.3%
Final simplification96.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 83.1%
associate-*l/83.7%
Simplified83.7%
Taylor expanded in y around inf 49.5%
Final simplification49.5%
(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 2023240
(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))