
(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}
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 (<= y -9.5e-187) t_0 (if (<= y 1.45e+139) (- 0.0 z) t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = (x * 3.0) * y;
double tmp;
if (y <= -9.5e-187) {
tmp = t_0;
} else if (y <= 1.45e+139) {
tmp = 0.0 - z;
} else {
tmp = t_0;
}
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 (y <= (-9.5d-187)) then
tmp = t_0
else if (y <= 1.45d+139) then
tmp = 0.0d0 - z
else
tmp = t_0
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 (y <= -9.5e-187) {
tmp = t_0;
} else if (y <= 1.45e+139) {
tmp = 0.0 - z;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = (x * 3.0) * y tmp = 0 if y <= -9.5e-187: tmp = t_0 elif y <= 1.45e+139: tmp = 0.0 - z else: tmp = t_0 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 (y <= -9.5e-187) tmp = t_0; elseif (y <= 1.45e+139) tmp = Float64(0.0 - z); else tmp = t_0; 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 (y <= -9.5e-187)
tmp = t_0;
elseif (y <= 1.45e+139)
tmp = 0.0 - z;
else
tmp = t_0;
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[y, -9.5e-187], t$95$0, If[LessEqual[y, 1.45e+139], N[(0.0 - z), $MachinePrecision], t$95$0]]]
\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}\;y \leq -9.5 \cdot 10^{-187}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+139}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.49999999999999936e-187 or 1.4499999999999999e139 < 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-*.f6468.2%
Simplified68.2%
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6468.3%
Applied egg-rr68.3%
if -9.49999999999999936e-187 < y < 1.4499999999999999e139Initial 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--.f6469.5%
Simplified69.5%
sub0-negN/A
neg-lowering-neg.f6469.5%
Applied egg-rr69.5%
Final simplification68.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* 3.0 (* x y)))) (if (<= y -1.4e-177) t_0 (if (<= y 1.45e+139) (- 0.0 z) t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 3.0 * (x * y);
double tmp;
if (y <= -1.4e-177) {
tmp = t_0;
} else if (y <= 1.45e+139) {
tmp = 0.0 - z;
} else {
tmp = t_0;
}
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 = 3.0d0 * (x * y)
if (y <= (-1.4d-177)) then
tmp = t_0
else if (y <= 1.45d+139) then
tmp = 0.0d0 - z
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 3.0 * (x * y);
double tmp;
if (y <= -1.4e-177) {
tmp = t_0;
} else if (y <= 1.45e+139) {
tmp = 0.0 - z;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 3.0 * (x * y) tmp = 0 if y <= -1.4e-177: tmp = t_0 elif y <= 1.45e+139: tmp = 0.0 - z else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(3.0 * Float64(x * y)) tmp = 0.0 if (y <= -1.4e-177) tmp = t_0; elseif (y <= 1.45e+139) tmp = Float64(0.0 - z); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 3.0 * (x * y);
tmp = 0.0;
if (y <= -1.4e-177)
tmp = t_0;
elseif (y <= 1.45e+139)
tmp = 0.0 - z;
else
tmp = t_0;
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[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.4e-177], t$95$0, If[LessEqual[y, 1.45e+139], N[(0.0 - z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 3 \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -1.4 \cdot 10^{-177}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+139}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.39999999999999993e-177 or 1.4499999999999999e139 < 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-*.f6468.2%
Simplified68.2%
if -1.39999999999999993e-177 < y < 1.4499999999999999e139Initial 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--.f6469.5%
Simplified69.5%
sub0-negN/A
neg-lowering-neg.f6469.5%
Applied egg-rr69.5%
Final simplification68.8%
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--.f6450.3%
Simplified50.3%
sub0-negN/A
neg-lowering-neg.f6450.3%
Applied egg-rr50.3%
Final simplification50.3%
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--.f6450.3%
Simplified50.3%
flip3--N/A
div-invN/A
metadata-evalN/A
sub0-negN/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
distribute-lft-neg-inN/A
div-invN/A
flip3--N/A
sub0-negN/A
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 2024150
(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))