| Alternative 1 | |
|---|---|
| Error | 20.2 |
| Cost | 1616 |
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ (* x y) (* t (* z -9.0)))))
(if (<= t_1 (- INFINITY))
(* (* t (/ z a)) -4.5)
(if (<= t_1 5e+303) (/ t_1 (* a 2.0)) (* y (/ (* x 0.5) a))))))double code(double x, double y, double z, double t, double a) {
return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
double code(double x, double y, double z, double t, double a) {
double t_1 = (x * y) + (t * (z * -9.0));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = (t * (z / a)) * -4.5;
} else if (t_1 <= 5e+303) {
tmp = t_1 / (a * 2.0);
} else {
tmp = y * ((x * 0.5) / a);
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (x * y) + (t * (z * -9.0));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = (t * (z / a)) * -4.5;
} else if (t_1 <= 5e+303) {
tmp = t_1 / (a * 2.0);
} else {
tmp = y * ((x * 0.5) / a);
}
return tmp;
}
def code(x, y, z, t, a): return ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
def code(x, y, z, t, a): t_1 = (x * y) + (t * (z * -9.0)) tmp = 0 if t_1 <= -math.inf: tmp = (t * (z / a)) * -4.5 elif t_1 <= 5e+303: tmp = t_1 / (a * 2.0) else: tmp = y * ((x * 0.5) / a) return tmp
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0)) end
function code(x, y, z, t, a) t_1 = Float64(Float64(x * y) + Float64(t * Float64(z * -9.0))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(t * Float64(z / a)) * -4.5); elseif (t_1 <= 5e+303) tmp = Float64(t_1 / Float64(a * 2.0)); else tmp = Float64(y * Float64(Float64(x * 0.5) / a)); end return tmp end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - ((z * 9.0) * t)) / (a * 2.0); end
function tmp_2 = code(x, y, z, t, a) t_1 = (x * y) + (t * (z * -9.0)); tmp = 0.0; if (t_1 <= -Inf) tmp = (t * (z / a)) * -4.5; elseif (t_1 <= 5e+303) tmp = t_1 / (a * 2.0); else tmp = y * ((x * 0.5) / a); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] + N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(t * N[(z / a), $MachinePrecision]), $MachinePrecision] * -4.5), $MachinePrecision], If[LessEqual[t$95$1, 5e+303], N[(t$95$1 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(x * 0.5), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := x \cdot y + t \cdot \left(z \cdot -9\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\left(t \cdot \frac{z}{a}\right) \cdot -4.5\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+303}:\\
\;\;\;\;\frac{t_1}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\
\end{array}
Results
| Original | 8.0 |
|---|---|
| Target | 5.5 |
| Herbie | 4.4 |
if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -inf.0Initial program 64.0
Simplified63.6
[Start]64.0 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]64.0 | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
remove-double-neg [<=]64.0 | \[ \frac{\color{blue}{\left(-\left(-x \cdot y\right)\right)} + \left(-\left(z \cdot 9\right) \cdot t\right)}{a \cdot 2}
\] |
distribute-neg-in [<=]64.0 | \[ \frac{\color{blue}{-\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [<=]64.0 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}}{a \cdot 2}
\] |
sub-neg [<=]64.0 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]64.0 | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]64.0 | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]64.0 | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
sub-neg [=>]64.0 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}
\] |
+-commutative [=>]64.0 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}
\] |
neg-sub0 [=>]64.0 | \[ \frac{-1}{a \cdot 2} \cdot \left(\color{blue}{\left(0 - x \cdot y\right)} + \left(z \cdot 9\right) \cdot t\right)
\] |
associate-+l- [=>]64.0 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(0 - \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
sub0-neg [=>]64.0 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
distribute-rgt-neg-out [=>]64.0 | \[ \color{blue}{-\frac{-1}{a \cdot 2} \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
distribute-lft-neg-in [=>]64.0 | \[ \color{blue}{\left(-\frac{-1}{a \cdot 2}\right) \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
Taylor expanded in x around 0 62.7
Simplified63.0
[Start]62.7 | \[ -4.5 \cdot \frac{t \cdot z}{a}
\] |
|---|---|
associate-*r/ [=>]63.0 | \[ \color{blue}{\frac{-4.5 \cdot \left(t \cdot z\right)}{a}}
\] |
Applied egg-rr31.6
if -inf.0 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 4.9999999999999997e303Initial program 0.7
if 4.9999999999999997e303 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) Initial program 62.2
Simplified61.7
[Start]62.2 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]62.2 | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
remove-double-neg [<=]62.2 | \[ \frac{\color{blue}{\left(-\left(-x \cdot y\right)\right)} + \left(-\left(z \cdot 9\right) \cdot t\right)}{a \cdot 2}
\] |
distribute-neg-in [<=]62.2 | \[ \frac{\color{blue}{-\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [<=]62.2 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}}{a \cdot 2}
\] |
sub-neg [<=]62.2 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]62.2 | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]62.2 | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]62.2 | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
sub-neg [=>]62.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}
\] |
+-commutative [=>]62.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}
\] |
neg-sub0 [=>]62.2 | \[ \frac{-1}{a \cdot 2} \cdot \left(\color{blue}{\left(0 - x \cdot y\right)} + \left(z \cdot 9\right) \cdot t\right)
\] |
associate-+l- [=>]62.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(0 - \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
sub0-neg [=>]62.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
distribute-rgt-neg-out [=>]62.2 | \[ \color{blue}{-\frac{-1}{a \cdot 2} \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
distribute-lft-neg-in [=>]62.2 | \[ \color{blue}{\left(-\frac{-1}{a \cdot 2}\right) \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
Taylor expanded in x around inf 62.0
Simplified32.4
[Start]62.0 | \[ 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
*-commutative [<=]62.0 | \[ 0.5 \cdot \frac{\color{blue}{x \cdot y}}{a}
\] |
associate-*r/ [=>]62.0 | \[ \color{blue}{\frac{0.5 \cdot \left(x \cdot y\right)}{a}}
\] |
associate-*l/ [<=]62.0 | \[ \color{blue}{\frac{0.5}{a} \cdot \left(x \cdot y\right)}
\] |
associate-*r* [=>]32.5 | \[ \color{blue}{\left(\frac{0.5}{a} \cdot x\right) \cdot y}
\] |
*-commutative [=>]32.5 | \[ \color{blue}{y \cdot \left(\frac{0.5}{a} \cdot x\right)}
\] |
associate-*l/ [=>]32.4 | \[ y \cdot \color{blue}{\frac{0.5 \cdot x}{a}}
\] |
Final simplification4.4
| Alternative 1 | |
|---|---|
| Error | 20.2 |
| Cost | 1616 |
| Alternative 2 | |
|---|---|
| Error | 20.2 |
| Cost | 1616 |
| Alternative 3 | |
|---|---|
| Error | 20.2 |
| Cost | 1488 |
| Alternative 4 | |
|---|---|
| Error | 6.2 |
| Cost | 1092 |
| Alternative 5 | |
|---|---|
| Error | 6.2 |
| Cost | 1092 |
| Alternative 6 | |
|---|---|
| Error | 23.5 |
| Cost | 978 |
| Alternative 7 | |
|---|---|
| Error | 23.6 |
| Cost | 976 |
| Alternative 8 | |
|---|---|
| Error | 23.4 |
| Cost | 976 |
| Alternative 9 | |
|---|---|
| Error | 24.5 |
| Cost | 976 |
| Alternative 10 | |
|---|---|
| Error | 24.6 |
| Cost | 976 |
| Alternative 11 | |
|---|---|
| Error | 24.5 |
| Cost | 976 |
| Alternative 12 | |
|---|---|
| Error | 32.7 |
| Cost | 580 |
| Alternative 13 | |
|---|---|
| Error | 32.7 |
| Cost | 580 |
| Alternative 14 | |
|---|---|
| Error | 32.5 |
| Cost | 580 |
| Alternative 15 | |
|---|---|
| Error | 32.5 |
| Cost | 448 |
herbie shell --seed 2023060
(FPCore (x y z t a)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, I"
:precision binary64
:herbie-target
(if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))
(/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))