ln(1 + x)

Percentage Accurate: 39.2% → 100.0%
Time: 10.6s
Alternatives: 6
Speedup: 17.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 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.

Initial Program: 39.2% 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.2%

    \[\log \left(1 + x\right) \]
  2. Step-by-step derivation
    1. log1p-defineN/A

      \[\leadsto \mathsf{log1p}\left(x\right) \]
    2. log1p-lowering-log1p.f64100.0%

      \[\leadsto \mathsf{log1p.f64}\left(x\right) \]
  3. Simplified100.0%

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

Alternative 2: 70.8% accurate, 8.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.45:\\ \;\;\;\;x + x \cdot \left(x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 1.45) (+ x (* x (* x -0.5))) 2.0))
double code(double x) {
	double tmp;
	if (x <= 1.45) {
		tmp = x + (x * (x * -0.5));
	} else {
		tmp = 2.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.45d0) then
        tmp = x + (x * (x * (-0.5d0)))
    else
        tmp = 2.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 1.45) {
		tmp = x + (x * (x * -0.5));
	} else {
		tmp = 2.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 1.45:
		tmp = x + (x * (x * -0.5))
	else:
		tmp = 2.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 1.45)
		tmp = Float64(x + Float64(x * Float64(x * -0.5)));
	else
		tmp = 2.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.45)
		tmp = x + (x * (x * -0.5));
	else
		tmp = 2.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 1.45], N[(x + N[(x * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.45:\\
\;\;\;\;x + x \cdot \left(x \cdot -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.44999999999999996

    1. Initial program 7.9%

      \[\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. *-lowering-*.f64N/A

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

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

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{-1}{2}}\right)\right)\right) \]
      4. *-lowering-*.f6499.1%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{-1}{2}}\right)\right)\right) \]
    5. Simplified99.1%

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

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

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(x \cdot \frac{-1}{2}\right)\right), x\right) \]
      6. *-lowering-*.f6499.1%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{2}\right)\right), x\right) \]
    7. Applied egg-rr99.1%

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

    if 1.44999999999999996 < 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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
      9. *-lowering-*.f644.1%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
    5. Simplified4.1%

      \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)} \]
    6. Step-by-step derivation
      1. flip3-+N/A

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)}^{3}}{1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)\right)}}}\right)\right) \]
      6. flip3-+N/A

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

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

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

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)}\right)\right)\right)\right) \]
    7. Applied egg-rr4.1%

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

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(1 + \frac{1}{2} \cdot x\right)}\right) \]
    9. Step-by-step derivation
      1. +-lowering-+.f64N/A

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

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
      3. *-lowering-*.f6414.5%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
    10. Simplified14.5%

      \[\leadsto \frac{x}{\color{blue}{1 + x \cdot 0.5}} \]
    11. Taylor expanded in x around inf

      \[\leadsto \color{blue}{2} \]
    12. Step-by-step derivation
      1. Simplified14.5%

        \[\leadsto \color{blue}{2} \]
    13. Recombined 2 regimes into one program.
    14. Final simplification70.3%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.45:\\ \;\;\;\;x + x \cdot \left(x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]
    15. Add Preprocessing

    Alternative 3: 70.8% accurate, 8.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.45:\\ \;\;\;\;x \cdot \left(1 + x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \end{array} \]
    (FPCore (x) :precision binary64 (if (<= x 1.45) (* x (+ 1.0 (* x -0.5))) 2.0))
    double code(double x) {
    	double tmp;
    	if (x <= 1.45) {
    		tmp = x * (1.0 + (x * -0.5));
    	} else {
    		tmp = 2.0;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= 1.45d0) then
            tmp = x * (1.0d0 + (x * (-0.5d0)))
        else
            tmp = 2.0d0
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= 1.45) {
    		tmp = x * (1.0 + (x * -0.5));
    	} else {
    		tmp = 2.0;
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= 1.45:
    		tmp = x * (1.0 + (x * -0.5))
    	else:
    		tmp = 2.0
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= 1.45)
    		tmp = Float64(x * Float64(1.0 + Float64(x * -0.5)));
    	else
    		tmp = 2.0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= 1.45)
    		tmp = x * (1.0 + (x * -0.5));
    	else
    		tmp = 2.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, 1.45], N[(x * N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq 1.45:\\
    \;\;\;\;x \cdot \left(1 + x \cdot -0.5\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;2\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1.44999999999999996

      1. Initial program 7.9%

        \[\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. *-lowering-*.f64N/A

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

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

          \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{-1}{2}}\right)\right)\right) \]
        4. *-lowering-*.f6499.1%

          \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{-1}{2}}\right)\right)\right) \]
      5. Simplified99.1%

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

      if 1.44999999999999996 < 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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

          \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
        9. *-lowering-*.f644.1%

          \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
      5. Simplified4.1%

        \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)} \]
      6. Step-by-step derivation
        1. flip3-+N/A

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

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

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

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

          \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)}^{3}}{1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)\right)}}}\right)\right) \]
        6. flip3-+N/A

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

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

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

          \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)}\right)\right)\right)\right) \]
      7. Applied egg-rr4.1%

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

        \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(1 + \frac{1}{2} \cdot x\right)}\right) \]
      9. Step-by-step derivation
        1. +-lowering-+.f64N/A

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

          \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
        3. *-lowering-*.f6414.5%

          \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
      10. Simplified14.5%

        \[\leadsto \frac{x}{\color{blue}{1 + x \cdot 0.5}} \]
      11. Taylor expanded in x around inf

        \[\leadsto \color{blue}{2} \]
      12. Step-by-step derivation
        1. Simplified14.5%

          \[\leadsto \color{blue}{2} \]
      13. Recombined 2 regimes into one program.
      14. Add Preprocessing

      Alternative 4: 70.8% accurate, 14.7× speedup?

      \[\begin{array}{l} \\ \frac{x}{1 + x \cdot 0.5} \end{array} \]
      (FPCore (x) :precision binary64 (/ x (+ 1.0 (* x 0.5))))
      double code(double x) {
      	return x / (1.0 + (x * 0.5));
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          code = x / (1.0d0 + (x * 0.5d0))
      end function
      
      public static double code(double x) {
      	return x / (1.0 + (x * 0.5));
      }
      
      def code(x):
      	return x / (1.0 + (x * 0.5))
      
      function code(x)
      	return Float64(x / Float64(1.0 + Float64(x * 0.5)))
      end
      
      function tmp = code(x)
      	tmp = x / (1.0 + (x * 0.5));
      end
      
      code[x_] := N[(x / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{x}{1 + x \cdot 0.5}
      \end{array}
      
      Derivation
      1. Initial program 39.2%

        \[\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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

          \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
        9. *-lowering-*.f6467.0%

          \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
      5. Simplified67.0%

        \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)} \]
      6. Step-by-step derivation
        1. flip3-+N/A

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

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

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

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

          \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)}^{3}}{1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)\right)}}}\right)\right) \]
        6. flip3-+N/A

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

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

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

          \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)}\right)\right)\right)\right) \]
      7. Applied egg-rr67.0%

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

        \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(1 + \frac{1}{2} \cdot x\right)}\right) \]
      9. Step-by-step derivation
        1. +-lowering-+.f64N/A

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

          \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
        3. *-lowering-*.f6470.4%

          \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
      10. Simplified70.4%

        \[\leadsto \frac{x}{\color{blue}{1 + x \cdot 0.5}} \]
      11. Add Preprocessing

      Alternative 5: 70.0% accurate, 17.1× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \end{array} \]
      (FPCore (x) :precision binary64 (if (<= x 2.0) x 2.0))
      double code(double x) {
      	double tmp;
      	if (x <= 2.0) {
      		tmp = x;
      	} else {
      		tmp = 2.0;
      	}
      	return tmp;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          real(8) :: tmp
          if (x <= 2.0d0) then
              tmp = x
          else
              tmp = 2.0d0
          end if
          code = tmp
      end function
      
      public static double code(double x) {
      	double tmp;
      	if (x <= 2.0) {
      		tmp = x;
      	} else {
      		tmp = 2.0;
      	}
      	return tmp;
      }
      
      def code(x):
      	tmp = 0
      	if x <= 2.0:
      		tmp = x
      	else:
      		tmp = 2.0
      	return tmp
      
      function code(x)
      	tmp = 0.0
      	if (x <= 2.0)
      		tmp = x;
      	else
      		tmp = 2.0;
      	end
      	return tmp
      end
      
      function tmp_2 = code(x)
      	tmp = 0.0;
      	if (x <= 2.0)
      		tmp = x;
      	else
      		tmp = 2.0;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_] := If[LessEqual[x, 2.0], x, 2.0]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq 2:\\
      \;\;\;\;x\\
      
      \mathbf{else}:\\
      \;\;\;\;2\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < 2

        1. Initial program 8.4%

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

          \[\leadsto \color{blue}{x} \]
        4. Step-by-step derivation
          1. Simplified97.9%

            \[\leadsto \color{blue}{x} \]

          if 2 < 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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

              \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
            9. *-lowering-*.f643.9%

              \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
          5. Simplified3.9%

            \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)} \]
          6. Step-by-step derivation
            1. flip3-+N/A

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

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

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

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

              \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)}^{3}}{1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)\right)}}}\right)\right) \]
            6. flip3-+N/A

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

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

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

              \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)}\right)\right)\right)\right) \]
          7. Applied egg-rr3.9%

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

            \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(1 + \frac{1}{2} \cdot x\right)}\right) \]
          9. Step-by-step derivation
            1. +-lowering-+.f64N/A

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

              \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
            3. *-lowering-*.f6414.4%

              \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
          10. Simplified14.4%

            \[\leadsto \frac{x}{\color{blue}{1 + x \cdot 0.5}} \]
          11. Taylor expanded in x around inf

            \[\leadsto \color{blue}{2} \]
          12. Step-by-step derivation
            1. Simplified14.4%

              \[\leadsto \color{blue}{2} \]
          13. Recombined 2 regimes into one program.
          14. Add Preprocessing

          Alternative 6: 7.4% accurate, 103.0× speedup?

          \[\begin{array}{l} \\ 2 \end{array} \]
          (FPCore (x) :precision binary64 2.0)
          double code(double x) {
          	return 2.0;
          }
          
          real(8) function code(x)
              real(8), intent (in) :: x
              code = 2.0d0
          end function
          
          public static double code(double x) {
          	return 2.0;
          }
          
          def code(x):
          	return 2.0
          
          function code(x)
          	return 2.0
          end
          
          function tmp = code(x)
          	tmp = 2.0;
          end
          
          code[x_] := 2.0
          
          \begin{array}{l}
          
          \\
          2
          \end{array}
          
          Derivation
          1. Initial program 39.2%

            \[\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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

              \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
            9. *-lowering-*.f6467.0%

              \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{3}}\right)\right)\right)\right)\right) \]
          5. Simplified67.0%

            \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(-0.5 + x \cdot 0.3333333333333333\right)\right)} \]
          6. Step-by-step derivation
            1. flip3-+N/A

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

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

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

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

              \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)}^{3}}{1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)\right)\right)}}}\right)\right) \]
            6. flip3-+N/A

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

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

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

              \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{-1}{2} + x \cdot \frac{1}{3}\right)}\right)\right)\right)\right) \]
          7. Applied egg-rr67.0%

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

            \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(1 + \frac{1}{2} \cdot x\right)}\right) \]
          9. Step-by-step derivation
            1. +-lowering-+.f64N/A

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

              \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
            3. *-lowering-*.f6470.4%

              \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
          10. Simplified70.4%

            \[\leadsto \frac{x}{\color{blue}{1 + x \cdot 0.5}} \]
          11. Taylor expanded in x around inf

            \[\leadsto \color{blue}{2} \]
          12. Step-by-step derivation
            1. Simplified7.4%

              \[\leadsto \color{blue}{2} \]
            2. Add Preprocessing

            Developer Target 1: 99.6% accurate, 0.9× 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 2024161 
            (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)))