
(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.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 (if (or (<= x -1.65e+28) (not (<= x 1.85e-90))) (* 3.0 (* x y)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e+28) || !(x <= 1.85e-90)) {
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 ((x <= (-1.65d+28)) .or. (.not. (x <= 1.85d-90))) 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 ((x <= -1.65e+28) || !(x <= 1.85e-90)) {
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 (x <= -1.65e+28) or not (x <= 1.85e-90): 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 ((x <= -1.65e+28) || !(x <= 1.85e-90)) 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 ((x <= -1.65e+28) || ~((x <= 1.85e-90)))
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[x, -1.65e+28], N[Not[LessEqual[x, 1.85e-90]], $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}\;x \leq -1.65 \cdot 10^{+28} \lor \neg \left(x \leq 1.85 \cdot 10^{-90}\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.65e28 or 1.85000000000000009e-90 < x Initial program 99.1%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 74.8%
if -1.65e28 < x < 1.85000000000000009e-90Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 72.5%
mul-1-neg72.5%
Simplified72.5%
Final simplification73.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= x -5.9e+28) (not (<= x 4.1e-88))) (* x (* 3.0 y)) (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.9e+28) || !(x <= 4.1e-88)) {
tmp = x * (3.0 * 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 ((x <= (-5.9d+28)) .or. (.not. (x <= 4.1d-88))) then
tmp = x * (3.0d0 * 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 ((x <= -5.9e+28) || !(x <= 4.1e-88)) {
tmp = x * (3.0 * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x <= -5.9e+28) or not (x <= 4.1e-88): tmp = x * (3.0 * y) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((x <= -5.9e+28) || !(x <= 4.1e-88)) tmp = Float64(x * Float64(3.0 * 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 ((x <= -5.9e+28) || ~((x <= 4.1e-88)))
tmp = x * (3.0 * 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[x, -5.9e+28], N[Not[LessEqual[x, 4.1e-88]], $MachinePrecision]], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.9 \cdot 10^{+28} \lor \neg \left(x \leq 4.1 \cdot 10^{-88}\right):\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.9000000000000002e28 or 4.1000000000000001e-88 < x Initial program 99.1%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 74.8%
associate-*r*74.2%
*-commutative74.2%
associate-*r*74.8%
Simplified74.8%
if -5.9000000000000002e28 < x < 4.1000000000000001e-88Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 72.5%
mul-1-neg72.5%
Simplified72.5%
Final simplification73.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -5.2e+29) (* x (* 3.0 y)) (if (<= x 4.4e-88) (- z) (* y (* x 3.0)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+29) {
tmp = x * (3.0 * y);
} else if (x <= 4.4e-88) {
tmp = -z;
} else {
tmp = y * (x * 3.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) :: tmp
if (x <= (-5.2d+29)) then
tmp = x * (3.0d0 * y)
else if (x <= 4.4d-88) then
tmp = -z
else
tmp = y * (x * 3.0d0)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+29) {
tmp = x * (3.0 * y);
} else if (x <= 4.4e-88) {
tmp = -z;
} else {
tmp = y * (x * 3.0);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -5.2e+29: tmp = x * (3.0 * y) elif x <= 4.4e-88: tmp = -z else: tmp = y * (x * 3.0) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -5.2e+29) tmp = Float64(x * Float64(3.0 * y)); elseif (x <= 4.4e-88) tmp = Float64(-z); else tmp = Float64(y * Float64(x * 3.0)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -5.2e+29)
tmp = x * (3.0 * y);
elseif (x <= 4.4e-88)
tmp = -z;
else
tmp = y * (x * 3.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_] := If[LessEqual[x, -5.2e+29], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.4e-88], (-z), N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+29}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{-88}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if x < -5.2e29Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 85.4%
associate-*r*85.5%
*-commutative85.5%
associate-*r*85.4%
Simplified85.4%
if -5.2e29 < x < 4.4000000000000001e-88Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 72.5%
mul-1-neg72.5%
Simplified72.5%
if 4.4000000000000001e-88 < x Initial program 98.6%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 66.0%
associate-*r*64.9%
*-commutative64.9%
associate-*r*66.0%
Simplified66.0%
Taylor expanded in x around 0 66.0%
associate-*r*64.9%
Simplified64.9%
Final simplification73.4%
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.5%
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.5%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 47.2%
mul-1-neg47.2%
Simplified47.2%
Final simplification47.2%
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.5%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.5%
add-sqr-sqrt51.4%
associate-*r*51.4%
fma-neg51.4%
add-sqr-sqrt28.3%
sqrt-unprod31.1%
sqr-neg31.1%
sqrt-unprod11.4%
add-sqr-sqrt25.9%
Applied egg-rr25.9%
Taylor expanded in x around 0 2.3%
Final simplification2.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 2024078
(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))