
(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 8 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 (fma (* 3.0 y) x (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((3.0 * y), x, -z);
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(3.0 * y), x, Float64(-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 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.5%
*-commutative99.5%
fma-neg99.5%
Simplified99.5%
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.3e-124) (not (<= y 2.5e+89))) (* y (* 3.0 x)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.3e-124) || !(y <= 2.5e+89)) {
tmp = y * (3.0 * x);
} 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.3d-124)) .or. (.not. (y <= 2.5d+89))) then
tmp = y * (3.0d0 * x)
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.3e-124) || !(y <= 2.5e+89)) {
tmp = y * (3.0 * x);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -3.3e-124) or not (y <= 2.5e+89): tmp = y * (3.0 * x) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -3.3e-124) || !(y <= 2.5e+89)) tmp = Float64(y * Float64(3.0 * x)); 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.3e-124) || ~((y <= 2.5e+89)))
tmp = y * (3.0 * x);
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.3e-124], N[Not[LessEqual[y, 2.5e+89]], $MachinePrecision]], N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{-124} \lor \neg \left(y \leq 2.5 \cdot 10^{+89}\right):\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -3.29999999999999984e-124 or 2.49999999999999992e89 < y Initial program 99.8%
associate-*l*99.1%
Simplified99.1%
Taylor expanded in y around inf 98.5%
+-commutative98.5%
fma-define98.5%
mul-1-neg98.5%
fma-neg98.5%
Simplified98.5%
Taylor expanded in x around inf 70.1%
if -3.29999999999999984e-124 < y < 2.49999999999999992e89Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.5%
mul-1-neg74.5%
Simplified74.5%
Final simplification71.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.4e-124) (not (<= y 3.9e+89))) (* 3.0 (* y x)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-124) || !(y <= 3.9e+89)) {
tmp = 3.0 * (y * x);
} 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.4d-124)) .or. (.not. (y <= 3.9d+89))) then
tmp = 3.0d0 * (y * x)
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.4e-124) || !(y <= 3.9e+89)) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -3.4e-124) or not (y <= 3.9e+89): tmp = 3.0 * (y * x) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-124) || !(y <= 3.9e+89)) tmp = Float64(3.0 * Float64(y * x)); 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.4e-124) || ~((y <= 3.9e+89)))
tmp = 3.0 * (y * x);
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.4e-124], N[Not[LessEqual[y, 3.9e+89]], $MachinePrecision]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-124} \lor \neg \left(y \leq 3.9 \cdot 10^{+89}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -3.4000000000000001e-124 or 3.90000000000000011e89 < y Initial program 99.8%
associate-*l*99.1%
Simplified99.1%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 70.1%
if -3.4000000000000001e-124 < y < 3.90000000000000011e89Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.5%
mul-1-neg74.5%
Simplified74.5%
Final simplification71.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -2.3e-126) (* y (* 3.0 x)) (if (<= y 2.5e+89) (- z) (* (* 3.0 y) x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e-126) {
tmp = y * (3.0 * x);
} else if (y <= 2.5e+89) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
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 <= (-2.3d-126)) then
tmp = y * (3.0d0 * x)
else if (y <= 2.5d+89) then
tmp = -z
else
tmp = (3.0d0 * y) * x
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 <= -2.3e-126) {
tmp = y * (3.0 * x);
} else if (y <= 2.5e+89) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -2.3e-126: tmp = y * (3.0 * x) elif y <= 2.5e+89: tmp = -z else: tmp = (3.0 * y) * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -2.3e-126) tmp = Float64(y * Float64(3.0 * x)); elseif (y <= 2.5e+89) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -2.3e-126)
tmp = y * (3.0 * x);
elseif (y <= 2.5e+89)
tmp = -z;
else
tmp = (3.0 * y) * x;
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[LessEqual[y, -2.3e-126], N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.5e+89], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-126}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+89}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if y < -2.30000000000000011e-126Initial program 99.8%
associate-*l*98.8%
Simplified98.8%
Taylor expanded in y around inf 97.9%
+-commutative97.9%
fma-define97.8%
mul-1-neg97.8%
fma-neg97.9%
Simplified97.9%
Taylor expanded in x around inf 63.4%
if -2.30000000000000011e-126 < y < 2.49999999999999992e89Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.3%
mul-1-neg74.3%
Simplified74.3%
if 2.49999999999999992e89 < y Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 81.3%
*-commutative81.3%
associate-*r*81.3%
Simplified81.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* 3.0 y) x) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return ((3.0 * y) * x) - 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 * y) * x) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return ((3.0 * y) * x) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return ((3.0 * y) * x) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(Float64(3.0 * y) * x) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = ((3.0 * y) * x) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(3 \cdot y\right) \cdot x - z
\end{array}
Initial program 99.8%
associate-*l*99.5%
Simplified99.5%
Final simplification99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* y x)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (y * x)) - 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 * (y * x)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (y * x)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (y * x)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(y * x)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (y * x)) - 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[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
3 \cdot \left(y \cdot x\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.5%
Simplified99.5%
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.8%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 49.3%
mul-1-neg49.3%
Simplified49.3%
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 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.5%
Simplified99.5%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.8%
fma-neg99.8%
add-sqr-sqrt46.6%
sqrt-unprod59.8%
sqr-neg59.8%
sqrt-unprod27.1%
add-sqr-sqrt50.9%
Applied egg-rr50.9%
Taylor expanded in y around 0 2.1%
(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 2024137
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x (* 3 y)) z))
(- (* (* x 3.0) y) z))