Average Error: 38.2 → 25.9
Time: 15.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 3.408719160070714088752655754041470680881 \cdot 10^{143}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\
\;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\mathbf{elif}\;x \le 3.408719160070714088752655754041470680881 \cdot 10^{143}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\end{array}
double f(double x, double y, double z) {
        double r54233992 = x;
        double r54233993 = r54233992 * r54233992;
        double r54233994 = y;
        double r54233995 = r54233994 * r54233994;
        double r54233996 = r54233993 + r54233995;
        double r54233997 = z;
        double r54233998 = r54233997 * r54233997;
        double r54233999 = r54233996 + r54233998;
        double r54234000 = 3.0;
        double r54234001 = r54233999 / r54234000;
        double r54234002 = sqrt(r54234001);
        return r54234002;
}

double f(double x, double y, double z) {
        double r54234003 = x;
        double r54234004 = -2.1993493867760175e+110;
        bool r54234005 = r54234003 <= r54234004;
        double r54234006 = 0.3333333333333333;
        double r54234007 = sqrt(r54234006);
        double r54234008 = r54234003 * r54234007;
        double r54234009 = -r54234008;
        double r54234010 = 3.408719160070714e+143;
        bool r54234011 = r54234003 <= r54234010;
        double r54234012 = r54234003 * r54234003;
        double r54234013 = y;
        double r54234014 = r54234013 * r54234013;
        double r54234015 = r54234012 + r54234014;
        double r54234016 = z;
        double r54234017 = r54234016 * r54234016;
        double r54234018 = r54234015 + r54234017;
        double r54234019 = r54234006 * r54234018;
        double r54234020 = sqrt(r54234019);
        double r54234021 = r54234011 ? r54234020 : r54234008;
        double r54234022 = r54234005 ? r54234009 : r54234021;
        return r54234022;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.2
Target25.9
Herbie25.9
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -2.1993493867760175e+110

    1. Initial program 56.6

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Taylor expanded around -inf 19.4

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    3. Simplified19.4

      \[\leadsto \color{blue}{-x \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]

    if -2.1993493867760175e+110 < x < 3.408719160070714e+143

    1. Initial program 29.5

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Taylor expanded around 0 29.6

      \[\leadsto \sqrt{\color{blue}{0.3333333333333333148296162562473909929395 \cdot {y}^{2} + \left(0.3333333333333333148296162562473909929395 \cdot {x}^{2} + 0.3333333333333333148296162562473909929395 \cdot {z}^{2}\right)}}\]
    3. Simplified29.6

      \[\leadsto \sqrt{\color{blue}{0.3333333333333333148296162562473909929395 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}}\]

    if 3.408719160070714e+143 < x

    1. Initial program 61.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Taylor expanded around inf 14.4

      \[\leadsto \color{blue}{x \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 3.408719160070714088752655754041470680881 \cdot 10^{143}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))