Average Error: 37.4 → 18.3
Time: 27.0s
Precision: 64
Internal precision: 128
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.2461039277906793 \cdot 10^{+90}:\\ \;\;\;\;\left(-y\right) \cdot \sqrt{0.3333333333333333}\\ \mathbf{if}\;y \le -3833755296400741.5:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \mathbf{if}\;y \le 2.7533805383758474 \cdot 10^{+165}:\\ \;\;\;\;\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)} \cdot \sqrt{\frac{1}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original37.4
Comparison29.2
Herbie18.3
\[ \begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3.0}}\\ \mathbf{if}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left({z}^2 + {x}^2\right) + {y}^2}}{\sqrt{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array} \]

Derivation

  1. Split input into 4 regimes.
  2. if y < -1.2461039277906793e+90

    1. Initial program 51.5

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Applied simplify 51.5

      \[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
    3. Applied taylor 0.2

      \[\leadsto -1 \cdot \left(\sqrt{0.3333333333333333} \cdot y\right)\]
    4. Taylor expanded around -inf 0.2

      \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{0.3333333333333333} \cdot y\right)}\]
    5. Applied simplify 0.2

      \[\leadsto \color{blue}{\left(-y\right) \cdot \sqrt{0.3333333333333333}}\]

    if -1.2461039277906793e+90 < y < -3833755296400741.5

    1. Initial program 58.2

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Applied simplify 58.2

      \[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
    3. Applied taylor 0.2

      \[\leadsto \sqrt{0.3333333333333333} \cdot x\]
    4. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot x}\]

    if -3833755296400741.5 < y < 2.7533805383758474e+165

    1. Initial program 27.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Applied simplify 27.8

      \[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
    3. Using strategy rm
    4. Applied div-inv 27.8

      \[\leadsto \sqrt{\color{blue}{\left({y}^2 + \left({z}^2 + x \cdot x\right)\right) \cdot \frac{1}{3.0}}}\]
    5. Applied sqrt-prod 27.9

      \[\leadsto \color{blue}{\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)} \cdot \sqrt{\frac{1}{3.0}}}\]

    if 2.7533805383758474e+165 < y

    1. Initial program 59.6

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Applied simplify 59.6

      \[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
    3. Applied taylor 0.2

      \[\leadsto \sqrt{0.3333333333333333} \cdot y\]
    4. Taylor expanded around inf 0.2

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot y}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 27.0s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(851321798 3617685590 4011722190 1634036316 762064292 2712077172)'
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

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

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