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

Percentage Accurate: 100.0% → 100.0%
Time: 2.1s
Alternatives: 3
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 3 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. Final simplification100.0%

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

Alternative 2: 84.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{x - z}\\ \mathbf{if}\;x \leq -8.2 \cdot 10^{-10} \lor \neg \left(x \leq -4.3 \cdot 10^{-175}\right) \land x \leq 4.35 \cdot 10^{-299}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot {y}^{y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (exp (- x z))))
   (if (or (<= x -8.2e-10) (and (not (<= x -4.3e-175)) (<= x 4.35e-299)))
     t_0
     (* t_0 (pow y y)))))
double code(double x, double y, double z) {
	double t_0 = exp((x - z));
	double tmp;
	if ((x <= -8.2e-10) || (!(x <= -4.3e-175) && (x <= 4.35e-299))) {
		tmp = t_0;
	} else {
		tmp = t_0 * pow(y, y);
	}
	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 = exp((x - z))
    if ((x <= (-8.2d-10)) .or. (.not. (x <= (-4.3d-175))) .and. (x <= 4.35d-299)) then
        tmp = t_0
    else
        tmp = t_0 * (y ** y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = Math.exp((x - z));
	double tmp;
	if ((x <= -8.2e-10) || (!(x <= -4.3e-175) && (x <= 4.35e-299))) {
		tmp = t_0;
	} else {
		tmp = t_0 * Math.pow(y, y);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = math.exp((x - z))
	tmp = 0
	if (x <= -8.2e-10) or (not (x <= -4.3e-175) and (x <= 4.35e-299)):
		tmp = t_0
	else:
		tmp = t_0 * math.pow(y, y)
	return tmp
function code(x, y, z)
	t_0 = exp(Float64(x - z))
	tmp = 0.0
	if ((x <= -8.2e-10) || (!(x <= -4.3e-175) && (x <= 4.35e-299)))
		tmp = t_0;
	else
		tmp = Float64(t_0 * (y ^ y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = exp((x - z));
	tmp = 0.0;
	if ((x <= -8.2e-10) || (~((x <= -4.3e-175)) && (x <= 4.35e-299)))
		tmp = t_0;
	else
		tmp = t_0 * (y ^ y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -8.2e-10], And[N[Not[LessEqual[x, -4.3e-175]], $MachinePrecision], LessEqual[x, 4.35e-299]]], t$95$0, N[(t$95$0 * N[Power[y, y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{x - z}\\
\mathbf{if}\;x \leq -8.2 \cdot 10^{-10} \lor \neg \left(x \leq -4.3 \cdot 10^{-175}\right) \land x \leq 4.35 \cdot 10^{-299}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot {y}^{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -8.1999999999999996e-10 or -4.29999999999999998e-175 < x < 4.35000000000000012e-299

    1. Initial program 100.0%

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

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

    if -8.1999999999999996e-10 < x < -4.29999999999999998e-175 or 4.35000000000000012e-299 < x

    1. Initial program 100.0%

      \[e^{\left(x + y \cdot \log y\right) - z} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto e^{\color{blue}{\left(y \cdot \log y + x\right)} - z} \]
      2. associate--l+100.0%

        \[\leadsto e^{\color{blue}{y \cdot \log y + \left(x - z\right)}} \]
      3. exp-sum92.3%

        \[\leadsto \color{blue}{e^{y \cdot \log y} \cdot e^{x - z}} \]
      4. *-commutative92.3%

        \[\leadsto e^{\color{blue}{\log y \cdot y}} \cdot e^{x - z} \]
      5. exp-to-pow92.3%

        \[\leadsto \color{blue}{{y}^{y}} \cdot e^{x - z} \]
    3. Simplified92.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.2 \cdot 10^{-10} \lor \neg \left(x \leq -4.3 \cdot 10^{-175}\right) \land x \leq 4.35 \cdot 10^{-299}:\\ \;\;\;\;e^{x - z}\\ \mathbf{else}:\\ \;\;\;\;e^{x - z} \cdot {y}^{y}\\ \end{array} \]

Alternative 3: 78.5% 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. Taylor expanded in x around inf 83.8%

    \[\leadsto e^{\color{blue}{x} - z} \]
  3. Final simplification83.8%

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

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 2023196 
(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)))