(FPCore (x) :precision binary64 (pow x 2.0))
double code(double x) { return pow(x, 2.0); }
real(8) function code(x) real(8), intent (in) :: x code = x ** 2.0d0 end function
public static double code(double x) { return Math.pow(x, 2.0); }
def code(x): return math.pow(x, 2.0)
function code(x) return x ^ 2.0 end
function tmp = code(x) tmp = x ^ 2.0; end
code[x_] := N[Power[x, 2.0], $MachinePrecision]
\begin{array}{l} \\ {x}^{2} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (pow x 2.0))
double code(double x) { return pow(x, 2.0); }
real(8) function code(x) real(8), intent (in) :: x code = x ** 2.0d0 end function
public static double code(double x) { return Math.pow(x, 2.0); }
def code(x): return math.pow(x, 2.0)
function code(x) return x ^ 2.0 end
function tmp = code(x) tmp = x ^ 2.0; end
code[x_] := N[Power[x, 2.0], $MachinePrecision]
\begin{array}{l} \\ {x}^{2} \end{array}
(FPCore (x) :precision binary64 (* x x))
double code(double x) { return x * x; }
real(8) function code(x) real(8), intent (in) :: x code = x * x end function
public static double code(double x) { return x * x; }
def code(x): return x * x
function code(x) return Float64(x * x) end
function tmp = code(x) tmp = x * x; end
code[x_] := N[(x * x), $MachinePrecision]
\begin{array}{l} \\ x \cdot x \end{array}
Initial program 100.0%
Taylor expanded in x around 0
unpow2
N/A
lower-*.f64
100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 x)
double code(double x) { return x; }
real(8) function code(x) real(8), intent (in) :: x code = x end function
public static double code(double x) { return x; }
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l} \\ x \end{array}
Initial program 100.0%
lift-pow.f64
N/A
pow-to-exp
N/A
*-commutative
N/A
count-2
N/A
flip-+
N/A
+-inverses
N/A
+-inverses
N/A
+-inverses
N/A
+-inverses
N/A
flip-+
N/A
log-prod
N/A
sqr-pow
N/A
metadata-eval
N/A
unpow1
N/A
rem-exp-log
7.2
Applied rewrites7.2%
herbie shell --seed 1
(FPCore (x)
:name "pow(x, 2)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 1.79e+308))
(pow x 2.0))