Hyperbolic arc-(co)secant

Percentage Accurate: 99.9% → 99.9%
Time: 6.8s
Alternatives: 7
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (log (+ (/ 1.0 x) (/ (sqrt (- 1.0 (* x x))) x))))
double code(double x) {
	return log(((1.0 / x) + (sqrt((1.0 - (x * x))) / x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = log(((1.0d0 / x) + (sqrt((1.0d0 - (x * x))) / x)))
end function
public static double code(double x) {
	return Math.log(((1.0 / x) + (Math.sqrt((1.0 - (x * x))) / x)));
}
def code(x):
	return math.log(((1.0 / x) + (math.sqrt((1.0 - (x * x))) / x)))
function code(x)
	return log(Float64(Float64(1.0 / x) + Float64(sqrt(Float64(1.0 - Float64(x * x))) / x)))
end
function tmp = code(x)
	tmp = log(((1.0 / x) + (sqrt((1.0 - (x * x))) / x)));
end
code[x_] := N[Log[N[(N[(1.0 / x), $MachinePrecision] + N[(N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 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 7 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: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (log (+ (/ 1.0 x) (/ (sqrt (- 1.0 (* x x))) x))))
double code(double x) {
	return log(((1.0 / x) + (sqrt((1.0 - (x * x))) / x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = log(((1.0d0 / x) + (sqrt((1.0d0 - (x * x))) / x)))
end function
public static double code(double x) {
	return Math.log(((1.0 / x) + (Math.sqrt((1.0 - (x * x))) / x)));
}
def code(x):
	return math.log(((1.0 / x) + (math.sqrt((1.0 - (x * x))) / x)))
function code(x)
	return log(Float64(Float64(1.0 / x) + Float64(sqrt(Float64(1.0 - Float64(x * x))) / x)))
end
function tmp = code(x)
	tmp = log(((1.0 / x) + (sqrt((1.0 - (x * x))) / x)));
end
code[x_] := N[Log[N[(N[(1.0 / x), $MachinePrecision] + N[(N[Sqrt[N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log \left(\frac{-1}{x} \cdot \left(-1 - \sqrt{\mathsf{fma}\left(-x, x, 1\right)}\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (log (* (/ -1.0 x) (- -1.0 (sqrt (fma (- x) x 1.0))))))
double code(double x) {
	return log(((-1.0 / x) * (-1.0 - sqrt(fma(-x, x, 1.0)))));
}
function code(x)
	return log(Float64(Float64(-1.0 / x) * Float64(-1.0 - sqrt(fma(Float64(-x), x, 1.0)))))
end
code[x_] := N[Log[N[(N[(-1.0 / x), $MachinePrecision] * N[(-1.0 - N[Sqrt[N[((-x) * x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(\frac{-1}{x} \cdot \left(-1 - \sqrt{\mathsf{fma}\left(-x, x, 1\right)}\right)\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{1}{x}} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    3. metadata-evalN/A

      \[\leadsto \log \left(\frac{\color{blue}{\mathsf{neg}\left(-1\right)}}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{x}\right)\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    5. div-invN/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    6. lift-/.f64N/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(-1 \cdot \color{blue}{\frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    7. neg-mul-1N/A

      \[\leadsto \log \left(\color{blue}{-1 \cdot \left(-1 \cdot \frac{1}{x}\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    8. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\sqrt{1 - x \cdot x}}{x}}\right) \]
    9. frac-2negN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)}{\mathsf{neg}\left(x\right)}}\right) \]
    10. div-invN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \frac{1}{\mathsf{neg}\left(x\right)}}\right) \]
    11. distribute-frac-neg2N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}\right) \]
    12. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{1}{x}}\right)\right)\right) \]
    13. neg-mul-1N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(-1 \cdot \frac{1}{x}\right)}\right) \]
    14. distribute-rgt-outN/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    15. lower-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    16. lift-/.f64N/A

      \[\leadsto \log \left(\left(-1 \cdot \color{blue}{\frac{1}{x}}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    17. div-invN/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    18. lower-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    19. lower-+.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)}\right) \]
    20. lower-neg.f64100.0

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \color{blue}{\left(-\sqrt{1 - x \cdot x}\right)}\right)\right) \]
    21. lift--.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 - x \cdot x}}\right)\right)\right) \]
    22. lift-*.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{1 - \color{blue}{x \cdot x}}\right)\right)\right) \]
    23. cancel-sign-sub-invN/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x}}\right)\right)\right) \]
    24. +-commutativeN/A

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

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

    \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 - \sqrt{\mathsf{fma}\left(-x, x, 1\right)}\right)\right) \]
  6. Add Preprocessing

Alternative 2: 99.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \log \left(\frac{\sqrt{\mathsf{fma}\left(-x, x, 1\right)} + 1}{x}\right) \end{array} \]
(FPCore (x) :precision binary64 (log (/ (+ (sqrt (fma (- x) x 1.0)) 1.0) x)))
double code(double x) {
	return log(((sqrt(fma(-x, x, 1.0)) + 1.0) / x));
}
function code(x)
	return log(Float64(Float64(sqrt(fma(Float64(-x), x, 1.0)) + 1.0) / x))
end
code[x_] := N[Log[N[(N[(N[Sqrt[N[((-x) * x + 1.0), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(\frac{\sqrt{\mathsf{fma}\left(-x, x, 1\right)} + 1}{x}\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto \log \left(\frac{1}{x} + \color{blue}{\frac{\sqrt{1 - x \cdot x}}{x}}\right) \]
    3. div-invN/A

      \[\leadsto \log \left(\frac{1}{x} + \color{blue}{\sqrt{1 - x \cdot x} \cdot \frac{1}{x}}\right) \]
    4. lift-/.f64N/A

      \[\leadsto \log \left(\frac{1}{x} + \sqrt{1 - x \cdot x} \cdot \color{blue}{\frac{1}{x}}\right) \]
    5. distribute-rgt1-inN/A

      \[\leadsto \log \color{blue}{\left(\left(\sqrt{1 - x \cdot x} + 1\right) \cdot \frac{1}{x}\right)} \]
    6. lift-/.f64N/A

      \[\leadsto \log \left(\left(\sqrt{1 - x \cdot x} + 1\right) \cdot \color{blue}{\frac{1}{x}}\right) \]
    7. un-div-invN/A

      \[\leadsto \log \color{blue}{\left(\frac{\sqrt{1 - x \cdot x} + 1}{x}\right)} \]
    8. lower-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{\sqrt{1 - x \cdot x} + 1}{x}\right)} \]
    9. lower-+.f64100.0

      \[\leadsto \log \left(\frac{\color{blue}{\sqrt{1 - x \cdot x} + 1}}{x}\right) \]
    10. lift--.f64N/A

      \[\leadsto \log \left(\frac{\sqrt{\color{blue}{1 - x \cdot x}} + 1}{x}\right) \]
    11. lift-*.f64N/A

      \[\leadsto \log \left(\frac{\sqrt{1 - \color{blue}{x \cdot x}} + 1}{x}\right) \]
    12. cancel-sign-sub-invN/A

      \[\leadsto \log \left(\frac{\sqrt{\color{blue}{1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x}} + 1}{x}\right) \]
    13. +-commutativeN/A

      \[\leadsto \log \left(\frac{\sqrt{\color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot x + 1}} + 1}{x}\right) \]
    14. lower-fma.f64N/A

      \[\leadsto \log \left(\frac{\sqrt{\color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(x\right), x, 1\right)}} + 1}{x}\right) \]
    15. lower-neg.f64100.0

      \[\leadsto \log \left(\frac{\sqrt{\mathsf{fma}\left(\color{blue}{-x}, x, 1\right)} + 1}{x}\right) \]
  4. Applied rewrites100.0%

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

Alternative 3: 99.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ -\log \left(\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x \cdot x, 0.125\right), x \cdot x, 0.5\right) \cdot x\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (- (log (* (fma (fma 0.0625 (* x x) 0.125) (* x x) 0.5) x))))
double code(double x) {
	return -log((fma(fma(0.0625, (x * x), 0.125), (x * x), 0.5) * x));
}
function code(x)
	return Float64(-log(Float64(fma(fma(0.0625, Float64(x * x), 0.125), Float64(x * x), 0.5) * x)))
end
code[x_] := (-N[Log[N[(N[(N[(0.0625 * N[(x * x), $MachinePrecision] + 0.125), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}

\\
-\log \left(\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x \cdot x, 0.125\right), x \cdot x, 0.5\right) \cdot x\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{1}{x}} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    3. metadata-evalN/A

      \[\leadsto \log \left(\frac{\color{blue}{\mathsf{neg}\left(-1\right)}}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{x}\right)\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    5. div-invN/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    6. lift-/.f64N/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(-1 \cdot \color{blue}{\frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    7. neg-mul-1N/A

      \[\leadsto \log \left(\color{blue}{-1 \cdot \left(-1 \cdot \frac{1}{x}\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    8. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\sqrt{1 - x \cdot x}}{x}}\right) \]
    9. frac-2negN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)}{\mathsf{neg}\left(x\right)}}\right) \]
    10. div-invN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \frac{1}{\mathsf{neg}\left(x\right)}}\right) \]
    11. distribute-frac-neg2N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}\right) \]
    12. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{1}{x}}\right)\right)\right) \]
    13. neg-mul-1N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(-1 \cdot \frac{1}{x}\right)}\right) \]
    14. distribute-rgt-outN/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    15. lower-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    16. lift-/.f64N/A

      \[\leadsto \log \left(\left(-1 \cdot \color{blue}{\frac{1}{x}}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    17. div-invN/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    18. lower-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    19. lower-+.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)}\right) \]
    20. lower-neg.f64100.0

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \color{blue}{\left(-\sqrt{1 - x \cdot x}\right)}\right)\right) \]
    21. lift--.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 - x \cdot x}}\right)\right)\right) \]
    22. lift-*.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{1 - \color{blue}{x \cdot x}}\right)\right)\right) \]
    23. cancel-sign-sub-invN/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x}}\right)\right)\right) \]
    24. +-commutativeN/A

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

    \[\leadsto \log \color{blue}{\left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\mathsf{fma}\left(-x, x, 1\right)}\right)\right)\right)} \]
  5. Taylor expanded in x around 0

    \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(\frac{1}{2} \cdot {x}^{2} - 2\right)}\right) \]
  6. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(\frac{1}{2} \cdot {x}^{2} + \left(\mathsf{neg}\left(2\right)\right)\right)}\right) \]
    2. lower-fma.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, \mathsf{neg}\left(2\right)\right)}\right) \]
    3. unpow2N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, \color{blue}{x \cdot x}, \mathsf{neg}\left(2\right)\right)\right) \]
    4. lower-*.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, \color{blue}{x \cdot x}, \mathsf{neg}\left(2\right)\right)\right) \]
    5. metadata-eval99.4

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(0.5, x \cdot x, \color{blue}{-2}\right)\right) \]
  7. Applied rewrites99.4%

    \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\mathsf{fma}\left(0.5, x \cdot x, -2\right)}\right) \]
  8. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)} \]
    3. lift-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right) \]
    4. associate-*l/N/A

      \[\leadsto \log \color{blue}{\left(\frac{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}{x}\right)} \]
    5. clear-numN/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}}\right)} \]
    6. log-recN/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)\right)} \]
    7. lower-neg.f64N/A

      \[\leadsto \color{blue}{-\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    8. lower-log.f64N/A

      \[\leadsto -\color{blue}{\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    9. lower-/.f64N/A

      \[\leadsto -\log \color{blue}{\left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    10. mul-1-negN/A

      \[\leadsto -\log \left(\frac{x}{\color{blue}{\mathsf{neg}\left(\mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)}}\right) \]
  9. Applied rewrites99.4%

    \[\leadsto \color{blue}{-\log \left(\frac{x}{-\mathsf{fma}\left(0.5, x \cdot x, -2\right)}\right)} \]
  10. Taylor expanded in x around 0

    \[\leadsto -\log \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{8} + \frac{1}{16} \cdot {x}^{2}\right)\right)\right)} \]
  11. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto -\log \color{blue}{\left(\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{8} + \frac{1}{16} \cdot {x}^{2}\right)\right) \cdot x\right)} \]
    2. lower-*.f64N/A

      \[\leadsto -\log \color{blue}{\left(\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{8} + \frac{1}{16} \cdot {x}^{2}\right)\right) \cdot x\right)} \]
    3. +-commutativeN/A

      \[\leadsto -\log \left(\color{blue}{\left({x}^{2} \cdot \left(\frac{1}{8} + \frac{1}{16} \cdot {x}^{2}\right) + \frac{1}{2}\right)} \cdot x\right) \]
    4. *-commutativeN/A

      \[\leadsto -\log \left(\left(\color{blue}{\left(\frac{1}{8} + \frac{1}{16} \cdot {x}^{2}\right) \cdot {x}^{2}} + \frac{1}{2}\right) \cdot x\right) \]
    5. lower-fma.f64N/A

      \[\leadsto -\log \left(\color{blue}{\mathsf{fma}\left(\frac{1}{8} + \frac{1}{16} \cdot {x}^{2}, {x}^{2}, \frac{1}{2}\right)} \cdot x\right) \]
    6. +-commutativeN/A

      \[\leadsto -\log \left(\mathsf{fma}\left(\color{blue}{\frac{1}{16} \cdot {x}^{2} + \frac{1}{8}}, {x}^{2}, \frac{1}{2}\right) \cdot x\right) \]
    7. lower-fma.f64N/A

      \[\leadsto -\log \left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{16}, {x}^{2}, \frac{1}{8}\right)}, {x}^{2}, \frac{1}{2}\right) \cdot x\right) \]
    8. unpow2N/A

      \[\leadsto -\log \left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{16}, \color{blue}{x \cdot x}, \frac{1}{8}\right), {x}^{2}, \frac{1}{2}\right) \cdot x\right) \]
    9. lower-*.f64N/A

      \[\leadsto -\log \left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{16}, \color{blue}{x \cdot x}, \frac{1}{8}\right), {x}^{2}, \frac{1}{2}\right) \cdot x\right) \]
    10. unpow2N/A

      \[\leadsto -\log \left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{16}, x \cdot x, \frac{1}{8}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right) \cdot x\right) \]
    11. lower-*.f6499.4

      \[\leadsto -\log \left(\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x \cdot x, 0.125\right), \color{blue}{x \cdot x}, 0.5\right) \cdot x\right) \]
  12. Applied rewrites99.4%

    \[\leadsto -\log \color{blue}{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x \cdot x, 0.125\right), x \cdot x, 0.5\right) \cdot x\right)} \]
  13. Add Preprocessing

Alternative 4: 99.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \log \left(\frac{\mathsf{fma}\left(x \cdot x, -0.5, 2\right)}{x}\right) \end{array} \]
(FPCore (x) :precision binary64 (log (/ (fma (* x x) -0.5 2.0) x)))
double code(double x) {
	return log((fma((x * x), -0.5, 2.0) / x));
}
function code(x)
	return log(Float64(fma(Float64(x * x), -0.5, 2.0) / x))
end
code[x_] := N[Log[N[(N[(N[(x * x), $MachinePrecision] * -0.5 + 2.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(\frac{\mathsf{fma}\left(x \cdot x, -0.5, 2\right)}{x}\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \log \color{blue}{\left(\frac{2 + \frac{-1}{2} \cdot {x}^{2}}{x}\right)} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{2 + \frac{-1}{2} \cdot {x}^{2}}{x}\right)} \]
    2. +-commutativeN/A

      \[\leadsto \log \left(\frac{\color{blue}{\frac{-1}{2} \cdot {x}^{2} + 2}}{x}\right) \]
    3. *-commutativeN/A

      \[\leadsto \log \left(\frac{\color{blue}{{x}^{2} \cdot \frac{-1}{2}} + 2}{x}\right) \]
    4. lower-fma.f64N/A

      \[\leadsto \log \left(\frac{\color{blue}{\mathsf{fma}\left({x}^{2}, \frac{-1}{2}, 2\right)}}{x}\right) \]
    5. unpow2N/A

      \[\leadsto \log \left(\frac{\mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{-1}{2}, 2\right)}{x}\right) \]
    6. lower-*.f6499.4

      \[\leadsto \log \left(\frac{\mathsf{fma}\left(\color{blue}{x \cdot x}, -0.5, 2\right)}{x}\right) \]
  5. Applied rewrites99.4%

    \[\leadsto \log \color{blue}{\left(\frac{\mathsf{fma}\left(x \cdot x, -0.5, 2\right)}{x}\right)} \]
  6. Add Preprocessing

Alternative 5: 99.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ -\log \left(\mathsf{fma}\left(0.125, x \cdot x, 0.5\right) \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (- (log (* (fma 0.125 (* x x) 0.5) x))))
double code(double x) {
	return -log((fma(0.125, (x * x), 0.5) * x));
}
function code(x)
	return Float64(-log(Float64(fma(0.125, Float64(x * x), 0.5) * x)))
end
code[x_] := (-N[Log[N[(N[(0.125 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}

\\
-\log \left(\mathsf{fma}\left(0.125, x \cdot x, 0.5\right) \cdot x\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{1}{x}} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    3. metadata-evalN/A

      \[\leadsto \log \left(\frac{\color{blue}{\mathsf{neg}\left(-1\right)}}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{x}\right)\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    5. div-invN/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    6. lift-/.f64N/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(-1 \cdot \color{blue}{\frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    7. neg-mul-1N/A

      \[\leadsto \log \left(\color{blue}{-1 \cdot \left(-1 \cdot \frac{1}{x}\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    8. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\sqrt{1 - x \cdot x}}{x}}\right) \]
    9. frac-2negN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)}{\mathsf{neg}\left(x\right)}}\right) \]
    10. div-invN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \frac{1}{\mathsf{neg}\left(x\right)}}\right) \]
    11. distribute-frac-neg2N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}\right) \]
    12. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{1}{x}}\right)\right)\right) \]
    13. neg-mul-1N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(-1 \cdot \frac{1}{x}\right)}\right) \]
    14. distribute-rgt-outN/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    15. lower-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    16. lift-/.f64N/A

      \[\leadsto \log \left(\left(-1 \cdot \color{blue}{\frac{1}{x}}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    17. div-invN/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    18. lower-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    19. lower-+.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)}\right) \]
    20. lower-neg.f64100.0

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \color{blue}{\left(-\sqrt{1 - x \cdot x}\right)}\right)\right) \]
    21. lift--.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 - x \cdot x}}\right)\right)\right) \]
    22. lift-*.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{1 - \color{blue}{x \cdot x}}\right)\right)\right) \]
    23. cancel-sign-sub-invN/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x}}\right)\right)\right) \]
    24. +-commutativeN/A

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

    \[\leadsto \log \color{blue}{\left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\mathsf{fma}\left(-x, x, 1\right)}\right)\right)\right)} \]
  5. Taylor expanded in x around 0

    \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(\frac{1}{2} \cdot {x}^{2} - 2\right)}\right) \]
  6. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(\frac{1}{2} \cdot {x}^{2} + \left(\mathsf{neg}\left(2\right)\right)\right)}\right) \]
    2. lower-fma.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, \mathsf{neg}\left(2\right)\right)}\right) \]
    3. unpow2N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, \color{blue}{x \cdot x}, \mathsf{neg}\left(2\right)\right)\right) \]
    4. lower-*.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, \color{blue}{x \cdot x}, \mathsf{neg}\left(2\right)\right)\right) \]
    5. metadata-eval99.4

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(0.5, x \cdot x, \color{blue}{-2}\right)\right) \]
  7. Applied rewrites99.4%

    \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\mathsf{fma}\left(0.5, x \cdot x, -2\right)}\right) \]
  8. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)} \]
    3. lift-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right) \]
    4. associate-*l/N/A

      \[\leadsto \log \color{blue}{\left(\frac{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}{x}\right)} \]
    5. clear-numN/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}}\right)} \]
    6. log-recN/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)\right)} \]
    7. lower-neg.f64N/A

      \[\leadsto \color{blue}{-\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    8. lower-log.f64N/A

      \[\leadsto -\color{blue}{\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    9. lower-/.f64N/A

      \[\leadsto -\log \color{blue}{\left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    10. mul-1-negN/A

      \[\leadsto -\log \left(\frac{x}{\color{blue}{\mathsf{neg}\left(\mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)}}\right) \]
  9. Applied rewrites99.4%

    \[\leadsto \color{blue}{-\log \left(\frac{x}{-\mathsf{fma}\left(0.5, x \cdot x, -2\right)}\right)} \]
  10. Taylor expanded in x around 0

    \[\leadsto -\log \color{blue}{\left(x \cdot \left(\frac{1}{2} + \frac{1}{8} \cdot {x}^{2}\right)\right)} \]
  11. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto -\log \color{blue}{\left(\left(\frac{1}{2} + \frac{1}{8} \cdot {x}^{2}\right) \cdot x\right)} \]
    2. lower-*.f64N/A

      \[\leadsto -\log \color{blue}{\left(\left(\frac{1}{2} + \frac{1}{8} \cdot {x}^{2}\right) \cdot x\right)} \]
    3. +-commutativeN/A

      \[\leadsto -\log \left(\color{blue}{\left(\frac{1}{8} \cdot {x}^{2} + \frac{1}{2}\right)} \cdot x\right) \]
    4. lower-fma.f64N/A

      \[\leadsto -\log \left(\color{blue}{\mathsf{fma}\left(\frac{1}{8}, {x}^{2}, \frac{1}{2}\right)} \cdot x\right) \]
    5. unpow2N/A

      \[\leadsto -\log \left(\mathsf{fma}\left(\frac{1}{8}, \color{blue}{x \cdot x}, \frac{1}{2}\right) \cdot x\right) \]
    6. lower-*.f6499.4

      \[\leadsto -\log \left(\mathsf{fma}\left(0.125, \color{blue}{x \cdot x}, 0.5\right) \cdot x\right) \]
  12. Applied rewrites99.4%

    \[\leadsto -\log \color{blue}{\left(\mathsf{fma}\left(0.125, x \cdot x, 0.5\right) \cdot x\right)} \]
  13. Add Preprocessing

Alternative 6: 99.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ -\log \left(0.5 \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (- (log (* 0.5 x))))
double code(double x) {
	return -log((0.5 * x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = -log((0.5d0 * x))
end function
public static double code(double x) {
	return -Math.log((0.5 * x));
}
def code(x):
	return -math.log((0.5 * x))
function code(x)
	return Float64(-log(Float64(0.5 * x)))
end
function tmp = code(x)
	tmp = -log((0.5 * x));
end
code[x_] := (-N[Log[N[(0.5 * x), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}

\\
-\log \left(0.5 \cdot x\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\log \left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{1}{x}} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    3. metadata-evalN/A

      \[\leadsto \log \left(\frac{\color{blue}{\mathsf{neg}\left(-1\right)}}{x} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{x}\right)\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    5. div-invN/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot \frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    6. lift-/.f64N/A

      \[\leadsto \log \left(\left(\mathsf{neg}\left(-1 \cdot \color{blue}{\frac{1}{x}}\right)\right) + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    7. neg-mul-1N/A

      \[\leadsto \log \left(\color{blue}{-1 \cdot \left(-1 \cdot \frac{1}{x}\right)} + \frac{\sqrt{1 - x \cdot x}}{x}\right) \]
    8. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\sqrt{1 - x \cdot x}}{x}}\right) \]
    9. frac-2negN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\frac{\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)}{\mathsf{neg}\left(x\right)}}\right) \]
    10. div-invN/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \color{blue}{\left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \frac{1}{\mathsf{neg}\left(x\right)}}\right) \]
    11. distribute-frac-neg2N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}\right) \]
    12. lift-/.f64N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{1}{x}}\right)\right)\right) \]
    13. neg-mul-1N/A

      \[\leadsto \log \left(-1 \cdot \left(-1 \cdot \frac{1}{x}\right) + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right) \cdot \color{blue}{\left(-1 \cdot \frac{1}{x}\right)}\right) \]
    14. distribute-rgt-outN/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    15. lower-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(-1 \cdot \frac{1}{x}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right)} \]
    16. lift-/.f64N/A

      \[\leadsto \log \left(\left(-1 \cdot \color{blue}{\frac{1}{x}}\right) \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    17. div-invN/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    18. lower-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)\right) \]
    19. lower-+.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(-1 + \left(\mathsf{neg}\left(\sqrt{1 - x \cdot x}\right)\right)\right)}\right) \]
    20. lower-neg.f64100.0

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \color{blue}{\left(-\sqrt{1 - x \cdot x}\right)}\right)\right) \]
    21. lift--.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 - x \cdot x}}\right)\right)\right) \]
    22. lift-*.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{1 - \color{blue}{x \cdot x}}\right)\right)\right) \]
    23. cancel-sign-sub-invN/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\color{blue}{1 + \left(\mathsf{neg}\left(x\right)\right) \cdot x}}\right)\right)\right) \]
    24. +-commutativeN/A

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

    \[\leadsto \log \color{blue}{\left(\frac{-1}{x} \cdot \left(-1 + \left(-\sqrt{\mathsf{fma}\left(-x, x, 1\right)}\right)\right)\right)} \]
  5. Taylor expanded in x around 0

    \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(\frac{1}{2} \cdot {x}^{2} - 2\right)}\right) \]
  6. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\left(\frac{1}{2} \cdot {x}^{2} + \left(\mathsf{neg}\left(2\right)\right)\right)}\right) \]
    2. lower-fma.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, \mathsf{neg}\left(2\right)\right)}\right) \]
    3. unpow2N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, \color{blue}{x \cdot x}, \mathsf{neg}\left(2\right)\right)\right) \]
    4. lower-*.f64N/A

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, \color{blue}{x \cdot x}, \mathsf{neg}\left(2\right)\right)\right) \]
    5. metadata-eval99.4

      \[\leadsto \log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(0.5, x \cdot x, \color{blue}{-2}\right)\right) \]
  7. Applied rewrites99.4%

    \[\leadsto \log \left(\frac{-1}{x} \cdot \color{blue}{\mathsf{fma}\left(0.5, x \cdot x, -2\right)}\right) \]
  8. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{-1}{x} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)} \]
    3. lift-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{x}} \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right) \]
    4. associate-*l/N/A

      \[\leadsto \log \color{blue}{\left(\frac{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}{x}\right)} \]
    5. clear-numN/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}}\right)} \]
    6. log-recN/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)\right)} \]
    7. lower-neg.f64N/A

      \[\leadsto \color{blue}{-\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    8. lower-log.f64N/A

      \[\leadsto -\color{blue}{\log \left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    9. lower-/.f64N/A

      \[\leadsto -\log \color{blue}{\left(\frac{x}{-1 \cdot \mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)}\right)} \]
    10. mul-1-negN/A

      \[\leadsto -\log \left(\frac{x}{\color{blue}{\mathsf{neg}\left(\mathsf{fma}\left(\frac{1}{2}, x \cdot x, -2\right)\right)}}\right) \]
  9. Applied rewrites99.4%

    \[\leadsto \color{blue}{-\log \left(\frac{x}{-\mathsf{fma}\left(0.5, x \cdot x, -2\right)}\right)} \]
  10. Taylor expanded in x around 0

    \[\leadsto -\log \color{blue}{\left(\frac{1}{2} \cdot x\right)} \]
  11. Step-by-step derivation
    1. lower-*.f6499.2

      \[\leadsto -\log \color{blue}{\left(0.5 \cdot x\right)} \]
  12. Applied rewrites99.2%

    \[\leadsto -\log \color{blue}{\left(0.5 \cdot x\right)} \]
  13. Add Preprocessing

Alternative 7: 0.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \log \left(-0.5 \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (log (* -0.5 x)))
double code(double x) {
	return log((-0.5 * x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = log(((-0.5d0) * x))
end function
public static double code(double x) {
	return Math.log((-0.5 * x));
}
def code(x):
	return math.log((-0.5 * x))
function code(x)
	return log(Float64(-0.5 * x))
end
function tmp = code(x)
	tmp = log((-0.5 * x));
end
code[x_] := N[Log[N[(-0.5 * x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(-0.5 \cdot x\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \log \color{blue}{\left(\frac{2 + \frac{-1}{2} \cdot {x}^{2}}{x}\right)} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{2 + \frac{-1}{2} \cdot {x}^{2}}{x}\right)} \]
    2. +-commutativeN/A

      \[\leadsto \log \left(\frac{\color{blue}{\frac{-1}{2} \cdot {x}^{2} + 2}}{x}\right) \]
    3. *-commutativeN/A

      \[\leadsto \log \left(\frac{\color{blue}{{x}^{2} \cdot \frac{-1}{2}} + 2}{x}\right) \]
    4. lower-fma.f64N/A

      \[\leadsto \log \left(\frac{\color{blue}{\mathsf{fma}\left({x}^{2}, \frac{-1}{2}, 2\right)}}{x}\right) \]
    5. unpow2N/A

      \[\leadsto \log \left(\frac{\mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{-1}{2}, 2\right)}{x}\right) \]
    6. lower-*.f6499.4

      \[\leadsto \log \left(\frac{\mathsf{fma}\left(\color{blue}{x \cdot x}, -0.5, 2\right)}{x}\right) \]
  5. Applied rewrites99.4%

    \[\leadsto \log \color{blue}{\left(\frac{\mathsf{fma}\left(x \cdot x, -0.5, 2\right)}{x}\right)} \]
  6. Taylor expanded in x around inf

    \[\leadsto \log \left(\frac{-1}{2} \cdot \color{blue}{x}\right) \]
  7. Step-by-step derivation
    1. Applied rewrites0.0%

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

    Reproduce

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