
(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 8 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 (- 0.0 z)))
double code(double x, double y, double z) {
return fma((x * y), 3.0, (0.0 - z));
}
function code(x, y, z) return fma(Float64(x * y), 3.0, Float64(0.0 - z)) end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] * 3.0 + N[(0.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, 3, 0 - z\right)
\end{array}
Initial program 99.9%
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
neg-sub0N/A
--lowering--.f6499.9
Applied egg-rr99.9%
sub0-negN/A
neg-lowering-neg.f6499.9
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (* x 3.0))) (t_1 (* x (* y 3.0)))) (if (<= t_0 -2e+117) t_1 (if (<= t_0 4e+86) (- 0.0 z) t_1))))
double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double t_1 = x * (y * 3.0);
double tmp;
if (t_0 <= -2e+117) {
tmp = t_1;
} else if (t_0 <= 4e+86) {
tmp = 0.0 - z;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = y * (x * 3.0d0)
t_1 = x * (y * 3.0d0)
if (t_0 <= (-2d+117)) then
tmp = t_1
else if (t_0 <= 4d+86) then
tmp = 0.0d0 - z
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double t_1 = x * (y * 3.0);
double tmp;
if (t_0 <= -2e+117) {
tmp = t_1;
} else if (t_0 <= 4e+86) {
tmp = 0.0 - z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * 3.0) t_1 = x * (y * 3.0) tmp = 0 if t_0 <= -2e+117: tmp = t_1 elif t_0 <= 4e+86: tmp = 0.0 - z else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x * 3.0)) t_1 = Float64(x * Float64(y * 3.0)) tmp = 0.0 if (t_0 <= -2e+117) tmp = t_1; elseif (t_0 <= 4e+86) tmp = Float64(0.0 - z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x * 3.0); t_1 = x * (y * 3.0); tmp = 0.0; if (t_0 <= -2e+117) tmp = t_1; elseif (t_0 <= 4e+86) tmp = 0.0 - z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+117], t$95$1, If[LessEqual[t$95$0, 4e+86], N[(0.0 - z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot 3\right)\\
t_1 := x \cdot \left(y \cdot 3\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+117}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+86}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -2.0000000000000001e117 or 4.0000000000000001e86 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in x around inf
+-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
+-rgt-identityN/A
accelerator-lowering-fma.f6484.7
Simplified84.7%
+-rgt-identityN/A
+-rgt-identityN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6484.8
Applied egg-rr84.8%
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6484.7
Applied egg-rr84.7%
if -2.0000000000000001e117 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 4.0000000000000001e86Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6475.5
Simplified75.5%
sub0-negN/A
neg-lowering-neg.f6475.5
Applied egg-rr75.5%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (* x 3.0)))) (if (<= t_0 -2e+117) t_0 (if (<= t_0 4e+86) (- 0.0 z) (* (* x y) 3.0)))))
double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double tmp;
if (t_0 <= -2e+117) {
tmp = t_0;
} else if (t_0 <= 4e+86) {
tmp = 0.0 - 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 (t_0 <= (-2d+117)) then
tmp = t_0
else if (t_0 <= 4d+86) then
tmp = 0.0d0 - 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 (t_0 <= -2e+117) {
tmp = t_0;
} else if (t_0 <= 4e+86) {
tmp = 0.0 - z;
} else {
tmp = (x * y) * 3.0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * 3.0) tmp = 0 if t_0 <= -2e+117: tmp = t_0 elif t_0 <= 4e+86: tmp = 0.0 - 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 (t_0 <= -2e+117) tmp = t_0; elseif (t_0 <= 4e+86) tmp = Float64(0.0 - 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 (t_0 <= -2e+117) tmp = t_0; elseif (t_0 <= 4e+86) tmp = 0.0 - 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[t$95$0, -2e+117], t$95$0, If[LessEqual[t$95$0, 4e+86], N[(0.0 - z), $MachinePrecision], 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}\;t\_0 \leq -2 \cdot 10^{+117}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+86}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -2.0000000000000001e117Initial program 99.8%
Taylor expanded in x around inf
+-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
+-rgt-identityN/A
accelerator-lowering-fma.f6488.4
Simplified88.4%
+-rgt-identityN/A
+-rgt-identityN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6488.5
Applied egg-rr88.5%
if -2.0000000000000001e117 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 4.0000000000000001e86Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6475.5
Simplified75.5%
sub0-negN/A
neg-lowering-neg.f6475.5
Applied egg-rr75.5%
if 4.0000000000000001e86 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in x around inf
+-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
+-rgt-identityN/A
accelerator-lowering-fma.f6480.5
Simplified80.5%
+-rgt-identityN/A
+-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6480.5
Applied egg-rr80.5%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (* x 3.0)))) (if (<= t_0 -2.35e+113) t_0 (if (<= t_0 3.4e+86) (- 0.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x * 3.0);
double tmp;
if (t_0 <= -2.35e+113) {
tmp = t_0;
} else if (t_0 <= 3.4e+86) {
tmp = 0.0 - z;
} else {
tmp = t_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 (t_0 <= (-2.35d+113)) then
tmp = t_0
else if (t_0 <= 3.4d+86) then
tmp = 0.0d0 - z
else
tmp = t_0
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 (t_0 <= -2.35e+113) {
tmp = t_0;
} else if (t_0 <= 3.4e+86) {
tmp = 0.0 - z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * 3.0) tmp = 0 if t_0 <= -2.35e+113: tmp = t_0 elif t_0 <= 3.4e+86: tmp = 0.0 - z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x * 3.0)) tmp = 0.0 if (t_0 <= -2.35e+113) tmp = t_0; elseif (t_0 <= 3.4e+86) tmp = Float64(0.0 - z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x * 3.0); tmp = 0.0; if (t_0 <= -2.35e+113) tmp = t_0; elseif (t_0 <= 3.4e+86) tmp = 0.0 - z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2.35e+113], t$95$0, If[LessEqual[t$95$0, 3.4e+86], N[(0.0 - z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot 3\right)\\
\mathbf{if}\;t\_0 \leq -2.35 \cdot 10^{+113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 3.4 \cdot 10^{+86}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -2.3499999999999999e113 or 3.3999999999999998e86 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
Taylor expanded in x around inf
+-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
+-rgt-identityN/A
accelerator-lowering-fma.f6484.7
Simplified84.7%
+-rgt-identityN/A
+-rgt-identityN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6484.8
Applied egg-rr84.8%
if -2.3499999999999999e113 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 3.3999999999999998e86Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6475.5
Simplified75.5%
sub0-negN/A
neg-lowering-neg.f6475.5
Applied egg-rr75.5%
Final simplification78.9%
(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.9%
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8
Applied egg-rr99.8%
(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.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (- 0.0 z))
double code(double x, double y, double z) {
return 0.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 = 0.0d0 - z
end function
public static double code(double x, double y, double z) {
return 0.0 - z;
}
def code(x, y, z): return 0.0 - z
function code(x, y, z) return Float64(0.0 - z) end
function tmp = code(x, y, z) tmp = 0.0 - z; end
code[x_, y_, z_] := N[(0.0 - z), $MachinePrecision]
\begin{array}{l}
\\
0 - z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6453.9
Simplified53.9%
sub0-negN/A
neg-lowering-neg.f6453.9
Applied egg-rr53.9%
Final simplification53.9%
(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.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6453.9
Simplified53.9%
flip--N/A
+-lft-identityN/A
metadata-evalN/A
sub-divN/A
frac-subN/A
mul0-lftN/A
cube-multN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
sub0-negN/A
sub0-negN/A
pow-prod-downN/A
sqr-powN/A
sub0-negN/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
sub-divN/A
div0N/A
+-rgt-identityN/A
mul0-lftN/A
+-lft-identityN/A
Applied egg-rr2.0%
(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 2024198
(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))