Average Error: 30.6 → 0.0
Time: 2.3s
Precision: binary64
Cost: 6528
\[\sqrt{\left(2 \cdot x\right) \cdot x} \]
\[\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(Float64(2.0 * 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[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
code[x_] := N[Sqrt[x ^ 2 + x ^ 2], $MachinePrecision]
\sqrt{\left(2 \cdot x\right) \cdot x}
\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.6

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

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

    \[\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-rr46.0

    \[\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)))): 144 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))): 34 points increase in error, 11 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))): 3 points increase in error, 8 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))): 131 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)))): 4 points increase in error, 40 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)))): 12 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)))))))): 4 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, 3 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, 131 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)))): 2 points increase in error, 5 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, 126 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))))): 179 points increase in error, 15 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)): 15 points increase in error, 179 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)): 64 points increase in error, 64 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
Error55.8
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;x \cdot \left(x + x\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 2
Error56.7
Cost192
\[x + x \]
Alternative 3
Error62.9
Cost64
\[-2 \]

Error

Reproduce

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