Rust f64::atanh

Percentage Accurate: 100.0% → 100.0%
Time: 2.3s
Alternatives: 8
Speedup: 1.0×

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

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

    \[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-+.f64100.0%

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

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

Alternative 2: 99.0% accurate, 0.8× speedup?

\[\mathsf{copysign}\left(1, x\right) \cdot \left(0.5 \cdot \mathsf{log1p}\left(\left|x\right| \cdot \left(\left(2 + \left|x\right|\right) + \left|x\right|\right)\right)\right) \]
(FPCore (x)
  :precision binary64
  (*
 (copysign 1.0 x)
 (* 0.5 (log1p (* (fabs x) (+ (+ 2.0 (fabs x)) (fabs x)))))))
double code(double x) {
	return copysign(1.0, x) * (0.5 * log1p((fabs(x) * ((2.0 + fabs(x)) + fabs(x)))));
}
public static double code(double x) {
	return Math.copySign(1.0, x) * (0.5 * Math.log1p((Math.abs(x) * ((2.0 + Math.abs(x)) + Math.abs(x)))));
}
def code(x):
	return math.copysign(1.0, x) * (0.5 * math.log1p((math.fabs(x) * ((2.0 + math.fabs(x)) + math.fabs(x)))))
function code(x)
	return Float64(copysign(1.0, x) * Float64(0.5 * log1p(Float64(abs(x) * Float64(Float64(2.0 + abs(x)) + abs(x))))))
end
code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(0.5 * N[Log[1 + N[(N[Abs[x], $MachinePrecision] * N[(N[(2.0 + N[Abs[x], $MachinePrecision]), $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \left(0.5 \cdot \mathsf{log1p}\left(\left|x\right| \cdot \left(\left(2 + \left|x\right|\right) + \left|x\right|\right)\right)\right)
Derivation
  1. Initial program 100.0%

    \[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{2 \cdot x}{\color{blue}{1 - x}}\right) \]
    2. flip--N/A

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

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

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

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

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

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

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

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

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\color{blue}{\frac{1 \cdot 1 - x \cdot 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-*.f6499.0%

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(x \cdot \left(\left(2 + x\right) + x\right)\right) \]
  8. Applied rewrites98.9%

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(x \cdot \left(\left(2 + x\right) + \color{blue}{x}\right)\right) \]
  9. Add Preprocessing

Alternative 3: 98.9% accurate, 0.8× speedup?

\[\mathsf{copysign}\left(1, x\right) \cdot \left(\mathsf{log1p}\left(\mathsf{fma}\left(2, \left|x\right|, 2\right) \cdot \left|x\right|\right) \cdot 0.5\right) \]
(FPCore (x)
  :precision binary64
  (*
 (copysign 1.0 x)
 (* (log1p (* (fma 2.0 (fabs x) 2.0) (fabs x))) 0.5)))
double code(double x) {
	return copysign(1.0, x) * (log1p((fma(2.0, fabs(x), 2.0) * fabs(x))) * 0.5);
}
function code(x)
	return Float64(copysign(1.0, x) * Float64(log1p(Float64(fma(2.0, abs(x), 2.0) * abs(x))) * 0.5))
end
code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[Log[1 + N[(N[(2.0 * N[Abs[x], $MachinePrecision] + 2.0), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \left(\mathsf{log1p}\left(\mathsf{fma}\left(2, \left|x\right|, 2\right) \cdot \left|x\right|\right) \cdot 0.5\right)
Derivation
  1. Initial program 100.0%

    \[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. lift-log1p.f64N/A

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

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

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

      \[\leadsto \color{blue}{\log \left(1 + \frac{2 \cdot x}{1 - x}\right) \cdot \frac{1}{2}} \]
  3. Applied rewrites8.5%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{log1p}\left(\left(2 \cdot x + 2\right) \cdot x\right) \cdot \frac{1}{2} \]
    9. lower-fma.f6499.0%

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

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

Alternative 4: 97.9% accurate, 1.0× speedup?

\[\mathsf{copysign}\left(1, x\right) \cdot \left(0.5 \cdot \mathsf{log1p}\left(2 \cdot \left|x\right|\right)\right) \]
(FPCore (x)
  :precision binary64
  (* (copysign 1.0 x) (* 0.5 (log1p (* 2.0 (fabs x))))))
double code(double x) {
	return copysign(1.0, x) * (0.5 * log1p((2.0 * fabs(x))));
}
public static double code(double x) {
	return Math.copySign(1.0, x) * (0.5 * Math.log1p((2.0 * Math.abs(x))));
}
def code(x):
	return math.copysign(1.0, x) * (0.5 * math.log1p((2.0 * math.fabs(x))))
function code(x)
	return Float64(copysign(1.0, x) * Float64(0.5 * log1p(Float64(2.0 * abs(x)))))
end
code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(0.5 * N[Log[1 + N[(2.0 * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \left(0.5 \cdot \mathsf{log1p}\left(2 \cdot \left|x\right|\right)\right)
Derivation
  1. Initial program 100.0%

    \[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(\color{blue}{\frac{2 \cdot x}{1 - x}}\right) \]
    2. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \mathsf{log1p}\left(\frac{-2}{\color{blue}{x - 1}} \cdot x\right) \]
    12. lower--.f64100.0%

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

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

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{2} \cdot x\right) \]
  5. Step-by-step derivation
    1. Applied rewrites97.9%

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

    Alternative 5: 7.6% accurate, 1.0× speedup?

    \[\mathsf{copysign}\left(1, x\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{fma}\left(\left|x\right|, 0.5, 1\right), \left|x\right|, 1\right)\right) \]
    (FPCore (x)
      :precision binary64
      (* (copysign 1.0 x) (log (fma (fma (fabs x) 0.5 1.0) (fabs x) 1.0))))
    double code(double x) {
    	return copysign(1.0, x) * log(fma(fma(fabs(x), 0.5, 1.0), fabs(x), 1.0));
    }
    
    function code(x)
    	return Float64(copysign(1.0, x) * log(fma(fma(abs(x), 0.5, 1.0), abs(x), 1.0)))
    end
    
    code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[Log[N[(N[(N[Abs[x], $MachinePrecision] * 0.5 + 1.0), $MachinePrecision] * N[Abs[x], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
    
    \mathsf{copysign}\left(1, x\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{fma}\left(\left|x\right|, 0.5, 1\right), \left|x\right|, 1\right)\right)
    
    Derivation
    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \log \left(\sqrt{\color{blue}{\frac{2 \cdot x}{1 - x} + \frac{1 - x}{1 - x}}}\right) \]
    3. Applied rewrites8.4%

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

      \[\leadsto \log \left(\sqrt{\mathsf{fma}\left(\color{blue}{2}, x, 1\right)}\right) \]
    5. Step-by-step derivation
      1. Applied rewrites7.3%

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

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

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

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

          \[\leadsto \log \left(1 + x \cdot \left(1 + \color{blue}{\frac{1}{2} \cdot x}\right)\right) \]
        4. lower-*.f647.7%

          \[\leadsto \log \left(1 + x \cdot \left(1 + 0.5 \cdot \color{blue}{x}\right)\right) \]
      4. Applied rewrites7.7%

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

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

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

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

          \[\leadsto \log \left(\left(1 + \frac{1}{2} \cdot x\right) \cdot x + 1\right) \]
        5. lower-fma.f647.7%

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

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

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

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

          \[\leadsto \log \left(\mathsf{fma}\left(x \cdot \frac{1}{2} + 1, x, 1\right)\right) \]
        10. lower-fma.f647.7%

          \[\leadsto \log \left(\mathsf{fma}\left(\mathsf{fma}\left(x, 0.5, 1\right), x, 1\right)\right) \]
      6. Applied rewrites7.7%

        \[\leadsto \log \left(\mathsf{fma}\left(\mathsf{fma}\left(x, 0.5, 1\right), \color{blue}{x}, 1\right)\right) \]
      7. Add Preprocessing

      Alternative 6: 7.3% accurate, 2.5× speedup?

      \[\log \left(1 + x\right) \]
      (FPCore (x)
        :precision binary64
        (log (+ 1.0 x)))
      double code(double x) {
      	return log((1.0 + x));
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(x)
      use fmin_fmax_functions
          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]
      
      \log \left(1 + x\right)
      
      Derivation
      1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

          \[\leadsto \log \left(\sqrt{\color{blue}{\frac{2 \cdot x}{1 - x} + \frac{1 - x}{1 - x}}}\right) \]
      3. Applied rewrites8.4%

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

        \[\leadsto \log \left(\sqrt{\mathsf{fma}\left(\color{blue}{2}, x, 1\right)}\right) \]
      5. Step-by-step derivation
        1. Applied rewrites7.3%

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

          \[\leadsto \log \left(\sqrt{\color{blue}{1}}\right) \]
        3. Step-by-step derivation
          1. Applied rewrites5.3%

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

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

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

            \[\leadsto \log \color{blue}{\left(1 + x\right)} \]
          5. Add Preprocessing

          Alternative 7: 5.3% accurate, 2.6× speedup?

          \[\log \left(\sqrt{1}\right) \]
          (FPCore (x)
            :precision binary64
            (log (sqrt 1.0)))
          double code(double x) {
          	return log(sqrt(1.0));
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(x)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              code = log(sqrt(1.0d0))
          end function
          
          public static double code(double x) {
          	return Math.log(Math.sqrt(1.0));
          }
          
          def code(x):
          	return math.log(math.sqrt(1.0))
          
          function code(x)
          	return log(sqrt(1.0))
          end
          
          function tmp = code(x)
          	tmp = log(sqrt(1.0));
          end
          
          code[x_] := N[Log[N[Sqrt[1.0], $MachinePrecision]], $MachinePrecision]
          
          \log \left(\sqrt{1}\right)
          
          Derivation
          1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

              \[\leadsto \log \left(\sqrt{\color{blue}{\frac{2 \cdot x}{1 - x} + \frac{1 - x}{1 - x}}}\right) \]
          3. Applied rewrites8.4%

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

            \[\leadsto \log \left(\sqrt{\mathsf{fma}\left(\color{blue}{2}, x, 1\right)}\right) \]
          5. Step-by-step derivation
            1. Applied rewrites7.3%

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

              \[\leadsto \log \left(\sqrt{\color{blue}{1}}\right) \]
            3. Step-by-step derivation
              1. Applied rewrites5.3%

                \[\leadsto \log \left(\sqrt{\color{blue}{1}}\right) \]
              2. Add Preprocessing

              Alternative 8: 1.6% accurate, 5.0× speedup?

              \[\frac{-1}{x} \]
              (FPCore (x)
                :precision binary64
                (/ -1.0 x))
              double code(double x) {
              	return -1.0 / x;
              }
              
              module fmin_fmax_functions
                  implicit none
                  private
                  public fmax
                  public fmin
              
                  interface fmax
                      module procedure fmax88
                      module procedure fmax44
                      module procedure fmax84
                      module procedure fmax48
                  end interface
                  interface fmin
                      module procedure fmin88
                      module procedure fmin44
                      module procedure fmin84
                      module procedure fmin48
                  end interface
              contains
                  real(8) function fmax88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmax44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmax84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmax48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                  end function
                  real(8) function fmin88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmin44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmin84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmin48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                  end function
              end module
              
              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 100.0%

                \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
              2. Taylor expanded in x around inf

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

                  \[\leadsto \frac{-1}{\color{blue}{x}} \]
              4. Applied rewrites1.6%

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

              Reproduce

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