Math FPCore C Julia Wolfram TeX \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\frac{\mathsf{fma}\left(b, \frac{d}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}\right)}{\mathsf{hypot}\left(c, d\right)}
\]
(FPCore (a b c d)
:precision binary64
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))) ↓
(FPCore (a b c d)
:precision binary64
(/ (fma b (/ d (hypot c d)) (/ a (/ (hypot c d) c))) (hypot c d))) double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
↓
double code(double a, double b, double c, double d) {
return fma(b, (d / hypot(c, d)), (a / (hypot(c, d) / c))) / hypot(c, 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 code(a, b, c, d)
return Float64(fma(b, Float64(d / hypot(c, d)), Float64(a / Float64(hypot(c, d) / c))) / hypot(c, 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]
↓
code[a_, b_, c_, d_] := N[(N[(b * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
↓
\frac{\mathsf{fma}\left(b, \frac{d}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}\right)}{\mathsf{hypot}\left(c, d\right)}
Alternatives Alternative 1 Accuracy 88.5% Cost 22988
\[\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := b \cdot d + c \cdot a\\
t_2 := \frac{t_1}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_0 \cdot \left(a + \frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+262}:\\
\;\;\;\;t_0 \cdot \frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, 1, \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}\right)}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\]
Alternative 2 Accuracy 98.9% Cost 20352
\[\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{d}} + a \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\right)
\]
Alternative 3 Accuracy 87.9% Cost 16844
\[\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := t_0 \cdot \left(a + \frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)\\
t_2 := b \cdot d + c \cdot a\\
t_3 := \frac{t_2}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_3 \leq -1 \cdot 10^{-102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{elif}\;t_3 \leq 2 \cdot 10^{+262}:\\
\;\;\;\;t_0 \cdot \frac{t_2}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
Alternative 4 Accuracy 82.5% Cost 14028
\[\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{+38}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;c \leq -1.22 \cdot 10^{-67}:\\
\;\;\;\;\frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{-131}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)\\
\end{array}
\]
Alternative 5 Accuracy 79.6% Cost 7436
\[\begin{array}{l}
\mathbf{if}\;d \leq -0.65:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq 3 \cdot 10^{-132}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 3.4 \cdot 10^{+46}:\\
\;\;\;\;\frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\]
Alternative 6 Accuracy 79.4% Cost 1356
\[\begin{array}{l}
\mathbf{if}\;d \leq -0.56:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\mathbf{elif}\;d \leq 5.1 \cdot 10^{-133}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+55}:\\
\;\;\;\;\frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\end{array}
\]
Alternative 7 Accuracy 76.5% Cost 1232
\[\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -0.6:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{-78}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{+40}:\\
\;\;\;\;\frac{d}{\frac{c \cdot c + d \cdot d}{b}}\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{+45}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
Alternative 8 Accuracy 76.5% Cost 1232
\[\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -0.56:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{-78}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 8.8 \cdot 10^{+40}:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{+44}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
Alternative 9 Accuracy 71.1% Cost 969
\[\begin{array}{l}
\mathbf{if}\;d \leq -1.32 \cdot 10^{+16} \lor \neg \left(d \leq 3 \cdot 10^{+44}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\end{array}
\]
Alternative 10 Accuracy 76.7% Cost 969
\[\begin{array}{l}
\mathbf{if}\;d \leq -0.6 \lor \neg \left(d \leq 1.24 \cdot 10^{+45}\right):\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\end{array}
\]
Alternative 11 Accuracy 76.9% Cost 969
\[\begin{array}{l}
\mathbf{if}\;d \leq -0.6 \lor \neg \left(d \leq 3.9 \cdot 10^{+46}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\end{array}
\]
Alternative 12 Accuracy 63.0% Cost 844
\[\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{-64}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -5.6 \cdot 10^{-223}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq -4.8 \cdot 10^{-239}:\\
\;\;\;\;\frac{a}{d \cdot \frac{d}{c}}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{-16}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\]
Alternative 13 Accuracy 64.1% Cost 456
\[\begin{array}{l}
\mathbf{if}\;d \leq -8.6 \cdot 10^{+17}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 5 \cdot 10^{+44}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 14 Accuracy 41.6% Cost 192
\[\frac{a}{c}
\]