Hyperbolic arc-(co)secant

Percentage Accurate: 99.9% → 99.9%
Time: 6.2s
Alternatives: 4
Speedup: TODO×

Specification

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

Your Program's Arguments

Results

Enter valid numbers for all inputs

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 4 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.

Alternative 1?

\[\log \left(\frac{1 + \sqrt{1 - x \cdot x}}{x}\right) \]
Derivation
  1. Initial program 100.0%

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

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

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

      \[\leadsto \log \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{\sqrt{1 - x \cdot x}}{x} + \frac{1}{x}}\right)} - 1\right) \]
    4. div-inv100.0%

      \[\leadsto \log \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{1 - x \cdot x} \cdot \frac{1}{x}} + \frac{1}{x}\right)} - 1\right) \]
    5. *-un-lft-identity100.0%

      \[\leadsto \log \left(e^{\mathsf{log1p}\left(\sqrt{1 - x \cdot x} \cdot \frac{1}{x} + \color{blue}{1 \cdot \frac{1}{x}}\right)} - 1\right) \]
    6. distribute-rgt-out100.0%

      \[\leadsto \log \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{1}{x} \cdot \left(\sqrt{1 - x \cdot x} + 1\right)}\right)} - 1\right) \]
  3. Applied egg-rr100.0%

    \[\leadsto \log \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{x} \cdot \left(\sqrt{1 - x \cdot x} + 1\right)\right)} - 1\right)} \]
  4. Step-by-step derivation
    1. expm1-def100.0%

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

      \[\leadsto \log \color{blue}{\left(\frac{1}{x} \cdot \left(\sqrt{1 - x \cdot x} + 1\right)\right)} \]
    3. associate-*l/100.0%

      \[\leadsto \log \color{blue}{\left(\frac{1 \cdot \left(\sqrt{1 - x \cdot x} + 1\right)}{x}\right)} \]
    4. *-lft-identity100.0%

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

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

    \[\leadsto \log \color{blue}{\left(\frac{1 + \sqrt{1 - x \cdot x}}{x}\right)} \]
  6. Final simplification100.0%

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

Alternative 2?

\[\log \left(\frac{1}{x} + \left(\frac{1}{x} + x \cdot -0.5\right)\right) \]
Derivation
  1. Initial program 100.0%

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

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

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

Alternative 3?

\[\log \left(x \cdot -0.5 + \frac{1}{x} \cdot 2\right) \]
Derivation
  1. Initial program 100.0%

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

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

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

Alternative 4?

\[\log \left(\frac{2}{x}\right) \]
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \log \color{blue}{\left(\frac{2}{x}\right)} \]
  3. Final simplification98.1%

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

Reproduce

?
herbie shell --seed 2023166 
(FPCore (x)
  :name "Hyperbolic arc-(co)secant"
  :precision binary64
  (log (+ (/ 1.0 x) (/ (sqrt (- 1.0 (* x x))) x))))