Average Error: 37.9 → 26.3
Time: 3.3s
Precision: binary64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.4611892877848995 \cdot 10^{149}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -4.6541970574734218 \cdot 10^{-38}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -1.4720033509998629 \cdot 10^{-54}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le -2.17193274660449406 \cdot 10^{-286}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 2.09211786826040624 \cdot 10^{-275}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 3.19659555588810615 \cdot 10^{148}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original37.9
Target25.7
Herbie26.3
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if x < -8.4611892877848995e149

    1. Initial program 63.4

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified14.5

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

    if -8.4611892877848995e149 < x < -4.6541970574734218e-38 or -1.4720033509998629e-54 < x < -2.17193274660449406e-286 or 2.09211786826040624e-275 < x < 3.19659555588810615e148

    1. Initial program 29.1

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

    if -4.6541970574734218e-38 < x < -1.4720033509998629e-54 or -2.17193274660449406e-286 < x < 2.09211786826040624e-275

    1. Initial program 29.1

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

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

    if 3.19659555588810615e148 < x

    1. Initial program 62.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.4611892877848995 \cdot 10^{149}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -4.6541970574734218 \cdot 10^{-38}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -1.4720033509998629 \cdot 10^{-54}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le -2.17193274660449406 \cdot 10^{-286}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 2.09211786826040624 \cdot 10^{-275}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 3.19659555588810615 \cdot 10^{148}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2020184 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

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

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