
(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 -5e+174) (- x (/ (* z x) y)) (if (<= z 1.45e-61) (* x (- 1.0 (/ z y))) (- x (* z (/ x y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e+174) {
tmp = x - ((z * x) / y);
} else if (z <= 1.45e-61) {
tmp = x * (1.0 - (z / 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 <= (-5d+174)) then
tmp = x - ((z * x) / y)
else if (z <= 1.45d-61) then
tmp = x * (1.0d0 - (z / 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 <= -5e+174) {
tmp = x - ((z * x) / y);
} else if (z <= 1.45e-61) {
tmp = x * (1.0 - (z / y));
} else {
tmp = x - (z * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5e+174: tmp = x - ((z * x) / y) elif z <= 1.45e-61: tmp = x * (1.0 - (z / y)) else: tmp = x - (z * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5e+174) tmp = Float64(x - Float64(Float64(z * x) / y)); elseif (z <= 1.45e-61) tmp = Float64(x * Float64(1.0 - Float64(z / 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 <= -5e+174) tmp = x - ((z * x) / y); elseif (z <= 1.45e-61) tmp = x * (1.0 - (z / y)); else tmp = x - (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5e+174], N[(x - N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.45e-61], N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+174}:\\
\;\;\;\;x - \frac{z \cdot x}{y}\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-61}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -4.9999999999999997e174Initial program 95.8%
associate-*l/83.9%
distribute-rgt-out--79.8%
associate-*r/86.5%
associate-*l/90.4%
*-inverses90.4%
*-lft-identity90.4%
Simplified90.4%
Taylor expanded in z around 0 95.8%
if -4.9999999999999997e174 < z < 1.45e-61Initial program 83.4%
*-un-lft-identity83.4%
times-frac99.3%
Applied egg-rr99.3%
clear-num99.1%
frac-2neg99.1%
frac-times80.4%
*-un-lft-identity80.4%
sub-neg80.4%
distribute-neg-in80.4%
remove-double-neg80.4%
Applied egg-rr80.4%
*-lft-identity80.4%
times-frac99.1%
remove-double-div99.3%
+-commutative99.3%
unsub-neg99.3%
Simplified99.3%
Taylor expanded in z around 0 99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
if 1.45e-61 < z Initial program 87.2%
associate-*l/94.1%
distribute-rgt-out--85.6%
associate-*r/90.4%
associate-*l/99.9%
*-inverses99.9%
*-lft-identity99.9%
Simplified99.9%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.8e+96) (not (<= x 7.2e-218))) (* x (- 1.0 (/ z y))) (- x (* z (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e+96) || !(x <= 7.2e-218)) {
tmp = x * (1.0 - (z / 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 ((x <= (-9.8d+96)) .or. (.not. (x <= 7.2d-218))) then
tmp = x * (1.0d0 - (z / 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 ((x <= -9.8e+96) || !(x <= 7.2e-218)) {
tmp = x * (1.0 - (z / y));
} else {
tmp = x - (z * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.8e+96) or not (x <= 7.2e-218): tmp = x * (1.0 - (z / y)) else: tmp = x - (z * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.8e+96) || !(x <= 7.2e-218)) tmp = Float64(x * Float64(1.0 - Float64(z / 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 ((x <= -9.8e+96) || ~((x <= 7.2e-218))) tmp = x * (1.0 - (z / y)); else tmp = x - (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.8e+96], N[Not[LessEqual[x, 7.2e-218]], $MachinePrecision]], N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{+96} \lor \neg \left(x \leq 7.2 \cdot 10^{-218}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if x < -9.7999999999999993e96 or 7.20000000000000023e-218 < x Initial program 83.0%
*-un-lft-identity83.0%
times-frac99.3%
Applied egg-rr99.3%
clear-num99.1%
frac-2neg99.1%
frac-times86.1%
*-un-lft-identity86.1%
sub-neg86.1%
distribute-neg-in86.1%
remove-double-neg86.1%
Applied egg-rr86.1%
*-lft-identity86.1%
times-frac99.1%
remove-double-div99.3%
+-commutative99.3%
unsub-neg99.3%
Simplified99.3%
Taylor expanded in z around 0 99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
if -9.7999999999999993e96 < x < 7.20000000000000023e-218Initial program 89.5%
associate-*l/81.6%
distribute-rgt-out--81.6%
associate-*r/93.5%
associate-*l/98.0%
*-inverses98.0%
*-lft-identity98.0%
Simplified98.0%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.9e-37) x (if (<= y 1.08e+15) (* x (/ (- z) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-37) {
tmp = x;
} else if (y <= 1.08e+15) {
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 <= (-1.9d-37)) then
tmp = x
else if (y <= 1.08d+15) 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 <= -1.9e-37) {
tmp = x;
} else if (y <= 1.08e+15) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e-37: tmp = x elif y <= 1.08e+15: tmp = x * (-z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e-37) tmp = x; elseif (y <= 1.08e+15) 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 <= -1.9e-37) tmp = x; elseif (y <= 1.08e+15) tmp = x * (-z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e-37], x, If[LessEqual[y, 1.08e+15], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-37}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.08 \cdot 10^{+15}:\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.9000000000000002e-37 or 1.08e15 < y Initial program 76.4%
Taylor expanded in y around inf 81.9%
if -1.9000000000000002e-37 < y < 1.08e15Initial program 93.5%
Taylor expanded in y around 0 70.3%
mul-1-neg70.3%
associate-*l/65.7%
*-commutative65.7%
distribute-rgt-neg-in65.7%
distribute-frac-neg65.7%
Simplified65.7%
Final simplification73.3%
(FPCore (x y z) :precision binary64 (if (<= y -7.2e-37) x (if (<= y 45000000000.0) (* z (/ (- x) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e-37) {
tmp = x;
} else if (y <= 45000000000.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 <= (-7.2d-37)) then
tmp = x
else if (y <= 45000000000.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 <= -7.2e-37) {
tmp = x;
} else if (y <= 45000000000.0) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.2e-37: tmp = x elif y <= 45000000000.0: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.2e-37) tmp = x; elseif (y <= 45000000000.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 <= -7.2e-37) tmp = x; elseif (y <= 45000000000.0) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.2e-37], x, If[LessEqual[y, 45000000000.0], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-37}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 45000000000:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.20000000000000014e-37 or 4.5e10 < y Initial program 76.4%
Taylor expanded in y around inf 81.9%
if -7.20000000000000014e-37 < y < 4.5e10Initial program 93.5%
Taylor expanded in y around 0 70.3%
mul-1-neg70.3%
associate-*r/71.8%
*-commutative71.8%
distribute-rgt-neg-in71.8%
Simplified71.8%
Final simplification76.5%
(FPCore (x y z) :precision binary64 (if (<= y -6.5e-37) x (if (<= y 90000000000000.0) (/ z (/ (- y) x)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e-37) {
tmp = x;
} else if (y <= 90000000000000.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 <= (-6.5d-37)) then
tmp = x
else if (y <= 90000000000000.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 <= -6.5e-37) {
tmp = x;
} else if (y <= 90000000000000.0) {
tmp = z / (-y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.5e-37: tmp = x elif y <= 90000000000000.0: tmp = z / (-y / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.5e-37) tmp = x; elseif (y <= 90000000000000.0) 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 <= -6.5e-37) tmp = x; elseif (y <= 90000000000000.0) tmp = z / (-y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.5e-37], x, If[LessEqual[y, 90000000000000.0], N[(z / N[((-y) / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-37}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 90000000000000:\\
\;\;\;\;\frac{z}{\frac{-y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.5000000000000001e-37 or 9e13 < y Initial program 76.4%
Taylor expanded in y around inf 81.9%
if -6.5000000000000001e-37 < y < 9e13Initial program 93.5%
Taylor expanded in y around 0 70.3%
mul-1-neg70.3%
associate-*l/65.7%
*-commutative65.7%
distribute-rgt-neg-in65.7%
distribute-frac-neg65.7%
Simplified65.7%
associate-*r/70.3%
distribute-rgt-neg-out70.3%
distribute-lft-neg-out70.3%
*-commutative70.3%
associate-/l*71.9%
frac-2neg71.9%
add-sqr-sqrt36.7%
sqrt-unprod24.9%
sqr-neg24.9%
sqrt-unprod0.8%
add-sqr-sqrt1.6%
add-sqr-sqrt0.8%
sqrt-unprod23.9%
sqr-neg23.9%
sqrt-unprod29.1%
add-sqr-sqrt71.9%
Applied egg-rr71.9%
Final simplification76.6%
(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 85.6%
*-un-lft-identity85.6%
times-frac95.1%
Applied egg-rr95.1%
clear-num95.0%
frac-2neg95.0%
frac-times84.2%
*-un-lft-identity84.2%
sub-neg84.2%
distribute-neg-in84.2%
remove-double-neg84.2%
Applied egg-rr84.2%
*-lft-identity84.2%
times-frac95.0%
remove-double-div95.1%
+-commutative95.1%
unsub-neg95.1%
Simplified95.1%
Taylor expanded in z around 0 95.1%
mul-1-neg95.1%
unsub-neg95.1%
Simplified95.1%
Final simplification95.1%
(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 85.6%
Taylor expanded in y around inf 52.3%
Final simplification52.3%
(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 2023175
(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))