
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(if (or (<= d -2.4e+129) (not (<= d 4.2e+136)))
(fma (/ 1.0 (hypot d c)) (* c (/ b (hypot d c))) (/ a (- d)))
(fma
(/ c (hypot c d))
(/ b (hypot c d))
(* a (/ (- d) (pow (hypot c d) 2.0))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.4e+129) || !(d <= 4.2e+136)) {
tmp = fma((1.0 / hypot(d, c)), (c * (b / hypot(d, c))), (a / -d));
} else {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (-d / pow(hypot(c, d), 2.0))));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.4e+129) || !(d <= 4.2e+136)) tmp = fma(Float64(1.0 / hypot(d, c)), Float64(c * Float64(b / hypot(d, c))), Float64(a / Float64(-d))); else tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0)))); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.4e+129], N[Not[LessEqual[d, 4.2e+136]], $MachinePrecision]], N[(N[(1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a / (-d)), $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[((-d) / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.4 \cdot 10^{+129} \lor \neg \left(d \leq 4.2 \cdot 10^{+136}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(d, c\right)}, c \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}, \frac{a}{-d}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
\end{array}
\end{array}
if d < -2.3999999999999999e129 or 4.1999999999999998e136 < d Initial program 28.1%
div-sub28.1%
*-un-lft-identity28.1%
add-sqr-sqrt28.1%
times-frac28.1%
fma-neg28.1%
hypot-define28.1%
hypot-define31.4%
associate-/l*37.8%
add-sqr-sqrt37.8%
pow237.8%
hypot-define37.8%
Applied egg-rr37.8%
hypot-undefine34.4%
unpow234.4%
unpow234.4%
+-commutative34.4%
unpow234.4%
unpow234.4%
hypot-define37.8%
*-commutative37.8%
associate-/l*43.5%
hypot-undefine34.8%
unpow234.8%
unpow234.8%
+-commutative34.8%
unpow234.8%
unpow234.8%
hypot-define43.5%
distribute-rgt-neg-in43.5%
distribute-frac-neg43.5%
Simplified43.5%
Taylor expanded in d around inf 94.0%
associate-*r/94.0%
neg-mul-194.0%
Simplified94.0%
if -2.3999999999999999e129 < d < 4.1999999999999998e136Initial program 69.2%
div-sub68.0%
*-commutative68.0%
add-sqr-sqrt68.0%
times-frac72.9%
fma-neg72.9%
hypot-define72.9%
hypot-define89.3%
associate-/l*91.6%
add-sqr-sqrt91.6%
pow291.6%
hypot-define91.6%
Applied egg-rr91.6%
Final simplification92.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 2e+215)))
(fma (/ 1.0 (hypot d c)) (* c (/ b (hypot d c))) (/ (- a) d))
(* (/ 1.0 (hypot c d)) (/ (fma b c (* d (- a))) (hypot c d))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 2e+215)) {
tmp = fma((1.0 / hypot(d, c)), (c * (b / hypot(d, c))), (-a / d));
} else {
tmp = (1.0 / hypot(c, d)) * (fma(b, c, (d * -a)) / hypot(c, d));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 2e+215)) tmp = fma(Float64(1.0 / hypot(d, c)), Float64(c * Float64(b / hypot(d, c))), Float64(Float64(-a) / d)); else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(d * Float64(-a))) / hypot(c, d))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 2e+215]], $MachinePrecision]], N[(N[(1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{+215}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(d, c\right)}, c \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}, \frac{-a}{d}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0 or 1.99999999999999981e215 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.5%
div-sub14.2%
*-un-lft-identity14.2%
add-sqr-sqrt14.2%
times-frac14.2%
fma-neg14.2%
hypot-define14.2%
hypot-define15.9%
associate-/l*25.9%
add-sqr-sqrt25.9%
pow225.9%
hypot-define25.9%
Applied egg-rr25.9%
hypot-undefine24.0%
unpow224.0%
unpow224.0%
+-commutative24.0%
unpow224.0%
unpow224.0%
hypot-define25.9%
*-commutative25.9%
associate-/l*57.2%
hypot-undefine34.6%
unpow234.6%
unpow234.6%
+-commutative34.6%
unpow234.6%
unpow234.6%
hypot-define57.2%
distribute-rgt-neg-in57.2%
distribute-frac-neg57.2%
Simplified57.2%
Taylor expanded in d around inf 74.0%
associate-*r/74.0%
neg-mul-174.0%
Simplified74.0%
if -inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999981e215Initial program 78.6%
*-un-lft-identity78.6%
add-sqr-sqrt78.6%
times-frac78.6%
hypot-define78.6%
fma-neg78.6%
distribute-rgt-neg-in78.6%
hypot-define97.8%
Applied egg-rr97.8%
Final simplification89.3%
(FPCore (a b c d)
:precision binary64
(if (<= d -2.05e+136)
(/ (- (* b (/ c d)) a) d)
(if (<= d -7.3e-78)
(* (/ 1.0 (hypot c d)) (/ (fma b c (* d (- a))) (hypot c d)))
(if (<= d 1.9e+49) (/ (- b (* (/ d c) a)) c) (/ (- (* c (/ b d)) a) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.05e+136) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= -7.3e-78) {
tmp = (1.0 / hypot(c, d)) * (fma(b, c, (d * -a)) / hypot(c, d));
} else if (d <= 1.9e+49) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -2.05e+136) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (d <= -7.3e-78) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(d * Float64(-a))) / hypot(c, d))); elseif (d <= 1.9e+49) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.05e+136], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -7.3e-78], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.9e+49], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.05 \cdot 10^{+136}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;d \leq -7.3 \cdot 10^{-78}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+49}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -2.0499999999999999e136Initial program 25.2%
div-sub25.2%
*-un-lft-identity25.2%
add-sqr-sqrt25.2%
times-frac25.2%
fma-neg25.2%
hypot-define25.2%
hypot-define27.4%
associate-/l*35.9%
add-sqr-sqrt35.9%
pow235.9%
hypot-define35.9%
Applied egg-rr35.9%
hypot-undefine33.5%
unpow233.5%
unpow233.5%
+-commutative33.5%
unpow233.5%
unpow233.5%
hypot-define35.9%
*-commutative35.9%
associate-/l*41.7%
hypot-undefine34.0%
unpow234.0%
unpow234.0%
+-commutative34.0%
unpow234.0%
unpow234.0%
hypot-define41.7%
distribute-rgt-neg-in41.7%
distribute-frac-neg41.7%
Simplified41.7%
Taylor expanded in d around inf 86.6%
associate-*r/97.7%
+-commutative97.7%
associate-*r/86.6%
neg-mul-186.6%
sub-neg86.6%
associate-*r/97.7%
Simplified97.7%
if -2.0499999999999999e136 < d < -7.29999999999999981e-78Initial program 67.0%
*-un-lft-identity67.0%
add-sqr-sqrt67.0%
times-frac67.2%
hypot-define67.2%
fma-neg67.2%
distribute-rgt-neg-in67.2%
hypot-define85.6%
Applied egg-rr85.6%
if -7.29999999999999981e-78 < d < 1.8999999999999999e49Initial program 68.9%
Taylor expanded in c around inf 87.9%
mul-1-neg87.9%
unsub-neg87.9%
associate-/l*88.0%
Simplified88.0%
if 1.8999999999999999e49 < d Initial program 45.5%
Taylor expanded in d around -inf 77.8%
mul-1-neg77.8%
+-commutative77.8%
remove-double-neg77.8%
sub-neg77.8%
neg-mul-177.8%
distribute-neg-frac277.8%
cancel-sign-sub-inv77.8%
metadata-eval77.8%
*-lft-identity77.8%
+-commutative77.8%
mul-1-neg77.8%
unsub-neg77.8%
*-commutative77.8%
associate-/l*80.1%
Simplified80.1%
Final simplification87.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.8e+20) (not (<= d 3e+49))) (/ (- (* b (/ c d)) a) d) (/ (- b (* (/ d c) a)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+20) || !(d <= 3e+49)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-1.8d+20)) .or. (.not. (d <= 3d+49))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - ((d / c) * a)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+20) || !(d <= 3e+49)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.8e+20) or not (d <= 3e+49): tmp = ((b * (c / d)) - a) / d else: tmp = (b - ((d / c) * a)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.8e+20) || !(d <= 3e+49)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.8e+20) || ~((d <= 3e+49))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - ((d / c) * a)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.8e+20], N[Not[LessEqual[d, 3e+49]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{+20} \lor \neg \left(d \leq 3 \cdot 10^{+49}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if d < -1.8e20 or 3.0000000000000002e49 < d Initial program 40.5%
div-sub40.5%
*-un-lft-identity40.5%
add-sqr-sqrt40.5%
times-frac40.4%
fma-neg40.5%
hypot-define40.5%
hypot-define45.5%
associate-/l*52.4%
add-sqr-sqrt52.4%
pow252.4%
hypot-define52.4%
Applied egg-rr52.4%
hypot-undefine47.3%
unpow247.3%
unpow247.3%
+-commutative47.3%
unpow247.3%
unpow247.3%
hypot-define52.4%
*-commutative52.4%
associate-/l*59.5%
hypot-undefine49.2%
unpow249.2%
unpow249.2%
+-commutative49.2%
unpow249.2%
unpow249.2%
hypot-define59.5%
distribute-rgt-neg-in59.5%
distribute-frac-neg59.5%
Simplified59.5%
Taylor expanded in d around inf 80.0%
associate-*r/84.4%
+-commutative84.4%
associate-*r/80.0%
neg-mul-180.0%
sub-neg80.0%
associate-*r/84.4%
Simplified84.4%
if -1.8e20 < d < 3.0000000000000002e49Initial program 69.8%
Taylor expanded in c around inf 86.3%
mul-1-neg86.3%
unsub-neg86.3%
associate-/l*86.4%
Simplified86.4%
Final simplification85.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.15e+23) (not (<= d 5.8e+57))) (/ (- a) d) (/ (- b (* (/ d c) a)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.15e+23) || !(d <= 5.8e+57)) {
tmp = -a / d;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2.15d+23)) .or. (.not. (d <= 5.8d+57))) then
tmp = -a / d
else
tmp = (b - ((d / c) * a)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.15e+23) || !(d <= 5.8e+57)) {
tmp = -a / d;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.15e+23) or not (d <= 5.8e+57): tmp = -a / d else: tmp = (b - ((d / c) * a)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.15e+23) || !(d <= 5.8e+57)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.15e+23) || ~((d <= 5.8e+57))) tmp = -a / d; else tmp = (b - ((d / c) * a)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.15e+23], N[Not[LessEqual[d, 5.8e+57]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.15 \cdot 10^{+23} \lor \neg \left(d \leq 5.8 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if d < -2.1499999999999999e23 or 5.8000000000000003e57 < d Initial program 40.3%
Taylor expanded in c around 0 74.1%
associate-*r/74.1%
neg-mul-174.1%
Simplified74.1%
if -2.1499999999999999e23 < d < 5.8000000000000003e57Initial program 69.6%
Taylor expanded in c around inf 85.8%
mul-1-neg85.8%
unsub-neg85.8%
associate-/l*85.9%
Simplified85.9%
Final simplification80.7%
(FPCore (a b c d) :precision binary64 (if (<= d -6.8e+16) (/ (- (* b (/ c d)) a) d) (if (<= d 1.9e+49) (/ (- b (* (/ d c) a)) c) (/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.8e+16) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 1.9e+49) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-6.8d+16)) then
tmp = ((b * (c / d)) - a) / d
else if (d <= 1.9d+49) then
tmp = (b - ((d / c) * a)) / c
else
tmp = ((c * (b / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.8e+16) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 1.9e+49) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -6.8e+16: tmp = ((b * (c / d)) - a) / d elif d <= 1.9e+49: tmp = (b - ((d / c) * a)) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -6.8e+16) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (d <= 1.9e+49) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -6.8e+16) tmp = ((b * (c / d)) - a) / d; elseif (d <= 1.9e+49) tmp = (b - ((d / c) * a)) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -6.8e+16], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.9e+49], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.8 \cdot 10^{+16}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;d \leq 1.9 \cdot 10^{+49}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if d < -6.8e16Initial program 36.5%
div-sub36.5%
*-un-lft-identity36.5%
add-sqr-sqrt36.5%
times-frac36.5%
fma-neg36.5%
hypot-define36.5%
hypot-define41.9%
associate-/l*52.0%
add-sqr-sqrt52.0%
pow252.0%
hypot-define52.0%
Applied egg-rr52.0%
hypot-undefine46.5%
unpow246.5%
unpow246.5%
+-commutative46.5%
unpow246.5%
unpow246.5%
hypot-define52.0%
*-commutative52.0%
associate-/l*58.9%
hypot-undefine46.9%
unpow246.9%
unpow246.9%
+-commutative46.9%
unpow246.9%
unpow246.9%
hypot-define58.9%
distribute-rgt-neg-in58.9%
distribute-frac-neg58.9%
Simplified58.9%
Taylor expanded in d around inf 81.6%
associate-*r/89.1%
+-commutative89.1%
associate-*r/81.6%
neg-mul-181.6%
sub-neg81.6%
associate-*r/89.1%
Simplified89.1%
if -6.8e16 < d < 1.8999999999999999e49Initial program 69.8%
Taylor expanded in c around inf 86.3%
mul-1-neg86.3%
unsub-neg86.3%
associate-/l*86.4%
Simplified86.4%
if 1.8999999999999999e49 < d Initial program 45.5%
Taylor expanded in d around -inf 77.8%
mul-1-neg77.8%
+-commutative77.8%
remove-double-neg77.8%
sub-neg77.8%
neg-mul-177.8%
distribute-neg-frac277.8%
cancel-sign-sub-inv77.8%
metadata-eval77.8%
*-lft-identity77.8%
+-commutative77.8%
mul-1-neg77.8%
unsub-neg77.8%
*-commutative77.8%
associate-/l*80.1%
Simplified80.1%
Final simplification85.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.35e+14) (not (<= d 2.5e+49))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.35e+14) || !(d <= 2.5e+49)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2.35d+14)) .or. (.not. (d <= 2.5d+49))) then
tmp = a / -d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.35e+14) || !(d <= 2.5e+49)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.35e+14) or not (d <= 2.5e+49): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.35e+14) || !(d <= 2.5e+49)) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.35e+14) || ~((d <= 2.5e+49))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.35e+14], N[Not[LessEqual[d, 2.5e+49]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.35 \cdot 10^{+14} \lor \neg \left(d \leq 2.5 \cdot 10^{+49}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.35e14 or 2.5000000000000002e49 < d Initial program 40.5%
Taylor expanded in c around 0 73.7%
associate-*r/73.7%
neg-mul-173.7%
Simplified73.7%
if -2.35e14 < d < 2.5000000000000002e49Initial program 69.8%
Taylor expanded in c around inf 67.8%
Final simplification70.5%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 56.5%
Taylor expanded in c around inf 42.8%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 56.5%
*-un-lft-identity56.5%
add-sqr-sqrt56.5%
times-frac56.5%
hypot-define56.5%
fma-neg56.5%
distribute-rgt-neg-in56.5%
hypot-define71.3%
Applied egg-rr71.3%
Taylor expanded in c around -inf 31.4%
+-commutative31.4%
neg-mul-131.4%
unsub-neg31.4%
associate-/l*33.0%
Simplified33.0%
Taylor expanded in c around 0 7.9%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024114
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))