
(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 (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 60.1%
div-sub58.4%
*-commutative58.4%
add-sqr-sqrt58.4%
times-frac61.5%
fma-neg61.5%
hypot-define61.5%
hypot-define78.2%
associate-/l*81.9%
add-sqr-sqrt81.9%
pow281.9%
hypot-define81.9%
Applied egg-rr81.9%
*-un-lft-identity81.9%
unpow281.9%
times-frac96.7%
hypot-undefine81.9%
+-commutative81.9%
hypot-define96.7%
hypot-undefine81.9%
+-commutative81.9%
hypot-define96.7%
Applied egg-rr96.7%
associate-*l/96.7%
*-lft-identity96.7%
Simplified96.7%
Final simplification96.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ c (hypot c d)))
(t_1 (/ b (hypot c d)))
(t_2 (fma t_0 t_1 (* a (/ (- d) (pow (hypot c d) 2.0)))))
(t_3 (fma t_0 t_1 (/ a (- d)))))
(if (<= d -7e+131)
t_3
(if (<= d -1e-134)
t_2
(if (<= d 460.0)
(/ (- b (* a (/ d c))) c)
(if (<= d 2.6e+147) t_2 t_3))))))
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 t_2 = fma(t_0, t_1, (a * (-d / pow(hypot(c, d), 2.0))));
double t_3 = fma(t_0, t_1, (a / -d));
double tmp;
if (d <= -7e+131) {
tmp = t_3;
} else if (d <= -1e-134) {
tmp = t_2;
} else if (d <= 460.0) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 2.6e+147) {
tmp = t_2;
} else {
tmp = t_3;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(c / hypot(c, d)) t_1 = Float64(b / hypot(c, d)) t_2 = fma(t_0, t_1, Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0)))) t_3 = fma(t_0, t_1, Float64(a / Float64(-d))) tmp = 0.0 if (d <= -7e+131) tmp = t_3; elseif (d <= -1e-134) tmp = t_2; elseif (d <= 460.0) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 2.6e+147) tmp = t_2; else tmp = t_3; 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]}, Block[{t$95$2 = 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]}, Block[{t$95$3 = N[(t$95$0 * t$95$1 + N[(a / (-d)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7e+131], t$95$3, If[LessEqual[d, -1e-134], t$95$2, If[LessEqual[d, 460.0], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.6e+147], t$95$2, t$95$3]]]]]]]]
\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)}\\
t_2 := \mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
t_3 := \mathsf{fma}\left(t\_0, t\_1, \frac{a}{-d}\right)\\
\mathbf{if}\;d \leq -7 \cdot 10^{+131}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-134}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq 460:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{+147}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if d < -6.9999999999999998e131 or 2.5999999999999999e147 < d Initial program 31.5%
div-sub31.5%
*-commutative31.5%
add-sqr-sqrt31.5%
times-frac31.8%
fma-neg31.8%
hypot-define31.8%
hypot-define49.6%
associate-/l*53.9%
add-sqr-sqrt53.9%
pow253.9%
hypot-define53.9%
Applied egg-rr53.9%
Taylor expanded in d around inf 93.9%
if -6.9999999999999998e131 < d < -1.00000000000000004e-134 or 460 < d < 2.5999999999999999e147Initial program 72.4%
div-sub72.4%
*-commutative72.4%
add-sqr-sqrt72.4%
times-frac77.0%
fma-neg77.0%
hypot-define77.0%
hypot-define88.5%
associate-/l*93.7%
add-sqr-sqrt93.7%
pow293.7%
hypot-define93.7%
Applied egg-rr93.7%
if -1.00000000000000004e-134 < d < 460Initial program 66.2%
Taylor expanded in c around inf 93.5%
mul-1-neg93.5%
remove-double-neg93.5%
mul-1-neg93.5%
distribute-neg-in93.5%
mul-1-neg93.5%
mul-1-neg93.5%
distribute-neg-in93.5%
mul-1-neg93.5%
remove-double-neg93.5%
unsub-neg93.5%
associate-/l*94.4%
Simplified94.4%
Final simplification94.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ a (- d)))))
(if (<= d -4.6e+102)
t_0
(if (<= d -3.15e-50)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(if (<= d 35000000000.0) (/ (- b (* a (/ d c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((c / hypot(c, d)), (b / hypot(c, d)), (a / -d));
double tmp;
if (d <= -4.6e+102) {
tmp = t_0;
} else if (d <= -3.15e-50) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 35000000000.0) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a / Float64(-d))) tmp = 0.0 if (d <= -4.6e+102) tmp = t_0; elseif (d <= -3.15e-50) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 35000000000.0) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a / (-d)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.6e+102], t$95$0, If[LessEqual[d, -3.15e-50], 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, 35000000000.0], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{-d}\right)\\
\mathbf{if}\;d \leq -4.6 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -3.15 \cdot 10^{-50}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 35000000000:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.5999999999999998e102 or 3.5e10 < d Initial program 44.9%
div-sub44.9%
*-commutative44.9%
add-sqr-sqrt44.9%
times-frac46.2%
fma-neg46.2%
hypot-define46.2%
hypot-define61.3%
associate-/l*70.0%
add-sqr-sqrt70.0%
pow270.0%
hypot-define70.0%
Applied egg-rr70.0%
Taylor expanded in d around inf 91.7%
if -4.5999999999999998e102 < d < -3.15000000000000011e-50Initial program 83.0%
if -3.15000000000000011e-50 < d < 3.5e10Initial program 65.6%
Taylor expanded in c around inf 91.5%
mul-1-neg91.5%
remove-double-neg91.5%
mul-1-neg91.5%
distribute-neg-in91.5%
mul-1-neg91.5%
mul-1-neg91.5%
distribute-neg-in91.5%
mul-1-neg91.5%
remove-double-neg91.5%
unsub-neg91.5%
associate-/l*92.3%
Simplified92.3%
Final simplification90.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= d -1.7e+106)
(/ (- (* c (/ b d)) a) d)
(if (<= d -2.4e-45)
t_0
(if (<= d 460.0)
(/ (- b (* a (/ d c))) c)
(if (<= d 3.5e+75) t_0 (/ (- (* b (/ c d)) 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 <= -1.7e+106) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -2.4e-45) {
tmp = t_0;
} else if (d <= 460.0) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 3.5e+75) {
tmp = t_0;
} else {
tmp = ((b * (c / 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) :: t_0
real(8) :: tmp
t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
if (d <= (-1.7d+106)) then
tmp = ((c * (b / d)) - a) / d
else if (d <= (-2.4d-45)) then
tmp = t_0
else if (d <= 460.0d0) then
tmp = (b - (a * (d / c))) / c
else if (d <= 3.5d+75) then
tmp = t_0
else
tmp = ((b * (c / d)) - 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 <= -1.7e+106) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -2.4e-45) {
tmp = t_0;
} else if (d <= 460.0) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 3.5e+75) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.7e+106: tmp = ((c * (b / d)) - a) / d elif d <= -2.4e-45: tmp = t_0 elif d <= 460.0: tmp = (b - (a * (d / c))) / c elif d <= 3.5e+75: tmp = t_0 else: tmp = ((b * (c / d)) - 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 <= -1.7e+106) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= -2.4e-45) tmp = t_0; elseif (d <= 460.0) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 3.5e+75) tmp = t_0; else tmp = Float64(Float64(Float64(b * Float64(c / d)) - 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 <= -1.7e+106) tmp = ((c * (b / d)) - a) / d; elseif (d <= -2.4e-45) tmp = t_0; elseif (d <= 460.0) tmp = (b - (a * (d / c))) / c; elseif (d <= 3.5e+75) tmp = t_0; else tmp = ((b * (c / d)) - 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, -1.7e+106], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.4e-45], t$95$0, If[LessEqual[d, 460.0], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.5e+75], t$95$0, N[(N[(N[(b * N[(c / d), $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 -1.7 \cdot 10^{+106}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 460:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.69999999999999997e106Initial program 33.7%
Taylor expanded in c around 0 71.8%
+-commutative71.8%
mul-1-neg71.8%
unsub-neg71.8%
unpow271.8%
associate-/r*79.2%
div-sub79.2%
*-commutative79.2%
associate-/l*87.8%
Simplified87.8%
if -1.69999999999999997e106 < d < -2.3999999999999999e-45 or 460 < d < 3.4999999999999998e75Initial program 86.2%
if -2.3999999999999999e-45 < d < 460Initial program 65.6%
Taylor expanded in c around inf 91.5%
mul-1-neg91.5%
remove-double-neg91.5%
mul-1-neg91.5%
distribute-neg-in91.5%
mul-1-neg91.5%
mul-1-neg91.5%
distribute-neg-in91.5%
mul-1-neg91.5%
remove-double-neg91.5%
unsub-neg91.5%
associate-/l*92.3%
Simplified92.3%
if 3.4999999999999998e75 < d Initial program 38.1%
div-sub38.1%
*-commutative38.1%
add-sqr-sqrt38.1%
times-frac40.4%
fma-neg40.4%
hypot-define40.4%
hypot-define51.2%
associate-/l*63.2%
add-sqr-sqrt63.2%
pow263.2%
hypot-define63.2%
Applied egg-rr63.2%
Taylor expanded in c around 0 70.1%
*-commutative70.1%
unpow270.1%
associate-/l/71.7%
div-sub71.7%
*-commutative71.7%
associate-/l*78.7%
Simplified78.7%
Final simplification88.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e-51) (not (<= c 1.22e-210))) (/ (- b (* a (/ d c))) c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e-51) || !(c <= 1.22e-210)) {
tmp = (b - (a * (d / c))) / 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 <= (-2.6d-51)) .or. (.not. (c <= 1.22d-210))) then
tmp = (b - (a * (d / c))) / 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 <= -2.6e-51) || !(c <= 1.22e-210)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.6e-51) or not (c <= 1.22e-210): tmp = (b - (a * (d / c))) / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e-51) || !(c <= 1.22e-210)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.6e-51) || ~((c <= 1.22e-210))) tmp = (b - (a * (d / c))) / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e-51], N[Not[LessEqual[c, 1.22e-210]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{-51} \lor \neg \left(c \leq 1.22 \cdot 10^{-210}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.6e-51 or 1.22e-210 < c Initial program 55.7%
Taylor expanded in c around inf 75.9%
mul-1-neg75.9%
remove-double-neg75.9%
mul-1-neg75.9%
distribute-neg-in75.9%
mul-1-neg75.9%
mul-1-neg75.9%
distribute-neg-in75.9%
mul-1-neg75.9%
remove-double-neg75.9%
unsub-neg75.9%
associate-/l*78.7%
Simplified78.7%
if -2.6e-51 < c < 1.22e-210Initial program 69.9%
Taylor expanded in c around 0 81.9%
associate-*r/81.9%
neg-mul-181.9%
Simplified81.9%
Final simplification79.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -6.2e-51) (not (<= c 8.5e-47))) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.2e-51) || !(c <= 8.5e-47)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / 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 ((c <= (-6.2d-51)) .or. (.not. (c <= 8.5d-47))) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((b * (c / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -6.2e-51) || !(c <= 8.5e-47)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -6.2e-51) or not (c <= 8.5e-47): tmp = (b - (a * (d / c))) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -6.2e-51) || !(c <= 8.5e-47)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -6.2e-51) || ~((c <= 8.5e-47))) tmp = (b - (a * (d / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6.2e-51], N[Not[LessEqual[c, 8.5e-47]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-51} \lor \neg \left(c \leq 8.5 \cdot 10^{-47}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -6.1999999999999995e-51 or 8.4999999999999999e-47 < c Initial program 54.5%
Taylor expanded in c around inf 80.5%
mul-1-neg80.5%
remove-double-neg80.5%
mul-1-neg80.5%
distribute-neg-in80.5%
mul-1-neg80.5%
mul-1-neg80.5%
distribute-neg-in80.5%
mul-1-neg80.5%
remove-double-neg80.5%
unsub-neg80.5%
associate-/l*83.1%
Simplified83.1%
if -6.1999999999999995e-51 < c < 8.4999999999999999e-47Initial program 68.5%
div-sub64.1%
*-commutative64.1%
add-sqr-sqrt64.1%
times-frac63.3%
fma-neg63.3%
hypot-define63.4%
hypot-define66.6%
associate-/l*75.3%
add-sqr-sqrt75.3%
pow275.3%
hypot-define75.3%
Applied egg-rr75.3%
Taylor expanded in c around 0 77.3%
*-commutative77.3%
unpow277.3%
associate-/l/83.5%
div-sub83.6%
*-commutative83.6%
associate-/l*83.7%
Simplified83.7%
Final simplification83.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.1e-51) (not (<= c 4.2e-47))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.1e-51) || !(c <= 4.2e-47)) {
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 <= (-4.1d-51)) .or. (.not. (c <= 4.2d-47))) 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 <= -4.1e-51) || !(c <= 4.2e-47)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.1e-51) or not (c <= 4.2e-47): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.1e-51) || !(c <= 4.2e-47)) 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 <= -4.1e-51) || ~((c <= 4.2e-47))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.1e-51], N[Not[LessEqual[c, 4.2e-47]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.1 \cdot 10^{-51} \lor \neg \left(c \leq 4.2 \cdot 10^{-47}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -4.09999999999999973e-51 or 4.2000000000000001e-47 < c Initial program 54.5%
Taylor expanded in c around inf 67.8%
if -4.09999999999999973e-51 < c < 4.2000000000000001e-47Initial program 68.5%
Taylor expanded in c around 0 73.9%
associate-*r/73.9%
neg-mul-173.9%
Simplified73.9%
Final simplification70.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.8e+116) (not (<= d 7e+153))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.8e+116) || !(d <= 7e+153)) {
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 <= (-5.8d+116)) .or. (.not. (d <= 7d+153))) 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 <= -5.8e+116) || !(d <= 7e+153)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.8e+116) or not (d <= 7e+153): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.8e+116) || !(d <= 7e+153)) 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 <= -5.8e+116) || ~((d <= 7e+153))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.8e+116], N[Not[LessEqual[d, 7e+153]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.8 \cdot 10^{+116} \lor \neg \left(d \leq 7 \cdot 10^{+153}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -5.8000000000000003e116 or 6.9999999999999998e153 < d Initial program 32.1%
Taylor expanded in c around 0 71.3%
+-commutative71.3%
mul-1-neg71.3%
unsub-neg71.3%
unpow271.3%
associate-/r*76.8%
div-sub76.9%
*-commutative76.9%
associate-/l*85.3%
Simplified85.3%
clear-num84.9%
inv-pow84.9%
fma-neg84.9%
add-sqr-sqrt38.1%
sqrt-unprod47.1%
sqr-neg47.1%
sqrt-unprod20.0%
add-sqr-sqrt39.3%
Applied egg-rr39.3%
unpow-139.3%
Simplified39.3%
Taylor expanded in d around inf 29.7%
if -5.8000000000000003e116 < d < 6.9999999999999998e153Initial program 69.3%
Taylor expanded in c around inf 56.7%
Final simplification50.1%
(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 60.1%
Taylor expanded in c around 0 39.9%
+-commutative39.9%
mul-1-neg39.9%
unsub-neg39.9%
unpow239.9%
associate-/r*43.5%
div-sub43.6%
*-commutative43.6%
associate-/l*45.3%
Simplified45.3%
clear-num45.2%
inv-pow45.2%
fma-neg45.2%
add-sqr-sqrt21.8%
sqrt-unprod23.9%
sqr-neg23.9%
sqrt-unprod7.4%
add-sqr-sqrt16.3%
Applied egg-rr16.3%
unpow-116.3%
Simplified16.3%
Taylor expanded in d around inf 10.0%
Final simplification10.0%
(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 2024096
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(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))))