| Alternative 1 | |
|---|---|
| Accuracy | 92.6% |
| Cost | 1220 |

(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 (if (<= (* (* z 9.0) t) (- INFINITY)) (* z (/ (* t -4.5) a)) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0))))
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 tmp;
if (((z * 9.0) * t) <= -((double) INFINITY)) {
tmp = z * ((t * -4.5) / a);
} else {
tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0);
}
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 tmp;
if (((z * 9.0) * t) <= -Double.POSITIVE_INFINITY) {
tmp = z * ((t * -4.5) / a);
} else {
tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0);
}
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): tmp = 0 if ((z * 9.0) * t) <= -math.inf: tmp = z * ((t * -4.5) / a) else: tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0) 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) tmp = 0.0 if (Float64(Float64(z * 9.0) * t) <= Float64(-Inf)) tmp = Float64(z * Float64(Float64(t * -4.5) / a)); else tmp = Float64(Float64(Float64(x * y) - Float64(z * Float64(9.0 * t))) / Float64(a * 2.0)); 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) tmp = 0.0; if (((z * 9.0) * t) <= -Inf) tmp = z * ((t * -4.5) / a); else tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0); 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_] := If[LessEqual[N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision], (-Infinity)], N[(z * N[(N[(t * -4.5), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * y), $MachinePrecision] - N[(z * N[(9.0 * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
\mathbf{if}\;\left(z \cdot 9\right) \cdot t \leq -\infty:\\
\;\;\;\;z \cdot \frac{t \cdot -4.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}\\
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 90.7% |
|---|---|
| Target | 92.7% |
| Herbie | 92.6% |
if (*.f64 (*.f64 z 9) t) < -inf.0Initial program 60.8%
Simplified67.1%
[Start]60.8% | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]60.8% | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [=>]60.8% | \[ \frac{\color{blue}{\left(-\left(z \cdot 9\right) \cdot t\right) + x \cdot y}}{a \cdot 2}
\] |
neg-sub0 [=>]60.8% | \[ \frac{\color{blue}{\left(0 - \left(z \cdot 9\right) \cdot t\right)} + x \cdot y}{a \cdot 2}
\] |
associate-+l- [=>]60.8% | \[ \frac{\color{blue}{0 - \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
sub0-neg [=>]60.8% | \[ \frac{\color{blue}{-\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]60.8% | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]60.8% | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]60.8% | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
*-commutative [=>]60.8% | \[ \color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right) \cdot \frac{-1}{a \cdot 2}}
\] |
sub-neg [=>]60.8% | \[ \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)} \cdot \frac{-1}{a \cdot 2}
\] |
+-commutative [=>]60.8% | \[ \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)} \cdot \frac{-1}{a \cdot 2}
\] |
neg-sub0 [=>]60.8% | \[ \left(\color{blue}{\left(0 - x \cdot y\right)} + \left(z \cdot 9\right) \cdot t\right) \cdot \frac{-1}{a \cdot 2}
\] |
associate-+l- [=>]60.8% | \[ \color{blue}{\left(0 - \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)} \cdot \frac{-1}{a \cdot 2}
\] |
sub0-neg [=>]60.8% | \[ \color{blue}{\left(-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)} \cdot \frac{-1}{a \cdot 2}
\] |
distribute-lft-neg-out [=>]60.8% | \[ \color{blue}{-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right) \cdot \frac{-1}{a \cdot 2}}
\] |
distribute-rgt-neg-in [=>]60.8% | \[ \color{blue}{\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right) \cdot \left(-\frac{-1}{a \cdot 2}\right)}
\] |
Applied egg-rr67.1%
[Start]67.1% | \[ \mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right) \cdot \frac{0.5}{a}
\] |
|---|---|
associate-*r/ [=>]67.1% | \[ \color{blue}{\frac{\mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right) \cdot 0.5}{a}}
\] |
clear-num [=>]67.1% | \[ \color{blue}{\frac{1}{\frac{a}{\mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right) \cdot 0.5}}}
\] |
*-commutative [=>]67.1% | \[ \frac{1}{\frac{a}{\color{blue}{0.5 \cdot \mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right)}}}
\] |
Taylor expanded in x around 0 67.1%
Simplified99.9%
[Start]67.1% | \[ -4.5 \cdot \frac{t \cdot z}{a}
\] |
|---|---|
*-commutative [=>]67.1% | \[ \color{blue}{\frac{t \cdot z}{a} \cdot -4.5}
\] |
*-commutative [=>]67.1% | \[ \frac{\color{blue}{z \cdot t}}{a} \cdot -4.5
\] |
associate-*r/ [<=]99.8% | \[ \color{blue}{\left(z \cdot \frac{t}{a}\right)} \cdot -4.5
\] |
associate-*l* [=>]99.8% | \[ \color{blue}{z \cdot \left(\frac{t}{a} \cdot -4.5\right)}
\] |
associate-*l/ [=>]99.9% | \[ z \cdot \color{blue}{\frac{t \cdot -4.5}{a}}
\] |
if -inf.0 < (*.f64 (*.f64 z 9) t) Initial program 94.6%
Simplified94.6%
[Start]94.6% | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
associate-*l* [=>]94.6% | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Final simplification95.0%
| Alternative 1 | |
|---|---|
| Accuracy | 92.6% |
| Cost | 1220 |
| Alternative 2 | |
|---|---|
| Accuracy | 65.4% |
| Cost | 977 |
| Alternative 3 | |
|---|---|
| Accuracy | 65.9% |
| Cost | 977 |
| Alternative 4 | |
|---|---|
| Accuracy | 52.2% |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Accuracy | 52.3% |
| Cost | 448 |
| Alternative 6 | |
|---|---|
| Accuracy | 52.2% |
| Cost | 448 |
herbie shell --seed 2023171
(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)))