
(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 (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.9%
*-commutative99.9%
fmm-def99.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 -8.1e-112) (not (<= y 3e+18))) (* (* 3.0 y) x) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.1e-112) || !(y <= 3e+18)) {
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 <= (-8.1d-112)) .or. (.not. (y <= 3d+18))) 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 <= -8.1e-112) || !(y <= 3e+18)) {
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 <= -8.1e-112) or not (y <= 3e+18): 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 <= -8.1e-112) || !(y <= 3e+18)) tmp = Float64(Float64(3.0 * 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 <= -8.1e-112) || ~((y <= 3e+18)))
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, -8.1e-112], N[Not[LessEqual[y, 3e+18]], $MachinePrecision]], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.1 \cdot 10^{-112} \lor \neg \left(y \leq 3 \cdot 10^{+18}\right):\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -8.10000000000000022e-112 or 3e18 < y Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in z around inf 91.9%
*-commutative91.9%
fmm-def92.0%
associate-/l*85.2%
metadata-eval85.2%
Simplified85.2%
Taylor expanded in x around inf 68.0%
*-commutative68.0%
associate-*r*68.0%
*-commutative68.0%
Simplified68.0%
if -8.10000000000000022e-112 < y < 3e18Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 79.5%
mul-1-neg79.5%
Simplified79.5%
Final simplification73.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 -3.7e-110) (not (<= y 4.4e+17))) (* 3.0 (* y x)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e-110) || !(y <= 4.4e+17)) {
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.7d-110)) .or. (.not. (y <= 4.4d+17))) 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.7e-110) || !(y <= 4.4e+17)) {
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.7e-110) or not (y <= 4.4e+17): 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.7e-110) || !(y <= 4.4e+17)) 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.7e-110) || ~((y <= 4.4e+17)))
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.7e-110], N[Not[LessEqual[y, 4.4e+17]], $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.7 \cdot 10^{-110} \lor \neg \left(y \leq 4.4 \cdot 10^{+17}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -3.70000000000000016e-110 or 4.4e17 < y Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in z around inf 91.9%
*-commutative91.9%
fmm-def92.0%
associate-/l*85.2%
metadata-eval85.2%
Simplified85.2%
Taylor expanded in x around inf 68.0%
if -3.70000000000000016e-110 < y < 4.4e17Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 79.5%
mul-1-neg79.5%
Simplified79.5%
Final simplification73.1%
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.9%
Simplified99.9%
Final simplification99.9%
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.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.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 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.9%
Simplified99.9%
Taylor expanded in x around 0 53.4%
mul-1-neg53.4%
Simplified53.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.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 53.4%
mul-1-neg53.4%
Simplified53.4%
neg-sub053.4%
sub-neg53.4%
add-sqr-sqrt27.6%
sqrt-unprod18.0%
sqr-neg18.0%
sqrt-unprod0.9%
add-sqr-sqrt2.1%
Applied egg-rr2.1%
+-lft-identity2.1%
Simplified2.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 2024160
(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))