?

Average Error: 13.0 → 1.8
Time: 1.7min
Precision: binary64
Cost: 46216

?

\[\left(0 \leq s \land s \leq 256\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 0.25\right)\]
\[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
\[\begin{array}{l} t_0 := \log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right)\\ t_1 := s \cdot t_0\\ \mathbf{if}\;1 - 4 \cdot u \leq 0.9995:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_1 \ne 0:\\ \;\;\;\;{\left(\frac{\frac{1}{s}}{t_0}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(64, {u}^{4}, 4 \cdot u\right), s, \left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) \cdot s\right)\\ \end{array} \]
(FPCore (s u) :precision binary64 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
(FPCore (s u)
 :precision binary64
 (let* ((t_0 (log (pow (fma -4.0 u 1.0) -1.0))) (t_1 (* s t_0)))
   (if (<= (- 1.0 (* 4.0 u)) 0.9995)
     (if (!= t_1 0.0) (pow (/ (/ 1.0 s) t_0) -1.0) t_1)
     (fma
      (fma 64.0 (pow u 4.0) (* 4.0 u))
      s
      (* (* (pow u 2.0) (+ 8.0 (* 21.333333333333332 u))) s)))))
double code(double s, double u) {
	return s * log((1.0 / (1.0 - (4.0 * u))));
}
double code(double s, double u) {
	double t_0 = log(pow(fma(-4.0, u, 1.0), -1.0));
	double t_1 = s * t_0;
	double tmp_1;
	if ((1.0 - (4.0 * u)) <= 0.9995) {
		double tmp_2;
		if (t_1 != 0.0) {
			tmp_2 = pow(((1.0 / s) / t_0), -1.0);
		} else {
			tmp_2 = t_1;
		}
		tmp_1 = tmp_2;
	} else {
		tmp_1 = fma(fma(64.0, pow(u, 4.0), (4.0 * u)), s, ((pow(u, 2.0) * (8.0 + (21.333333333333332 * u))) * s));
	}
	return tmp_1;
}
function code(s, u)
	return Float64(s * log(Float64(1.0 / Float64(1.0 - Float64(4.0 * u)))))
end
function code(s, u)
	t_0 = log((fma(-4.0, u, 1.0) ^ -1.0))
	t_1 = Float64(s * t_0)
	tmp_1 = 0.0
	if (Float64(1.0 - Float64(4.0 * u)) <= 0.9995)
		tmp_2 = 0.0
		if (t_1 != 0.0)
			tmp_2 = Float64(Float64(1.0 / s) / t_0) ^ -1.0;
		else
			tmp_2 = t_1;
		end
		tmp_1 = tmp_2;
	else
		tmp_1 = fma(fma(64.0, (u ^ 4.0), Float64(4.0 * u)), s, Float64(Float64((u ^ 2.0) * Float64(8.0 + Float64(21.333333333333332 * u))) * s));
	end
	return tmp_1
end
code[s_, u_] := N[(s * N[Log[N[(1.0 / N[(1.0 - N[(4.0 * u), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[s_, u_] := Block[{t$95$0 = N[Log[N[Power[N[(-4.0 * u + 1.0), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(s * t$95$0), $MachinePrecision]}, If[LessEqual[N[(1.0 - N[(4.0 * u), $MachinePrecision]), $MachinePrecision], 0.9995], If[Unequal[t$95$1, 0.0], N[Power[N[(N[(1.0 / s), $MachinePrecision] / t$95$0), $MachinePrecision], -1.0], $MachinePrecision], t$95$1], N[(N[(64.0 * N[Power[u, 4.0], $MachinePrecision] + N[(4.0 * u), $MachinePrecision]), $MachinePrecision] * s + N[(N[(N[Power[u, 2.0], $MachinePrecision] * N[(8.0 + N[(21.333333333333332 * u), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * s), $MachinePrecision]), $MachinePrecision]]]]
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\begin{array}{l}
t_0 := \log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right)\\
t_1 := s \cdot t_0\\
\mathbf{if}\;1 - 4 \cdot u \leq 0.9995:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t_1 \ne 0:\\
\;\;\;\;{\left(\frac{\frac{1}{s}}{t_0}\right)}^{-1}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(64, {u}^{4}, 4 \cdot u\right), s, \left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) \cdot s\right)\\


\end{array}

Error?

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 1 (*.f64 4 u)) < 0.99950000000000006

    1. Initial program 4.0

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Applied egg-rr4.2

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;s \cdot \log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right) \ne 0:\\ \;\;\;\;{\left(\frac{1}{s \cdot \log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right)}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right)\\ } \end{array}} \]
    3. Simplified4.2

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;s \cdot \log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right) \ne 0:\\ \;\;\;\;{\left(\frac{\frac{1}{s}}{\log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right)}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right)\\ } \end{array}} \]
      Proof

    if 0.99950000000000006 < (-.f64 1 (*.f64 4 u))

    1. Initial program 18.3

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Taylor expanded in u around 0 0.6

      \[\leadsto \color{blue}{21.333333333333332 \cdot \left({u}^{3} \cdot s\right) + \left(4 \cdot \left(s \cdot u\right) + \left(8 \cdot \left(s \cdot {u}^{2}\right) + 64 \cdot \left(s \cdot {u}^{4}\right)\right)\right)} \]
    3. Applied egg-rr0.7

      \[\leadsto 21.333333333333332 \cdot \left({u}^{3} \cdot s\right) + \color{blue}{\left(8 \cdot \left(u \cdot \left(s \cdot u\right)\right) + s \cdot \left(4 \cdot u + 64 \cdot {u}^{4}\right)\right)} \]
    4. Simplified0.6

      \[\leadsto 21.333333333333332 \cdot \left({u}^{3} \cdot s\right) + \color{blue}{\mathsf{fma}\left(s, \mathsf{fma}\left(64, {u}^{4}, u \cdot 4\right), \left(\left(u \cdot s\right) \cdot u\right) \cdot 8\right)} \]
      Proof
    5. Applied egg-rr0.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(64, {u}^{4}, 4 \cdot u\right), s, s \cdot \left(u \cdot \left(8 \cdot u\right) + 21.333333333333332 \cdot {u}^{3}\right)\right)} \]
    6. Applied egg-rr0.4

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(64, {u}^{4}, 4 \cdot u\right), s, \color{blue}{\left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) \cdot s}\right) \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error1.7
Cost26948
\[\begin{array}{l} \mathbf{if}\;4 \cdot u \leq 0.0005:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(64, {u}^{4}, 4 \cdot u\right), s, \left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) \cdot s\right)\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left({\left(\frac{1}{{\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{3}}\right)}^{0.3333333333333333}\right)\\ \end{array} \]
Alternative 2
Error1.8
Cost26436
\[\begin{array}{l} \mathbf{if}\;4 \cdot u \leq 0.0005:\\ \;\;\;\;\left(s \cdot \left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) + \left(64 \cdot {u}^{4}\right) \cdot s\right) + \left(4 \cdot u\right) \cdot s\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left({\left(\frac{1}{{\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{3}}\right)}^{0.3333333333333333}\right)\\ \end{array} \]
Alternative 3
Error1.8
Cost20100
\[\begin{array}{l} \mathbf{if}\;4 \cdot u \leq 0.0005:\\ \;\;\;\;\left(s \cdot \left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) + \left(64 \cdot {u}^{4}\right) \cdot s\right) + \left(4 \cdot u\right) \cdot s\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left({\left(\mathsf{fma}\left(-4, u, 1\right)\right)}^{-1}\right) \cdot s}{3} \cdot 3\\ \end{array} \]
Alternative 4
Error1.8
Cost14532
\[\begin{array}{l} \mathbf{if}\;4 \cdot u \leq 0.0005:\\ \;\;\;\;\left(s \cdot \left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) + \left(4 \cdot u\right) \cdot s\right) + \left(64 \cdot {u}^{4}\right) \cdot s\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)\\ \end{array} \]
Alternative 5
Error1.8
Cost14532
\[\begin{array}{l} \mathbf{if}\;4 \cdot u \leq 0.0005:\\ \;\;\;\;\left(s \cdot \left({u}^{2} \cdot \left(8 + 21.333333333333332 \cdot u\right)\right) + \left(64 \cdot {u}^{4}\right) \cdot s\right) + \left(4 \cdot u\right) \cdot s\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)\\ \end{array} \]
Alternative 6
Error1.8
Cost14212
\[\begin{array}{l} \mathbf{if}\;4 \cdot u \leq 0.0005:\\ \;\;\;\;s \cdot \left(\mathsf{fma}\left(64, {u}^{4}, 4 \cdot u\right) + \left(u \cdot u\right) \cdot \left(8 + 21.333333333333332 \cdot u\right)\right)\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)\\ \end{array} \]
Alternative 7
Error3.0
Cost7556
\[\begin{array}{l} \mathbf{if}\;4 \cdot u \leq 0.000116:\\ \;\;\;\;s \cdot \left({u}^{2} \cdot \left(21.333333333333332 \cdot u + 8\right) + 4 \cdot u\right)\\ \mathbf{else}:\\ \;\;\;\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)\\ \end{array} \]
Alternative 8
Error6.3
Cost7364
\[\begin{array}{l} t_0 := 1 - 4 \cdot u\\ \mathbf{if}\;t_0 \leq 0.9999961:\\ \;\;\;\;s \cdot \log \left(\frac{1}{t_0}\right)\\ \mathbf{else}:\\ \;\;\;\;s \cdot \left(u \cdot 4 + 8 \cdot \left(u \cdot u\right)\right)\\ \end{array} \]
Alternative 9
Error21.8
Cost704
\[s \cdot \left(u \cdot 4 + 8 \cdot \left(u \cdot u\right)\right) \]
Alternative 10
Error21.9
Cost576
\[s \cdot \left(u \cdot \left(4 - -8 \cdot u\right)\right) \]
Alternative 11
Error36.5
Cost320
\[4 \cdot \left(u \cdot s\right) \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (s u)
  :name "Disney BSSRDF, sample scattering profile, lower"
  :precision binary64
  :pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 2.328306437e-10 u) (<= u 0.25)))
  (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))