
(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 (- (* (* 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(Float64(x * 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[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(x \cdot 3\right) \cdot y - z
\end{array}
Initial program 99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y))) (if (<= t_0 -5e+21) t_0 (if (<= t_0 2e-78) (- 0.0 z) (* x (* 3.0 y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -5e+21) {
tmp = t_0;
} else if (t_0 <= 2e-78) {
tmp = 0.0 - z;
} else {
tmp = x * (3.0 * 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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-5d+21)) then
tmp = t_0
else if (t_0 <= 2d-78) then
tmp = 0.0d0 - z
else
tmp = x * (3.0d0 * y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -5e+21) {
tmp = t_0;
} else if (t_0 <= 2e-78) {
tmp = 0.0 - z;
} else {
tmp = x * (3.0 * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -5e+21: tmp = t_0 elif t_0 <= 2e-78: tmp = 0.0 - z else: tmp = x * (3.0 * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -5e+21) tmp = t_0; elseif (t_0 <= 2e-78) tmp = Float64(0.0 - z); else tmp = Float64(x * Float64(3.0 * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = (x * 3.0) * y;
tmp = 0.0;
if (t_0 <= -5e+21)
tmp = t_0;
elseif (t_0 <= 2e-78)
tmp = 0.0 - z;
else
tmp = x * (3.0 * 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_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+21], t$95$0, If[LessEqual[t$95$0, 2e-78], N[(0.0 - z), $MachinePrecision], N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+21}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-78}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -5e21Initial program 99.7%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7%
Simplified99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6480.6%
Simplified80.6%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6480.6%
Applied egg-rr80.6%
if -5e21 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 2e-78Initial program 99.9%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.9%
Simplified99.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6481.8%
Simplified81.8%
sub0-negN/A
neg-lowering-neg.f6481.8%
Applied egg-rr81.8%
if 2e-78 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.9%
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6477.2%
Simplified77.2%
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6477.3%
Applied egg-rr77.3%
Final simplification80.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x 3.0) y))) (if (<= t_0 -5e+21) t_0 (if (<= t_0 2e-78) (- 0.0 z) (* 3.0 (* x y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -5e+21) {
tmp = t_0;
} else if (t_0 <= 2e-78) {
tmp = 0.0 - 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) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * y
if (t_0 <= (-5d+21)) then
tmp = t_0
else if (t_0 <= 2d-78) then
tmp = 0.0d0 - 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 t_0 = (x * 3.0) * y;
double tmp;
if (t_0 <= -5e+21) {
tmp = t_0;
} else if (t_0 <= 2e-78) {
tmp = 0.0 - z;
} else {
tmp = 3.0 * (x * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if t_0 <= -5e+21: tmp = t_0 elif t_0 <= 2e-78: tmp = 0.0 - z else: tmp = 3.0 * (x * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x * 3.0) * y) tmp = 0.0 if (t_0 <= -5e+21) tmp = t_0; elseif (t_0 <= 2e-78) tmp = Float64(0.0 - 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)
t_0 = (x * 3.0) * y;
tmp = 0.0;
if (t_0 <= -5e+21)
tmp = t_0;
elseif (t_0 <= 2e-78)
tmp = 0.0 - 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_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+21], t$95$0, If[LessEqual[t$95$0, 2e-78], N[(0.0 - z), $MachinePrecision], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+21}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-78}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -5e21Initial program 99.7%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7%
Simplified99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6480.6%
Simplified80.6%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6480.6%
Applied egg-rr80.6%
if -5e21 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 2e-78Initial program 99.9%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.9%
Simplified99.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6481.8%
Simplified81.8%
sub0-negN/A
neg-lowering-neg.f6481.8%
Applied egg-rr81.8%
if 2e-78 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) Initial program 99.8%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.9%
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6477.2%
Simplified77.2%
Final simplification80.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -5.1e-18) (- 0.0 z) (if (<= z 1.9e+50) (* 3.0 (* x y)) (- 0.0 z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -5.1e-18) {
tmp = 0.0 - z;
} else if (z <= 1.9e+50) {
tmp = 3.0 * (x * y);
} else {
tmp = 0.0 - 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 (z <= (-5.1d-18)) then
tmp = 0.0d0 - z
else if (z <= 1.9d+50) then
tmp = 3.0d0 * (x * y)
else
tmp = 0.0d0 - 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 (z <= -5.1e-18) {
tmp = 0.0 - z;
} else if (z <= 1.9e+50) {
tmp = 3.0 * (x * y);
} else {
tmp = 0.0 - z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= -5.1e-18: tmp = 0.0 - z elif z <= 1.9e+50: tmp = 3.0 * (x * y) else: tmp = 0.0 - z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= -5.1e-18) tmp = Float64(0.0 - z); elseif (z <= 1.9e+50) tmp = Float64(3.0 * Float64(x * y)); else tmp = Float64(0.0 - z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -5.1e-18)
tmp = 0.0 - z;
elseif (z <= 1.9e+50)
tmp = 3.0 * (x * y);
else
tmp = 0.0 - 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[LessEqual[z, -5.1e-18], N[(0.0 - z), $MachinePrecision], If[LessEqual[z, 1.9e+50], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(0.0 - z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.1 \cdot 10^{-18}:\\
\;\;\;\;0 - z\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{+50}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;0 - z\\
\end{array}
\end{array}
if z < -5.09999999999999983e-18 or 1.89999999999999994e50 < z Initial program 100.0%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6477.0%
Simplified77.0%
sub0-negN/A
neg-lowering-neg.f6477.0%
Applied egg-rr77.0%
if -5.09999999999999983e-18 < z < 1.89999999999999994e50Initial program 99.7%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7%
Simplified99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6473.2%
Simplified73.2%
Final simplification75.1%
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%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8%
Simplified99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- 0.0 z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return 0.0 - 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 = 0.0d0 - z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return 0.0 - z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return 0.0 - z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(0.0 - z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = 0.0 - z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(0.0 - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
0 - z
\end{array}
Initial program 99.8%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8%
Simplified99.8%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6451.5%
Simplified51.5%
sub0-negN/A
neg-lowering-neg.f6451.5%
Applied egg-rr51.5%
Final simplification51.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%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8%
Simplified99.8%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6451.5%
Simplified51.5%
flip3--N/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
sub0-negN/A
sqr-powN/A
unpow-prod-downN/A
sub0-negN/A
sub0-negN/A
sqr-negN/A
unpow-prod-downN/A
sqr-powN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow12.3%
Applied egg-rr2.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 2024145
(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))