
(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 (- (* 3.0 (* x y)) z))
double code(double x, double y, double z) {
return (3.0 * (x * 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 = (3.0d0 * (x * y)) - z
end function
public static double code(double x, double y, double z) {
return (3.0 * (x * y)) - z;
}
def code(x, y, z): return (3.0 * (x * y)) - z
function code(x, y, z) return Float64(Float64(3.0 * Float64(x * y)) - z) end
function tmp = code(x, y, z) tmp = (3.0 * (x * y)) - z; end
code[x_, y_, z_] := N[(N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(x \cdot y\right) - z
\end{array}
Initial program 99.5%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 99.7%
Final simplification99.7%
(FPCore (x y z)
:precision binary64
(if (or (<= z -4.3e+91)
(and (not (<= z -0.78))
(or (<= z -5e-71) (not (<= z 880000000000.0)))))
(- z)
(* 3.0 (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.3e+91) || (!(z <= -0.78) && ((z <= -5e-71) || !(z <= 880000000000.0)))) {
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) :: tmp
if ((z <= (-4.3d+91)) .or. (.not. (z <= (-0.78d0))) .and. (z <= (-5d-71)) .or. (.not. (z <= 880000000000.0d0))) 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 tmp;
if ((z <= -4.3e+91) || (!(z <= -0.78) && ((z <= -5e-71) || !(z <= 880000000000.0)))) {
tmp = -z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.3e+91) or (not (z <= -0.78) and ((z <= -5e-71) or not (z <= 880000000000.0))): tmp = -z else: tmp = 3.0 * (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.3e+91) || (!(z <= -0.78) && ((z <= -5e-71) || !(z <= 880000000000.0)))) tmp = Float64(-z); else tmp = Float64(3.0 * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.3e+91) || (~((z <= -0.78)) && ((z <= -5e-71) || ~((z <= 880000000000.0))))) tmp = -z; else tmp = 3.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.3e+91], And[N[Not[LessEqual[z, -0.78]], $MachinePrecision], Or[LessEqual[z, -5e-71], N[Not[LessEqual[z, 880000000000.0]], $MachinePrecision]]]], (-z), N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3 \cdot 10^{+91} \lor \neg \left(z \leq -0.78\right) \land \left(z \leq -5 \cdot 10^{-71} \lor \neg \left(z \leq 880000000000\right)\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -4.3000000000000001e91 or -0.78000000000000003 < z < -4.99999999999999998e-71 or 8.8e11 < z Initial program 99.2%
associate-*l*99.1%
Simplified99.1%
Taylor expanded in x around 0 75.1%
mul-1-neg75.1%
Simplified75.1%
if -4.3000000000000001e91 < z < -0.78000000000000003 or -4.99999999999999998e-71 < z < 8.8e11Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 78.5%
Final simplification77.0%
(FPCore (x y z)
:precision binary64
(if (or (<= z -6e+91)
(not
(or (<= z -0.00365)
(and (not (<= z -2.7e-71)) (<= z 4300000000000.0)))))
(- z)
(* y (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+91) || !((z <= -0.00365) || (!(z <= -2.7e-71) && (z <= 4300000000000.0)))) {
tmp = -z;
} else {
tmp = y * (3.0 * x);
}
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) :: tmp
if ((z <= (-6d+91)) .or. (.not. (z <= (-0.00365d0)) .or. (.not. (z <= (-2.7d-71))) .and. (z <= 4300000000000.0d0))) then
tmp = -z
else
tmp = y * (3.0d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+91) || !((z <= -0.00365) || (!(z <= -2.7e-71) && (z <= 4300000000000.0)))) {
tmp = -z;
} else {
tmp = y * (3.0 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6e+91) or not ((z <= -0.00365) or (not (z <= -2.7e-71) and (z <= 4300000000000.0))): tmp = -z else: tmp = y * (3.0 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6e+91) || !((z <= -0.00365) || (!(z <= -2.7e-71) && (z <= 4300000000000.0)))) tmp = Float64(-z); else tmp = Float64(y * Float64(3.0 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6e+91) || ~(((z <= -0.00365) || (~((z <= -2.7e-71)) && (z <= 4300000000000.0))))) tmp = -z; else tmp = y * (3.0 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e+91], N[Not[Or[LessEqual[z, -0.00365], And[N[Not[LessEqual[z, -2.7e-71]], $MachinePrecision], LessEqual[z, 4300000000000.0]]]], $MachinePrecision]], (-z), N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+91} \lor \neg \left(z \leq -0.00365 \lor \neg \left(z \leq -2.7 \cdot 10^{-71}\right) \land z \leq 4300000000000\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\end{array}
\end{array}
if z < -6.00000000000000012e91 or -0.00365000000000000003 < z < -2.7000000000000001e-71 or 4.3e12 < z Initial program 99.2%
associate-*l*99.1%
Simplified99.1%
Taylor expanded in x around 0 75.1%
mul-1-neg75.1%
Simplified75.1%
if -6.00000000000000012e91 < z < -0.00365000000000000003 or -2.7000000000000001e-71 < z < 4.3e12Initial program 99.7%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in y around inf 99.0%
+-commutative99.0%
fma-define99.0%
mul-1-neg99.0%
fma-neg99.0%
Simplified99.0%
Taylor expanded in x around inf 78.6%
Final simplification77.0%
(FPCore (x y z)
:precision binary64
(if (<= z -2.45e+91)
(- z)
(if (<= z -0.34)
(* y (* 3.0 x))
(if (or (<= z -3.1e-71) (not (<= z 650000000000.0)))
(- z)
(* x (* 3.0 y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.45e+91) {
tmp = -z;
} else if (z <= -0.34) {
tmp = y * (3.0 * x);
} else if ((z <= -3.1e-71) || !(z <= 650000000000.0)) {
tmp = -z;
} else {
tmp = x * (3.0 * 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) :: tmp
if (z <= (-2.45d+91)) then
tmp = -z
else if (z <= (-0.34d0)) then
tmp = y * (3.0d0 * x)
else if ((z <= (-3.1d-71)) .or. (.not. (z <= 650000000000.0d0))) then
tmp = -z
else
tmp = x * (3.0d0 * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.45e+91) {
tmp = -z;
} else if (z <= -0.34) {
tmp = y * (3.0 * x);
} else if ((z <= -3.1e-71) || !(z <= 650000000000.0)) {
tmp = -z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.45e+91: tmp = -z elif z <= -0.34: tmp = y * (3.0 * x) elif (z <= -3.1e-71) or not (z <= 650000000000.0): tmp = -z else: tmp = x * (3.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.45e+91) tmp = Float64(-z); elseif (z <= -0.34) tmp = Float64(y * Float64(3.0 * x)); elseif ((z <= -3.1e-71) || !(z <= 650000000000.0)) tmp = Float64(-z); else tmp = Float64(x * Float64(3.0 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.45e+91) tmp = -z; elseif (z <= -0.34) tmp = y * (3.0 * x); elseif ((z <= -3.1e-71) || ~((z <= 650000000000.0))) tmp = -z; else tmp = x * (3.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.45e+91], (-z), If[LessEqual[z, -0.34], N[(y * N[(3.0 * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -3.1e-71], N[Not[LessEqual[z, 650000000000.0]], $MachinePrecision]], (-z), N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.45 \cdot 10^{+91}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -0.34:\\
\;\;\;\;y \cdot \left(3 \cdot x\right)\\
\mathbf{elif}\;z \leq -3.1 \cdot 10^{-71} \lor \neg \left(z \leq 650000000000\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if z < -2.45000000000000015e91 or -0.340000000000000024 < z < -3.10000000000000002e-71 or 6.5e11 < z Initial program 99.2%
associate-*l*99.1%
Simplified99.1%
Taylor expanded in x around 0 75.1%
mul-1-neg75.1%
Simplified75.1%
if -2.45000000000000015e91 < z < -0.340000000000000024Initial program 99.7%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around inf 94.0%
+-commutative94.0%
fma-define94.0%
mul-1-neg94.0%
fma-neg94.0%
Simplified94.0%
Taylor expanded in x around inf 93.8%
if -3.10000000000000002e-71 < z < 6.5e11Initial program 99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 76.4%
*-commutative76.4%
associate-*r*76.6%
Simplified76.6%
Final simplification77.0%
(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.5%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in x around 0 45.8%
mul-1-neg45.8%
Simplified45.8%
Final simplification45.8%
(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 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.5%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in y around inf 87.1%
+-commutative87.1%
fma-define87.1%
mul-1-neg87.1%
fma-neg87.1%
Simplified87.1%
Taylor expanded in x around 0 33.5%
mul-1-neg33.5%
distribute-neg-frac233.5%
Simplified33.5%
clear-num33.4%
un-div-inv33.8%
add-sqr-sqrt15.6%
sqrt-unprod11.2%
sqr-neg11.2%
sqrt-unprod1.1%
add-sqr-sqrt2.4%
Applied egg-rr2.4%
associate-/r/2.5%
*-inverses2.5%
*-lft-identity2.5%
Simplified2.5%
Final simplification2.5%
(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 2024059
(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))