
(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 (sqrt (fma (- x -1.0) (- x) (- x -1.0))))
double code(double x) {
return sqrt(fma((x - -1.0), -x, (x - -1.0)));
}
function code(x) return sqrt(fma(Float64(x - -1.0), Float64(-x), Float64(x - -1.0))) end
code[x_] := N[Sqrt[N[(N[(x - -1.0), $MachinePrecision] * (-x) + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(x - -1, -x, x - -1\right)}
\end{array}
Initial program 100.0%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
pow-prod-downN/A
pow-prod-upN/A
lower-pow.f64N/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-pow.f64N/A
metadata-evalN/A
pow-powN/A
pow2N/A
lift-*.f64N/A
pow2N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
lift-/.f64N/A
frac-2negN/A
lift-fma.f64N/A
distribute-neg-inN/A
distribute-rgt-neg-outN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
sqr-negN/A
sub-negN/A
metadata-evalN/A
distribute-frac-neg2N/A
lift-fma.f64N/A
lift-*.f64N/A
flip--N/A
lift-*.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift-neg.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
lift-neg.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
lift-+.f64N/A
metadata-evalN/A
sub-negN/A
lower--.f64100.0
lift-+.f64N/A
metadata-evalN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.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 (fma (* x x) -0.5 1.0))
double code(double x) {
return fma((x * x), -0.5, 1.0);
}
function code(x) return fma(Float64(x * x), -0.5, 1.0) end
code[x_] := N[(N[(x * x), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot x, -0.5, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.7
Applied rewrites98.7%
(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
Applied rewrites98.0%
herbie shell --seed 2024277
(FPCore (x)
:name "Diagrams.TwoD.Ellipse:ellipse from diagrams-lib-1.3.0.3"
:precision binary64
(sqrt (- 1.0 (* x x))))