
(FPCore (x y z t a b) :precision binary64 (- (* (* 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) {
return ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((2.0d0 * sqrt(x)) * cos((y - ((z * t) / 3.0d0)))) - (a / (b * 3.0d0))
end function
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));
}
def code(x, y, z, t, a, b): return ((2.0 * math.sqrt(x)) * math.cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0))
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 tmp = code(x, y, z, t, a, b) tmp = ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0)); 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]
\begin{array}{l}
\\
\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (- (* (* 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) {
return ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((2.0d0 * sqrt(x)) * cos((y - ((z * t) / 3.0d0)))) - (a / (b * 3.0d0))
end function
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));
}
def code(x, y, z, t, a, b): return ((2.0 * math.sqrt(x)) * math.cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0))
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 tmp = code(x, y, z, t, a, b) tmp = ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0)); 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]
\begin{array}{l}
\\
\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3}
\end{array}
(FPCore (x y z t a b) :precision binary64 (fma (* (cos y) 2.0) (sqrt x) (/ a (* b -3.0))))
double code(double x, double y, double z, double t, double a, double b) {
return fma((cos(y) * 2.0), sqrt(x), (a / (b * -3.0)));
}
function code(x, y, z, t, a, b) return fma(Float64(cos(y) * 2.0), sqrt(x), Float64(a / Float64(b * -3.0))) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[Cos[y], $MachinePrecision] * 2.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision] + N[(a / N[(b * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y \cdot 2, \sqrt{x}, \frac{a}{b \cdot -3}\right)
\end{array}
Initial program 71.4%
Taylor expanded in z around 0
lower-cos.f6478.3
Applied rewrites78.3%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-/.f64N/A
distribute-neg-frac2N/A
lower-/.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6478.3
Applied rewrites78.3%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (/ a (* 3.0 b))))
(if (<= t_1 -2e-99)
(fma (sqrt x) 2.0 (/ (* a -0.3333333333333333) b))
(if (<= t_1 500000.0)
(* 2.0 (* (sqrt x) (cos (fma (* z t) -0.3333333333333333 y))))
(fma (* 2.0 1.0) (sqrt x) (/ a (* b -3.0)))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = a / (3.0 * b);
double tmp;
if (t_1 <= -2e-99) {
tmp = fma(sqrt(x), 2.0, ((a * -0.3333333333333333) / b));
} else if (t_1 <= 500000.0) {
tmp = 2.0 * (sqrt(x) * cos(fma((z * t), -0.3333333333333333, y)));
} else {
tmp = fma((2.0 * 1.0), sqrt(x), (a / (b * -3.0)));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(a / Float64(3.0 * b)) tmp = 0.0 if (t_1 <= -2e-99) tmp = fma(sqrt(x), 2.0, Float64(Float64(a * -0.3333333333333333) / b)); elseif (t_1 <= 500000.0) tmp = Float64(2.0 * Float64(sqrt(x) * cos(fma(Float64(z * t), -0.3333333333333333, y)))); else tmp = fma(Float64(2.0 * 1.0), sqrt(x), Float64(a / Float64(b * -3.0))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a / N[(3.0 * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-99], N[(N[Sqrt[x], $MachinePrecision] * 2.0 + N[(N[(a * -0.3333333333333333), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 500000.0], N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[Cos[N[(N[(z * t), $MachinePrecision] * -0.3333333333333333 + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision] + N[(a / N[(b * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{a}{3 \cdot b}\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-99}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, 2, \frac{a \cdot -0.3333333333333333}{b}\right)\\
\mathbf{elif}\;t\_1 \leq 500000:\\
\;\;\;\;2 \cdot \left(\sqrt{x} \cdot \cos \left(\mathsf{fma}\left(z \cdot t, -0.3333333333333333, y\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2 \cdot 1, \sqrt{x}, \frac{a}{b \cdot -3}\right)\\
\end{array}
\end{array}
if (/.f64 a (*.f64 b #s(literal 3 binary64))) < -2e-99Initial program 79.6%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
+-commutativeN/A
sin-multN/A
div-invN/A
metadata-evalN/A
lower-fma.f64N/A
Applied rewrites79.6%
Taylor expanded in z around 0
associate--l+N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-cos.f64N/A
cancel-sign-sub-invN/A
associate-*r*N/A
metadata-evalN/A
lower-fma.f64N/A
Applied rewrites72.7%
Taylor expanded in a around inf
Applied rewrites72.4%
Taylor expanded in y around 0
Applied rewrites82.4%
if -2e-99 < (/.f64 a (*.f64 b #s(literal 3 binary64))) < 5e5Initial program 58.4%
Taylor expanded in z around 0
lower-cos.f6459.7
Applied rewrites59.7%
Taylor expanded in x around inf
cancel-sign-sub-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-cos.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
if 5e5 < (/.f64 a (*.f64 b #s(literal 3 binary64))) Initial program 83.2%
Taylor expanded in z around 0
lower-cos.f6494.7
Applied rewrites94.7%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-/.f64N/A
distribute-neg-frac2N/A
lower-/.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6494.7
Applied rewrites94.7%
Taylor expanded in y around 0
Applied rewrites92.2%
Final simplification71.5%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (/ (/ 0.3333333333333333 z) t))
(t_2 (/ (/ a 3.0) b))
(t_3 (* 2.0 (sqrt x))))
(if (< z -1.3793337487235141e+129)
(- (* t_3 (cos (- (/ 1.0 y) t_1))) t_2)
(if (< z 3.516290613555987e+106)
(- (* (* (sqrt x) 2.0) (cos (- y (* (/ t 3.0) z)))) t_2)
(- (* (cos (- y t_1)) t_3) (/ (/ a b) 3.0))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (0.3333333333333333 / z) / t;
double t_2 = (a / 3.0) / b;
double t_3 = 2.0 * sqrt(x);
double tmp;
if (z < -1.3793337487235141e+129) {
tmp = (t_3 * cos(((1.0 / y) - t_1))) - t_2;
} else if (z < 3.516290613555987e+106) {
tmp = ((sqrt(x) * 2.0) * cos((y - ((t / 3.0) * z)))) - t_2;
} else {
tmp = (cos((y - t_1)) * t_3) - ((a / b) / 3.0);
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = (0.3333333333333333d0 / z) / t
t_2 = (a / 3.0d0) / b
t_3 = 2.0d0 * sqrt(x)
if (z < (-1.3793337487235141d+129)) then
tmp = (t_3 * cos(((1.0d0 / y) - t_1))) - t_2
else if (z < 3.516290613555987d+106) then
tmp = ((sqrt(x) * 2.0d0) * cos((y - ((t / 3.0d0) * z)))) - t_2
else
tmp = (cos((y - t_1)) * t_3) - ((a / b) / 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (0.3333333333333333 / z) / t;
double t_2 = (a / 3.0) / b;
double t_3 = 2.0 * Math.sqrt(x);
double tmp;
if (z < -1.3793337487235141e+129) {
tmp = (t_3 * Math.cos(((1.0 / y) - t_1))) - t_2;
} else if (z < 3.516290613555987e+106) {
tmp = ((Math.sqrt(x) * 2.0) * Math.cos((y - ((t / 3.0) * z)))) - t_2;
} else {
tmp = (Math.cos((y - t_1)) * t_3) - ((a / b) / 3.0);
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (0.3333333333333333 / z) / t t_2 = (a / 3.0) / b t_3 = 2.0 * math.sqrt(x) tmp = 0 if z < -1.3793337487235141e+129: tmp = (t_3 * math.cos(((1.0 / y) - t_1))) - t_2 elif z < 3.516290613555987e+106: tmp = ((math.sqrt(x) * 2.0) * math.cos((y - ((t / 3.0) * z)))) - t_2 else: tmp = (math.cos((y - t_1)) * t_3) - ((a / b) / 3.0) return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(0.3333333333333333 / z) / t) t_2 = Float64(Float64(a / 3.0) / b) t_3 = Float64(2.0 * sqrt(x)) tmp = 0.0 if (z < -1.3793337487235141e+129) tmp = Float64(Float64(t_3 * cos(Float64(Float64(1.0 / y) - t_1))) - t_2); elseif (z < 3.516290613555987e+106) tmp = Float64(Float64(Float64(sqrt(x) * 2.0) * cos(Float64(y - Float64(Float64(t / 3.0) * z)))) - t_2); else tmp = Float64(Float64(cos(Float64(y - t_1)) * t_3) - Float64(Float64(a / b) / 3.0)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (0.3333333333333333 / z) / t; t_2 = (a / 3.0) / b; t_3 = 2.0 * sqrt(x); tmp = 0.0; if (z < -1.3793337487235141e+129) tmp = (t_3 * cos(((1.0 / y) - t_1))) - t_2; elseif (z < 3.516290613555987e+106) tmp = ((sqrt(x) * 2.0) * cos((y - ((t / 3.0) * z)))) - t_2; else tmp = (cos((y - t_1)) * t_3) - ((a / b) / 3.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(0.3333333333333333 / z), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a / 3.0), $MachinePrecision] / b), $MachinePrecision]}, Block[{t$95$3 = N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[Less[z, -1.3793337487235141e+129], N[(N[(t$95$3 * N[Cos[N[(N[(1.0 / y), $MachinePrecision] - t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], If[Less[z, 3.516290613555987e+106], N[(N[(N[(N[Sqrt[x], $MachinePrecision] * 2.0), $MachinePrecision] * N[Cos[N[(y - N[(N[(t / 3.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[(N[Cos[N[(y - t$95$1), $MachinePrecision]], $MachinePrecision] * t$95$3), $MachinePrecision] - N[(N[(a / b), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\frac{0.3333333333333333}{z}}{t}\\
t_2 := \frac{\frac{a}{3}}{b}\\
t_3 := 2 \cdot \sqrt{x}\\
\mathbf{if}\;z < -1.3793337487235141 \cdot 10^{+129}:\\
\;\;\;\;t\_3 \cdot \cos \left(\frac{1}{y} - t\_1\right) - t\_2\\
\mathbf{elif}\;z < 3.516290613555987 \cdot 10^{+106}:\\
\;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \cos \left(y - \frac{t}{3} \cdot z\right) - t\_2\\
\mathbf{else}:\\
\;\;\;\;\cos \left(y - t\_1\right) \cdot t\_3 - \frac{\frac{a}{b}}{3}\\
\end{array}
\end{array}
herbie shell --seed 2024223
(FPCore (x y z t a b)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, K"
:precision binary64
:alt
(! :herbie-platform default (if (< z -1379333748723514100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* (* 2 (sqrt x)) (cos (- (/ 1 y) (/ (/ 3333333333333333/10000000000000000 z) t)))) (/ (/ a 3) b)) (if (< z 35162906135559870000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* (* (sqrt x) 2) (cos (- y (* (/ t 3) z)))) (/ (/ a 3) b)) (- (* (cos (- y (/ (/ 3333333333333333/10000000000000000 z) t))) (* 2 (sqrt x))) (/ (/ a b) 3)))))
(- (* (* 2.0 (sqrt x)) (cos (- y (/ (* z t) 3.0)))) (/ a (* b 3.0))))