(FPCore (x) :precision binary64 (* (sqrt (- 1.0 (* x x))) x))
double code(double x) { return sqrt((1.0 - (x * x))) * x; }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((1.0d0 - (x * x))) * x end function
public static double code(double x) { return Math.sqrt((1.0 - (x * x))) * x; }
def code(x): return math.sqrt((1.0 - (x * x))) * x
function code(x) return Float64(sqrt(Float64(1.0 - Float64(x * x))) * x) end
function tmp = code(x) tmp = sqrt((1.0 - (x * x))) * x; end
code[x_] := N[(N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l} \\ \sqrt{1 - x \cdot x} \cdot x \end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (* (sqrt (- 1.0 (* x x))) x))
double code(double x) { return sqrt((1.0 - (x * x))) * x; }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((1.0d0 - (x * x))) * x end function
public static double code(double x) { return Math.sqrt((1.0 - (x * x))) * x; }
def code(x): return math.sqrt((1.0 - (x * x))) * x
function code(x) return Float64(sqrt(Float64(1.0 - Float64(x * x))) * x) end
function tmp = code(x) tmp = sqrt((1.0 - (x * x))) * x; end
code[x_] := N[(N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l} \\ \sqrt{1 - x \cdot x} \cdot x \end{array}
(FPCore (x) :precision binary64 (* (sqrt (- 1.0 (* x x))) x))
double code(double x) { return sqrt((1.0 - (x * x))) * x; }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((1.0d0 - (x * x))) * x end function
public static double code(double x) { return Math.sqrt((1.0 - (x * x))) * x; }
def code(x): return math.sqrt((1.0 - (x * x))) * x
function code(x) return Float64(sqrt(Float64(1.0 - Float64(x * x))) * x) end
function tmp = code(x) tmp = sqrt((1.0 - (x * x))) * x; end
code[x_] := N[(N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l} \\ \sqrt{1 - x \cdot x} \cdot x \end{array}
Initial program 100.0%
(FPCore (x) :precision binary64 (* (fma (* x x) -0.5 1.0) x))
double code(double x) { return fma((x * x), -0.5, 1.0) * x; }
function code(x) return Float64(fma(Float64(x * x), -0.5, 1.0) * x) end
code[x_] := N[(N[(N[(x * x), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(x \cdot x, -0.5, 1\right) \cdot x \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
unpow2
N/A
lower-*.f64
99.4
Applied rewrites99.4%
(FPCore (x) :precision binary64 (* 1.0 x))
double code(double x) { return 1.0 * x; }
real(8) function code(x) real(8), intent (in) :: x code = 1.0d0 * x end function
public static double code(double x) { return 1.0 * x; }
def code(x): return 1.0 * x
function code(x) return Float64(1.0 * x) end
function tmp = code(x) tmp = 1.0 * x; end
code[x_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l} \\ 1 \cdot x \end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.1%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(1.0 - x * x) * x"
:precision binary64
:pre (and (<= -1000000000.0 x) (<= x 1000000000.0))
(* (sqrt (- 1.0 (* x x))) x))