| Alternative 1 | |
|---|---|
| Error | 30.2 |
| Cost | 1240 |
(FPCore (x y z t) :precision binary64 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ (- x (/ y (* z 3.0))) (/ t (* y (* z 3.0))))))
(if (<= t_1 (- INFINITY))
(* (/ t y) (/ 0.3333333333333333 z))
(if (<= t_1 1e+288)
t_1
(+ x (* (/ -0.3333333333333333 z) (- y (/ t y))))))))double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
double code(double x, double y, double z, double t) {
double t_1 = (x - (y / (z * 3.0))) + (t / (y * (z * 3.0)));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = (t / y) * (0.3333333333333333 / z);
} else if (t_1 <= 1e+288) {
tmp = t_1;
} else {
tmp = x + ((-0.3333333333333333 / z) * (y - (t / y)));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x - (y / (z * 3.0))) + (t / (y * (z * 3.0)));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = (t / y) * (0.3333333333333333 / z);
} else if (t_1 <= 1e+288) {
tmp = t_1;
} else {
tmp = x + ((-0.3333333333333333 / z) * (y - (t / y)));
}
return tmp;
}
def code(x, y, z, t): return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y))
def code(x, y, z, t): t_1 = (x - (y / (z * 3.0))) + (t / (y * (z * 3.0))) tmp = 0 if t_1 <= -math.inf: tmp = (t / y) * (0.3333333333333333 / z) elif t_1 <= 1e+288: tmp = t_1 else: tmp = x + ((-0.3333333333333333 / z) * (y - (t / y))) return tmp
function code(x, y, z, t) return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y))) end
function code(x, y, z, t) t_1 = Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(y * Float64(z * 3.0)))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(t / y) * Float64(0.3333333333333333 / z)); elseif (t_1 <= 1e+288) tmp = t_1; else tmp = Float64(x + Float64(Float64(-0.3333333333333333 / z) * Float64(y - Float64(t / y)))); end return tmp end
function tmp = code(x, y, z, t) tmp = (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y)); end
function tmp_2 = code(x, y, z, t) t_1 = (x - (y / (z * 3.0))) + (t / (y * (z * 3.0))); tmp = 0.0; if (t_1 <= -Inf) tmp = (t / y) * (0.3333333333333333 / z); elseif (t_1 <= 1e+288) tmp = t_1; else tmp = x + ((-0.3333333333333333 / z) * (y - (t / y))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(y * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(t / y), $MachinePrecision] * N[(0.3333333333333333 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+288], t$95$1, N[(x + N[(N[(-0.3333333333333333 / z), $MachinePrecision] * N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
t_1 := \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{t}{y} \cdot \frac{0.3333333333333333}{z}\\
\mathbf{elif}\;t_1 \leq 10^{+288}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)\\
\end{array}
Results
| Original | 3.6 |
|---|---|
| Target | 1.6 |
| Herbie | 1.1 |
if (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))) < -inf.0Initial program 64.0
Simplified0.3
[Start]64.0 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-/r* [=>]0.3 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{\frac{t}{z \cdot 3}}{y}}
\] |
Taylor expanded in x around 0 64.0
Simplified10.4
[Start]64.0 | \[ 0.3333333333333333 \cdot \frac{t}{y \cdot z} - 0.3333333333333333 \cdot \frac{y}{z}
\] |
|---|---|
associate-/r* [=>]10.3 | \[ 0.3333333333333333 \cdot \color{blue}{\frac{\frac{t}{y}}{z}} - 0.3333333333333333 \cdot \frac{y}{z}
\] |
associate-*r/ [=>]10.3 | \[ \color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y}}{z}} - 0.3333333333333333 \cdot \frac{y}{z}
\] |
associate-*r/ [=>]10.3 | \[ \frac{0.3333333333333333 \cdot \frac{t}{y}}{z} - \color{blue}{\frac{0.3333333333333333 \cdot y}{z}}
\] |
div-sub [<=]10.3 | \[ \color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y} - 0.3333333333333333 \cdot y}{z}}
\] |
distribute-lft-out-- [=>]10.3 | \[ \frac{\color{blue}{0.3333333333333333 \cdot \left(\frac{t}{y} - y\right)}}{z}
\] |
associate-/l* [=>]10.4 | \[ \color{blue}{\frac{0.3333333333333333}{\frac{z}{\frac{t}{y} - y}}}
\] |
Taylor expanded in t around inf 64.0
Simplified17.6
[Start]64.0 | \[ 0.3333333333333333 \cdot \frac{t}{y \cdot z}
\] |
|---|---|
associate-/r* [=>]17.6 | \[ 0.3333333333333333 \cdot \color{blue}{\frac{\frac{t}{y}}{z}}
\] |
associate-*r/ [=>]17.5 | \[ \color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y}}{z}}
\] |
associate-*l/ [<=]17.6 | \[ \color{blue}{\frac{0.3333333333333333}{z} \cdot \frac{t}{y}}
\] |
*-commutative [<=]17.6 | \[ \color{blue}{\frac{t}{y} \cdot \frac{0.3333333333333333}{z}}
\] |
if -inf.0 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))) < 1e288Initial program 0.5
if 1e288 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))) Initial program 26.6
Simplified3.4
[Start]26.6 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]26.6 | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]26.6 | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]26.6 | \[ x + \color{blue}{-1 \cdot \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
distribute-lft-out-- [<=]26.6 | \[ x + \color{blue}{\left(-1 \cdot \frac{y}{z \cdot 3} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
associate-*r/ [=>]26.6 | \[ x + \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*l/ [<=]26.7 | \[ x + \left(\color{blue}{\frac{-1}{z \cdot 3} \cdot y} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*r/ [=>]26.7 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1 \cdot t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
times-frac [=>]3.4 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]3.4 | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]3.4 | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]3.4 | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]3.4 | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Final simplification1.1
| Alternative 1 | |
|---|---|
| Error | 30.2 |
| Cost | 1240 |
| Alternative 2 | |
|---|---|
| Error | 30.2 |
| Cost | 1240 |
| Alternative 3 | |
|---|---|
| Error | 29.5 |
| Cost | 1240 |
| Alternative 4 | |
|---|---|
| Error | 13.2 |
| Cost | 1236 |
| Alternative 5 | |
|---|---|
| Error | 9.0 |
| Cost | 972 |
| Alternative 6 | |
|---|---|
| Error | 9.0 |
| Cost | 972 |
| Alternative 7 | |
|---|---|
| Error | 9.0 |
| Cost | 972 |
| Alternative 8 | |
|---|---|
| Error | 4.1 |
| Cost | 968 |
| Alternative 9 | |
|---|---|
| Error | 4.1 |
| Cost | 968 |
| Alternative 10 | |
|---|---|
| Error | 4.1 |
| Cost | 968 |
| Alternative 11 | |
|---|---|
| Error | 1.6 |
| Cost | 960 |
| Alternative 12 | |
|---|---|
| Error | 1.6 |
| Cost | 960 |
| Alternative 13 | |
|---|---|
| Error | 15.7 |
| Cost | 713 |
| Alternative 14 | |
|---|---|
| Error | 15.6 |
| Cost | 713 |
| Alternative 15 | |
|---|---|
| Error | 15.6 |
| Cost | 712 |
| Alternative 16 | |
|---|---|
| Error | 15.6 |
| Cost | 712 |
| Alternative 17 | |
|---|---|
| Error | 15.6 |
| Cost | 712 |
| Alternative 18 | |
|---|---|
| Error | 29.0 |
| Cost | 584 |
| Alternative 19 | |
|---|---|
| Error | 29.0 |
| Cost | 584 |
| Alternative 20 | |
|---|---|
| Error | 37.4 |
| Cost | 64 |
herbie shell --seed 2022349
(FPCore (x y z t)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, H"
:precision binary64
:herbie-target
(+ (- x (/ y (* z 3.0))) (/ (/ t (* z 3.0)) y))
(+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))