HairBSDF, sample_f, cosTheta

Percentage Accurate: 99.5% → 99.5%
Time: 11.8s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
\[\begin{array}{l} \\ 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
float code(float u, float v) {
	return 1.0f + (v * logf((u + ((1.0f - u) * expf((-2.0f / v))))));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log((u + ((1.0e0 - u) * exp(((-2.0e0) / v))))))
end function
function code(u, v)
	return Float32(Float32(1.0) + Float32(v * log(Float32(u + Float32(Float32(Float32(1.0) - u) * exp(Float32(Float32(-2.0) / v)))))))
end
function tmp = code(u, v)
	tmp = single(1.0) + (v * log((u + ((single(1.0) - u) * exp((single(-2.0) / v))))));
end
\begin{array}{l}

\\
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)
\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 11 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: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
float code(float u, float v) {
	return 1.0f + (v * logf((u + ((1.0f - u) * expf((-2.0f / v))))));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log((u + ((1.0e0 - u) * exp(((-2.0e0) / v))))))
end function
function code(u, v)
	return Float32(Float32(1.0) + Float32(v * log(Float32(u + Float32(Float32(Float32(1.0) - u) * exp(Float32(Float32(-2.0) / v)))))))
end
function tmp = code(u, v)
	tmp = single(1.0) + (v * log((u + ((single(1.0) - u) * exp((single(-2.0) / v))))));
end
\begin{array}{l}

\\
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)
\end{array}

Alternative 1: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
float code(float u, float v) {
	return 1.0f + (v * logf((u + ((1.0f - u) * expf((-2.0f / v))))));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log((u + ((1.0e0 - u) * exp(((-2.0e0) / v))))))
end function
function code(u, v)
	return Float32(Float32(1.0) + Float32(v * log(Float32(u + Float32(Float32(Float32(1.0) - u) * exp(Float32(Float32(-2.0) / v)))))))
end
function tmp = code(u, v)
	tmp = single(1.0) + (v * log((u + ((single(1.0) - u) * exp((single(-2.0) / v))))));
end
\begin{array}{l}

\\
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)
\end{array}
Derivation
  1. Initial program 99.5%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Final simplification99.5%

    \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]

Alternative 2: 91.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} + -1\right)\right) - 2\right)\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612)
   1.0
   (+ 1.0 (- (* v (* u (+ (/ 1.0 (exp (/ -2.0 v))) -1.0))) 2.0))))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = 1.0f + ((v * (u * ((1.0f / expf((-2.0f / v))) + -1.0f))) - 2.0f);
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = 1.0e0 + ((v * (u * ((1.0e0 / exp(((-2.0e0) / v))) + (-1.0e0)))) - 2.0e0)
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(1.0) + Float32(Float32(v * Float32(u * Float32(Float32(Float32(1.0) / exp(Float32(Float32(-2.0) / v))) + Float32(-1.0)))) - Float32(2.0)));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = single(1.0) + ((v * (u * ((single(1.0) / exp((single(-2.0) / v))) + single(-1.0)))) - single(2.0));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;1 + \left(v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} + -1\right)\right) - 2\right)\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Taylor expanded in u around 0 67.3%

      \[\leadsto 1 + \color{blue}{\left(v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) - 2\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} + -1\right)\right) - 2\right)\\ \end{array} \]

Alternative 3: 91.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} + -1\right)\right) + -1\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612)
   1.0
   (+ (* v (* u (+ (/ 1.0 (exp (/ -2.0 v))) -1.0))) -1.0)))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = (v * (u * ((1.0f / expf((-2.0f / v))) + -1.0f))) + -1.0f;
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = (v * (u * ((1.0e0 / exp(((-2.0e0) / v))) + (-1.0e0)))) + (-1.0e0)
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(v * Float32(u * Float32(Float32(Float32(1.0) / exp(Float32(Float32(-2.0) / v))) + Float32(-1.0)))) + Float32(-1.0));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = (v * (u * ((single(1.0) / exp((single(-2.0) / v))) + single(-1.0)))) + single(-1.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} + -1\right)\right) + -1\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Taylor expanded in u around 0 67.2%

      \[\leadsto \color{blue}{v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} + -1\right)\right) + -1\\ \end{array} \]

Alternative 4: 91.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;v \cdot \left(u \cdot \left(e^{\frac{2}{v}} + -1\right)\right) + -1\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612)
   1.0
   (+ (* v (* u (+ (exp (/ 2.0 v)) -1.0))) -1.0)))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = (v * (u * (expf((2.0f / v)) + -1.0f))) + -1.0f;
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = (v * (u * (exp((2.0e0 / v)) + (-1.0e0)))) + (-1.0e0)
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(v * Float32(u * Float32(exp(Float32(Float32(2.0) / v)) + Float32(-1.0)))) + Float32(-1.0));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = (v * (u * (exp((single(2.0) / v)) + single(-1.0)))) + single(-1.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;v \cdot \left(u \cdot \left(e^{\frac{2}{v}} + -1\right)\right) + -1\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. +-commutative94.9%

        \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
      2. *-commutative94.9%

        \[\leadsto \color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v} + 1 \]
      3. add-sqr-sqrt93.6%

        \[\leadsto \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \color{blue}{\left(\sqrt{v} \cdot \sqrt{v}\right)} + 1 \]
      4. associate-*r*94.1%

        \[\leadsto \color{blue}{\left(\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \sqrt{v}\right) \cdot \sqrt{v}} + 1 \]
      5. fma-def93.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \sqrt{v}, \sqrt{v}, 1\right)} \]
      6. +-commutative93.7%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)} \cdot \sqrt{v}, \sqrt{v}, 1\right) \]
      7. fma-udef93.8%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)} \cdot \sqrt{v}, \sqrt{v}, 1\right) \]
    3. Applied egg-rr93.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot \sqrt{v}, \sqrt{v}, 1\right)} \]
    4. Taylor expanded in u around 0 76.1%

      \[\leadsto \color{blue}{\left(v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) + -0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}}\right) - 1} \]
    5. Step-by-step derivation
      1. associate--l+75.8%

        \[\leadsto \color{blue}{v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right)} \]
      2. associate-*r*75.8%

        \[\leadsto \color{blue}{\left(v \cdot u\right) \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)} + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      3. rec-exp76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \left(\color{blue}{e^{-\frac{-2}{v}}} - 1\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      4. expm1-def76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \color{blue}{\mathsf{expm1}\left(-\frac{-2}{v}\right)} + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      5. distribute-neg-frac76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\color{blue}{\frac{--2}{v}}\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      6. metadata-eval76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{\color{blue}{2}}{v}\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      7. fma-neg76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{2}{v}\right) + \color{blue}{\mathsf{fma}\left(-0.5, \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}}, -1\right)} \]
    6. Simplified76.0%

      \[\leadsto \color{blue}{\left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{2}{v}\right) + \mathsf{fma}\left(-0.5, \frac{{\left(1 - e^{\frac{-2}{v}}\right)}^{2}}{\frac{{\left(e^{\frac{-2}{v}}\right)}^{2}}{v \cdot \left(u \cdot u\right)}}, -1\right)} \]
    7. Taylor expanded in u around 0 67.2%

      \[\leadsto \color{blue}{v \cdot \left(\left(e^{\frac{2}{v}} - 1\right) \cdot u\right) - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;v \cdot \left(u \cdot \left(e^{\frac{2}{v}} + -1\right)\right) + -1\\ \end{array} \]

Alternative 5: 91.1% accurate, 11.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \left(u \cdot \frac{u}{v}\right) + 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612)
   1.0
   (+ (+ (* -2.0 (* u (/ u v))) (* 2.0 (+ u (/ u v)))) -1.0)))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = ((-2.0f * (u * (u / v))) + (2.0f * (u + (u / v)))) + -1.0f;
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = (((-2.0e0) * (u * (u / v))) + (2.0e0 * (u + (u / v)))) + (-1.0e0)
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(Float32(Float32(-2.0) * Float32(u * Float32(u / v))) + Float32(Float32(2.0) * Float32(u + Float32(u / v)))) + Float32(-1.0));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = ((single(-2.0) * (u * (u / v))) + (single(2.0) * (u + (u / v)))) + single(-1.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \left(u \cdot \frac{u}{v}\right) + 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. +-commutative94.9%

        \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
      2. *-commutative94.9%

        \[\leadsto \color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v} + 1 \]
      3. add-sqr-sqrt93.6%

        \[\leadsto \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \color{blue}{\left(\sqrt{v} \cdot \sqrt{v}\right)} + 1 \]
      4. associate-*r*94.1%

        \[\leadsto \color{blue}{\left(\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \sqrt{v}\right) \cdot \sqrt{v}} + 1 \]
      5. fma-def93.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \sqrt{v}, \sqrt{v}, 1\right)} \]
      6. +-commutative93.7%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)} \cdot \sqrt{v}, \sqrt{v}, 1\right) \]
      7. fma-udef93.8%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)} \cdot \sqrt{v}, \sqrt{v}, 1\right) \]
    3. Applied egg-rr93.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot \sqrt{v}, \sqrt{v}, 1\right)} \]
    4. Taylor expanded in u around 0 76.1%

      \[\leadsto \color{blue}{\left(v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) + -0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}}\right) - 1} \]
    5. Step-by-step derivation
      1. associate--l+75.8%

        \[\leadsto \color{blue}{v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right)} \]
      2. associate-*r*75.8%

        \[\leadsto \color{blue}{\left(v \cdot u\right) \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)} + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      3. rec-exp76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \left(\color{blue}{e^{-\frac{-2}{v}}} - 1\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      4. expm1-def76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \color{blue}{\mathsf{expm1}\left(-\frac{-2}{v}\right)} + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      5. distribute-neg-frac76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\color{blue}{\frac{--2}{v}}\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      6. metadata-eval76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{\color{blue}{2}}{v}\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      7. fma-neg76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{2}{v}\right) + \color{blue}{\mathsf{fma}\left(-0.5, \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}}, -1\right)} \]
    6. Simplified76.0%

      \[\leadsto \color{blue}{\left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{2}{v}\right) + \mathsf{fma}\left(-0.5, \frac{{\left(1 - e^{\frac{-2}{v}}\right)}^{2}}{\frac{{\left(e^{\frac{-2}{v}}\right)}^{2}}{v \cdot \left(u \cdot u\right)}}, -1\right)} \]
    7. Taylor expanded in v around inf 60.3%

      \[\leadsto \color{blue}{\left(-2 \cdot \frac{{u}^{2}}{v} + \left(2 \cdot u + 2 \cdot \frac{u}{v}\right)\right) - 1} \]
    8. Step-by-step derivation
      1. sub-neg60.3%

        \[\leadsto \color{blue}{\left(-2 \cdot \frac{{u}^{2}}{v} + \left(2 \cdot u + 2 \cdot \frac{u}{v}\right)\right) + \left(-1\right)} \]
      2. fma-def60.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-2, \frac{{u}^{2}}{v}, 2 \cdot u + 2 \cdot \frac{u}{v}\right)} + \left(-1\right) \]
      3. unpow260.3%

        \[\leadsto \mathsf{fma}\left(-2, \frac{\color{blue}{u \cdot u}}{v}, 2 \cdot u + 2 \cdot \frac{u}{v}\right) + \left(-1\right) \]
      4. distribute-lft-out60.3%

        \[\leadsto \mathsf{fma}\left(-2, \frac{u \cdot u}{v}, \color{blue}{2 \cdot \left(u + \frac{u}{v}\right)}\right) + \left(-1\right) \]
      5. metadata-eval60.3%

        \[\leadsto \mathsf{fma}\left(-2, \frac{u \cdot u}{v}, 2 \cdot \left(u + \frac{u}{v}\right)\right) + \color{blue}{-1} \]
    9. Simplified60.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-2, \frac{u \cdot u}{v}, 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1} \]
    10. Step-by-step derivation
      1. fma-udef60.3%

        \[\leadsto \color{blue}{\left(-2 \cdot \frac{u \cdot u}{v} + 2 \cdot \left(u + \frac{u}{v}\right)\right)} + -1 \]
      2. associate-/l*60.3%

        \[\leadsto \left(-2 \cdot \color{blue}{\frac{u}{\frac{v}{u}}} + 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1 \]
      3. div-inv60.3%

        \[\leadsto \left(-2 \cdot \color{blue}{\left(u \cdot \frac{1}{\frac{v}{u}}\right)} + 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1 \]
      4. clear-num60.3%

        \[\leadsto \left(-2 \cdot \left(u \cdot \color{blue}{\frac{u}{v}}\right) + 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1 \]
    11. Applied egg-rr60.3%

      \[\leadsto \color{blue}{\left(-2 \cdot \left(u \cdot \frac{u}{v}\right) + 2 \cdot \left(u + \frac{u}{v}\right)\right)} + -1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \left(u \cdot \frac{u}{v}\right) + 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1\\ \end{array} \]

Alternative 6: 91.0% accurate, 14.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \frac{u}{v} - \left(2 + u \cdot -2\right)\right)\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612)
   1.0
   (+ 1.0 (- (* 2.0 (/ u v)) (+ 2.0 (* u -2.0))))))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = 1.0f + ((2.0f * (u / v)) - (2.0f + (u * -2.0f)));
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = 1.0e0 + ((2.0e0 * (u / v)) - (2.0e0 + (u * (-2.0e0))))
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(1.0) + Float32(Float32(Float32(2.0) * Float32(u / v)) - Float32(Float32(2.0) + Float32(u * Float32(-2.0)))));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = single(1.0) + ((single(2.0) * (u / v)) - (single(2.0) + (u * single(-2.0))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;1 + \left(2 \cdot \frac{u}{v} - \left(2 + u \cdot -2\right)\right)\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Taylor expanded in u around 0 67.1%

      \[\leadsto 1 + v \cdot \color{blue}{\left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right) - 2 \cdot \frac{1}{v}\right)} \]
    3. Taylor expanded in v around -inf 58.2%

      \[\leadsto \color{blue}{1 + \left(2 \cdot \frac{u}{v} + -1 \cdot \left(2 + -2 \cdot u\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \frac{u}{v} - \left(2 + u \cdot -2\right)\right)\\ \end{array} \]

Alternative 7: 91.0% accurate, 16.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(u \cdot \left(1 + \frac{1}{v}\right)\right) + -1\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612) 1.0 (+ (* 2.0 (* u (+ 1.0 (/ 1.0 v)))) -1.0)))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = (2.0f * (u * (1.0f + (1.0f / v)))) + -1.0f;
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = (2.0e0 * (u * (1.0e0 + (1.0e0 / v)))) + (-1.0e0)
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(Float32(2.0) * Float32(u * Float32(Float32(1.0) + Float32(Float32(1.0) / v)))) + Float32(-1.0));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = (single(2.0) * (u * (single(1.0) + (single(1.0) / v)))) + single(-1.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(u \cdot \left(1 + \frac{1}{v}\right)\right) + -1\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. +-commutative94.9%

        \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
      2. *-commutative94.9%

        \[\leadsto \color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v} + 1 \]
      3. add-sqr-sqrt93.6%

        \[\leadsto \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \color{blue}{\left(\sqrt{v} \cdot \sqrt{v}\right)} + 1 \]
      4. associate-*r*94.1%

        \[\leadsto \color{blue}{\left(\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \sqrt{v}\right) \cdot \sqrt{v}} + 1 \]
      5. fma-def93.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot \sqrt{v}, \sqrt{v}, 1\right)} \]
      6. +-commutative93.7%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)} \cdot \sqrt{v}, \sqrt{v}, 1\right) \]
      7. fma-udef93.8%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)} \cdot \sqrt{v}, \sqrt{v}, 1\right) \]
    3. Applied egg-rr93.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot \sqrt{v}, \sqrt{v}, 1\right)} \]
    4. Taylor expanded in u around 0 76.1%

      \[\leadsto \color{blue}{\left(v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) + -0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}}\right) - 1} \]
    5. Step-by-step derivation
      1. associate--l+75.8%

        \[\leadsto \color{blue}{v \cdot \left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right)} \]
      2. associate-*r*75.8%

        \[\leadsto \color{blue}{\left(v \cdot u\right) \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right)} + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      3. rec-exp76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \left(\color{blue}{e^{-\frac{-2}{v}}} - 1\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      4. expm1-def76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \color{blue}{\mathsf{expm1}\left(-\frac{-2}{v}\right)} + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      5. distribute-neg-frac76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\color{blue}{\frac{--2}{v}}\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      6. metadata-eval76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{\color{blue}{2}}{v}\right) + \left(-0.5 \cdot \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}} - 1\right) \]
      7. fma-neg76.0%

        \[\leadsto \left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{2}{v}\right) + \color{blue}{\mathsf{fma}\left(-0.5, \frac{{\left(1 + -1 \cdot e^{\frac{-2}{v}}\right)}^{2} \cdot \left(v \cdot {u}^{2}\right)}{{\left(e^{\frac{-2}{v}}\right)}^{2}}, -1\right)} \]
    6. Simplified76.0%

      \[\leadsto \color{blue}{\left(v \cdot u\right) \cdot \mathsf{expm1}\left(\frac{2}{v}\right) + \mathsf{fma}\left(-0.5, \frac{{\left(1 - e^{\frac{-2}{v}}\right)}^{2}}{\frac{{\left(e^{\frac{-2}{v}}\right)}^{2}}{v \cdot \left(u \cdot u\right)}}, -1\right)} \]
    7. Taylor expanded in v around inf 60.3%

      \[\leadsto \color{blue}{\left(-2 \cdot \frac{{u}^{2}}{v} + \left(2 \cdot u + 2 \cdot \frac{u}{v}\right)\right) - 1} \]
    8. Step-by-step derivation
      1. sub-neg60.3%

        \[\leadsto \color{blue}{\left(-2 \cdot \frac{{u}^{2}}{v} + \left(2 \cdot u + 2 \cdot \frac{u}{v}\right)\right) + \left(-1\right)} \]
      2. fma-def60.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-2, \frac{{u}^{2}}{v}, 2 \cdot u + 2 \cdot \frac{u}{v}\right)} + \left(-1\right) \]
      3. unpow260.3%

        \[\leadsto \mathsf{fma}\left(-2, \frac{\color{blue}{u \cdot u}}{v}, 2 \cdot u + 2 \cdot \frac{u}{v}\right) + \left(-1\right) \]
      4. distribute-lft-out60.3%

        \[\leadsto \mathsf{fma}\left(-2, \frac{u \cdot u}{v}, \color{blue}{2 \cdot \left(u + \frac{u}{v}\right)}\right) + \left(-1\right) \]
      5. metadata-eval60.3%

        \[\leadsto \mathsf{fma}\left(-2, \frac{u \cdot u}{v}, 2 \cdot \left(u + \frac{u}{v}\right)\right) + \color{blue}{-1} \]
    9. Simplified60.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-2, \frac{u \cdot u}{v}, 2 \cdot \left(u + \frac{u}{v}\right)\right) + -1} \]
    10. Taylor expanded in u around 0 58.1%

      \[\leadsto \color{blue}{2 \cdot \left(\left(1 + \frac{1}{v}\right) \cdot u\right) - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(u \cdot \left(1 + \frac{1}{v}\right)\right) + -1\\ \end{array} \]

Alternative 8: 91.0% accurate, 19.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(u + \frac{u}{v}\right) + -1\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612) 1.0 (+ (* 2.0 (+ u (/ u v))) -1.0)))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = (2.0f * (u + (u / v))) + -1.0f;
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = (2.0e0 * (u + (u / v))) + (-1.0e0)
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(Float32(2.0) * Float32(u + Float32(u / v))) + Float32(-1.0));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = (single(2.0) * (u + (u / v))) + single(-1.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(u + \frac{u}{v}\right) + -1\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Taylor expanded in u around 0 67.1%

      \[\leadsto 1 + v \cdot \color{blue}{\left(u \cdot \left(\frac{1}{e^{\frac{-2}{v}}} - 1\right) - 2 \cdot \frac{1}{v}\right)} \]
    3. Taylor expanded in v around inf 58.1%

      \[\leadsto \color{blue}{\left(2 \cdot u + 2 \cdot \frac{u}{v}\right) - 1} \]
    4. Step-by-step derivation
      1. sub-neg58.1%

        \[\leadsto \color{blue}{\left(2 \cdot u + 2 \cdot \frac{u}{v}\right) + \left(-1\right)} \]
      2. distribute-lft-out58.1%

        \[\leadsto \color{blue}{2 \cdot \left(u + \frac{u}{v}\right)} + \left(-1\right) \]
      3. metadata-eval58.1%

        \[\leadsto 2 \cdot \left(u + \frac{u}{v}\right) + \color{blue}{-1} \]
    5. Simplified58.1%

      \[\leadsto \color{blue}{2 \cdot \left(u + \frac{u}{v}\right) + -1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(u + \frac{u}{v}\right) + -1\\ \end{array} \]

Alternative 9: 90.4% accurate, 29.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;u \cdot 2 + -1\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (if (<= v 0.10000000149011612) 1.0 (+ (* u 2.0) -1.0)))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = (u * 2.0f) + -1.0f;
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = (u * 2.0e0) + (-1.0e0)
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(Float32(u * Float32(2.0)) + Float32(-1.0));
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = (u * single(2.0)) + single(-1.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;u \cdot 2 + -1\\


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Taylor expanded in v around inf 51.2%

      \[\leadsto 1 + \color{blue}{-2 \cdot \left(1 - u\right)} \]
    3. Step-by-step derivation
      1. *-commutative51.2%

        \[\leadsto 1 + \color{blue}{\left(1 - u\right) \cdot -2} \]
    4. Simplified51.2%

      \[\leadsto 1 + \color{blue}{\left(1 - u\right) \cdot -2} \]
    5. Taylor expanded in u around 0 51.2%

      \[\leadsto \color{blue}{2 \cdot u - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;u \cdot 2 + -1\\ \end{array} \]

Alternative 10: 89.7% accurate, 68.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (u v) :precision binary32 (if (<= v 0.10000000149011612) 1.0 -1.0))
float code(float u, float v) {
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = 1.0f;
	} else {
		tmp = -1.0f;
	}
	return tmp;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    real(4) :: tmp
    if (v <= 0.10000000149011612e0) then
        tmp = 1.0e0
    else
        tmp = -1.0e0
    end if
    code = tmp
end function
function code(u, v)
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(1.0);
	else
		tmp = Float32(-1.0);
	end
	return tmp
end
function tmp_2 = code(u, v)
	tmp = single(0.0);
	if (v <= single(0.10000000149011612))
		tmp = single(1.0);
	else
		tmp = single(-1.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;1\\

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


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

    1. Initial program 100.0%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)\right)\right)} \]
      2. expm1-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)} - 1}\right) \]
      3. *-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(e^{\color{blue}{\log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \cdot v}} - 1\right) \]
      4. exp-to-pow99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{{\left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)}^{v}} - 1\right) \]
      5. +-commutative99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\left(1 - u\right) \cdot e^{\frac{-2}{v}} + u\right)}}^{v} - 1\right) \]
      6. fma-udef99.9%

        \[\leadsto 1 + \mathsf{log1p}\left({\color{blue}{\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}}^{v} - 1\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto 1 + \color{blue}{\mathsf{log1p}\left({\left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)}^{v} - 1\right)} \]
    4. Step-by-step derivation
      1. pow-to-exp99.9%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{e^{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v}} - 1\right) \]
      2. expm1-def100.0%

        \[\leadsto 1 + \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v\right)}\right) \]
      3. log1p-expm1-u100.0%

        \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    5. Applied egg-rr100.0%

      \[\leadsto 1 + \color{blue}{\log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \cdot v} \]
    6. Taylor expanded in v around 0 94.7%

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

    if 0.100000001 < v

    1. Initial program 94.9%

      \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
    2. Taylor expanded in u around 0 41.7%

      \[\leadsto \color{blue}{-1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 11: 5.8% accurate, 213.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (u v) :precision binary32 -1.0)
float code(float u, float v) {
	return -1.0f;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = -1.0e0
end function
function code(u, v)
	return Float32(-1.0)
end
function tmp = code(u, v)
	tmp = single(-1.0);
end
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 99.5%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Taylor expanded in u around 0 6.8%

    \[\leadsto \color{blue}{-1} \]
  3. Final simplification6.8%

    \[\leadsto -1 \]

Reproduce

?
herbie shell --seed 2023240 
(FPCore (u v)
  :name "HairBSDF, sample_f, cosTheta"
  :precision binary32
  :pre (and (and (<= 1e-5 u) (<= u 1.0)) (and (<= 0.0 v) (<= v 109.746574)))
  (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))