
(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 6 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 x -1.0))))
double code(double x) {
return sqrt(-fma(x, x, -1.0));
}
function code(x) return sqrt(Float64(-fma(x, x, -1.0))) end
code[x_] := N[Sqrt[(-N[(x * x + -1.0), $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{-\mathsf{fma}\left(x, x, -1\right)}
\end{array}
Initial program 100.0%
sqr-neg100.0%
remove-double-neg100.0%
cancel-sign-sub100.0%
+-commutative100.0%
distribute-neg-in100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
sqr-neg100.0%
fma-neg100.0%
metadata-eval100.0%
Simplified100.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 (/ 1.0 (+ -1.0 (* x (* 0.25 (* x (* x x))))))) (+ -1.0 (* (* x x) -0.5))))
double code(double x) {
return (1.0 / (1.0 / (-1.0 + (x * (0.25 * (x * (x * x))))))) / (-1.0 + ((x * x) * -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (1.0d0 / ((-1.0d0) + (x * (0.25d0 * (x * (x * x))))))) / ((-1.0d0) + ((x * x) * (-0.5d0)))
end function
public static double code(double x) {
return (1.0 / (1.0 / (-1.0 + (x * (0.25 * (x * (x * x))))))) / (-1.0 + ((x * x) * -0.5));
}
def code(x): return (1.0 / (1.0 / (-1.0 + (x * (0.25 * (x * (x * x))))))) / (-1.0 + ((x * x) * -0.5))
function code(x) return Float64(Float64(1.0 / Float64(1.0 / Float64(-1.0 + Float64(x * Float64(0.25 * Float64(x * Float64(x * x))))))) / Float64(-1.0 + Float64(Float64(x * x) * -0.5))) end
function tmp = code(x) tmp = (1.0 / (1.0 / (-1.0 + (x * (0.25 * (x * (x * x))))))) / (-1.0 + ((x * x) * -0.5)); end
code[x_] := N[(N[(1.0 / N[(1.0 / N[(-1.0 + N[(x * N[(0.25 * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\frac{1}{-1 + x \cdot \left(0.25 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}}}{-1 + \left(x \cdot x\right) \cdot -0.5}
\end{array}
Initial program 100.0%
sqr-neg100.0%
remove-double-neg100.0%
cancel-sign-sub100.0%
+-commutative100.0%
distribute-neg-in100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
sqr-neg100.0%
fma-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
+-commutative99.1%
unpow299.1%
fma-define99.1%
Simplified99.1%
fma-undefine99.1%
flip-+99.1%
*-commutative99.1%
*-commutative99.1%
metadata-eval99.1%
*-commutative99.1%
Applied egg-rr99.1%
swap-sqr99.1%
metadata-eval99.1%
Applied egg-rr99.1%
metadata-eval99.1%
swap-sqr99.1%
associate-*r*99.1%
associate-*r*99.1%
difference-of-sqr-199.1%
remove-double-div99.1%
sub-neg99.1%
metadata-eval99.1%
associate-/r/99.1%
clear-num99.1%
clear-num99.1%
associate-/r/99.1%
remove-double-div99.1%
metadata-eval99.1%
sub-neg99.1%
difference-of-sqr-199.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x) :precision binary64 (/ 1.0 (/ (+ -1.0 (* x (* x -0.5))) (+ -1.0 (* x (* 0.25 (* x (* x x))))))))
double code(double x) {
return 1.0 / ((-1.0 + (x * (x * -0.5))) / (-1.0 + (x * (0.25 * (x * (x * x))))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((-1.0d0) + (x * (x * (-0.5d0)))) / ((-1.0d0) + (x * (0.25d0 * (x * (x * x))))))
end function
public static double code(double x) {
return 1.0 / ((-1.0 + (x * (x * -0.5))) / (-1.0 + (x * (0.25 * (x * (x * x))))));
}
def code(x): return 1.0 / ((-1.0 + (x * (x * -0.5))) / (-1.0 + (x * (0.25 * (x * (x * x))))))
function code(x) return Float64(1.0 / Float64(Float64(-1.0 + Float64(x * Float64(x * -0.5))) / Float64(-1.0 + Float64(x * Float64(0.25 * Float64(x * Float64(x * x))))))) end
function tmp = code(x) tmp = 1.0 / ((-1.0 + (x * (x * -0.5))) / (-1.0 + (x * (0.25 * (x * (x * x)))))); end
code[x_] := N[(1.0 / N[(N[(-1.0 + N[(x * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(x * N[(0.25 * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{-1 + x \cdot \left(0.25 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}}
\end{array}
Initial program 100.0%
sqr-neg100.0%
remove-double-neg100.0%
cancel-sign-sub100.0%
+-commutative100.0%
distribute-neg-in100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
sqr-neg100.0%
fma-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
+-commutative99.1%
unpow299.1%
fma-define99.1%
Simplified99.1%
fma-undefine99.1%
*-commutative99.1%
Applied egg-rr99.1%
flip-+99.1%
metadata-eval99.1%
clear-num99.1%
clear-num99.1%
metadata-eval99.1%
flip-+99.1%
associate-*l*99.1%
Applied egg-rr99.1%
*-un-lft-identity99.1%
*-inverses99.1%
associate-/r/99.1%
+-commutative99.1%
clear-num99.1%
associate-/r/99.1%
remove-double-div99.1%
metadata-eval99.1%
sub-neg99.1%
difference-of-sqr-199.1%
sub-neg99.1%
swap-sqr99.1%
swap-sqr99.1%
metadata-eval99.1%
*-commutative99.1%
associate-*r*99.1%
metadata-eval99.1%
+-commutative99.1%
*-commutative99.1%
Applied egg-rr99.1%
(FPCore (x) :precision binary64 (+ 1.0 (* (* x x) -0.5)))
double code(double x) {
return 1.0 + ((x * x) * -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + ((x * x) * (-0.5d0))
end function
public static double code(double x) {
return 1.0 + ((x * x) * -0.5);
}
def code(x): return 1.0 + ((x * x) * -0.5)
function code(x) return Float64(1.0 + Float64(Float64(x * x) * -0.5)) end
function tmp = code(x) tmp = 1.0 + ((x * x) * -0.5); end
code[x_] := N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(x \cdot x\right) \cdot -0.5
\end{array}
Initial program 100.0%
sqr-neg100.0%
remove-double-neg100.0%
cancel-sign-sub100.0%
+-commutative100.0%
distribute-neg-in100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
sqr-neg100.0%
fma-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
+-commutative99.1%
unpow299.1%
fma-define99.1%
Simplified99.1%
fma-undefine99.1%
*-commutative99.1%
Applied egg-rr99.1%
Final simplification99.1%
(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%
sqr-neg100.0%
remove-double-neg100.0%
cancel-sign-sub100.0%
+-commutative100.0%
distribute-neg-in100.0%
distribute-lft-neg-out100.0%
sub-neg100.0%
sqr-neg100.0%
fma-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 98.2%
herbie shell --seed 2024097
(FPCore (x)
:name "Diagrams.TwoD.Ellipse:ellipse from diagrams-lib-1.3.0.3"
:precision binary64
(sqrt (- 1.0 (* x x))))