Average Error: 35.7 → 21.1
Time: 1.2m
Precision: 64
Internal Precision: 384
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.2462366172629023 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{if}\;x \le 1.8809713604828146 \cdot 10^{+158}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3.0}}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original35.7
Target25.5
Herbie21.1
\[\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 \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.2462366172629023e+154

    1. Initial program 59.6

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

      \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{0.3333333333333333} \cdot x\right)}\]
    3. Applied simplify0.2

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

    if -1.2462366172629023e+154 < x < 1.8809713604828146e+158

    1. Initial program 27.9

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]

    if 1.8809713604828146e+158 < x

    1. Initial program 59.5

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Using strategy rm
    3. Applied sqrt-div59.5

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3.0}}}\]
    4. Taylor expanded around inf 0.4

      \[\leadsto \frac{\color{blue}{x}}{\sqrt{3.0}}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 1.2m)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(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)))