(FPCore (x y) :precision binary64 (log (sqrt (+ (* x x) (* y y)))))
double code(double x, double y) { return log(sqrt(((x * x) + (y * y)))); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = log(sqrt(((x * x) + (y * y)))) end function
public static double code(double x, double y) { return Math.log(Math.sqrt(((x * x) + (y * y)))); }
def code(x, y): return math.log(math.sqrt(((x * x) + (y * y))))
function code(x, y) return log(sqrt(Float64(Float64(x * x) + Float64(y * y)))) end
function tmp = code(x, y) tmp = log(sqrt(((x * x) + (y * y)))); end
code[x_, y_] := N[Log[N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \log \left(\sqrt{x \cdot x + y \cdot y}\right) \end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x y) :precision binary64 (log (sqrt (+ (* x x) (* y y)))))
double code(double x, double y) { return log(sqrt(((x * x) + (y * y)))); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = log(sqrt(((x * x) + (y * y)))) end function
public static double code(double x, double y) { return Math.log(Math.sqrt(((x * x) + (y * y)))); }
def code(x, y): return math.log(math.sqrt(((x * x) + (y * y))))
function code(x, y) return log(sqrt(Float64(Float64(x * x) + Float64(y * y)))) end
function tmp = code(x, y) tmp = log(sqrt(((x * x) + (y * y)))); end
code[x_, y_] := N[Log[N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \log \left(\sqrt{x \cdot x + y \cdot y}\right) \end{array}
(FPCore (x y) :precision binary64 (log (hypot y x)))
double code(double x, double y) { return log(hypot(y, x)); }
public static double code(double x, double y) { return Math.log(Math.hypot(y, x)); }
def code(x, y): return math.log(math.hypot(y, x))
function code(x, y) return log(hypot(y, x)) end
function tmp = code(x, y) tmp = log(hypot(y, x)); end
code[x_, y_] := N[Log[N[Sqrt[y ^ 2 + x ^ 2], $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \log \left(\mathsf{hypot}\left(y, x\right)\right) \end{array}
Initial program 81.6%
lift-sqrt.f64
N/A
lift-+.f64
N/A
+-commutative
N/A
lift-*.f64
N/A
lift-*.f64
N/A
lower-hypot.f64
100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (* (fma (/ (/ x y) y) x (* (log y) 2.0)) 0.5))
double code(double x, double y) { return fma(((x / y) / y), x, (log(y) * 2.0)) * 0.5; }
function code(x, y) return Float64(fma(Float64(Float64(x / y) / y), x, Float64(log(y) * 2.0)) * 0.5) end
code[x_, y_] := N[(N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] * x + N[(N[Log[y], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\frac{\frac{x}{y}}{y}, x, \log y \cdot 2\right) \cdot 0.5 \end{array}
Initial program 81.6%
lift-log.f64
N/A
lift-sqrt.f64
N/A
pow1/2
N/A
pow-to-exp
N/A
rem-log-exp
N/A
lower-*.f64
N/A
lower-log.f64
81.6
lift-+.f64
N/A
+-commutative
N/A
lift-*.f64
N/A
lower-fma.f64
81.6
Applied rewrites81.6%
Taylor expanded in y around inf
+-commutative
N/A
unpow2
N/A
associate-/l*
N/A
*-commutative
N/A
lower-fma.f64
N/A
unpow2
N/A
associate-/r*
N/A
lower-/.f64
N/A
lower-/.f64
N/A
remove-double-neg
N/A
*-commutative
N/A
distribute-lft-neg-out
N/A
mul-1-neg
N/A
distribute-rgt-neg-in
N/A
metadata-eval
N/A
lower-*.f64
N/A
mul-1-neg
N/A
log-rec
N/A
remove-double-neg
N/A
lower-log.f64
21.9
Applied rewrites21.9%
(FPCore (x y) :precision binary64 (log y))
double code(double x, double y) { return log(y); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = log(y) end function
public static double code(double x, double y) { return Math.log(y); }
def code(x, y): return math.log(y)
function code(x, y) return log(y) end
function tmp = code(x, y) tmp = log(y); end
code[x_, y_] := N[Log[y], $MachinePrecision]
\begin{array}{l} \\ \log y \end{array}
Initial program 81.6%
Taylor expanded in x around 0
lower-log.f64
27.0
Applied rewrites27.0%
herbie shell --seed 1
(FPCore (x y)
:name "log(sqrt(x*x+y*y))"
:precision binary64
:pre (and (and (<= -1.0 x) (<= x 1.0)) (and (<= -1.0 y) (<= y 1.0)))
(log (sqrt (+ (* x x) (* y y)))))