
(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 7 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 (- (* y (* x 3.0)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (y * (x * 3.0)) - 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 = (y * (x * 3.0d0)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (y * (x * 3.0)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (y * (x * 3.0)) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 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 (if (or (<= y -1.85e-124) (not (<= y 8.8e+54))) (* 3.0 (* x y)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.85e-124) || !(y <= 8.8e+54)) {
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 <= (-1.85d-124)) .or. (.not. (y <= 8.8d+54))) 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 <= -1.85e-124) || !(y <= 8.8e+54)) {
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 <= -1.85e-124) or not (y <= 8.8e+54): 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 <= -1.85e-124) || !(y <= 8.8e+54)) 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 <= -1.85e-124) || ~((y <= 8.8e+54)))
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, -1.85e-124], N[Not[LessEqual[y, 8.8e+54]], $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 -1.85 \cdot 10^{-124} \lor \neg \left(y \leq 8.8 \cdot 10^{+54}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.84999999999999995e-124 or 8.7999999999999996e54 < 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 70.2%
if -1.84999999999999995e-124 < y < 8.7999999999999996e54Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 73.0%
neg-mul-173.0%
Simplified73.0%
Final simplification71.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -8.9e-156) (* y (* x 3.0)) (if (<= y 3.9e+54) (- z) (* 3.0 (* x y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -8.9e-156) {
tmp = y * (x * 3.0);
} else if (y <= 3.9e+54) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 <= (-8.9d-156)) then
tmp = y * (x * 3.0d0)
else if (y <= 3.9d+54) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
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 <= -8.9e-156) {
tmp = y * (x * 3.0);
} else if (y <= 3.9e+54) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -8.9e-156: tmp = y * (x * 3.0) elif y <= 3.9e+54: tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -8.9e-156) tmp = Float64(y * Float64(x * 3.0)); elseif (y <= 3.9e+54) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -8.9e-156)
tmp = y * (x * 3.0);
elseif (y <= 3.9e+54)
tmp = -z;
else
tmp = 3.0 * (x * y);
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, -8.9e-156], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.9e+54], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.9 \cdot 10^{-156}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{+54}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -8.9000000000000002e-156Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 87.1%
sub-neg87.1%
distribute-rgt-in87.1%
*-commutative87.1%
associate-/l*87.2%
metadata-eval87.2%
neg-mul-187.2%
add-sqr-sqrt44.9%
sqrt-unprod58.3%
sqr-neg58.3%
sqrt-unprod25.2%
add-sqr-sqrt50.9%
Applied egg-rr50.9%
Taylor expanded in y around inf 63.5%
fma-define63.5%
Simplified63.5%
Taylor expanded in x around inf 64.2%
if -8.9000000000000002e-156 < y < 3.9000000000000003e54Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.1%
neg-mul-174.1%
Simplified74.1%
if 3.9000000000000003e54 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 79.8%
Final simplification70.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -7.6e-156) (* x (* 3.0 y)) (if (<= y 7.6e+54) (- z) (* 3.0 (* x y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -7.6e-156) {
tmp = x * (3.0 * y);
} else if (y <= 7.6e+54) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 <= (-7.6d-156)) then
tmp = x * (3.0d0 * y)
else if (y <= 7.6d+54) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
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 <= -7.6e-156) {
tmp = x * (3.0 * y);
} else if (y <= 7.6e+54) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -7.6e-156: tmp = x * (3.0 * y) elif y <= 7.6e+54: tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -7.6e-156) tmp = Float64(x * Float64(3.0 * y)); elseif (y <= 7.6e+54) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -7.6e-156)
tmp = x * (3.0 * y);
elseif (y <= 7.6e+54)
tmp = -z;
else
tmp = 3.0 * (x * y);
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, -7.6e-156], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.6e+54], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{-156}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+54}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -7.60000000000000015e-156Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 64.1%
*-commutative64.1%
associate-*r*64.2%
*-commutative64.2%
Simplified64.2%
if -7.60000000000000015e-156 < y < 7.6000000000000005e54Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.1%
neg-mul-174.1%
Simplified74.1%
if 7.6000000000000005e54 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around inf 79.8%
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.8%
Simplified99.8%
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.8%
Simplified99.8%
Taylor expanded in x around 0 48.4%
neg-mul-148.4%
Simplified48.4%
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.8%
Simplified99.8%
Taylor expanded in x around 0 48.4%
neg-mul-148.4%
Simplified48.4%
neg-sub048.4%
sub-neg48.4%
add-sqr-sqrt26.7%
sqrt-unprod18.9%
sqr-neg18.9%
sqrt-unprod1.1%
add-sqr-sqrt2.3%
Applied egg-rr2.3%
+-lft-identity2.3%
Simplified2.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 2024172
(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))