Rust f32::asinh

Percentage Accurate: 38.5% → 99.4%
Time: 5.5s
Alternatives: 8
Speedup: 4.0×

Specification

?
\[\begin{array}{l} \\ \sinh^{-1} x \end{array} \]
(FPCore (x) :precision binary32 (asinh x))
float code(float x) {
	return asinhf(x);
}
function code(x)
	return asinh(x)
end
function tmp = code(x)
	tmp = asinh(x);
end
\begin{array}{l}

\\
\sinh^{-1} x
\end{array}

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

\[\begin{array}{l} \\ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \end{array} \]
(FPCore (x)
 :precision binary32
 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
float code(float x) {
	return copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
}
function code(x)
	return copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x)
end
function tmp = code(x)
	tmp = sign(x) * abs(log((abs(x) + sqrt(((x * x) + single(1.0))))));
end
\begin{array}{l}

\\
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\end{array}

Alternative 1: 99.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ \mathbf{if}\;t\_0 \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;t\_0 \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
   (if (<= t_0 -0.20000000298023224)
     (copysign (- (log (- (hypot 1.0 x) x))) x)
     (if (<= t_0 0.05000000074505806)
       (copysign
        (*
         x
         (+ 1.0 (* (pow x 2.0) (- (* (pow x 2.0) 0.075) 0.16666666666666666))))
        x)
       (copysign (log (+ x (hypot 1.0 x))) x)))))
float code(float x) {
	float t_0 = copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
	float tmp;
	if (t_0 <= -0.20000000298023224f) {
		tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
	} else if (t_0 <= 0.05000000074505806f) {
		tmp = copysignf((x * (1.0f + (powf(x, 2.0f) * ((powf(x, 2.0f) * 0.075f) - 0.16666666666666666f)))), x);
	} else {
		tmp = copysignf(logf((x + hypotf(1.0f, x))), x);
	}
	return tmp;
}
function code(x)
	t_0 = copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x)
	tmp = Float32(0.0)
	if (t_0 <= Float32(-0.20000000298023224))
		tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x);
	elseif (t_0 <= Float32(0.05000000074505806))
		tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32((x ^ Float32(2.0)) * Float32(Float32((x ^ Float32(2.0)) * Float32(0.075)) - Float32(0.16666666666666666))))), x);
	else
		tmp = copysign(log(Float32(x + hypot(Float32(1.0), x))), x);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = sign(x) * abs(log((abs(x) + sqrt(((x * x) + single(1.0))))));
	tmp = single(0.0);
	if (t_0 <= single(-0.20000000298023224))
		tmp = sign(x) * abs(-log((hypot(single(1.0), x) - x)));
	elseif (t_0 <= single(0.05000000074505806))
		tmp = sign(x) * abs((x * (single(1.0) + ((x ^ single(2.0)) * (((x ^ single(2.0)) * single(0.075)) - single(0.16666666666666666))))));
	else
		tmp = sign(x) * abs(log((x + hypot(single(1.0), x))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\
\mathbf{if}\;t\_0 \leq -0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\

\mathbf{elif}\;t\_0 \leq 0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) < -0.200000003

    1. Initial program 55.1%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative55.1%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip-+6.2%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\left|x\right| \cdot \left|x\right| - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)}{\left|x\right| - \mathsf{hypot}\left(1, x\right)}\right)}, x\right) \]
      2. frac-2neg6.2%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\frac{-\left(\left|x\right| \cdot \left|x\right| - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)}{-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)}\right)}, x\right) \]
      3. log-div6.2%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(-\left(\left|x\right| \cdot \left|x\right| - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right) \]
      4. pow26.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left(\color{blue}{{\left(\left|x\right|\right)}^{2}} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      5. add-sqr-sqrt-0.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({\left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)}^{2} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      6. fabs-sqr-0.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}^{2} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      7. add-sqr-sqrt6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({\color{blue}{x}}^{2} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      8. hypot-1-def6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \color{blue}{\sqrt{1 + x \cdot x}} \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      9. hypot-1-def6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \sqrt{1 + x \cdot x} \cdot \color{blue}{\sqrt{1 + x \cdot x}}\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      10. add-sqr-sqrt6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \color{blue}{\left(1 + x \cdot x\right)}\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      11. pow26.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \left(1 + \color{blue}{{x}^{2}}\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
    6. Applied egg-rr11.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(-\left({x}^{2} - \left(1 + {x}^{2}\right)\right)\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right) \]
    7. Step-by-step derivation
      1. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(0 - \left({x}^{2} - \left(1 + {x}^{2}\right)\right)\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      2. associate--r-11.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(0 - {x}^{2}\right) + \left(1 + {x}^{2}\right)\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      3. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\color{blue}{\left(-{x}^{2}\right)} + \left(1 + {x}^{2}\right)\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      4. +-commutative11.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(1 + {x}^{2}\right) + \left(-{x}^{2}\right)\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      5. sub-neg11.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(1 + {x}^{2}\right) - {x}^{2}\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      6. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(0 - \left(x - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right) \]
      7. associate--r-11.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(\left(0 - x\right) + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
      8. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \left(\color{blue}{\left(-x\right)} + \mathsf{hypot}\left(1, x\right)\right), x\right) \]
      9. +-commutative11.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + \left(-x\right)\right)}, x\right) \]
      10. sub-neg11.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right) \]
      11. associate--l+52.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(1 + \left({x}^{2} - {x}^{2}\right)\right)} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      12. +-inverses100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(1 + \color{blue}{0}\right) - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      13. metadata-eval100.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{1} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      14. metadata-eval100.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{0} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      15. neg-sub0100.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right) \]
    8. Simplified100.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right) \]

    if -0.200000003 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) < 0.0500000007

    1. Initial program 16.4%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative16.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def16.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified16.4%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 17.6%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right) + {x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right)}, x\right) \]
    6. Step-by-step derivation
      1. +-commutative17.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right) + \log \left(1 + \left|x\right|\right)}, x\right) \]
      2. fma-define17.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, -0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
    7. Simplified100.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{1 + x} + \frac{-0.125}{{\left(1 + x\right)}^{2}}\right) + \frac{0.5}{1 + x}, \mathsf{log1p}\left(x\right)\right)}, x\right) \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot \left(1 + {x}^{2} \cdot \left(0.075 \cdot {x}^{2} - 0.16666666666666666\right)\right)}, x\right) \]

    if 0.0500000007 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x)

    1. Initial program 51.6%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative51.6%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def99.8%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + \left|x\right|\right)}, x\right) \]
      2. add-sqr-sqrt99.9%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right), x\right) \]
      3. fabs-sqr99.9%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right), x\right) \]
      4. add-sqr-sqrt99.8%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \color{blue}{x}\right), x\right) \]
    6. Applied egg-rr99.8%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + x\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.4% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;x \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -0.20000000298023224)
   (copysign (- (log (- (hypot 1.0 x) x))) x)
   (if (<= x 0.05000000074505806)
     (copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
     (copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
	float tmp;
	if (x <= -0.20000000298023224f) {
		tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
	} else if (x <= 0.05000000074505806f) {
		tmp = copysignf((x + (powf(x, 3.0f) * -0.16666666666666666f)), x);
	} else {
		tmp = copysignf(logf((x + hypotf(1.0f, x))), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(-0.20000000298023224))
		tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x);
	elseif (x <= Float32(0.05000000074505806))
		tmp = copysign(Float32(x + Float32((x ^ Float32(3.0)) * Float32(-0.16666666666666666))), x);
	else
		tmp = copysign(log(Float32(x + hypot(Float32(1.0), x))), x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = single(0.0);
	if (x <= single(-0.20000000298023224))
		tmp = sign(x) * abs(-log((hypot(single(1.0), x) - x)));
	elseif (x <= single(0.05000000074505806))
		tmp = sign(x) * abs((x + ((x ^ single(3.0)) * single(-0.16666666666666666))));
	else
		tmp = sign(x) * abs(log((x + hypot(single(1.0), x))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\

\mathbf{elif}\;x \leq 0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\


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

    1. Initial program 55.1%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative55.1%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip-+6.2%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\left|x\right| \cdot \left|x\right| - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)}{\left|x\right| - \mathsf{hypot}\left(1, x\right)}\right)}, x\right) \]
      2. frac-2neg6.2%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\frac{-\left(\left|x\right| \cdot \left|x\right| - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)}{-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)}\right)}, x\right) \]
      3. log-div6.2%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(-\left(\left|x\right| \cdot \left|x\right| - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right) \]
      4. pow26.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left(\color{blue}{{\left(\left|x\right|\right)}^{2}} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      5. add-sqr-sqrt-0.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({\left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)}^{2} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      6. fabs-sqr-0.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}^{2} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      7. add-sqr-sqrt6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({\color{blue}{x}}^{2} - \mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      8. hypot-1-def6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \color{blue}{\sqrt{1 + x \cdot x}} \cdot \mathsf{hypot}\left(1, x\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      9. hypot-1-def6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \sqrt{1 + x \cdot x} \cdot \color{blue}{\sqrt{1 + x \cdot x}}\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      10. add-sqr-sqrt6.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \color{blue}{\left(1 + x \cdot x\right)}\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      11. pow26.2%

        \[\leadsto \mathsf{copysign}\left(\log \left(-\left({x}^{2} - \left(1 + \color{blue}{{x}^{2}}\right)\right)\right) - \log \left(-\left(\left|x\right| - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
    6. Applied egg-rr11.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(-\left({x}^{2} - \left(1 + {x}^{2}\right)\right)\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right) \]
    7. Step-by-step derivation
      1. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(0 - \left({x}^{2} - \left(1 + {x}^{2}\right)\right)\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      2. associate--r-11.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(0 - {x}^{2}\right) + \left(1 + {x}^{2}\right)\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      3. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\color{blue}{\left(-{x}^{2}\right)} + \left(1 + {x}^{2}\right)\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      4. +-commutative11.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(1 + {x}^{2}\right) + \left(-{x}^{2}\right)\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      5. sub-neg11.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(1 + {x}^{2}\right) - {x}^{2}\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right) \]
      6. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(0 - \left(x - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right) \]
      7. associate--r-11.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(\left(0 - x\right) + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
      8. neg-sub011.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \left(\color{blue}{\left(-x\right)} + \mathsf{hypot}\left(1, x\right)\right), x\right) \]
      9. +-commutative11.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + \left(-x\right)\right)}, x\right) \]
      10. sub-neg11.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left(1 + {x}^{2}\right) - {x}^{2}\right) - \log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right) \]
      11. associate--l+52.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(1 + \left({x}^{2} - {x}^{2}\right)\right)} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      12. +-inverses100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(1 + \color{blue}{0}\right) - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      13. metadata-eval100.0%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{1} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      14. metadata-eval100.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{0} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right) \]
      15. neg-sub0100.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right) \]
    8. Simplified100.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right) \]

    if -0.200000003 < x < 0.0500000007

    1. Initial program 16.4%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative16.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def16.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified16.4%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 17.6%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right) + {x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right)}, x\right) \]
    6. Step-by-step derivation
      1. +-commutative17.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right) + \log \left(1 + \left|x\right|\right)}, x\right) \]
      2. fma-define17.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, -0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
    7. Simplified100.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{1 + x} + \frac{-0.125}{{\left(1 + x\right)}^{2}}\right) + \frac{0.5}{1 + x}, \mathsf{log1p}\left(x\right)\right)}, x\right) \]
    8. Taylor expanded in x around 0 99.9%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot \left(1 + -0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
    9. Step-by-step derivation
      1. distribute-lft-in99.9%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot 1 + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
      2. *-rgt-identity99.9%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x} + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right), x\right) \]
      3. *-commutative99.9%

        \[\leadsto \mathsf{copysign}\left(x + x \cdot \color{blue}{\left({x}^{2} \cdot -0.16666666666666666\right)}, x\right) \]
      4. associate-*r*99.9%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{\left(x \cdot {x}^{2}\right) \cdot -0.16666666666666666}, x\right) \]
      5. unpow299.9%

        \[\leadsto \mathsf{copysign}\left(x + \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot -0.16666666666666666, x\right) \]
      6. cube-mult99.9%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{{x}^{3}} \cdot -0.16666666666666666, x\right) \]
    10. Simplified99.9%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x + {x}^{3} \cdot -0.16666666666666666}, x\right) \]

    if 0.0500000007 < x

    1. Initial program 51.6%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative51.6%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def99.8%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + \left|x\right|\right)}, x\right) \]
      2. add-sqr-sqrt99.9%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right), x\right) \]
      3. fabs-sqr99.9%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right), x\right) \]
      4. add-sqr-sqrt99.8%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \color{blue}{x}\right), x\right) \]
    6. Applied egg-rr99.8%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + x\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;x \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\left(1 + \log \left(\frac{-0.5}{x}\right)\right) + -1, x\right)\\ \mathbf{elif}\;x \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -2.0)
   (copysign (+ (+ 1.0 (log (/ -0.5 x))) -1.0) x)
   (if (<= x 0.05000000074505806)
     (copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
     (copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
	float tmp;
	if (x <= -2.0f) {
		tmp = copysignf(((1.0f + logf((-0.5f / x))) + -1.0f), x);
	} else if (x <= 0.05000000074505806f) {
		tmp = copysignf((x + (powf(x, 3.0f) * -0.16666666666666666f)), x);
	} else {
		tmp = copysignf(logf((x + hypotf(1.0f, x))), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(-2.0))
		tmp = copysign(Float32(Float32(Float32(1.0) + log(Float32(Float32(-0.5) / x))) + Float32(-1.0)), x);
	elseif (x <= Float32(0.05000000074505806))
		tmp = copysign(Float32(x + Float32((x ^ Float32(3.0)) * Float32(-0.16666666666666666))), x);
	else
		tmp = copysign(log(Float32(x + hypot(Float32(1.0), x))), x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = single(0.0);
	if (x <= single(-2.0))
		tmp = sign(x) * abs(((single(1.0) + log((single(-0.5) / x))) + single(-1.0)));
	elseif (x <= single(0.05000000074505806))
		tmp = sign(x) * abs((x + ((x ^ single(3.0)) * single(-0.16666666666666666))));
	else
		tmp = sign(x) * abs(log((x + hypot(single(1.0), x))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

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

\mathbf{elif}\;x \leq 0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\


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

    1. Initial program 54.5%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative54.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u97.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)\right)}, x\right) \]
      2. expm1-undefine97.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{e^{\mathsf{log1p}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)} - 1}, x\right) \]
      3. log1p-undefine97.6%

        \[\leadsto \mathsf{copysign}\left(e^{\color{blue}{\log \left(1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}} - 1, x\right) \]
      4. rem-exp-log99.9%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\left(1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)} - 1, x\right) \]
      5. *-un-lft-identity99.9%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(1 \cdot \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}\right) - 1, x\right) \]
      6. *-un-lft-identity99.9%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)}\right) - 1, x\right) \]
      7. add-sqr-sqrt-0.0%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right) \]
      8. fabs-sqr-0.0%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right) \]
      9. add-sqr-sqrt11.0%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \left(\color{blue}{x} + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right) \]
    6. Applied egg-rr11.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\left(1 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right)\right) - 1}, x\right) \]
    7. Taylor expanded in x around -inf 98.3%

      \[\leadsto \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(\frac{-0.5}{x}\right)}\right) - 1, x\right) \]

    if -2 < x < 0.0500000007

    1. Initial program 17.1%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative17.1%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def17.1%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified17.1%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 18.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right) + {x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right)}, x\right) \]
    6. Step-by-step derivation
      1. +-commutative18.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right) + \log \left(1 + \left|x\right|\right)}, x\right) \]
      2. fma-define18.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, -0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
    7. Simplified99.7%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{1 + x} + \frac{-0.125}{{\left(1 + x\right)}^{2}}\right) + \frac{0.5}{1 + x}, \mathsf{log1p}\left(x\right)\right)}, x\right) \]
    8. Taylor expanded in x around 0 99.6%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot \left(1 + -0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
    9. Step-by-step derivation
      1. distribute-lft-in99.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot 1 + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
      2. *-rgt-identity99.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x} + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right), x\right) \]
      3. *-commutative99.6%

        \[\leadsto \mathsf{copysign}\left(x + x \cdot \color{blue}{\left({x}^{2} \cdot -0.16666666666666666\right)}, x\right) \]
      4. associate-*r*99.6%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{\left(x \cdot {x}^{2}\right) \cdot -0.16666666666666666}, x\right) \]
      5. unpow299.6%

        \[\leadsto \mathsf{copysign}\left(x + \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot -0.16666666666666666, x\right) \]
      6. cube-mult99.6%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{{x}^{3}} \cdot -0.16666666666666666, x\right) \]
    10. Simplified99.6%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x + {x}^{3} \cdot -0.16666666666666666}, x\right) \]

    if 0.0500000007 < x

    1. Initial program 51.6%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative51.6%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def99.8%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + \left|x\right|\right)}, x\right) \]
      2. add-sqr-sqrt99.9%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right), x\right) \]
      3. fabs-sqr99.9%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right), x\right) \]
      4. add-sqr-sqrt99.8%

        \[\leadsto \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + \color{blue}{x}\right), x\right) \]
    6. Applied egg-rr99.8%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + x\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\left(1 + \log \left(\frac{-0.5}{x}\right)\right) + -1, x\right)\\ \mathbf{elif}\;x \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 97.9% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\left(1 + \log \left(\frac{-0.5}{x}\right)\right) + -1, x\right)\\ \mathbf{elif}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{x}{x}\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -2.0)
   (copysign (+ (+ 1.0 (log (/ -0.5 x))) -1.0) x)
   (if (<= x 0.5)
     (copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
     (copysign (log (* x (+ 1.0 (/ x x)))) x))))
float code(float x) {
	float tmp;
	if (x <= -2.0f) {
		tmp = copysignf(((1.0f + logf((-0.5f / x))) + -1.0f), x);
	} else if (x <= 0.5f) {
		tmp = copysignf((x + (powf(x, 3.0f) * -0.16666666666666666f)), x);
	} else {
		tmp = copysignf(logf((x * (1.0f + (x / x)))), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(-2.0))
		tmp = copysign(Float32(Float32(Float32(1.0) + log(Float32(Float32(-0.5) / x))) + Float32(-1.0)), x);
	elseif (x <= Float32(0.5))
		tmp = copysign(Float32(x + Float32((x ^ Float32(3.0)) * Float32(-0.16666666666666666))), x);
	else
		tmp = copysign(log(Float32(x * Float32(Float32(1.0) + Float32(x / x)))), x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = single(0.0);
	if (x <= single(-2.0))
		tmp = sign(x) * abs(((single(1.0) + log((single(-0.5) / x))) + single(-1.0)));
	elseif (x <= single(0.5))
		tmp = sign(x) * abs((x + ((x ^ single(3.0)) * single(-0.16666666666666666))));
	else
		tmp = sign(x) * abs(log((x * (single(1.0) + (x / x)))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

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

\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\

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


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

    1. Initial program 54.5%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative54.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u97.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)\right)}, x\right) \]
      2. expm1-undefine97.6%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{e^{\mathsf{log1p}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)} - 1}, x\right) \]
      3. log1p-undefine97.6%

        \[\leadsto \mathsf{copysign}\left(e^{\color{blue}{\log \left(1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}} - 1, x\right) \]
      4. rem-exp-log99.9%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\left(1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)} - 1, x\right) \]
      5. *-un-lft-identity99.9%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(1 \cdot \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}\right) - 1, x\right) \]
      6. *-un-lft-identity99.9%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)}\right) - 1, x\right) \]
      7. add-sqr-sqrt-0.0%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right) \]
      8. fabs-sqr-0.0%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right) \]
      9. add-sqr-sqrt11.0%

        \[\leadsto \mathsf{copysign}\left(\left(1 + \log \left(\color{blue}{x} + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right) \]
    6. Applied egg-rr11.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\left(1 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right)\right) - 1}, x\right) \]
    7. Taylor expanded in x around -inf 98.3%

      \[\leadsto \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(\frac{-0.5}{x}\right)}\right) - 1, x\right) \]

    if -2 < x < 0.5

    1. Initial program 18.4%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative18.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def18.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified18.4%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 18.8%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right) + {x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right)}, x\right) \]
    6. Step-by-step derivation
      1. +-commutative18.8%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right) + \log \left(1 + \left|x\right|\right)}, x\right) \]
      2. fma-define18.8%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, -0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
    7. Simplified99.1%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{1 + x} + \frac{-0.125}{{\left(1 + x\right)}^{2}}\right) + \frac{0.5}{1 + x}, \mathsf{log1p}\left(x\right)\right)}, x\right) \]
    8. Taylor expanded in x around 0 99.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot \left(1 + -0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
    9. Step-by-step derivation
      1. distribute-lft-in99.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot 1 + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
      2. *-rgt-identity99.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x} + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right), x\right) \]
      3. *-commutative99.0%

        \[\leadsto \mathsf{copysign}\left(x + x \cdot \color{blue}{\left({x}^{2} \cdot -0.16666666666666666\right)}, x\right) \]
      4. associate-*r*99.0%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{\left(x \cdot {x}^{2}\right) \cdot -0.16666666666666666}, x\right) \]
      5. unpow299.0%

        \[\leadsto \mathsf{copysign}\left(x + \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot -0.16666666666666666, x\right) \]
      6. cube-mult99.0%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{{x}^{3}} \cdot -0.16666666666666666, x\right) \]
    10. Simplified99.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x + {x}^{3} \cdot -0.16666666666666666}, x\right) \]

    if 0.5 < x

    1. Initial program 50.3%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative50.3%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 96.5%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(x \cdot \left(1 + \frac{\left|x\right|}{x}\right)\right)}, x\right) \]
    6. Step-by-step derivation
      1. rem-square-sqrt96.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{x}\right)\right), x\right) \]
      2. fabs-sqr96.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{x}\right)\right), x\right) \]
      3. rem-square-sqrt96.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{\color{blue}{x}}{x}\right)\right), x\right) \]
    7. Simplified96.5%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(x \cdot \left(1 + \frac{x}{x}\right)\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification98.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\left(1 + \log \left(\frac{-0.5}{x}\right)\right) + -1, x\right)\\ \mathbf{elif}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{x}{x}\right)\right), x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 84.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{elif}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{x}{x}\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -2.0)
   (copysign (log (- x)) x)
   (if (<= x 0.5)
     (copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
     (copysign (log (* x (+ 1.0 (/ x x)))) x))))
float code(float x) {
	float tmp;
	if (x <= -2.0f) {
		tmp = copysignf(logf(-x), x);
	} else if (x <= 0.5f) {
		tmp = copysignf((x + (powf(x, 3.0f) * -0.16666666666666666f)), x);
	} else {
		tmp = copysignf(logf((x * (1.0f + (x / x)))), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(-2.0))
		tmp = copysign(log(Float32(-x)), x);
	elseif (x <= Float32(0.5))
		tmp = copysign(Float32(x + Float32((x ^ Float32(3.0)) * Float32(-0.16666666666666666))), x);
	else
		tmp = copysign(log(Float32(x * Float32(Float32(1.0) + Float32(x / x)))), x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = single(0.0);
	if (x <= single(-2.0))
		tmp = sign(x) * abs(log(-x));
	elseif (x <= single(0.5))
		tmp = sign(x) * abs((x + ((x ^ single(3.0)) * single(-0.16666666666666666))));
	else
		tmp = sign(x) * abs(log((x * (single(1.0) + (x / x)))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\

\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\

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


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

    1. Initial program 54.5%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative54.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around -inf 44.4%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(-1 \cdot x\right)}, x\right) \]
    6. Step-by-step derivation
      1. mul-1-neg44.4%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(-x\right)}, x\right) \]
    7. Simplified44.4%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(-x\right)}, x\right) \]

    if -2 < x < 0.5

    1. Initial program 18.4%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative18.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def18.4%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified18.4%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 18.8%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right) + {x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right)}, x\right) \]
    6. Step-by-step derivation
      1. +-commutative18.8%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right) + \log \left(1 + \left|x\right|\right)}, x\right) \]
      2. fma-define18.8%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, -0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
    7. Simplified99.1%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{1 + x} + \frac{-0.125}{{\left(1 + x\right)}^{2}}\right) + \frac{0.5}{1 + x}, \mathsf{log1p}\left(x\right)\right)}, x\right) \]
    8. Taylor expanded in x around 0 99.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot \left(1 + -0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
    9. Step-by-step derivation
      1. distribute-lft-in99.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x \cdot 1 + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right)}, x\right) \]
      2. *-rgt-identity99.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{x} + x \cdot \left(-0.16666666666666666 \cdot {x}^{2}\right), x\right) \]
      3. *-commutative99.0%

        \[\leadsto \mathsf{copysign}\left(x + x \cdot \color{blue}{\left({x}^{2} \cdot -0.16666666666666666\right)}, x\right) \]
      4. associate-*r*99.0%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{\left(x \cdot {x}^{2}\right) \cdot -0.16666666666666666}, x\right) \]
      5. unpow299.0%

        \[\leadsto \mathsf{copysign}\left(x + \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot -0.16666666666666666, x\right) \]
      6. cube-mult99.0%

        \[\leadsto \mathsf{copysign}\left(x + \color{blue}{{x}^{3}} \cdot -0.16666666666666666, x\right) \]
    10. Simplified99.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x + {x}^{3} \cdot -0.16666666666666666}, x\right) \]

    if 0.5 < x

    1. Initial program 50.3%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative50.3%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 96.5%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(x \cdot \left(1 + \frac{\left|x\right|}{x}\right)\right)}, x\right) \]
    6. Step-by-step derivation
      1. rem-square-sqrt96.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{x}\right)\right), x\right) \]
      2. fabs-sqr96.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{x}\right)\right), x\right) \]
      3. rem-square-sqrt96.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{\color{blue}{x}}{x}\right)\right), x\right) \]
    7. Simplified96.5%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(x \cdot \left(1 + \frac{x}{x}\right)\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 68.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -2.0) (copysign (log (- x)) x) (copysign (log1p x) x)))
float code(float x) {
	float tmp;
	if (x <= -2.0f) {
		tmp = copysignf(logf(-x), x);
	} else {
		tmp = copysignf(log1pf(x), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(-2.0))
		tmp = copysign(log(Float32(-x)), x);
	else
		tmp = copysign(log1p(x), x);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\


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

    1. Initial program 54.5%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative54.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around -inf 44.4%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(-1 \cdot x\right)}, x\right) \]
    6. Step-by-step derivation
      1. mul-1-neg44.4%

        \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(-x\right)}, x\right) \]
    7. Simplified44.4%

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(-x\right)}, x\right) \]

    if -2 < x

    1. Initial program 29.5%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative29.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def46.8%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified46.8%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 25.9%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right)}, x\right) \]
    6. Step-by-step derivation
      1. log1p-define78.0%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(\left|x\right|\right)}, x\right) \]
      2. rem-square-sqrt48.3%

        \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right), x\right) \]
      3. fabs-sqr48.3%

        \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right), x\right) \]
      4. rem-square-sqrt78.0%

        \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{x}\right), x\right) \]
    7. Simplified78.0%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(x\right)}, x\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 62.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x 2.0) (copysign x x) (copysign (log1p x) x)))
float code(float x) {
	float tmp;
	if (x <= 2.0f) {
		tmp = copysignf(x, x);
	} else {
		tmp = copysignf(log1pf(x), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(2.0))
		tmp = copysign(x, x);
	else
		tmp = copysign(log1p(x), x);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\


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

    1. Initial program 32.3%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative32.3%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def49.3%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified49.3%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 14.9%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right) + {x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right)}, x\right) \]
    6. Step-by-step derivation
      1. +-commutative14.9%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right) + \log \left(1 + \left|x\right|\right)}, x\right) \]
      2. fma-define14.9%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, -0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
    7. Simplified61.8%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{1 + x} + \frac{-0.125}{{\left(1 + x\right)}^{2}}\right) + \frac{0.5}{1 + x}, \mathsf{log1p}\left(x\right)\right)}, x\right) \]
    8. Taylor expanded in x around 0 65.3%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{x}, x\right) \]

    if 2 < x

    1. Initial program 49.5%

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Step-by-step derivation
      1. +-commutative49.5%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
      2. hypot-1-def100.0%

        \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 44.8%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right)}, x\right) \]
    6. Step-by-step derivation
      1. log1p-define44.8%

        \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(\left|x\right|\right)}, x\right) \]
      2. rem-square-sqrt44.8%

        \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right), x\right) \]
      3. fabs-sqr44.8%

        \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right), x\right) \]
      4. rem-square-sqrt44.8%

        \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{x}\right), x\right) \]
    7. Simplified44.8%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(x\right)}, x\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 54.1% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \mathsf{copysign}\left(x, x\right) \end{array} \]
(FPCore (x) :precision binary32 (copysign x x))
float code(float x) {
	return copysignf(x, x);
}
function code(x)
	return copysign(x, x)
end
function tmp = code(x)
	tmp = sign(x) * abs(x);
end
\begin{array}{l}

\\
\mathsf{copysign}\left(x, x\right)
\end{array}
Derivation
  1. Initial program 36.5%

    \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
  2. Step-by-step derivation
    1. +-commutative36.5%

      \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right) \]
    2. hypot-1-def61.7%

      \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right) \]
  3. Simplified61.7%

    \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 13.2%

    \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(1 + \left|x\right|\right) + {x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right)}, x\right) \]
  6. Step-by-step derivation
    1. +-commutative13.2%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}\right) + \log \left(1 + \left|x\right|\right)}, x\right) \]
    2. fma-define13.2%

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, -0.041666666666666664 \cdot \left({x}^{2} \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) + 0.5 \cdot \frac{1}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
  7. Simplified48.5%

    \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{1 + x} + \frac{-0.125}{{\left(1 + x\right)}^{2}}\right) + \frac{0.5}{1 + x}, \mathsf{log1p}\left(x\right)\right)}, x\right) \]
  8. Taylor expanded in x around 0 51.9%

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

Developer target: 99.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\left|x\right|}\\ \mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right| + \frac{\left|x\right|}{\mathsf{hypot}\left(1, t\_0\right) + t\_0}\right), x\right) \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (let* ((t_0 (/ 1.0 (fabs x))))
   (copysign (log1p (+ (fabs x) (/ (fabs x) (+ (hypot 1.0 t_0) t_0)))) x)))
float code(float x) {
	float t_0 = 1.0f / fabsf(x);
	return copysignf(log1pf((fabsf(x) + (fabsf(x) / (hypotf(1.0f, t_0) + t_0)))), x);
}
function code(x)
	t_0 = Float32(Float32(1.0) / abs(x))
	return copysign(log1p(Float32(abs(x) + Float32(abs(x) / Float32(hypot(Float32(1.0), t_0) + t_0)))), x)
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right| + \frac{\left|x\right|}{\mathsf{hypot}\left(1, t\_0\right) + t\_0}\right), x\right)
\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024096 
(FPCore (x)
  :name "Rust f32::asinh"
  :precision binary32

  :alt
  (copysign (log1p (+ (fabs x) (/ (fabs x) (+ (hypot 1.0 (/ 1.0 (fabs x))) (/ 1.0 (fabs x)))))) x)

  (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))