
(FPCore (x y z) :precision binary64 (- x (* (* y 4.0) z)))
double code(double x, double y, double z) {
return x - ((y * 4.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 * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return x - ((y * 4.0) * z);
}
def code(x, y, z): return x - ((y * 4.0) * z)
function code(x, y, z) return Float64(x - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = x - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(x - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(y \cdot 4\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- x (* (* y 4.0) z)))
double code(double x, double y, double z) {
return x - ((y * 4.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 * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return x - ((y * 4.0) * z);
}
def code(x, y, z): return x - ((y * 4.0) * z)
function code(x, y, z) return Float64(x - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = x - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(x - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(y \cdot 4\right) \cdot z
\end{array}
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- x (* (* y 4.0) z)))
assert(y < z);
double code(double x, double y, double z) {
return x - ((y * 4.0) * z);
}
NOTE: 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 - ((y * 4.0d0) * z)
end function
assert y < z;
public static double code(double x, double y, double z) {
return x - ((y * 4.0) * z);
}
[y, z] = sort([y, z]) def code(x, y, z): return x - ((y * 4.0) * z)
y, z = sort([y, z]) function code(x, y, z) return Float64(x - Float64(Float64(y * 4.0) * z)) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x - ((y * 4.0) * z);
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x - \left(y \cdot 4\right) \cdot z
\end{array}
Initial program 99.6%
Final simplification99.6%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -7e+74) (not (<= y 7.4e-65))) (* z (* y -4.0)) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -7e+74) || !(y <= 7.4e-65)) {
tmp = z * (y * -4.0);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 ((y <= (-7d+74)) .or. (.not. (y <= 7.4d-65))) then
tmp = z * (y * (-4.0d0))
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7e+74) || !(y <= 7.4e-65)) {
tmp = z * (y * -4.0);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -7e+74) or not (y <= 7.4e-65): tmp = z * (y * -4.0) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -7e+74) || !(y <= 7.4e-65)) tmp = Float64(z * Float64(y * -4.0)); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -7e+74) || ~((y <= 7.4e-65)))
tmp = z * (y * -4.0);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[y, -7e+74], N[Not[LessEqual[y, 7.4e-65]], $MachinePrecision]], N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+74} \lor \neg \left(y \leq 7.4 \cdot 10^{-65}\right):\\
\;\;\;\;z \cdot \left(y \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.00000000000000029e74 or 7.4e-65 < y Initial program 99.3%
Taylor expanded in x around 0 68.5%
associate-*r*67.8%
Simplified67.8%
if -7.00000000000000029e74 < y < 7.4e-65Initial program 100.0%
Taylor expanded in x around inf 71.0%
Final simplification69.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: 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
end function
assert y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 99.6%
Taylor expanded in x around inf 50.7%
Final simplification50.7%
herbie shell --seed 2023308
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A"
:precision binary64
(- x (* (* y 4.0) z)))