Rust f64::atanh

Percentage Accurate: 50.4% → 99.9%
Time: 1.9s
Alternatives: 5
Speedup: 3.4×

Specification

?
\[\tanh^{-1} x \]
(FPCore (x)
  :precision binary64
  (atanh x))
double code(double x) {
	return atanh(x);
}
def code(x):
	return math.atanh(x)
function code(x)
	return atanh(x)
end
function tmp = code(x)
	tmp = atanh(x);
end
code[x_] := N[ArcTanh[x], $MachinePrecision]
\tanh^{-1} x

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 5 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: 50.4% accurate, 1.0× speedup?

\[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
(FPCore (x)
  :precision binary64
  (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
double code(double x) {
	return 0.5 * log1p(((2.0 * x) / (1.0 - x)));
}
public static double code(double x) {
	return 0.5 * Math.log1p(((2.0 * x) / (1.0 - x)));
}
def code(x):
	return 0.5 * math.log1p(((2.0 * x) / (1.0 - x)))
function code(x)
	return Float64(0.5 * log1p(Float64(Float64(2.0 * x) / Float64(1.0 - x))))
end
code[x_] := N[(0.5 * N[Log[1 + N[(N[(2.0 * x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)

Alternative 1: 99.9% accurate, 0.6× speedup?

\[\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.023:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\frac{\left|x\right| + \left|x\right|}{1 - \left|x\right|}\right)\\ \mathbf{else}:\\ \;\;\;\;\log 1\\ \end{array} \]
(FPCore (x)
  :precision binary64
  (*
 (copysign 1.0 x)
 (if (<= (fabs x) 0.023)
   (* 0.5 (log1p (/ (+ (fabs x) (fabs x)) (- 1.0 (fabs x)))))
   (log 1.0))))
double code(double x) {
	double tmp;
	if (fabs(x) <= 0.023) {
		tmp = 0.5 * log1p(((fabs(x) + fabs(x)) / (1.0 - fabs(x))));
	} else {
		tmp = log(1.0);
	}
	return copysign(1.0, x) * tmp;
}
public static double code(double x) {
	double tmp;
	if (Math.abs(x) <= 0.023) {
		tmp = 0.5 * Math.log1p(((Math.abs(x) + Math.abs(x)) / (1.0 - Math.abs(x))));
	} else {
		tmp = Math.log(1.0);
	}
	return Math.copySign(1.0, x) * tmp;
}
def code(x):
	tmp = 0
	if math.fabs(x) <= 0.023:
		tmp = 0.5 * math.log1p(((math.fabs(x) + math.fabs(x)) / (1.0 - math.fabs(x))))
	else:
		tmp = math.log(1.0)
	return math.copysign(1.0, x) * tmp
function code(x)
	tmp = 0.0
	if (abs(x) <= 0.023)
		tmp = Float64(0.5 * log1p(Float64(Float64(abs(x) + abs(x)) / Float64(1.0 - abs(x)))));
	else
		tmp = log(1.0);
	end
	return Float64(copysign(1.0, x) * tmp)
end
code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 0.023], N[(0.5 * N[Log[1 + N[(N[(N[Abs[x], $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Log[1.0], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.023:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\frac{\left|x\right| + \left|x\right|}{1 - \left|x\right|}\right)\\

\mathbf{else}:\\
\;\;\;\;\log 1\\


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

    1. Initial program 50.4%

      \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \mathsf{log1p}\left(\frac{\color{blue}{2 \cdot x}}{1 - x}\right) \]
      2. count-2-revN/A

        \[\leadsto \frac{1}{2} \cdot \mathsf{log1p}\left(\frac{\color{blue}{x + x}}{1 - x}\right) \]
      3. lower-+.f6450.4%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\frac{\color{blue}{x + x}}{1 - x}\right) \]
    3. Applied rewrites50.4%

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

    if 0.023 < x

    1. Initial program 50.4%

      \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \log \left(\sqrt{\color{blue}{\mathsf{fma}\left(\frac{x}{1 - x}, 2, 1\right)}}\right) \]
      13. lower-/.f644.1%

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

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

      \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
    5. Step-by-step derivation
      1. lower-+.f644.4%

        \[\leadsto \log \left(1 + \color{blue}{x}\right) \]
    6. Applied rewrites4.4%

      \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
    7. Taylor expanded in x around 0

      \[\leadsto \log 1 \]
    8. Step-by-step derivation
      1. Applied rewrites52.3%

        \[\leadsto \log 1 \]
    9. Recombined 2 regimes into one program.
    10. Add Preprocessing

    Alternative 2: 99.6% accurate, 0.7× speedup?

    \[\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.023:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{fma}\left(\left|x\right|, \left|x\right|, \left|x\right|\right) \cdot 2\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log 1\\ \end{array} \]
    (FPCore (x)
      :precision binary64
      (*
     (copysign 1.0 x)
     (if (<= (fabs x) 0.023)
       (* (log1p (* (fma (fabs x) (fabs x) (fabs x)) 2.0)) 0.5)
       (log 1.0))))
    double code(double x) {
    	double tmp;
    	if (fabs(x) <= 0.023) {
    		tmp = log1p((fma(fabs(x), fabs(x), fabs(x)) * 2.0)) * 0.5;
    	} else {
    		tmp = log(1.0);
    	}
    	return copysign(1.0, x) * tmp;
    }
    
    function code(x)
    	tmp = 0.0
    	if (abs(x) <= 0.023)
    		tmp = Float64(log1p(Float64(fma(abs(x), abs(x), abs(x)) * 2.0)) * 0.5);
    	else
    		tmp = log(1.0);
    	end
    	return Float64(copysign(1.0, x) * tmp)
    end
    
    code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 0.023], N[(N[Log[1 + N[(N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[Log[1.0], $MachinePrecision]]), $MachinePrecision]
    
    \mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
    \mathbf{if}\;\left|x\right| \leq 0.023:\\
    \;\;\;\;\mathsf{log1p}\left(\mathsf{fma}\left(\left|x\right|, \left|x\right|, \left|x\right|\right) \cdot 2\right) \cdot 0.5\\
    
    \mathbf{else}:\\
    \;\;\;\;\log 1\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 0.023

      1. Initial program 50.4%

        \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \log \left(\mathsf{fma}\left(x \cdot \color{blue}{\left(1 + x\right)}, 2, 1\right)\right) \cdot \frac{1}{2} \]
        2. lower-+.f645.0%

          \[\leadsto \log \left(\mathsf{fma}\left(x \cdot \left(1 + \color{blue}{x}\right), 2, 1\right)\right) \cdot 0.5 \]
      6. Applied rewrites5.0%

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

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

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

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

          \[\leadsto \color{blue}{\mathsf{log1p}\left(\left(x \cdot \left(1 + x\right)\right) \cdot 2\right)} \cdot \frac{1}{2} \]
        5. lower-*.f6451.1%

          \[\leadsto \mathsf{log1p}\left(\color{blue}{\left(x \cdot \left(1 + x\right)\right) \cdot 2}\right) \cdot 0.5 \]
        6. lift-*.f64N/A

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

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

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

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

          \[\leadsto \mathsf{log1p}\left(\left(x \cdot x + \color{blue}{x}\right) \cdot 2\right) \cdot \frac{1}{2} \]
        11. lower-fma.f6451.1%

          \[\leadsto \mathsf{log1p}\left(\mathsf{fma}\left(x, \color{blue}{x}, x\right) \cdot 2\right) \cdot 0.5 \]
      8. Applied rewrites51.1%

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

      if 0.023 < x

      1. Initial program 50.4%

        \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \log \left(\sqrt{\color{blue}{\mathsf{fma}\left(\frac{x}{1 - x}, 2, 1\right)}}\right) \]
        13. lower-/.f644.1%

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

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

        \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
      5. Step-by-step derivation
        1. lower-+.f644.4%

          \[\leadsto \log \left(1 + \color{blue}{x}\right) \]
      6. Applied rewrites4.4%

        \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
      7. Taylor expanded in x around 0

        \[\leadsto \log 1 \]
      8. Step-by-step derivation
        1. Applied rewrites52.3%

          \[\leadsto \log 1 \]
      9. Recombined 2 regimes into one program.
      10. Add Preprocessing

      Alternative 3: 99.1% accurate, 0.8× speedup?

      \[\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.023:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\left|x\right| \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\log 1\\ \end{array} \]
      (FPCore (x)
        :precision binary64
        (*
       (copysign 1.0 x)
       (if (<= (fabs x) 0.023) (* 0.5 (log1p (* (fabs x) 2.0))) (log 1.0))))
      double code(double x) {
      	double tmp;
      	if (fabs(x) <= 0.023) {
      		tmp = 0.5 * log1p((fabs(x) * 2.0));
      	} else {
      		tmp = log(1.0);
      	}
      	return copysign(1.0, x) * tmp;
      }
      
      public static double code(double x) {
      	double tmp;
      	if (Math.abs(x) <= 0.023) {
      		tmp = 0.5 * Math.log1p((Math.abs(x) * 2.0));
      	} else {
      		tmp = Math.log(1.0);
      	}
      	return Math.copySign(1.0, x) * tmp;
      }
      
      def code(x):
      	tmp = 0
      	if math.fabs(x) <= 0.023:
      		tmp = 0.5 * math.log1p((math.fabs(x) * 2.0))
      	else:
      		tmp = math.log(1.0)
      	return math.copysign(1.0, x) * tmp
      
      function code(x)
      	tmp = 0.0
      	if (abs(x) <= 0.023)
      		tmp = Float64(0.5 * log1p(Float64(abs(x) * 2.0)));
      	else
      		tmp = log(1.0);
      	end
      	return Float64(copysign(1.0, x) * tmp)
      end
      
      code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 0.023], N[(0.5 * N[Log[1 + N[(N[Abs[x], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Log[1.0], $MachinePrecision]]), $MachinePrecision]
      
      \mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
      \mathbf{if}\;\left|x\right| \leq 0.023:\\
      \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\left|x\right| \cdot 2\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\log 1\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < 0.023

        1. Initial program 50.4%

          \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
        2. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \frac{1}{2} \cdot \mathsf{log1p}\left(\frac{\color{blue}{2 \cdot x}}{1 - x}\right) \]
          2. count-2-revN/A

            \[\leadsto \frac{1}{2} \cdot \mathsf{log1p}\left(\frac{\color{blue}{x + x}}{1 - x}\right) \]
          3. lower-+.f6450.4%

            \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\frac{\color{blue}{x + x}}{1 - x}\right) \]
        3. Applied rewrites50.4%

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

          \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{x \cdot \left(2 + 2 \cdot x\right)}\right) \]
        5. Step-by-step derivation
          1. lower-*.f64N/A

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

            \[\leadsto \frac{1}{2} \cdot \mathsf{log1p}\left(x \cdot \left(2 + \color{blue}{2 \cdot x}\right)\right) \]
          3. lower-*.f6451.1%

            \[\leadsto 0.5 \cdot \mathsf{log1p}\left(x \cdot \left(2 + 2 \cdot \color{blue}{x}\right)\right) \]
        6. Applied rewrites51.1%

          \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{x \cdot \left(2 + 2 \cdot x\right)}\right) \]
        7. Taylor expanded in x around 0

          \[\leadsto 0.5 \cdot \mathsf{log1p}\left(x \cdot 2\right) \]
        8. Step-by-step derivation
          1. Applied rewrites50.2%

            \[\leadsto 0.5 \cdot \mathsf{log1p}\left(x \cdot 2\right) \]

          if 0.023 < x

          1. Initial program 50.4%

            \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
          2. Step-by-step derivation
            1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \log \left(\sqrt{\color{blue}{\mathsf{fma}\left(\frac{x}{1 - x}, 2, 1\right)}}\right) \]
            13. lower-/.f644.1%

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

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

            \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
          5. Step-by-step derivation
            1. lower-+.f644.4%

              \[\leadsto \log \left(1 + \color{blue}{x}\right) \]
          6. Applied rewrites4.4%

            \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
          7. Taylor expanded in x around 0

            \[\leadsto \log 1 \]
          8. Step-by-step derivation
            1. Applied rewrites52.3%

              \[\leadsto \log 1 \]
          9. Recombined 2 regimes into one program.
          10. Add Preprocessing

          Alternative 4: 52.3% accurate, 3.4× speedup?

          \[\log 1 \]
          (FPCore (x)
            :precision binary64
            (log 1.0))
          double code(double x) {
          	return log(1.0);
          }
          
          real(8) function code(x)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              code = log(1.0d0)
          end function
          
          public static double code(double x) {
          	return Math.log(1.0);
          }
          
          def code(x):
          	return math.log(1.0)
          
          function code(x)
          	return log(1.0)
          end
          
          function tmp = code(x)
          	tmp = log(1.0);
          end
          
          code[x_] := N[Log[1.0], $MachinePrecision]
          
          \log 1
          
          Derivation
          1. Initial program 50.4%

            \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
          2. Step-by-step derivation
            1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \log \left(\sqrt{\color{blue}{\mathsf{fma}\left(\frac{x}{1 - x}, 2, 1\right)}}\right) \]
            13. lower-/.f644.1%

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

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

            \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
          5. Step-by-step derivation
            1. lower-+.f644.4%

              \[\leadsto \log \left(1 + \color{blue}{x}\right) \]
          6. Applied rewrites4.4%

            \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
          7. Taylor expanded in x around 0

            \[\leadsto \log 1 \]
          8. Step-by-step derivation
            1. Applied rewrites52.3%

              \[\leadsto \log 1 \]
            2. Add Preprocessing

            Alternative 5: 4.6% accurate, 5.0× speedup?

            \[\frac{1}{x} \]
            (FPCore (x)
              :precision binary64
              (/ 1.0 x))
            double code(double x) {
            	return 1.0 / x;
            }
            
            real(8) function code(x)
            use fmin_fmax_functions
                real(8), intent (in) :: x
                code = 1.0d0 / x
            end function
            
            public static double code(double x) {
            	return 1.0 / x;
            }
            
            def code(x):
            	return 1.0 / x
            
            function code(x)
            	return Float64(1.0 / x)
            end
            
            function tmp = code(x)
            	tmp = 1.0 / x;
            end
            
            code[x_] := N[(1.0 / x), $MachinePrecision]
            
            \frac{1}{x}
            
            Derivation
            1. Initial program 50.4%

              \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
            2. Step-by-step derivation
              1. lift-log1p.f64N/A

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

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

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

                \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\log \left(\left|1 \cdot \left(1 - x\right) + 2 \cdot x\right|\right) - \log \left(\left|1 - x\right|\right)\right)} \]
              5. diff-logN/A

                \[\leadsto \frac{1}{2} \cdot \color{blue}{\log \left(\frac{\left|1 \cdot \left(1 - x\right) + 2 \cdot x\right|}{\left|1 - x\right|}\right)} \]
              6. fabs-divN/A

                \[\leadsto \frac{1}{2} \cdot \log \color{blue}{\left(\left|\frac{1 \cdot \left(1 - x\right) + 2 \cdot x}{1 - x}\right|\right)} \]
              7. add-to-fractionN/A

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

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

                \[\leadsto \frac{1}{2} \cdot \color{blue}{\log \left(\left|1 + \frac{2 \cdot x}{1 - x}\right|\right)} \]
              10. add-flipN/A

                \[\leadsto \frac{1}{2} \cdot \log \left(\left|\color{blue}{1 - \left(\mathsf{neg}\left(\frac{2 \cdot x}{1 - x}\right)\right)}\right|\right) \]
              11. fabs-subN/A

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

                \[\leadsto \frac{1}{2} \cdot \log \color{blue}{\left(\left|\left(\mathsf{neg}\left(\frac{2 \cdot x}{1 - x}\right)\right) - 1\right|\right)} \]
              13. sub-flipN/A

                \[\leadsto \frac{1}{2} \cdot \log \left(\left|\color{blue}{\left(\mathsf{neg}\left(\frac{2 \cdot x}{1 - x}\right)\right) + \left(\mathsf{neg}\left(1\right)\right)}\right|\right) \]
              14. metadata-evalN/A

                \[\leadsto \frac{1}{2} \cdot \log \left(\left|\left(\mathsf{neg}\left(\frac{2 \cdot x}{1 - x}\right)\right) + \color{blue}{-1}\right|\right) \]
            3. Applied rewrites51.7%

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

              \[\leadsto \color{blue}{\frac{1}{x}} \]
            5. Step-by-step derivation
              1. lower-/.f644.6%

                \[\leadsto \frac{1}{\color{blue}{x}} \]
            6. Applied rewrites4.6%

              \[\leadsto \color{blue}{\frac{1}{x}} \]
            7. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2025313 -o setup:search
            (FPCore (x)
              :name "Rust f64::atanh"
              :precision binary64
              (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))