
(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 10 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 (- (* (/ 1.0 (hypot c d)) (* b (/ c (hypot c d)))) (* (/ d (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
return ((1.0 / hypot(c, d)) * (b * (c / hypot(c, d)))) - ((d / hypot(c, d)) * (a / hypot(c, d)));
}
public static double code(double a, double b, double c, double d) {
return ((1.0 / Math.hypot(c, d)) * (b * (c / Math.hypot(c, d)))) - ((d / Math.hypot(c, d)) * (a / Math.hypot(c, d)));
}
def code(a, b, c, d): return ((1.0 / math.hypot(c, d)) * (b * (c / math.hypot(c, d)))) - ((d / math.hypot(c, d)) * (a / math.hypot(c, d)))
function code(a, b, c, d) return Float64(Float64(Float64(1.0 / hypot(c, d)) * Float64(b * Float64(c / hypot(c, d)))) - Float64(Float64(d / hypot(c, d)) * Float64(a / hypot(c, d)))) end
function tmp = code(a, b, c, d) tmp = ((1.0 / hypot(c, d)) * (b * (c / hypot(c, d)))) - ((d / hypot(c, d)) * (a / hypot(c, d))); end
code[a_, b_, c_, d_] := 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 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\right) - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}
\end{array}
Initial program 64.6%
div-sub62.9%
*-un-lft-identity62.9%
add-sqr-sqrt62.9%
times-frac62.9%
fmm-def62.9%
hypot-define62.9%
hypot-define68.7%
associate-/l*71.1%
add-sqr-sqrt71.1%
pow271.1%
hypot-define71.1%
Applied egg-rr71.1%
fmm-undef71.1%
associate-/l*80.9%
associate-*r/78.1%
*-commutative78.1%
Simplified78.1%
unpow278.1%
times-frac97.8%
Applied egg-rr97.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ 1.0 (hypot c d))) (t_1 (- (* c b) (* d a))))
(if (<= (/ t_1 (+ (* c c) (* d d))) 2e+301)
(* t_0 (/ t_1 (hypot c d)))
(- (* t_0 (* b (/ c (hypot c d)))) (/ a d)))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / hypot(c, d);
double t_1 = (c * b) - (d * a);
double tmp;
if ((t_1 / ((c * c) + (d * d))) <= 2e+301) {
tmp = t_0 * (t_1 / hypot(c, d));
} else {
tmp = (t_0 * (b * (c / hypot(c, d)))) - (a / d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = 1.0 / Math.hypot(c, d);
double t_1 = (c * b) - (d * a);
double tmp;
if ((t_1 / ((c * c) + (d * d))) <= 2e+301) {
tmp = t_0 * (t_1 / Math.hypot(c, d));
} else {
tmp = (t_0 * (b * (c / Math.hypot(c, d)))) - (a / d);
}
return tmp;
}
def code(a, b, c, d): t_0 = 1.0 / math.hypot(c, d) t_1 = (c * b) - (d * a) tmp = 0 if (t_1 / ((c * c) + (d * d))) <= 2e+301: tmp = t_0 * (t_1 / math.hypot(c, d)) else: tmp = (t_0 * (b * (c / math.hypot(c, d)))) - (a / d) return tmp
function code(a, b, c, d) t_0 = Float64(1.0 / hypot(c, d)) t_1 = Float64(Float64(c * b) - Float64(d * a)) tmp = 0.0 if (Float64(t_1 / Float64(Float64(c * c) + Float64(d * d))) <= 2e+301) tmp = Float64(t_0 * Float64(t_1 / hypot(c, d))); else tmp = Float64(Float64(t_0 * Float64(b * Float64(c / hypot(c, d)))) - Float64(a / d)); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = 1.0 / hypot(c, d); t_1 = (c * b) - (d * a); tmp = 0.0; if ((t_1 / ((c * c) + (d * d))) <= 2e+301) tmp = t_0 * (t_1 / hypot(c, d)); else tmp = (t_0 * (b * (c / hypot(c, d)))) - (a / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+301], N[(t$95$0 * N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(b * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := c \cdot b - d \cdot a\\
\mathbf{if}\;\frac{t\_1}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+301}:\\
\;\;\;\;t\_0 \cdot \frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\right) - \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.00000000000000011e301Initial program 81.5%
*-un-lft-identity81.5%
add-sqr-sqrt81.5%
times-frac81.6%
hypot-define81.6%
hypot-define97.7%
Applied egg-rr97.7%
if 2.00000000000000011e301 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.0%
div-sub12.8%
*-un-lft-identity12.8%
add-sqr-sqrt12.8%
times-frac12.8%
fmm-def12.8%
hypot-define12.8%
hypot-define16.8%
associate-/l*26.8%
add-sqr-sqrt26.8%
pow226.8%
hypot-define26.8%
Applied egg-rr26.8%
fmm-undef26.8%
associate-/l*61.9%
associate-*r/50.4%
*-commutative50.4%
Simplified50.4%
Taylor expanded in d around inf 77.9%
Final simplification92.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* c b) (* d a))))
(if (<= (/ t_0 (+ (* c c) (* d d))) 2e+301)
(* (/ 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 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 2e+301) {
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 = (c * b) - (d * a);
double tmp;
if ((t_0 / ((c * c) + (d * d))) <= 2e+301) {
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 = (c * b) - (d * a) tmp = 0 if (t_0 / ((c * c) + (d * d))) <= 2e+301: 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(c * b) - Float64(d * a)) tmp = 0.0 if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 2e+301) 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 = (c * b) - (d * a); tmp = 0.0; if ((t_0 / ((c * c) + (d * d))) <= 2e+301) 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[(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], 2e+301], 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 := c \cdot b - d \cdot a\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+301}:\\
\;\;\;\;\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))) < 2.00000000000000011e301Initial program 81.5%
*-un-lft-identity81.5%
add-sqr-sqrt81.5%
times-frac81.6%
hypot-define81.6%
hypot-define97.7%
Applied egg-rr97.7%
if 2.00000000000000011e301 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.0%
Taylor expanded in c around 0 49.5%
+-commutative49.5%
mul-1-neg49.5%
unsub-neg49.5%
unpow249.5%
associate-/r*54.7%
div-sub54.9%
*-commutative54.9%
associate-/l*63.5%
Simplified63.5%
Taylor expanded in c around 0 54.9%
associate-/l*63.5%
Simplified63.5%
Final simplification88.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -16000000000.0)
t_0
(if (<= d -4.5e-115)
(/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
(if (<= d 1850000000000.0) (/ (- b (* a (/ d c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -16000000000.0) {
tmp = t_0;
} else if (d <= -4.5e-115) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 1850000000000.0) {
tmp = (b - (a * (d / c))) / c;
} 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 <= (-16000000000.0d0)) then
tmp = t_0
else if (d <= (-4.5d-115)) then
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
else if (d <= 1850000000000.0d0) then
tmp = (b - (a * (d / c))) / c
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 <= -16000000000.0) {
tmp = t_0;
} else if (d <= -4.5e-115) {
tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
} else if (d <= 1850000000000.0) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * (b / d)) - a) / d tmp = 0 if d <= -16000000000.0: tmp = t_0 elif d <= -4.5e-115: tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)) elif d <= 1850000000000.0: tmp = (b - (a * (d / c))) / c 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 <= -16000000000.0) tmp = t_0; elseif (d <= -4.5e-115) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 1850000000000.0) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); 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 <= -16000000000.0) tmp = t_0; elseif (d <= -4.5e-115) tmp = ((c * b) - (d * a)) / ((c * c) + (d * d)); elseif (d <= 1850000000000.0) tmp = (b - (a * (d / c))) / c; 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, -16000000000.0], t$95$0, If[LessEqual[d, -4.5e-115], 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, 1850000000000.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 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -16000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.5 \cdot 10^{-115}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 1850000000000:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.6e10 or 1.85e12 < d Initial program 52.0%
Taylor expanded in c around 0 73.8%
+-commutative73.8%
mul-1-neg73.8%
unsub-neg73.8%
unpow273.8%
associate-/r*77.8%
div-sub77.8%
*-commutative77.8%
associate-/l*83.0%
Simplified83.0%
if -1.6e10 < d < -4.50000000000000023e-115Initial program 99.6%
if -4.50000000000000023e-115 < d < 1.85e12Initial program 72.5%
Taylor expanded in c around inf 86.5%
mul-1-neg86.5%
unsub-neg86.5%
*-commutative86.5%
Simplified86.5%
*-commutative86.5%
associate-*r/86.5%
*-commutative86.5%
Applied egg-rr86.5%
Final simplification85.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -60000000.0) (not (<= d 6e+14))) (/ (- (* c (/ b d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -60000000.0) || !(d <= 6e+14)) {
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 <= (-60000000.0d0)) .or. (.not. (d <= 6d+14))) 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 <= -60000000.0) || !(d <= 6e+14)) {
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 <= -60000000.0) or not (d <= 6e+14): 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 <= -60000000.0) || !(d <= 6e+14)) 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 <= -60000000.0) || ~((d <= 6e+14))) 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, -60000000.0], N[Not[LessEqual[d, 6e+14]], $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 -60000000 \lor \neg \left(d \leq 6 \cdot 10^{+14}\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 < -6e7 or 6e14 < d Initial program 52.4%
Taylor expanded in c around 0 74.0%
+-commutative74.0%
mul-1-neg74.0%
unsub-neg74.0%
unpow274.0%
associate-/r*78.0%
div-sub78.0%
*-commutative78.0%
associate-/l*83.2%
Simplified83.2%
if -6e7 < d < 6e14Initial program 76.7%
Taylor expanded in c around inf 81.7%
mul-1-neg81.7%
unsub-neg81.7%
*-commutative81.7%
Simplified81.7%
*-commutative81.7%
associate-*r/81.7%
*-commutative81.7%
Applied egg-rr81.7%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= d -16200000.0) (not (<= d 5e-13))) (/ (- (* b (/ c d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -16200000.0) || !(d <= 5e-13)) {
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 <= (-16200000.0d0)) .or. (.not. (d <= 5d-13))) 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 <= -16200000.0) || !(d <= 5e-13)) {
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 <= -16200000.0) or not (d <= 5e-13): 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 <= -16200000.0) || !(d <= 5e-13)) tmp = Float64(Float64(Float64(b * Float64(c / 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 <= -16200000.0) || ~((d <= 5e-13))) 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, -16200000.0], N[Not[LessEqual[d, 5e-13]], $MachinePrecision]], N[(N[(N[(b * N[(c / 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 -16200000 \lor \neg \left(d \leq 5 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.62e7 or 4.9999999999999999e-13 < d Initial program 53.4%
Taylor expanded in c around 0 72.7%
+-commutative72.7%
mul-1-neg72.7%
unsub-neg72.7%
unpow272.7%
associate-/r*76.4%
div-sub76.4%
*-commutative76.4%
associate-/l*80.6%
Simplified80.6%
Taylor expanded in c around 0 76.4%
associate-/l*80.6%
Simplified80.6%
if -1.62e7 < d < 4.9999999999999999e-13Initial program 76.9%
Taylor expanded in c around inf 83.7%
mul-1-neg83.7%
unsub-neg83.7%
*-commutative83.7%
Simplified83.7%
*-commutative83.7%
associate-*r/83.7%
*-commutative83.7%
Applied egg-rr83.7%
Final simplification82.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.8e-38) (not (<= d 1.3e+24))) (/ a (- d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.8e-38) || !(d <= 1.3e+24)) {
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 <= (-7.8d-38)) .or. (.not. (d <= 1.3d+24))) 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 <= -7.8e-38) || !(d <= 1.3e+24)) {
tmp = a / -d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.8e-38) or not (d <= 1.3e+24): tmp = a / -d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.8e-38) || !(d <= 1.3e+24)) 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 <= -7.8e-38) || ~((d <= 1.3e+24))) tmp = a / -d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.8e-38], N[Not[LessEqual[d, 1.3e+24]], $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 -7.8 \cdot 10^{-38} \lor \neg \left(d \leq 1.3 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -7.7999999999999998e-38 or 1.2999999999999999e24 < d Initial program 54.6%
Taylor expanded in c around 0 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
if -7.7999999999999998e-38 < d < 1.2999999999999999e24Initial program 75.2%
Taylor expanded in c around inf 82.7%
mul-1-neg82.7%
unsub-neg82.7%
*-commutative82.7%
Simplified82.7%
*-commutative82.7%
associate-*r/82.7%
*-commutative82.7%
Applied egg-rr82.7%
Final simplification75.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.35e-38) (not (<= d 4e+21))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.35e-38) || !(d <= 4e+21)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-2.35d-38)) .or. (.not. (d <= 4d+21))) then
tmp = a / -d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.35e-38) || !(d <= 4e+21)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.35e-38) or not (d <= 4e+21): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.35e-38) || !(d <= 4e+21)) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.35e-38) || ~((d <= 4e+21))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.35e-38], N[Not[LessEqual[d, 4e+21]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.35 \cdot 10^{-38} \lor \neg \left(d \leq 4 \cdot 10^{+21}\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.34999999999999999e-38 or 4e21 < d Initial program 54.6%
Taylor expanded in c around 0 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
if -2.34999999999999999e-38 < d < 4e21Initial program 75.2%
Taylor expanded in c around inf 70.2%
Final simplification69.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -5.6e+210) (not (<= d 1.02e+166))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -5.6e+210) || !(d <= 1.02e+166)) {
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.6d+210)) .or. (.not. (d <= 1.02d+166))) 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.6e+210) || !(d <= 1.02e+166)) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -5.6e+210) or not (d <= 1.02e+166): tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -5.6e+210) || !(d <= 1.02e+166)) 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.6e+210) || ~((d <= 1.02e+166))) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.6e+210], N[Not[LessEqual[d, 1.02e+166]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.6 \cdot 10^{+210} \lor \neg \left(d \leq 1.02 \cdot 10^{+166}\right):\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -5.6000000000000004e210 or 1.0200000000000001e166 < d Initial program 40.7%
Taylor expanded in c around 0 87.8%
associate-*r/87.8%
neg-mul-187.8%
Simplified87.8%
add-sqr-sqrt43.7%
sqrt-unprod48.6%
sqr-neg48.6%
sqrt-unprod19.6%
add-sqr-sqrt41.4%
*-un-lft-identity41.4%
Applied egg-rr41.4%
*-lft-identity41.4%
Simplified41.4%
if -5.6000000000000004e210 < d < 1.0200000000000001e166Initial program 70.7%
Taylor expanded in c around inf 52.4%
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 64.6%
Taylor expanded in c around 0 43.2%
associate-*r/43.2%
neg-mul-143.2%
Simplified43.2%
add-sqr-sqrt23.7%
sqrt-unprod24.1%
sqr-neg24.1%
sqrt-unprod6.3%
add-sqr-sqrt12.5%
*-un-lft-identity12.5%
Applied egg-rr12.5%
*-lft-identity12.5%
Simplified12.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 2024166
(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))))