Average Error: 30.1 → 15.7
Time: 9.6s
Precision: 64
Internal Precision: 320
\[\sqrt{{x}^{2} + {y}^{2}}\]
\[\begin{array}{l} \mathbf{if}\;\sqrt{{x}^{2} + {y}^{2}} \le 3.187023177785276 \cdot 10^{-162}:\\ \;\;\;\;\left|x\right|\\ \mathbf{if}\;\sqrt{{x}^{2} + {y}^{2}} \le 1.4999337484132257 \cdot 10^{+149}:\\ \;\;\;\;\sqrt{{x}^{2} + {y}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\left|x\right|\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (sqrt (+ (pow x 2) (pow y 2))) < 3.187023177785276e-162 or 1.4999337484132257e+149 < (sqrt (+ (pow x 2) (pow y 2)))

    1. Initial program 58.1

      \[\sqrt{{x}^{2} + {y}^{2}}\]
    2. Taylor expanded around -inf 59.9

      \[\leadsto \sqrt{\color{blue}{e^{2 \cdot \left(\log -1 - \log \left(\frac{-1}{x}\right)\right)}}}\]
    3. Applied simplify30.3

      \[\leadsto \color{blue}{\left|x\right|}\]

    if 3.187023177785276e-162 < (sqrt (+ (pow x 2) (pow y 2))) < 1.4999337484132257e+149

    1. Initial program 0.2

      \[\sqrt{{x}^{2} + {y}^{2}}\]
  3. Recombined 2 regimes into one program.

Runtime

Time bar (total: 9.6s)Debug log

herbie shell --seed '#(2775764126 3555076145 3898259844 1891440260 2599947619 1948460636)' 
(FPCore (x y)
  :name "sqrt(x^2 + y^2)"
  (sqrt (+ (pow x 2) (pow y 2))))