
(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 8 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.9e+152) (not (<= d 2.1e+122)))
(/ (- (* c (/ b d)) a) d)
(-
(* (/ 1.0 (hypot c d)) (* b (/ c (hypot c d))))
(/ (* d a) (pow (hypot c d) 2.0)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.9e+152) || !(d <= 2.1e+122)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = ((1.0 / hypot(c, d)) * (b * (c / hypot(c, d)))) - ((d * a) / pow(hypot(c, d), 2.0));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.9e+152) || !(d <= 2.1e+122)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = ((1.0 / Math.hypot(c, d)) * (b * (c / Math.hypot(c, d)))) - ((d * a) / Math.pow(Math.hypot(c, d), 2.0));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.9e+152) or not (d <= 2.1e+122): tmp = ((c * (b / d)) - a) / d else: tmp = ((1.0 / math.hypot(c, d)) * (b * (c / math.hypot(c, d)))) - ((d * a) / math.pow(math.hypot(c, d), 2.0)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.9e+152) || !(d <= 2.1e+122)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(Float64(1.0 / hypot(c, d)) * Float64(b * Float64(c / hypot(c, d)))) - Float64(Float64(d * a) / (hypot(c, d) ^ 2.0))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.9e+152) || ~((d <= 2.1e+122))) tmp = ((c * (b / d)) - a) / d; else tmp = ((1.0 / hypot(c, d)) * (b * (c / hypot(c, d)))) - ((d * a) / (hypot(c, d) ^ 2.0)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.9e+152], N[Not[LessEqual[d, 2.1e+122]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(d * a), $MachinePrecision] / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.9 \cdot 10^{+152} \lor \neg \left(d \leq 2.1 \cdot 10^{+122}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\right) - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\
\end{array}
\end{array}
if d < -2.8999999999999998e152 or 2.10000000000000016e122 < d Initial program 30.0%
Taylor expanded in c around 0 80.8%
+-commutative80.8%
mul-1-neg80.8%
unsub-neg80.8%
unpow280.8%
associate-/r*89.4%
div-sub89.4%
*-commutative89.4%
associate-/l*91.9%
Simplified91.9%
if -2.8999999999999998e152 < d < 2.10000000000000016e122Initial program 71.9%
div-sub70.0%
*-un-lft-identity70.0%
add-sqr-sqrt70.0%
times-frac69.8%
fmm-def69.8%
hypot-define69.8%
hypot-define76.4%
associate-/l*76.0%
add-sqr-sqrt76.0%
pow276.0%
hypot-define76.0%
Applied egg-rr76.0%
fmm-undef75.4%
associate-/l*89.5%
associate-*r/88.7%
*-commutative88.7%
Simplified88.7%
Final simplification89.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* c b) (* d a))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 5e+304)
(* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
(/ (- (* c (/ b d)) a) d))))
double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 5e+304) {
tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 5e+304) {
tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = (c * b) - (d * a) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 5e+304: tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d)) else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(c * b) - Float64(d * a)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 5e+304) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d))); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (c * b) - (d * a); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 5e+304) tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d)); else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+304], 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[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot b - d \cdot a\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.9999999999999997e304Initial program 76.2%
*-un-lft-identity76.2%
add-sqr-sqrt76.2%
times-frac76.0%
hypot-define76.0%
hypot-define97.2%
Applied egg-rr97.2%
if 4.9999999999999997e304 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 11.5%
Taylor expanded in c around 0 51.3%
+-commutative51.3%
mul-1-neg51.3%
unsub-neg51.3%
unpow251.3%
associate-/r*53.0%
div-sub54.5%
*-commutative54.5%
associate-/l*58.5%
Simplified58.5%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -310.0)
t_0
(if (<= d 1.1e-152)
(/ (- b (/ (* d a) c)) c)
(if (<= d 1.25e+118)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -310.0) {
tmp = t_0;
} else if (d <= 1.1e-152) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 1.25e+118) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
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) / d
if (d <= (-310.0d0)) then
tmp = t_0
else if (d <= 1.1d-152) then
tmp = (b - ((d * a) / c)) / c
else if (d <= 1.25d+118) then
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
else
tmp = t_0
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) / d;
double tmp;
if (d <= -310.0) {
tmp = t_0;
} else if (d <= 1.1e-152) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 1.25e+118) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * (b / d)) - a) / d tmp = 0 if d <= -310.0: tmp = t_0 elif d <= 1.1e-152: tmp = (b - ((d * a) / c)) / c elif d <= 1.25e+118: tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -310.0) tmp = t_0; elseif (d <= 1.1e-152) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 1.25e+118) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -310.0) tmp = t_0; elseif (d <= 1.1e-152) tmp = (b - ((d * a) / c)) / c; elseif (d <= 1.25e+118) tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -310.0], t$95$0, If[LessEqual[d, 1.1e-152], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.25e+118], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -310:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.1 \cdot 10^{-152}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{+118}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -310 or 1.24999999999999993e118 < d Initial program 39.1%
Taylor expanded in c around 0 75.9%
+-commutative75.9%
mul-1-neg75.9%
unsub-neg75.9%
unpow275.9%
associate-/r*82.3%
div-sub82.3%
*-commutative82.3%
associate-/l*84.1%
Simplified84.1%
if -310 < d < 1.09999999999999992e-152Initial program 66.0%
Taylor expanded in c around inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
*-commutative90.4%
Simplified90.4%
if 1.09999999999999992e-152 < d < 1.24999999999999993e118Initial program 85.2%
Final simplification86.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -370000.0) (not (<= d 2.8e-37))) (/ (- (* c (/ b d)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -370000.0) || !(d <= 2.8e-37)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((d * a) / 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 <= (-370000.0d0)) .or. (.not. (d <= 2.8d-37))) then
tmp = ((c * (b / d)) - a) / d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -370000.0) || !(d <= 2.8e-37)) {
tmp = ((c * (b / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -370000.0) or not (d <= 2.8e-37): tmp = ((c * (b / d)) - a) / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -370000.0) || !(d <= 2.8e-37)) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -370000.0) || ~((d <= 2.8e-37))) tmp = ((c * (b / d)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -370000.0], N[Not[LessEqual[d, 2.8e-37]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -370000 \lor \neg \left(d \leq 2.8 \cdot 10^{-37}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -3.7e5 or 2.8000000000000001e-37 < d Initial program 47.4%
Taylor expanded in c around 0 74.5%
+-commutative74.5%
mul-1-neg74.5%
unsub-neg74.5%
unpow274.5%
associate-/r*79.5%
div-sub79.5%
*-commutative79.5%
associate-/l*81.0%
Simplified81.0%
if -3.7e5 < d < 2.8000000000000001e-37Initial program 71.5%
Taylor expanded in c around inf 88.3%
mul-1-neg88.3%
unsub-neg88.3%
*-commutative88.3%
Simplified88.3%
Final simplification84.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.5e+16) (not (<= d 9.6e-35))) (/ a (- d)) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.5e+16) || !(d <= 9.6e-35)) {
tmp = a / -d;
} else {
tmp = (b - ((d * a) / 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 <= (-6.5d+16)) .or. (.not. (d <= 9.6d-35))) then
tmp = a / -d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.5e+16) || !(d <= 9.6e-35)) {
tmp = a / -d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.5e+16) or not (d <= 9.6e-35): tmp = a / -d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.5e+16) || !(d <= 9.6e-35)) tmp = Float64(a / Float64(-d)); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -6.5e+16) || ~((d <= 9.6e-35))) tmp = a / -d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.5e+16], N[Not[LessEqual[d, 9.6e-35]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.5 \cdot 10^{+16} \lor \neg \left(d \leq 9.6 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -6.5e16 or 9.6000000000000005e-35 < d Initial program 47.3%
Taylor expanded in c around 0 66.6%
associate-*r/66.6%
neg-mul-166.6%
Simplified66.6%
if -6.5e16 < d < 9.6000000000000005e-35Initial program 71.1%
Taylor expanded in c around inf 87.6%
mul-1-neg87.6%
unsub-neg87.6%
*-commutative87.6%
Simplified87.6%
Final simplification76.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7e+30) (not (<= d 3.5e-44))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7e+30) || !(d <= 3.5e-44)) {
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 <= (-7d+30)) .or. (.not. (d <= 3.5d-44))) 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 <= -7e+30) || !(d <= 3.5e-44)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7e+30) or not (d <= 3.5e-44): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7e+30) || !(d <= 3.5e-44)) 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 <= -7e+30) || ~((d <= 3.5e-44))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7e+30], N[Not[LessEqual[d, 3.5e-44]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{+30} \lor \neg \left(d \leq 3.5 \cdot 10^{-44}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -7.00000000000000042e30 or 3.4999999999999998e-44 < d Initial program 47.3%
Taylor expanded in c around 0 66.9%
associate-*r/66.9%
neg-mul-166.9%
Simplified66.9%
if -7.00000000000000042e30 < d < 3.4999999999999998e-44Initial program 70.7%
Taylor expanded in c around inf 69.8%
Final simplification68.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.3e+181) (not (<= d 2e+94))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.3e+181) || !(d <= 2e+94)) {
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 <= (-3.3d+181)) .or. (.not. (d <= 2d+94))) 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 <= -3.3e+181) || !(d <= 2e+94)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.3e+181) or not (d <= 2e+94): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.3e+181) || !(d <= 2e+94)) 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 <= -3.3e+181) || ~((d <= 2e+94))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.3e+181], N[Not[LessEqual[d, 2e+94]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.3 \cdot 10^{+181} \lor \neg \left(d \leq 2 \cdot 10^{+94}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -3.30000000000000017e181 or 2e94 < d Initial program 36.2%
*-un-lft-identity36.2%
add-sqr-sqrt36.2%
times-frac36.2%
hypot-define36.2%
hypot-define63.6%
Applied egg-rr63.6%
Taylor expanded in d around -inf 54.1%
associate-*r/54.1%
*-commutative54.1%
neg-mul-154.1%
distribute-rgt-neg-in54.1%
Simplified54.1%
Taylor expanded in c around 0 32.2%
if -3.30000000000000017e181 < d < 2e94Initial program 68.1%
Taylor expanded in c around inf 56.1%
Final simplification48.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 58.0%
*-un-lft-identity58.0%
add-sqr-sqrt58.0%
times-frac57.9%
hypot-define57.9%
hypot-define74.4%
Applied egg-rr74.4%
Taylor expanded in d around -inf 32.3%
associate-*r/32.3%
*-commutative32.3%
neg-mul-132.3%
distribute-rgt-neg-in32.3%
Simplified32.3%
Taylor expanded in c around 0 12.6%
(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 2024181
(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))))