
(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}
(FPCore (x y z) :precision binary64 (fma (* x y) 3.0 (- z)))
double code(double x, double y, double z) {
return fma((x * y), 3.0, -z);
}
function code(x, y, z) return fma(Float64(x * y), 3.0, Float64(-z)) end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] * 3.0 + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, 3, -z\right)
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
*-commutative99.9%
fma-neg99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -2.15e-172)
(and (not (<= y 7.5e+49))
(or (<= y 9.8e+103) (not (<= y 1.65e+131)))))
(* (* x y) 3.0)
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.15e-172) || (!(y <= 7.5e+49) && ((y <= 9.8e+103) || !(y <= 1.65e+131)))) {
tmp = (x * y) * 3.0;
} 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) :: tmp
if ((y <= (-2.15d-172)) .or. (.not. (y <= 7.5d+49)) .and. (y <= 9.8d+103) .or. (.not. (y <= 1.65d+131))) then
tmp = (x * y) * 3.0d0
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.15e-172) || (!(y <= 7.5e+49) && ((y <= 9.8e+103) || !(y <= 1.65e+131)))) {
tmp = (x * y) * 3.0;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.15e-172) or (not (y <= 7.5e+49) and ((y <= 9.8e+103) or not (y <= 1.65e+131))): tmp = (x * y) * 3.0 else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.15e-172) || (!(y <= 7.5e+49) && ((y <= 9.8e+103) || !(y <= 1.65e+131)))) tmp = Float64(Float64(x * y) * 3.0); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.15e-172) || (~((y <= 7.5e+49)) && ((y <= 9.8e+103) || ~((y <= 1.65e+131))))) tmp = (x * y) * 3.0; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.15e-172], And[N[Not[LessEqual[y, 7.5e+49]], $MachinePrecision], Or[LessEqual[y, 9.8e+103], N[Not[LessEqual[y, 1.65e+131]], $MachinePrecision]]]], N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{-172} \lor \neg \left(y \leq 7.5 \cdot 10^{+49}\right) \land \left(y \leq 9.8 \cdot 10^{+103} \lor \neg \left(y \leq 1.65 \cdot 10^{+131}\right)\right):\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -2.1499999999999999e-172 or 7.4999999999999995e49 < y < 9.7999999999999997e103 or 1.6499999999999999e131 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 70.5%
if -2.1499999999999999e-172 < y < 7.4999999999999995e49 or 9.7999999999999997e103 < y < 1.6499999999999999e131Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 75.1%
mul-1-neg75.1%
Simplified75.1%
Final simplification72.6%
(FPCore (x y z)
:precision binary64
(if (<= y -5.4e-176)
(* x (* y 3.0))
(if (or (<= y 2.3e+46) (and (not (<= y 8.5e+103)) (<= y 1.5e+131)))
(- z)
(* (* x y) 3.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e-176) {
tmp = x * (y * 3.0);
} else if ((y <= 2.3e+46) || (!(y <= 8.5e+103) && (y <= 1.5e+131))) {
tmp = -z;
} else {
tmp = (x * y) * 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) :: tmp
if (y <= (-5.4d-176)) then
tmp = x * (y * 3.0d0)
else if ((y <= 2.3d+46) .or. (.not. (y <= 8.5d+103)) .and. (y <= 1.5d+131)) then
tmp = -z
else
tmp = (x * y) * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e-176) {
tmp = x * (y * 3.0);
} else if ((y <= 2.3e+46) || (!(y <= 8.5e+103) && (y <= 1.5e+131))) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.4e-176: tmp = x * (y * 3.0) elif (y <= 2.3e+46) or (not (y <= 8.5e+103) and (y <= 1.5e+131)): tmp = -z else: tmp = (x * y) * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.4e-176) tmp = Float64(x * Float64(y * 3.0)); elseif ((y <= 2.3e+46) || (!(y <= 8.5e+103) && (y <= 1.5e+131))) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.4e-176) tmp = x * (y * 3.0); elseif ((y <= 2.3e+46) || (~((y <= 8.5e+103)) && (y <= 1.5e+131))) tmp = -z; else tmp = (x * y) * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.4e-176], N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 2.3e+46], And[N[Not[LessEqual[y, 8.5e+103]], $MachinePrecision], LessEqual[y, 1.5e+131]]], (-z), N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-176}:\\
\;\;\;\;x \cdot \left(y \cdot 3\right)\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+46} \lor \neg \left(y \leq 8.5 \cdot 10^{+103}\right) \land y \leq 1.5 \cdot 10^{+131}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if y < -5.3999999999999997e-176Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 64.7%
*-commutative64.7%
associate-*l*64.7%
*-commutative64.7%
Simplified64.7%
if -5.3999999999999997e-176 < y < 2.3000000000000001e46 or 8.4999999999999992e103 < y < 1.5000000000000001e131Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
if 2.3000000000000001e46 < y < 8.4999999999999992e103 or 1.5000000000000001e131 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 81.6%
Final simplification72.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* x 3.0))))
(if (<= y -5.4e-176)
t_0
(if (<= y 2.8e+43)
(- z)
(if (<= y 3.4e+100) t_0 (if (<= y 1.36e+131) (- z) (* (* x y) 3.0)))))))
double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double tmp;
if (y <= -5.4e-176) {
tmp = t_0;
} else if (y <= 2.8e+43) {
tmp = -z;
} else if (y <= 3.4e+100) {
tmp = t_0;
} else if (y <= 1.36e+131) {
tmp = -z;
} else {
tmp = (x * y) * 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 = y * (x * 3.0d0)
if (y <= (-5.4d-176)) then
tmp = t_0
else if (y <= 2.8d+43) then
tmp = -z
else if (y <= 3.4d+100) then
tmp = t_0
else if (y <= 1.36d+131) then
tmp = -z
else
tmp = (x * y) * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double tmp;
if (y <= -5.4e-176) {
tmp = t_0;
} else if (y <= 2.8e+43) {
tmp = -z;
} else if (y <= 3.4e+100) {
tmp = t_0;
} else if (y <= 1.36e+131) {
tmp = -z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * 3.0) tmp = 0 if y <= -5.4e-176: tmp = t_0 elif y <= 2.8e+43: tmp = -z elif y <= 3.4e+100: tmp = t_0 elif y <= 1.36e+131: tmp = -z else: tmp = (x * y) * 3.0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x * 3.0)) tmp = 0.0 if (y <= -5.4e-176) tmp = t_0; elseif (y <= 2.8e+43) tmp = Float64(-z); elseif (y <= 3.4e+100) tmp = t_0; elseif (y <= 1.36e+131) tmp = Float64(-z); else tmp = Float64(Float64(x * y) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x * 3.0); tmp = 0.0; if (y <= -5.4e-176) tmp = t_0; elseif (y <= 2.8e+43) tmp = -z; elseif (y <= 3.4e+100) tmp = t_0; elseif (y <= 1.36e+131) tmp = -z; else tmp = (x * y) * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.4e-176], t$95$0, If[LessEqual[y, 2.8e+43], (-z), If[LessEqual[y, 3.4e+100], t$95$0, If[LessEqual[y, 1.36e+131], (-z), N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot 3\right)\\
\mathbf{if}\;y \leq -5.4 \cdot 10^{-176}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+43}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+100}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.36 \cdot 10^{+131}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if y < -5.3999999999999997e-176 or 2.80000000000000019e43 < y < 3.39999999999999994e100Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 65.7%
*-commutative65.7%
associate-*l*65.7%
*-commutative65.7%
Simplified65.7%
Taylor expanded in x around 0 65.7%
associate-*r*65.7%
Simplified65.7%
if -5.3999999999999997e-176 < y < 2.80000000000000019e43 or 3.39999999999999994e100 < y < 1.36e131Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
if 1.36e131 < y Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 84.9%
Final simplification72.2%
(FPCore (x y z) :precision binary64 (- (* (* x y) 3.0) z))
double code(double x, double y, double z) {
return ((x * y) * 3.0) - 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 * y) * 3.0d0) - z
end function
public static double code(double x, double y, double z) {
return ((x * y) * 3.0) - z;
}
def code(x, y, z): return ((x * y) * 3.0) - z
function code(x, y, z) return Float64(Float64(Float64(x * y) * 3.0) - z) end
function tmp = code(x, y, z) tmp = ((x * y) * 3.0) - z; end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y\right) \cdot 3 - z
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (- (* y (* x 3.0)) z))
double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y * (x * 3.0d0)) - z
end function
public static double code(double x, double y, double z) {
return (y * (x * 3.0)) - z;
}
def code(x, y, z): return (y * (x * 3.0)) - z
function code(x, y, z) return Float64(Float64(y * Float64(x * 3.0)) - z) end
function tmp = code(x, y, z) tmp = (y * (x * 3.0)) - z; end
code[x_, y_, z_] := N[(N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot 3\right) - z
\end{array}
Initial program 99.8%
Final simplification99.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 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%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 50.7%
mul-1-neg50.7%
Simplified50.7%
Final simplification50.7%
(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 2024096
(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))