Rust f32::acosh

Percentage Accurate: 52.7% → 97.9%
Time: 8.6s
Alternatives: 8
Speedup: 2.0×

Specification

?
\[x \geq 1\]
\[\begin{array}{l} \\ \cosh^{-1} x \end{array} \]
(FPCore (x) :precision binary32 (acosh x))
float code(float x) {
	return acoshf(x);
}
function code(x)
	return acosh(x)
end
function tmp = code(x)
	tmp = acosh(x);
end
\begin{array}{l}

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

Sampling outcomes in binary32 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 8 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: 52.7% 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))));
}
real(4) function code(x)
    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: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log 2 + \left(\log x - \frac{0.25}{x \cdot x}\right) \end{array} \]
(FPCore (x) :precision binary32 (+ (log 2.0) (- (log x) (/ 0.25 (* x x)))))
float code(float x) {
	return logf(2.0f) + (logf(x) - (0.25f / (x * x)));
}
real(4) function code(x)
    real(4), intent (in) :: x
    code = log(2.0e0) + (log(x) - (0.25e0 / (x * x)))
end function
function code(x)
	return Float32(log(Float32(2.0)) + Float32(log(x) - Float32(Float32(0.25) / Float32(x * x))))
end
function tmp = code(x)
	tmp = log(single(2.0)) + (log(x) - (single(0.25) / (x * x)));
end
\begin{array}{l}

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

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

    \[\leadsto \color{blue}{\left(\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)\right) - 0.25 \cdot \frac{1}{{x}^{2}}} \]
  3. Step-by-step derivation
    1. associate--l+97.5%

      \[\leadsto \color{blue}{\log 2 + \left(-1 \cdot \log \left(\frac{1}{x}\right) - 0.25 \cdot \frac{1}{{x}^{2}}\right)} \]
    2. mul-1-neg97.5%

      \[\leadsto \log 2 + \left(\color{blue}{\left(-\log \left(\frac{1}{x}\right)\right)} - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    3. log-rec97.5%

      \[\leadsto \log 2 + \left(\left(-\color{blue}{\left(-\log x\right)}\right) - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    4. remove-double-neg97.5%

      \[\leadsto \log 2 + \left(\color{blue}{\log x} - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    5. unpow297.5%

      \[\leadsto \log 2 + \left(\log x - 0.25 \cdot \frac{1}{\color{blue}{x \cdot x}}\right) \]
    6. associate-*r/97.5%

      \[\leadsto \log 2 + \left(\log x - \color{blue}{\frac{0.25 \cdot 1}{x \cdot x}}\right) \]
    7. metadata-eval97.5%

      \[\leadsto \log 2 + \left(\log x - \frac{\color{blue}{0.25}}{x \cdot x}\right) \]
  4. Simplified97.5%

    \[\leadsto \color{blue}{\log 2 + \left(\log x - \frac{0.25}{x \cdot x}\right)} \]
  5. Final simplification97.5%

    \[\leadsto \log 2 + \left(\log x - \frac{0.25}{x \cdot x}\right) \]

Alternative 2: 98.4% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \mathsf{log1p}\left(\left(2 \cdot x - \left(\frac{0.5}{x} + \frac{0.25}{x \cdot x} \cdot \frac{0.5}{x}\right)\right) + -1\right) \end{array} \]
(FPCore (x)
 :precision binary32
 (log1p (+ (- (* 2.0 x) (+ (/ 0.5 x) (* (/ 0.25 (* x x)) (/ 0.5 x)))) -1.0)))
float code(float x) {
	return log1pf((((2.0f * x) - ((0.5f / x) + ((0.25f / (x * x)) * (0.5f / x)))) + -1.0f));
}
function code(x)
	return log1p(Float32(Float32(Float32(Float32(2.0) * x) - Float32(Float32(Float32(0.5) / x) + Float32(Float32(Float32(0.25) / Float32(x * x)) * Float32(Float32(0.5) / x)))) + Float32(-1.0)))
end
\begin{array}{l}

\\
\mathsf{log1p}\left(\left(2 \cdot x - \left(\frac{0.5}{x} + \frac{0.25}{x \cdot x} \cdot \frac{0.5}{x}\right)\right) + -1\right)
\end{array}
Derivation
  1. Initial program 47.0%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Step-by-step derivation
    1. log1p-expm1-u47.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(x + \sqrt{x \cdot x - 1}\right)\right)\right)} \]
    2. expm1-udef47.0%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{e^{\log \left(x + \sqrt{x \cdot x - 1}\right)} - 1}\right) \]
    3. add-exp-log47.0%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{\left(x + \sqrt{x \cdot x - 1}\right)} - 1\right) \]
    4. fma-neg47.0%

      \[\leadsto \mathsf{log1p}\left(\left(x + \sqrt{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}}\right) - 1\right) \]
    5. metadata-eval47.0%

      \[\leadsto \mathsf{log1p}\left(\left(x + \sqrt{\mathsf{fma}\left(x, x, \color{blue}{-1}\right)}\right) - 1\right) \]
  3. Applied egg-rr47.0%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\left(x + \sqrt{\mathsf{fma}\left(x, x, -1\right)}\right) - 1\right)} \]
  4. Taylor expanded in x around inf 97.4%

    \[\leadsto \mathsf{log1p}\left(\color{blue}{\left(2 \cdot x - \left(0.125 \cdot \frac{1}{{x}^{3}} + 0.5 \cdot \frac{1}{x}\right)\right)} - 1\right) \]
  5. Step-by-step derivation
    1. *-commutative97.4%

      \[\leadsto \mathsf{log1p}\left(\left(\color{blue}{x \cdot 2} - \left(0.125 \cdot \frac{1}{{x}^{3}} + 0.5 \cdot \frac{1}{x}\right)\right) - 1\right) \]
    2. +-commutative97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \color{blue}{\left(0.5 \cdot \frac{1}{x} + 0.125 \cdot \frac{1}{{x}^{3}}\right)}\right) - 1\right) \]
    3. associate-*r/97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\color{blue}{\frac{0.5 \cdot 1}{x}} + 0.125 \cdot \frac{1}{{x}^{3}}\right)\right) - 1\right) \]
    4. metadata-eval97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{\color{blue}{0.5}}{x} + 0.125 \cdot \frac{1}{{x}^{3}}\right)\right) - 1\right) \]
    5. associate-*r/97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \color{blue}{\frac{0.125 \cdot 1}{{x}^{3}}}\right)\right) - 1\right) \]
    6. metadata-eval97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \frac{\color{blue}{0.125}}{{x}^{3}}\right)\right) - 1\right) \]
  6. Simplified97.4%

    \[\leadsto \mathsf{log1p}\left(\color{blue}{\left(x \cdot 2 - \left(\frac{0.5}{x} + \frac{0.125}{{x}^{3}}\right)\right)} - 1\right) \]
  7. Step-by-step derivation
    1. metadata-eval97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \frac{\color{blue}{{0.5}^{3}}}{{x}^{3}}\right)\right) - 1\right) \]
    2. cube-div97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \color{blue}{{\left(\frac{0.5}{x}\right)}^{3}}\right)\right) - 1\right) \]
    3. cube-mult97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \color{blue}{\frac{0.5}{x} \cdot \left(\frac{0.5}{x} \cdot \frac{0.5}{x}\right)}\right)\right) - 1\right) \]
    4. frac-times97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \frac{0.5}{x} \cdot \color{blue}{\frac{0.5 \cdot 0.5}{x \cdot x}}\right)\right) - 1\right) \]
    5. metadata-eval97.4%

      \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \frac{0.5}{x} \cdot \frac{\color{blue}{0.25}}{x \cdot x}\right)\right) - 1\right) \]
  8. Applied egg-rr97.4%

    \[\leadsto \mathsf{log1p}\left(\left(x \cdot 2 - \left(\frac{0.5}{x} + \color{blue}{\frac{0.5}{x} \cdot \frac{0.25}{x \cdot x}}\right)\right) - 1\right) \]
  9. Final simplification97.4%

    \[\leadsto \mathsf{log1p}\left(\left(2 \cdot x - \left(\frac{0.5}{x} + \frac{0.25}{x \cdot x} \cdot \frac{0.5}{x}\right)\right) + -1\right) \]

Alternative 3: 98.0% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \log \left(x + \left(x - \frac{0.5}{x}\right)\right) \end{array} \]
(FPCore (x) :precision binary32 (log (+ x (- x (/ 0.5 x)))))
float code(float x) {
	return logf((x + (x - (0.5f / x))));
}
real(4) function code(x)
    real(4), intent (in) :: x
    code = log((x + (x - (0.5e0 / x))))
end function
function code(x)
	return log(Float32(x + Float32(x - Float32(Float32(0.5) / x))))
end
function tmp = code(x)
	tmp = log((x + (x - (single(0.5) / x))));
end
\begin{array}{l}

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

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

    \[\leadsto \log \left(x + \color{blue}{\left(x - 0.5 \cdot \frac{1}{x}\right)}\right) \]
  3. Step-by-step derivation
    1. associate-*r/97.0%

      \[\leadsto \log \left(x + \left(x - \color{blue}{\frac{0.5 \cdot 1}{x}}\right)\right) \]
    2. metadata-eval97.0%

      \[\leadsto \log \left(x + \left(x - \frac{\color{blue}{0.5}}{x}\right)\right) \]
  4. Simplified97.0%

    \[\leadsto \log \left(x + \color{blue}{\left(x - \frac{0.5}{x}\right)}\right) \]
  5. Final simplification97.0%

    \[\leadsto \log \left(x + \left(x - \frac{0.5}{x}\right)\right) \]

Alternative 4: 96.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \log \left(x + x\right) \end{array} \]
(FPCore (x) :precision binary32 (log (+ x x)))
float code(float x) {
	return logf((x + x));
}
real(4) function code(x)
    real(4), intent (in) :: x
    code = log((x + x))
end function
function code(x)
	return log(Float32(x + x))
end
function tmp = code(x)
	tmp = log((x + x));
end
\begin{array}{l}

\\
\log \left(x + x\right)
\end{array}
Derivation
  1. Initial program 47.0%

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

    \[\leadsto \log \left(x + \color{blue}{x}\right) \]
  3. Final simplification95.6%

    \[\leadsto \log \left(x + x\right) \]

Alternative 5: 20.5% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \log 2 \end{array} \]
(FPCore (x) :precision binary32 (log 2.0))
float code(float x) {
	return logf(2.0f);
}
real(4) function code(x)
    real(4), intent (in) :: x
    code = log(2.0e0)
end function
function code(x)
	return log(Float32(2.0))
end
function tmp = code(x)
	tmp = log(single(2.0));
end
\begin{array}{l}

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

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

    \[\leadsto \color{blue}{\left(\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)\right) - 0.25 \cdot \frac{1}{{x}^{2}}} \]
  3. Step-by-step derivation
    1. associate--l+97.5%

      \[\leadsto \color{blue}{\log 2 + \left(-1 \cdot \log \left(\frac{1}{x}\right) - 0.25 \cdot \frac{1}{{x}^{2}}\right)} \]
    2. mul-1-neg97.5%

      \[\leadsto \log 2 + \left(\color{blue}{\left(-\log \left(\frac{1}{x}\right)\right)} - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    3. log-rec97.5%

      \[\leadsto \log 2 + \left(\left(-\color{blue}{\left(-\log x\right)}\right) - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    4. remove-double-neg97.5%

      \[\leadsto \log 2 + \left(\color{blue}{\log x} - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    5. unpow297.5%

      \[\leadsto \log 2 + \left(\log x - 0.25 \cdot \frac{1}{\color{blue}{x \cdot x}}\right) \]
    6. associate-*r/97.5%

      \[\leadsto \log 2 + \left(\log x - \color{blue}{\frac{0.25 \cdot 1}{x \cdot x}}\right) \]
    7. metadata-eval97.5%

      \[\leadsto \log 2 + \left(\log x - \frac{\color{blue}{0.25}}{x \cdot x}\right) \]
  4. Simplified97.5%

    \[\leadsto \color{blue}{\log 2 + \left(\log x - \frac{0.25}{x \cdot x}\right)} \]
  5. Step-by-step derivation
    1. expm1-log1p-u95.7%

      \[\leadsto \log 2 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log x - \frac{0.25}{x \cdot x}\right)\right)} \]
    2. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x - \frac{\color{blue}{0.5 \cdot 0.5}}{x \cdot x}\right)\right) \]
    3. frac-times95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x - \color{blue}{\frac{0.5}{x} \cdot \frac{0.5}{x}}\right)\right) \]
    4. cancel-sign-sub-inv95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\log x + \left(-\frac{0.5}{x}\right) \cdot \frac{0.5}{x}}\right)\right) \]
    5. distribute-lft-neg-in95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \color{blue}{\left(-\frac{0.5}{x} \cdot \frac{0.5}{x}\right)}\right)\right) \]
    6. frac-times95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{0.5 \cdot 0.5}{x \cdot x}}\right)\right)\right) \]
    7. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{\color{blue}{0.25}}{x \cdot x}\right)\right)\right) \]
    8. associate-/r*95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{\frac{0.25}{x}}{x}}\right)\right)\right) \]
    9. associate-/r*95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{0.25}{x \cdot x}}\right)\right)\right) \]
    10. clear-num95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{1}{\frac{x \cdot x}{0.25}}}\right)\right)\right) \]
    11. div-inv95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{0.25}}}\right)\right)\right) \]
    12. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot x\right) \cdot \color{blue}{4}}\right)\right)\right) \]
    13. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot x\right) \cdot \color{blue}{\left(2 \cdot 2\right)}}\right)\right)\right) \]
    14. swap-sqr95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\color{blue}{\left(x \cdot 2\right) \cdot \left(x \cdot 2\right)}}\right)\right)\right) \]
    15. *-commutative95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \color{blue}{\left(2 \cdot x\right)}}\right)\right)\right) \]
    16. count-295.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \color{blue}{\left(x + x\right)}}\right)\right)\right) \]
    17. flip-+-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \color{blue}{\frac{x \cdot x - x \cdot x}{x - x}}}\right)\right)\right) \]
    18. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \frac{x \cdot x - x \cdot x}{\color{blue}{0}}}\right)\right)\right) \]
    19. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \frac{x \cdot x - x \cdot x}{\color{blue}{x \cdot x - x \cdot x}}}\right)\right)\right) \]
    20. associate-*r/-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\color{blue}{\frac{\left(x \cdot 2\right) \cdot \left(x \cdot x - x \cdot x\right)}{x \cdot x - x \cdot x}}}\right)\right)\right) \]
    21. *-commutative-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\color{blue}{\left(2 \cdot x\right)} \cdot \left(x \cdot x - x \cdot x\right)}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    22. count-2-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\color{blue}{\left(x + x\right)} \cdot \left(x \cdot x - x \cdot x\right)}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    23. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\left(x + x\right) \cdot \color{blue}{0}}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    24. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\left(x + x\right) \cdot \color{blue}{\left(x - x\right)}}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    25. difference-of-squares-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\color{blue}{x \cdot x - x \cdot x}}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    26. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{x \cdot x - x \cdot x}{\color{blue}{0}}}\right)\right)\right) \]
    27. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{x \cdot x - x \cdot x}{\color{blue}{x - x}}}\right)\right)\right) \]
  6. Applied egg-rr91.7%

    \[\leadsto \log 2 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \frac{-0.5}{x}\right)\right)} \]
  7. Taylor expanded in x around 0 20.5%

    \[\leadsto \log 2 + \color{blue}{\frac{-0.5}{x}} \]
  8. Taylor expanded in x around inf 20.6%

    \[\leadsto \color{blue}{\log 2} \]
  9. Final simplification20.6%

    \[\leadsto \log 2 \]

Alternative 6: 5.3% accurate, 41.4× speedup?

\[\begin{array}{l} \\ \frac{-0.25}{x \cdot x} \end{array} \]
(FPCore (x) :precision binary32 (/ -0.25 (* x x)))
float code(float x) {
	return -0.25f / (x * x);
}
real(4) function code(x)
    real(4), intent (in) :: x
    code = (-0.25e0) / (x * x)
end function
function code(x)
	return Float32(Float32(-0.25) / Float32(x * x))
end
function tmp = code(x)
	tmp = single(-0.25) / (x * x);
end
\begin{array}{l}

\\
\frac{-0.25}{x \cdot x}
\end{array}
Derivation
  1. Initial program 47.0%

    \[\log \left(x + \sqrt{x \cdot x - 1}\right) \]
  2. Step-by-step derivation
    1. log1p-expm1-u47.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(x + \sqrt{x \cdot x - 1}\right)\right)\right)} \]
    2. expm1-udef47.0%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{e^{\log \left(x + \sqrt{x \cdot x - 1}\right)} - 1}\right) \]
    3. add-exp-log47.0%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{\left(x + \sqrt{x \cdot x - 1}\right)} - 1\right) \]
    4. fma-neg47.0%

      \[\leadsto \mathsf{log1p}\left(\left(x + \sqrt{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}}\right) - 1\right) \]
    5. metadata-eval47.0%

      \[\leadsto \mathsf{log1p}\left(\left(x + \sqrt{\mathsf{fma}\left(x, x, \color{blue}{-1}\right)}\right) - 1\right) \]
  3. Applied egg-rr47.0%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\left(x + \sqrt{\mathsf{fma}\left(x, x, -1\right)}\right) - 1\right)} \]
  4. Taylor expanded in x around inf 97.5%

    \[\leadsto \color{blue}{\left(\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)\right) - 0.25 \cdot \frac{1}{{x}^{2}}} \]
  5. Step-by-step derivation
    1. +-commutative97.5%

      \[\leadsto \color{blue}{\left(-1 \cdot \log \left(\frac{1}{x}\right) + \log 2\right)} - 0.25 \cdot \frac{1}{{x}^{2}} \]
    2. mul-1-neg97.5%

      \[\leadsto \left(\color{blue}{\left(-\log \left(\frac{1}{x}\right)\right)} + \log 2\right) - 0.25 \cdot \frac{1}{{x}^{2}} \]
    3. log-rec97.5%

      \[\leadsto \left(\left(-\color{blue}{\left(-\log x\right)}\right) + \log 2\right) - 0.25 \cdot \frac{1}{{x}^{2}} \]
    4. remove-double-neg97.5%

      \[\leadsto \left(\color{blue}{\log x} + \log 2\right) - 0.25 \cdot \frac{1}{{x}^{2}} \]
    5. log-prod96.9%

      \[\leadsto \color{blue}{\log \left(x \cdot 2\right)} - 0.25 \cdot \frac{1}{{x}^{2}} \]
    6. unpow296.9%

      \[\leadsto \log \left(x \cdot 2\right) - 0.25 \cdot \frac{1}{\color{blue}{x \cdot x}} \]
    7. associate-*r/96.9%

      \[\leadsto \log \left(x \cdot 2\right) - \color{blue}{\frac{0.25 \cdot 1}{x \cdot x}} \]
    8. metadata-eval96.9%

      \[\leadsto \log \left(x \cdot 2\right) - \frac{\color{blue}{0.25}}{x \cdot x} \]
    9. associate-/r*96.9%

      \[\leadsto \log \left(x \cdot 2\right) - \color{blue}{\frac{\frac{0.25}{x}}{x}} \]
  6. Simplified96.9%

    \[\leadsto \color{blue}{\log \left(x \cdot 2\right) - \frac{\frac{0.25}{x}}{x}} \]
  7. Taylor expanded in x around 0 5.4%

    \[\leadsto \color{blue}{\frac{-0.25}{{x}^{2}}} \]
  8. Step-by-step derivation
    1. unpow25.4%

      \[\leadsto \frac{-0.25}{\color{blue}{x \cdot x}} \]
  9. Simplified5.4%

    \[\leadsto \color{blue}{\frac{-0.25}{x \cdot x}} \]
  10. Final simplification5.4%

    \[\leadsto \frac{-0.25}{x \cdot x} \]

Alternative 7: 4.5% accurate, 69.0× speedup?

\[\begin{array}{l} \\ \frac{-0.5}{x} \end{array} \]
(FPCore (x) :precision binary32 (/ -0.5 x))
float code(float x) {
	return -0.5f / x;
}
real(4) function code(x)
    real(4), intent (in) :: x
    code = (-0.5e0) / x
end function
function code(x)
	return Float32(Float32(-0.5) / x)
end
function tmp = code(x)
	tmp = single(-0.5) / x;
end
\begin{array}{l}

\\
\frac{-0.5}{x}
\end{array}
Derivation
  1. Initial program 47.0%

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

    \[\leadsto \color{blue}{\left(\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)\right) - 0.25 \cdot \frac{1}{{x}^{2}}} \]
  3. Step-by-step derivation
    1. associate--l+97.5%

      \[\leadsto \color{blue}{\log 2 + \left(-1 \cdot \log \left(\frac{1}{x}\right) - 0.25 \cdot \frac{1}{{x}^{2}}\right)} \]
    2. mul-1-neg97.5%

      \[\leadsto \log 2 + \left(\color{blue}{\left(-\log \left(\frac{1}{x}\right)\right)} - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    3. log-rec97.5%

      \[\leadsto \log 2 + \left(\left(-\color{blue}{\left(-\log x\right)}\right) - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    4. remove-double-neg97.5%

      \[\leadsto \log 2 + \left(\color{blue}{\log x} - 0.25 \cdot \frac{1}{{x}^{2}}\right) \]
    5. unpow297.5%

      \[\leadsto \log 2 + \left(\log x - 0.25 \cdot \frac{1}{\color{blue}{x \cdot x}}\right) \]
    6. associate-*r/97.5%

      \[\leadsto \log 2 + \left(\log x - \color{blue}{\frac{0.25 \cdot 1}{x \cdot x}}\right) \]
    7. metadata-eval97.5%

      \[\leadsto \log 2 + \left(\log x - \frac{\color{blue}{0.25}}{x \cdot x}\right) \]
  4. Simplified97.5%

    \[\leadsto \color{blue}{\log 2 + \left(\log x - \frac{0.25}{x \cdot x}\right)} \]
  5. Step-by-step derivation
    1. expm1-log1p-u95.7%

      \[\leadsto \log 2 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log x - \frac{0.25}{x \cdot x}\right)\right)} \]
    2. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x - \frac{\color{blue}{0.5 \cdot 0.5}}{x \cdot x}\right)\right) \]
    3. frac-times95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x - \color{blue}{\frac{0.5}{x} \cdot \frac{0.5}{x}}\right)\right) \]
    4. cancel-sign-sub-inv95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\log x + \left(-\frac{0.5}{x}\right) \cdot \frac{0.5}{x}}\right)\right) \]
    5. distribute-lft-neg-in95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \color{blue}{\left(-\frac{0.5}{x} \cdot \frac{0.5}{x}\right)}\right)\right) \]
    6. frac-times95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{0.5 \cdot 0.5}{x \cdot x}}\right)\right)\right) \]
    7. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{\color{blue}{0.25}}{x \cdot x}\right)\right)\right) \]
    8. associate-/r*95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{\frac{0.25}{x}}{x}}\right)\right)\right) \]
    9. associate-/r*95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{0.25}{x \cdot x}}\right)\right)\right) \]
    10. clear-num95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\color{blue}{\frac{1}{\frac{x \cdot x}{0.25}}}\right)\right)\right) \]
    11. div-inv95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{0.25}}}\right)\right)\right) \]
    12. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot x\right) \cdot \color{blue}{4}}\right)\right)\right) \]
    13. metadata-eval95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot x\right) \cdot \color{blue}{\left(2 \cdot 2\right)}}\right)\right)\right) \]
    14. swap-sqr95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\color{blue}{\left(x \cdot 2\right) \cdot \left(x \cdot 2\right)}}\right)\right)\right) \]
    15. *-commutative95.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \color{blue}{\left(2 \cdot x\right)}}\right)\right)\right) \]
    16. count-295.7%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \color{blue}{\left(x + x\right)}}\right)\right)\right) \]
    17. flip-+-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \color{blue}{\frac{x \cdot x - x \cdot x}{x - x}}}\right)\right)\right) \]
    18. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \frac{x \cdot x - x \cdot x}{\color{blue}{0}}}\right)\right)\right) \]
    19. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\left(x \cdot 2\right) \cdot \frac{x \cdot x - x \cdot x}{\color{blue}{x \cdot x - x \cdot x}}}\right)\right)\right) \]
    20. associate-*r/-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\color{blue}{\frac{\left(x \cdot 2\right) \cdot \left(x \cdot x - x \cdot x\right)}{x \cdot x - x \cdot x}}}\right)\right)\right) \]
    21. *-commutative-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\color{blue}{\left(2 \cdot x\right)} \cdot \left(x \cdot x - x \cdot x\right)}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    22. count-2-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\color{blue}{\left(x + x\right)} \cdot \left(x \cdot x - x \cdot x\right)}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    23. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\left(x + x\right) \cdot \color{blue}{0}}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    24. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\left(x + x\right) \cdot \color{blue}{\left(x - x\right)}}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    25. difference-of-squares-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{\color{blue}{x \cdot x - x \cdot x}}{x \cdot x - x \cdot x}}\right)\right)\right) \]
    26. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{x \cdot x - x \cdot x}{\color{blue}{0}}}\right)\right)\right) \]
    27. +-inverses-0.0%

      \[\leadsto \log 2 + \mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \left(-\frac{1}{\frac{x \cdot x - x \cdot x}{\color{blue}{x - x}}}\right)\right)\right) \]
  6. Applied egg-rr91.7%

    \[\leadsto \log 2 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log x + \frac{-0.5}{x}\right)\right)} \]
  7. Taylor expanded in x around 0 20.5%

    \[\leadsto \log 2 + \color{blue}{\frac{-0.5}{x}} \]
  8. Taylor expanded in x around 0 4.5%

    \[\leadsto \color{blue}{\frac{-0.5}{x}} \]
  9. Final simplification4.5%

    \[\leadsto \frac{-0.5}{x} \]

Alternative 8: 3.2% accurate, 207.0× speedup?

\[\begin{array}{l} \\ -0.03125 \end{array} \]
(FPCore (x) :precision binary32 -0.03125)
float code(float x) {
	return -0.03125f;
}
real(4) function code(x)
    real(4), intent (in) :: x
    code = -0.03125e0
end function
function code(x)
	return Float32(-0.03125)
end
function tmp = code(x)
	tmp = single(-0.03125);
end
\begin{array}{l}

\\
-0.03125
\end{array}
Derivation
  1. Initial program 47.0%

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

    \[\leadsto \log \left(x + \color{blue}{\left(x - 0.5 \cdot \frac{1}{x}\right)}\right) \]
  3. Step-by-step derivation
    1. associate-*r/97.0%

      \[\leadsto \log \left(x + \left(x - \color{blue}{\frac{0.5 \cdot 1}{x}}\right)\right) \]
    2. metadata-eval97.0%

      \[\leadsto \log \left(x + \left(x - \frac{\color{blue}{0.5}}{x}\right)\right) \]
  4. Simplified97.0%

    \[\leadsto \log \left(x + \color{blue}{\left(x - \frac{0.5}{x}\right)}\right) \]
  5. Taylor expanded in x around inf 97.6%

    \[\leadsto \color{blue}{\left(\log 2 + -1 \cdot \log \left(\frac{1}{x}\right)\right) - \left(0.03125 \cdot \frac{1}{{x}^{4}} + 0.25 \cdot \frac{1}{{x}^{2}}\right)} \]
  6. Simplified3.2%

    \[\leadsto \color{blue}{-0.03125} \]
  7. Final simplification3.2%

    \[\leadsto -0.03125 \]

Developer target: 99.1% accurate, 0.7× 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)))));
}
real(4) function code(x)
    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 2023275 
(FPCore (x)
  :name "Rust f32::acosh"
  :precision binary32
  :pre (>= x 1.0)

  :herbie-target
  (log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0)))))

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