| Alternative 1 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 8649 |

(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
NOTE: z and t should be sorted in increasing order before calling this function.
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (* x y) (* (* z 9.0) t))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 5e+273)))
(fma (/ x a) (/ y 2.0) (* 0.5 (/ t (/ a (* z -9.0)))))
(/ (fma x y (* z (* t -9.0))) (* 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);
}
assert(z < t);
double code(double x, double y, double z, double t, double a) {
double t_1 = (x * y) - ((z * 9.0) * t);
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 5e+273)) {
tmp = fma((x / a), (y / 2.0), (0.5 * (t / (a / (z * -9.0)))));
} else {
tmp = fma(x, y, (z * (t * -9.0))) / (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
z, t = sort([z, t]) function code(x, y, z, t, a) t_1 = Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 5e+273)) tmp = fma(Float64(x / a), Float64(y / 2.0), Float64(0.5 * Float64(t / Float64(a / Float64(z * -9.0))))); else tmp = Float64(fma(x, y, Float64(z * Float64(t * -9.0))) / Float64(a * 2.0)); end return 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]
NOTE: z and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 5e+273]], $MachinePrecision]], N[(N[(x / a), $MachinePrecision] * N[(y / 2.0), $MachinePrecision] + N[(0.5 * N[(t / N[(a / N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y + N[(z * N[(t * -9.0), $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}
[z, t] = \mathsf{sort}([z, t])\\
\\
\begin{array}{l}
t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 5 \cdot 10^{+273}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{a}, \frac{y}{2}, 0.5 \cdot \frac{t}{\frac{a}{z \cdot -9}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right)}{a \cdot 2}\\
\end{array}
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 90.9% |
|---|---|
| Target | 93.3% |
| Herbie | 97.2% |
if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -inf.0 or 4.99999999999999961e273 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) Initial program 58.9%
Simplified60.5%
[Start]58.9% | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]58.9% | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [=>]58.9% | \[ \frac{\color{blue}{\left(-\left(z \cdot 9\right) \cdot t\right) + x \cdot y}}{a \cdot 2}
\] |
neg-sub0 [=>]58.9% | \[ \frac{\color{blue}{\left(0 - \left(z \cdot 9\right) \cdot t\right)} + x \cdot y}{a \cdot 2}
\] |
associate-+l- [=>]58.9% | \[ \frac{\color{blue}{0 - \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
sub0-neg [=>]58.9% | \[ \frac{\color{blue}{-\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]58.9% | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]58.9% | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]58.9% | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
*-commutative [=>]58.9% | \[ \color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right) \cdot \frac{-1}{a \cdot 2}}
\] |
sub-neg [=>]58.9% | \[ \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)} \cdot \frac{-1}{a \cdot 2}
\] |
+-commutative [=>]58.9% | \[ \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)} \cdot \frac{-1}{a \cdot 2}
\] |
neg-sub0 [=>]58.9% | \[ \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- [=>]58.9% | \[ \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 [=>]58.9% | \[ \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 [=>]58.9% | \[ \color{blue}{-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right) \cdot \frac{-1}{a \cdot 2}}
\] |
distribute-rgt-neg-in [=>]58.9% | \[ \color{blue}{\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right) \cdot \left(-\frac{-1}{a \cdot 2}\right)}
\] |
Applied egg-rr74.8%
[Start]60.5% | \[ \mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right) \cdot \frac{0.5}{a}
\] |
|---|---|
*-commutative [=>]60.5% | \[ \color{blue}{\frac{0.5}{a} \cdot \mathsf{fma}\left(x, y, z \cdot \left(t \cdot -9\right)\right)}
\] |
fma-udef [=>]58.9% | \[ \frac{0.5}{a} \cdot \color{blue}{\left(x \cdot y + z \cdot \left(t \cdot -9\right)\right)}
\] |
*-commutative [=>]58.9% | \[ \frac{0.5}{a} \cdot \left(x \cdot y + z \cdot \color{blue}{\left(-9 \cdot t\right)}\right)
\] |
metadata-eval [<=]58.9% | \[ \frac{0.5}{a} \cdot \left(x \cdot y + z \cdot \left(\color{blue}{\left(-9\right)} \cdot t\right)\right)
\] |
distribute-lft-neg-in [<=]58.9% | \[ \frac{0.5}{a} \cdot \left(x \cdot y + z \cdot \color{blue}{\left(-9 \cdot t\right)}\right)
\] |
distribute-rgt-neg-in [<=]58.9% | \[ \frac{0.5}{a} \cdot \left(x \cdot y + \color{blue}{\left(-z \cdot \left(9 \cdot t\right)\right)}\right)
\] |
distribute-rgt-in [=>]55.7% | \[ \color{blue}{\left(x \cdot y\right) \cdot \frac{0.5}{a} + \left(-z \cdot \left(9 \cdot t\right)\right) \cdot \frac{0.5}{a}}
\] |
clear-num [=>]55.7% | \[ \left(x \cdot y\right) \cdot \color{blue}{\frac{1}{\frac{a}{0.5}}} + \left(-z \cdot \left(9 \cdot t\right)\right) \cdot \frac{0.5}{a}
\] |
div-inv [=>]55.7% | \[ \left(x \cdot y\right) \cdot \frac{1}{\color{blue}{a \cdot \frac{1}{0.5}}} + \left(-z \cdot \left(9 \cdot t\right)\right) \cdot \frac{0.5}{a}
\] |
metadata-eval [=>]55.7% | \[ \left(x \cdot y\right) \cdot \frac{1}{a \cdot \color{blue}{2}} + \left(-z \cdot \left(9 \cdot t\right)\right) \cdot \frac{0.5}{a}
\] |
div-inv [<=]55.7% | \[ \color{blue}{\frac{x \cdot y}{a \cdot 2}} + \left(-z \cdot \left(9 \cdot t\right)\right) \cdot \frac{0.5}{a}
\] |
Simplified96.7%
[Start]74.8% | \[ \frac{x}{a} \cdot \frac{y}{2} + 0.5 \cdot \frac{t \cdot \left(z \cdot -9\right)}{a}
\] |
|---|---|
fma-def [=>]76.4% | \[ \color{blue}{\mathsf{fma}\left(\frac{x}{a}, \frac{y}{2}, 0.5 \cdot \frac{t \cdot \left(z \cdot -9\right)}{a}\right)}
\] |
associate-/l* [=>]96.7% | \[ \mathsf{fma}\left(\frac{x}{a}, \frac{y}{2}, 0.5 \cdot \color{blue}{\frac{t}{\frac{a}{z \cdot -9}}}\right)
\] |
if -inf.0 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 4.99999999999999961e273Initial program 99.6%
Simplified99.6%
[Start]99.6% | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
div-sub [=>]98.5% | \[ \color{blue}{\frac{x \cdot y}{a \cdot 2} - \frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}}
\] |
+-rgt-identity [<=]98.5% | \[ \frac{\color{blue}{x \cdot y + 0}}{a \cdot 2} - \frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
div-sub [<=]99.6% | \[ \color{blue}{\frac{\left(x \cdot y + 0\right) - \left(z \cdot 9\right) \cdot t}{a \cdot 2}}
\] |
+-rgt-identity [=>]99.6% | \[ \frac{\color{blue}{x \cdot y} - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
fma-neg [=>]99.6% | \[ \frac{\color{blue}{\mathsf{fma}\left(x, y, -\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
associate-*l* [=>]99.6% | \[ \frac{\mathsf{fma}\left(x, y, -\color{blue}{z \cdot \left(9 \cdot t\right)}\right)}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]99.6% | \[ \frac{\mathsf{fma}\left(x, y, \color{blue}{z \cdot \left(-9 \cdot t\right)}\right)}{a \cdot 2}
\] |
*-commutative [=>]99.6% | \[ \frac{\mathsf{fma}\left(x, y, z \cdot \left(-\color{blue}{t \cdot 9}\right)\right)}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]99.6% | \[ \frac{\mathsf{fma}\left(x, y, z \cdot \color{blue}{\left(t \cdot \left(-9\right)\right)}\right)}{a \cdot 2}
\] |
metadata-eval [=>]99.6% | \[ \frac{\mathsf{fma}\left(x, y, z \cdot \left(t \cdot \color{blue}{-9}\right)\right)}{a \cdot 2}
\] |
Final simplification98.9%
| Alternative 1 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 8649 |
| Alternative 2 | |
|---|---|
| Accuracy | 91.9% |
| Cost | 7364 |
| Alternative 3 | |
|---|---|
| Accuracy | 71.0% |
| Cost | 2008 |
| Alternative 4 | |
|---|---|
| Accuracy | 71.0% |
| Cost | 2008 |
| Alternative 5 | |
|---|---|
| Accuracy | 91.8% |
| Cost | 1732 |
| Alternative 6 | |
|---|---|
| Accuracy | 91.6% |
| Cost | 1092 |
| Alternative 7 | |
|---|---|
| Accuracy | 91.7% |
| Cost | 1092 |
| Alternative 8 | |
|---|---|
| Accuracy | 67.9% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 68.3% |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 448 |
| Alternative 11 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 448 |
herbie shell --seed 2023167
(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)))