| Alternative 1 | |
|---|---|
| Error | 9.5 |
| Cost | 7624 |
(FPCore (x y z t) :precision binary64 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t)
:precision binary64
(if (<= z -6.2e+23)
(- x (/ (* (- (exp z) 1.0) y) t))
(if (<= z -1.05e-130)
(- x (/ (log (+ 1.0 (* y (+ z (* 0.5 (pow z 2.0)))))) t))
(+ x (* (+ (* 0.5 (/ (pow z 2.0) t)) (/ z t)) (- y))))))double code(double x, double y, double z, double t) {
return x - (log(((1.0 - y) + (y * exp(z)))) / t);
}
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6.2e+23) {
tmp = x - (((exp(z) - 1.0) * y) / t);
} else if (z <= -1.05e-130) {
tmp = x - (log((1.0 + (y * (z + (0.5 * pow(z, 2.0)))))) / t);
} else {
tmp = x + (((0.5 * (pow(z, 2.0) / t)) + (z / t)) * -y);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - (log(((1.0d0 - y) + (y * exp(z)))) / t)
end function
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-6.2d+23)) then
tmp = x - (((exp(z) - 1.0d0) * y) / t)
else if (z <= (-1.05d-130)) then
tmp = x - (log((1.0d0 + (y * (z + (0.5d0 * (z ** 2.0d0)))))) / t)
else
tmp = x + (((0.5d0 * ((z ** 2.0d0) / t)) + (z / t)) * -y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return x - (Math.log(((1.0 - y) + (y * Math.exp(z)))) / t);
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6.2e+23) {
tmp = x - (((Math.exp(z) - 1.0) * y) / t);
} else if (z <= -1.05e-130) {
tmp = x - (Math.log((1.0 + (y * (z + (0.5 * Math.pow(z, 2.0)))))) / t);
} else {
tmp = x + (((0.5 * (Math.pow(z, 2.0) / t)) + (z / t)) * -y);
}
return tmp;
}
def code(x, y, z, t): return x - (math.log(((1.0 - y) + (y * math.exp(z)))) / t)
def code(x, y, z, t): tmp = 0 if z <= -6.2e+23: tmp = x - (((math.exp(z) - 1.0) * y) / t) elif z <= -1.05e-130: tmp = x - (math.log((1.0 + (y * (z + (0.5 * math.pow(z, 2.0)))))) / t) else: tmp = x + (((0.5 * (math.pow(z, 2.0) / t)) + (z / t)) * -y) return tmp
function code(x, y, z, t) return Float64(x - Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t)) end
function code(x, y, z, t) tmp = 0.0 if (z <= -6.2e+23) tmp = Float64(x - Float64(Float64(Float64(exp(z) - 1.0) * y) / t)); elseif (z <= -1.05e-130) tmp = Float64(x - Float64(log(Float64(1.0 + Float64(y * Float64(z + Float64(0.5 * (z ^ 2.0)))))) / t)); else tmp = Float64(x + Float64(Float64(Float64(0.5 * Float64((z ^ 2.0) / t)) + Float64(z / t)) * Float64(-y))); end return tmp end
function tmp = code(x, y, z, t) tmp = x - (log(((1.0 - y) + (y * exp(z)))) / t); end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -6.2e+23) tmp = x - (((exp(z) - 1.0) * y) / t); elseif (z <= -1.05e-130) tmp = x - (log((1.0 + (y * (z + (0.5 * (z ^ 2.0)))))) / t); else tmp = x + (((0.5 * ((z ^ 2.0) / t)) + (z / t)) * -y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x - N[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[z, -6.2e+23], N[(x - N[(N[(N[(N[Exp[z], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -1.05e-130], N[(x - N[(N[Log[N[(1.0 + N[(y * N[(z + N[(0.5 * N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(N[(0.5 * N[(N[Power[z, 2.0], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] + N[(z / t), $MachinePrecision]), $MachinePrecision] * (-y)), $MachinePrecision]), $MachinePrecision]]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+23}:\\
\;\;\;\;x - \frac{\left(e^{z} - 1\right) \cdot y}{t}\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-130}:\\
\;\;\;\;x - \frac{\log \left(1 + y \cdot \left(z + 0.5 \cdot {z}^{2}\right)\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \left(0.5 \cdot \frac{{z}^{2}}{t} + \frac{z}{t}\right) \cdot \left(-y\right)\\
\end{array}
Results
| Original | 25.3 |
|---|---|
| Target | 16.3 |
| Herbie | 9.8 |
if z < -6.19999999999999941e23Initial program 11.8
Taylor expanded in y around 0 15.0
if -6.19999999999999941e23 < z < -1.05000000000000001e-130Initial program 25.9
Taylor expanded in z around 0 14.2
Simplified14.2
[Start]14.2 | \[ x - \frac{\log \left(y \cdot z + \left(1 + 0.5 \cdot \left(y \cdot {z}^{2}\right)\right)\right)}{t}
\] |
|---|---|
rational.json-simplify-41 [=>]14.2 | \[ x - \frac{\log \color{blue}{\left(1 + \left(0.5 \cdot \left(y \cdot {z}^{2}\right) + y \cdot z\right)\right)}}{t}
\] |
rational.json-simplify-43 [=>]14.2 | \[ x - \frac{\log \left(1 + \left(\color{blue}{y \cdot \left({z}^{2} \cdot 0.5\right)} + y \cdot z\right)\right)}{t}
\] |
rational.json-simplify-2 [=>]14.2 | \[ x - \frac{\log \left(1 + \left(y \cdot \left({z}^{2} \cdot 0.5\right) + \color{blue}{z \cdot y}\right)\right)}{t}
\] |
rational.json-simplify-51 [=>]14.2 | \[ x - \frac{\log \left(1 + \color{blue}{y \cdot \left(z + {z}^{2} \cdot 0.5\right)}\right)}{t}
\] |
rational.json-simplify-2 [=>]14.2 | \[ x - \frac{\log \left(1 + y \cdot \left(z + \color{blue}{0.5 \cdot {z}^{2}}\right)\right)}{t}
\] |
if -1.05000000000000001e-130 < z Initial program 31.6
Taylor expanded in z around 0 14.7
Simplified14.7
[Start]14.7 | \[ x - \frac{y \cdot z + 0.5 \cdot \left({z}^{2} \cdot \left(-1 \cdot {y}^{2} + y\right)\right)}{t}
\] |
|---|---|
rational.json-simplify-2 [=>]14.7 | \[ x - \frac{\color{blue}{z \cdot y} + 0.5 \cdot \left({z}^{2} \cdot \left(-1 \cdot {y}^{2} + y\right)\right)}{t}
\] |
rational.json-simplify-43 [=>]14.7 | \[ x - \frac{z \cdot y + \color{blue}{{z}^{2} \cdot \left(\left(-1 \cdot {y}^{2} + y\right) \cdot 0.5\right)}}{t}
\] |
rational.json-simplify-43 [=>]14.7 | \[ x - \frac{z \cdot y + \color{blue}{\left(-1 \cdot {y}^{2} + y\right) \cdot \left(0.5 \cdot {z}^{2}\right)}}{t}
\] |
rational.json-simplify-1 [=>]14.7 | \[ x - \frac{z \cdot y + \color{blue}{\left(y + -1 \cdot {y}^{2}\right)} \cdot \left(0.5 \cdot {z}^{2}\right)}{t}
\] |
rational.json-simplify-2 [=>]14.7 | \[ x - \frac{z \cdot y + \left(y + \color{blue}{{y}^{2} \cdot -1}\right) \cdot \left(0.5 \cdot {z}^{2}\right)}{t}
\] |
rational.json-simplify-9 [=>]14.7 | \[ x - \frac{z \cdot y + \left(y + \color{blue}{\left(-{y}^{2}\right)}\right) \cdot \left(0.5 \cdot {z}^{2}\right)}{t}
\] |
Taylor expanded in y around 0 6.0
Simplified6.0
[Start]6.0 | \[ -1 \cdot \left(\left(0.5 \cdot \frac{{z}^{2}}{t} + \frac{z}{t}\right) \cdot y\right) + x
\] |
|---|---|
rational.json-simplify-1 [=>]6.0 | \[ \color{blue}{x + -1 \cdot \left(\left(0.5 \cdot \frac{{z}^{2}}{t} + \frac{z}{t}\right) \cdot y\right)}
\] |
rational.json-simplify-43 [=>]6.0 | \[ x + \color{blue}{\left(0.5 \cdot \frac{{z}^{2}}{t} + \frac{z}{t}\right) \cdot \left(y \cdot -1\right)}
\] |
rational.json-simplify-9 [=>]6.0 | \[ x + \left(0.5 \cdot \frac{{z}^{2}}{t} + \frac{z}{t}\right) \cdot \color{blue}{\left(-y\right)}
\] |
Final simplification9.8
| Alternative 1 | |
|---|---|
| Error | 9.5 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 9.5 |
| Cost | 7432 |
| Alternative 3 | |
|---|---|
| Error | 11.8 |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 9.5 |
| Cost | 7240 |
| Alternative 5 | |
|---|---|
| Error | 19.1 |
| Cost | 648 |
| Alternative 6 | |
|---|---|
| Error | 14.8 |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Error | 12.2 |
| Cost | 580 |
| Alternative 8 | |
|---|---|
| Error | 18.6 |
| Cost | 64 |
herbie shell --seed 2023074
(FPCore (x y z t)
:name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
:precision binary64
:herbie-target
(if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))
(- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))