
(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 (fma (* x 3.0) y (- z)))
assert(x < y);
double code(double x, double y, double z) {
return fma((x * 3.0), y, -z);
}
x, y = sort([x, y]) function code(x, y, z) return fma(Float64(x * 3.0), y, Float64(-z)) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * 3.0), $MachinePrecision] * y + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(x \cdot 3, y, -z\right)
\end{array}
Initial program 99.8%
fma-neg99.8%
Simplified99.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 -1.8e-39)
(- z)
(if (or (<= z 3.9e-32) (and (not (<= z 11600000.0)) (<= z 1.9e+74)))
(* 3.0 (* x y))
(- z))))assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e-39) {
tmp = -z;
} else if ((z <= 3.9e-32) || (!(z <= 11600000.0) && (z <= 1.9e+74))) {
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 <= (-1.8d-39)) then
tmp = -z
else if ((z <= 3.9d-32) .or. (.not. (z <= 11600000.0d0)) .and. (z <= 1.9d+74)) 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 <= -1.8e-39) {
tmp = -z;
} else if ((z <= 3.9e-32) || (!(z <= 11600000.0) && (z <= 1.9e+74))) {
tmp = 3.0 * (x * y);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -1.8e-39: tmp = -z elif (z <= 3.9e-32) or (not (z <= 11600000.0) and (z <= 1.9e+74)): 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 <= -1.8e-39) tmp = Float64(-z); elseif ((z <= 3.9e-32) || (!(z <= 11600000.0) && (z <= 1.9e+74))) 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 <= -1.8e-39)
tmp = -z;
elseif ((z <= 3.9e-32) || (~((z <= 11600000.0)) && (z <= 1.9e+74)))
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, -1.8e-39], (-z), If[Or[LessEqual[z, 3.9e-32], And[N[Not[LessEqual[z, 11600000.0]], $MachinePrecision], LessEqual[z, 1.9e+74]]], 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 -1.8 \cdot 10^{-39}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{-32} \lor \neg \left(z \leq 11600000\right) \land z \leq 1.9 \cdot 10^{+74}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -1.8e-39 or 3.9000000000000001e-32 < z < 1.16e7 or 1.8999999999999999e74 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 74.1%
mul-1-neg74.1%
Simplified74.1%
if -1.8e-39 < z < 3.9000000000000001e-32 or 1.16e7 < z < 1.8999999999999999e74Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 79.3%
Final simplification76.6%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= z -2.65e-36)
(- z)
(if (<= z 2e-32)
(* 3.0 (* x y))
(if (<= z 30500.0)
(- z)
(if (<= z 1.56e+74) (/ y (/ 0.3333333333333333 x)) (- z))))))assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -2.65e-36) {
tmp = -z;
} else if (z <= 2e-32) {
tmp = 3.0 * (x * y);
} else if (z <= 30500.0) {
tmp = -z;
} else if (z <= 1.56e+74) {
tmp = y / (0.3333333333333333 / x);
} 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.65d-36)) then
tmp = -z
else if (z <= 2d-32) then
tmp = 3.0d0 * (x * y)
else if (z <= 30500.0d0) then
tmp = -z
else if (z <= 1.56d+74) then
tmp = y / (0.3333333333333333d0 / x)
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.65e-36) {
tmp = -z;
} else if (z <= 2e-32) {
tmp = 3.0 * (x * y);
} else if (z <= 30500.0) {
tmp = -z;
} else if (z <= 1.56e+74) {
tmp = y / (0.3333333333333333 / x);
} else {
tmp = -z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -2.65e-36: tmp = -z elif z <= 2e-32: tmp = 3.0 * (x * y) elif z <= 30500.0: tmp = -z elif z <= 1.56e+74: tmp = y / (0.3333333333333333 / x) else: tmp = -z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= -2.65e-36) tmp = Float64(-z); elseif (z <= 2e-32) tmp = Float64(3.0 * Float64(x * y)); elseif (z <= 30500.0) tmp = Float64(-z); elseif (z <= 1.56e+74) tmp = Float64(y / Float64(0.3333333333333333 / x)); 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.65e-36)
tmp = -z;
elseif (z <= 2e-32)
tmp = 3.0 * (x * y);
elseif (z <= 30500.0)
tmp = -z;
elseif (z <= 1.56e+74)
tmp = y / (0.3333333333333333 / x);
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.65e-36], (-z), If[LessEqual[z, 2e-32], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 30500.0], (-z), If[LessEqual[z, 1.56e+74], N[(y / N[(0.3333333333333333 / x), $MachinePrecision]), $MachinePrecision], (-z)]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.65 \cdot 10^{-36}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-32}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;z \leq 30500:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 1.56 \cdot 10^{+74}:\\
\;\;\;\;\frac{y}{\frac{0.3333333333333333}{x}}\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -2.6499999999999999e-36 or 2.00000000000000011e-32 < z < 30500 or 1.56e74 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 74.1%
mul-1-neg74.1%
Simplified74.1%
if -2.6499999999999999e-36 < z < 2.00000000000000011e-32Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 80.8%
if 30500 < z < 1.56e74Initial program 99.6%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 68.6%
metadata-eval68.6%
*-inverses55.3%
associate-/l*55.3%
*-commutative55.3%
associate-/l*55.3%
metadata-eval55.3%
associate-/l*55.2%
*-commutative55.2%
associate-*r*54.8%
*-commutative54.8%
associate-*r*55.0%
remove-double-neg55.0%
distribute-lft-neg-out55.0%
metadata-eval55.0%
frac-2neg55.0%
associate-/r/54.8%
*-commutative54.8%
associate-/l*55.0%
Applied egg-rr68.5%
Final simplification76.6%
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.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
assert(x < y);
double code(double x, double y, double z) {
return ((x * 3.0) * 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 = ((x * 3.0d0) * y) - z
end function
assert x < y;
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
[x, y] = sort([x, y]) def code(x, y, z): return ((x * 3.0) * y) - z
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = ((x * 3.0) * y) - z;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\left(x \cdot 3\right) \cdot y - 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 (- 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.9%
Simplified99.9%
Taylor expanded in x around 0 49.2%
mul-1-neg49.2%
Simplified49.2%
Final simplification49.2%
(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 2023297
(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))