
(FPCore (x) :precision binary64 :pre TRUE (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (sqrt((x + (1)))) - (sqrt(x)) END code
\sqrt{x + 1} - \sqrt{x}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 :pre TRUE (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (sqrt((x + (1)))) - (sqrt(x)) END code
\sqrt{x + 1} - \sqrt{x}
(FPCore (x) :precision binary64 :pre TRUE (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
return 1.0 / (sqrt(x) + sqrt((1.0 + x)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 1.0d0 / (sqrt(x) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x): return 1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x) return Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + sqrt((1.0 + x))); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (1) / ((sqrt(x)) + (sqrt(((1) + x)))) END code
\frac{1}{\sqrt{x} + \sqrt{1 + x}}
Initial program 52.8%
Applied rewrites99.7%
(FPCore (x) :precision binary64 :pre TRUE (if (<= x 1907310.3737776245) (- (sqrt (+ x 1.0)) (sqrt x)) (* 0.5 (sqrt (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 1907310.3737776245) {
tmp = sqrt((x + 1.0)) - sqrt(x);
} else {
tmp = 0.5 * sqrt((1.0 / x));
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1907310.3737776245d0) then
tmp = sqrt((x + 1.0d0)) - sqrt(x)
else
tmp = 0.5d0 * sqrt((1.0d0 / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1907310.3737776245) {
tmp = Math.sqrt((x + 1.0)) - Math.sqrt(x);
} else {
tmp = 0.5 * Math.sqrt((1.0 / x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1907310.3737776245: tmp = math.sqrt((x + 1.0)) - math.sqrt(x) else: tmp = 0.5 * math.sqrt((1.0 / x)) return tmp
function code(x) tmp = 0.0 if (x <= 1907310.3737776245) tmp = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)); else tmp = Float64(0.5 * sqrt(Float64(1.0 / x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1907310.3737776245) tmp = sqrt((x + 1.0)) - sqrt(x); else tmp = 0.5 * sqrt((1.0 / x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1907310.3737776245], N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (x <= (190731037377762445248663425445556640625e-32)) THEN ((sqrt((x + (1)))) - (sqrt(x))) ELSE ((5e-1) * (sqrt(((1) / x)))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq 1907310.3737776245:\\
\;\;\;\;\sqrt{x + 1} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\
\end{array}
if x < 1907310.3737776245Initial program 52.8%
if 1907310.3737776245 < x Initial program 52.8%
Taylor expanded in x around inf
Applied rewrites52.8%
Applied rewrites52.9%
Taylor expanded in x around inf
Applied rewrites53.0%
(FPCore (x) :precision binary64 :pre TRUE (if (<= x 0.19634788085319213) (- 1.0 (sqrt x)) (* 0.5 (sqrt (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 0.19634788085319213) {
tmp = 1.0 - sqrt(x);
} else {
tmp = 0.5 * sqrt((1.0 / x));
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.19634788085319213d0) then
tmp = 1.0d0 - sqrt(x)
else
tmp = 0.5d0 * sqrt((1.0d0 / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.19634788085319213) {
tmp = 1.0 - Math.sqrt(x);
} else {
tmp = 0.5 * Math.sqrt((1.0 / x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.19634788085319213: tmp = 1.0 - math.sqrt(x) else: tmp = 0.5 * math.sqrt((1.0 / x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.19634788085319213) tmp = Float64(1.0 - sqrt(x)); else tmp = Float64(0.5 * sqrt(Float64(1.0 / x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.19634788085319213) tmp = 1.0 - sqrt(x); else tmp = 0.5 * sqrt((1.0 / x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.19634788085319213], N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (x <= (1963478808531921304680878392900922335684299468994140625e-55)) THEN ((1) - (sqrt(x))) ELSE ((5e-1) * (sqrt(((1) / x)))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq 0.19634788085319213:\\
\;\;\;\;1 - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\
\end{array}
if x < 0.19634788085319213Initial program 52.8%
Taylor expanded in x around 0
Applied rewrites49.0%
if 0.19634788085319213 < x Initial program 52.8%
Taylor expanded in x around inf
Applied rewrites52.8%
Applied rewrites52.9%
Taylor expanded in x around inf
Applied rewrites53.0%
(FPCore (x) :precision binary64 :pre TRUE (if (<= x 0.19634788085319213) (- 1.0 (sqrt x)) (/ 0.5 (sqrt x))))
double code(double x) {
double tmp;
if (x <= 0.19634788085319213) {
tmp = 1.0 - sqrt(x);
} else {
tmp = 0.5 / sqrt(x);
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.19634788085319213d0) then
tmp = 1.0d0 - sqrt(x)
else
tmp = 0.5d0 / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.19634788085319213) {
tmp = 1.0 - Math.sqrt(x);
} else {
tmp = 0.5 / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.19634788085319213: tmp = 1.0 - math.sqrt(x) else: tmp = 0.5 / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.19634788085319213) tmp = Float64(1.0 - sqrt(x)); else tmp = Float64(0.5 / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.19634788085319213) tmp = 1.0 - sqrt(x); else tmp = 0.5 / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.19634788085319213], N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF (x <= (1963478808531921304680878392900922335684299468994140625e-55)) THEN ((1) - (sqrt(x))) ELSE ((5e-1) / (sqrt(x))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq 0.19634788085319213:\\
\;\;\;\;1 - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\sqrt{x}}\\
\end{array}
if x < 0.19634788085319213Initial program 52.8%
Taylor expanded in x around 0
Applied rewrites49.0%
if 0.19634788085319213 < x Initial program 52.8%
Taylor expanded in x around inf
Applied rewrites52.8%
Applied rewrites52.9%
(FPCore (x) :precision binary64 :pre TRUE (- 1.0 (sqrt 0.0)))
double code(double x) {
return 1.0 - sqrt(0.0);
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 1.0d0 - sqrt(0.0d0)
end function
public static double code(double x) {
return 1.0 - Math.sqrt(0.0);
}
def code(x): return 1.0 - math.sqrt(0.0)
function code(x) return Float64(1.0 - sqrt(0.0)) end
function tmp = code(x) tmp = 1.0 - sqrt(0.0); end
code[x_] := N[(1.0 - N[Sqrt[0.0], $MachinePrecision]), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (1) - (sqrt((0))) END code
1 - \sqrt{0}
Initial program 52.8%
Taylor expanded in x around 0
Applied rewrites49.0%
Taylor expanded in undef-var around zero
Applied rewrites50.6%
(FPCore (x) :precision binary64 :pre TRUE (- 1.0 (sqrt x)))
double code(double x) {
return 1.0 - sqrt(x);
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (1) - (sqrt(x)) END code
1 - \sqrt{x}
Initial program 52.8%
Taylor expanded in x around 0
Applied rewrites49.0%
herbie shell --seed 2026092
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
(- (sqrt (+ x 1.0)) (sqrt x)))