
(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 (- (* 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(x * Float64(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[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Initial program 99.8%
associate-*l*99.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 (<= z -1.6e+101)
(and (not (<= z -4e-63)) (or (<= z -3.7e-101) (not (<= z 7.6e-40)))))
(- z)
(* 3.0 (* x y))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.6e+101) || (!(z <= -4e-63) && ((z <= -3.7e-101) || !(z <= 7.6e-40)))) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 ((z <= (-1.6d+101)) .or. (.not. (z <= (-4d-63))) .and. (z <= (-3.7d-101)) .or. (.not. (z <= 7.6d-40))) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.6e+101) || (!(z <= -4e-63) && ((z <= -3.7e-101) || !(z <= 7.6e-40)))) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.6e+101) or (not (z <= -4e-63) and ((z <= -3.7e-101) or not (z <= 7.6e-40))): tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.6e+101) || (!(z <= -4e-63) && ((z <= -3.7e-101) || !(z <= 7.6e-40)))) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.6e+101) || (~((z <= -4e-63)) && ((z <= -3.7e-101) || ~((z <= 7.6e-40)))))
tmp = -z;
else
tmp = 3.0 * (x * y);
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[z, -1.6e+101], And[N[Not[LessEqual[z, -4e-63]], $MachinePrecision], Or[LessEqual[z, -3.7e-101], N[Not[LessEqual[z, 7.6e-40]], $MachinePrecision]]]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{+101} \lor \neg \left(z \leq -4 \cdot 10^{-63}\right) \land \left(z \leq -3.7 \cdot 10^{-101} \lor \neg \left(z \leq 7.6 \cdot 10^{-40}\right)\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.60000000000000003e101 or -4.00000000000000027e-63 < z < -3.70000000000000005e-101 or 7.5999999999999998e-40 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 79.6%
neg-mul-179.6%
Simplified79.6%
if -1.60000000000000003e101 < z < -4.00000000000000027e-63 or -3.70000000000000005e-101 < z < 7.5999999999999998e-40Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in z around inf 84.5%
Taylor expanded in z around 0 79.2%
Final simplification79.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= z -1.18e+101)
(- z)
(if (<= z -3.7e-63)
(* x (* 3.0 y))
(if (or (<= z -4.8e-101) (not (<= z 5.6e-41))) (- z) (* 3.0 (* x y))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -1.18e+101) {
tmp = -z;
} else if (z <= -3.7e-63) {
tmp = x * (3.0 * y);
} else if ((z <= -4.8e-101) || !(z <= 5.6e-41)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 (z <= (-1.18d+101)) then
tmp = -z
else if (z <= (-3.7d-63)) then
tmp = x * (3.0d0 * y)
else if ((z <= (-4.8d-101)) .or. (.not. (z <= 5.6d-41))) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.18e+101) {
tmp = -z;
} else if (z <= -3.7e-63) {
tmp = x * (3.0 * y);
} else if ((z <= -4.8e-101) || !(z <= 5.6e-41)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= -1.18e+101: tmp = -z elif z <= -3.7e-63: tmp = x * (3.0 * y) elif (z <= -4.8e-101) or not (z <= 5.6e-41): tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= -1.18e+101) tmp = Float64(-z); elseif (z <= -3.7e-63) tmp = Float64(x * Float64(3.0 * y)); elseif ((z <= -4.8e-101) || !(z <= 5.6e-41)) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -1.18e+101)
tmp = -z;
elseif (z <= -3.7e-63)
tmp = x * (3.0 * y);
elseif ((z <= -4.8e-101) || ~((z <= 5.6e-41)))
tmp = -z;
else
tmp = 3.0 * (x * y);
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[z, -1.18e+101], (-z), If[LessEqual[z, -3.7e-63], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -4.8e-101], N[Not[LessEqual[z, 5.6e-41]], $MachinePrecision]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.18 \cdot 10^{+101}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -3.7 \cdot 10^{-63}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{-101} \lor \neg \left(z \leq 5.6 \cdot 10^{-41}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.18000000000000005e101 or -3.70000000000000012e-63 < z < -4.8e-101 or 5.6000000000000003e-41 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 79.6%
neg-mul-179.6%
Simplified79.6%
if -1.18000000000000005e101 < z < -3.70000000000000012e-63Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 99.6%
Taylor expanded in z around 0 66.3%
associate-*r*66.5%
*-commutative66.5%
Simplified66.5%
Taylor expanded in y around 0 66.3%
associate-*r*66.5%
*-commutative66.5%
associate-*r*66.3%
Simplified66.3%
if -4.8e-101 < z < 5.6000000000000003e-41Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in z around inf 80.6%
Taylor expanded in z around 0 82.6%
Final simplification79.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= z -1.28e+101)
(- z)
(if (<= z -3.9e-63)
(* y (* x 3.0))
(if (or (<= z -3.7e-101) (not (<= z 1.2e-40))) (- z) (* 3.0 (* x y))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -1.28e+101) {
tmp = -z;
} else if (z <= -3.9e-63) {
tmp = y * (x * 3.0);
} else if ((z <= -3.7e-101) || !(z <= 1.2e-40)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
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 (z <= (-1.28d+101)) then
tmp = -z
else if (z <= (-3.9d-63)) then
tmp = y * (x * 3.0d0)
else if ((z <= (-3.7d-101)) .or. (.not. (z <= 1.2d-40))) then
tmp = -z
else
tmp = 3.0d0 * (x * y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.28e+101) {
tmp = -z;
} else if (z <= -3.9e-63) {
tmp = y * (x * 3.0);
} else if ((z <= -3.7e-101) || !(z <= 1.2e-40)) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= -1.28e+101: tmp = -z elif z <= -3.9e-63: tmp = y * (x * 3.0) elif (z <= -3.7e-101) or not (z <= 1.2e-40): tmp = -z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= -1.28e+101) tmp = Float64(-z); elseif (z <= -3.9e-63) tmp = Float64(y * Float64(x * 3.0)); elseif ((z <= -3.7e-101) || !(z <= 1.2e-40)) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -1.28e+101)
tmp = -z;
elseif (z <= -3.9e-63)
tmp = y * (x * 3.0);
elseif ((z <= -3.7e-101) || ~((z <= 1.2e-40)))
tmp = -z;
else
tmp = 3.0 * (x * y);
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[z, -1.28e+101], (-z), If[LessEqual[z, -3.9e-63], N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -3.7e-101], N[Not[LessEqual[z, 1.2e-40]], $MachinePrecision]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.28 \cdot 10^{+101}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -3.9 \cdot 10^{-63}:\\
\;\;\;\;y \cdot \left(x \cdot 3\right)\\
\mathbf{elif}\;z \leq -3.7 \cdot 10^{-101} \lor \neg \left(z \leq 1.2 \cdot 10^{-40}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.28e101 or -3.90000000000000022e-63 < z < -3.70000000000000005e-101 or 1.19999999999999996e-40 < z Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 79.6%
neg-mul-179.6%
Simplified79.6%
if -1.28e101 < z < -3.90000000000000022e-63Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in z around inf 99.6%
Taylor expanded in z around 0 66.3%
associate-*r*66.5%
*-commutative66.5%
Simplified66.5%
if -3.70000000000000005e-101 < z < 1.19999999999999996e-40Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in z around inf 80.6%
Taylor expanded in z around 0 82.6%
Final simplification79.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* 3.0 (* x y)) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (3.0 * (x * 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 = (3.0d0 * (x * y)) - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (3.0 * (x * y)) - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (3.0 * (x * y)) - 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[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
3 \cdot \left(x \cdot y\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.6%
neg-mul-150.6%
Simplified50.6%
Final simplification50.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 2024081
(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))