
(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 7 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 (* 3.0 y) x (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((3.0 * y), x, -z);
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(3.0 * y), x, Float64(-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 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
*-commutative99.8%
fma-neg99.8%
Simplified99.8%
Final simplification99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= y -2.3e-59)
(not (or (<= y 2.8e-69) (and (not (<= y 4.5e-48)) (<= y 2.4e-23)))))
(* 3.0 (* y x))
(- z)))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-59) || !((y <= 2.8e-69) || (!(y <= 4.5e-48) && (y <= 2.4e-23)))) {
tmp = 3.0 * (y * x);
} 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) :: tmp
if ((y <= (-2.3d-59)) .or. (.not. (y <= 2.8d-69) .or. (.not. (y <= 4.5d-48)) .and. (y <= 2.4d-23))) then
tmp = 3.0d0 * (y * x)
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 tmp;
if ((y <= -2.3e-59) || !((y <= 2.8e-69) || (!(y <= 4.5e-48) && (y <= 2.4e-23)))) {
tmp = 3.0 * (y * x);
} else {
tmp = -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -2.3e-59) or not ((y <= 2.8e-69) or (not (y <= 4.5e-48) and (y <= 2.4e-23))): tmp = 3.0 * (y * x) else: tmp = -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -2.3e-59) || !((y <= 2.8e-69) || (!(y <= 4.5e-48) && (y <= 2.4e-23)))) tmp = Float64(3.0 * Float64(y * x)); else tmp = Float64(-z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -2.3e-59) || ~(((y <= 2.8e-69) || (~((y <= 4.5e-48)) && (y <= 2.4e-23)))))
tmp = 3.0 * (y * x);
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_] := If[Or[LessEqual[y, -2.3e-59], N[Not[Or[LessEqual[y, 2.8e-69], And[N[Not[LessEqual[y, 4.5e-48]], $MachinePrecision], LessEqual[y, 2.4e-23]]]], $MachinePrecision]], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-59} \lor \neg \left(y \leq 2.8 \cdot 10^{-69} \lor \neg \left(y \leq 4.5 \cdot 10^{-48}\right) \land y \leq 2.4 \cdot 10^{-23}\right):\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -2.29999999999999979e-59 or 2.79999999999999979e-69 < y < 4.49999999999999988e-48 or 2.39999999999999996e-23 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
fma-define99.7%
mul-1-neg99.7%
fma-neg99.7%
Simplified99.7%
Taylor expanded in y around inf 72.2%
if -2.29999999999999979e-59 < y < 2.79999999999999979e-69 or 4.49999999999999988e-48 < y < 2.39999999999999996e-23Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 79.9%
mul-1-neg79.9%
Simplified79.9%
Final simplification75.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 3.0 (* y x))))
(if (<= y -2.7e-59)
t_0
(if (<= y 2.65e-69)
(- z)
(if (<= y 5.5e-48) t_0 (if (<= y 4.5e-23) (- z) (* (* 3.0 y) x)))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 3.0 * (y * x);
double tmp;
if (y <= -2.7e-59) {
tmp = t_0;
} else if (y <= 2.65e-69) {
tmp = -z;
} else if (y <= 5.5e-48) {
tmp = t_0;
} else if (y <= 4.5e-23) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
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 = 3.0d0 * (y * x)
if (y <= (-2.7d-59)) then
tmp = t_0
else if (y <= 2.65d-69) then
tmp = -z
else if (y <= 5.5d-48) then
tmp = t_0
else if (y <= 4.5d-23) then
tmp = -z
else
tmp = (3.0d0 * y) * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 3.0 * (y * x);
double tmp;
if (y <= -2.7e-59) {
tmp = t_0;
} else if (y <= 2.65e-69) {
tmp = -z;
} else if (y <= 5.5e-48) {
tmp = t_0;
} else if (y <= 4.5e-23) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 3.0 * (y * x) tmp = 0 if y <= -2.7e-59: tmp = t_0 elif y <= 2.65e-69: tmp = -z elif y <= 5.5e-48: tmp = t_0 elif y <= 4.5e-23: tmp = -z else: tmp = (3.0 * y) * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(3.0 * Float64(y * x)) tmp = 0.0 if (y <= -2.7e-59) tmp = t_0; elseif (y <= 2.65e-69) tmp = Float64(-z); elseif (y <= 5.5e-48) tmp = t_0; elseif (y <= 4.5e-23) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 3.0 * (y * x);
tmp = 0.0;
if (y <= -2.7e-59)
tmp = t_0;
elseif (y <= 2.65e-69)
tmp = -z;
elseif (y <= 5.5e-48)
tmp = t_0;
elseif (y <= 4.5e-23)
tmp = -z;
else
tmp = (3.0 * y) * x;
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[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.7e-59], t$95$0, If[LessEqual[y, 2.65e-69], (-z), If[LessEqual[y, 5.5e-48], t$95$0, If[LessEqual[y, 4.5e-23], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 3 \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -2.7 \cdot 10^{-59}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-69}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-23}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if y < -2.6999999999999999e-59 or 2.65e-69 < y < 5.50000000000000047e-48Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
fma-define99.7%
mul-1-neg99.7%
fma-neg99.7%
Simplified99.7%
Taylor expanded in y around inf 69.7%
if -2.6999999999999999e-59 < y < 2.65e-69 or 5.50000000000000047e-48 < y < 4.49999999999999975e-23Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 79.9%
mul-1-neg79.9%
Simplified79.9%
if 4.49999999999999975e-23 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
fma-define99.7%
mul-1-neg99.7%
fma-neg99.7%
Simplified99.7%
Taylor expanded in y around inf 75.3%
associate-*r*75.3%
*-commutative75.3%
associate-*r*75.3%
Simplified75.3%
Final simplification75.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -6.5e-58)
(* y (* 3.0 x))
(if (<= y 2.2e-69)
(- z)
(if (<= y 5e-48)
(* 3.0 (* y x))
(if (<= y 4.4e-23) (- z) (* (* 3.0 y) x))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e-58) {
tmp = y * (3.0 * x);
} else if (y <= 2.2e-69) {
tmp = -z;
} else if (y <= 5e-48) {
tmp = 3.0 * (y * x);
} else if (y <= 4.4e-23) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
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) :: tmp
if (y <= (-6.5d-58)) then
tmp = y * (3.0d0 * x)
else if (y <= 2.2d-69) then
tmp = -z
else if (y <= 5d-48) then
tmp = 3.0d0 * (y * x)
else if (y <= 4.4d-23) then
tmp = -z
else
tmp = (3.0d0 * y) * x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e-58) {
tmp = y * (3.0 * x);
} else if (y <= 2.2e-69) {
tmp = -z;
} else if (y <= 5e-48) {
tmp = 3.0 * (y * x);
} else if (y <= 4.4e-23) {
tmp = -z;
} else {
tmp = (3.0 * y) * x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -6.5e-58: tmp = y * (3.0 * x) elif y <= 2.2e-69: tmp = -z elif y <= 5e-48: tmp = 3.0 * (y * x) elif y <= 4.4e-23: tmp = -z else: tmp = (3.0 * y) * x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -6.5e-58) tmp = Float64(y * Float64(3.0 * x)); elseif (y <= 2.2e-69) tmp = Float64(-z); elseif (y <= 5e-48) tmp = Float64(3.0 * Float64(y * x)); elseif (y <= 4.4e-23) tmp = Float64(-z); else tmp = Float64(Float64(3.0 * y) * x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -6.5e-58)
tmp = y * (3.0 * x);
elseif (y <= 2.2e-69)
tmp = -z;
elseif (y <= 5e-48)
tmp = 3.0 * (y * x);
elseif (y <= 4.4e-23)
tmp = -z;
else
tmp = (3.0 * y) * x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -6.5e-58], N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.2e-69], (-z), If[LessEqual[y, 5e-48], N[(3.0 * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.4e-23], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-58}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-69}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-48}:\\
\;\;\;\;3 \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{-23}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\
\end{array}
\end{array}
if y < -6.49999999999999964e-58Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
fma-define99.7%
mul-1-neg99.7%
fma-neg99.8%
Simplified99.8%
Taylor expanded in y around inf 69.4%
associate-*r*69.5%
Simplified69.5%
if -6.49999999999999964e-58 < y < 2.2e-69 or 4.9999999999999999e-48 < y < 4.3999999999999999e-23Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 79.9%
mul-1-neg79.9%
Simplified79.9%
if 2.2e-69 < y < 4.9999999999999999e-48Initial program 99.2%
associate-*l*99.2%
Simplified99.2%
Taylor expanded in y around inf 99.2%
+-commutative99.2%
fma-define99.2%
mul-1-neg99.2%
fma-neg99.2%
Simplified99.2%
Taylor expanded in y around inf 75.7%
if 4.3999999999999999e-23 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
fma-define99.7%
mul-1-neg99.7%
fma-neg99.7%
Simplified99.7%
Taylor expanded in y around inf 75.3%
associate-*r*75.3%
*-commutative75.3%
associate-*r*75.3%
Simplified75.3%
Final simplification75.6%
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.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.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%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 50.5%
mul-1-neg50.5%
Simplified50.5%
Final simplification50.5%
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 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%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*r*99.8%
fma-neg99.8%
add-sqr-sqrt51.6%
sqrt-unprod61.2%
sqr-neg61.2%
sqrt-unprod24.2%
add-sqr-sqrt49.1%
Applied egg-rr49.1%
Taylor expanded in y around 0 2.3%
Final simplification2.3%
(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 2024058
(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))