
(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * 3.0d0) * y) - z
end function
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
def code(x, y, z): return ((x * 3.0) * y) - z
function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
function tmp = code(x, y, z) tmp = ((x * 3.0) * y) - z; end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * 3.0d0) * y) - z
end function
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
def code(x, y, z): return ((x * 3.0) * y) - z
function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
function tmp = code(x, y, z) tmp = ((x * 3.0) * y) - z; end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (3.0d0 * y)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x * (3.0 * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x * (3.0 * y)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= x -9.5e+87)
(and (not (<= x -6.2e+53))
(or (<= x -4.9e+25) (not (<= x 1.35e-74)))))
(* 3.0 (* x y))
(- z)))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+87) || (!(x <= -6.2e+53) && ((x <= -4.9e+25) || !(x <= 1.35e-74)))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-9.5d+87)) .or. (.not. (x <= (-6.2d+53))) .and. (x <= (-4.9d+25)) .or. (.not. (x <= 1.35d-74))) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+87) || (!(x <= -6.2e+53) && ((x <= -4.9e+25) || !(x <= 1.35e-74)))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x <= -9.5e+87) or (not (x <= -6.2e+53) and ((x <= -4.9e+25) or not (x <= 1.35e-74))): tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((x <= -9.5e+87) || (!(x <= -6.2e+53) && ((x <= -4.9e+25) || !(x <= 1.35e-74)))) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x <= -9.5e+87) || (~((x <= -6.2e+53)) && ((x <= -4.9e+25) || ~((x <= 1.35e-74)))))
tmp = 3.0 * (x * y);
else
tmp = -z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e+87], And[N[Not[LessEqual[x, -6.2e+53]], $MachinePrecision], Or[LessEqual[x, -4.9e+25], N[Not[LessEqual[x, 1.35e-74]], $MachinePrecision]]]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+87} \lor \neg \left(x \leq -6.2 \cdot 10^{+53}\right) \land \left(x \leq -4.9 \cdot 10^{+25} \lor \neg \left(x \leq 1.35 \cdot 10^{-74}\right)\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -9.4999999999999992e87 or -6.20000000000000038e53 < x < -4.9000000000000001e25 or 1.35000000000000009e-74 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.7%
fma-neg99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 66.4%
if -9.4999999999999992e87 < x < -6.20000000000000038e53 or -4.9000000000000001e25 < x < 1.35000000000000009e-74Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 75.7%
neg-mul-175.7%
Simplified75.7%
Final simplification71.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (* 3.0 y))))
(if (<= x -6e+87)
t_0
(if (<= x -1.25e+54)
(- z)
(if (<= x -1.95e+21) (* 3.0 (* x y)) (if (<= x 1.35e-72) (- z) t_0))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = x * (3.0 * y);
double tmp;
if (x <= -6e+87) {
tmp = t_0;
} else if (x <= -1.25e+54) {
tmp = -z;
} else if (x <= -1.95e+21) {
tmp = 3.0 * (x * y);
} else if (x <= 1.35e-72) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * (3.0d0 * y)
if (x <= (-6d+87)) then
tmp = t_0
else if (x <= (-1.25d+54)) then
tmp = -z
else if (x <= (-1.95d+21)) then
tmp = 3.0d0 * (x * y)
else if (x <= 1.35d-72) then
tmp = -z
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = x * (3.0 * y);
double tmp;
if (x <= -6e+87) {
tmp = t_0;
} else if (x <= -1.25e+54) {
tmp = -z;
} else if (x <= -1.95e+21) {
tmp = 3.0 * (x * y);
} else if (x <= 1.35e-72) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = x * (3.0 * y) tmp = 0 if x <= -6e+87: tmp = t_0 elif x <= -1.25e+54: tmp = -z elif x <= -1.95e+21: tmp = 3.0 * (x * y) elif x <= 1.35e-72: tmp = -z else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(x * Float64(3.0 * y)) tmp = 0.0 if (x <= -6e+87) tmp = t_0; elseif (x <= -1.25e+54) tmp = Float64(-z); elseif (x <= -1.95e+21) tmp = Float64(3.0 * Float64(x * y)); elseif (x <= 1.35e-72) tmp = Float64(-z); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x * (3.0 * y);
tmp = 0.0;
if (x <= -6e+87)
tmp = t_0;
elseif (x <= -1.25e+54)
tmp = -z;
elseif (x <= -1.95e+21)
tmp = 3.0 * (x * y);
elseif (x <= 1.35e-72)
tmp = -z;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6e+87], t$95$0, If[LessEqual[x, -1.25e+54], (-z), If[LessEqual[x, -1.95e+21], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.35e-72], (-z), t$95$0]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(3 \cdot y\right)\\
\mathbf{if}\;x \leq -6 \cdot 10^{+87}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{+54}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq -1.95 \cdot 10^{+21}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;x \leq 1.35 \cdot 10^{-72}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -5.9999999999999998e87 or 1.35e-72 < x Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.7%
fma-neg99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 64.7%
*-commutative64.7%
associate-*l*64.8%
*-commutative64.8%
Simplified64.8%
if -5.9999999999999998e87 < x < -1.25000000000000001e54 or -1.95e21 < x < 1.35e-72Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 75.7%
neg-mul-175.7%
Simplified75.7%
if -1.25000000000000001e54 < x < -1.95e21Initial program 99.2%
associate-*l*99.5%
Simplified99.5%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.5%
fma-neg99.2%
Applied egg-rr99.2%
Taylor expanded in y around inf 99.5%
Final simplification71.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (3.0d0 * (x * y)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return -z;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return -z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return -z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(-z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
-z
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 55.6%
neg-mul-155.6%
Simplified55.6%
Final simplification55.6%
(FPCore (x y z) :precision binary64 (- (* x (* 3.0 y)) z))
double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (3.0d0 * y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (3.0 * y)) - z;
}
def code(x, y, z): return (x * (3.0 * y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(3.0 * y)) - z) end
function tmp = code(x, y, z) tmp = (x * (3.0 * y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
herbie shell --seed 2023322
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))