
(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 12 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 (- x x)) (+ (sqrt (+ 1.0 x)) (sqrt x))))
double code(double x) {
return (1.0 + (x - x)) / (sqrt((1.0 + x)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + (x - x)) / (sqrt((1.0d0 + x)) + sqrt(x))
end function
public static double code(double x) {
return (1.0 + (x - x)) / (Math.sqrt((1.0 + x)) + Math.sqrt(x));
}
def code(x): return (1.0 + (x - x)) / (math.sqrt((1.0 + x)) + math.sqrt(x))
function code(x) return Float64(Float64(1.0 + Float64(x - x)) / Float64(sqrt(Float64(1.0 + x)) + sqrt(x))) end
function tmp = code(x) tmp = (1.0 + (x - x)) / (sqrt((1.0 + x)) + sqrt(x)); end
code[x_] := N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 + \left(x - x\right)}{\sqrt{1 + x} + \sqrt{x}}
\end{array}
Initial program 56.8%
sub-neg56.8%
flip-+57.2%
add-sqr-sqrt57.1%
pow157.1%
pow157.1%
pow-prod-up57.1%
metadata-eval57.1%
Applied egg-rr57.1%
unpow257.1%
sqr-neg57.1%
add-sqr-sqrt57.4%
*-un-lft-identity57.4%
+-commutative57.4%
*-un-lft-identity57.4%
associate--l+99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (- t_0 (sqrt x)) 0.0)
(/ (+ 1.0 (- x x)) (+ (sqrt x) (sqrt x)))
(/ (+ x (- 1.0 x)) (+ t_0 (sqrt x))))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if ((t_0 - sqrt(x)) <= 0.0) {
tmp = (1.0 + (x - x)) / (sqrt(x) + sqrt(x));
} else {
tmp = (x + (1.0 - x)) / (t_0 + sqrt(x));
}
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))
if ((t_0 - sqrt(x)) <= 0.0d0) then
tmp = (1.0d0 + (x - x)) / (sqrt(x) + sqrt(x))
else
tmp = (x + (1.0d0 - x)) / (t_0 + sqrt(x))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if ((t_0 - Math.sqrt(x)) <= 0.0) {
tmp = (1.0 + (x - x)) / (Math.sqrt(x) + Math.sqrt(x));
} else {
tmp = (x + (1.0 - x)) / (t_0 + Math.sqrt(x));
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if (t_0 - math.sqrt(x)) <= 0.0: tmp = (1.0 + (x - x)) / (math.sqrt(x) + math.sqrt(x)) else: tmp = (x + (1.0 - x)) / (t_0 + math.sqrt(x)) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(t_0 - sqrt(x)) <= 0.0) tmp = Float64(Float64(1.0 + Float64(x - x)) / Float64(sqrt(x) + sqrt(x))); else tmp = Float64(Float64(x + Float64(1.0 - x)) / Float64(t_0 + sqrt(x))); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if ((t_0 - sqrt(x)) <= 0.0) tmp = (1.0 + (x - x)) / (sqrt(x) + sqrt(x)); else tmp = (x + (1.0 - x)) / (t_0 + sqrt(x)); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;t\_0 - \sqrt{x} \leq 0:\\
\;\;\;\;\frac{1 + \left(x - x\right)}{\sqrt{x} + \sqrt{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + \left(1 - x\right)}{t\_0 + \sqrt{x}}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 0.0Initial program 3.8%
sub-neg3.8%
flip-+3.8%
add-sqr-sqrt3.5%
pow13.5%
pow13.5%
pow-prod-up3.5%
metadata-eval3.5%
Applied egg-rr3.5%
unpow23.5%
sqr-neg3.5%
add-sqr-sqrt3.8%
*-un-lft-identity3.8%
+-commutative3.8%
*-un-lft-identity3.8%
associate--l+99.6%
Applied egg-rr99.6%
add-sqr-sqrt99.3%
pow299.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 99.6%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 98.8%
flip--99.4%
add-sqr-sqrt99.3%
add-sqr-sqrt99.9%
associate--l+99.9%
Applied egg-rr99.9%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (- t_0 (sqrt x)) 2e-7)
(/ (+ 1.0 (- x x)) (+ (sqrt x) (sqrt x)))
(- t_0 (/ x (sqrt x))))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if ((t_0 - sqrt(x)) <= 2e-7) {
tmp = (1.0 + (x - x)) / (sqrt(x) + sqrt(x));
} else {
tmp = t_0 - (x / sqrt(x));
}
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))
if ((t_0 - sqrt(x)) <= 2d-7) then
tmp = (1.0d0 + (x - x)) / (sqrt(x) + sqrt(x))
else
tmp = t_0 - (x / sqrt(x))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if ((t_0 - Math.sqrt(x)) <= 2e-7) {
tmp = (1.0 + (x - x)) / (Math.sqrt(x) + Math.sqrt(x));
} else {
tmp = t_0 - (x / Math.sqrt(x));
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if (t_0 - math.sqrt(x)) <= 2e-7: tmp = (1.0 + (x - x)) / (math.sqrt(x) + math.sqrt(x)) else: tmp = t_0 - (x / math.sqrt(x)) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(t_0 - sqrt(x)) <= 2e-7) tmp = Float64(Float64(1.0 + Float64(x - x)) / Float64(sqrt(x) + sqrt(x))); else tmp = Float64(t_0 - Float64(x / sqrt(x))); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if ((t_0 - sqrt(x)) <= 2e-7) tmp = (1.0 + (x - x)) / (sqrt(x) + sqrt(x)); else tmp = t_0 - (x / sqrt(x)); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 2e-7], N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[(x / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;t\_0 - \sqrt{x} \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\frac{1 + \left(x - x\right)}{\sqrt{x} + \sqrt{x}}\\
\mathbf{else}:\\
\;\;\;\;t\_0 - \frac{x}{\sqrt{x}}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 1.9999999999999999e-7Initial program 4.2%
sub-neg4.2%
flip-+4.9%
add-sqr-sqrt4.6%
pow14.6%
pow14.6%
pow-prod-up4.6%
metadata-eval4.6%
Applied egg-rr4.6%
unpow24.6%
sqr-neg4.6%
add-sqr-sqrt5.4%
*-un-lft-identity5.4%
+-commutative5.4%
*-un-lft-identity5.4%
associate--l+99.6%
Applied egg-rr99.6%
add-sqr-sqrt99.3%
pow299.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 99.4%
if 1.9999999999999999e-7 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 99.7%
Applied egg-rr99.7%
sub-neg99.7%
associate-+l+99.7%
fma-undefine99.7%
+-commutative99.7%
*-commutative99.7%
distribute-rgt-neg-out99.7%
distribute-lft-neg-out99.7%
associate-+r+99.7%
+-commutative99.7%
unsub-neg99.7%
+-inverses99.7%
+-commutative99.7%
+-rgt-identity99.7%
distribute-lft-neg-out99.7%
unsub-neg99.7%
*-commutative99.7%
Simplified99.7%
pow1/399.7%
pow-prod-up99.7%
metadata-eval99.7%
pow1/299.7%
add-sqr-sqrt99.7%
sqr-neg99.7%
sqrt-prod0.0%
add-sqr-sqrt91.8%
neg-sub091.8%
flip--91.8%
metadata-eval91.8%
add-sqr-sqrt91.8%
neg-sub091.8%
add-sqr-sqrt91.8%
distribute-lft-neg-in91.8%
add-sqr-sqrt0.0%
sqrt-prod99.8%
sqr-neg99.8%
add-sqr-sqrt99.8%
add-sqr-sqrt99.8%
add-sqr-sqrt99.8%
sqr-neg99.8%
sqrt-prod0.0%
add-sqr-sqrt91.8%
sub-neg91.8%
neg-sub091.8%
add-sqr-sqrt0.0%
Applied egg-rr99.8%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (- t_0 (sqrt x)) 0.0)
(/ -1.0 (- (sqrt (+ 1.0 (+ x x)))))
(- t_0 (/ x (sqrt x))))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if ((t_0 - sqrt(x)) <= 0.0) {
tmp = -1.0 / -sqrt((1.0 + (x + x)));
} else {
tmp = t_0 - (x / sqrt(x));
}
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))
if ((t_0 - sqrt(x)) <= 0.0d0) then
tmp = (-1.0d0) / -sqrt((1.0d0 + (x + x)))
else
tmp = t_0 - (x / sqrt(x))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if ((t_0 - Math.sqrt(x)) <= 0.0) {
tmp = -1.0 / -Math.sqrt((1.0 + (x + x)));
} else {
tmp = t_0 - (x / Math.sqrt(x));
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if (t_0 - math.sqrt(x)) <= 0.0: tmp = -1.0 / -math.sqrt((1.0 + (x + x))) else: tmp = t_0 - (x / math.sqrt(x)) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(t_0 - sqrt(x)) <= 0.0) tmp = Float64(-1.0 / Float64(-sqrt(Float64(1.0 + Float64(x + x))))); else tmp = Float64(t_0 - Float64(x / sqrt(x))); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if ((t_0 - sqrt(x)) <= 0.0) tmp = -1.0 / -sqrt((1.0 + (x + x))); else tmp = t_0 - (x / sqrt(x)); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.0], N[(-1.0 / (-N[Sqrt[N[(1.0 + N[(x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(t$95$0 - N[(x / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;t\_0 - \sqrt{x} \leq 0:\\
\;\;\;\;\frac{-1}{-\sqrt{1 + \left(x + x\right)}}\\
\mathbf{else}:\\
\;\;\;\;t\_0 - \frac{x}{\sqrt{x}}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 0.0Initial program 3.8%
Applied egg-rr5.8%
sub-neg5.8%
associate-+l+5.8%
fma-undefine5.8%
+-commutative5.8%
*-commutative5.8%
distribute-rgt-neg-out5.8%
distribute-lft-neg-out5.8%
associate-+r+5.8%
+-commutative5.8%
unsub-neg5.8%
+-inverses5.8%
+-commutative5.8%
+-rgt-identity5.8%
distribute-lft-neg-out5.8%
unsub-neg5.8%
*-commutative5.8%
Simplified5.8%
Applied egg-rr3.8%
Taylor expanded in x around 0 20.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 98.8%
Applied egg-rr98.7%
sub-neg98.7%
associate-+l+98.7%
fma-undefine98.7%
+-commutative98.7%
*-commutative98.7%
distribute-rgt-neg-out98.7%
distribute-lft-neg-out98.7%
associate-+r+98.7%
+-commutative98.7%
unsub-neg98.7%
+-inverses98.7%
+-commutative98.7%
+-rgt-identity98.7%
distribute-lft-neg-out98.7%
unsub-neg98.7%
*-commutative98.7%
Simplified98.7%
pow1/398.7%
pow-prod-up98.8%
metadata-eval98.8%
pow1/298.8%
add-sqr-sqrt98.8%
sqr-neg98.8%
sqrt-prod0.0%
add-sqr-sqrt90.6%
neg-sub090.6%
flip--90.6%
metadata-eval90.6%
add-sqr-sqrt90.6%
neg-sub090.6%
add-sqr-sqrt90.6%
distribute-lft-neg-in90.6%
add-sqr-sqrt0.0%
sqrt-prod98.8%
sqr-neg98.8%
add-sqr-sqrt98.8%
add-sqr-sqrt98.8%
add-sqr-sqrt98.8%
sqr-neg98.8%
sqrt-prod0.0%
add-sqr-sqrt90.6%
sub-neg90.6%
neg-sub090.6%
add-sqr-sqrt0.0%
Applied egg-rr98.8%
Final simplification64.2%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 0.0) (/ -1.0 (- (sqrt (+ 1.0 (+ x x))))) t_0)))
double code(double x) {
double t_0 = sqrt((1.0 + x)) - sqrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = -1.0 / -sqrt((1.0 + (x + x)));
} 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 <= 0.0d0) then
tmp = (-1.0d0) / -sqrt((1.0d0 + (x + x)))
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 <= 0.0) {
tmp = -1.0 / -Math.sqrt((1.0 + (x + x)));
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) - math.sqrt(x) tmp = 0 if t_0 <= 0.0: tmp = -1.0 / -math.sqrt((1.0 + (x + x))) 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 <= 0.0) tmp = Float64(-1.0 / Float64(-sqrt(Float64(1.0 + Float64(x + x))))); 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 <= 0.0) tmp = -1.0 / -sqrt((1.0 + (x + x))); 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, 0.0], N[(-1.0 / (-N[Sqrt[N[(1.0 + N[(x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{-1}{-\sqrt{1 + \left(x + x\right)}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 0.0Initial program 3.8%
Applied egg-rr5.8%
sub-neg5.8%
associate-+l+5.8%
fma-undefine5.8%
+-commutative5.8%
*-commutative5.8%
distribute-rgt-neg-out5.8%
distribute-lft-neg-out5.8%
associate-+r+5.8%
+-commutative5.8%
unsub-neg5.8%
+-inverses5.8%
+-commutative5.8%
+-rgt-identity5.8%
distribute-lft-neg-out5.8%
unsub-neg5.8%
*-commutative5.8%
Simplified5.8%
Applied egg-rr3.8%
Taylor expanded in x around 0 20.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 98.8%
Final simplification64.2%
(FPCore (x) :precision binary64 (if (<= x 4.0) (/ (+ x (- 1.0 x)) (+ (sqrt x) (+ 1.0 (* x (+ 0.5 (* x -0.125)))))) (/ -1.0 (- (sqrt (+ 1.0 (+ x x)))))))
double code(double x) {
double tmp;
if (x <= 4.0) {
tmp = (x + (1.0 - x)) / (sqrt(x) + (1.0 + (x * (0.5 + (x * -0.125)))));
} else {
tmp = -1.0 / -sqrt((1.0 + (x + x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 4.0d0) then
tmp = (x + (1.0d0 - x)) / (sqrt(x) + (1.0d0 + (x * (0.5d0 + (x * (-0.125d0))))))
else
tmp = (-1.0d0) / -sqrt((1.0d0 + (x + x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 4.0) {
tmp = (x + (1.0 - x)) / (Math.sqrt(x) + (1.0 + (x * (0.5 + (x * -0.125)))));
} else {
tmp = -1.0 / -Math.sqrt((1.0 + (x + x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 4.0: tmp = (x + (1.0 - x)) / (math.sqrt(x) + (1.0 + (x * (0.5 + (x * -0.125))))) else: tmp = -1.0 / -math.sqrt((1.0 + (x + x))) return tmp
function code(x) tmp = 0.0 if (x <= 4.0) tmp = Float64(Float64(x + Float64(1.0 - x)) / Float64(sqrt(x) + Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * -0.125)))))); else tmp = Float64(-1.0 / Float64(-sqrt(Float64(1.0 + Float64(x + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 4.0) tmp = (x + (1.0 - x)) / (sqrt(x) + (1.0 + (x * (0.5 + (x * -0.125))))); else tmp = -1.0 / -sqrt((1.0 + (x + x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 4.0], N[(N[(x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[(1.0 + N[(x * N[(0.5 + N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 / (-N[Sqrt[N[(1.0 + N[(x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4:\\
\;\;\;\;\frac{x + \left(1 - x\right)}{\sqrt{x} + \left(1 + x \cdot \left(0.5 + x \cdot -0.125\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{-\sqrt{1 + \left(x + x\right)}}\\
\end{array}
\end{array}
if x < 4Initial program 99.9%
flip--99.8%
add-sqr-sqrt99.9%
add-sqr-sqrt99.9%
associate--l+99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.4%
+-commutative97.4%
unpow297.4%
associate-*r*97.4%
distribute-rgt-out97.4%
*-commutative97.4%
Simplified97.4%
if 4 < x Initial program 4.9%
Applied egg-rr6.8%
sub-neg6.8%
associate-+l+6.8%
fma-undefine6.8%
+-commutative6.8%
*-commutative6.8%
distribute-rgt-neg-out6.8%
distribute-lft-neg-out6.8%
associate-+r+6.8%
+-commutative6.8%
unsub-neg6.8%
+-inverses6.8%
+-commutative6.8%
+-rgt-identity6.8%
distribute-lft-neg-out6.8%
unsub-neg6.8%
*-commutative6.8%
Simplified6.8%
Applied egg-rr4.2%
Taylor expanded in x around 0 20.3%
Final simplification62.5%
(FPCore (x) :precision binary64 (if (<= x 1.55) (- (+ 1.0 (* x (+ 0.5 (* x -0.125)))) (sqrt x)) (/ -1.0 (- (sqrt (+ 1.0 (+ x x)))))))
double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x);
} else {
tmp = -1.0 / -sqrt((1.0 + (x + x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.55d0) then
tmp = (1.0d0 + (x * (0.5d0 + (x * (-0.125d0))))) - sqrt(x)
else
tmp = (-1.0d0) / -sqrt((1.0d0 + (x + x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - Math.sqrt(x);
} else {
tmp = -1.0 / -Math.sqrt((1.0 + (x + x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.55: tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - math.sqrt(x) else: tmp = -1.0 / -math.sqrt((1.0 + (x + x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.55) tmp = Float64(Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * -0.125)))) - sqrt(x)); else tmp = Float64(-1.0 / Float64(-sqrt(Float64(1.0 + Float64(x + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.55) tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x); else tmp = -1.0 / -sqrt((1.0 + (x + x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.55], N[(N[(1.0 + N[(x * N[(0.5 + N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(-1.0 / (-N[Sqrt[N[(1.0 + N[(x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;\left(1 + x \cdot \left(0.5 + x \cdot -0.125\right)\right) - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{-\sqrt{1 + \left(x + x\right)}}\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 99.9%
Taylor expanded in x around 0 97.4%
+-commutative97.4%
unpow297.4%
associate-*r*97.4%
distribute-rgt-out97.4%
*-commutative97.4%
Simplified97.4%
if 1.55000000000000004 < x Initial program 4.9%
Applied egg-rr6.8%
sub-neg6.8%
associate-+l+6.8%
fma-undefine6.8%
+-commutative6.8%
*-commutative6.8%
distribute-rgt-neg-out6.8%
distribute-lft-neg-out6.8%
associate-+r+6.8%
+-commutative6.8%
unsub-neg6.8%
+-inverses6.8%
+-commutative6.8%
+-rgt-identity6.8%
distribute-lft-neg-out6.8%
unsub-neg6.8%
*-commutative6.8%
Simplified6.8%
Applied egg-rr4.2%
Taylor expanded in x around 0 20.3%
Final simplification62.5%
(FPCore (x) :precision binary64 (if (<= x 1.4) (- (+ 1.0 (* x 0.5)) (sqrt x)) (/ -1.0 (- (sqrt (+ 1.0 (+ x x)))))))
double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = (1.0 + (x * 0.5)) - sqrt(x);
} else {
tmp = -1.0 / -sqrt((1.0 + (x + x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.4d0) then
tmp = (1.0d0 + (x * 0.5d0)) - sqrt(x)
else
tmp = (-1.0d0) / -sqrt((1.0d0 + (x + x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = (1.0 + (x * 0.5)) - Math.sqrt(x);
} else {
tmp = -1.0 / -Math.sqrt((1.0 + (x + x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.4: tmp = (1.0 + (x * 0.5)) - math.sqrt(x) else: tmp = -1.0 / -math.sqrt((1.0 + (x + x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.4) tmp = Float64(Float64(1.0 + Float64(x * 0.5)) - sqrt(x)); else tmp = Float64(-1.0 / Float64(-sqrt(Float64(1.0 + Float64(x + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.4) tmp = (1.0 + (x * 0.5)) - sqrt(x); else tmp = -1.0 / -sqrt((1.0 + (x + x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.4], N[(N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(-1.0 / (-N[Sqrt[N[(1.0 + N[(x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\left(1 + x \cdot 0.5\right) - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{-\sqrt{1 + \left(x + x\right)}}\\
\end{array}
\end{array}
if x < 1.3999999999999999Initial program 99.9%
Taylor expanded in x around 0 96.9%
if 1.3999999999999999 < x Initial program 4.9%
Applied egg-rr6.8%
sub-neg6.8%
associate-+l+6.8%
fma-undefine6.8%
+-commutative6.8%
*-commutative6.8%
distribute-rgt-neg-out6.8%
distribute-lft-neg-out6.8%
associate-+r+6.8%
+-commutative6.8%
unsub-neg6.8%
+-inverses6.8%
+-commutative6.8%
+-rgt-identity6.8%
distribute-lft-neg-out6.8%
unsub-neg6.8%
*-commutative6.8%
Simplified6.8%
Applied egg-rr4.2%
Taylor expanded in x around 0 20.3%
Final simplification62.2%
(FPCore (x) :precision binary64 (- (+ 1.0 (* x 0.5)) (sqrt x)))
double code(double x) {
return (1.0 + (x * 0.5)) - sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + (x * 0.5d0)) - sqrt(x)
end function
public static double code(double x) {
return (1.0 + (x * 0.5)) - Math.sqrt(x);
}
def code(x): return (1.0 + (x * 0.5)) - math.sqrt(x)
function code(x) return Float64(Float64(1.0 + Float64(x * 0.5)) - sqrt(x)) end
function tmp = code(x) tmp = (1.0 + (x * 0.5)) - sqrt(x); end
code[x_] := N[(N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + x \cdot 0.5\right) - \sqrt{x}
\end{array}
Initial program 56.8%
Taylor expanded in x around 0 55.0%
Final simplification55.0%
(FPCore (x) :precision binary64 (/ 1.0 (+ 1.0 (* x 1.5))))
double code(double x) {
return 1.0 / (1.0 + (x * 1.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 + (x * 1.5d0))
end function
public static double code(double x) {
return 1.0 / (1.0 + (x * 1.5));
}
def code(x): return 1.0 / (1.0 + (x * 1.5))
function code(x) return Float64(1.0 / Float64(1.0 + Float64(x * 1.5))) end
function tmp = code(x) tmp = 1.0 / (1.0 + (x * 1.5)); end
code[x_] := N[(1.0 / N[(1.0 + N[(x * 1.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + x \cdot 1.5}
\end{array}
Initial program 56.8%
pow1/256.8%
pow156.8%
pow-to-exp56.7%
pow-exp56.7%
log1p-expm1-u56.7%
expm1-define56.7%
pow-exp56.7%
pow156.7%
expm1-undefine56.7%
log1p-expm1-u56.7%
+-commutative56.7%
log1p-define56.7%
Applied egg-rr56.7%
Taylor expanded in x around 0 55.0%
*-commutative55.0%
Simplified55.0%
Applied egg-rr53.8%
exp-prod53.8%
unpow-153.8%
log1p-undefine53.8%
rem-exp-log53.8%
fma-undefine53.8%
*-commutative53.8%
distribute-lft1-in53.8%
metadata-eval53.8%
Simplified53.8%
Final simplification53.8%
(FPCore (x) :precision binary64 (/ -1.0 (- -1.0 x)))
double code(double x) {
return -1.0 / (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) / ((-1.0d0) - x)
end function
public static double code(double x) {
return -1.0 / (-1.0 - x);
}
def code(x): return -1.0 / (-1.0 - x)
function code(x) return Float64(-1.0 / Float64(-1.0 - x)) end
function tmp = code(x) tmp = -1.0 / (-1.0 - x); end
code[x_] := N[(-1.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{-1 - x}
\end{array}
Initial program 56.8%
Applied egg-rr57.7%
sub-neg57.7%
associate-+l+57.7%
fma-undefine57.7%
+-commutative57.7%
*-commutative57.7%
distribute-rgt-neg-out57.7%
distribute-lft-neg-out57.7%
associate-+r+57.7%
+-commutative57.7%
unsub-neg57.7%
+-inverses57.7%
+-commutative57.7%
+-rgt-identity57.7%
distribute-lft-neg-out57.7%
unsub-neg57.7%
*-commutative57.7%
Simplified57.7%
Applied egg-rr52.5%
Taylor expanded in x around 0 59.8%
Taylor expanded in x around 0 53.8%
Final simplification53.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 56.8%
Taylor expanded in x around 0 53.7%
Final simplification53.7%
(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 2024039
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))