
(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.8%
associate-*l*99.9%
Simplified99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= y -3.2e-46)
(and (not (<= y 2.8e-18)) (or (<= y 1.2e+21) (not (<= y 2.05e+78)))))
(* 3.0 (* x y))
(- z)))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.2e-46) || (!(y <= 2.8e-18) && ((y <= 1.2e+21) || !(y <= 2.05e+78)))) {
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 ((y <= (-3.2d-46)) .or. (.not. (y <= 2.8d-18)) .and. (y <= 1.2d+21) .or. (.not. (y <= 2.05d+78))) 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 ((y <= -3.2e-46) || (!(y <= 2.8e-18) && ((y <= 1.2e+21) || !(y <= 2.05e+78)))) {
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 (y <= -3.2e-46) or (not (y <= 2.8e-18) and ((y <= 1.2e+21) or not (y <= 2.05e+78))): 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 ((y <= -3.2e-46) || (!(y <= 2.8e-18) && ((y <= 1.2e+21) || !(y <= 2.05e+78)))) 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 ((y <= -3.2e-46) || (~((y <= 2.8e-18)) && ((y <= 1.2e+21) || ~((y <= 2.05e+78)))))
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[y, -3.2e-46], And[N[Not[LessEqual[y, 2.8e-18]], $MachinePrecision], Or[LessEqual[y, 1.2e+21], N[Not[LessEqual[y, 2.05e+78]], $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}\;y \leq -3.2 \cdot 10^{-46} \lor \neg \left(y \leq 2.8 \cdot 10^{-18}\right) \land \left(y \leq 1.2 \cdot 10^{+21} \lor \neg \left(y \leq 2.05 \cdot 10^{+78}\right)\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -3.1999999999999999e-46 or 2.80000000000000012e-18 < y < 1.2e21 or 2.0499999999999998e78 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 69.5%
if -3.1999999999999999e-46 < y < 2.80000000000000012e-18 or 1.2e21 < y < 2.0499999999999998e78Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 67.9%
neg-mul-167.9%
Simplified67.9%
Final simplification68.7%
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 (<= y -1.05e-50)
t_0
(if (<= y 4e-17)
(- z)
(if (<= y 1.2e+26) (* 3.0 (* x y)) (if (<= y 3.3e+79) (- 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 (y <= -1.05e-50) {
tmp = t_0;
} else if (y <= 4e-17) {
tmp = -z;
} else if (y <= 1.2e+26) {
tmp = 3.0 * (x * y);
} else if (y <= 3.3e+79) {
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 (y <= (-1.05d-50)) then
tmp = t_0
else if (y <= 4d-17) then
tmp = -z
else if (y <= 1.2d+26) then
tmp = 3.0d0 * (x * y)
else if (y <= 3.3d+79) 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 (y <= -1.05e-50) {
tmp = t_0;
} else if (y <= 4e-17) {
tmp = -z;
} else if (y <= 1.2e+26) {
tmp = 3.0 * (x * y);
} else if (y <= 3.3e+79) {
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 y <= -1.05e-50: tmp = t_0 elif y <= 4e-17: tmp = -z elif y <= 1.2e+26: tmp = 3.0 * (x * y) elif y <= 3.3e+79: 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 (y <= -1.05e-50) tmp = t_0; elseif (y <= 4e-17) tmp = Float64(-z); elseif (y <= 1.2e+26) tmp = Float64(3.0 * Float64(x * y)); elseif (y <= 3.3e+79) 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 (y <= -1.05e-50)
tmp = t_0;
elseif (y <= 4e-17)
tmp = -z;
elseif (y <= 1.2e+26)
tmp = 3.0 * (x * y);
elseif (y <= 3.3e+79)
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[y, -1.05e-50], t$95$0, If[LessEqual[y, 4e-17], (-z), If[LessEqual[y, 1.2e+26], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.3e+79], (-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}\;y \leq -1.05 \cdot 10^{-50}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-17}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{+26}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{+79}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.05e-50 or 3.3000000000000002e79 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 69.0%
*-commutative69.0%
associate-*r*69.0%
Simplified69.0%
if -1.05e-50 < y < 4.00000000000000029e-17 or 1.20000000000000002e26 < y < 3.3000000000000002e79Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 67.9%
neg-mul-167.9%
Simplified67.9%
if 4.00000000000000029e-17 < y < 1.20000000000000002e26Initial program 100.0%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around inf 80.4%
Final simplification68.7%
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.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.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.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 50.2%
neg-mul-150.2%
Simplified50.2%
(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 2024091
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))