?

Average Accuracy: 40.9% → 99.2%
Time: 2.5s
Precision: binary64
Cost: 6528

?

\[ \begin{array}{c}[x, y, z] = \mathsf{sort}([x, y, z])\\ \end{array} \]
\[\mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, y\right)\right), \mathsf{*.f64}\left(z, z\right)\right)\right) \]
\[\mathsf{hypot.f64}\left(z, x\right) \]
(FPCore (x y z)
 :precision binary64
 (sqrt.f64 (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z))))
(FPCore (x y z) :precision binary64 (hypot.f64 z x))
\mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, y\right)\right), \mathsf{*.f64}\left(z, z\right)\right)\right)
\mathsf{hypot.f64}\left(z, x\right)

Error?

Target

Original40.9%
Target69.5%
Herbie99.2%
\[\begin{array}{l} \mathbf{if}\;\mathsf{<.f64}\left(z, -63964793941097760000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\right):\\ \;\;\;\;\mathsf{neg.f64}\left(z\right)\\ \mathbf{elif}\;\mathsf{<.f64}\left(z, 7320293694404182000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\right):\\ \;\;\;\;\mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(z, z\right), \mathsf{*.f64}\left(x, x\right)\right), \mathsf{*.f64}\left(y, y\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Derivation?

  1. Initial program 40.9%

    \[\mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, y\right)\right), \mathsf{*.f64}\left(z, z\right)\right)\right) \]
  2. Taylor expanded in y around 0 40.5%

    \[\leadsto \color{blue}{\mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{pow.f64}\left(z, 2\right), \mathsf{pow.f64}\left(x, 2\right)\right)\right)} \]
  3. Simplified99.2%

    \[\leadsto \color{blue}{\mathsf{hypot.f64}\left(z, x\right)} \]
    Proof

    [Start]40.5

    \[ \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{pow.f64}\left(z, 2\right), \mathsf{pow.f64}\left(x, 2\right)\right)\right) \]

    unpow2 [=>]40.5

    \[ \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\color{blue}{\mathsf{*.f64}\left(z, z\right)}, \mathsf{pow.f64}\left(x, 2\right)\right)\right) \]

    unpow2 [=>]40.5

    \[ \mathsf{sqrt.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(z, z\right), \color{blue}{\mathsf{*.f64}\left(x, x\right)}\right)\right) \]

    hypot-def [=>]99.2

    \[ \color{blue}{\mathsf{hypot.f64}\left(z, x\right)} \]
  4. Final simplification99.2%

    \[\leadsto \mathsf{hypot.f64}\left(z, x\right) \]

Alternatives

Alternative 1
Accuracy81.2%
Cost260
\[\begin{array}{l} \mathbf{if}\;\mathsf{<=.f64}\left(x, -16500000000000000528482304\right):\\ \;\;\;\;\mathsf{neg.f64}\left(x\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Accuracy51.2%
Cost64
\[z \]

Error

Reproduce?

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

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

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