
(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
(let* ((t_0 (- (* b c) (* a d))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 1e+295)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 1e+295) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 1e+295) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (a * d) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 1e+295: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 1e+295) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); 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 = (b * c) - (a * d); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 1e+295) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+295], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 10^{+295}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999998e294Initial program 81.0%
*-un-lft-identity81.0%
add-sqr-sqrt81.0%
times-frac81.0%
hypot-define81.0%
hypot-define97.1%
Applied egg-rr97.1%
if 9.9999999999999998e294 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 21.8%
*-un-lft-identity21.8%
add-sqr-sqrt21.8%
times-frac21.9%
hypot-define21.9%
hypot-define25.4%
Applied egg-rr25.4%
Taylor expanded in d around inf 62.4%
+-commutative62.4%
neg-mul-162.4%
sub-neg62.4%
associate-/l*68.0%
Simplified68.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(t_1 (/ (- (* c (/ b d)) a) d)))
(if (<= d -1.6e+96)
t_1
(if (<= d -9.4e-104)
t_0
(if (<= d 3.3e-156)
(/ (- b (/ (* a d) c)) c)
(if (<= d 3.2e+115) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.6e+96) {
tmp = t_1;
} else if (d <= -9.4e-104) {
tmp = t_0;
} else if (d <= 3.3e-156) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 3.2e+115) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
t_1 = ((c * (b / d)) - a) / d
if (d <= (-1.6d+96)) then
tmp = t_1
else if (d <= (-9.4d-104)) then
tmp = t_0
else if (d <= 3.3d-156) then
tmp = (b - ((a * d) / c)) / c
else if (d <= 3.2d+115) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -1.6e+96) {
tmp = t_1;
} else if (d <= -9.4e-104) {
tmp = t_0;
} else if (d <= 3.3e-156) {
tmp = (b - ((a * d) / c)) / c;
} else if (d <= 3.2e+115) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) t_1 = ((c * (b / d)) - a) / d tmp = 0 if d <= -1.6e+96: tmp = t_1 elif d <= -9.4e-104: tmp = t_0 elif d <= 3.3e-156: tmp = (b - ((a * d) / c)) / c elif d <= 3.2e+115: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -1.6e+96) tmp = t_1; elseif (d <= -9.4e-104) tmp = t_0; elseif (d <= 3.3e-156) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); elseif (d <= 3.2e+115) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); t_1 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -1.6e+96) tmp = t_1; elseif (d <= -9.4e-104) tmp = t_0; elseif (d <= 3.3e-156) tmp = (b - ((a * d) / c)) / c; elseif (d <= 3.2e+115) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.6e+96], t$95$1, If[LessEqual[d, -9.4e-104], t$95$0, If[LessEqual[d, 3.3e-156], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.2e+115], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.6 \cdot 10^{+96}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -9.4 \cdot 10^{-104}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{-156}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{+115}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.60000000000000003e96 or 3.2e115 < d Initial program 40.0%
Taylor expanded in c around 0 77.9%
+-commutative77.9%
mul-1-neg77.9%
unsub-neg77.9%
unpow277.9%
associate-/r*83.3%
div-sub83.3%
*-commutative83.3%
associate-/l*86.1%
Simplified86.1%
if -1.60000000000000003e96 < d < -9.4e-104 or 3.2999999999999999e-156 < d < 3.2e115Initial program 84.9%
if -9.4e-104 < d < 3.2999999999999999e-156Initial program 76.5%
Taylor expanded in c around inf 94.6%
mul-1-neg94.6%
unsub-neg94.6%
*-commutative94.6%
Simplified94.6%
Final simplification87.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.6e+97) (not (<= d 9e-26))) (/ (- (* c (/ b d)) a) d) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.6e+97) || !(d <= 9e-26)) {
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 <= (-1.6d+97)) .or. (.not. (d <= 9d-26))) 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 <= -1.6e+97) || !(d <= 9e-26)) {
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 <= -1.6e+97) or not (d <= 9e-26): 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 <= -1.6e+97) || !(d <= 9e-26)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.6e+97) || ~((d <= 9e-26))) 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, -1.6e+97], N[Not[LessEqual[d, 9e-26]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.6 \cdot 10^{+97} \lor \neg \left(d \leq 9 \cdot 10^{-26}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.60000000000000008e97 or 8.9999999999999998e-26 < d Initial program 50.3%
Taylor expanded in c around 0 75.1%
+-commutative75.1%
mul-1-neg75.1%
unsub-neg75.1%
unpow275.1%
associate-/r*79.4%
div-sub79.4%
*-commutative79.4%
associate-/l*81.5%
Simplified81.5%
if -1.60000000000000008e97 < d < 8.9999999999999998e-26Initial program 80.3%
Taylor expanded in c around inf 80.9%
mul-1-neg80.9%
unsub-neg80.9%
*-commutative80.9%
Simplified80.9%
Final simplification81.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.6e+97) (not (<= d 1.45e-24))) (/ (- (* b (/ c d)) a) d) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.6e+97) || !(d <= 1.45e-24)) {
tmp = ((b * (c / 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 <= (-1.6d+97)) .or. (.not. (d <= 1.45d-24))) then
tmp = ((b * (c / 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 <= -1.6e+97) || !(d <= 1.45e-24)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.6e+97) or not (d <= 1.45e-24): tmp = ((b * (c / d)) - a) / d else: tmp = (b - ((a * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.6e+97) || !(d <= 1.45e-24)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.6e+97) || ~((d <= 1.45e-24))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - ((a * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.6e+97], N[Not[LessEqual[d, 1.45e-24]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.6 \cdot 10^{+97} \lor \neg \left(d \leq 1.45 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.60000000000000008e97 or 1.4499999999999999e-24 < d Initial program 50.3%
*-un-lft-identity50.3%
add-sqr-sqrt50.3%
times-frac50.2%
hypot-define50.2%
hypot-define69.3%
Applied egg-rr69.3%
Taylor expanded in d around inf 79.4%
+-commutative79.4%
neg-mul-179.4%
sub-neg79.4%
associate-/l*81.0%
Simplified81.0%
if -1.60000000000000008e97 < d < 1.4499999999999999e-24Initial program 80.3%
Taylor expanded in c around inf 80.9%
mul-1-neg80.9%
unsub-neg80.9%
*-commutative80.9%
Simplified80.9%
Final simplification80.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3e+106) (not (<= d 5.8e-9))) (/ a (- d)) (/ (- b (/ (* a d) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3e+106) || !(d <= 5.8e-9)) {
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 <= (-3d+106)) .or. (.not. (d <= 5.8d-9))) 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 <= -3e+106) || !(d <= 5.8e-9)) {
tmp = a / -d;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3e+106) or not (d <= 5.8e-9): tmp = a / -d else: tmp = (b - ((a * d) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3e+106) || !(d <= 5.8e-9)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3e+106) || ~((d <= 5.8e-9))) tmp = a / -d; else tmp = (b - ((a * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3e+106], N[Not[LessEqual[d, 5.8e-9]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{+106} \lor \neg \left(d \leq 5.8 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.0000000000000001e106 or 5.79999999999999982e-9 < d Initial program 49.4%
Taylor expanded in c around 0 73.4%
associate-*r/73.4%
neg-mul-173.4%
Simplified73.4%
if -3.0000000000000001e106 < d < 5.79999999999999982e-9Initial program 80.2%
Taylor expanded in c around inf 79.5%
mul-1-neg79.5%
unsub-neg79.5%
*-commutative79.5%
Simplified79.5%
Final simplification76.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3e+106) (not (<= d 2.8e-15))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3e+106) || !(d <= 2.8e-15)) {
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 <= (-3d+106)) .or. (.not. (d <= 2.8d-15))) 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 <= -3e+106) || !(d <= 2.8e-15)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3e+106) or not (d <= 2.8e-15): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3e+106) || !(d <= 2.8e-15)) 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 <= -3e+106) || ~((d <= 2.8e-15))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3e+106], N[Not[LessEqual[d, 2.8e-15]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{+106} \lor \neg \left(d \leq 2.8 \cdot 10^{-15}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.0000000000000001e106 or 2.80000000000000014e-15 < d Initial program 49.4%
Taylor expanded in c around 0 73.0%
associate-*r/73.0%
neg-mul-173.0%
Simplified73.0%
if -3.0000000000000001e106 < d < 2.80000000000000014e-15Initial program 80.6%
Taylor expanded in c around inf 63.0%
Final simplification67.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.6e+168) (not (<= d 2.25e+147))) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.6e+168) || !(d <= 2.25e+147)) {
tmp = a / d;
} else {
tmp = 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 <= (-3.6d+168)) .or. (.not. (d <= 2.25d+147))) then
tmp = a / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.6e+168) || !(d <= 2.25e+147)) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.6e+168) or not (d <= 2.25e+147): tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.6e+168) || !(d <= 2.25e+147)) tmp = Float64(a / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.6e+168) || ~((d <= 2.25e+147))) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.6e+168], N[Not[LessEqual[d, 2.25e+147]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.6 \cdot 10^{+168} \lor \neg \left(d \leq 2.25 \cdot 10^{+147}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -3.5999999999999999e168 or 2.25000000000000004e147 < d Initial program 34.3%
*-un-lft-identity34.3%
add-sqr-sqrt34.3%
times-frac34.3%
hypot-define34.3%
hypot-define59.4%
Applied egg-rr59.4%
Taylor expanded in d around -inf 48.2%
Taylor expanded in c around 0 30.0%
if -3.5999999999999999e168 < d < 2.25000000000000004e147Initial program 79.5%
*-un-lft-identity79.5%
add-sqr-sqrt79.5%
times-frac79.5%
hypot-define79.5%
hypot-define88.2%
Applied egg-rr88.2%
Taylor expanded in d around -inf 20.4%
Taylor expanded in c around inf 11.2%
Final simplification16.4%
(FPCore (a b c d) :precision binary64 (if (<= d -2.3e+138) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.3e+138) {
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.3d+138)) 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.3e+138) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.3e+138: tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.3e+138) 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 <= -2.3e+138) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.3e+138], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.3 \cdot 10^{+138}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.30000000000000008e138Initial program 34.5%
*-un-lft-identity34.5%
add-sqr-sqrt34.5%
times-frac34.5%
hypot-define34.5%
hypot-define53.8%
Applied egg-rr53.8%
Taylor expanded in d around -inf 80.8%
Taylor expanded in c around 0 30.1%
if -2.30000000000000008e138 < d Initial program 72.5%
Taylor expanded in c around inf 48.5%
(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 67.2%
*-un-lft-identity67.2%
add-sqr-sqrt67.2%
times-frac67.1%
hypot-define67.1%
hypot-define80.3%
Applied egg-rr80.3%
Taylor expanded in d around -inf 28.0%
Taylor expanded in c around inf 11.4%
(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 2024163
(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))))