| Alternative 1 | |
|---|---|
| Error | 14.6 |
| Cost | 456 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -40:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{-66}:\\
\;\;\;\;\frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (+ x (/ (exp (* y (log (/ y (+ z y))))) y)))
(FPCore (x y z) :precision binary64 (+ x (/ (pow (exp y) (log (/ y (+ y z)))) y)))
double code(double x, double y, double z) {
return x + (exp((y * log((y / (z + y))))) / y);
}
double code(double x, double y, double z) {
return x + (pow(exp(y), log((y / (y + z)))) / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (exp((y * log((y / (z + y))))) / y)
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((exp(y) ** log((y / (y + z)))) / y)
end function
public static double code(double x, double y, double z) {
return x + (Math.exp((y * Math.log((y / (z + y))))) / y);
}
public static double code(double x, double y, double z) {
return x + (Math.pow(Math.exp(y), Math.log((y / (y + z)))) / y);
}
def code(x, y, z): return x + (math.exp((y * math.log((y / (z + y))))) / y)
def code(x, y, z): return x + (math.pow(math.exp(y), math.log((y / (y + z)))) / y)
function code(x, y, z) return Float64(x + Float64(exp(Float64(y * log(Float64(y / Float64(z + y))))) / y)) end
function code(x, y, z) return Float64(x + Float64((exp(y) ^ log(Float64(y / Float64(y + z)))) / y)) end
function tmp = code(x, y, z) tmp = x + (exp((y * log((y / (z + y))))) / y); end
function tmp = code(x, y, z) tmp = x + ((exp(y) ^ log((y / (y + z)))) / y); end
code[x_, y_, z_] := N[(x + N[(N[Exp[N[(y * N[Log[N[(y / N[(z + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(x + N[(N[Power[N[Exp[y], $MachinePrecision], N[Log[N[(y / N[(y + z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y}
x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{y + z}\right)}}{y}
Results
| Original | 5.9 |
|---|---|
| Target | 1.0 |
| Herbie | 1.1 |
Initial program 5.9
Simplified1.1
[Start]5.9 | \[ x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y}
\] |
|---|---|
exp-prod [=>]1.1 | \[ x + \frac{\color{blue}{{\left(e^{y}\right)}^{\log \left(\frac{y}{z + y}\right)}}}{y}
\] |
sqr-pow [=>]1.1 | \[ x + \frac{\color{blue}{{\left(e^{y}\right)}^{\left(\frac{\log \left(\frac{y}{z + y}\right)}{2}\right)} \cdot {\left(e^{y}\right)}^{\left(\frac{\log \left(\frac{y}{z + y}\right)}{2}\right)}}}{y}
\] |
sqr-pow [<=]1.1 | \[ x + \frac{\color{blue}{{\left(e^{y}\right)}^{\log \left(\frac{y}{z + y}\right)}}}{y}
\] |
+-commutative [=>]1.1 | \[ x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{\color{blue}{y + z}}\right)}}{y}
\] |
Final simplification1.1
| Alternative 1 | |
|---|---|
| Error | 14.6 |
| Cost | 456 |
| Alternative 2 | |
|---|---|
| Error | 2.5 |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Error | 28.0 |
| Cost | 64 |
herbie shell --seed 2023016
(FPCore (x y z)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, G"
:precision binary64
:herbie-target
(if (< (/ y (+ z y)) 7.11541576e-315) (+ x (/ (exp (/ -1.0 z)) y)) (+ x (/ (exp (log (pow (/ y (+ y z)) y))) y)))
(+ x (/ (exp (* y (log (/ y (+ z y))))) y)))