(FPCore (x) :precision binary64 (- (sqrt (+ (pow x 2.0) 1.0)) (sqrt x)))
double code(double x) { return sqrt((pow(x, 2.0) + 1.0)) - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt(((x ** 2.0d0) + 1.0d0)) - sqrt(x) end function
public static double code(double x) { return Math.sqrt((Math.pow(x, 2.0) + 1.0)) - Math.sqrt(x); }
def code(x): return math.sqrt((math.pow(x, 2.0) + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64((x ^ 2.0) + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt(((x ^ 2.0) + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{{x}^{2} + 1} - \sqrt{x} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (sqrt (+ (pow x 2.0) 1.0)) (sqrt x)))
double code(double x) { return sqrt((pow(x, 2.0) + 1.0)) - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt(((x ** 2.0d0) + 1.0d0)) - sqrt(x) end function
public static double code(double x) { return Math.sqrt((Math.pow(x, 2.0) + 1.0)) - Math.sqrt(x); }
def code(x): return math.sqrt((math.pow(x, 2.0) + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64((x ^ 2.0) + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt(((x ^ 2.0) + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{{x}^{2} + 1} - \sqrt{x} \end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (sqrt x)))) (- (sqrt (fma x x 1.0)) (* t_0 t_0))))
double code(double x) { double t_0 = sqrt(sqrt(x)); return sqrt(fma(x, x, 1.0)) - (t_0 * t_0); }
function code(x) t_0 = sqrt(sqrt(x)) return Float64(sqrt(fma(x, x, 1.0)) - Float64(t_0 * t_0)) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Sqrt[x], $MachinePrecision]], $MachinePrecision]}, N[(N[Sqrt[N[(x * x + 1.0), $MachinePrecision]], $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\sqrt{x}}\\ \sqrt{\mathsf{fma}\left(x, x, 1\right)} - t\_0 \cdot t\_0 \end{array} \end{array}
Initial program 100.0%
lift-+.f64
N/A
lift-pow.f64
N/A
unpow2
N/A
lower-fma.f64
100.0
Applied rewrites100.0%
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
sqrt-prod
N/A
lower-*.f64
N/A
lower-sqrt.f64
N/A
lower-sqrt.f64
100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (- (sqrt (fma x x 1.0)) (sqrt x)))
double code(double x) { return sqrt(fma(x, x, 1.0)) - sqrt(x); }
function code(x) return Float64(sqrt(fma(x, x, 1.0)) - sqrt(x)) end
code[x_] := N[(N[Sqrt[N[(x * x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{\mathsf{fma}\left(x, x, 1\right)} - \sqrt{x} \end{array}
Initial program 100.0%
lift-+.f64
N/A
lift-pow.f64
N/A
unpow2
N/A
lower-fma.f64
100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (fma 0.5 (* x x) (- 1.0 (sqrt x))))
double code(double x) { return fma(0.5, (x * x), (1.0 - sqrt(x))); }
function code(x) return fma(0.5, Float64(x * x), Float64(1.0 - sqrt(x))) end
code[x_] := N[(0.5 * N[(x * x), $MachinePrecision] + N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(0.5, x \cdot x, 1 - \sqrt{x}\right) \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
associate--l+
N/A
lower-fma.f64
N/A
unpow2
N/A
lower-*.f64
N/A
lower--.f64
N/A
lower-sqrt.f64
98.7
Applied rewrites98.7%
(FPCore (x) :precision binary64 (- 1.0 (sqrt x)))
double code(double x) { return 1.0 - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = 1.0d0 - sqrt(x) end function
public static double code(double x) { return 1.0 - Math.sqrt(x); }
def code(x): return 1.0 - math.sqrt(x)
function code(x) return Float64(1.0 - sqrt(x)) end
function tmp = code(x) tmp = 1.0 - sqrt(x); end
code[x_] := N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ 1 - \sqrt{x} \end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower--.f64
N/A
lower-sqrt.f64
98.3
Applied rewrites98.3%
(FPCore (x) :precision binary64 (- (sqrt x)))
double code(double x) { return -sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = -sqrt(x) end function
public static double code(double x) { return -Math.sqrt(x); }
def code(x): return -math.sqrt(x)
function code(x) return Float64(-sqrt(x)) end
function tmp = code(x) tmp = -sqrt(x); end
code[x_] := (-N[Sqrt[x], $MachinePrecision])
\begin{array}{l} \\ -\sqrt{x} \end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower--.f64
N/A
lower-sqrt.f64
98.3
Applied rewrites98.3%
Taylor expanded in x around inf
Applied rewrites1.9%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(pow(x,2)+1) - sqrt(x)"
:precision binary64
:pre (and (<= -100.0 x) (<= x 100.0))
(- (sqrt (+ (pow x 2.0) 1.0)) (sqrt x)))