Statistics.Distribution.Poisson.Internal:probability from math-functions-0.1.5.2

Percentage Accurate: 100.0% → 100.0%
Time: 3.7s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ e^{\left(x + y \cdot \log y\right) - z} \end{array} \]
(FPCore (x y z) :precision binary64 (exp (- (+ x (* y (log y))) z)))
double code(double x, double y, double z) {
	return exp(((x + (y * log(y))) - z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = exp(((x + (y * log(y))) - z))
end function
public static double code(double x, double y, double z) {
	return Math.exp(((x + (y * Math.log(y))) - z));
}
def code(x, y, z):
	return math.exp(((x + (y * math.log(y))) - z))
function code(x, y, z)
	return exp(Float64(Float64(x + Float64(y * log(y))) - z))
end
function tmp = code(x, y, z)
	tmp = exp(((x + (y * log(y))) - z));
end
code[x_, y_, z_] := N[Exp[N[(N[(x + N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left(x + y \cdot \log y\right) - z}
\end{array}

Sampling outcomes in binary64 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 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ e^{\left(x + y \cdot \log y\right) - z} \end{array} \]
(FPCore (x y z) :precision binary64 (exp (- (+ x (* y (log y))) z)))
double code(double x, double y, double z) {
	return exp(((x + (y * log(y))) - z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = exp(((x + (y * log(y))) - z))
end function
public static double code(double x, double y, double z) {
	return Math.exp(((x + (y * Math.log(y))) - z));
}
def code(x, y, z):
	return math.exp(((x + (y * math.log(y))) - z))
function code(x, y, z)
	return exp(Float64(Float64(x + Float64(y * log(y))) - z))
end
function tmp = code(x, y, z)
	tmp = exp(((x + (y * log(y))) - z));
end
code[x_, y_, z_] := N[Exp[N[(N[(x + N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left(x + y \cdot \log y\right) - z}
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ e^{\left(x + y \cdot \log y\right) - z} \end{array} \]
(FPCore (x y z) :precision binary64 (exp (- (+ x (* y (log y))) z)))
double code(double x, double y, double z) {
	return exp(((x + (y * log(y))) - z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = exp(((x + (y * log(y))) - z))
end function
public static double code(double x, double y, double z) {
	return Math.exp(((x + (y * Math.log(y))) - z));
}
def code(x, y, z):
	return math.exp(((x + (y * math.log(y))) - z))
function code(x, y, z)
	return exp(Float64(Float64(x + Float64(y * log(y))) - z))
end
function tmp = code(x, y, z)
	tmp = exp(((x + (y * log(y))) - z));
end
code[x_, y_, z_] := N[Exp[N[(N[(x + N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left(x + y \cdot \log y\right) - z}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{\left(x + y \cdot \log y\right) - z} \]
  2. Add Preprocessing
  3. Final simplification100.0%

    \[\leadsto e^{\left(x + y \cdot \log y\right) - z} \]
  4. Add Preprocessing

Alternative 2: 90.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \log y\\ \mathbf{if}\;t\_0 \leq 1.25 \cdot 10^{+48} \lor \neg \left(t\_0 \leq 9 \cdot 10^{+83}\right) \land t\_0 \leq 3.2 \cdot 10^{+107}:\\ \;\;\;\;e^{x - z}\\ \mathbf{else}:\\ \;\;\;\;e^{t\_0}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (log y))))
   (if (or (<= t_0 1.25e+48) (and (not (<= t_0 9e+83)) (<= t_0 3.2e+107)))
     (exp (- x z))
     (exp t_0))))
double code(double x, double y, double z) {
	double t_0 = y * log(y);
	double tmp;
	if ((t_0 <= 1.25e+48) || (!(t_0 <= 9e+83) && (t_0 <= 3.2e+107))) {
		tmp = exp((x - z));
	} else {
		tmp = exp(t_0);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y * log(y)
    if ((t_0 <= 1.25d+48) .or. (.not. (t_0 <= 9d+83)) .and. (t_0 <= 3.2d+107)) then
        tmp = exp((x - z))
    else
        tmp = exp(t_0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * Math.log(y);
	double tmp;
	if ((t_0 <= 1.25e+48) || (!(t_0 <= 9e+83) && (t_0 <= 3.2e+107))) {
		tmp = Math.exp((x - z));
	} else {
		tmp = Math.exp(t_0);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * math.log(y)
	tmp = 0
	if (t_0 <= 1.25e+48) or (not (t_0 <= 9e+83) and (t_0 <= 3.2e+107)):
		tmp = math.exp((x - z))
	else:
		tmp = math.exp(t_0)
	return tmp
function code(x, y, z)
	t_0 = Float64(y * log(y))
	tmp = 0.0
	if ((t_0 <= 1.25e+48) || (!(t_0 <= 9e+83) && (t_0 <= 3.2e+107)))
		tmp = exp(Float64(x - z));
	else
		tmp = exp(t_0);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * log(y);
	tmp = 0.0;
	if ((t_0 <= 1.25e+48) || (~((t_0 <= 9e+83)) && (t_0 <= 3.2e+107)))
		tmp = exp((x - z));
	else
		tmp = exp(t_0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, 1.25e+48], And[N[Not[LessEqual[t$95$0, 9e+83]], $MachinePrecision], LessEqual[t$95$0, 3.2e+107]]], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], N[Exp[t$95$0], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \log y\\
\mathbf{if}\;t\_0 \leq 1.25 \cdot 10^{+48} \lor \neg \left(t\_0 \leq 9 \cdot 10^{+83}\right) \land t\_0 \leq 3.2 \cdot 10^{+107}:\\
\;\;\;\;e^{x - z}\\

\mathbf{else}:\\
\;\;\;\;e^{t\_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y (log.f64 y)) < 1.24999999999999993e48 or 8.9999999999999999e83 < (*.f64 y (log.f64 y)) < 3.20000000000000029e107

    1. Initial program 100.0%

      \[e^{\left(x + y \cdot \log y\right) - z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 98.4%

      \[\leadsto e^{\color{blue}{x} - z} \]

    if 1.24999999999999993e48 < (*.f64 y (log.f64 y)) < 8.9999999999999999e83 or 3.20000000000000029e107 < (*.f64 y (log.f64 y))

    1. Initial program 100.0%

      \[e^{\left(x + y \cdot \log y\right) - z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 97.1%

      \[\leadsto e^{\color{blue}{y \cdot \log y - z}} \]
    4. Taylor expanded in y around inf 93.2%

      \[\leadsto e^{\color{blue}{-1 \cdot \left(y \cdot \log \left(\frac{1}{y}\right)\right)}} \]
    5. Step-by-step derivation
      1. mul-1-neg93.2%

        \[\leadsto e^{\color{blue}{-y \cdot \log \left(\frac{1}{y}\right)}} \]
      2. distribute-rgt-neg-in93.2%

        \[\leadsto e^{\color{blue}{y \cdot \left(-\log \left(\frac{1}{y}\right)\right)}} \]
      3. log-rec93.2%

        \[\leadsto e^{y \cdot \left(-\color{blue}{\left(-\log y\right)}\right)} \]
      4. remove-double-neg93.2%

        \[\leadsto e^{y \cdot \color{blue}{\log y}} \]
    6. Simplified93.2%

      \[\leadsto e^{\color{blue}{y \cdot \log y}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \log y \leq 1.25 \cdot 10^{+48} \lor \neg \left(y \cdot \log y \leq 9 \cdot 10^{+83}\right) \land y \cdot \log y \leq 3.2 \cdot 10^{+107}:\\ \;\;\;\;e^{x - z}\\ \mathbf{else}:\\ \;\;\;\;e^{y \cdot \log y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 94.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \log y\\ \mathbf{if}\;t\_0 \leq 10^{+26}:\\ \;\;\;\;e^{x - z}\\ \mathbf{else}:\\ \;\;\;\;e^{t\_0 - z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (log y))))
   (if (<= t_0 1e+26) (exp (- x z)) (exp (- t_0 z)))))
double code(double x, double y, double z) {
	double t_0 = y * log(y);
	double tmp;
	if (t_0 <= 1e+26) {
		tmp = exp((x - z));
	} else {
		tmp = exp((t_0 - z));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y * log(y)
    if (t_0 <= 1d+26) then
        tmp = exp((x - z))
    else
        tmp = exp((t_0 - z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * Math.log(y);
	double tmp;
	if (t_0 <= 1e+26) {
		tmp = Math.exp((x - z));
	} else {
		tmp = Math.exp((t_0 - z));
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * math.log(y)
	tmp = 0
	if t_0 <= 1e+26:
		tmp = math.exp((x - z))
	else:
		tmp = math.exp((t_0 - z))
	return tmp
function code(x, y, z)
	t_0 = Float64(y * log(y))
	tmp = 0.0
	if (t_0 <= 1e+26)
		tmp = exp(Float64(x - z));
	else
		tmp = exp(Float64(t_0 - z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * log(y);
	tmp = 0.0;
	if (t_0 <= 1e+26)
		tmp = exp((x - z));
	else
		tmp = exp((t_0 - z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e+26], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], N[Exp[N[(t$95$0 - z), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \log y\\
\mathbf{if}\;t\_0 \leq 10^{+26}:\\
\;\;\;\;e^{x - z}\\

\mathbf{else}:\\
\;\;\;\;e^{t\_0 - z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y (log.f64 y)) < 1.00000000000000005e26

    1. Initial program 100.0%

      \[e^{\left(x + y \cdot \log y\right) - z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 99.6%

      \[\leadsto e^{\color{blue}{x} - z} \]

    if 1.00000000000000005e26 < (*.f64 y (log.f64 y))

    1. Initial program 100.0%

      \[e^{\left(x + y \cdot \log y\right) - z} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 95.7%

      \[\leadsto e^{\color{blue}{y \cdot \log y - z}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \log y \leq 10^{+26}:\\ \;\;\;\;e^{x - z}\\ \mathbf{else}:\\ \;\;\;\;e^{y \cdot \log y - z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ e^{x - z} \end{array} \]
(FPCore (x y z) :precision binary64 (exp (- x z)))
double code(double x, double y, double z) {
	return exp((x - z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = exp((x - z))
end function
public static double code(double x, double y, double z) {
	return Math.exp((x - z));
}
def code(x, y, z):
	return math.exp((x - z))
function code(x, y, z)
	return exp(Float64(x - z))
end
function tmp = code(x, y, z)
	tmp = exp((x - z));
end
code[x_, y_, z_] := N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{x - z}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{\left(x + y \cdot \log y\right) - z} \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 78.4%

    \[\leadsto e^{\color{blue}{x} - z} \]
  4. Final simplification78.4%

    \[\leadsto e^{x - z} \]
  5. Add Preprocessing

Alternative 5: 52.1% accurate, 2.0× speedup?

\[\begin{array}{l} \\ e^{-z} \end{array} \]
(FPCore (x y z) :precision binary64 (exp (- z)))
double code(double x, double y, double z) {
	return exp(-z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = exp(-z)
end function
public static double code(double x, double y, double z) {
	return Math.exp(-z);
}
def code(x, y, z):
	return math.exp(-z)
function code(x, y, z)
	return exp(Float64(-z))
end
function tmp = code(x, y, z)
	tmp = exp(-z);
end
code[x_, y_, z_] := N[Exp[(-z)], $MachinePrecision]
\begin{array}{l}

\\
e^{-z}
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{\left(x + y \cdot \log y\right) - z} \]
  2. Add Preprocessing
  3. Taylor expanded in z around inf 51.5%

    \[\leadsto e^{\color{blue}{-1 \cdot z}} \]
  4. Step-by-step derivation
    1. neg-mul-151.5%

      \[\leadsto e^{\color{blue}{-z}} \]
  5. Simplified51.5%

    \[\leadsto e^{\color{blue}{-z}} \]
  6. Final simplification51.5%

    \[\leadsto e^{-z} \]
  7. Add Preprocessing

Developer target: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ e^{\left(x - z\right) + \log y \cdot y} \end{array} \]
(FPCore (x y z) :precision binary64 (exp (+ (- x z) (* (log y) y))))
double code(double x, double y, double z) {
	return exp(((x - z) + (log(y) * y)));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = exp(((x - z) + (log(y) * y)))
end function
public static double code(double x, double y, double z) {
	return Math.exp(((x - z) + (Math.log(y) * y)));
}
def code(x, y, z):
	return math.exp(((x - z) + (math.log(y) * y)))
function code(x, y, z)
	return exp(Float64(Float64(x - z) + Float64(log(y) * y)))
end
function tmp = code(x, y, z)
	tmp = exp(((x - z) + (log(y) * y)));
end
code[x_, y_, z_] := N[Exp[N[(N[(x - z), $MachinePrecision] + N[(N[Log[y], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left(x - z\right) + \log y \cdot y}
\end{array}

Reproduce

?
herbie shell --seed 2024044 
(FPCore (x y z)
  :name "Statistics.Distribution.Poisson.Internal:probability from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (exp (+ (- x z) (* (log y) y)))

  (exp (- (+ x (* y (log y))) z)))