
(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 6 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 and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* y (* x 3.0)) z))
assert(x < y);
double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (y * (x * 3.0)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (y * (x * 3.0)) - z;
end
NOTE: x and y 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] = \mathsf{sort}([x, y])\\
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -5.2e-57) (- z) (if (<= z 4.8e-25) (* 3.0 (* x y)) (- z))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e-57) {
tmp = -z;
} else if (z <= 4.8e-25) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
NOTE: x and y 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 (z <= (-5.2d-57)) then
tmp = -z
else if (z <= 4.8d-25) then
tmp = 3.0d0 * (x * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e-57) {
tmp = -z;
} else if (z <= 4.8e-25) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -5.2e-57: tmp = -z elif z <= 4.8e-25: tmp = 3.0 * (x * y) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= -5.2e-57) tmp = Float64(-z); elseif (z <= 4.8e-25) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(-z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -5.2e-57)
tmp = -z;
elseif (z <= 4.8e-25)
tmp = 3.0 * (x * y);
else
tmp = -z;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -5.2e-57], (-z), If[LessEqual[z, 4.8e-25], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{-57}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{-25}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -5.19999999999999971e-57 or 4.80000000000000018e-25 < z Initial program 99.9%
associate-*l*99.3%
Simplified99.3%
Taylor expanded in x around 0 77.0%
neg-mul-177.0%
Simplified77.0%
if -5.19999999999999971e-57 < z < 4.80000000000000018e-25Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 74.9%
Final simplification76.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -4.6e-58) (- z) (if (<= z 5000.0) (* y (* x 3.0)) (- z))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e-58) {
tmp = -z;
} else if (z <= 5000.0) {
tmp = y * (x * 3.0);
} else {
tmp = -z;
}
return tmp;
}
NOTE: x and y 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 (z <= (-4.6d-58)) then
tmp = -z
else if (z <= 5000.0d0) then
tmp = y * (x * 3.0d0)
else
tmp = -z
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e-58) {
tmp = -z;
} else if (z <= 5000.0) {
tmp = y * (x * 3.0);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -4.6e-58: tmp = -z elif z <= 5000.0: tmp = y * (x * 3.0) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= -4.6e-58) tmp = Float64(-z); elseif (z <= 5000.0) tmp = Float64(y * Float64(x * 3.0)); else tmp = Float64(-z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -4.6e-58)
tmp = -z;
elseif (z <= 5000.0)
tmp = y * (x * 3.0);
else
tmp = -z;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -4.6e-58], (-z), If[LessEqual[z, 5000.0], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{-58}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 5000:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -4.5999999999999998e-58 or 5e3 < z Initial program 99.9%
associate-*l*99.3%
Simplified99.3%
Taylor expanded in x around 0 77.7%
neg-mul-177.7%
Simplified77.7%
if -4.5999999999999998e-58 < z < 5e3Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 74.0%
add-cube-cbrt73.0%
pow373.0%
Applied egg-rr73.0%
rem-cube-cbrt74.0%
associate-*r*74.0%
Applied egg-rr74.0%
Final simplification76.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -2.2e-55) (- z) (if (<= z 1020000.0) (* x (* 3.0 y)) (- z))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-55) {
tmp = -z;
} else if (z <= 1020000.0) {
tmp = x * (3.0 * y);
} else {
tmp = -z;
}
return tmp;
}
NOTE: x and y 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 (z <= (-2.2d-55)) then
tmp = -z
else if (z <= 1020000.0d0) then
tmp = x * (3.0d0 * y)
else
tmp = -z
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-55) {
tmp = -z;
} else if (z <= 1020000.0) {
tmp = x * (3.0 * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -2.2e-55: tmp = -z elif z <= 1020000.0: tmp = x * (3.0 * y) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= -2.2e-55) tmp = Float64(-z); elseif (z <= 1020000.0) tmp = Float64(x * Float64(3.0 * y)); else tmp = Float64(-z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -2.2e-55)
tmp = -z;
elseif (z <= 1020000.0)
tmp = x * (3.0 * y);
else
tmp = -z;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -2.2e-55], (-z), If[LessEqual[z, 1020000.0], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-55}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 1020000:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -2.2e-55 or 1.02e6 < z Initial program 99.9%
associate-*l*99.3%
Simplified99.3%
Taylor expanded in x around 0 77.7%
neg-mul-177.7%
Simplified77.7%
if -2.2e-55 < z < 1.02e6Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 74.0%
add-cube-cbrt73.0%
pow373.0%
Applied egg-rr73.0%
rem-cube-cbrt74.0%
*-commutative74.0%
associate-*r*74.0%
Applied egg-rr74.0%
Final simplification76.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y);
double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - z;
end
NOTE: x and y 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] = \mathsf{sort}([x, y])\\
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- z))
assert(x < y);
double code(double x, double y, double z) {
return -z;
}
NOTE: x and y 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;
public static double code(double x, double y, double z) {
return -z;
}
[x, y] = sort([x, y]) def code(x, y, z): return -z
x, y = sort([x, y]) function code(x, y, z) return Float64(-z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = -z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := (-z)
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
-z
\end{array}
Initial program 99.8%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 56.6%
neg-mul-156.6%
Simplified56.6%
Final simplification56.6%
(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 2023287
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))