
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= t_0 (- INFINITY))
(+ (/ a c) (/ b (* c (/ c d))))
(if (<= t_0 5e+302)
(/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
(* (/ -1.0 d) (- (/ (- a) (/ d c)) b))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = (a / c) + (b / (c * (c / d)));
} else if (t_0 <= 5e+302) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (-1.0 / d) * ((-a / (d / c)) - b);
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); elseif (t_0 <= 5e+302) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-a) / Float64(d / c)) - b)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+302], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / d), $MachinePrecision] * N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0Initial program 47.7%
Taylor expanded in c around inf 65.9%
associate-/l*65.9%
Simplified65.9%
pow265.9%
*-un-lft-identity65.9%
times-frac75.9%
Applied egg-rr75.9%
if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5e302Initial program 84.6%
*-un-lft-identity84.6%
add-sqr-sqrt84.6%
times-frac84.6%
hypot-def84.6%
fma-def84.6%
hypot-def99.6%
Applied egg-rr99.6%
associate-*l/99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
if 5e302 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 7.6%
*-un-lft-identity7.6%
add-sqr-sqrt7.6%
times-frac7.6%
hypot-def7.6%
fma-def7.6%
hypot-def12.8%
Applied egg-rr12.8%
Taylor expanded in d around -inf 22.0%
neg-mul-122.0%
+-commutative22.0%
unsub-neg22.0%
mul-1-neg22.0%
associate-/l*25.2%
distribute-neg-frac25.2%
Simplified25.2%
Taylor expanded in d around -inf 55.8%
Final simplification87.6%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.56e+121)
(/ (- (/ (- a) (/ d c)) b) (hypot c d))
(if (<= d -5.2e-158)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 5.4e-15)
(+ (/ a c) (/ b (* c (/ c d))))
(/ (+ b (/ 1.0 (/ (/ d c) a))) (hypot c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.56e+121) {
tmp = ((-a / (d / c)) - b) / hypot(c, d);
} else if (d <= -5.2e-158) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 5.4e-15) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = (b + (1.0 / ((d / c) / a))) / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.56e+121) {
tmp = ((-a / (d / c)) - b) / Math.hypot(c, d);
} else if (d <= -5.2e-158) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 5.4e-15) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = (b + (1.0 / ((d / c) / a))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.56e+121: tmp = ((-a / (d / c)) - b) / math.hypot(c, d) elif d <= -5.2e-158: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 5.4e-15: tmp = (a / c) + (b / (c * (c / d))) else: tmp = (b + (1.0 / ((d / c) / a))) / math.hypot(c, d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.56e+121) tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d)); elseif (d <= -5.2e-158) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 5.4e-15) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); else tmp = Float64(Float64(b + Float64(1.0 / Float64(Float64(d / c) / a))) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.56e+121) tmp = ((-a / (d / c)) - b) / hypot(c, d); elseif (d <= -5.2e-158) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 5.4e-15) tmp = (a / c) + (b / (c * (c / d))); else tmp = (b + (1.0 / ((d / c) / a))) / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.56e+121], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.2e-158], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.4e-15], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\
\;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -5.2 \cdot 10^{-158}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 5.4 \cdot 10^{-15}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{1}{\frac{\frac{d}{c}}{a}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.5599999999999999e121Initial program 39.4%
*-un-lft-identity39.4%
add-sqr-sqrt39.4%
times-frac39.5%
hypot-def39.5%
fma-def39.5%
hypot-def63.1%
Applied egg-rr63.1%
associate-*l/63.1%
*-un-lft-identity63.1%
Applied egg-rr63.1%
Taylor expanded in d around -inf 84.0%
neg-mul-183.6%
+-commutative83.6%
unsub-neg83.6%
mul-1-neg83.6%
associate-/l*88.6%
distribute-neg-frac88.6%
Simplified89.0%
if -1.5599999999999999e121 < d < -5.2000000000000001e-158Initial program 83.0%
if -5.2000000000000001e-158 < d < 5.40000000000000018e-15Initial program 70.4%
Taylor expanded in c around inf 82.0%
associate-/l*79.9%
Simplified79.9%
pow279.9%
*-un-lft-identity79.9%
times-frac87.1%
Applied egg-rr87.1%
if 5.40000000000000018e-15 < d Initial program 53.1%
*-un-lft-identity53.1%
add-sqr-sqrt53.1%
times-frac53.1%
hypot-def53.1%
fma-def53.1%
hypot-def64.6%
Applied egg-rr64.6%
associate-*l/64.8%
*-un-lft-identity64.8%
Applied egg-rr64.8%
Taylor expanded in c around 0 80.3%
associate-/l*86.1%
Simplified86.1%
clear-num86.2%
inv-pow86.2%
associate-/l/80.3%
*-commutative80.3%
Applied egg-rr80.3%
unpow-180.3%
associate-/r*86.2%
Simplified86.2%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.56e+121)
(* (/ -1.0 d) (- (/ (- a) (/ d c)) b))
(if (<= d -2.4e-162)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 2.3e-14)
(+ (/ a c) (/ b (* c (/ c d))))
(/ (+ b (* a (/ c d))) (hypot c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.56e+121) {
tmp = (-1.0 / d) * ((-a / (d / c)) - b);
} else if (d <= -2.4e-162) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.3e-14) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = (b + (a * (c / d))) / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.56e+121) {
tmp = (-1.0 / d) * ((-a / (d / c)) - b);
} else if (d <= -2.4e-162) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 2.3e-14) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = (b + (a * (c / d))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.56e+121: tmp = (-1.0 / d) * ((-a / (d / c)) - b) elif d <= -2.4e-162: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 2.3e-14: tmp = (a / c) + (b / (c * (c / d))) else: tmp = (b + (a * (c / d))) / math.hypot(c, d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.56e+121) tmp = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-a) / Float64(d / c)) - b)); elseif (d <= -2.4e-162) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 2.3e-14) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.56e+121) tmp = (-1.0 / d) * ((-a / (d / c)) - b); elseif (d <= -2.4e-162) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 2.3e-14) tmp = (a / c) + (b / (c * (c / d))); else tmp = (b + (a * (c / d))) / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.56e+121], N[(N[(-1.0 / d), $MachinePrecision] * N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.4e-162], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.3e-14], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-162}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{-14}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.5599999999999999e121Initial program 39.4%
*-un-lft-identity39.4%
add-sqr-sqrt39.4%
times-frac39.5%
hypot-def39.5%
fma-def39.5%
hypot-def63.1%
Applied egg-rr63.1%
Taylor expanded in d around -inf 83.6%
neg-mul-183.6%
+-commutative83.6%
unsub-neg83.6%
mul-1-neg83.6%
associate-/l*88.6%
distribute-neg-frac88.6%
Simplified88.6%
Taylor expanded in d around -inf 83.4%
if -1.5599999999999999e121 < d < -2.4000000000000002e-162Initial program 83.0%
if -2.4000000000000002e-162 < d < 2.29999999999999998e-14Initial program 70.4%
Taylor expanded in c around inf 82.0%
associate-/l*79.9%
Simplified79.9%
pow279.9%
*-un-lft-identity79.9%
times-frac87.1%
Applied egg-rr87.1%
if 2.29999999999999998e-14 < d Initial program 53.1%
*-un-lft-identity53.1%
add-sqr-sqrt53.1%
times-frac53.1%
hypot-def53.1%
fma-def53.1%
hypot-def64.6%
Applied egg-rr64.6%
associate-*l/64.8%
*-un-lft-identity64.8%
Applied egg-rr64.8%
Taylor expanded in c around 0 80.3%
associate-/l*86.1%
Simplified86.1%
clear-num86.2%
associate-/r/86.1%
clear-num86.1%
Applied egg-rr86.1%
Final simplification85.3%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.56e+121)
(/ (- (/ (- a) (/ d c)) b) (hypot c d))
(if (<= d -7.5e-161)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 1.6e-15)
(+ (/ a c) (/ b (* c (/ c d))))
(/ (+ b (* a (/ c d))) (hypot c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.56e+121) {
tmp = ((-a / (d / c)) - b) / hypot(c, d);
} else if (d <= -7.5e-161) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 1.6e-15) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = (b + (a * (c / d))) / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.56e+121) {
tmp = ((-a / (d / c)) - b) / Math.hypot(c, d);
} else if (d <= -7.5e-161) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 1.6e-15) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = (b + (a * (c / d))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.56e+121: tmp = ((-a / (d / c)) - b) / math.hypot(c, d) elif d <= -7.5e-161: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 1.6e-15: tmp = (a / c) + (b / (c * (c / d))) else: tmp = (b + (a * (c / d))) / math.hypot(c, d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.56e+121) tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d)); elseif (d <= -7.5e-161) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 1.6e-15) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.56e+121) tmp = ((-a / (d / c)) - b) / hypot(c, d); elseif (d <= -7.5e-161) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 1.6e-15) tmp = (a / c) + (b / (c * (c / d))); else tmp = (b + (a * (c / d))) / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.56e+121], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -7.5e-161], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.6e-15], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\
\;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -7.5 \cdot 10^{-161}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 1.6 \cdot 10^{-15}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.5599999999999999e121Initial program 39.4%
*-un-lft-identity39.4%
add-sqr-sqrt39.4%
times-frac39.5%
hypot-def39.5%
fma-def39.5%
hypot-def63.1%
Applied egg-rr63.1%
associate-*l/63.1%
*-un-lft-identity63.1%
Applied egg-rr63.1%
Taylor expanded in d around -inf 84.0%
neg-mul-183.6%
+-commutative83.6%
unsub-neg83.6%
mul-1-neg83.6%
associate-/l*88.6%
distribute-neg-frac88.6%
Simplified89.0%
if -1.5599999999999999e121 < d < -7.49999999999999991e-161Initial program 83.0%
if -7.49999999999999991e-161 < d < 1.6e-15Initial program 70.4%
Taylor expanded in c around inf 82.0%
associate-/l*79.9%
Simplified79.9%
pow279.9%
*-un-lft-identity79.9%
times-frac87.1%
Applied egg-rr87.1%
if 1.6e-15 < d Initial program 53.1%
*-un-lft-identity53.1%
add-sqr-sqrt53.1%
times-frac53.1%
hypot-def53.1%
fma-def53.1%
hypot-def64.6%
Applied egg-rr64.6%
associate-*l/64.8%
*-un-lft-identity64.8%
Applied egg-rr64.8%
Taylor expanded in c around 0 80.3%
associate-/l*86.1%
Simplified86.1%
clear-num86.2%
associate-/r/86.1%
clear-num86.1%
Applied egg-rr86.1%
Final simplification86.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* (/ -1.0 d) (- (/ (- a) (/ d c)) b))))
(if (<= d -1.56e+121)
t_0
(if (<= d -2.55e-159)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 7.2e-15) (+ (/ a c) (/ b (* c (/ c d)))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (-1.0 / d) * ((-a / (d / c)) - b);
double tmp;
if (d <= -1.56e+121) {
tmp = t_0;
} else if (d <= -2.55e-159) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 7.2e-15) {
tmp = (a / c) + (b / (c * (c / 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 = ((-1.0d0) / d) * ((-a / (d / c)) - b)
if (d <= (-1.56d+121)) then
tmp = t_0
else if (d <= (-2.55d-159)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (d <= 7.2d-15) then
tmp = (a / c) + (b / (c * (c / 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 = (-1.0 / d) * ((-a / (d / c)) - b);
double tmp;
if (d <= -1.56e+121) {
tmp = t_0;
} else if (d <= -2.55e-159) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 7.2e-15) {
tmp = (a / c) + (b / (c * (c / d)));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (-1.0 / d) * ((-a / (d / c)) - b) tmp = 0 if d <= -1.56e+121: tmp = t_0 elif d <= -2.55e-159: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif d <= 7.2e-15: tmp = (a / c) + (b / (c * (c / d))) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-a) / Float64(d / c)) - b)) tmp = 0.0 if (d <= -1.56e+121) tmp = t_0; elseif (d <= -2.55e-159) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 7.2e-15) tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (-1.0 / d) * ((-a / (d / c)) - b); tmp = 0.0; if (d <= -1.56e+121) tmp = t_0; elseif (d <= -2.55e-159) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (d <= 7.2e-15) tmp = (a / c) + (b / (c * (c / d))); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(-1.0 / d), $MachinePrecision] * N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.56e+121], t$95$0, If[LessEqual[d, -2.55e-159], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.2e-15], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\
\mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -2.55 \cdot 10^{-159}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{-15}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -1.5599999999999999e121 or 7.2000000000000002e-15 < d Initial program 48.7%
*-un-lft-identity48.7%
add-sqr-sqrt48.7%
times-frac48.7%
hypot-def48.7%
fma-def48.7%
hypot-def64.1%
Applied egg-rr64.1%
Taylor expanded in d around -inf 50.1%
neg-mul-150.1%
+-commutative50.1%
unsub-neg50.1%
mul-1-neg50.1%
associate-/l*51.8%
distribute-neg-frac51.8%
Simplified51.8%
Taylor expanded in d around -inf 85.0%
if -1.5599999999999999e121 < d < -2.5499999999999997e-159Initial program 83.0%
if -2.5499999999999997e-159 < d < 7.2000000000000002e-15Initial program 70.4%
Taylor expanded in c around inf 82.0%
associate-/l*79.9%
Simplified79.9%
pow279.9%
*-un-lft-identity79.9%
times-frac87.1%
Applied egg-rr87.1%
Final simplification85.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.4e+23) (not (<= c 8.8e+24))) (/ a c) (* (/ -1.0 d) (- (/ (- a) (/ d c)) b))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.4e+23) || !(c <= 8.8e+24)) {
tmp = a / c;
} else {
tmp = (-1.0 / d) * ((-a / (d / c)) - b);
}
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 <= (-1.4d+23)) .or. (.not. (c <= 8.8d+24))) then
tmp = a / c
else
tmp = ((-1.0d0) / d) * ((-a / (d / c)) - b)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.4e+23) || !(c <= 8.8e+24)) {
tmp = a / c;
} else {
tmp = (-1.0 / d) * ((-a / (d / c)) - b);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.4e+23) or not (c <= 8.8e+24): tmp = a / c else: tmp = (-1.0 / d) * ((-a / (d / c)) - b) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.4e+23) || !(c <= 8.8e+24)) tmp = Float64(a / c); else tmp = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-a) / Float64(d / c)) - b)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.4e+23) || ~((c <= 8.8e+24))) tmp = a / c; else tmp = (-1.0 / d) * ((-a / (d / c)) - b); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.4e+23], N[Not[LessEqual[c, 8.8e+24]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(-1.0 / d), $MachinePrecision] * N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{+23} \lor \neg \left(c \leq 8.8 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\
\end{array}
\end{array}
if c < -1.4e23 or 8.80000000000000007e24 < c Initial program 45.4%
Taylor expanded in c around inf 69.6%
if -1.4e23 < c < 8.80000000000000007e24Initial program 77.2%
*-un-lft-identity77.2%
add-sqr-sqrt77.2%
times-frac77.2%
hypot-def77.2%
fma-def77.2%
hypot-def85.2%
Applied egg-rr85.2%
Taylor expanded in d around -inf 56.8%
neg-mul-156.8%
+-commutative56.8%
unsub-neg56.8%
mul-1-neg56.8%
associate-/l*57.4%
distribute-neg-frac57.4%
Simplified57.4%
Taylor expanded in d around -inf 84.4%
Final simplification78.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.95e-61) (not (<= d 1.95e-13))) (* (/ -1.0 d) (- (/ (- a) (/ d c)) b)) (+ (/ a c) (/ b (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.95e-61) || !(d <= 1.95e-13)) {
tmp = (-1.0 / d) * ((-a / (d / c)) - b);
} else {
tmp = (a / c) + (b / (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 ((d <= (-1.95d-61)) .or. (.not. (d <= 1.95d-13))) then
tmp = ((-1.0d0) / d) * ((-a / (d / c)) - b)
else
tmp = (a / c) + (b / (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.95e-61) || !(d <= 1.95e-13)) {
tmp = (-1.0 / d) * ((-a / (d / c)) - b);
} else {
tmp = (a / c) + (b / (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.95e-61) or not (d <= 1.95e-13): tmp = (-1.0 / d) * ((-a / (d / c)) - b) else: tmp = (a / c) + (b / (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.95e-61) || !(d <= 1.95e-13)) tmp = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-a) / Float64(d / c)) - b)); else tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.95e-61) || ~((d <= 1.95e-13))) tmp = (-1.0 / d) * ((-a / (d / c)) - b); else tmp = (a / c) + (b / (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.95e-61], N[Not[LessEqual[d, 1.95e-13]], $MachinePrecision]], N[(N[(-1.0 / d), $MachinePrecision] * N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{-61} \lor \neg \left(d \leq 1.95 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
if d < -1.95000000000000016e-61 or 1.95000000000000002e-13 < d Initial program 57.9%
*-un-lft-identity57.9%
add-sqr-sqrt57.9%
times-frac57.9%
hypot-def57.9%
fma-def57.9%
hypot-def70.9%
Applied egg-rr70.9%
Taylor expanded in d around -inf 52.6%
neg-mul-152.6%
+-commutative52.6%
unsub-neg52.6%
mul-1-neg52.6%
associate-/l*53.8%
distribute-neg-frac53.8%
Simplified53.8%
Taylor expanded in d around -inf 77.6%
if -1.95000000000000016e-61 < d < 1.95000000000000002e-13Initial program 72.9%
Taylor expanded in c around inf 82.0%
associate-/l*79.2%
Simplified79.2%
pow279.2%
*-un-lft-identity79.2%
times-frac85.2%
Applied egg-rr85.2%
Final simplification80.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -9.8e+22) (not (<= c 2.05e+24))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9.8e+22) || !(c <= 2.05e+24)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-9.8d+22)) .or. (.not. (c <= 2.05d+24))) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9.8e+22) || !(c <= 2.05e+24)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -9.8e+22) or not (c <= 2.05e+24): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -9.8e+22) || !(c <= 2.05e+24)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -9.8e+22) || ~((c <= 2.05e+24))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -9.8e+22], N[Not[LessEqual[c, 2.05e+24]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.8 \cdot 10^{+22} \lor \neg \left(c \leq 2.05 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -9.79999999999999958e22 or 2.05e24 < c Initial program 45.4%
Taylor expanded in c around inf 69.6%
if -9.79999999999999958e22 < c < 2.05e24Initial program 77.2%
Taylor expanded in c around 0 70.1%
Final simplification69.9%
(FPCore (a b c d) :precision binary64 (if (<= d 5e+173) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 5e+173) {
tmp = a / 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 (d <= 5d+173) then
tmp = a / 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 (d <= 5e+173) {
tmp = a / c;
} else {
tmp = a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 5e+173: tmp = a / c else: tmp = a / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 5e+173) tmp = Float64(a / c); else tmp = Float64(a / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 5e+173) tmp = a / c; else tmp = a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 5e+173], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 5 \cdot 10^{+173}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\end{array}
if d < 5.00000000000000034e173Initial program 66.6%
Taylor expanded in c around inf 43.2%
if 5.00000000000000034e173 < d Initial program 48.6%
*-un-lft-identity48.6%
add-sqr-sqrt48.6%
times-frac48.6%
hypot-def48.6%
fma-def48.6%
hypot-def62.9%
Applied egg-rr62.9%
Taylor expanded in d around -inf 49.2%
neg-mul-149.2%
+-commutative49.2%
unsub-neg49.2%
mul-1-neg49.2%
associate-/l*49.2%
distribute-neg-frac49.2%
Simplified49.2%
Taylor expanded in c around -inf 20.9%
Final simplification39.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 63.7%
Taylor expanded in c around inf 37.5%
Final simplification37.5%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2023315
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))