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

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

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

    1. Initial program 51.4

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

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

      \[\leadsto -1 \cdot y\]
    4. Taylor expanded around -inf 0

      \[\leadsto \color{blue}{-1 \cdot y}\]
    5. Applied simplify 0

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

    if -1.2461039277906793e+90 < y < -3833755296400741.5

    1. Initial program 58.2

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

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

      \[\leadsto x\]
    4. Taylor expanded around 0 0

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

    if -3833755296400741.5 < y < 2.7533805383758474e+165

    1. Initial program 27.7

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

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

    if 2.7533805383758474e+165 < y

    1. Initial program 59.5

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

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

      \[\leadsto y\]
    4. Taylor expanded around inf 0

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

Runtime

Time bar (total: 22.9s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(1911028787 4173371268 2724411631 1922811693 3973967741 3489382408)'
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"

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

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