
(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 11 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 (fma (/ c (hypot c d)) (/ b (hypot c d)) (* a (/ (/ d (hypot d c)) (- (hypot d c))))))
double code(double a, double b, double c, double d) {
return fma((c / hypot(c, d)), (b / hypot(c, d)), (a * ((d / hypot(d, c)) / -hypot(d, c))));
}
function code(a, b, c, d) return fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(d / hypot(d, c)) / Float64(-hypot(d, c))))) end
code[a_, b_, c_, d_] := N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{-\mathsf{hypot}\left(d, c\right)}\right)
\end{array}
Initial program 65.3%
div-sub63.3%
*-commutative63.3%
add-sqr-sqrt63.3%
times-frac65.3%
fma-neg65.3%
hypot-define65.3%
hypot-define78.1%
associate-/l*79.7%
add-sqr-sqrt79.7%
pow279.7%
hypot-define79.7%
Applied egg-rr79.7%
*-un-lft-identity79.7%
unpow279.7%
times-frac95.5%
Applied egg-rr95.5%
associate-*l/95.5%
*-lft-identity95.5%
hypot-undefine79.7%
unpow279.7%
unpow279.7%
+-commutative79.7%
unpow279.7%
unpow279.7%
hypot-define95.5%
hypot-undefine79.7%
unpow279.7%
unpow279.7%
+-commutative79.7%
unpow279.7%
unpow279.7%
hypot-define95.5%
Simplified95.5%
Final simplification95.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ c (hypot c d))) (t_1 (/ b (hypot c d))))
(if (<= d -2e+17)
(fma t_0 t_1 (* a (/ (- -1.0) (hypot d c))))
(if (<= d 1.35e+154)
(fma t_0 t_1 (* a (/ (- d) (pow (hypot c d) 2.0))))
(/ (- (/ c (/ d b)) a) d)))))
double code(double a, double b, double c, double d) {
double t_0 = c / hypot(c, d);
double t_1 = b / hypot(c, d);
double tmp;
if (d <= -2e+17) {
tmp = fma(t_0, t_1, (a * (-(-1.0) / hypot(d, c))));
} else if (d <= 1.35e+154) {
tmp = fma(t_0, t_1, (a * (-d / pow(hypot(c, d), 2.0))));
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(c / hypot(c, d)) t_1 = Float64(b / hypot(c, d)) tmp = 0.0 if (d <= -2e+17) tmp = fma(t_0, t_1, Float64(a * Float64(Float64(-(-1.0)) / hypot(d, c)))); elseif (d <= 1.35e+154) tmp = fma(t_0, t_1, Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0)))); else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2e+17], N[(t$95$0 * t$95$1 + N[(a * N[((--1.0) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.35e+154], N[(t$95$0 * t$95$1 + N[(a * N[((-d) / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -2 \cdot 10^{+17}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{--1}{\mathsf{hypot}\left(d, c\right)}\right)\\
\mathbf{elif}\;d \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if d < -2e17Initial program 44.7%
div-sub44.7%
*-commutative44.7%
add-sqr-sqrt44.7%
times-frac45.1%
fma-neg45.1%
hypot-define45.1%
hypot-define59.1%
associate-/l*61.9%
add-sqr-sqrt61.9%
pow261.9%
hypot-define61.9%
Applied egg-rr61.9%
*-un-lft-identity61.9%
unpow261.9%
times-frac91.4%
Applied egg-rr91.4%
associate-*l/91.4%
*-lft-identity91.4%
hypot-undefine62.0%
unpow262.0%
unpow262.0%
+-commutative62.0%
unpow262.0%
unpow262.0%
hypot-define91.4%
hypot-undefine62.0%
unpow262.0%
unpow262.0%
+-commutative62.0%
unpow262.0%
unpow262.0%
hypot-define91.4%
Simplified91.4%
Taylor expanded in d around -inf 85.1%
if -2e17 < d < 1.35000000000000003e154Initial program 77.0%
div-sub74.1%
*-commutative74.1%
add-sqr-sqrt74.1%
times-frac76.9%
fma-neg76.9%
hypot-define76.9%
hypot-define90.4%
associate-/l*91.6%
add-sqr-sqrt91.6%
pow291.6%
hypot-define91.6%
Applied egg-rr91.6%
if 1.35000000000000003e154 < d Initial program 31.3%
Taylor expanded in c around 0 78.3%
+-commutative78.3%
mul-1-neg78.3%
unsub-neg78.3%
unpow278.3%
associate-/r*87.3%
div-sub87.3%
*-commutative87.3%
associate-/l*90.5%
Simplified90.5%
clear-num90.5%
un-div-inv90.6%
Applied egg-rr90.6%
Final simplification90.2%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.85e-25)
(fma (/ c (hypot c d)) (/ b (hypot c d)) (* a (/ (- -1.0) (hypot d c))))
(if (<= d 1.75e-62)
(/ (- b (* d (/ a c))) c)
(if (<= d 5.5e+47)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(/ (- (/ c (/ d b)) a) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.85e-25) {
tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (-(-1.0) / hypot(d, c))));
} else if (d <= 1.75e-62) {
tmp = (b - (d * (a / c))) / c;
} else if (d <= 5.5e+47) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.85e-25) tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(-(-1.0)) / hypot(d, c)))); elseif (d <= 1.75e-62) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (d <= 5.5e+47) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.85e-25], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[((--1.0) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.75e-62], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.5e+47], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.85 \cdot 10^{-25}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{--1}{\mathsf{hypot}\left(d, c\right)}\right)\\
\mathbf{elif}\;d \leq 1.75 \cdot 10^{-62}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;d \leq 5.5 \cdot 10^{+47}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if d < -1.85000000000000004e-25Initial program 50.5%
div-sub50.5%
*-commutative50.5%
add-sqr-sqrt50.5%
times-frac51.0%
fma-neg51.0%
hypot-define51.0%
hypot-define65.7%
associate-/l*68.1%
add-sqr-sqrt68.1%
pow268.1%
hypot-define68.1%
Applied egg-rr68.1%
*-un-lft-identity68.1%
unpow268.1%
times-frac92.7%
Applied egg-rr92.7%
associate-*l/92.8%
*-lft-identity92.8%
hypot-undefine68.2%
unpow268.2%
unpow268.2%
+-commutative68.2%
unpow268.2%
unpow268.2%
hypot-define92.8%
hypot-undefine68.2%
unpow268.2%
unpow268.2%
+-commutative68.2%
unpow268.2%
unpow268.2%
hypot-define92.8%
Simplified92.8%
Taylor expanded in d around -inf 84.4%
if -1.85000000000000004e-25 < d < 1.7500000000000001e-62Initial program 75.5%
Taylor expanded in c around inf 90.5%
mul-1-neg90.5%
unsub-neg90.5%
*-commutative90.5%
associate-/l*91.3%
Simplified91.3%
if 1.7500000000000001e-62 < d < 5.4999999999999998e47Initial program 95.2%
if 5.4999999999999998e47 < d Initial program 42.2%
Taylor expanded in c around 0 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
unpow274.9%
associate-/r*80.4%
div-sub80.4%
*-commutative80.4%
associate-/l*84.3%
Simplified84.3%
clear-num84.3%
un-div-inv84.4%
Applied egg-rr84.4%
Final simplification88.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= d -6.2e+35)
(- (/ (* c (/ b d)) d) (/ a d))
(if (<= d -5.1e-117)
t_0
(if (<= d 2.2e-61)
(/ (- b (* d (/ a c))) c)
(if (<= d 1.45e+47) t_0 (/ (- (/ c (/ d b)) a) 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 (d <= -6.2e+35) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (d <= -5.1e-117) {
tmp = t_0;
} else if (d <= 2.2e-61) {
tmp = (b - (d * (a / c))) / c;
} else if (d <= 1.45e+47) {
tmp = t_0;
} else {
tmp = ((c / (d / b)) - 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) :: t_0
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
if (d <= (-6.2d+35)) then
tmp = ((c * (b / d)) / d) - (a / d)
else if (d <= (-5.1d-117)) then
tmp = t_0
else if (d <= 2.2d-61) then
tmp = (b - (d * (a / c))) / c
else if (d <= 1.45d+47) then
tmp = t_0
else
tmp = ((c / (d / b)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (d <= -6.2e+35) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (d <= -5.1e-117) {
tmp = t_0;
} else if (d <= 2.2e-61) {
tmp = (b - (d * (a / c))) / c;
} else if (d <= 1.45e+47) {
tmp = t_0;
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if d <= -6.2e+35: tmp = ((c * (b / d)) / d) - (a / d) elif d <= -5.1e-117: tmp = t_0 elif d <= 2.2e-61: tmp = (b - (d * (a / c))) / c elif d <= 1.45e+47: tmp = t_0 else: tmp = ((c / (d / b)) - a) / 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 (d <= -6.2e+35) tmp = Float64(Float64(Float64(c * Float64(b / d)) / d) - Float64(a / d)); elseif (d <= -5.1e-117) tmp = t_0; elseif (d <= 2.2e-61) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); elseif (d <= 1.45e+47) tmp = t_0; else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -6.2e+35) tmp = ((c * (b / d)) / d) - (a / d); elseif (d <= -5.1e-117) tmp = t_0; elseif (d <= 2.2e-61) tmp = (b - (d * (a / c))) / c; elseif (d <= 1.45e+47) tmp = t_0; else tmp = ((c / (d / b)) - a) / d; end tmp_2 = 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[LessEqual[d, -6.2e+35], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.1e-117], t$95$0, If[LessEqual[d, 2.2e-61], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.45e+47], t$95$0, N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -6.2 \cdot 10^{+35}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -5.1 \cdot 10^{-117}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{-61}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+47}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if d < -6.19999999999999973e35Initial program 38.6%
Taylor expanded in c around 0 64.7%
+-commutative64.7%
mul-1-neg64.7%
unsub-neg64.7%
unpow264.7%
associate-/r*68.0%
div-sub68.0%
*-commutative68.0%
associate-/l*82.7%
Simplified82.7%
div-sub82.8%
Applied egg-rr82.8%
if -6.19999999999999973e35 < d < -5.1000000000000002e-117 or 2.20000000000000009e-61 < d < 1.4499999999999999e47Initial program 90.6%
if -5.1000000000000002e-117 < d < 2.20000000000000009e-61Initial program 73.9%
Taylor expanded in c around inf 93.6%
mul-1-neg93.6%
unsub-neg93.6%
*-commutative93.6%
associate-/l*94.5%
Simplified94.5%
if 1.4499999999999999e47 < d Initial program 42.2%
Taylor expanded in c around 0 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
unpow274.9%
associate-/r*80.4%
div-sub80.4%
*-commutative80.4%
associate-/l*84.3%
Simplified84.3%
clear-num84.3%
un-div-inv84.4%
Applied egg-rr84.4%
Final simplification89.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.35e-14) (not (<= d 3.1e-52))) (/ (- (* c (/ b d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.35e-14) || !(d <= 3.1e-52)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / 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 <= 3.1d-52))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b - (a * (d / c))) / 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 <= 3.1e-52)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.35e-14) or not (d <= 3.1e-52): tmp = ((c * (b / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.35e-14) || !(d <= 3.1e-52)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.35e-14) || ~((d <= 3.1e-52))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.35e-14], N[Not[LessEqual[d, 3.1e-52]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.35 \cdot 10^{-14} \lor \neg \left(d \leq 3.1 \cdot 10^{-52}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -2.3500000000000001e-14 or 3.0999999999999999e-52 < d Initial program 55.6%
Taylor expanded in c around 0 68.5%
+-commutative68.5%
mul-1-neg68.5%
unsub-neg68.5%
unpow268.5%
associate-/r*71.7%
div-sub71.8%
*-commutative71.8%
associate-/l*76.9%
Simplified76.9%
if -2.3500000000000001e-14 < d < 3.0999999999999999e-52Initial program 75.2%
div-sub71.2%
*-commutative71.2%
add-sqr-sqrt71.2%
times-frac76.4%
fma-neg76.4%
hypot-define76.4%
hypot-define92.2%
associate-/l*90.8%
add-sqr-sqrt90.8%
pow290.8%
hypot-define90.8%
Applied egg-rr90.8%
Taylor expanded in c around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
associate-/l*89.5%
Simplified89.5%
Final simplification83.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.1e+32) (not (<= d 8200000000.0))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e+32) || !(d <= 8200000000.0)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / 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 <= (-3.1d+32)) .or. (.not. (d <= 8200000000.0d0))) then
tmp = a / -d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.1e+32) || !(d <= 8200000000.0)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.1e+32) or not (d <= 8200000000.0): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.1e+32) || !(d <= 8200000000.0)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.1e+32) || ~((d <= 8200000000.0))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.1e+32], N[Not[LessEqual[d, 8200000000.0]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+32} \lor \neg \left(d \leq 8200000000\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.09999999999999993e32 or 8.2e9 < d Initial program 45.5%
Taylor expanded in c around 0 67.8%
associate-*r/67.8%
neg-mul-167.8%
Simplified67.8%
if -3.09999999999999993e32 < d < 8.2e9Initial program 78.7%
div-sub75.3%
*-commutative75.3%
add-sqr-sqrt75.3%
times-frac78.5%
fma-neg78.5%
hypot-define78.5%
hypot-define92.2%
associate-/l*91.1%
add-sqr-sqrt91.1%
pow291.1%
hypot-define91.1%
Applied egg-rr91.1%
Taylor expanded in c around inf 81.1%
mul-1-neg81.1%
unsub-neg81.1%
associate-/l*81.7%
Simplified81.7%
Final simplification76.1%
(FPCore (a b c d) :precision binary64 (if (<= d -1.15e-14) (- (/ (* c (/ b d)) d) (/ a d)) (if (<= d 3.15e-52) (/ (- b (* a (/ d c))) c) (/ (- (/ c (/ d b)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.15e-14) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (d <= 3.15e-52) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c / (d / b)) - 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 <= (-1.15d-14)) then
tmp = ((c * (b / d)) / d) - (a / d)
else if (d <= 3.15d-52) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((c / (d / b)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.15e-14) {
tmp = ((c * (b / d)) / d) - (a / d);
} else if (d <= 3.15e-52) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.15e-14: tmp = ((c * (b / d)) / d) - (a / d) elif d <= 3.15e-52: tmp = (b - (a * (d / c))) / c else: tmp = ((c / (d / b)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.15e-14) tmp = Float64(Float64(Float64(c * Float64(b / d)) / d) - Float64(a / d)); elseif (d <= 3.15e-52) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.15e-14) tmp = ((c * (b / d)) / d) - (a / d); elseif (d <= 3.15e-52) tmp = (b - (a * (d / c))) / c; else tmp = ((c / (d / b)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.15e-14], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.15e-52], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.15 \cdot 10^{-14}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq 3.15 \cdot 10^{-52}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if d < -1.14999999999999999e-14Initial program 48.7%
Taylor expanded in c around 0 63.6%
+-commutative63.6%
mul-1-neg63.6%
unsub-neg63.6%
unpow263.6%
associate-/r*66.4%
div-sub66.4%
*-commutative66.4%
associate-/l*78.7%
Simplified78.7%
div-sub78.7%
Applied egg-rr78.7%
if -1.14999999999999999e-14 < d < 3.1500000000000002e-52Initial program 75.2%
div-sub71.2%
*-commutative71.2%
add-sqr-sqrt71.2%
times-frac76.4%
fma-neg76.4%
hypot-define76.4%
hypot-define92.2%
associate-/l*90.8%
add-sqr-sqrt90.8%
pow290.8%
hypot-define90.8%
Applied egg-rr90.8%
Taylor expanded in c around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
associate-/l*89.5%
Simplified89.5%
if 3.1500000000000002e-52 < d Initial program 60.5%
Taylor expanded in c around 0 72.0%
+-commutative72.0%
mul-1-neg72.0%
unsub-neg72.0%
unpow272.0%
associate-/r*75.6%
div-sub75.6%
*-commutative75.6%
associate-/l*75.6%
Simplified75.6%
clear-num75.6%
un-div-inv75.7%
Applied egg-rr75.7%
(FPCore (a b c d) :precision binary64 (if (<= d -1.1e-14) (/ (- (* c (/ b d)) a) d) (if (<= d 4e-52) (/ (- b (* a (/ d c))) c) (/ (- (/ c (/ d b)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.1e-14) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= 4e-52) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c / (d / b)) - 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 <= (-1.1d-14)) then
tmp = ((c * (b / d)) - a) / d
else if (d <= 4d-52) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((c / (d / b)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.1e-14) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= 4e-52) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((c / (d / b)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.1e-14: tmp = ((c * (b / d)) - a) / d elif d <= 4e-52: tmp = (b - (a * (d / c))) / c else: tmp = ((c / (d / b)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.1e-14) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= 4e-52) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.1e-14) tmp = ((c * (b / d)) - a) / d; elseif (d <= 4e-52) tmp = (b - (a * (d / c))) / c; else tmp = ((c / (d / b)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.1e-14], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 4e-52], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.1 \cdot 10^{-14}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq 4 \cdot 10^{-52}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\
\end{array}
\end{array}
if d < -1.1e-14Initial program 48.7%
Taylor expanded in c around 0 63.6%
+-commutative63.6%
mul-1-neg63.6%
unsub-neg63.6%
unpow263.6%
associate-/r*66.4%
div-sub66.4%
*-commutative66.4%
associate-/l*78.7%
Simplified78.7%
if -1.1e-14 < d < 4e-52Initial program 75.2%
div-sub71.2%
*-commutative71.2%
add-sqr-sqrt71.2%
times-frac76.4%
fma-neg76.4%
hypot-define76.4%
hypot-define92.2%
associate-/l*90.8%
add-sqr-sqrt90.8%
pow290.8%
hypot-define90.8%
Applied egg-rr90.8%
Taylor expanded in c around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
associate-/l*89.5%
Simplified89.5%
if 4e-52 < d Initial program 60.5%
Taylor expanded in c around 0 72.0%
+-commutative72.0%
mul-1-neg72.0%
unsub-neg72.0%
unpow272.0%
associate-/r*75.6%
div-sub75.6%
*-commutative75.6%
associate-/l*75.6%
Simplified75.6%
clear-num75.6%
un-div-inv75.7%
Applied egg-rr75.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -9.5e-107) (not (<= c 9500000000000.0))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9.5e-107) || !(c <= 9500000000000.0)) {
tmp = b / c;
} else {
tmp = 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 ((c <= (-9.5d-107)) .or. (.not. (c <= 9500000000000.0d0))) then
tmp = b / c
else
tmp = a / -d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9.5e-107) || !(c <= 9500000000000.0)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -9.5e-107) or not (c <= 9500000000000.0): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -9.5e-107) || !(c <= 9500000000000.0)) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -9.5e-107) || ~((c <= 9500000000000.0))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -9.5e-107], N[Not[LessEqual[c, 9500000000000.0]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.5 \cdot 10^{-107} \lor \neg \left(c \leq 9500000000000\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -9.4999999999999999e-107 or 9.5e12 < c Initial program 58.4%
Taylor expanded in c around inf 61.3%
if -9.4999999999999999e-107 < c < 9.5e12Initial program 73.3%
Taylor expanded in c around 0 65.0%
associate-*r/65.0%
neg-mul-165.0%
Simplified65.0%
Final simplification63.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.9e+225) (not (<= d 4.9e+154))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.9e+225) || !(d <= 4.9e+154)) {
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 <= (-1.9d+225)) .or. (.not. (d <= 4.9d+154))) 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 <= -1.9e+225) || !(d <= 4.9e+154)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.9e+225) or not (d <= 4.9e+154): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.9e+225) || !(d <= 4.9e+154)) tmp = Float64(a / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.9e+225) || ~((d <= 4.9e+154))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.9e+225], N[Not[LessEqual[d, 4.9e+154]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{+225} \lor \neg \left(d \leq 4.9 \cdot 10^{+154}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -1.9e225 or 4.9000000000000002e154 < d Initial program 33.4%
Taylor expanded in c around 0 84.2%
associate-*r/84.2%
neg-mul-184.2%
Simplified84.2%
neg-sub084.2%
sub-neg84.2%
add-sqr-sqrt44.0%
sqrt-unprod43.9%
sqr-neg43.9%
sqrt-unprod17.9%
add-sqr-sqrt32.3%
Applied egg-rr32.3%
+-lft-identity32.3%
Simplified32.3%
if -1.9e225 < d < 4.9000000000000002e154Initial program 71.8%
Taylor expanded in c around inf 47.1%
Final simplification44.6%
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
return a / 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 = a / d
end function
public static double code(double a, double b, double c, double d) {
return a / d;
}
def code(a, b, c, d): return a / d
function code(a, b, c, d) return Float64(a / d) end
function tmp = code(a, b, c, d) tmp = a / d; end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{d}
\end{array}
Initial program 65.3%
Taylor expanded in c around 0 39.9%
associate-*r/39.9%
neg-mul-139.9%
Simplified39.9%
neg-sub039.9%
sub-neg39.9%
add-sqr-sqrt18.7%
sqrt-unprod18.6%
sqr-neg18.6%
sqrt-unprod4.7%
add-sqr-sqrt9.5%
Applied egg-rr9.5%
+-lft-identity9.5%
Simplified9.5%
(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 2024144
(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))))