| Alternative 1 | |
|---|---|
| Error | 16.6 |
| Cost | 39944 |
(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 (* (pow (cos y) 2.0) (* x 4.0))) (t_2 (/ a (* b 3.0))))
(if (<= (* z t) -1e+21)
(- (sqrt (expm1 (log1p t_1))) t_2)
(if (<= (* z t) 5e+256)
(-
(*
(* 2.0 (sqrt x))
(-
(* (cos y) (cos (* t (/ z 3.0))))
(* (sin (* t (* z -0.3333333333333333))) (sin y))))
t_2)
(-
(*
(pow (cbrt (cbrt t_1)) 3.0)
(pow (cbrt (cbrt (* (cos y) (sqrt (* x 4.0))))) 3.0))
t_2)))))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 = pow(cos(y), 2.0) * (x * 4.0);
double t_2 = a / (b * 3.0);
double tmp;
if ((z * t) <= -1e+21) {
tmp = sqrt(expm1(log1p(t_1))) - t_2;
} else if ((z * t) <= 5e+256) {
tmp = ((2.0 * sqrt(x)) * ((cos(y) * cos((t * (z / 3.0)))) - (sin((t * (z * -0.3333333333333333))) * sin(y)))) - t_2;
} else {
tmp = (pow(cbrt(cbrt(t_1)), 3.0) * pow(cbrt(cbrt((cos(y) * sqrt((x * 4.0))))), 3.0)) - t_2;
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
return ((2.0 * Math.sqrt(x)) * Math.cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = Math.pow(Math.cos(y), 2.0) * (x * 4.0);
double t_2 = a / (b * 3.0);
double tmp;
if ((z * t) <= -1e+21) {
tmp = Math.sqrt(Math.expm1(Math.log1p(t_1))) - t_2;
} else if ((z * t) <= 5e+256) {
tmp = ((2.0 * Math.sqrt(x)) * ((Math.cos(y) * Math.cos((t * (z / 3.0)))) - (Math.sin((t * (z * -0.3333333333333333))) * Math.sin(y)))) - t_2;
} else {
tmp = (Math.pow(Math.cbrt(Math.cbrt(t_1)), 3.0) * Math.pow(Math.cbrt(Math.cbrt((Math.cos(y) * Math.sqrt((x * 4.0))))), 3.0)) - t_2;
}
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 = Float64((cos(y) ^ 2.0) * Float64(x * 4.0)) t_2 = Float64(a / Float64(b * 3.0)) tmp = 0.0 if (Float64(z * t) <= -1e+21) tmp = Float64(sqrt(expm1(log1p(t_1))) - t_2); elseif (Float64(z * t) <= 5e+256) tmp = Float64(Float64(Float64(2.0 * sqrt(x)) * Float64(Float64(cos(y) * cos(Float64(t * Float64(z / 3.0)))) - Float64(sin(Float64(t * Float64(z * -0.3333333333333333))) * sin(y)))) - t_2); else tmp = Float64(Float64((cbrt(cbrt(t_1)) ^ 3.0) * (cbrt(cbrt(Float64(cos(y) * sqrt(Float64(x * 4.0))))) ^ 3.0)) - t_2); 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[(N[Power[N[Cos[y], $MachinePrecision], 2.0], $MachinePrecision] * N[(x * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -1e+21], N[(N[Sqrt[N[(Exp[N[Log[1 + t$95$1], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision] - t$95$2), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+256], N[(N[(N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[N[(t * N[(z / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(t * N[(z * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[(N[Power[N[Power[N[Power[t$95$1, 1/3], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[N[Power[N[Power[N[(N[Cos[y], $MachinePrecision] * N[Sqrt[N[(x * 4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - t$95$2), $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 := {\cos y}^{2} \cdot \left(x \cdot 4\right)\\
t_2 := \frac{a}{b \cdot 3}\\
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+21}:\\
\;\;\;\;\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(t_1\right)\right)} - t_2\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+256}:\\
\;\;\;\;\left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(t \cdot \frac{z}{3}\right) - \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right) \cdot \sin y\right) - t_2\\
\mathbf{else}:\\
\;\;\;\;{\left(\sqrt[3]{\sqrt[3]{t_1}}\right)}^{3} \cdot {\left(\sqrt[3]{\sqrt[3]{\cos y \cdot \sqrt{x \cdot 4}}}\right)}^{3} - t_2\\
\end{array}
Results
| Original | 20.6 |
|---|---|
| Target | 19.0 |
| Herbie | 16.6 |
if (*.f64 z t) < -1e21Initial program 40.4
Taylor expanded in z around 0 32.6
Applied egg-rr32.7
Applied egg-rr32.7
if -1e21 < (*.f64 z t) < 5.00000000000000015e256Initial program 9.2
Simplified9.2
[Start]9.2 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3}
\] |
|---|---|
associate-*l* [=>]9.2 | \[ \color{blue}{2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)} - \frac{a}{b \cdot 3}
\] |
associate-*l* [<=]9.2 | \[ \color{blue}{\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right)} - \frac{a}{b \cdot 3}
\] |
remove-double-neg [<=]9.2 | \[ \color{blue}{\left(-\left(-\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)\right)} - \frac{a}{b \cdot 3}
\] |
neg-mul-1 [=>]9.2 | \[ \color{blue}{-1 \cdot \left(-\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)} - \frac{a}{b \cdot 3}
\] |
neg-mul-1 [<=]9.2 | \[ \color{blue}{\left(-\left(-\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)\right)} - \frac{a}{b \cdot 3}
\] |
remove-double-neg [=>]9.2 | \[ \color{blue}{\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right)} - \frac{a}{b \cdot 3}
\] |
associate-*l/ [<=]9.2 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \color{blue}{\frac{z}{3} \cdot t}\right) - \frac{a}{b \cdot 3}
\] |
*-commutative [=>]9.2 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z}{3} \cdot t\right) - \frac{a}{\color{blue}{3 \cdot b}}
\] |
Applied egg-rr8.6
Simplified8.5
[Start]8.6 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
|---|---|
associate-*r* [=>]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \color{blue}{\left(\left(t \cdot z\right) \cdot -0.3333333333333333\right)} - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(\color{blue}{\left(z \cdot t\right)} \cdot -0.3333333333333333\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \color{blue}{\left(-0.3333333333333333 \cdot \left(z \cdot t\right)\right)} - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
metadata-eval [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(\color{blue}{\left(-0.3333333333333333\right)} \cdot \left(z \cdot t\right)\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
distribute-lft-neg-in [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \color{blue}{\left(-0.3333333333333333 \cdot \left(z \cdot t\right)\right)} - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [=>]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(-0.3333333333333333 \cdot \color{blue}{\left(t \cdot z\right)}\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
cos-neg [=>]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \color{blue}{\cos \left(0.3333333333333333 \cdot \left(t \cdot z\right)\right)} - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
metadata-eval [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(\color{blue}{\frac{1}{3}} \cdot \left(t \cdot z\right)\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(\frac{1}{3} \cdot \color{blue}{\left(z \cdot t\right)}\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
associate-/r/ [<=]8.6 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \color{blue}{\left(\frac{1}{\frac{3}{z \cdot t}}\right)} - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
associate-/l* [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \color{blue}{\left(\frac{1 \cdot \left(z \cdot t\right)}{3}\right)} - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(\frac{\color{blue}{\left(z \cdot t\right) \cdot 1}}{3}\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-rgt-identity [=>]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(\frac{\color{blue}{z \cdot t}}{3}\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [=>]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(\frac{\color{blue}{t \cdot z}}{3}\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
associate-*r/ [<=]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \color{blue}{\left(t \cdot \frac{z}{3}\right)} - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - \frac{a}{3 \cdot b}
\] |
*-commutative [=>]8.5 | \[ \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos y \cdot \cos \left(t \cdot \frac{z}{3}\right) - \color{blue}{\sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right) \cdot \sin y}\right) - \frac{a}{3 \cdot b}
\] |
if 5.00000000000000015e256 < (*.f64 z t) Initial program 56.9
Taylor expanded in z around 0 36.9
Applied egg-rr36.7
Applied egg-rr36.9
Final simplification16.6
| Alternative 1 | |
|---|---|
| Error | 16.6 |
| Cost | 39944 |
| Alternative 2 | |
|---|---|
| Error | 16.6 |
| Cost | 34120 |
| Alternative 3 | |
|---|---|
| Error | 16.6 |
| Cost | 34120 |
| Alternative 4 | |
|---|---|
| Error | 17.0 |
| Cost | 33028 |
| Alternative 5 | |
|---|---|
| Error | 17.0 |
| Cost | 26884 |
| Alternative 6 | |
|---|---|
| Error | 17.1 |
| Cost | 14536 |
| Alternative 7 | |
|---|---|
| Error | 17.1 |
| Cost | 14408 |
| Alternative 8 | |
|---|---|
| Error | 21.2 |
| Cost | 13897 |
| Alternative 9 | |
|---|---|
| Error | 17.5 |
| Cost | 13504 |
| Alternative 10 | |
|---|---|
| Error | 17.5 |
| Cost | 13504 |
| Alternative 11 | |
|---|---|
| Error | 17.4 |
| Cost | 13504 |
| Alternative 12 | |
|---|---|
| Error | 25.4 |
| Cost | 6976 |
| Alternative 13 | |
|---|---|
| Error | 36.2 |
| Cost | 320 |
| Alternative 14 | |
|---|---|
| Error | 36.2 |
| Cost | 320 |
| Alternative 15 | |
|---|---|
| Error | 36.2 |
| Cost | 320 |
| Alternative 16 | |
|---|---|
| Error | 36.2 |
| Cost | 320 |
herbie shell --seed 2022356
(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))))