
(FPCore (x y z t a b) :precision binary64 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
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 = ((x * 2.0d0) - (((y * 9.0d0) * z) * t)) + ((a * 27.0d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
def code(x, y, z, t, a, b): return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
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 = ((x * 2.0d0) - (((y * 9.0d0) * z) * t)) + ((a * 27.0d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
def code(x, y, z, t, a, b): return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\end{array}
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (* z (* 9.0 y))))
(if (<= t_1 4e+14)
(+ (* b (* 27.0 a)) (- (* 2.0 x) (* t t_1)))
(fma (fma (/ (* b 27.0) y) a (* (* -9.0 t) z)) y (* 2.0 x)))))assert(x < y && y < z && z < t && t < a && a < b);
assert(x < y && y < z && z < t && t < a && a < b);
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = z * (9.0 * y);
double tmp;
if (t_1 <= 4e+14) {
tmp = (b * (27.0 * a)) + ((2.0 * x) - (t * t_1));
} else {
tmp = fma(fma(((b * 27.0) / y), a, ((-9.0 * t) * z)), y, (2.0 * x));
}
return tmp;
}
x, y, z, t, a, b = sort([x, y, z, t, a, b]) x, y, z, t, a, b = sort([x, y, z, t, a, b]) function code(x, y, z, t, a, b) t_1 = Float64(z * Float64(9.0 * y)) tmp = 0.0 if (t_1 <= 4e+14) tmp = Float64(Float64(b * Float64(27.0 * a)) + Float64(Float64(2.0 * x) - Float64(t * t_1))); else tmp = fma(fma(Float64(Float64(b * 27.0) / y), a, Float64(Float64(-9.0 * t) * z)), y, Float64(2.0 * x)); end return tmp end
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(z * N[(9.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 4e+14], N[(N[(b * N[(27.0 * a), $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * x), $MachinePrecision] - N[(t * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(b * 27.0), $MachinePrecision] / y), $MachinePrecision] * a + N[(N[(-9.0 * t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision] * y + N[(2.0 * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\
\\
\begin{array}{l}
t_1 := z \cdot \left(9 \cdot y\right)\\
\mathbf{if}\;t\_1 \leq 4 \cdot 10^{+14}:\\
\;\;\;\;b \cdot \left(27 \cdot a\right) + \left(2 \cdot x - t \cdot t\_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{b \cdot 27}{y}, a, \left(-9 \cdot t\right) \cdot z\right), y, 2 \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 9 binary64)) z) < 4e14Initial program 98.9%
if 4e14 < (*.f64 (*.f64 y #s(literal 9 binary64)) z) Initial program 89.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6414.3
Applied rewrites14.3%
Taylor expanded in y around inf
associate--l+N/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r/N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-inversesN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r/N/A
lower-fma.f64N/A
Applied rewrites98.5%
Final simplification98.8%
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (* (* (* z y) t) -9.0)) (t_2 (* t (* z (* 9.0 y)))))
(if (<= t_2 -1e+90)
t_1
(if (<= t_2 -5e-21) (* b (* 27.0 a)) (if (<= t_2 1e-40) (* 2.0 x) t_1)))))assert(x < y && y < z && z < t && t < a && a < b);
assert(x < y && y < z && z < t && t < a && a < b);
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = ((z * y) * t) * -9.0;
double t_2 = t * (z * (9.0 * y));
double tmp;
if (t_2 <= -1e+90) {
tmp = t_1;
} else if (t_2 <= -5e-21) {
tmp = b * (27.0 * a);
} else if (t_2 <= 1e-40) {
tmp = 2.0 * x;
} else {
tmp = t_1;
}
return tmp;
}
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
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) :: tmp
t_1 = ((z * y) * t) * (-9.0d0)
t_2 = t * (z * (9.0d0 * y))
if (t_2 <= (-1d+90)) then
tmp = t_1
else if (t_2 <= (-5d-21)) then
tmp = b * (27.0d0 * a)
else if (t_2 <= 1d-40) then
tmp = 2.0d0 * x
else
tmp = t_1
end if
code = tmp
end function
assert x < y && y < z && z < t && t < a && a < b;
assert x < y && y < z && z < t && t < a && a < b;
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = ((z * y) * t) * -9.0;
double t_2 = t * (z * (9.0 * y));
double tmp;
if (t_2 <= -1e+90) {
tmp = t_1;
} else if (t_2 <= -5e-21) {
tmp = b * (27.0 * a);
} else if (t_2 <= 1e-40) {
tmp = 2.0 * x;
} else {
tmp = t_1;
}
return tmp;
}
[x, y, z, t, a, b] = sort([x, y, z, t, a, b]) [x, y, z, t, a, b] = sort([x, y, z, t, a, b]) def code(x, y, z, t, a, b): t_1 = ((z * y) * t) * -9.0 t_2 = t * (z * (9.0 * y)) tmp = 0 if t_2 <= -1e+90: tmp = t_1 elif t_2 <= -5e-21: tmp = b * (27.0 * a) elif t_2 <= 1e-40: tmp = 2.0 * x else: tmp = t_1 return tmp
x, y, z, t, a, b = sort([x, y, z, t, a, b]) x, y, z, t, a, b = sort([x, y, z, t, a, b]) function code(x, y, z, t, a, b) t_1 = Float64(Float64(Float64(z * y) * t) * -9.0) t_2 = Float64(t * Float64(z * Float64(9.0 * y))) tmp = 0.0 if (t_2 <= -1e+90) tmp = t_1; elseif (t_2 <= -5e-21) tmp = Float64(b * Float64(27.0 * a)); elseif (t_2 <= 1e-40) tmp = Float64(2.0 * x); else tmp = t_1; end return tmp end
x, y, z, t, a, b = num2cell(sort([x, y, z, t, a, b])){:}
x, y, z, t, a, b = num2cell(sort([x, y, z, t, a, b])){:}
function tmp_2 = code(x, y, z, t, a, b)
t_1 = ((z * y) * t) * -9.0;
t_2 = t * (z * (9.0 * y));
tmp = 0.0;
if (t_2 <= -1e+90)
tmp = t_1;
elseif (t_2 <= -5e-21)
tmp = b * (27.0 * a);
elseif (t_2 <= 1e-40)
tmp = 2.0 * x;
else
tmp = t_1;
end
tmp_2 = tmp;
end
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(N[(z * y), $MachinePrecision] * t), $MachinePrecision] * -9.0), $MachinePrecision]}, Block[{t$95$2 = N[(t * N[(z * N[(9.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+90], t$95$1, If[LessEqual[t$95$2, -5e-21], N[(b * N[(27.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e-40], N[(2.0 * x), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\
\\
\begin{array}{l}
t_1 := \left(\left(z \cdot y\right) \cdot t\right) \cdot -9\\
t_2 := t \cdot \left(z \cdot \left(9 \cdot y\right)\right)\\
\mathbf{if}\;t\_2 \leq -1 \cdot 10^{+90}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq -5 \cdot 10^{-21}:\\
\;\;\;\;b \cdot \left(27 \cdot a\right)\\
\mathbf{elif}\;t\_2 \leq 10^{-40}:\\
\;\;\;\;2 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 y #s(literal 9 binary64)) z) t) < -9.99999999999999966e89 or 9.9999999999999993e-41 < (*.f64 (*.f64 (*.f64 y #s(literal 9 binary64)) z) t) Initial program 91.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6414.3
Applied rewrites14.3%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6465.7
Applied rewrites65.7%
Applied rewrites65.8%
if -9.99999999999999966e89 < (*.f64 (*.f64 (*.f64 y #s(literal 9 binary64)) z) t) < -4.99999999999999973e-21Initial program 99.7%
Taylor expanded in a around inf
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6438.1
Applied rewrites38.1%
if -4.99999999999999973e-21 < (*.f64 (*.f64 (*.f64 y #s(literal 9 binary64)) z) t) < 9.9999999999999993e-41Initial program 99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6445.7
Applied rewrites45.7%
Final simplification54.6%
(FPCore (x y z t a b) :precision binary64 (if (< y 7.590524218811189e-161) (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* a (* 27.0 b))) (+ (- (* x 2.0) (* 9.0 (* y (* t z)))) (* (* a 27.0) b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (y < 7.590524218811189e-161) {
tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + (a * (27.0 * b));
} else {
tmp = ((x * 2.0) - (9.0 * (y * (t * z)))) + ((a * 27.0) * b);
}
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) :: tmp
if (y < 7.590524218811189d-161) then
tmp = ((x * 2.0d0) - (((y * 9.0d0) * z) * t)) + (a * (27.0d0 * b))
else
tmp = ((x * 2.0d0) - (9.0d0 * (y * (t * z)))) + ((a * 27.0d0) * b)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (y < 7.590524218811189e-161) {
tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + (a * (27.0 * b));
} else {
tmp = ((x * 2.0) - (9.0 * (y * (t * z)))) + ((a * 27.0) * b);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if y < 7.590524218811189e-161: tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + (a * (27.0 * b)) else: tmp = ((x * 2.0) - (9.0 * (y * (t * z)))) + ((a * 27.0) * b) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (y < 7.590524218811189e-161) tmp = Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(a * Float64(27.0 * b))); else tmp = Float64(Float64(Float64(x * 2.0) - Float64(9.0 * Float64(y * Float64(t * z)))) + Float64(Float64(a * 27.0) * b)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (y < 7.590524218811189e-161) tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + (a * (27.0 * b)); else tmp = ((x * 2.0) - (9.0 * (y * (t * z)))) + ((a * 27.0) * b); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Less[y, 7.590524218811189e-161], N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] - N[(9.0 * N[(y * N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y < 7.590524218811189 \cdot 10^{-161}:\\
\;\;\;\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + a \cdot \left(27 \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\
\end{array}
\end{array}
herbie shell --seed 2024230
(FPCore (x y z t a b)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, A"
:precision binary64
:alt
(! :herbie-platform default (if (< y 7590524218811189/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (+ (- (* x 2) (* (* (* y 9) z) t)) (* a (* 27 b))) (+ (- (* x 2) (* 9 (* y (* t z)))) (* (* a 27) b))))
(+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))