
(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.9%
associate-*l*99.8%
*-commutative99.8%
fma-neg99.8%
Simplified99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-83) (not (<= y 4.9e+51))) (* y (* 3.0 x)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-83) || !(y <= 4.9e+51)) {
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 <= (-2.5d-83)) .or. (.not. (y <= 4.9d+51))) 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 <= -2.5e-83) || !(y <= 4.9e+51)) {
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 <= -2.5e-83) or not (y <= 4.9e+51): 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 <= -2.5e-83) || !(y <= 4.9e+51)) 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 <= -2.5e-83) || ~((y <= 4.9e+51)))
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, -2.5e-83], N[Not[LessEqual[y, 4.9e+51]], $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 -2.5 \cdot 10^{-83} \lor \neg \left(y \leq 4.9 \cdot 10^{+51}\right):\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -2.5e-83 or 4.89999999999999983e51 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
fma-define99.8%
mul-1-neg99.8%
fma-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 72.2%
if -2.5e-83 < y < 4.89999999999999983e51Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 71.8%
mul-1-neg71.8%
Simplified71.8%
Final simplification72.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -4.8e-83) (not (<= y 4.7e+47))) (* 3.0 (* y x)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.8e-83) || !(y <= 4.7e+47)) {
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 <= (-4.8d-83)) .or. (.not. (y <= 4.7d+47))) 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 <= -4.8e-83) || !(y <= 4.7e+47)) {
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 <= -4.8e-83) or not (y <= 4.7e+47): 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 <= -4.8e-83) || !(y <= 4.7e+47)) 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 <= -4.8e-83) || ~((y <= 4.7e+47)))
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, -4.8e-83], N[Not[LessEqual[y, 4.7e+47]], $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 -4.8 \cdot 10^{-83} \lor \neg \left(y \leq 4.7 \cdot 10^{+47}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -4.8000000000000002e-83 or 4.69999999999999964e47 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 72.2%
if -4.8000000000000002e-83 < y < 4.69999999999999964e47Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 71.8%
mul-1-neg71.8%
Simplified71.8%
Final simplification72.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -3.6e-83) (* (* 3.0 y) x) (if (<= y 1.54e+47) (- z) (* y (* 3.0 x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.6e-83) {
tmp = (3.0 * y) * x;
} else if (y <= 1.54e+47) {
tmp = -z;
} else {
tmp = y * (3.0 * 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 <= (-3.6d-83)) then
tmp = (3.0d0 * y) * x
else if (y <= 1.54d+47) then
tmp = -z
else
tmp = y * (3.0d0 * 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 <= -3.6e-83) {
tmp = (3.0 * y) * x;
} else if (y <= 1.54e+47) {
tmp = -z;
} else {
tmp = y * (3.0 * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -3.6e-83: tmp = (3.0 * y) * x elif y <= 1.54e+47: tmp = -z else: tmp = y * (3.0 * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.6e-83) tmp = Float64(Float64(3.0 * y) * x); elseif (y <= 1.54e+47) tmp = Float64(-z); else tmp = Float64(y * Float64(3.0 * 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 <= -3.6e-83)
tmp = (3.0 * y) * x;
elseif (y <= 1.54e+47)
tmp = -z;
else
tmp = y * (3.0 * 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, -3.6e-83], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 1.54e+47], (-z), N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-83}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\mathbf{elif}\;y \leq 1.54 \cdot 10^{+47}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\end{array}
\end{array}
if y < -3.60000000000000012e-83Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 65.7%
*-commutative65.7%
associate-*r*65.7%
Simplified65.7%
if -3.60000000000000012e-83 < y < 1.54000000000000008e47Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 71.8%
mul-1-neg71.8%
Simplified71.8%
if 1.54000000000000008e47 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
fma-define99.7%
mul-1-neg99.7%
fma-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 79.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.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 (- (* 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.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 46.9%
mul-1-neg46.9%
Simplified46.9%
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.9%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.9%
*-commutative99.9%
associate-*r*99.8%
fma-neg99.8%
add-sqr-sqrt48.6%
sqrt-unprod63.9%
sqr-neg63.9%
sqrt-unprod27.5%
add-sqr-sqrt53.6%
Applied egg-rr53.6%
Taylor expanded in y around 0 2.3%
(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 2024135
(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))