(FPCore (x s) :precision binary64 (pow (sqrt (- x (* (pow (- 1.0 s) 2.0) 0.25))) 0.5))
double code(double x, double s) { return pow(sqrt((x - (pow((1.0 - s), 2.0) * 0.25))), 0.5); }
real(8) function code(x, s) real(8), intent (in) :: x real(8), intent (in) :: s code = sqrt((x - (((1.0d0 - s) ** 2.0d0) * 0.25d0))) ** 0.5d0 end function
public static double code(double x, double s) { return Math.pow(Math.sqrt((x - (Math.pow((1.0 - s), 2.0) * 0.25))), 0.5); }
def code(x, s): return math.pow(math.sqrt((x - (math.pow((1.0 - s), 2.0) * 0.25))), 0.5)
function code(x, s) return sqrt(Float64(x - Float64((Float64(1.0 - s) ^ 2.0) * 0.25))) ^ 0.5 end
function tmp = code(x, s) tmp = sqrt((x - (((1.0 - s) ^ 2.0) * 0.25))) ^ 0.5; end
code[x_, s_] := N[Power[N[Sqrt[N[(x - N[(N[Power[N[(1.0 - s), $MachinePrecision], 2.0], $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.5], $MachinePrecision]
\begin{array}{l} \\ {\left(\sqrt{x - {\left(1 - s\right)}^{2} \cdot 0.25}\right)}^{0.5} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x s) :precision binary64 (pow (sqrt (- x (* (pow (- 1.0 s) 2.0) 0.25))) 0.5))
double code(double x, double s) { return pow(sqrt((x - (pow((1.0 - s), 2.0) * 0.25))), 0.5); }
real(8) function code(x, s) real(8), intent (in) :: x real(8), intent (in) :: s code = sqrt((x - (((1.0d0 - s) ** 2.0d0) * 0.25d0))) ** 0.5d0 end function
public static double code(double x, double s) { return Math.pow(Math.sqrt((x - (Math.pow((1.0 - s), 2.0) * 0.25))), 0.5); }
def code(x, s): return math.pow(math.sqrt((x - (math.pow((1.0 - s), 2.0) * 0.25))), 0.5)
function code(x, s) return sqrt(Float64(x - Float64((Float64(1.0 - s) ^ 2.0) * 0.25))) ^ 0.5 end
function tmp = code(x, s) tmp = sqrt((x - (((1.0 - s) ^ 2.0) * 0.25))) ^ 0.5; end
code[x_, s_] := N[Power[N[Sqrt[N[(x - N[(N[Power[N[(1.0 - s), $MachinePrecision], 2.0], $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.5], $MachinePrecision]
\begin{array}{l} \\ {\left(\sqrt{x - {\left(1 - s\right)}^{2} \cdot 0.25}\right)}^{0.5} \end{array}
(FPCore (x s) :precision binary64 (pow (fma (- 1.0 s) (* (- 1.0 s) -0.25) x) 0.25))
double code(double x, double s) { return pow(fma((1.0 - s), ((1.0 - s) * -0.25), x), 0.25); }
function code(x, s) return fma(Float64(1.0 - s), Float64(Float64(1.0 - s) * -0.25), x) ^ 0.25 end
code[x_, s_] := N[Power[N[(N[(1.0 - s), $MachinePrecision] * N[(N[(1.0 - s), $MachinePrecision] * -0.25), $MachinePrecision] + x), $MachinePrecision], 0.25], $MachinePrecision]
\begin{array}{l} \\ {\left(\mathsf{fma}\left(1 - s, \left(1 - s\right) \cdot -0.25, x\right)\right)}^{0.25} \end{array}
Initial program 99.7%
lift-pow.f64
N/A
lift-sqrt.f64
N/A
sqrt-pow2
N/A
metadata-eval
N/A
lower-pow.f64
99.8
lift--.f64
N/A
sub-neg
N/A
+-commutative
N/A
lift-*.f64
N/A
*-commutative
N/A
distribute-lft-neg-in
N/A
lower-fma.f64
N/A
metadata-eval
99.8
Applied rewrites99.8%
lift-fma.f64
N/A
*-commutative
N/A
lift-pow.f64
N/A
unpow2
N/A
associate-*l*
N/A
lower-fma.f64
N/A
lower-*.f64
99.9
Applied rewrites99.9%
(FPCore (x s) :precision binary64 (pow (fma -0.25 (fma (- s 2.0) s 1.0) x) 0.25))
double code(double x, double s) { return pow(fma(-0.25, fma((s - 2.0), s, 1.0), x), 0.25); }
function code(x, s) return fma(-0.25, fma(Float64(s - 2.0), s, 1.0), x) ^ 0.25 end
code[x_, s_] := N[Power[N[(-0.25 * N[(N[(s - 2.0), $MachinePrecision] * s + 1.0), $MachinePrecision] + x), $MachinePrecision], 0.25], $MachinePrecision]
\begin{array}{l} \\ {\left(\mathsf{fma}\left(-0.25, \mathsf{fma}\left(s - 2, s, 1\right), x\right)\right)}^{0.25} \end{array}
Initial program 99.7%
lift-pow.f64
N/A
lift-sqrt.f64
N/A
sqrt-pow2
N/A
metadata-eval
N/A
lower-pow.f64
99.8
lift--.f64
N/A
sub-neg
N/A
+-commutative
N/A
lift-*.f64
N/A
*-commutative
N/A
distribute-lft-neg-in
N/A
lower-fma.f64
N/A
metadata-eval
99.8
Applied rewrites99.8%
Taylor expanded in s around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
lower--.f64
92.0
Applied rewrites92.0%
(FPCore (x s) :precision binary64 (sqrt (sqrt (- x (fma (fma 0.25 s -0.5) s 0.25)))))
double code(double x, double s) { return sqrt(sqrt((x - fma(fma(0.25, s, -0.5), s, 0.25)))); }
function code(x, s) return sqrt(sqrt(Float64(x - fma(fma(0.25, s, -0.5), s, 0.25)))) end
code[x_, s_] := N[Sqrt[N[Sqrt[N[(x - N[(N[(0.25 * s + -0.5), $MachinePrecision] * s + 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \sqrt{\sqrt{x - \mathsf{fma}\left(\mathsf{fma}\left(0.25, s, -0.5\right), s, 0.25\right)}} \end{array}
Initial program 99.7%
Taylor expanded in s around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
sub-neg
N/A
metadata-eval
N/A
lower-fma.f64
92.0
Applied rewrites92.0%
lift-pow.f64
N/A
unpow1/2
N/A
lower-sqrt.f64
92.0
Applied rewrites92.0%
herbie shell --seed 1
(FPCore (x s)
:name "sqrt(x - (1-s)^2 * 0.25)^(0.5)"
:precision binary64
:pre (and (and (<= 0.0 x) (<= x 0.001)) (and (<= 0.99 s) (<= s 1.0)))
(pow (sqrt (- x (* (pow (- 1.0 s) 2.0) 0.25))) 0.5))