| Alternative 1 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 13897 |
(FPCore (x y z t a b) :precision binary64 (- (* (* 2.0 (sqrt x)) (cos (- y (/ (* z t) 3.0)))) (/ a (* b 3.0))))
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma t (* z -0.3333333333333333) y))
(t_2 (- y (/ (* z t) 3.0)))
(t_3 (fma (* z -0.3333333333333333) t (* (* z t) 0.3333333333333333)))
(t_4 (/ a (* 3.0 b))))
(if (or (<= t_2 (- INFINITY)) (not (<= t_2 5e+299)))
(- (exp (log (* 2.0 (sqrt x)))) t_4)
(-
(* 2.0 (* (sqrt x) (- (* (cos t_1) (cos t_3)) (* (sin t_1) (sin t_3)))))
t_4))))double code(double x, double y, double z, double t, double a, double b) {
return ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(t, (z * -0.3333333333333333), y);
double t_2 = y - ((z * t) / 3.0);
double t_3 = fma((z * -0.3333333333333333), t, ((z * t) * 0.3333333333333333));
double t_4 = a / (3.0 * b);
double tmp;
if ((t_2 <= -((double) INFINITY)) || !(t_2 <= 5e+299)) {
tmp = exp(log((2.0 * sqrt(x)))) - t_4;
} else {
tmp = (2.0 * (sqrt(x) * ((cos(t_1) * cos(t_3)) - (sin(t_1) * sin(t_3))))) - t_4;
}
return tmp;
}
function code(x, y, z, t, a, b) return Float64(Float64(Float64(2.0 * sqrt(x)) * cos(Float64(y - Float64(Float64(z * t) / 3.0)))) - Float64(a / Float64(b * 3.0))) end
function code(x, y, z, t, a, b) t_1 = fma(t, Float64(z * -0.3333333333333333), y) t_2 = Float64(y - Float64(Float64(z * t) / 3.0)) t_3 = fma(Float64(z * -0.3333333333333333), t, Float64(Float64(z * t) * 0.3333333333333333)) t_4 = Float64(a / Float64(3.0 * b)) tmp = 0.0 if ((t_2 <= Float64(-Inf)) || !(t_2 <= 5e+299)) tmp = Float64(exp(log(Float64(2.0 * sqrt(x)))) - t_4); else tmp = Float64(Float64(2.0 * Float64(sqrt(x) * Float64(Float64(cos(t_1) * cos(t_3)) - Float64(sin(t_1) * sin(t_3))))) - t_4); end return tmp end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(y - N[(N[(z * t), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(t * N[(z * -0.3333333333333333), $MachinePrecision] + y), $MachinePrecision]}, Block[{t$95$2 = N[(y - N[(N[(z * t), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(z * -0.3333333333333333), $MachinePrecision] * t + N[(N[(z * t), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(a / N[(3.0 * b), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$2, (-Infinity)], N[Not[LessEqual[t$95$2, 5e+299]], $MachinePrecision]], N[(N[Exp[N[Log[N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] - t$95$4), $MachinePrecision], N[(N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[(N[(N[Cos[t$95$1], $MachinePrecision] * N[Cos[t$95$3], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$1], $MachinePrecision] * N[Sin[t$95$3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$4), $MachinePrecision]]]]]]
\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3}
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\\
t_2 := y - \frac{z \cdot t}{3}\\
t_3 := \mathsf{fma}\left(z \cdot -0.3333333333333333, t, \left(z \cdot t\right) \cdot 0.3333333333333333\right)\\
t_4 := \frac{a}{3 \cdot b}\\
\mathbf{if}\;t_2 \leq -\infty \lor \neg \left(t_2 \leq 5 \cdot 10^{+299}\right):\\
\;\;\;\;e^{\log \left(2 \cdot \sqrt{x}\right)} - t_4\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sqrt{x} \cdot \left(\cos t_1 \cdot \cos t_3 - \sin t_1 \cdot \sin t_3\right)\right) - t_4\\
\end{array}
| Original | 68.0% |
|---|---|
| Target | 70.5% |
| Herbie | 74.8% |
if (-.f64 y (/.f64 (*.f64 z t) 3)) < -inf.0 or 5.0000000000000003e299 < (-.f64 y (/.f64 (*.f64 z t) 3)) Initial program 5.0%
Taylor expanded in z around 0 45.2%
Applied egg-rr34.4%
[Start]45.2 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{a}{b \cdot 3}
\] |
|---|---|
add-exp-log [=>]34.4 | \[ \color{blue}{e^{\log \left(\left(2 \cdot \sqrt{x}\right) \cdot \cos y\right)}} - \frac{a}{b \cdot 3}
\] |
associate-*l* [=>]34.4 | \[ e^{\log \color{blue}{\left(2 \cdot \left(\sqrt{x} \cdot \cos y\right)\right)}} - \frac{a}{b \cdot 3}
\] |
Taylor expanded in y around 0 43.7%
if -inf.0 < (-.f64 y (/.f64 (*.f64 z t) 3)) < 5.0000000000000003e299Initial program 77.2%
Simplified77.2%
[Start]77.2 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3}
\] |
|---|---|
associate-*l* [=>]77.2 | \[ \color{blue}{2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)} - \frac{a}{b \cdot 3}
\] |
fma-neg [=>]77.2 | \[ \color{blue}{\mathsf{fma}\left(2, \sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right), -\frac{a}{b \cdot 3}\right)}
\] |
remove-double-neg [<=]77.2 | \[ \mathsf{fma}\left(2, \color{blue}{-\left(-\sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)}, -\frac{a}{b \cdot 3}\right)
\] |
fma-neg [<=]77.2 | \[ \color{blue}{2 \cdot \left(-\left(-\sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)\right) - \frac{a}{b \cdot 3}}
\] |
remove-double-neg [=>]77.2 | \[ 2 \cdot \color{blue}{\left(\sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)} - \frac{a}{b \cdot 3}
\] |
associate-*l/ [<=]77.2 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \color{blue}{\frac{z}{3} \cdot t}\right)\right) - \frac{a}{b \cdot 3}
\] |
*-commutative [=>]77.2 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z}{3} \cdot t\right)\right) - \frac{a}{\color{blue}{3 \cdot b}}
\] |
Applied egg-rr79.4%
[Start]77.2 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z}{3} \cdot t\right)\right) - \frac{a}{3 \cdot b}
\] |
|---|---|
*-un-lft-identity [=>]77.2 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(\color{blue}{1 \cdot y} - \frac{z}{3} \cdot t\right)\right) - \frac{a}{3 \cdot b}
\] |
add-sqr-sqrt [=>]45.5 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(1 \cdot y - \color{blue}{\sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}}\right)\right) - \frac{a}{3 \cdot b}
\] |
prod-diff [=>]45.5 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \color{blue}{\left(\mathsf{fma}\left(1, y, -\sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}\right) + \mathsf{fma}\left(-\sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}\right)\right)}\right) - \frac{a}{3 \cdot b}
\] |
add-sqr-sqrt [<=]45.6 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(\mathsf{fma}\left(1, y, -\color{blue}{\frac{z}{3} \cdot t}\right) + \mathsf{fma}\left(-\sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
fma-neg [<=]45.6 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(\color{blue}{\left(1 \cdot y - \frac{z}{3} \cdot t\right)} + \mathsf{fma}\left(-\sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-un-lft-identity [<=]45.6 | \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(\left(\color{blue}{y} - \frac{z}{3} \cdot t\right) + \mathsf{fma}\left(-\sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
cos-sum [=>]45.6 | \[ 2 \cdot \left(\sqrt{x} \cdot \color{blue}{\left(\cos \left(y - \frac{z}{3} \cdot t\right) \cdot \cos \left(\mathsf{fma}\left(-\sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}\right)\right) - \sin \left(y - \frac{z}{3} \cdot t\right) \cdot \sin \left(\mathsf{fma}\left(-\sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t}, \sqrt{\frac{z}{3} \cdot t} \cdot \sqrt{\frac{z}{3} \cdot t}\right)\right)\right)}\right) - \frac{a}{3 \cdot b}
\] |
Simplified79.3%
[Start]79.4 | \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right) - \sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
|---|---|
fma-neg [=>]79.4 | \[ 2 \cdot \left(\sqrt{x} \cdot \color{blue}{\mathsf{fma}\left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right), \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right), -\sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right)}\right) - \frac{a}{3 \cdot b}
\] |
*-lft-identity [<=]79.4 | \[ 2 \cdot \left(\sqrt{x} \cdot \mathsf{fma}\left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right), \color{blue}{1 \cdot \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)}, -\sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
fma-neg [<=]79.4 | \[ 2 \cdot \left(\sqrt{x} \cdot \color{blue}{\left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \left(1 \cdot \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right) - \sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right)}\right) - \frac{a}{3 \cdot b}
\] |
*-lft-identity [=>]79.4 | \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \color{blue}{\cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)} - \sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [=>]79.4 | \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, \color{blue}{\left(0.3333333333333333 \cdot t\right) \cdot z}\right)\right) - \sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
associate-*r* [<=]78.7 | \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, \color{blue}{0.3333333333333333 \cdot \left(t \cdot z\right)}\right)\right) - \sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(0.3333333333333333 \cdot t\right)\right)\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [=>]78.7 | \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, 0.3333333333333333 \cdot \left(t \cdot z\right)\right)\right) - \sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, \color{blue}{\left(0.3333333333333333 \cdot t\right) \cdot z}\right)\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
associate-*r* [<=]79.3 | \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \cos \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, 0.3333333333333333 \cdot \left(t \cdot z\right)\right)\right) - \sin \left(\mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\right) \cdot \sin \left(\mathsf{fma}\left(z \cdot -0.3333333333333333, t, \color{blue}{0.3333333333333333 \cdot \left(t \cdot z\right)}\right)\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
Final simplification74.8%
| Alternative 1 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 13897 |
| Alternative 2 | |
|---|---|
| Accuracy | 72.6% |
| Cost | 13504 |
| Alternative 3 | |
|---|---|
| Accuracy | 72.7% |
| Cost | 13504 |
| Alternative 4 | |
|---|---|
| Accuracy | 59.8% |
| Cost | 6976 |
| Alternative 5 | |
|---|---|
| Accuracy | 59.9% |
| Cost | 6976 |
| Alternative 6 | |
|---|---|
| Accuracy | 43.0% |
| Cost | 6720 |
| Alternative 7 | |
|---|---|
| Accuracy | 43.0% |
| Cost | 320 |
| Alternative 8 | |
|---|---|
| Accuracy | 43.0% |
| Cost | 320 |
herbie shell --seed 2023146
(FPCore (x y z t a b)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, K"
:precision binary64
:herbie-target
(if (< z -1.3793337487235141e+129) (- (* (* 2.0 (sqrt x)) (cos (- (/ 1.0 y) (/ (/ 0.3333333333333333 z) t)))) (/ (/ a 3.0) b)) (if (< z 3.516290613555987e+106) (- (* (* (sqrt x) 2.0) (cos (- y (* (/ t 3.0) z)))) (/ (/ a 3.0) b)) (- (* (cos (- y (/ (/ 0.3333333333333333 z) t))) (* 2.0 (sqrt x))) (/ (/ a b) 3.0))))
(- (* (* 2.0 (sqrt x)) (cos (- y (/ (* z t) 3.0)))) (/ a (* b 3.0))))