
(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 11 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 x) (hypot 1.0 (sqrt x)))))
double code(double x) {
return 1.0 / (sqrt(x) + hypot(1.0, sqrt(x)));
}
public static double code(double x) {
return 1.0 / (Math.sqrt(x) + Math.hypot(1.0, Math.sqrt(x)));
}
def code(x): return 1.0 / (math.sqrt(x) + math.hypot(1.0, math.sqrt(x)))
function code(x) return Float64(1.0 / Float64(sqrt(x) + hypot(1.0, sqrt(x)))) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + hypot(1.0, sqrt(x))); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[1.0 ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x} + \mathsf{hypot}\left(1, \sqrt{x}\right)}
\end{array}
Initial program 50.0%
flip--50.3%
div-inv50.3%
add-sqr-sqrt50.6%
add-sqr-sqrt51.1%
associate--l+51.1%
reciprocal-define47.3%
Applied egg-rr47.3%
reciprocal-undefine51.1%
associate-*r/51.1%
*-rgt-identity51.1%
+-commutative51.1%
associate-+l-99.7%
+-inverses99.7%
metadata-eval99.7%
reciprocal-undefine65.6%
+-commutative65.6%
Simplified65.6%
reciprocal-undefine99.7%
+-commutative99.7%
Applied egg-rr99.7%
add-sqr-sqrt99.7%
hypot-1-def99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 4e-6) (* 0.5 (pow x -0.5)) t_0)))
double code(double x) {
double t_0 = sqrt((1.0 + x)) - sqrt(x);
double tmp;
if (t_0 <= 4e-6) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x)) - sqrt(x)
if (t_0 <= 4d-6) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
double tmp;
if (t_0 <= 4e-6) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) - math.sqrt(x) tmp = 0 if t_0 <= 4e-6: tmp = 0.5 * math.pow(x, -0.5) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) tmp = 0.0 if (t_0 <= 4e-6) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)) - sqrt(x); tmp = 0.0; if (t_0 <= 4e-6) tmp = 0.5 * (x ^ -0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e-6], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 4 \cdot 10^{-6}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 3.99999999999999982e-6Initial program 4.7%
flip--5.2%
div-inv5.2%
add-sqr-sqrt6.0%
add-sqr-sqrt6.7%
associate--l+6.7%
reciprocal-define5.0%
Applied egg-rr5.0%
reciprocal-undefine6.7%
associate-*r/6.7%
*-rgt-identity6.7%
+-commutative6.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+63.8%
associate-/r/63.8%
reciprocal-define26.6%
+-commutative26.6%
sqrt-pow226.6%
metadata-eval26.6%
pow1/226.6%
+-commutative26.6%
pow-pow26.6%
metadata-eval26.6%
Applied egg-rr19.2%
reciprocal-undefine47.8%
associate-*l/47.8%
*-lft-identity47.8%
associate-+l+47.8%
associate--l+47.8%
count-247.8%
fma-udef47.8%
rem-square-sqrt47.8%
hypot-def64.1%
Simplified64.1%
Taylor expanded in x around inf 63.8%
Taylor expanded in x around inf 99.5%
rem-exp-log92.0%
exp-neg92.0%
unpow1/292.0%
exp-prod92.0%
distribute-lft-neg-out92.0%
distribute-rgt-neg-in92.0%
metadata-eval92.0%
exp-to-pow99.7%
Simplified99.7%
if 3.99999999999999982e-6 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (/ 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)
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]
\begin{array}{l}
\\
\frac{1}{\sqrt{x} + \sqrt{1 + x}}
\end{array}
Initial program 50.0%
flip--50.3%
div-inv50.3%
add-sqr-sqrt50.6%
add-sqr-sqrt51.1%
associate--l+51.1%
reciprocal-define47.3%
Applied egg-rr47.3%
reciprocal-undefine51.1%
associate-*r/51.1%
*-rgt-identity51.1%
+-commutative51.1%
associate-+l-99.7%
+-inverses99.7%
metadata-eval99.7%
reciprocal-undefine65.6%
+-commutative65.6%
Simplified65.6%
reciprocal-undefine99.7%
+-commutative99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 1.22) (- (+ 1.0 (* x (+ 0.5 (* x -0.125)))) (sqrt x)) (* 0.5 (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 1.22) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x);
} else {
tmp = 0.5 * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.22d0) then
tmp = (1.0d0 + (x * (0.5d0 + (x * (-0.125d0))))) - sqrt(x)
else
tmp = 0.5d0 * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.22) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - Math.sqrt(x);
} else {
tmp = 0.5 * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.22: tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - math.sqrt(x) else: tmp = 0.5 * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.22) tmp = Float64(Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * -0.125)))) - sqrt(x)); else tmp = Float64(0.5 * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.22) tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x); else tmp = 0.5 * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.22], N[(N[(1.0 + N[(x * N[(0.5 + N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.22:\\
\;\;\;\;\left(1 + x \cdot \left(0.5 + x \cdot -0.125\right)\right) - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 1.21999999999999997Initial program 99.9%
Taylor expanded in x around 0 99.2%
+-commutative99.2%
unpow299.2%
associate-*r*99.2%
distribute-rgt-out99.2%
*-commutative99.2%
Simplified99.2%
if 1.21999999999999997 < x Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.8%
add-sqr-sqrt8.7%
associate--l+8.7%
reciprocal-define5.7%
Applied egg-rr5.7%
reciprocal-undefine8.7%
associate-*r/8.7%
*-rgt-identity8.7%
+-commutative8.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+64.5%
associate-/r/64.5%
reciprocal-define26.9%
+-commutative26.9%
sqrt-pow226.9%
metadata-eval26.9%
pow1/226.9%
+-commutative26.9%
pow-pow26.9%
metadata-eval26.9%
Applied egg-rr19.6%
reciprocal-undefine48.9%
associate-*l/48.9%
*-lft-identity48.9%
associate-+l+48.9%
associate--l+48.9%
count-248.9%
fma-udef48.9%
rem-square-sqrt48.9%
hypot-def64.9%
Simplified64.9%
Taylor expanded in x around inf 63.1%
Taylor expanded in x around inf 98.1%
rem-exp-log90.7%
exp-neg90.7%
unpow1/290.7%
exp-prod90.7%
distribute-lft-neg-out90.7%
distribute-rgt-neg-in90.7%
metadata-eval90.7%
exp-to-pow98.3%
Simplified98.3%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ 1.0 (- (* x 0.5) (sqrt x))) (* 0.5 (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 + ((x * 0.5) - sqrt(x));
} else {
tmp = 0.5 * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 1.0d0 + ((x * 0.5d0) - sqrt(x))
else
tmp = 0.5d0 * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 + ((x * 0.5) - Math.sqrt(x));
} else {
tmp = 0.5 * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 1.0 + ((x * 0.5) - math.sqrt(x)) else: tmp = 0.5 * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 + Float64(Float64(x * 0.5) - sqrt(x))); else tmp = Float64(0.5 * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 1.0 + ((x * 0.5) - sqrt(x)); else tmp = 0.5 * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(1.0 + N[(N[(x * 0.5), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 + \left(x \cdot 0.5 - \sqrt{x}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 1Initial program 99.9%
Taylor expanded in x around 0 98.5%
associate--l+98.5%
+-commutative98.5%
*-commutative98.5%
Applied egg-rr98.5%
if 1 < x Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.8%
add-sqr-sqrt8.7%
associate--l+8.7%
reciprocal-define5.7%
Applied egg-rr5.7%
reciprocal-undefine8.7%
associate-*r/8.7%
*-rgt-identity8.7%
+-commutative8.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+64.5%
associate-/r/64.5%
reciprocal-define26.9%
+-commutative26.9%
sqrt-pow226.9%
metadata-eval26.9%
pow1/226.9%
+-commutative26.9%
pow-pow26.9%
metadata-eval26.9%
Applied egg-rr19.6%
reciprocal-undefine48.9%
associate-*l/48.9%
*-lft-identity48.9%
associate-+l+48.9%
associate--l+48.9%
count-248.9%
fma-udef48.9%
rem-square-sqrt48.9%
hypot-def64.9%
Simplified64.9%
Taylor expanded in x around inf 63.1%
Taylor expanded in x around inf 98.1%
rem-exp-log90.7%
exp-neg90.7%
unpow1/290.7%
exp-prod90.7%
distribute-lft-neg-out90.7%
distribute-rgt-neg-in90.7%
metadata-eval90.7%
exp-to-pow98.3%
Simplified98.3%
Final simplification98.4%
(FPCore (x) :precision binary64 (if (<= x 0.38) (/ 1.0 (+ 1.0 (pow x 1.5))) (* 0.5 (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.38) {
tmp = 1.0 / (1.0 + pow(x, 1.5));
} else {
tmp = 0.5 * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.38d0) then
tmp = 1.0d0 / (1.0d0 + (x ** 1.5d0))
else
tmp = 0.5d0 * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.38) {
tmp = 1.0 / (1.0 + Math.pow(x, 1.5));
} else {
tmp = 0.5 * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.38: tmp = 1.0 / (1.0 + math.pow(x, 1.5)) else: tmp = 0.5 * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.38) tmp = Float64(1.0 / Float64(1.0 + (x ^ 1.5))); else tmp = Float64(0.5 * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.38) tmp = 1.0 / (1.0 + (x ^ 1.5)); else tmp = 0.5 * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.38], N[(1.0 / N[(1.0 + N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.38:\\
\;\;\;\;\frac{1}{1 + {x}^{1.5}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.38Initial program 99.9%
flip--99.9%
div-inv99.9%
add-sqr-sqrt99.9%
add-sqr-sqrt99.9%
associate--l+99.9%
reciprocal-define95.1%
Applied egg-rr95.1%
reciprocal-undefine99.9%
associate-*r/99.9%
*-rgt-identity99.9%
+-commutative99.9%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
reciprocal-undefine95.1%
+-commutative95.1%
Simplified95.1%
reciprocal-undefine99.9%
+-commutative99.9%
flip3-+99.9%
associate-/r/99.9%
reciprocal-define96.8%
+-commutative96.8%
sqrt-pow296.8%
metadata-eval96.8%
pow1/296.8%
+-commutative96.8%
pow-pow96.8%
metadata-eval96.8%
Applied egg-rr96.8%
reciprocal-undefine99.9%
associate-*l/99.9%
*-lft-identity99.9%
associate-+l+99.9%
associate--l+99.9%
count-299.9%
fma-udef99.9%
rem-square-sqrt99.9%
hypot-def99.9%
Simplified99.9%
Taylor expanded in x around 0 94.6%
if 0.38 < x Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.8%
add-sqr-sqrt8.7%
associate--l+8.7%
reciprocal-define5.7%
Applied egg-rr5.7%
reciprocal-undefine8.7%
associate-*r/8.7%
*-rgt-identity8.7%
+-commutative8.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+64.5%
associate-/r/64.5%
reciprocal-define26.9%
+-commutative26.9%
sqrt-pow226.9%
metadata-eval26.9%
pow1/226.9%
+-commutative26.9%
pow-pow26.9%
metadata-eval26.9%
Applied egg-rr19.6%
reciprocal-undefine48.9%
associate-*l/48.9%
*-lft-identity48.9%
associate-+l+48.9%
associate--l+48.9%
count-248.9%
fma-udef48.9%
rem-square-sqrt48.9%
hypot-def64.9%
Simplified64.9%
Taylor expanded in x around inf 63.1%
Taylor expanded in x around inf 98.1%
rem-exp-log90.7%
exp-neg90.7%
unpow1/290.7%
exp-prod90.7%
distribute-lft-neg-out90.7%
distribute-rgt-neg-in90.7%
metadata-eval90.7%
exp-to-pow98.3%
Simplified98.3%
Final simplification96.6%
(FPCore (x) :precision binary64 (if (<= x 0.38) (reciprocal (+ 1.0 (pow x 1.5))) (* 0.5 (pow x -0.5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.38:\\
\;\;\;\;\mathsf{reciprocal}\left(\left(1 + {x}^{1.5}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.38Initial program 99.9%
flip--99.9%
div-inv99.9%
add-sqr-sqrt99.9%
add-sqr-sqrt99.9%
associate--l+99.9%
reciprocal-define95.1%
Applied egg-rr95.1%
reciprocal-undefine99.9%
associate-*r/99.9%
*-rgt-identity99.9%
+-commutative99.9%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
reciprocal-undefine95.1%
+-commutative95.1%
Simplified95.1%
reciprocal-undefine99.9%
+-commutative99.9%
flip3-+99.9%
associate-/r/99.9%
reciprocal-define96.8%
+-commutative96.8%
sqrt-pow296.8%
metadata-eval96.8%
pow1/296.8%
+-commutative96.8%
pow-pow96.8%
metadata-eval96.8%
Applied egg-rr96.8%
reciprocal-undefine99.9%
associate-*l/99.9%
*-lft-identity99.9%
associate-+l+99.9%
associate--l+99.9%
count-299.9%
fma-udef99.9%
rem-square-sqrt99.9%
hypot-def99.9%
Simplified99.9%
Taylor expanded in x around 0 94.6%
reciprocal-define94.6%
Simplified94.6%
if 0.38 < x Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.8%
add-sqr-sqrt8.7%
associate--l+8.7%
reciprocal-define5.7%
Applied egg-rr5.7%
reciprocal-undefine8.7%
associate-*r/8.7%
*-rgt-identity8.7%
+-commutative8.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+64.5%
associate-/r/64.5%
reciprocal-define26.9%
+-commutative26.9%
sqrt-pow226.9%
metadata-eval26.9%
pow1/226.9%
+-commutative26.9%
pow-pow26.9%
metadata-eval26.9%
Applied egg-rr19.6%
reciprocal-undefine48.9%
associate-*l/48.9%
*-lft-identity48.9%
associate-+l+48.9%
associate--l+48.9%
count-248.9%
fma-udef48.9%
rem-square-sqrt48.9%
hypot-def64.9%
Simplified64.9%
Taylor expanded in x around inf 63.1%
Taylor expanded in x around inf 98.1%
rem-exp-log90.7%
exp-neg90.7%
unpow1/290.7%
exp-prod90.7%
distribute-lft-neg-out90.7%
distribute-rgt-neg-in90.7%
metadata-eval90.7%
exp-to-pow98.3%
Simplified98.3%
Final simplification96.6%
(FPCore (x) :precision binary64 (if (<= x 0.25) 1.0 (* 0.5 (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.25) {
tmp = 1.0;
} else {
tmp = 0.5 * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.25d0) then
tmp = 1.0d0
else
tmp = 0.5d0 * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.25) {
tmp = 1.0;
} else {
tmp = 0.5 * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.25: tmp = 1.0 else: tmp = 0.5 * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.25) tmp = 1.0; else tmp = Float64(0.5 * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.25) tmp = 1.0; else tmp = 0.5 * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.25], 1.0, N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.25:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.25Initial program 99.9%
Taylor expanded in x around 0 94.6%
if 0.25 < x Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.8%
add-sqr-sqrt8.7%
associate--l+8.7%
reciprocal-define5.7%
Applied egg-rr5.7%
reciprocal-undefine8.7%
associate-*r/8.7%
*-rgt-identity8.7%
+-commutative8.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+64.5%
associate-/r/64.5%
reciprocal-define26.9%
+-commutative26.9%
sqrt-pow226.9%
metadata-eval26.9%
pow1/226.9%
+-commutative26.9%
pow-pow26.9%
metadata-eval26.9%
Applied egg-rr19.6%
reciprocal-undefine48.9%
associate-*l/48.9%
*-lft-identity48.9%
associate-+l+48.9%
associate--l+48.9%
count-248.9%
fma-udef48.9%
rem-square-sqrt48.9%
hypot-def64.9%
Simplified64.9%
Taylor expanded in x around inf 63.1%
Taylor expanded in x around inf 98.1%
rem-exp-log90.7%
exp-neg90.7%
unpow1/290.7%
exp-prod90.7%
distribute-lft-neg-out90.7%
distribute-rgt-neg-in90.7%
metadata-eval90.7%
exp-to-pow98.3%
Simplified98.3%
Final simplification96.6%
(FPCore (x) :precision binary64 (if (<= x 0.25) 1.0 (* 0.5 (reciprocal (sqrt x)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.25:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{reciprocal}\left(\left(\sqrt{x}\right)\right)\\
\end{array}
\end{array}
if x < 0.25Initial program 99.9%
Taylor expanded in x around 0 94.6%
if 0.25 < x Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.8%
add-sqr-sqrt8.7%
associate--l+8.7%
reciprocal-define5.7%
Applied egg-rr5.7%
reciprocal-undefine8.7%
associate-*r/8.7%
*-rgt-identity8.7%
+-commutative8.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+64.5%
associate-/r/64.5%
reciprocal-define26.9%
+-commutative26.9%
sqrt-pow226.9%
metadata-eval26.9%
pow1/226.9%
+-commutative26.9%
pow-pow26.9%
metadata-eval26.9%
Applied egg-rr19.6%
reciprocal-undefine48.9%
associate-*l/48.9%
*-lft-identity48.9%
associate-+l+48.9%
associate--l+48.9%
count-248.9%
fma-udef48.9%
rem-square-sqrt48.9%
hypot-def64.9%
Simplified64.9%
Taylor expanded in x around inf 98.1%
sqrt-div97.9%
metadata-eval97.9%
reciprocal-define39.7%
Applied egg-rr39.7%
Final simplification65.3%
(FPCore (x) :precision binary64 (if (<= x 0.25) 1.0 (* 0.5 (sqrt (reciprocal x)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.25:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{reciprocal}\left(x\right)}\\
\end{array}
\end{array}
if x < 0.25Initial program 99.9%
Taylor expanded in x around 0 94.6%
if 0.25 < x Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.8%
add-sqr-sqrt8.7%
associate--l+8.7%
reciprocal-define5.7%
Applied egg-rr5.7%
reciprocal-undefine8.7%
associate-*r/8.7%
*-rgt-identity8.7%
+-commutative8.7%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
reciprocal-undefine39.9%
+-commutative39.9%
Simplified39.9%
reciprocal-undefine99.5%
+-commutative99.5%
flip3-+64.5%
associate-/r/64.5%
reciprocal-define26.9%
+-commutative26.9%
sqrt-pow226.9%
metadata-eval26.9%
pow1/226.9%
+-commutative26.9%
pow-pow26.9%
metadata-eval26.9%
Applied egg-rr19.6%
reciprocal-undefine48.9%
associate-*l/48.9%
*-lft-identity48.9%
associate-+l+48.9%
associate--l+48.9%
count-248.9%
fma-udef48.9%
rem-square-sqrt48.9%
hypot-def64.9%
Simplified64.9%
Taylor expanded in x around inf 98.1%
reciprocal-define40.8%
Simplified40.8%
Final simplification65.8%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 50.0%
Taylor expanded in x around 0 47.7%
Final simplification47.7%
(FPCore (x) :precision binary64 (if (<= x 66000000.0) (- (sqrt (+ 1.0 x)) (sqrt x)) (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))))
double code(double x) {
double tmp;
if (x <= 66000000.0) {
tmp = sqrt((1.0 + x)) - sqrt(x);
} else {
tmp = 1.0 / (sqrt((x + 1.0)) + sqrt(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 66000000.0d0) then
tmp = sqrt((1.0d0 + x)) - sqrt(x)
else
tmp = 1.0d0 / (sqrt((x + 1.0d0)) + sqrt(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 66000000.0) {
tmp = Math.sqrt((1.0 + x)) - Math.sqrt(x);
} else {
tmp = 1.0 / (Math.sqrt((x + 1.0)) + Math.sqrt(x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 66000000.0: tmp = math.sqrt((1.0 + x)) - math.sqrt(x) else: tmp = 1.0 / (math.sqrt((x + 1.0)) + math.sqrt(x)) return tmp
function code(x) tmp = 0.0 if (x <= 66000000.0) tmp = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)); else tmp = Float64(1.0 / Float64(sqrt(Float64(x + 1.0)) + sqrt(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 66000000.0) tmp = sqrt((1.0 + x)) - sqrt(x); else tmp = 1.0 / (sqrt((x + 1.0)) + sqrt(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 66000000.0], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 66000000:\\
\;\;\;\;\sqrt{1 + x} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x + 1} + \sqrt{x}}\\
\end{array}
\end{array}
herbie shell --seed 2024024
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:herbie-target
(if (<= x 66000000.0) (- (sqrt (+ 1.0 x)) (sqrt x)) (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x))))
(- (sqrt (+ x 1.0)) (sqrt x)))