
(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 6 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}
(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}
Initial program 95.1%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (* (* (* y 9.0) z) t)) (t_2 (- (* x 2.0) t_1)))
(if (<= t_1 -1e+201)
t_2
(if (<= t_1 5e-42) (+ (* x 2.0) (* (* a 27.0) b)) t_2))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = ((y * 9.0) * z) * t;
double t_2 = (x * 2.0) - t_1;
double tmp;
if (t_1 <= -1e+201) {
tmp = t_2;
} else if (t_1 <= 5e-42) {
tmp = (x * 2.0) + ((a * 27.0) * b);
} else {
tmp = t_2;
}
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) :: tmp
t_1 = ((y * 9.0d0) * z) * t
t_2 = (x * 2.0d0) - t_1
if (t_1 <= (-1d+201)) then
tmp = t_2
else if (t_1 <= 5d-42) then
tmp = (x * 2.0d0) + ((a * 27.0d0) * b)
else
tmp = t_2
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 = ((y * 9.0) * z) * t;
double t_2 = (x * 2.0) - t_1;
double tmp;
if (t_1 <= -1e+201) {
tmp = t_2;
} else if (t_1 <= 5e-42) {
tmp = (x * 2.0) + ((a * 27.0) * b);
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = ((y * 9.0) * z) * t t_2 = (x * 2.0) - t_1 tmp = 0 if t_1 <= -1e+201: tmp = t_2 elif t_1 <= 5e-42: tmp = (x * 2.0) + ((a * 27.0) * b) else: tmp = t_2 return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(Float64(y * 9.0) * z) * t) t_2 = Float64(Float64(x * 2.0) - t_1) tmp = 0.0 if (t_1 <= -1e+201) tmp = t_2; elseif (t_1 <= 5e-42) tmp = Float64(Float64(x * 2.0) + Float64(Float64(a * 27.0) * b)); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = ((y * 9.0) * z) * t; t_2 = (x * 2.0) - t_1; tmp = 0.0; if (t_1 <= -1e+201) tmp = t_2; elseif (t_1 <= 5e-42) tmp = (x * 2.0) + ((a * 27.0) * b); else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * 2.0), $MachinePrecision] - t$95$1), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+201], t$95$2, If[LessEqual[t$95$1, 5e-42], N[(N[(x * 2.0), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\\
t_2 := x \cdot 2 - t\_1\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+201}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-42}:\\
\;\;\;\;x \cdot 2 + \left(a \cdot 27\right) \cdot b\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 y #s(literal 9 binary64)) z) t) < -1.00000000000000004e201 or 5.00000000000000003e-42 < (*.f64 (*.f64 (*.f64 y #s(literal 9 binary64)) z) t) Initial program 91.5%
Taylor expanded in x around 0
Applied rewrites82.5%
if -1.00000000000000004e201 < (*.f64 (*.f64 (*.f64 y #s(literal 9 binary64)) z) t) < 5.00000000000000003e-42Initial program 98.0%
Taylor expanded in x around 0
Applied rewrites88.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x 2.0) -2e+44) (* x 2.0) (if (<= (* x 2.0) 2.2e-22) (* (* a 27.0) b) (* x 2.0))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * 2.0) <= -2e+44) {
tmp = x * 2.0;
} else if ((x * 2.0) <= 2.2e-22) {
tmp = (a * 27.0) * b;
} else {
tmp = x * 2.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) :: tmp
if ((x * 2.0d0) <= (-2d+44)) then
tmp = x * 2.0d0
else if ((x * 2.0d0) <= 2.2d-22) then
tmp = (a * 27.0d0) * b
else
tmp = x * 2.0d0
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 ((x * 2.0) <= -2e+44) {
tmp = x * 2.0;
} else if ((x * 2.0) <= 2.2e-22) {
tmp = (a * 27.0) * b;
} else {
tmp = x * 2.0;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * 2.0) <= -2e+44: tmp = x * 2.0 elif (x * 2.0) <= 2.2e-22: tmp = (a * 27.0) * b else: tmp = x * 2.0 return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * 2.0) <= -2e+44) tmp = Float64(x * 2.0); elseif (Float64(x * 2.0) <= 2.2e-22) tmp = Float64(Float64(a * 27.0) * b); else tmp = Float64(x * 2.0); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * 2.0) <= -2e+44) tmp = x * 2.0; elseif ((x * 2.0) <= 2.2e-22) tmp = (a * 27.0) * b; else tmp = x * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * 2.0), $MachinePrecision], -2e+44], N[(x * 2.0), $MachinePrecision], If[LessEqual[N[(x * 2.0), $MachinePrecision], 2.2e-22], N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision], N[(x * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 2 \leq -2 \cdot 10^{+44}:\\
\;\;\;\;x \cdot 2\\
\mathbf{elif}\;x \cdot 2 \leq 2.2 \cdot 10^{-22}:\\
\;\;\;\;\left(a \cdot 27\right) \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot 2\\
\end{array}
\end{array}
if (*.f64 x #s(literal 2 binary64)) < -2.0000000000000002e44 or 2.2000000000000001e-22 < (*.f64 x #s(literal 2 binary64)) Initial program 93.5%
Taylor expanded in x around inf
Applied rewrites18.1%
Taylor expanded in x around inf
Applied rewrites53.9%
if -2.0000000000000002e44 < (*.f64 x #s(literal 2 binary64)) < 2.2000000000000001e-22Initial program 96.5%
Taylor expanded in x around inf
Applied rewrites47.9%
(FPCore (x y z t a b) :precision binary64 (+ (* x 2.0) (* (* a 27.0) b)))
double code(double x, double y, double z, double t, double a, double b) {
return (x * 2.0) + ((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) + ((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) + ((a * 27.0) * b);
}
def code(x, y, z, t, a, b): return (x * 2.0) + ((a * 27.0) * b)
function code(x, y, z, t, a, b) return Float64(Float64(x * 2.0) + Float64(Float64(a * 27.0) * b)) end
function tmp = code(x, y, z, t, a, b) tmp = (x * 2.0) + ((a * 27.0) * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * 2.0), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 2 + \left(a \cdot 27\right) \cdot b
\end{array}
Initial program 95.1%
Taylor expanded in x around 0
Applied rewrites62.5%
(FPCore (x y z t a b) :precision binary64 (* x 2.0))
double code(double x, double y, double z, double t, double a, double b) {
return x * 2.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 = x * 2.0d0
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x * 2.0;
}
def code(x, y, z, t, a, b): return x * 2.0
function code(x, y, z, t, a, b) return Float64(x * 2.0) end
function tmp = code(x, y, z, t, a, b) tmp = x * 2.0; end
code[x_, y_, z_, t_, a_, b_] := N[(x * 2.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 2
\end{array}
Initial program 95.1%
Taylor expanded in x around inf
Applied rewrites33.9%
Taylor expanded in x around inf
Applied rewrites30.5%
(FPCore (x y z t a b) :precision binary64 (* a 27.0))
double code(double x, double y, double z, double t, double a, double b) {
return a * 27.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 = a * 27.0d0
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return a * 27.0;
}
def code(x, y, z, t, a, b): return a * 27.0
function code(x, y, z, t, a, b) return Float64(a * 27.0) end
function tmp = code(x, y, z, t, a, b) tmp = a * 27.0; end
code[x_, y_, z_, t_, a_, b_] := N[(a * 27.0), $MachinePrecision]
\begin{array}{l}
\\
a \cdot 27
\end{array}
Initial program 95.1%
Taylor expanded in x around 0
Applied rewrites66.0%
Taylor expanded in x around 0
Applied rewrites3.2%
(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 2024321
(FPCore (x y z t a b)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, A"
:precision binary64
:pre (TRUE)
: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)))