Average Error: 16.2 → 14.1
Time: 11.2s
Precision: 64
\[\frac{c \cdot x + s \cdot y}{c + s}\]
\[\begin{array}{l} \mathbf{if}\;s \le -1.465428036835230337989988127524781201181 \cdot 10^{148}:\\ \;\;\;\;y\\ \mathbf{elif}\;s \le 9.05890113028923428299625745061644697218 \cdot 10^{-220}:\\ \;\;\;\;\frac{1}{\frac{c + s}{s \cdot y + x \cdot c}}\\ \mathbf{elif}\;s \le 8.138797109643353804083329461472826821839 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;s \le 1.426054384654359001246620979339779186506 \cdot 10^{137}:\\ \;\;\;\;\frac{1}{\frac{c + s}{s \cdot y + x \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]
\frac{c \cdot x + s \cdot y}{c + s}
\begin{array}{l}
\mathbf{if}\;s \le -1.465428036835230337989988127524781201181 \cdot 10^{148}:\\
\;\;\;\;y\\

\mathbf{elif}\;s \le 9.05890113028923428299625745061644697218 \cdot 10^{-220}:\\
\;\;\;\;\frac{1}{\frac{c + s}{s \cdot y + x \cdot c}}\\

\mathbf{elif}\;s \le 8.138797109643353804083329461472826821839 \cdot 10^{-147}:\\
\;\;\;\;x\\

\mathbf{elif}\;s \le 1.426054384654359001246620979339779186506 \cdot 10^{137}:\\
\;\;\;\;\frac{1}{\frac{c + s}{s \cdot y + x \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;y\\

\end{array}
double f(double c, double x, double s, double y) {
        double r2654888 = c;
        double r2654889 = x;
        double r2654890 = r2654888 * r2654889;
        double r2654891 = s;
        double r2654892 = y;
        double r2654893 = r2654891 * r2654892;
        double r2654894 = r2654890 + r2654893;
        double r2654895 = r2654888 + r2654891;
        double r2654896 = r2654894 / r2654895;
        return r2654896;
}

double f(double c, double x, double s, double y) {
        double r2654897 = s;
        double r2654898 = -1.4654280368352303e+148;
        bool r2654899 = r2654897 <= r2654898;
        double r2654900 = y;
        double r2654901 = 9.058901130289234e-220;
        bool r2654902 = r2654897 <= r2654901;
        double r2654903 = 1.0;
        double r2654904 = c;
        double r2654905 = r2654904 + r2654897;
        double r2654906 = r2654897 * r2654900;
        double r2654907 = x;
        double r2654908 = r2654907 * r2654904;
        double r2654909 = r2654906 + r2654908;
        double r2654910 = r2654905 / r2654909;
        double r2654911 = r2654903 / r2654910;
        double r2654912 = 8.138797109643354e-147;
        bool r2654913 = r2654897 <= r2654912;
        double r2654914 = 1.426054384654359e+137;
        bool r2654915 = r2654897 <= r2654914;
        double r2654916 = r2654915 ? r2654911 : r2654900;
        double r2654917 = r2654913 ? r2654907 : r2654916;
        double r2654918 = r2654902 ? r2654911 : r2654917;
        double r2654919 = r2654899 ? r2654900 : r2654918;
        return r2654919;
}

Error

Bits error versus c

Bits error versus x

Bits error versus s

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if s < -1.4654280368352303e+148 or 1.426054384654359e+137 < s

    1. Initial program 29.9

      \[\frac{c \cdot x + s \cdot y}{c + s}\]
    2. Taylor expanded around 0 18.7

      \[\leadsto \color{blue}{y}\]

    if -1.4654280368352303e+148 < s < 9.058901130289234e-220 or 8.138797109643354e-147 < s < 1.426054384654359e+137

    1. Initial program 11.2

      \[\frac{c \cdot x + s \cdot y}{c + s}\]
    2. Using strategy rm
    3. Applied clear-num11.3

      \[\leadsto \color{blue}{\frac{1}{\frac{c + s}{c \cdot x + s \cdot y}}}\]
    4. Simplified11.3

      \[\leadsto \frac{1}{\color{blue}{\frac{c + s}{s \cdot y + x \cdot c}}}\]

    if 9.058901130289234e-220 < s < 8.138797109643354e-147

    1. Initial program 10.1

      \[\frac{c \cdot x + s \cdot y}{c + s}\]
    2. Taylor expanded around inf 24.3

      \[\leadsto \color{blue}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \le -1.465428036835230337989988127524781201181 \cdot 10^{148}:\\ \;\;\;\;y\\ \mathbf{elif}\;s \le 9.05890113028923428299625745061644697218 \cdot 10^{-220}:\\ \;\;\;\;\frac{1}{\frac{c + s}{s \cdot y + x \cdot c}}\\ \mathbf{elif}\;s \le 8.138797109643353804083329461472826821839 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;s \le 1.426054384654359001246620979339779186506 \cdot 10^{137}:\\ \;\;\;\;\frac{1}{\frac{c + s}{s \cdot y + x \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (c x s y)
  :name "(c*x + s*y) / (c + s)"
  :precision binary64
  (/ (+ (* c x) (* s y)) (+ c s)))