
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ 1.0 x)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((1.0 + x)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((1.0d0 + x)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((1.0 + x)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((1.0 + x)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((1.0 + x)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{1 + x} + \sqrt{x}}
\end{array}
Initial program 6.7%
flip--N/A
/-lowering-/.f64N/A
rem-square-sqrtN/A
rem-square-sqrtN/A
associate--l+N/A
metadata-evalN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
+-lowering-+.f64N/A
pow1/2N/A
pow-lowering-pow.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f649.1%
Applied egg-rr9.1%
Taylor expanded in x around 0
Simplified99.6%
unpow1/2N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
+-lowering-+.f6499.6%
Applied egg-rr99.6%
(FPCore (x) :precision binary64 (* (pow x -0.5) 0.5))
double code(double x) {
return pow(x, -0.5) * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) * 0.5d0
end function
public static double code(double x) {
return Math.pow(x, -0.5) * 0.5;
}
def code(x): return math.pow(x, -0.5) * 0.5
function code(x) return Float64((x ^ -0.5) * 0.5) end
function tmp = code(x) tmp = (x ^ -0.5) * 0.5; end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} \cdot 0.5
\end{array}
Initial program 6.7%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified98.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6497.8%
Simplified97.8%
div-invN/A
*-commutativeN/A
associate-*l*N/A
pow1/2N/A
inv-powN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow1N/A
inv-powN/A
*-commutativeN/A
*-lowering-*.f64N/A
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
metadata-eval98.2%
Applied egg-rr98.2%
(FPCore (x) :precision binary64 (/ 0.5 (sqrt x)))
double code(double x) {
return 0.5 / sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 / sqrt(x)
end function
public static double code(double x) {
return 0.5 / Math.sqrt(x);
}
def code(x): return 0.5 / math.sqrt(x)
function code(x) return Float64(0.5 / sqrt(x)) end
function tmp = code(x) tmp = 0.5 / sqrt(x); end
code[x_] := N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{\sqrt{x}}
\end{array}
Initial program 6.7%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified98.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6497.8%
Simplified97.8%
div-invN/A
*-commutativeN/A
associate-*l*N/A
pow1/2N/A
inv-powN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow1N/A
inv-powN/A
sqrt-divN/A
metadata-evalN/A
un-div-invN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6497.8%
Applied egg-rr97.8%
(FPCore (x) :precision binary64 (/ (+ x (- 1.0 x)) (+ 1.0 (* x (* x -0.125)))))
double code(double x) {
return (x + (1.0 - x)) / (1.0 + (x * (x * -0.125)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (1.0d0 - x)) / (1.0d0 + (x * (x * (-0.125d0))))
end function
public static double code(double x) {
return (x + (1.0 - x)) / (1.0 + (x * (x * -0.125)));
}
def code(x): return (x + (1.0 - x)) / (1.0 + (x * (x * -0.125)))
function code(x) return Float64(Float64(x + Float64(1.0 - x)) / Float64(1.0 + Float64(x * Float64(x * -0.125)))) end
function tmp = code(x) tmp = (x + (1.0 - x)) / (1.0 + (x * (x * -0.125))); end
code[x_] := N[(N[(x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(x * N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \left(1 - x\right)}{1 + x \cdot \left(x \cdot -0.125\right)}
\end{array}
Initial program 6.7%
flip--N/A
/-lowering-/.f64N/A
rem-square-sqrtN/A
rem-square-sqrtN/A
associate--l+N/A
metadata-evalN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
+-lowering-+.f64N/A
pow1/2N/A
pow-lowering-pow.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f649.1%
Applied egg-rr9.1%
Taylor expanded in x around 0
+-lowering-+.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f643.8%
Simplified3.8%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f643.8%
Simplified3.8%
(FPCore (x) :precision binary64 (/ (+ x (- 1.0 x)) (* x (* x -0.125))))
double code(double x) {
return (x + (1.0 - x)) / (x * (x * -0.125));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (1.0d0 - x)) / (x * (x * (-0.125d0)))
end function
public static double code(double x) {
return (x + (1.0 - x)) / (x * (x * -0.125));
}
def code(x): return (x + (1.0 - x)) / (x * (x * -0.125))
function code(x) return Float64(Float64(x + Float64(1.0 - x)) / Float64(x * Float64(x * -0.125))) end
function tmp = code(x) tmp = (x + (1.0 - x)) / (x * (x * -0.125)); end
code[x_] := N[(N[(x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \left(1 - x\right)}{x \cdot \left(x \cdot -0.125\right)}
\end{array}
Initial program 6.7%
flip--N/A
/-lowering-/.f64N/A
rem-square-sqrtN/A
rem-square-sqrtN/A
associate--l+N/A
metadata-evalN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
+-lowering-+.f64N/A
pow1/2N/A
pow-lowering-pow.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f649.1%
Applied egg-rr9.1%
Taylor expanded in x around 0
+-lowering-+.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f643.8%
Simplified3.8%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f643.7%
Simplified3.7%
(FPCore (x) :precision binary64 (/ -8.0 (* x x)))
double code(double x) {
return -8.0 / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-8.0d0) / (x * x)
end function
public static double code(double x) {
return -8.0 / (x * x);
}
def code(x): return -8.0 / (x * x)
function code(x) return Float64(-8.0 / Float64(x * x)) end
function tmp = code(x) tmp = -8.0 / (x * x); end
code[x_] := N[(-8.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-8}{x \cdot x}
\end{array}
Initial program 6.7%
flip--N/A
/-lowering-/.f64N/A
rem-square-sqrtN/A
rem-square-sqrtN/A
associate--l+N/A
metadata-evalN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
+-lowering-+.f64N/A
pow1/2N/A
pow-lowering-pow.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f649.1%
Applied egg-rr9.1%
Taylor expanded in x around 0
+-lowering-+.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f643.8%
Simplified3.8%
Taylor expanded in x around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f643.4%
Simplified3.4%
(FPCore (x) :precision binary64 (* x (* x -0.125)))
double code(double x) {
return x * (x * -0.125);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (-0.125d0))
end function
public static double code(double x) {
return x * (x * -0.125);
}
def code(x): return x * (x * -0.125)
function code(x) return Float64(x * Float64(x * -0.125)) end
function tmp = code(x) tmp = x * (x * -0.125); end
code[x_] := N[(x * N[(x * -0.125), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot -0.125\right)
\end{array}
Initial program 6.7%
Taylor expanded in x around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f641.1%
Simplified1.1%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f641.1%
Simplified1.1%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((x + 1.0)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((x + 1.0d0)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((x + 1.0)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((x + 1.0)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(x + 1.0)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((x + 1.0)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x + 1} + \sqrt{x}}
\end{array}
herbie shell --seed 2024161
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform default (/ 1 (+ (sqrt (+ x 1)) (sqrt x))))
(- (sqrt (+ x 1.0)) (sqrt x)))