
(FPCore (x) :precision binary64 (sqrt (- 1.0 (* x x))))
double code(double x) {
return sqrt((1.0 - (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 - (x * x)))
end function
public static double code(double x) {
return Math.sqrt((1.0 - (x * x)));
}
def code(x): return math.sqrt((1.0 - (x * x)))
function code(x) return sqrt(Float64(1.0 - Float64(x * x))) end
function tmp = code(x) tmp = sqrt((1.0 - (x * x))); end
code[x_] := N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{1 - x \cdot x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (- 1.0 (* x x))))
double code(double x) {
return sqrt((1.0 - (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 - (x * x)))
end function
public static double code(double x) {
return Math.sqrt((1.0 - (x * x)));
}
def code(x): return math.sqrt((1.0 - (x * x)))
function code(x) return sqrt(Float64(1.0 - Float64(x * x))) end
function tmp = code(x) tmp = sqrt((1.0 - (x * x))); end
code[x_] := N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{1 - x \cdot x}
\end{array}
(FPCore (x) :precision binary64 (+ 1.0 (* (pow x 2.0) (- (* (pow x 2.0) -0.125) 0.5))))
double code(double x) {
return 1.0 + (pow(x, 2.0) * ((pow(x, 2.0) * -0.125) - 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + ((x ** 2.0d0) * (((x ** 2.0d0) * (-0.125d0)) - 0.5d0))
end function
public static double code(double x) {
return 1.0 + (Math.pow(x, 2.0) * ((Math.pow(x, 2.0) * -0.125) - 0.5));
}
def code(x): return 1.0 + (math.pow(x, 2.0) * ((math.pow(x, 2.0) * -0.125) - 0.5))
function code(x) return Float64(1.0 + Float64((x ^ 2.0) * Float64(Float64((x ^ 2.0) * -0.125) - 0.5))) end
function tmp = code(x) tmp = 1.0 + ((x ^ 2.0) * (((x ^ 2.0) * -0.125) - 0.5)); end
code[x_] := N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(N[Power[x, 2.0], $MachinePrecision] * -0.125), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + {x}^{2} \cdot \left({x}^{2} \cdot -0.125 - 0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (sqrt (+ 1.0 (- 1.0 (fma x x 1.0)))))
double code(double x) {
return sqrt((1.0 + (1.0 - fma(x, x, 1.0))));
}
function code(x) return sqrt(Float64(1.0 + Float64(1.0 - fma(x, x, 1.0)))) end
code[x_] := N[Sqrt[N[(1.0 + N[(1.0 - N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{1 + \left(1 - \mathsf{fma}\left(x, x, 1\right)\right)}
\end{array}
Initial program 100.0%
expm1-log1p-u100.0%
expm1-undefine100.0%
log1p-undefine100.0%
add-exp-log100.0%
+-commutative100.0%
fma-define100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (sqrt (- 1.0 (* x x))))
double code(double x) {
return sqrt((1.0 - (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 - (x * x)))
end function
public static double code(double x) {
return Math.sqrt((1.0 - (x * x)));
}
def code(x): return math.sqrt((1.0 - (x * x)))
function code(x) return sqrt(Float64(1.0 - Float64(x * x))) end
function tmp = code(x) tmp = sqrt((1.0 - (x * x))); end
code[x_] := N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{1 - x \cdot x}
\end{array}
Initial program 100.0%
(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 100.0%
Taylor expanded in x around 0 99.1%
herbie shell --seed 2024135
(FPCore (x)
:name "Diagrams.TwoD.Ellipse:ellipse from diagrams-lib-1.3.0.3"
:precision binary64
(sqrt (- 1.0 (* x x))))