ln(1 + x)

Percentage Accurate: 38.9% → 100.0%
Time: 8.6s
Alternatives: 7
Speedup: 6.1×

Specification

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

\\
\log \left(1 + 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: 38.9% accurate, 1.0× speedup?

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

\\
\log \left(1 + x\right)
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{log1p}\left(x\right) \end{array} \]
(FPCore (x) :precision binary64 (log1p x))
double code(double x) {
	return log1p(x);
}
public static double code(double x) {
	return Math.log1p(x);
}
def code(x):
	return math.log1p(x)
function code(x)
	return log1p(x)
end
code[x_] := N[Log[1 + x], $MachinePrecision]
\begin{array}{l}

\\
\mathsf{log1p}\left(x\right)
\end{array}
Derivation
  1. Initial program 39.4%

    \[\log \left(1 + x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lower-log1p.f64100.0

      \[\leadsto \color{blue}{\mathsf{log1p}\left(x\right)} \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(x\right)} \]
  5. Add Preprocessing

Alternative 2: 68.3% accurate, 3.6× speedup?

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

\\
\mathsf{fma}\left(\frac{x \cdot -0.25}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x, x\right)
\end{array}
Derivation
  1. Initial program 39.4%

    \[\log \left(1 + x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

      \[\leadsto \color{blue}{\left(x \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right) + 1\right)} \cdot x \]
    3. distribute-lft1-inN/A

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

      \[\leadsto \color{blue}{\left(\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot x\right)} \cdot x + x \]
    5. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot \left(x \cdot x\right)} + x \]
    6. unpow2N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{3}, \frac{-1}{2}\right), \color{blue}{x \cdot x}, x\right) \]
    13. lower-*.f6465.8

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), \color{blue}{x \cdot x}, x\right) \]
  5. Applied rewrites65.8%

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

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

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

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

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \frac{1}{3} + \frac{-1}{2}\right)} + x \]
    5. flip-+N/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{-1}{2} \cdot \frac{-1}{2}}{x \cdot \frac{1}{3} - \frac{-1}{2}}} + x \]
    6. associate-*r/N/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{-1}{2} \cdot \frac{-1}{2}\right), \frac{1}{x \cdot \frac{1}{3} - \frac{-1}{2}}, x\right)} \]
  7. Applied rewrites65.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, 0.1111111111111111, -0.25\right)\right), \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right)} \]
  8. Taylor expanded in x around 0

    \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(\frac{-1}{4} \cdot x\right)}, \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}, x\right) \]
  9. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(x \cdot -0.25\right)}, \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right) \]
  10. Applied rewrites65.7%

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

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

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

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \frac{1}{\color{blue}{x \cdot \frac{1}{3}} + \frac{1}{2}} + x \]
    4. flip-+N/A

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \frac{1}{\color{blue}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{1}{2} \cdot \frac{1}{2}}{x \cdot \frac{1}{3} - \frac{1}{2}}}} + x \]
    5. associate-/r/N/A

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \color{blue}{\left(\frac{1}{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{1}{2} \cdot \frac{1}{2}} \cdot \left(x \cdot \frac{1}{3} - \frac{1}{2}\right)\right)} + x \]
    6. associate-/r/N/A

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \color{blue}{\frac{1}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{1}{2} \cdot \frac{1}{2}}{x \cdot \frac{1}{3} - \frac{1}{2}}}} + x \]
    7. flip-+N/A

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot \left(\left(x \cdot \frac{-1}{4}\right) \cdot \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}\right)} + x \]
    13. *-commutativeN/A

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot \frac{-1}{4}\right) \cdot \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}, x, x\right)} \]
  12. Applied rewrites66.3%

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

Alternative 3: 68.3% accurate, 3.6× speedup?

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

\\
x \cdot \mathsf{fma}\left(x, \frac{-0.25}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, 1\right)
\end{array}
Derivation
  1. Initial program 39.4%

    \[\log \left(1 + x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

      \[\leadsto \color{blue}{\left(x \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right) + 1\right)} \cdot x \]
    3. distribute-lft1-inN/A

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

      \[\leadsto \color{blue}{\left(\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot x\right)} \cdot x + x \]
    5. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot \left(x \cdot x\right)} + x \]
    6. unpow2N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{3}, \frac{-1}{2}\right), \color{blue}{x \cdot x}, x\right) \]
    13. lower-*.f6465.8

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), \color{blue}{x \cdot x}, x\right) \]
  5. Applied rewrites65.8%

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

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

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

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

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \frac{1}{3} + \frac{-1}{2}\right)} + x \]
    5. flip-+N/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{-1}{2} \cdot \frac{-1}{2}}{x \cdot \frac{1}{3} - \frac{-1}{2}}} + x \]
    6. associate-*r/N/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{-1}{2} \cdot \frac{-1}{2}\right), \frac{1}{x \cdot \frac{1}{3} - \frac{-1}{2}}, x\right)} \]
  7. Applied rewrites65.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, 0.1111111111111111, -0.25\right)\right), \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right)} \]
  8. Taylor expanded in x around 0

    \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(\frac{-1}{4} \cdot x\right)}, \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}, x\right) \]
  9. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(x \cdot -0.25\right)}, \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right) \]
  10. Applied rewrites65.7%

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

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

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

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \frac{1}{\color{blue}{x \cdot \frac{1}{3}} + \frac{1}{2}} + x \]
    4. flip-+N/A

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \frac{1}{\color{blue}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{1}{2} \cdot \frac{1}{2}}{x \cdot \frac{1}{3} - \frac{1}{2}}}} + x \]
    5. associate-/r/N/A

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \color{blue}{\left(\frac{1}{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{1}{2} \cdot \frac{1}{2}} \cdot \left(x \cdot \frac{1}{3} - \frac{1}{2}\right)\right)} + x \]
    6. associate-/r/N/A

      \[\leadsto \left(x \cdot \left(x \cdot \frac{-1}{4}\right)\right) \cdot \color{blue}{\frac{1}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{1}{2} \cdot \frac{1}{2}}{x \cdot \frac{1}{3} - \frac{1}{2}}}} + x \]
    7. flip-+N/A

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot \left(\left(x \cdot \frac{-1}{4}\right) \cdot \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}\right)} + x \]
    13. *-commutativeN/A

      \[\leadsto \color{blue}{\left(\left(x \cdot \frac{-1}{4}\right) \cdot \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}\right) \cdot x} + x \]
    14. distribute-lft1-inN/A

      \[\leadsto \color{blue}{\left(\left(x \cdot \frac{-1}{4}\right) \cdot \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)} + 1\right) \cdot x} \]
  12. Applied rewrites66.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{-0.25}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, 1\right) \cdot x} \]
  13. Final simplification66.3%

    \[\leadsto x \cdot \mathsf{fma}\left(x, \frac{-0.25}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, 1\right) \]
  14. Add Preprocessing

Alternative 4: 68.0% accurate, 4.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + 1 \leq 2:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot -0.5, x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.25\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (+ x 1.0) 2.0) (fma x (* x -0.5) x) (* x 0.25)))
double code(double x) {
	double tmp;
	if ((x + 1.0) <= 2.0) {
		tmp = fma(x, (x * -0.5), x);
	} else {
		tmp = x * 0.25;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(x + 1.0) <= 2.0)
		tmp = fma(x, Float64(x * -0.5), x);
	else
		tmp = Float64(x * 0.25);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(x + 1.0), $MachinePrecision], 2.0], N[(x * N[(x * -0.5), $MachinePrecision] + x), $MachinePrecision], N[(x * 0.25), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x + 1 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot -0.5, x\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot 0.25\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 #s(literal 1 binary64) x) < 2

    1. Initial program 6.0%

      \[\log \left(1 + x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

        \[\leadsto x \cdot \color{blue}{\left(\frac{-1}{2} \cdot x + 1\right)} \]
      2. distribute-lft-inN/A

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x \cdot -0.5, x\right)} \]

    if 2 < (+.f64 #s(literal 1 binary64) x)

    1. Initial program 100.0%

      \[\log \left(1 + x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

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

        \[\leadsto \color{blue}{\left(x \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right) + 1\right)} \cdot x \]
      3. distribute-lft1-inN/A

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

        \[\leadsto \color{blue}{\left(\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot x\right)} \cdot x + x \]
      5. associate-*l*N/A

        \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot \left(x \cdot x\right)} + x \]
      6. unpow2N/A

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{3}, \frac{-1}{2}\right), \color{blue}{x \cdot x}, x\right) \]
      13. lower-*.f643.7

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), \color{blue}{x \cdot x}, x\right) \]
    5. Applied rewrites3.7%

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

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

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

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

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \frac{1}{3} + \frac{-1}{2}\right)} + x \]
      5. flip-+N/A

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{-1}{2} \cdot \frac{-1}{2}}{x \cdot \frac{1}{3} - \frac{-1}{2}}} + x \]
      6. associate-*r/N/A

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, 0.1111111111111111, -0.25\right)\right), \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right)} \]
    8. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(\frac{-1}{4} \cdot x\right)}, \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}, x\right) \]
    9. Step-by-step derivation
      1. *-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(x \cdot -0.25\right)}, \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right) \]
    10. Applied rewrites3.4%

      \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(x \cdot -0.25\right)}, \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right) \]
    11. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{1}{4} \cdot x} \]
    12. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{x \cdot \frac{1}{4}} \]
      2. lower-*.f645.3

        \[\leadsto \color{blue}{x \cdot 0.25} \]
    13. Applied rewrites5.3%

      \[\leadsto \color{blue}{x \cdot 0.25} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + 1 \leq 2:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot -0.5, x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.25\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 67.7% accurate, 5.8× speedup?

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

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

    \[\log \left(1 + x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

      \[\leadsto \color{blue}{\left(x \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right) + 1\right)} \cdot x \]
    3. distribute-lft1-inN/A

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

      \[\leadsto \color{blue}{\left(\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot x\right)} \cdot x + x \]
    5. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot \left(x \cdot x\right)} + x \]
    6. unpow2N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{3}, \frac{-1}{2}\right), \color{blue}{x \cdot x}, x\right) \]
    13. lower-*.f6465.8

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), \color{blue}{x \cdot x}, x\right) \]
  5. Applied rewrites65.8%

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

Alternative 6: 66.7% accurate, 6.1× speedup?

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

\\
\mathsf{fma}\left(x \cdot 0.3333333333333333, x \cdot x, x\right)
\end{array}
Derivation
  1. Initial program 39.4%

    \[\log \left(1 + x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

      \[\leadsto \color{blue}{\left(x \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right) + 1\right)} \cdot x \]
    3. distribute-lft1-inN/A

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

      \[\leadsto \color{blue}{\left(\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot x\right)} \cdot x + x \]
    5. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot \left(x \cdot x\right)} + x \]
    6. unpow2N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{3}, \frac{-1}{2}\right), \color{blue}{x \cdot x}, x\right) \]
    13. lower-*.f6465.8

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), \color{blue}{x \cdot x}, x\right) \]
  5. Applied rewrites65.8%

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

    \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{3} \cdot x}, x \cdot x, x\right) \]
  7. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \frac{1}{3}}, x \cdot x, x\right) \]
    2. lower-*.f6465.5

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot 0.3333333333333333}, x \cdot x, x\right) \]
  8. Applied rewrites65.5%

    \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot 0.3333333333333333}, x \cdot x, x\right) \]
  9. Add Preprocessing

Alternative 7: 13.3% accurate, 17.3× speedup?

\[\begin{array}{l} \\ x \cdot 0.25 \end{array} \]
(FPCore (x) :precision binary64 (* x 0.25))
double code(double x) {
	return x * 0.25;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * 0.25d0
end function
public static double code(double x) {
	return x * 0.25;
}
def code(x):
	return x * 0.25
function code(x)
	return Float64(x * 0.25)
end
function tmp = code(x)
	tmp = x * 0.25;
end
code[x_] := N[(x * 0.25), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.25
\end{array}
Derivation
  1. Initial program 39.4%

    \[\log \left(1 + x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

      \[\leadsto \color{blue}{\left(x \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right) + 1\right)} \cdot x \]
    3. distribute-lft1-inN/A

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

      \[\leadsto \color{blue}{\left(\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot x\right)} \cdot x + x \]
    5. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot x - \frac{1}{2}\right) \cdot \left(x \cdot x\right)} + x \]
    6. unpow2N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{3}, \frac{-1}{2}\right), \color{blue}{x \cdot x}, x\right) \]
    13. lower-*.f6465.8

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), \color{blue}{x \cdot x}, x\right) \]
  5. Applied rewrites65.8%

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

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

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

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

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \frac{1}{3} + \frac{-1}{2}\right)} + x \]
    5. flip-+N/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{-1}{2} \cdot \frac{-1}{2}}{x \cdot \frac{1}{3} - \frac{-1}{2}}} + x \]
    6. associate-*r/N/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\left(x \cdot \frac{1}{3}\right) \cdot \left(x \cdot \frac{1}{3}\right) - \frac{-1}{2} \cdot \frac{-1}{2}\right), \frac{1}{x \cdot \frac{1}{3} - \frac{-1}{2}}, x\right)} \]
  7. Applied rewrites65.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, 0.1111111111111111, -0.25\right)\right), \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right)} \]
  8. Taylor expanded in x around 0

    \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(\frac{-1}{4} \cdot x\right)}, \frac{1}{\mathsf{fma}\left(x, \frac{1}{3}, \frac{1}{2}\right)}, x\right) \]
  9. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(x \cdot -0.25\right)}, \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right) \]
  10. Applied rewrites65.7%

    \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(x \cdot -0.25\right)}, \frac{1}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, x\right) \]
  11. Taylor expanded in x around inf

    \[\leadsto \color{blue}{\frac{1}{4} \cdot x} \]
  12. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{x \cdot \frac{1}{4}} \]
    2. lower-*.f6413.0

      \[\leadsto \color{blue}{x \cdot 0.25} \]
  13. Applied rewrites13.0%

    \[\leadsto \color{blue}{x \cdot 0.25} \]
  14. Add Preprocessing

Developer Target 1: 99.6% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;1 + x = 1:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \log \left(1 + x\right)}{\left(1 + x\right) - 1}\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024219 
(FPCore (x)
  :name "ln(1 + x)"
  :precision binary64

  :alt
  (! :herbie-platform default (if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1))))

  (log (+ 1.0 x)))