
(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 3 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 y x (* x (* y 2.0))) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(y, x, (x * (y * 2.0))) - z;
}
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(fma(y, x, Float64(x * Float64(y * 2.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 * x + N[(x * N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(y, x, x \cdot \left(y \cdot 2\right)\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.1%
Simplified99.1%
Taylor expanded in x around 0 99.8%
add-log-exp56.7%
add-cube-cbrt56.7%
log-prod56.7%
pow256.7%
*-commutative56.7%
exp-prod56.7%
pow356.7%
add-cbrt-cube56.7%
exp-prod44.8%
*-commutative44.8%
exp-prod44.8%
pow344.8%
add-cbrt-cube44.8%
Applied egg-rr51.3%
+-commutative51.3%
*-commutative51.3%
fma-define51.3%
unpow251.3%
exp-prod45.5%
exp-prod58.0%
prod-exp58.1%
rem-log-exp99.9%
distribute-lft-out99.6%
count-299.6%
*-commutative99.6%
Simplified99.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x (* y 3.0)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x * (y * 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 = (x * (y * 3.0d0)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x * (y * 3.0)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x * (y * 3.0)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x * Float64(y * 3.0)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x * (y * 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[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(y \cdot 3\right) - z
\end{array}
Initial program 99.9%
associate-*l*99.1%
Simplified99.1%
Final simplification99.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(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.1%
Simplified99.1%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(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 2024106
(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))