
(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, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* y 3.0) x) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return ((y * 3.0) * 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 = ((y * 3.0d0) * x) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return ((y * 3.0) * x) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return ((y * 3.0) * x) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(Float64(y * 3.0) * x) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = ((y * 3.0) * x) - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[(y * 3.0), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(y \cdot 3\right) \cdot x - z
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y))) (if (or (<= t_0 -780000000000.0) (not (<= t_0 7.6e-57))) t_0 (- z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if ((t_0 <= -780000000000.0) || !(t_0 <= 7.6e-57)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if ((t_0 <= (-780000000000.0d0)) .or. (.not. (t_0 <= 7.6d-57))) then
tmp = t_0
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 t_0 = (x * 3.0) * y;
double tmp;
if ((t_0 <= -780000000000.0) || !(t_0 <= 7.6e-57)) {
tmp = t_0;
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if (t_0 <= -780000000000.0) or not (t_0 <= 7.6e-57): tmp = t_0 else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if ((t_0 <= -780000000000.0) || !(t_0 <= 7.6e-57)) tmp = t_0; else tmp = Float64(-z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (x * 3.0) * y;
tmp = 0.0;
if ((t_0 <= -780000000000.0) || ~((t_0 <= 7.6e-57)))
tmp = t_0;
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_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -780000000000.0], N[Not[LessEqual[t$95$0, 7.6e-57]], $MachinePrecision]], t$95$0, (-z)]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -780000000000 \lor \neg \left(t\_0 \leq 7.6 \cdot 10^{-57}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -7.8e11 or 7.5999999999999995e-57 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6497.8
Applied rewrites97.8%
Taylor expanded in x around inf
Applied rewrites79.1%
Applied rewrites79.2%
if -7.8e11 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 7.5999999999999995e-57Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6487.7
Applied rewrites87.7%
Final simplification83.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* x 3.0) y)))
(if (<= t_0 -2000000000000.0)
(* (* 3.0 y) x)
(if (<= t_0 4e-57) (- z) (* (* x y) 3.0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2000000000000.0) {
tmp = (3.0 * y) * x;
} else if (t_0 <= 4e-57) {
tmp = -z;
} else {
tmp = (x * y) * 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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-2000000000000.0d0)) then
tmp = (3.0d0 * y) * x
else if (t_0 <= 4d-57) then
tmp = -z
else
tmp = (x * y) * 3.0d0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2000000000000.0) {
tmp = (3.0 * y) * x;
} else if (t_0 <= 4e-57) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -2000000000000.0: tmp = (3.0 * y) * x elif t_0 <= 4e-57: tmp = -z else: tmp = (x * y) * 3.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -2000000000000.0) tmp = Float64(Float64(3.0 * y) * x); elseif (t_0 <= 4e-57) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * 3.0); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (x * 3.0) * y;
tmp = 0.0;
if (t_0 <= -2000000000000.0)
tmp = (3.0 * y) * x;
elseif (t_0 <= 4e-57)
tmp = -z;
else
tmp = (x * y) * 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_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2000000000000.0], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 4e-57], (-z), N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2000000000000:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-57}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -2e12Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites82.2%
if -2e12 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 3.99999999999999982e-57Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6487.7
Applied rewrites87.7%
if 3.99999999999999982e-57 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
Taylor expanded in x around inf
Applied rewrites76.4%
Final simplification83.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* x 3.0) y)))
(if (<= t_0 -2000000000000.0)
t_0
(if (<= t_0 4e-57) (- z) (* (* x y) 3.0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2000000000000.0) {
tmp = t_0;
} else if (t_0 <= 4e-57) {
tmp = -z;
} else {
tmp = (x * y) * 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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-2000000000000.0d0)) then
tmp = t_0
else if (t_0 <= 4d-57) then
tmp = -z
else
tmp = (x * y) * 3.0d0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -2000000000000.0) {
tmp = t_0;
} else if (t_0 <= 4e-57) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -2000000000000.0: tmp = t_0 elif t_0 <= 4e-57: tmp = -z else: tmp = (x * y) * 3.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -2000000000000.0) tmp = t_0; elseif (t_0 <= 4e-57) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * 3.0); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (x * 3.0) * y;
tmp = 0.0;
if (t_0 <= -2000000000000.0)
tmp = t_0;
elseif (t_0 <= 4e-57)
tmp = -z;
else
tmp = (x * y) * 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_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2000000000000.0], t$95$0, If[LessEqual[t$95$0, 4e-57], (-z), N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-57}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -2e12Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites82.1%
Applied rewrites82.2%
if -2e12 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 3.99999999999999982e-57Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6487.7
Applied rewrites87.7%
if 3.99999999999999982e-57 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
Taylor expanded in x around inf
Applied rewrites76.4%
Final simplification83.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return ((x * 3.0) * 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 = ((x * 3.0d0) * y) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return ((x * 3.0) * y) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = ((x * 3.0) * y) - z;
end
NOTE: x, y, and z 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, z] = \mathsf{sort}([x, y, z])\\
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
Initial program 99.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.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6452.6
Applied rewrites52.6%
Final simplification52.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 2024324
(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))