Alternative 1 | |
---|---|
Error | 0.3 |
Cost | 6848 |
\[\frac{x}{1 + \sqrt{x + 1}}
\]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) 1.0))
(FPCore (x) :precision binary64 (if (<= (+ x 1.0) 1.02) (+ (* x (* x -0.125)) (* x 0.5)) (+ (sqrt (+ x 1.0)) -1.0)))
double code(double x) { return sqrt((x + 1.0)) - 1.0; }
double code(double x) { double tmp; if ((x + 1.0) <= 1.02) { tmp = (x * (x * -0.125)) + (x * 0.5); } else { tmp = sqrt((x + 1.0)) + -1.0; } return tmp; }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((x + 1.0d0)) - 1.0d0 end function
real(8) function code(x) real(8), intent (in) :: x real(8) :: tmp if ((x + 1.0d0) <= 1.02d0) then tmp = (x * (x * (-0.125d0))) + (x * 0.5d0) else tmp = sqrt((x + 1.0d0)) + (-1.0d0) end if code = tmp end function
public static double code(double x) { return Math.sqrt((x + 1.0)) - 1.0; }
public static double code(double x) { double tmp; if ((x + 1.0) <= 1.02) { tmp = (x * (x * -0.125)) + (x * 0.5); } else { tmp = Math.sqrt((x + 1.0)) + -1.0; } return tmp; }
def code(x): return math.sqrt((x + 1.0)) - 1.0
def code(x): tmp = 0 if (x + 1.0) <= 1.02: tmp = (x * (x * -0.125)) + (x * 0.5) else: tmp = math.sqrt((x + 1.0)) + -1.0 return tmp
function code(x) return Float64(sqrt(Float64(x + 1.0)) - 1.0) end
function code(x) tmp = 0.0 if (Float64(x + 1.0) <= 1.02) tmp = Float64(Float64(x * Float64(x * -0.125)) + Float64(x * 0.5)); else tmp = Float64(sqrt(Float64(x + 1.0)) + -1.0); end return tmp end
function tmp = code(x) tmp = sqrt((x + 1.0)) - 1.0; end
function tmp_2 = code(x) tmp = 0.0; if ((x + 1.0) <= 1.02) tmp = (x * (x * -0.125)) + (x * 0.5); else tmp = sqrt((x + 1.0)) + -1.0; end tmp_2 = tmp; end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
code[x_] := If[LessEqual[N[(x + 1.0), $MachinePrecision], 1.02], N[(N[(x * N[(x * -0.125), $MachinePrecision]), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
\sqrt{x + 1} - 1
\begin{array}{l} \mathbf{if}\;x + 1 \leq 1.02:\\ \;\;\;\;x \cdot \left(x \cdot -0.125\right) + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array}
Results
if (+.f64 x 1) < 1.02
Initial program 58.9
Taylor expanded in x around 0 0.4
Simplified0.4
[Start]0.4 | \[ -0.125 \cdot {x}^{2} + 0.5 \cdot x
\] |
---|---|
+-commutative [=>]0.4 | \[ \color{blue}{0.5 \cdot x + -0.125 \cdot {x}^{2}}
\] |
fma-def [=>]0.4 | \[ \color{blue}{\mathsf{fma}\left(0.5, x, -0.125 \cdot {x}^{2}\right)}
\] |
*-commutative [=>]0.4 | \[ \mathsf{fma}\left(0.5, x, \color{blue}{{x}^{2} \cdot -0.125}\right)
\] |
unpow2 [=>]0.4 | \[ \mathsf{fma}\left(0.5, x, \color{blue}{\left(x \cdot x\right)} \cdot -0.125\right)
\] |
associate-*l* [=>]0.4 | \[ \mathsf{fma}\left(0.5, x, \color{blue}{x \cdot \left(x \cdot -0.125\right)}\right)
\] |
Applied egg-rr0.4
if 1.02 < (+.f64 x 1)
Initial program 0.0
Final simplification0.2
Alternative 1 | |
---|---|
Error | 0.3 |
Cost | 6848 |
Alternative 2 | |
---|---|
Error | 30.1 |
Cost | 448 |
Alternative 3 | |
---|---|
Error | 30.5 |
Cost | 192 |
herbie shell --seed 1
(FPCore (x)
:name "sqrt(x + 1) - 1"
:precision binary64
:pre (and (<= 0.0 x) (<= x 1.79e+308))
(- (sqrt (+ x 1.0)) 1.0))