Rust f32::acosh

?

Percentage Accurate: 53.7% → 98.3%
Time: 3.6s
Precision: binary32
Cost: 3424

?

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

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.

Herbie found 3 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original53.7%
Target99.3%
Herbie98.3%
\[\log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right) \]

Derivation?

  1. Initial program 58.7%

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

    \[\leadsto \log \color{blue}{\left(2 \cdot x - 0.5 \cdot \frac{1}{x}\right)} \]
  3. Simplified97.5%

    \[\leadsto \log \color{blue}{\left(x \cdot 2 - \frac{0.5}{x}\right)} \]
    Step-by-step derivation

    [Start]97.5%

    \[ \log \left(2 \cdot x - 0.5 \cdot \frac{1}{x}\right) \]

    *-commutative [=>]97.5%

    \[ \log \left(\color{blue}{x \cdot 2} - 0.5 \cdot \frac{1}{x}\right) \]

    associate-*r/ [=>]97.5%

    \[ \log \left(x \cdot 2 - \color{blue}{\frac{0.5 \cdot 1}{x}}\right) \]

    metadata-eval [=>]97.5%

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

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

Alternatives

Alternative 1
Accuracy98.3%
Cost3424
\[\log \left(x \cdot 2 - \frac{0.5}{x}\right) \]
Alternative 2
Accuracy97.0%
Cost3296
\[\log \left(x + x\right) \]
Alternative 3
Accuracy6.1%
Cost32
\[0 \]

Reproduce?

herbie shell --seed 2023178 
(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)))))