Average Error: 31.8 → 17.4
Time: 4.9s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.698394078287103056044252507484802867004 \cdot 10^{99}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.054943086021295889484086504553352873726 \cdot 10^{-251}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.165121834293701439390935746675830973093 \cdot 10^{-265}:\\ \;\;\;\;{y}^{\left(\sqrt[3]{\frac{1}{2}} \cdot {2}^{\frac{1}{3}}\right)}\\ \mathbf{elif}\;x \le 5.899170308214914221605341579553929540714 \cdot 10^{90}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -1.698394078287103056044252507484802867004 \cdot 10^{99}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le -1.054943086021295889484086504553352873726 \cdot 10^{-251}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{elif}\;x \le 1.165121834293701439390935746675830973093 \cdot 10^{-265}:\\
\;\;\;\;{y}^{\left(\sqrt[3]{\frac{1}{2}} \cdot {2}^{\frac{1}{3}}\right)}\\

\mathbf{elif}\;x \le 5.899170308214914221605341579553929540714 \cdot 10^{90}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y) {
        double r564000 = x;
        double r564001 = r564000 * r564000;
        double r564002 = y;
        double r564003 = r564002 * r564002;
        double r564004 = r564001 + r564003;
        double r564005 = sqrt(r564004);
        return r564005;
}

double f(double x, double y) {
        double r564006 = x;
        double r564007 = -1.698394078287103e+99;
        bool r564008 = r564006 <= r564007;
        double r564009 = -1.0;
        double r564010 = r564009 * r564006;
        double r564011 = -1.0549430860212959e-251;
        bool r564012 = r564006 <= r564011;
        double r564013 = r564006 * r564006;
        double r564014 = y;
        double r564015 = r564014 * r564014;
        double r564016 = r564013 + r564015;
        double r564017 = sqrt(r564016);
        double r564018 = 1.1651218342937014e-265;
        bool r564019 = r564006 <= r564018;
        double r564020 = 0.5;
        double r564021 = cbrt(r564020);
        double r564022 = 2.0;
        double r564023 = 0.3333333333333333;
        double r564024 = pow(r564022, r564023);
        double r564025 = r564021 * r564024;
        double r564026 = pow(r564014, r564025);
        double r564027 = 5.899170308214914e+90;
        bool r564028 = r564006 <= r564027;
        double r564029 = r564028 ? r564017 : r564006;
        double r564030 = r564019 ? r564026 : r564029;
        double r564031 = r564012 ? r564017 : r564030;
        double r564032 = r564008 ? r564010 : r564031;
        return r564032;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.8
Target17.3
Herbie17.4
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659982632437974301616192301785 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.116557621183362039388201959321597704512 \cdot 10^{93}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if x < -1.698394078287103e+99

    1. Initial program 51.6

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around -inf 10.6

      \[\leadsto \color{blue}{-1 \cdot x}\]

    if -1.698394078287103e+99 < x < -1.0549430860212959e-251 or 1.1651218342937014e-265 < x < 5.899170308214914e+90

    1. Initial program 19.9

      \[\sqrt{x \cdot x + y \cdot y}\]

    if -1.0549430860212959e-251 < x < 1.1651218342937014e-265

    1. Initial program 31.1

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-exp-log33.5

      \[\leadsto \color{blue}{e^{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt34.8

      \[\leadsto e^{\color{blue}{\left(\sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)} \cdot \sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}\right) \cdot \sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}}}\]
    6. Applied exp-prod34.8

      \[\leadsto \color{blue}{{\left(e^{\sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)} \cdot \sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}}\right)}^{\left(\sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}\right)}}\]
    7. Using strategy rm
    8. Applied pow1/234.8

      \[\leadsto {\left(e^{\sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)} \cdot \sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}}\right)}^{\left(\sqrt[3]{\log \color{blue}{\left({\left(x \cdot x + y \cdot y\right)}^{\frac{1}{2}}\right)}}\right)}\]
    9. Applied log-pow34.8

      \[\leadsto {\left(e^{\sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)} \cdot \sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}}\right)}^{\left(\sqrt[3]{\color{blue}{\frac{1}{2} \cdot \log \left(x \cdot x + y \cdot y\right)}}\right)}\]
    10. Applied cbrt-prod34.8

      \[\leadsto {\left(e^{\sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)} \cdot \sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}}\right)}^{\color{blue}{\left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{\log \left(x \cdot x + y \cdot y\right)}\right)}}\]
    11. Applied pow-unpow34.8

      \[\leadsto \color{blue}{{\left({\left(e^{\sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)} \cdot \sqrt[3]{\log \left(\sqrt{x \cdot x + y \cdot y}\right)}}\right)}^{\left(\sqrt[3]{\frac{1}{2}}\right)}\right)}^{\left(\sqrt[3]{\log \left(x \cdot x + y \cdot y\right)}\right)}}\]
    12. Taylor expanded around 0 34.7

      \[\leadsto \color{blue}{e^{{2}^{\frac{1}{3}} \cdot \left(\log y \cdot \sqrt[3]{\frac{1}{2}}\right)}}\]
    13. Simplified30.6

      \[\leadsto \color{blue}{{y}^{\left(\sqrt[3]{\frac{1}{2}} \cdot {2}^{\frac{1}{3}}\right)}}\]

    if 5.899170308214914e+90 < x

    1. Initial program 49.2

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 10.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.698394078287103056044252507484802867004 \cdot 10^{99}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.054943086021295889484086504553352873726 \cdot 10^{-251}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.165121834293701439390935746675830973093 \cdot 10^{-265}:\\ \;\;\;\;{y}^{\left(\sqrt[3]{\frac{1}{2}} \cdot {2}^{\frac{1}{3}}\right)}\\ \mathbf{elif}\;x \le 5.899170308214914221605341579553929540714 \cdot 10^{90}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 1978988140 
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"
  :precision binary64

  :herbie-target
  (if (< x -1.123695082659983e145) (- x) (if (< x 1.11655762118336204e93) (sqrt (+ (* x x) (* y y))) x))

  (sqrt (+ (* x x) (* y y))))