Average Error: 30.0 → 0.0
Time: 2.5s
Precision: binary64
Cost: 6528
\[\sqrt{2 \cdot \left(x \cdot x\right)} \]
\[\mathsf{hypot}\left(x, x\right) \]
(FPCore (x) :precision binary64 (sqrt (* 2.0 (* x x))))
(FPCore (x) :precision binary64 (hypot x x))
double code(double x) {
	return sqrt((2.0 * (x * x)));
}
double code(double x) {
	return hypot(x, x);
}
public static double code(double x) {
	return Math.sqrt((2.0 * (x * x)));
}
public static double code(double x) {
	return Math.hypot(x, x);
}
def code(x):
	return math.sqrt((2.0 * (x * x)))
def code(x):
	return math.hypot(x, x)
function code(x)
	return sqrt(Float64(2.0 * Float64(x * x)))
end
function code(x)
	return hypot(x, x)
end
function tmp = code(x)
	tmp = sqrt((2.0 * (x * x)));
end
function tmp = code(x)
	tmp = hypot(x, x);
end
code[x_] := N[Sqrt[N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := N[Sqrt[x ^ 2 + x ^ 2], $MachinePrecision]
\sqrt{2 \cdot \left(x \cdot x\right)}
\mathsf{hypot}\left(x, x\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 30.0

    \[\sqrt{2 \cdot \left(x \cdot x\right)} \]
  2. Taylor expanded in x around -inf 31.3

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

    \[\leadsto \color{blue}{\sqrt{2} \cdot \left(-x\right)} \]
    Proof
    (*.f64 (sqrt.f64 2) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (sqrt.f64 2) x))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 (sqrt.f64 2) x))): 0 points increase in error, 0 points decrease in error
  4. Applied egg-rr45.9

    \[\leadsto \color{blue}{\left(1 + \sqrt{2} \cdot x\right) - 1} \]
  5. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{hypot}\left(x, x\right)} \]
    Proof
    (hypot.f64 x x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= hypot-def_binary64 (sqrt.f64 (+.f64 (*.f64 x x) (*.f64 x x)))): 140 points increase in error, 1 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (/.f64 x (Rewrite<= metadata-eval (/.f64 2 2)))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x 2) 2))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (/.f64 (*.f64 x (Rewrite<= rem-square-sqrt_binary64 (*.f64 (sqrt.f64 2) (sqrt.f64 2)))) 2)) (*.f64 x x))): 36 points increase in error, 5 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x (sqrt.f64 2)) (sqrt.f64 2))) 2)) (*.f64 x x))): 1 points increase in error, 10 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (/.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (sqrt.f64 2) x)) (sqrt.f64 2)) 2)) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 (*.f64 (sqrt.f64 2) x) 2) (sqrt.f64 2)))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 x (sqrt.f64 2))) 2) (sqrt.f64 2))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x 2) (sqrt.f64 2))) (sqrt.f64 2))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (*.f64 (/.f64 x 2) (Rewrite<= rem-log-exp_binary64 (log.f64 (exp.f64 (sqrt.f64 2))))) (sqrt.f64 2))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (Rewrite<= log-pow_binary64 (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))) (sqrt.f64 2))) (*.f64 x x))): 132 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (Rewrite=> *-commutative_binary64 (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (/.f64 x (Rewrite<= metadata-eval (/.f64 2 2)))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x 2) 2))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (/.f64 (*.f64 x (Rewrite<= rem-square-sqrt_binary64 (*.f64 (sqrt.f64 2) (sqrt.f64 2)))) 2)))): 0 points increase in error, 44 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x (sqrt.f64 2)) (sqrt.f64 2))) 2)))): 14 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (/.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (sqrt.f64 2) x)) (sqrt.f64 2)) 2)))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 (*.f64 (sqrt.f64 2) x) 2) (sqrt.f64 2)))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (*.f64 (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 x (sqrt.f64 2))) 2) (sqrt.f64 2))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (*.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x 2) (sqrt.f64 2))) (sqrt.f64 2))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (*.f64 (*.f64 (/.f64 x 2) (Rewrite<= rem-log-exp_binary64 (log.f64 (exp.f64 (sqrt.f64 2))))) (sqrt.f64 2))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (*.f64 (Rewrite<= log-pow_binary64 (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))) (sqrt.f64 2))))): 66 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))))) (*.f64 x (Rewrite=> *-commutative_binary64 (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (Rewrite<= distribute-lft-in_binary64 (*.f64 x (+.f64 (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))) (*.f64 (sqrt.f64 2) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (*.f64 x (Rewrite<= distribute-lft-in_binary64 (*.f64 (sqrt.f64 2) (+.f64 (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2))) (log.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (*.f64 x (*.f64 (sqrt.f64 2) (Rewrite<= log-prod_binary64 (log.f64 (*.f64 (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)) (pow.f64 (exp.f64 (sqrt.f64 2)) (/.f64 x 2)))))))): 3 points increase in error, 4 points decrease in error
    (sqrt.f64 (*.f64 x (*.f64 (sqrt.f64 2) (log.f64 (Rewrite<= sqr-pow_binary64 (pow.f64 (exp.f64 (sqrt.f64 2)) x)))))): 0 points increase in error, 4 points decrease in error
    (sqrt.f64 (*.f64 x (*.f64 (sqrt.f64 2) (Rewrite=> log-pow_binary64 (*.f64 x (log.f64 (exp.f64 (sqrt.f64 2)))))))): 0 points increase in error, 132 points decrease in error
    (sqrt.f64 (*.f64 x (*.f64 (sqrt.f64 2) (*.f64 x (Rewrite=> rem-log-exp_binary64 (sqrt.f64 2)))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (*.f64 x (*.f64 (sqrt.f64 2) (Rewrite<= *-commutative_binary64 (*.f64 (sqrt.f64 2) x))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x (sqrt.f64 2)) (*.f64 (sqrt.f64 2) x)))): 0 points increase in error, 6 points decrease in error
    (sqrt.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (sqrt.f64 2) x)) (*.f64 (sqrt.f64 2) x))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> rem-sqrt-square_binary64 (fabs.f64 (*.f64 (sqrt.f64 2) x))): 0 points increase in error, 128 points decrease in error
    (fabs.f64 (Rewrite<= unpow1_binary64 (pow.f64 (*.f64 (sqrt.f64 2) x) 1))): 0 points increase in error, 0 points decrease in error
    (fabs.f64 (Rewrite=> sqr-pow_binary64 (*.f64 (pow.f64 (*.f64 (sqrt.f64 2) x) (/.f64 1 2)) (pow.f64 (*.f64 (sqrt.f64 2) x) (/.f64 1 2))))): 177 points increase in error, 11 points decrease in error
    (Rewrite=> fabs-sqr_binary64 (*.f64 (pow.f64 (*.f64 (sqrt.f64 2) x) (/.f64 1 2)) (pow.f64 (*.f64 (sqrt.f64 2) x) (/.f64 1 2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= sqr-pow_binary64 (pow.f64 (*.f64 (sqrt.f64 2) x) 1)): 11 points increase in error, 177 points decrease in error
    (Rewrite=> unpow1_binary64 (*.f64 (sqrt.f64 2) x)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-rgt-identity_binary64 (+.f64 (*.f64 (sqrt.f64 2) x) 0)): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (sqrt.f64 2) x) (Rewrite<= metadata-eval (-.f64 1 1))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (*.f64 (sqrt.f64 2) x) 1) 1)): 65 points increase in error, 59 points decrease in error
    (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 (sqrt.f64 2) x))) 1): 0 points increase in error, 0 points decrease in error
  6. Final simplification0.0

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

Alternatives

Alternative 1
Error56.8
Cost192
\[x + x \]
Alternative 2
Error62.9
Cost64
\[-2 \]

Error

Reproduce

herbie shell --seed 2022329 
(FPCore (x)
  :name "sqrt C"
  :precision binary64
  (sqrt (* 2.0 (* x x))))