Math FPCore C Java Python Julia MATLAB Wolfram TeX \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{d}} + \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}\right)
\]
(FPCore (a b c d)
:precision binary64
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))) ↓
(FPCore (a b c d)
:precision binary64
(* (/ 1.0 (hypot c d)) (+ (/ b (/ (hypot c d) d)) (/ a (/ (hypot c d) c))))) 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 (1.0 / hypot(c, d)) * ((b / (hypot(c, d) / d)) + (a / (hypot(c, d) / c)));
}
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
↓
public static double code(double a, double b, double c, double d) {
return (1.0 / Math.hypot(c, d)) * ((b / (Math.hypot(c, d) / d)) + (a / (Math.hypot(c, d) / c)));
}
def code(a, b, c, d):
return ((a * c) + (b * d)) / ((c * c) + (d * d))
↓
def code(a, b, c, d):
return (1.0 / math.hypot(c, d)) * ((b / (math.hypot(c, d) / d)) + (a / (math.hypot(c, d) / c)))
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(Float64(1.0 / hypot(c, d)) * Float64(Float64(b / Float64(hypot(c, d) / d)) + Float64(a / Float64(hypot(c, d) / c))))
end
function tmp = code(a, b, c, d)
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
end
↓
function tmp = code(a, b, c, d)
tmp = (1.0 / hypot(c, d)) * ((b / (hypot(c, d) / d)) + (a / (hypot(c, d) / c)));
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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] + N[(a / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
↓
\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{d}} + \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}\right)
Alternatives Alternative 1 Accuracy 81.6% Cost 21088
\[\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{a \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
t_2 := \frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -7.5 \cdot 10^{+135}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq -1.5 \cdot 10^{+18}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -5 \cdot 10^{-204}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.06 \cdot 10^{-110}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{elif}\;d \leq 4.6 \cdot 10^{-24}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 980000000000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq 1.05 \cdot 10^{+124}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\]
Alternative 2 Accuracy 99.1% Cost 20352
\[\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} + b \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)
\]
Alternative 3 Accuracy 82.8% Cost 14028
\[\begin{array}{l}
\mathbf{if}\;c \leq -8.6 \cdot 10^{+89}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;c \leq -1.25 \cdot 10^{-159}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 7 \cdot 10^{-87}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + b \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)\\
\end{array}
\]
Alternative 4 Accuracy 82.6% Cost 14028
\[\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{+80}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;c \leq -9.2 \cdot 10^{-160}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 1.15 \cdot 10^{-81}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{d}} + a\right)\\
\end{array}
\]
Alternative 5 Accuracy 77.6% Cost 13640
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{elif}\;d \leq -1.02 \cdot 10^{+109}:\\
\;\;\;\;\frac{a \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq -1.5 \cdot 10^{+18}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -9.5 \cdot 10^{-154}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 60000000000000:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \frac{c}{\frac{d}{a}}\right)\\
\end{array}
\]
Alternative 6 Accuracy 77.2% Cost 7828
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -1.5 \cdot 10^{+18}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -5.4 \cdot 10^{-153}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 3.8 \cdot 10^{+15}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\
\end{array}
\]
Alternative 7 Accuracy 77.3% Cost 7828
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{elif}\;d \leq -4.1 \cdot 10^{+108}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -2.75 \cdot 10^{+17}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -7.5 \cdot 10^{-152}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 4300000000000:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \frac{c}{\frac{d}{a}}\right)\\
\end{array}
\]
Alternative 8 Accuracy 68.8% Cost 1497
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -3.9 \cdot 10^{+108}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -1.42 \cdot 10^{+17}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -4.3 \cdot 10^{-18} \lor \neg \left(d \leq -2.7 \cdot 10^{-52}\right) \land d \leq 440000000000:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 9 Accuracy 68.7% Cost 1497
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -1.9 \cdot 10^{+17}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.95 \cdot 10^{-17} \lor \neg \left(d \leq -3.4 \cdot 10^{-52}\right) \land d \leq 8000000000000:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 10 Accuracy 68.5% Cost 1496
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -59000000000000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -4.2 \cdot 10^{-18}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;d \leq -3 \cdot 10^{-52}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 11 Accuracy 68.5% Cost 1496
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -1.9 \cdot 10^{+17}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -6 \cdot 10^{-18}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;d \leq -2.7 \cdot 10^{-52}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.6 \cdot 10^{+15}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 12 Accuracy 74.1% Cost 1496
\[\begin{array}{l}
t_0 := \frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -3.05 \cdot 10^{+16}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -1.82 \cdot 10^{-17}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;d \leq -2.1 \cdot 10^{-54}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 2.25 \cdot 10^{+14}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
Alternative 13 Accuracy 73.6% Cost 1496
\[\begin{array}{l}
t_0 := \frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -2.9 \cdot 10^{+16}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -1.05 \cdot 10^{-17}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;d \leq -4.2 \cdot 10^{-85}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{c}{d \cdot d}\\
\mathbf{elif}\;d \leq 500000000000:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
Alternative 14 Accuracy 73.6% Cost 1496
\[\begin{array}{l}
t_0 := \frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -17000000000000:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -6.7 \cdot 10^{-18}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{elif}\;d \leq -4.1 \cdot 10^{-85}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{c}{d \cdot d}\\
\mathbf{elif}\;d \leq 3.55 \cdot 10^{+15}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
Alternative 15 Accuracy 77.1% Cost 1488
\[\begin{array}{l}
t_0 := \frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -1.2 \cdot 10^{+109}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq -1.5 \cdot 10^{+18}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -5.4 \cdot 10^{-154}:\\
\;\;\;\;\frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{+14}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
Alternative 16 Accuracy 62.8% Cost 986
\[\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+135}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -7.2 \cdot 10^{+108} \lor \neg \left(d \leq -1.46 \cdot 10^{+15}\right) \land \left(d \leq -9 \cdot 10^{-18} \lor \neg \left(d \leq -9 \cdot 10^{-56}\right) \land d \leq 1.75 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 17 Accuracy 41.2% Cost 324
\[\begin{array}{l}
\mathbf{if}\;d \leq 2 \cdot 10^{+201}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{d}\\
\end{array}
\]
Alternative 18 Accuracy 40.5% Cost 192
\[\frac{a}{c}
\]