Rust f32::acosh

Percentage Accurate: 54.2% → 99.5%
Time: 2.9s
Alternatives: 10
Speedup: 1.7×

Specification

?
\[x \geq 1\]
\[\begin{array}{l} \\ \log \left(x + \sqrt{x \cdot x - 1}\right) \end{array} \]
(FPCore (x) :precision binary32 (log (+ x (sqrt (- (* x x) 1.0)))))
float code(float x) {
	return logf((x + sqrtf(((x * x) - 1.0f))));
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = log((x + sqrt(((x * x) - 1.0e0))))
end function
function code(x)
	return log(Float32(x + sqrt(Float32(Float32(x * x) - Float32(1.0)))))
end
function tmp = code(x)
	tmp = log((x + sqrt(((x * x) - single(1.0)))));
end
\begin{array}{l}

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

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 10 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: 54.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log \left(x + \sqrt{x \cdot x - 1}\right) \end{array} \]
(FPCore (x) :precision binary32 (log (+ x (sqrt (- (* x x) 1.0)))))
float code(float x) {
	return logf((x + sqrtf(((x * x) - 1.0f))));
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = log((x + sqrt(((x * x) - 1.0e0))))
end function
function code(x)
	return log(Float32(x + sqrt(Float32(Float32(x * x) - Float32(1.0)))))
end
function tmp = code(x)
	tmp = log((x + sqrt(((x * x) - single(1.0)))));
end
\begin{array}{l}

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

Alternative 1: 99.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 19999999961012896000:\\ \;\;\;\;\log \left(x + \sqrt{1 \cdot \mathsf{fma}\left(x, x, -1\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\log 2 + \log x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x 19999999961012896000.0)
   (log (+ x (sqrt (* 1.0 (fma x x -1.0)))))
   (+ (log 2.0) (log x))))
float code(float x) {
	float tmp;
	if (x <= 19999999961012896000.0f) {
		tmp = logf((x + sqrtf((1.0f * fmaf(x, x, -1.0f)))));
	} else {
		tmp = logf(2.0f) + logf(x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(19999999961012896000.0))
		tmp = log(Float32(x + sqrt(Float32(Float32(1.0) * fma(x, x, Float32(-1.0))))));
	else
		tmp = Float32(log(Float32(2.0)) + log(x));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 19999999961012896000:\\
\;\;\;\;\log \left(x + \sqrt{1 \cdot \mathsf{fma}\left(x, x, -1\right)}\right)\\

\mathbf{else}:\\
\;\;\;\;\log 2 + \log x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2e19

    1. Initial program 54.2%

      \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
    2. Applied rewrites54.2%

      \[\leadsto \log \left(x + \sqrt{\color{blue}{1 \cdot \mathsf{fma}\left(x, x, -1\right)}}\right) \]

    if 2e19 < x

    1. Initial program 54.2%

      \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
    3. Applied rewrites96.8%

      \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
    4. Taylor expanded in x around 0

      \[\leadsto \log 2 + \log x \]
    5. Applied rewrites96.8%

      \[\leadsto \log 2 + \log x \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 19999999961012896000:\\ \;\;\;\;\log \left(x + \sqrt{x \cdot x - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log 2 + \log x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x 19999999961012896000.0)
   (log (+ x (sqrt (- (* x x) 1.0))))
   (+ (log 2.0) (log x))))
float code(float x) {
	float tmp;
	if (x <= 19999999961012896000.0f) {
		tmp = logf((x + sqrtf(((x * x) - 1.0f))));
	} else {
		tmp = logf(2.0f) + logf(x);
	}
	return tmp;
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    real(4) :: tmp
    if (x <= 19999999961012896000.0e0) then
        tmp = log((x + sqrt(((x * x) - 1.0e0))))
    else
        tmp = log(2.0e0) + log(x)
    end if
    code = tmp
end function
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(19999999961012896000.0))
		tmp = log(Float32(x + sqrt(Float32(Float32(x * x) - Float32(1.0)))));
	else
		tmp = Float32(log(Float32(2.0)) + log(x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = single(0.0);
	if (x <= single(19999999961012896000.0))
		tmp = log((x + sqrt(((x * x) - single(1.0)))));
	else
		tmp = log(single(2.0)) + log(x);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 19999999961012896000:\\
\;\;\;\;\log \left(x + \sqrt{x \cdot x - 1}\right)\\

\mathbf{else}:\\
\;\;\;\;\log 2 + \log x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2e19

    1. Initial program 54.2%

      \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]

    if 2e19 < x

    1. Initial program 54.2%

      \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
    3. Applied rewrites96.8%

      \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
    4. Taylor expanded in x around 0

      \[\leadsto \log 2 + \log x \]
    5. Applied rewrites96.8%

      \[\leadsto \log 2 + \log x \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 99.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \log \left(x + \sqrt{x - 1} \cdot \sqrt{x \cdot \left(1 + \frac{1}{x}\right)}\right) \end{array} \]
(FPCore (x)
 :precision binary32
 (log (+ x (* (sqrt (- x 1.0)) (sqrt (* x (+ 1.0 (/ 1.0 x))))))))
float code(float x) {
	return logf((x + (sqrtf((x - 1.0f)) * sqrtf((x * (1.0f + (1.0f / x)))))));
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = log((x + (sqrt((x - 1.0e0)) * sqrt((x * (1.0e0 + (1.0e0 / x)))))))
end function
function code(x)
	return log(Float32(x + Float32(sqrt(Float32(x - Float32(1.0))) * sqrt(Float32(x * Float32(Float32(1.0) + Float32(Float32(1.0) / x)))))))
end
function tmp = code(x)
	tmp = log((x + (sqrt((x - single(1.0))) * sqrt((x * (single(1.0) + (single(1.0) / x)))))));
end
\begin{array}{l}

\\
\log \left(x + \sqrt{x - 1} \cdot \sqrt{x \cdot \left(1 + \frac{1}{x}\right)}\right)
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Applied rewrites99.3%

    \[\leadsto \log \left(x + \color{blue}{\sqrt{x - 1} \cdot \sqrt{x + 1}}\right) \]
  3. Taylor expanded in x around inf

    \[\leadsto \log \left(x + \sqrt{x - 1} \cdot \sqrt{\color{blue}{x \cdot \left(1 + \frac{1}{x}\right)}}\right) \]
  4. Applied rewrites99.3%

    \[\leadsto \log \left(x + \sqrt{x - 1} \cdot \sqrt{\color{blue}{x \cdot \left(1 + \frac{1}{x}\right)}}\right) \]
  5. Add Preprocessing

Alternative 4: 99.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right) \end{array} \]
(FPCore (x)
 :precision binary32
 (log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0))))))
float code(float x) {
	return logf((x + (sqrtf((x - 1.0f)) * sqrtf((x + 1.0f)))));
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = log((x + (sqrt((x - 1.0e0)) * sqrt((x + 1.0e0)))))
end function
function code(x)
	return log(Float32(x + Float32(sqrt(Float32(x - Float32(1.0))) * sqrt(Float32(x + Float32(1.0))))))
end
function tmp = code(x)
	tmp = log((x + (sqrt((x - single(1.0))) * sqrt((x + single(1.0))))));
end
\begin{array}{l}

\\
\log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right)
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Applied rewrites99.3%

    \[\leadsto \log \left(x + \color{blue}{\sqrt{x - 1} \cdot \sqrt{x + 1}}\right) \]
  3. Add Preprocessing

Alternative 5: 97.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \log 2 + \log x \end{array} \]
(FPCore (x) :precision binary32 (+ (log 2.0) (log x)))
float code(float x) {
	return logf(2.0f) + logf(x);
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = log(2.0e0) + log(x)
end function
function code(x)
	return Float32(log(Float32(2.0)) + log(x))
end
function tmp = code(x)
	tmp = log(single(2.0)) + log(x);
end
\begin{array}{l}

\\
\log 2 + \log x
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Taylor expanded in x around inf

    \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
  3. Applied rewrites96.8%

    \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto \log 2 + \log x \]
  5. Applied rewrites96.8%

    \[\leadsto \log 2 + \log x \]
  6. Add Preprocessing

Alternative 6: 96.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \log \left(2 \cdot x\right) \end{array} \]
(FPCore (x) :precision binary32 (log (* 2.0 x)))
float code(float x) {
	return logf((2.0f * x));
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = log((2.0e0 * x))
end function
function code(x)
	return log(Float32(Float32(2.0) * x))
end
function tmp = code(x)
	tmp = log((single(2.0) * x));
end
\begin{array}{l}

\\
\log \left(2 \cdot x\right)
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Taylor expanded in x around inf

    \[\leadsto \log \color{blue}{\left(2 \cdot x\right)} \]
  3. Applied rewrites97.1%

    \[\leadsto \log \color{blue}{\left(2 \cdot x\right)} \]
  4. Add Preprocessing

Alternative 7: 23.6% accurate, 4.8× speedup?

\[\begin{array}{l} \\ 2 + 2 \end{array} \]
(FPCore (x) :precision binary32 (+ 2.0 2.0))
float code(float x) {
	return 2.0f + 2.0f;
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = 2.0e0 + 2.0e0
end function
function code(x)
	return Float32(Float32(2.0) + Float32(2.0))
end
function tmp = code(x)
	tmp = single(2.0) + single(2.0);
end
\begin{array}{l}

\\
2 + 2
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Taylor expanded in x around inf

    \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
  3. Applied rewrites96.8%

    \[\leadsto \color{blue}{\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto \log 2 + \log x \]
  5. Applied rewrites96.8%

    \[\leadsto \log 2 + \log x \]
  6. Applied rewrites21.5%

    \[\leadsto \log 2 + \log 2 \]
  7. Applied rewrites23.6%

    \[\leadsto 2 + \color{blue}{2} \]
  8. Add Preprocessing

Alternative 8: 22.2% accurate, 17.0× speedup?

\[\begin{array}{l} \\ 2 \end{array} \]
(FPCore (x) :precision binary32 2.0)
float code(float x) {
	return 2.0f;
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = 2.0e0
end function
function code(x)
	return Float32(2.0)
end
function tmp = code(x)
	tmp = single(2.0);
end
\begin{array}{l}

\\
2
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Applied rewrites99.3%

    \[\leadsto \log \left(x + \color{blue}{\sqrt{x - 1} \cdot \sqrt{x + 1}}\right) \]
  3. Applied rewrites22.2%

    \[\leadsto \color{blue}{2} \]
  4. Add Preprocessing

Alternative 9: 21.1% accurate, 17.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (x) :precision binary32 1.0)
float code(float x) {
	return 1.0f;
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = 1.0e0
end function
function code(x)
	return Float32(1.0)
end
function tmp = code(x)
	tmp = single(1.0);
end
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Applied rewrites99.3%

    \[\leadsto \log \left(x + \color{blue}{\sqrt{x - 1} \cdot \sqrt{x + 1}}\right) \]
  3. Applied rewrites21.1%

    \[\leadsto \color{blue}{1} \]
  4. Add Preprocessing

Alternative 10: 20.2% accurate, 17.0× speedup?

\[\begin{array}{l} \\ 0.5 \end{array} \]
(FPCore (x) :precision binary32 0.5)
float code(float x) {
	return 0.5f;
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = 0.5e0
end function
function code(x)
	return Float32(0.5)
end
function tmp = code(x)
	tmp = single(0.5);
end
\begin{array}{l}

\\
0.5
\end{array}
Derivation
  1. Initial program 54.2%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Applied rewrites99.3%

    \[\leadsto \log \left(x + \color{blue}{\sqrt{x - 1} \cdot \sqrt{x + 1}}\right) \]
  3. Applied rewrites20.2%

    \[\leadsto \color{blue}{0.5} \]
  4. Add Preprocessing

Developer Target 1: 99.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right) \end{array} \]
(FPCore (x)
 :precision binary32
 (log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0))))))
float code(float x) {
	return logf((x + (sqrtf((x - 1.0f)) * sqrtf((x + 1.0f)))));
}
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(4) function code(x)
use fmin_fmax_functions
    real(4), intent (in) :: x
    code = log((x + (sqrt((x - 1.0e0)) * sqrt((x + 1.0e0)))))
end function
function code(x)
	return log(Float32(x + Float32(sqrt(Float32(x - Float32(1.0))) * sqrt(Float32(x + Float32(1.0))))))
end
function tmp = code(x)
	tmp = log((x + (sqrt((x - single(1.0))) * sqrt((x + single(1.0))))));
end
\begin{array}{l}

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

Reproduce

?
herbie shell --seed 2025159 
(FPCore (x)
  :name "Rust f32::acosh"
  :precision binary32
  :pre (>= x 1.0)

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

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