
(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}
(FPCore (x y z) :precision binary64 (- (fma -3.0 (* y x) z)))
double code(double x, double y, double z) {
return -fma(-3.0, (y * x), z);
}
function code(x, y, z) return Float64(-fma(-3.0, Float64(y * x), z)) end
code[x_, y_, z_] := (-N[(-3.0 * N[(y * x), $MachinePrecision] + z), $MachinePrecision])
\begin{array}{l}
\\
-\mathsf{fma}\left(-3, y \cdot x, z\right)
\end{array}
Initial program 99.8%
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y))) (if (or (<= t_0 -2e+134) (not (<= t_0 1e-86))) (* (* 3.0 x) y) (- z))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if ((t_0 <= -2e+134) || !(t_0 <= 1e-86)) {
tmp = (3.0 * x) * y;
} else {
tmp = -z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if ((t_0 <= (-2d+134)) .or. (.not. (t_0 <= 1d-86))) then
tmp = (3.0d0 * x) * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if ((t_0 <= -2e+134) || !(t_0 <= 1e-86)) {
tmp = (3.0 * x) * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if (t_0 <= -2e+134) or not (t_0 <= 1e-86): tmp = (3.0 * x) * y else: tmp = -z return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if ((t_0 <= -2e+134) || !(t_0 <= 1e-86)) tmp = Float64(Float64(3.0 * x) * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if ((t_0 <= -2e+134) || ~((t_0 <= 1e-86))) tmp = (3.0 * x) * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+134], N[Not[LessEqual[t$95$0, 1e-86]], $MachinePrecision]], N[(N[(3.0 * x), $MachinePrecision] * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+134} \lor \neg \left(t\_0 \leq 10^{-86}\right):\\
\;\;\;\;\left(3 \cdot x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -1.99999999999999984e134 or 1.00000000000000008e-86 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6419.3
Applied rewrites19.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
Applied rewrites82.5%
if -1.99999999999999984e134 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 1.00000000000000008e-86Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6471.8
Applied rewrites71.8%
Final simplification76.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* x 3.0) y)))
(if (<= t_0 -2e+134)
(* (* y 3.0) x)
(if (<= t_0 1e-86) (- z) (* (* y x) 3.0)))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2e+134) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 1e-86) {
tmp = -z;
} else {
tmp = (y * x) * 3.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-2d+134)) then
tmp = (y * 3.0d0) * x
else if (t_0 <= 1d-86) then
tmp = -z
else
tmp = (y * x) * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2e+134) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 1e-86) {
tmp = -z;
} else {
tmp = (y * x) * 3.0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -2e+134: tmp = (y * 3.0) * x elif t_0 <= 1e-86: tmp = -z else: tmp = (y * x) * 3.0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -2e+134) tmp = Float64(Float64(y * 3.0) * x); elseif (t_0 <= 1e-86) tmp = Float64(-z); else tmp = Float64(Float64(y * x) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if (t_0 <= -2e+134) tmp = (y * 3.0) * x; elseif (t_0 <= 1e-86) tmp = -z; else tmp = (y * x) * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+134], N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 1e-86], (-z), N[(N[(y * x), $MachinePrecision] * 3.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+134}:\\
\;\;\;\;\left(y \cdot 3\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 10^{-86}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot x\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -1.99999999999999984e134Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6416.4
Applied rewrites16.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6486.4
Applied rewrites86.4%
Applied rewrites86.3%
if -1.99999999999999984e134 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 1.00000000000000008e-86Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6471.8
Applied rewrites71.8%
if 1.00000000000000008e-86 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6420.6
Applied rewrites20.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6480.8
Applied rewrites80.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* x 3.0) y)))
(if (<= t_0 -2e+134)
(* (* y 3.0) x)
(if (<= t_0 1e-86) (- z) (* (* 3.0 x) y)))))
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2e+134) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 1e-86) {
tmp = -z;
} else {
tmp = (3.0 * x) * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-2d+134)) then
tmp = (y * 3.0d0) * x
else if (t_0 <= 1d-86) then
tmp = -z
else
tmp = (3.0d0 * x) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2e+134) {
tmp = (y * 3.0) * x;
} else if (t_0 <= 1e-86) {
tmp = -z;
} else {
tmp = (3.0 * x) * y;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -2e+134: tmp = (y * 3.0) * x elif t_0 <= 1e-86: tmp = -z else: tmp = (3.0 * x) * y return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -2e+134) tmp = Float64(Float64(y * 3.0) * x); elseif (t_0 <= 1e-86) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * x) * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 3.0) * y; tmp = 0.0; if (t_0 <= -2e+134) tmp = (y * 3.0) * x; elseif (t_0 <= 1e-86) tmp = -z; else tmp = (3.0 * x) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+134], N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 1e-86], (-z), N[(N[(3.0 * x), $MachinePrecision] * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+134}:\\
\;\;\;\;\left(y \cdot 3\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 10^{-86}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot x\right) \cdot y\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -1.99999999999999984e134Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6416.4
Applied rewrites16.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6486.4
Applied rewrites86.4%
Applied rewrites86.3%
if -1.99999999999999984e134 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 1.00000000000000008e-86Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6471.8
Applied rewrites71.8%
if 1.00000000000000008e-86 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6420.6
Applied rewrites20.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6480.8
Applied rewrites80.8%
Applied rewrites80.8%
(FPCore (x y z) :precision binary64 (fma (* 3.0 y) x (- z)))
double code(double x, double y, double z) {
return fma((3.0 * y), x, -z);
}
function code(x, y, z) return fma(Float64(3.0 * y), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(3.0 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
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
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6447.4
Applied rewrites47.4%
(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 2024326
(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))