Numeric.Log:$clog1p from log-domain-0.10.2.1, B

Percentage Accurate: 99.7% → 99.7%
Time: 3.0s
Alternatives: 6
Speedup: TODO×

Specification

?
\[\frac{x}{1 + \sqrt{x + 1}} \]

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 6 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?

\[\frac{x}{1 + \sqrt{x + 1}} \]
Derivation
  1. Initial program 99.8%

    \[\frac{x}{1 + \sqrt{x + 1}} \]
  2. Final simplification99.8%

    \[\leadsto \frac{x}{1 + \sqrt{x + 1}} \]

Alternative 2?

\[\begin{array}{l} \mathbf{if}\;x \leq 1.15 \cdot 10^{-5}:\\ \;\;\;\;\frac{x}{x \cdot 0.5 + 2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if x < 1.15e-5

    1. Initial program 100.0%

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Taylor expanded in x around 0 99.3%

      \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]

    if 1.15e-5 < x

    1. Initial program 99.3%

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. flip-+98.9%

        \[\leadsto \frac{x}{\color{blue}{\frac{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}}} \]
      2. metadata-eval98.9%

        \[\leadsto \frac{x}{\frac{\color{blue}{1} - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}} \]
      3. add-sqr-sqrt99.5%

        \[\leadsto \frac{x}{\frac{1 - \color{blue}{\left(x + 1\right)}}{1 - \sqrt{x + 1}}} \]
      4. +-commutative99.5%

        \[\leadsto \frac{x}{\frac{1 - \color{blue}{\left(1 + x\right)}}{1 - \sqrt{x + 1}}} \]
      5. associate--r+99.5%

        \[\leadsto \frac{x}{\frac{\color{blue}{\left(1 - 1\right) - x}}{1 - \sqrt{x + 1}}} \]
      6. metadata-eval99.5%

        \[\leadsto \frac{x}{\frac{\color{blue}{0} - x}{1 - \sqrt{x + 1}}} \]
      7. neg-sub099.5%

        \[\leadsto \frac{x}{\frac{\color{blue}{-x}}{1 - \sqrt{x + 1}}} \]
      8. associate-/r/99.5%

        \[\leadsto \color{blue}{\frac{x}{-x} \cdot \left(1 - \sqrt{x + 1}\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\frac{x}{-x} \cdot \left(1 - \sqrt{x + 1}\right)} \]
    4. Step-by-step derivation
      1. remove-double-neg99.5%

        \[\leadsto \frac{\color{blue}{-\left(-x\right)}}{-x} \cdot \left(1 - \sqrt{x + 1}\right) \]
      2. distribute-frac-neg99.5%

        \[\leadsto \color{blue}{\left(-\frac{-x}{-x}\right)} \cdot \left(1 - \sqrt{x + 1}\right) \]
      3. *-inverses99.5%

        \[\leadsto \left(-\color{blue}{1}\right) \cdot \left(1 - \sqrt{x + 1}\right) \]
      4. metadata-eval99.5%

        \[\leadsto \color{blue}{-1} \cdot \left(1 - \sqrt{x + 1}\right) \]
      5. neg-mul-199.5%

        \[\leadsto \color{blue}{-\left(1 - \sqrt{x + 1}\right)} \]
      6. sub-neg99.5%

        \[\leadsto -\color{blue}{\left(1 + \left(-\sqrt{x + 1}\right)\right)} \]
      7. +-commutative99.5%

        \[\leadsto -\color{blue}{\left(\left(-\sqrt{x + 1}\right) + 1\right)} \]
      8. distribute-neg-in99.5%

        \[\leadsto \color{blue}{\left(-\left(-\sqrt{x + 1}\right)\right) + \left(-1\right)} \]
      9. remove-double-neg99.5%

        \[\leadsto \color{blue}{\sqrt{x + 1}} + \left(-1\right) \]
      10. metadata-eval99.5%

        \[\leadsto \sqrt{x + 1} + \color{blue}{-1} \]
    5. Simplified99.5%

      \[\leadsto \color{blue}{\sqrt{x + 1} + -1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.15 \cdot 10^{-5}:\\ \;\;\;\;\frac{x}{x \cdot 0.5 + 2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array} \]

Alternative 3?

\[\begin{array}{l} \mathbf{if}\;x \leq 4:\\ \;\;\;\;\frac{x}{x \cdot 0.5 + 2}\\ \mathbf{else}:\\ \;\;\;\;-1 + \sqrt{x}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if x < 4

    1. Initial program 100.0%

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Taylor expanded in x around 0 98.9%

      \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]

    if 4 < x

    1. Initial program 99.3%

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. clear-num99.1%

        \[\leadsto \color{blue}{\frac{1}{\frac{1 + \sqrt{x + 1}}{x}}} \]
      2. inv-pow99.1%

        \[\leadsto \color{blue}{{\left(\frac{1 + \sqrt{x + 1}}{x}\right)}^{-1}} \]
    3. Applied egg-rr99.1%

      \[\leadsto \color{blue}{{\left(\frac{1 + \sqrt{x + 1}}{x}\right)}^{-1}} \]
    4. Step-by-step derivation
      1. unpow-199.1%

        \[\leadsto \color{blue}{\frac{1}{\frac{1 + \sqrt{x + 1}}{x}}} \]
      2. clear-num99.3%

        \[\leadsto \color{blue}{\frac{x}{1 + \sqrt{x + 1}}} \]
      3. expm1-log1p-u90.7%

        \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}}{1 + \sqrt{x + 1}} \]
      4. expm1-udef90.7%

        \[\leadsto \frac{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}}{1 + \sqrt{x + 1}} \]
      5. log1p-udef90.7%

        \[\leadsto \frac{e^{\color{blue}{\log \left(1 + x\right)}} - 1}{1 + \sqrt{x + 1}} \]
      6. +-commutative90.7%

        \[\leadsto \frac{e^{\log \color{blue}{\left(x + 1\right)}} - 1}{1 + \sqrt{x + 1}} \]
      7. add-exp-log99.3%

        \[\leadsto \frac{\color{blue}{\left(x + 1\right)} - 1}{1 + \sqrt{x + 1}} \]
      8. add-sqr-sqrt99.9%

        \[\leadsto \frac{\color{blue}{\sqrt{x + 1} \cdot \sqrt{x + 1}} - 1}{1 + \sqrt{x + 1}} \]
      9. metadata-eval99.9%

        \[\leadsto \frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \color{blue}{-1 \cdot -1}}{1 + \sqrt{x + 1}} \]
      10. +-commutative99.9%

        \[\leadsto \frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - -1 \cdot -1}{\color{blue}{\sqrt{x + 1} + 1}} \]
      11. metadata-eval99.9%

        \[\leadsto \frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - -1 \cdot -1}{\sqrt{x + 1} + \color{blue}{\left(--1\right)}} \]
      12. sub-neg99.9%

        \[\leadsto \frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - -1 \cdot -1}{\color{blue}{\sqrt{x + 1} - -1}} \]
      13. flip-+100.0%

        \[\leadsto \color{blue}{\sqrt{x + 1} + -1} \]
      14. pow1/2100.0%

        \[\leadsto \color{blue}{{\left(x + 1\right)}^{0.5}} + -1 \]
      15. pow-to-exp92.2%

        \[\leadsto \color{blue}{e^{\log \left(x + 1\right) \cdot 0.5}} + -1 \]
      16. +-commutative92.2%

        \[\leadsto e^{\log \color{blue}{\left(1 + x\right)} \cdot 0.5} + -1 \]
      17. log1p-udef92.2%

        \[\leadsto e^{\color{blue}{\mathsf{log1p}\left(x\right)} \cdot 0.5} + -1 \]
      18. *-commutative92.2%

        \[\leadsto e^{\color{blue}{0.5 \cdot \mathsf{log1p}\left(x\right)}} + -1 \]
      19. metadata-eval92.2%

        \[\leadsto e^{0.5 \cdot \mathsf{log1p}\left(x\right)} + \color{blue}{\left(-1\right)} \]
      20. sub-neg92.2%

        \[\leadsto \color{blue}{e^{0.5 \cdot \mathsf{log1p}\left(x\right)} - 1} \]
      21. expm1-udef92.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(0.5 \cdot \mathsf{log1p}\left(x\right)\right)} \]
      22. *-un-lft-identity92.2%

        \[\leadsto \color{blue}{1 \cdot \mathsf{expm1}\left(0.5 \cdot \mathsf{log1p}\left(x\right)\right)} \]
    5. Applied egg-rr92.2%

      \[\leadsto \color{blue}{1 \cdot \mathsf{expm1}\left(0.5 \cdot \mathsf{log1p}\left(x\right)\right)} \]
    6. Step-by-step derivation
      1. *-lft-identity92.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(0.5 \cdot \mathsf{log1p}\left(x\right)\right)} \]
    7. Simplified92.2%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(0.5 \cdot \mathsf{log1p}\left(x\right)\right)} \]
    8. Taylor expanded in x around -inf 0.0%

      \[\leadsto \color{blue}{e^{0.5 \cdot \left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1\right)} - 1} \]
    9. Step-by-step derivation
      1. sub-neg0.0%

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

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

        \[\leadsto \color{blue}{-1 + e^{0.5 \cdot \left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1\right)}} \]
      4. *-commutative0.0%

        \[\leadsto -1 + e^{\color{blue}{\left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1\right) \cdot 0.5}} \]
      5. exp-prod0.0%

        \[\leadsto -1 + \color{blue}{{\left(e^{-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1}\right)}^{0.5}} \]
      6. unpow1/20.0%

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

        \[\leadsto -1 + \sqrt{e^{\color{blue}{\log -1 + -1 \cdot \log \left(\frac{-1}{x}\right)}}} \]
      8. mul-1-neg0.0%

        \[\leadsto -1 + \sqrt{e^{\log -1 + \color{blue}{\left(-\log \left(\frac{-1}{x}\right)\right)}}} \]
      9. unsub-neg0.0%

        \[\leadsto -1 + \sqrt{e^{\color{blue}{\log -1 - \log \left(\frac{-1}{x}\right)}}} \]
      10. metadata-eval0.0%

        \[\leadsto -1 + \sqrt{e^{\log -1 - \log \left(\frac{\color{blue}{\frac{1}{-1}}}{x}\right)}} \]
      11. associate-/r*0.0%

        \[\leadsto -1 + \sqrt{e^{\log -1 - \log \color{blue}{\left(\frac{1}{-1 \cdot x}\right)}}} \]
      12. neg-mul-10.0%

        \[\leadsto -1 + \sqrt{e^{\log -1 - \log \left(\frac{1}{\color{blue}{-x}}\right)}} \]
      13. log-div88.7%

        \[\leadsto -1 + \sqrt{e^{\color{blue}{\log \left(\frac{-1}{\frac{1}{-x}}\right)}}} \]
      14. associate-/l*88.7%

        \[\leadsto -1 + \sqrt{e^{\log \color{blue}{\left(\frac{-1 \cdot \left(-x\right)}{1}\right)}}} \]
      15. neg-mul-188.7%

        \[\leadsto -1 + \sqrt{e^{\log \left(\frac{\color{blue}{-\left(-x\right)}}{1}\right)}} \]
      16. remove-double-neg88.7%

        \[\leadsto -1 + \sqrt{e^{\log \left(\frac{\color{blue}{x}}{1}\right)}} \]
      17. /-rgt-identity88.7%

        \[\leadsto -1 + \sqrt{e^{\log \color{blue}{x}}} \]
    10. Simplified96.3%

      \[\leadsto \color{blue}{-1 + \sqrt{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 4:\\ \;\;\;\;\frac{x}{x \cdot 0.5 + 2}\\ \mathbf{else}:\\ \;\;\;\;-1 + \sqrt{x}\\ \end{array} \]

Alternative 4?

\[\frac{x}{x \cdot 0.5 + 2} \]
Derivation
  1. Initial program 99.8%

    \[\frac{x}{1 + \sqrt{x + 1}} \]
  2. Taylor expanded in x around 0 69.8%

    \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]
  3. Final simplification69.8%

    \[\leadsto \frac{x}{x \cdot 0.5 + 2} \]

Alternative 5?

\[\frac{x}{2} \]
Derivation
  1. Initial program 99.8%

    \[\frac{x}{1 + \sqrt{x + 1}} \]
  2. Taylor expanded in x around 0 69.3%

    \[\leadsto \frac{x}{\color{blue}{2}} \]
  3. Final simplification69.3%

    \[\leadsto \frac{x}{2} \]

Alternative 6?

\[2 \]
Derivation
  1. Initial program 99.8%

    \[\frac{x}{1 + \sqrt{x + 1}} \]
  2. Taylor expanded in x around 0 69.8%

    \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]
  3. Taylor expanded in x around inf 4.7%

    \[\leadsto \color{blue}{2} \]
  4. Final simplification4.7%

    \[\leadsto 2 \]

Reproduce

?
herbie shell --seed 2023166 
(FPCore (x)
  :name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
  :precision binary64
  (/ x (+ 1.0 (sqrt (+ x 1.0)))))