Average Error: 6.7 → 0.8
Time: 13.4s
Precision: binary64
Cost: 15176
\[\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t \]
\[\begin{array}{l} t_1 := \log y \cdot x - t\\ \mathbf{if}\;x + -1 \leq -2 \cdot 10^{+142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq 10^{+135}:\\ \;\;\;\;\left(y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right) + \frac{\log y \cdot \mathsf{fma}\left(x, x, -1\right)}{1 - x \cdot x} \cdot \left(1 - x\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* (log y) x) t)))
   (if (<= (+ x -1.0) -2e+142)
     t_1
     (if (<= (+ x -1.0) 1e+135)
       (-
        (+
         (* y (* (+ -1.0 z) (+ -1.0 (* y -0.5))))
         (* (/ (* (log y) (fma x x -1.0)) (- 1.0 (* x x))) (- 1.0 x)))
        t)
       t_1))))
double code(double x, double y, double z, double t) {
	return (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
}
double code(double x, double y, double z, double t) {
	double t_1 = (log(y) * x) - t;
	double tmp;
	if ((x + -1.0) <= -2e+142) {
		tmp = t_1;
	} else if ((x + -1.0) <= 1e+135) {
		tmp = ((y * ((-1.0 + z) * (-1.0 + (y * -0.5)))) + (((log(y) * fma(x, x, -1.0)) / (1.0 - (x * x))) * (1.0 - x))) - t;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t)
end
function code(x, y, z, t)
	t_1 = Float64(Float64(log(y) * x) - t)
	tmp = 0.0
	if (Float64(x + -1.0) <= -2e+142)
		tmp = t_1;
	elseif (Float64(x + -1.0) <= 1e+135)
		tmp = Float64(Float64(Float64(y * Float64(Float64(-1.0 + z) * Float64(-1.0 + Float64(y * -0.5)))) + Float64(Float64(Float64(log(y) * fma(x, x, -1.0)) / Float64(1.0 - Float64(x * x))) * Float64(1.0 - x))) - t);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[N[(x + -1.0), $MachinePrecision], -2e+142], t$95$1, If[LessEqual[N[(x + -1.0), $MachinePrecision], 1e+135], N[(N[(N[(y * N[(N[(-1.0 + z), $MachinePrecision] * N[(-1.0 + N[(y * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Log[y], $MachinePrecision] * N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], t$95$1]]]
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\begin{array}{l}
t_1 := \log y \cdot x - t\\
\mathbf{if}\;x + -1 \leq -2 \cdot 10^{+142}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x + -1 \leq 10^{+135}:\\
\;\;\;\;\left(y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right) + \frac{\log y \cdot \mathsf{fma}\left(x, x, -1\right)}{1 - x \cdot x} \cdot \left(1 - x\right)\right) - t\\

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


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 x 1) < -2.0000000000000001e142 or 9.99999999999999962e134 < (-.f64 x 1)

    1. Initial program 1.6

      \[\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t \]
    2. Taylor expanded in y around 0 0.3

      \[\leadsto \left(\left(x - 1\right) \cdot \log y + \color{blue}{\left(-0.5 \cdot \left(\left(z - 1\right) \cdot {y}^{2}\right) + \left(-0.3333333333333333 \cdot \left(\left(z - 1\right) \cdot {y}^{3}\right) + -1 \cdot \left(\left(z - 1\right) \cdot y\right)\right)\right)}\right) - t \]
    3. Simplified0.3

      \[\leadsto \left(\left(x - 1\right) \cdot \log y + \color{blue}{\left(-1 + z\right) \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot -0.3333333333333333\right) - y\right)}\right) - t \]
    4. Taylor expanded in x around inf 1.9

      \[\leadsto \color{blue}{\log y \cdot x} - t \]

    if -2.0000000000000001e142 < (-.f64 x 1) < 9.99999999999999962e134

    1. Initial program 8.7

      \[\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t \]
    2. Taylor expanded in y around 0 0.3

      \[\leadsto \left(\left(x - 1\right) \cdot \log y + \color{blue}{\left(-0.5 \cdot \left(\left(z - 1\right) \cdot {y}^{2}\right) + -1 \cdot \left(\left(z - 1\right) \cdot y\right)\right)}\right) - t \]
    3. Simplified0.3

      \[\leadsto \left(\left(x - 1\right) \cdot \log y + \color{blue}{y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right)}\right) - t \]
    4. Applied egg-rr0.3

      \[\leadsto \left(\color{blue}{\frac{\log y \cdot \mathsf{fma}\left(x, x, -1\right)}{1 + x}} + y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right)\right) - t \]
    5. Applied egg-rr0.3

      \[\leadsto \left(\color{blue}{\frac{\log y \cdot \mathsf{fma}\left(x, x, -1\right)}{1 - x \cdot x} \cdot \left(1 - x\right)} + y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right)\right) - t \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + -1 \leq -2 \cdot 10^{+142}:\\ \;\;\;\;\log y \cdot x - t\\ \mathbf{elif}\;x + -1 \leq 10^{+135}:\\ \;\;\;\;\left(y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right) + \frac{\log y \cdot \mathsf{fma}\left(x, x, -1\right)}{1 - x \cdot x} \cdot \left(1 - x\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;\log y \cdot x - t\\ \end{array} \]

Alternatives

Alternative 1
Error1.8
Cost27140
\[\begin{array}{l} t_1 := \log y \cdot \left(x + -1\right)\\ \mathbf{if}\;x \leq 1.297231444543199 \cdot 10^{-16}:\\ \;\;\;\;\left(y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right) + {\left({\left({t_1}^{0.25}\right)}^{2}\right)}^{2}\right) - t\\ \mathbf{else}:\\ \;\;\;\;\left(y + t_1\right) - t\\ \end{array} \]
Alternative 2
Error0.7
Cost27136
\[\begin{array}{l} t_1 := \sqrt[3]{x + -1}\\ \left(t_1 \cdot \left(\log y \cdot {t_1}^{2}\right) + y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right)\right) - t \end{array} \]
Alternative 3
Error0.8
Cost14792
\[\begin{array}{l} t_1 := \log y \cdot x - t\\ \mathbf{if}\;x + -1 \leq -2 \cdot 10^{+142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq 10^{+135}:\\ \;\;\;\;\left(y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right) + \mathsf{fma}\left(x, x, -1\right) \cdot \frac{\log y}{x + 1}\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error0.9
Cost14408
\[\begin{array}{l} t_1 := \log y \cdot x - t\\ \mathbf{if}\;x + -1 \leq -2 \cdot 10^{+142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq 10^{+135}:\\ \;\;\;\;\left(\frac{\log y \cdot \mathsf{fma}\left(x, x, -1\right)}{x + 1} + y \cdot \left(1 - z\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error2.5
Cost13960
\[\begin{array}{l} t_1 := \left(y + \log y \cdot \left(x + -1\right)\right) - t\\ \mathbf{if}\;x + -1 \leq -1.0005:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq -0.9999999998:\\ \;\;\;\;\left(-1 + z\right) \cdot \mathsf{log1p}\left(-y\right) - \left(\log y + t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error2.6
Cost8392
\[\begin{array}{l} t_1 := \left(y + \log y \cdot \left(x + -1\right)\right) - t\\ \mathbf{if}\;x + -1 \leq -1.0005:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq -0.9999999998:\\ \;\;\;\;\left(\left(-1 + z\right) \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot \left(-0.3333333333333333 + y \cdot -0.25\right)\right) - y\right) - \log y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error2.6
Cost8136
\[\begin{array}{l} t_1 := \left(y + \log y \cdot \left(x + -1\right)\right) - t\\ \mathbf{if}\;x + -1 \leq -1.0005:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq -0.9999999998:\\ \;\;\;\;\left(\left(-1 + z\right) \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot -0.3333333333333333\right) - y\right) - \log y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error2.6
Cost7880
\[\begin{array}{l} t_1 := \left(y + \log y \cdot \left(x + -1\right)\right) - t\\ \mathbf{if}\;x + -1 \leq -1.0005:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq -0.9999999998:\\ \;\;\;\;\left(y \cdot \left(\left(-1 + z\right) \cdot \left(-1 + y \cdot -0.5\right)\right) - \log y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error3.2
Cost7496
\[\begin{array}{l} t_1 := \log y \cdot x - t\\ \mathbf{if}\;x + -1 \leq -1 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq 5 \cdot 10^{+16}:\\ \;\;\;\;\left(y - \left(\log y + y \cdot z\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error2.7
Cost7496
\[\begin{array}{l} t_1 := \left(y + \log y \cdot \left(x + -1\right)\right) - t\\ \mathbf{if}\;x + -1 \leq -1.0005:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x + -1 \leq -0.9999999998:\\ \;\;\;\;\left(y - \left(\log y + y \cdot z\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error15.3
Cost6984
\[\begin{array}{l} \mathbf{if}\;t \leq -9.232005716479031 \cdot 10^{+36}:\\ \;\;\;\;y \cdot \left(-z\right) - t\\ \mathbf{elif}\;t \leq 1.8180014669704785 \cdot 10^{+96}:\\ \;\;\;\;\log y \cdot \left(x + -1\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 12
Error8.3
Cost6984
\[\begin{array}{l} t_1 := \log y \cdot x - t\\ \mathbf{if}\;t \leq -180096411267643780:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.656533422335087 \cdot 10^{-17}:\\ \;\;\;\;\log y \cdot \left(x + -1\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error14.9
Cost6920
\[\begin{array}{l} t_1 := \log y \cdot x\\ \mathbf{if}\;x \leq -2.4537609339587795 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.471701837023806 \cdot 10^{+39}:\\ \;\;\;\;\left(-t\right) - \log y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 14
Error21.3
Cost6856
\[\begin{array}{l} t_1 := \log y \cdot x\\ \mathbf{if}\;x \leq -2.4537609339587795 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.485580181532721 \cdot 10^{+81}:\\ \;\;\;\;\left(y - y \cdot z\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 15
Error37.1
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -3.250009685170593 \cdot 10^{-24}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 684.0098824025533:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 16
Error34.8
Cost448
\[\left(y - y \cdot z\right) - t \]
Alternative 17
Error34.9
Cost384
\[y \cdot \left(-z\right) - t \]
Alternative 18
Error41.4
Cost128
\[-t \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (x y z t)
  :name "Statistics.Distribution.Beta:$cdensity from math-functions-0.1.5.2"
  :precision binary64
  (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))