
(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 5 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.9%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.5%
Simplified99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -4.2e+78) (- 0.0 z) (if (<= z 27.0) (* x (* 3.0 y)) (- 0.0 z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e+78) {
tmp = 0.0 - z;
} else if (z <= 27.0) {
tmp = x * (3.0 * 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 <= (-4.2d+78)) then
tmp = 0.0d0 - z
else if (z <= 27.0d0) then
tmp = x * (3.0d0 * 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 <= -4.2e+78) {
tmp = 0.0 - z;
} else if (z <= 27.0) {
tmp = x * (3.0 * y);
} else {
tmp = 0.0 - z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= -4.2e+78: tmp = 0.0 - z elif z <= 27.0: tmp = x * (3.0 * 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 <= -4.2e+78) tmp = Float64(0.0 - z); elseif (z <= 27.0) tmp = Float64(x * Float64(3.0 * 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 <= -4.2e+78)
tmp = 0.0 - z;
elseif (z <= 27.0)
tmp = x * (3.0 * 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, -4.2e+78], N[(0.0 - z), $MachinePrecision], If[LessEqual[z, 27.0], N[(x * N[(3.0 * 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 -4.2 \cdot 10^{+78}:\\
\;\;\;\;0 - z\\
\mathbf{elif}\;z \leq 27:\\
\;\;\;\;x \cdot \left(3 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;0 - z\\
\end{array}
\end{array}
if z < -4.2000000000000002e78 or 27 < 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--.f6478.0%
Simplified78.0%
sub0-negN/A
neg-lowering-neg.f6478.0%
Applied egg-rr78.0%
if -4.2000000000000002e78 < z < 27Initial program 99.8%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.1%
Simplified99.1%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6476.6%
Simplified76.6%
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6476.0%
Applied egg-rr76.0%
Final simplification76.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -5.3e+78) (- 0.0 z) (if (<= z 0.42) (* 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.3e+78) {
tmp = 0.0 - z;
} else if (z <= 0.42) {
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.3d+78)) then
tmp = 0.0d0 - z
else if (z <= 0.42d0) 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.3e+78) {
tmp = 0.0 - z;
} else if (z <= 0.42) {
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.3e+78: tmp = 0.0 - z elif z <= 0.42: 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.3e+78) tmp = Float64(0.0 - z); elseif (z <= 0.42) 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.3e+78)
tmp = 0.0 - z;
elseif (z <= 0.42)
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.3e+78], N[(0.0 - z), $MachinePrecision], If[LessEqual[z, 0.42], 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.3 \cdot 10^{+78}:\\
\;\;\;\;0 - z\\
\mathbf{elif}\;z \leq 0.42:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;0 - z\\
\end{array}
\end{array}
if z < -5.29999999999999961e78 or 0.419999999999999984 < 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--.f6478.0%
Simplified78.0%
sub0-negN/A
neg-lowering-neg.f6478.0%
Applied egg-rr78.0%
if -5.29999999999999961e78 < z < 0.419999999999999984Initial program 99.8%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.1%
Simplified99.1%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6476.6%
Simplified76.6%
Final simplification77.3%
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.9%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.5%
Simplified99.5%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6449.4%
Simplified49.4%
sub0-negN/A
neg-lowering-neg.f6449.4%
Applied egg-rr49.4%
Final simplification49.4%
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.9%
--lowering--.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.5%
Simplified99.5%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6449.4%
Simplified49.4%
flip3--N/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
metadata-evalN/A
+-lft-identityN/A
mul0-lftN/A
+-rgt-identityN/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 2024158
(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))