Rust f64::acosh

Percentage Accurate: 51.2% → 99.7%
Time: 2.2s
Alternatives: 1
Speedup: 1.2×

Specification

?
\[x \geq 1\]
\[\begin{array}{l} \\ \cosh^{-1} x \end{array} \]
(FPCore (x) :precision binary64 (acosh x))
double code(double x) {
	return acosh(x);
}
def code(x):
	return math.acosh(x)
function code(x)
	return acosh(x)
end
function tmp = code(x)
	tmp = acosh(x);
end
code[x_] := N[ArcCosh[x], $MachinePrecision]
\begin{array}{l}

\\
\cosh^{-1} x
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 1 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 51.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log \left(x + \sqrt{x \cdot x - 1}\right) \end{array} \]
(FPCore (x) :precision binary64 (log (+ x (sqrt (- (* x x) 1.0)))))
double code(double x) {
	return log((x + sqrt(((x * x) - 1.0))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = log((x + sqrt(((x * x) - 1.0d0))))
end function
public static double code(double x) {
	return Math.log((x + Math.sqrt(((x * x) - 1.0))));
}
def code(x):
	return math.log((x + math.sqrt(((x * x) - 1.0))))
function code(x)
	return log(Float64(x + sqrt(Float64(Float64(x * x) - 1.0))))
end
function tmp = code(x)
	tmp = log((x + sqrt(((x * x) - 1.0))));
end
code[x_] := N[Log[N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(x + \sqrt{x \cdot x - 1}\right)
\end{array}

Alternative 1: 99.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \cosh^{-1} x \end{array} \]
(FPCore (x) :precision binary64 (acosh x))
double code(double x) {
	return acosh(x);
}
def code(x):
	return math.acosh(x)
function code(x)
	return acosh(x)
end
function tmp = code(x)
	tmp = acosh(x);
end
code[x_] := N[ArcCosh[x], $MachinePrecision]
\begin{array}{l}

\\
\cosh^{-1} x
\end{array}
Derivation
  1. Initial program 49.3%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(x + \sqrt{x \cdot x - 1}\right)} \]
    2. lift-+.f64N/A

      \[\leadsto \log \color{blue}{\left(x + \sqrt{x \cdot x - 1}\right)} \]
    3. lift-sqrt.f64N/A

      \[\leadsto \log \left(x + \color{blue}{\sqrt{x \cdot x - 1}}\right) \]
    4. lift--.f64N/A

      \[\leadsto \log \left(x + \sqrt{\color{blue}{x \cdot x - 1}}\right) \]
    5. lift-*.f64N/A

      \[\leadsto \log \left(x + \sqrt{\color{blue}{x \cdot x} - 1}\right) \]
    6. acosh-def-revN/A

      \[\leadsto \color{blue}{\cosh^{-1} x} \]
    7. lower-acosh.f6499.6

      \[\leadsto \color{blue}{\cosh^{-1} x} \]
  4. Applied rewrites99.6%

    \[\leadsto \color{blue}{\cosh^{-1} x} \]
  5. Add Preprocessing

Developer Target 1: 99.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0))))))
double code(double x) {
	return log((x + (sqrt((x - 1.0)) * sqrt((x + 1.0)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = log((x + (sqrt((x - 1.0d0)) * sqrt((x + 1.0d0)))))
end function
public static double code(double x) {
	return Math.log((x + (Math.sqrt((x - 1.0)) * Math.sqrt((x + 1.0)))));
}
def code(x):
	return math.log((x + (math.sqrt((x - 1.0)) * math.sqrt((x + 1.0)))))
function code(x)
	return log(Float64(x + Float64(sqrt(Float64(x - 1.0)) * sqrt(Float64(x + 1.0)))))
end
function tmp = code(x)
	tmp = log((x + (sqrt((x - 1.0)) * sqrt((x + 1.0)))));
end
code[x_] := N[Log[N[(x + N[(N[Sqrt[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right)
\end{array}

Reproduce

?
herbie shell --seed 2025046 
(FPCore (x)
  :name "Rust f64::acosh"
  :precision binary64
  :pre (>= x 1.0)

  :alt
  (! :herbie-platform default (log (+ x (* (sqrt (- x 1)) (sqrt (+ x 1))))))

  (log (+ x (sqrt (- (* x x) 1.0)))))