| Alternative 1 | |
|---|---|
| Error | 8.2 |
| Cost | 13900 |
(FPCore (x y z t) :precision binary64 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t))))
(if (<= z -1.75e+36)
t_1
(if (<= z -380000000000.0)
(- x (/ (* (- (exp z) 1.0) y) t))
(if (<= z -5e-5)
t_1
(if (<= z 1.95e-81)
(- x (* y (/ z t)))
(- x (/ (log (+ 1.0 (* y (+ z (* 0.5 (pow z 2.0)))))) t))))))))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 t_1 = x - (log(((1.0 - y) + (y * exp(z)))) / t);
double tmp;
if (z <= -1.75e+36) {
tmp = t_1;
} else if (z <= -380000000000.0) {
tmp = x - (((exp(z) - 1.0) * y) / t);
} else if (z <= -5e-5) {
tmp = t_1;
} else if (z <= 1.95e-81) {
tmp = x - (y * (z / t));
} else {
tmp = x - (log((1.0 + (y * (z + (0.5 * pow(z, 2.0)))))) / t);
}
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) :: t_1
real(8) :: tmp
t_1 = x - (log(((1.0d0 - y) + (y * exp(z)))) / t)
if (z <= (-1.75d+36)) then
tmp = t_1
else if (z <= (-380000000000.0d0)) then
tmp = x - (((exp(z) - 1.0d0) * y) / t)
else if (z <= (-5d-5)) then
tmp = t_1
else if (z <= 1.95d-81) then
tmp = x - (y * (z / t))
else
tmp = x - (log((1.0d0 + (y * (z + (0.5d0 * (z ** 2.0d0)))))) / t)
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 t_1 = x - (Math.log(((1.0 - y) + (y * Math.exp(z)))) / t);
double tmp;
if (z <= -1.75e+36) {
tmp = t_1;
} else if (z <= -380000000000.0) {
tmp = x - (((Math.exp(z) - 1.0) * y) / t);
} else if (z <= -5e-5) {
tmp = t_1;
} else if (z <= 1.95e-81) {
tmp = x - (y * (z / t));
} else {
tmp = x - (Math.log((1.0 + (y * (z + (0.5 * Math.pow(z, 2.0)))))) / t);
}
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): t_1 = x - (math.log(((1.0 - y) + (y * math.exp(z)))) / t) tmp = 0 if z <= -1.75e+36: tmp = t_1 elif z <= -380000000000.0: tmp = x - (((math.exp(z) - 1.0) * y) / t) elif z <= -5e-5: tmp = t_1 elif z <= 1.95e-81: tmp = x - (y * (z / t)) else: tmp = x - (math.log((1.0 + (y * (z + (0.5 * math.pow(z, 2.0)))))) / t) 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) t_1 = Float64(x - Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t)) tmp = 0.0 if (z <= -1.75e+36) tmp = t_1; elseif (z <= -380000000000.0) tmp = Float64(x - Float64(Float64(Float64(exp(z) - 1.0) * y) / t)); elseif (z <= -5e-5) tmp = t_1; elseif (z <= 1.95e-81) tmp = Float64(x - Float64(y * Float64(z / t))); else tmp = Float64(x - Float64(log(Float64(1.0 + Float64(y * Float64(z + Float64(0.5 * (z ^ 2.0)))))) / t)); 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) t_1 = x - (log(((1.0 - y) + (y * exp(z)))) / t); tmp = 0.0; if (z <= -1.75e+36) tmp = t_1; elseif (z <= -380000000000.0) tmp = x - (((exp(z) - 1.0) * y) / t); elseif (z <= -5e-5) tmp = t_1; elseif (z <= 1.95e-81) tmp = x - (y * (z / t)); else tmp = x - (log((1.0 + (y * (z + (0.5 * (z ^ 2.0)))))) / t); 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_] := Block[{t$95$1 = N[(x - N[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.75e+36], t$95$1, If[LessEqual[z, -380000000000.0], N[(x - N[(N[(N[(N[Exp[z], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -5e-5], t$95$1, If[LessEqual[z, 1.95e-81], N[(x - N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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]]]]]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+36}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -380000000000:\\
\;\;\;\;x - \frac{\left(e^{z} - 1\right) \cdot y}{t}\\
\mathbf{elif}\;z \leq -5 \cdot 10^{-5}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{-81}:\\
\;\;\;\;x - y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(1 + y \cdot \left(z + 0.5 \cdot {z}^{2}\right)\right)}{t}\\
\end{array}
Results
| Original | 25.3 |
|---|---|
| Target | 16.4 |
| Herbie | 8.2 |
if z < -1.7499999999999999e36 or -3.8e11 < z < -5.00000000000000024e-5Initial program 12.2
if -1.7499999999999999e36 < z < -3.8e11Initial program 13.4
Taylor expanded in y around 0 14.6
if -5.00000000000000024e-5 < z < 1.94999999999999992e-81Initial program 31.4
Taylor expanded in y around 0 15.2
Taylor expanded in y around 0 15.2
Taylor expanded in z around 0 5.3
Simplified5.3
[Start]5.3 | \[ y \cdot \left(-1 \cdot \frac{z}{t}\right) + x
\] |
|---|---|
rational.json-simplify-2 [=>]5.3 | \[ y \cdot \color{blue}{\left(\frac{z}{t} \cdot -1\right)} + x
\] |
rational.json-simplify-9 [=>]5.3 | \[ y \cdot \color{blue}{\left(-\frac{z}{t}\right)} + x
\] |
Applied egg-rr5.3
Simplified5.3
[Start]5.3 | \[ y \cdot \left(-\frac{z}{t}\right) - \left(-x\right)
\] |
|---|---|
rational.json-simplify-8 [=>]5.3 | \[ y \cdot \color{blue}{\left(\frac{z}{t} \cdot -1\right)} - \left(-x\right)
\] |
rational.json-simplify-43 [<=]5.3 | \[ \color{blue}{-1 \cdot \left(y \cdot \frac{z}{t}\right)} - \left(-x\right)
\] |
rational.json-simplify-8 [=>]5.3 | \[ -1 \cdot \left(y \cdot \frac{z}{t}\right) - \color{blue}{x \cdot -1}
\] |
rational.json-simplify-48 [=>]5.3 | \[ \color{blue}{-1 \cdot \left(y \cdot \frac{z}{t} - x\right)}
\] |
rational.json-simplify-2 [=>]5.3 | \[ \color{blue}{\left(y \cdot \frac{z}{t} - x\right) \cdot -1}
\] |
rational.json-simplify-9 [=>]5.3 | \[ \color{blue}{-\left(y \cdot \frac{z}{t} - x\right)}
\] |
rational.json-simplify-12 [=>]5.3 | \[ \color{blue}{0 - \left(y \cdot \frac{z}{t} - x\right)}
\] |
rational.json-simplify-44 [=>]5.3 | \[ \color{blue}{x - \left(y \cdot \frac{z}{t} - 0\right)}
\] |
rational.json-simplify-5 [=>]5.3 | \[ x - \color{blue}{y \cdot \frac{z}{t}}
\] |
if 1.94999999999999992e-81 < z Initial program 29.3
Taylor expanded in z around 0 13.8
Simplified13.8
[Start]13.8 | \[ 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 [=>]13.8 | \[ 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 [=>]13.8 | \[ 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 [=>]13.8 | \[ 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-47 [=>]13.8 | \[ x - \frac{\log \left(1 + \color{blue}{y \cdot \left(z + {z}^{2} \cdot 0.5\right)}\right)}{t}
\] |
rational.json-simplify-2 [=>]13.8 | \[ x - \frac{\log \left(1 + y \cdot \left(z + \color{blue}{0.5 \cdot {z}^{2}}\right)\right)}{t}
\] |
Final simplification8.2
| Alternative 1 | |
|---|---|
| Error | 8.2 |
| Cost | 13900 |
| Alternative 2 | |
|---|---|
| Error | 8.8 |
| Cost | 13508 |
| Alternative 3 | |
|---|---|
| Error | 8.9 |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 8.9 |
| Cost | 7240 |
| Alternative 5 | |
|---|---|
| Error | 19.1 |
| Cost | 648 |
| Alternative 6 | |
|---|---|
| Error | 11.4 |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Error | 18.3 |
| Cost | 64 |
herbie shell --seed 2023077
(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)))