
(FPCore (x y z) :precision binary64 (- (* x x) (* (* y 4.0) z)))
double code(double x, double y, double z) {
return (x * 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 * x) - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
def code(x, y, z): return (x * x) - ((y * 4.0) * z)
function code(x, y, z) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = (x * x) - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* x x) (* (* y 4.0) z)))
double code(double x, double y, double z) {
return (x * 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 * x) - ((y * 4.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * x) - ((y * 4.0) * z);
}
def code(x, y, z): return (x * x) - ((y * 4.0) * z)
function code(x, y, z) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * z)) end
function tmp = code(x, y, z) tmp = (x * x) - ((y * 4.0) * z); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 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 (fma x x (* y (* z -4.0))))
assert(y < z);
double code(double x, double y, double z) {
return fma(x, x, (y * (z * -4.0)));
}
y, z = sort([y, z]) function code(x, y, z) return fma(x, x, Float64(y * Float64(z * -4.0))) end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x + N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\mathsf{fma}\left(x, x, y \cdot \left(z \cdot -4\right)\right)
\end{array}
Initial program 98.1%
fma-neg98.8%
associate-*l*98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
distribute-rgt-neg-in98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= (* x x) 4.3e-203)
(and (not (<= (* x x) 7e-191)) (<= (* x x) 5e-132)))
(* -4.0 (* y z))
(* x x)))assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (((x * x) <= 4.3e-203) || (!((x * x) <= 7e-191) && ((x * x) <= 5e-132))) {
tmp = -4.0 * (y * z);
} else {
tmp = x * 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 (((x * x) <= 4.3d-203) .or. (.not. ((x * x) <= 7d-191)) .and. ((x * x) <= 5d-132)) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((x * x) <= 4.3e-203) || (!((x * x) <= 7e-191) && ((x * x) <= 5e-132))) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if ((x * x) <= 4.3e-203) or (not ((x * x) <= 7e-191) and ((x * x) <= 5e-132)): tmp = -4.0 * (y * z) else: tmp = x * x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(x * x) <= 4.3e-203) || (!(Float64(x * x) <= 7e-191) && (Float64(x * x) <= 5e-132))) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((x * x) <= 4.3e-203) || (~(((x * x) <= 7e-191)) && ((x * x) <= 5e-132)))
tmp = -4.0 * (y * z);
else
tmp = x * 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[N[(x * x), $MachinePrecision], 4.3e-203], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 7e-191]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 5e-132]]], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4.3 \cdot 10^{-203} \lor \neg \left(x \cdot x \leq 7 \cdot 10^{-191}\right) \land x \cdot x \leq 5 \cdot 10^{-132}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 4.30000000000000027e-203 or 7.00000000000000013e-191 < (*.f64 x x) < 4.9999999999999999e-132Initial program 99.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 97.0%
if 4.30000000000000027e-203 < (*.f64 x x) < 7.00000000000000013e-191 or 4.9999999999999999e-132 < (*.f64 x x) Initial program 97.5%
associate-*l*96.9%
Simplified96.9%
Taylor expanded in x around inf 79.9%
unpow279.9%
Simplified79.9%
Final simplification86.2%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= (* x x) 4.3e-203)
(* y (* z -4.0))
(if (<= (* x x) 7e-191)
(* x x)
(if (<= (* x x) 4.8e-132) (* -4.0 (* y z)) (* x x)))))assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 4.3e-203) {
tmp = y * (z * -4.0);
} else if ((x * x) <= 7e-191) {
tmp = x * x;
} else if ((x * x) <= 4.8e-132) {
tmp = -4.0 * (y * z);
} else {
tmp = x * 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 ((x * x) <= 4.3d-203) then
tmp = y * (z * (-4.0d0))
else if ((x * x) <= 7d-191) then
tmp = x * x
else if ((x * x) <= 4.8d-132) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 4.3e-203) {
tmp = y * (z * -4.0);
} else if ((x * x) <= 7e-191) {
tmp = x * x;
} else if ((x * x) <= 4.8e-132) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (x * x) <= 4.3e-203: tmp = y * (z * -4.0) elif (x * x) <= 7e-191: tmp = x * x elif (x * x) <= 4.8e-132: tmp = -4.0 * (y * z) else: tmp = x * x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 4.3e-203) tmp = Float64(y * Float64(z * -4.0)); elseif (Float64(x * x) <= 7e-191) tmp = Float64(x * x); elseif (Float64(x * x) <= 4.8e-132) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * x) <= 4.3e-203)
tmp = y * (z * -4.0);
elseif ((x * x) <= 7e-191)
tmp = x * x;
elseif ((x * x) <= 4.8e-132)
tmp = -4.0 * (y * z);
else
tmp = x * 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[LessEqual[N[(x * x), $MachinePrecision], 4.3e-203], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 7e-191], N[(x * x), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4.8e-132], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4.3 \cdot 10^{-203}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{elif}\;x \cdot x \leq 7 \cdot 10^{-191}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \cdot x \leq 4.8 \cdot 10^{-132}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 4.30000000000000027e-203Initial program 98.9%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 97.8%
expm1-log1p-u71.9%
expm1-udef39.6%
log1p-udef39.6%
add-exp-log65.5%
Applied egg-rr65.5%
+-commutative65.5%
associate--l+97.8%
*-commutative97.8%
metadata-eval97.8%
associate-*l*97.9%
Simplified97.9%
if 4.30000000000000027e-203 < (*.f64 x x) < 7.00000000000000013e-191 or 4.80000000000000031e-132 < (*.f64 x x) Initial program 97.5%
associate-*l*96.9%
Simplified96.9%
Taylor expanded in x around inf 79.9%
unpow279.9%
Simplified79.9%
if 7.00000000000000013e-191 < (*.f64 x x) < 4.80000000000000031e-132Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 83.9%
Final simplification86.2%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (- (* x x) (* y (* z 4.0))))
assert(y < z);
double code(double x, double y, double z) {
return (x * x) - (y * (z * 4.0));
}
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 * x) - (y * (z * 4.0d0))
end function
assert y < z;
public static double code(double x, double y, double z) {
return (x * x) - (y * (z * 4.0));
}
[y, z] = sort([y, z]) def code(x, y, z): return (x * x) - (y * (z * 4.0))
y, z = sort([y, z]) function code(x, y, z) return Float64(Float64(x * x) - Float64(y * Float64(z * 4.0))) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = (x * x) - (y * (z * 4.0));
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x \cdot x - y \cdot \left(z \cdot 4\right)
\end{array}
Initial program 98.1%
associate-*l*98.1%
Simplified98.1%
Final simplification98.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x x))
assert(y < z);
double code(double x, double y, double z) {
return x * 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 * x
end function
assert y < z;
public static double code(double x, double y, double z) {
return x * x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x * x
y, z = sort([y, z]) function code(x, y, z) return Float64(x * x) end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x * x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x \cdot x
\end{array}
Initial program 98.1%
associate-*l*98.1%
Simplified98.1%
Taylor expanded in x around inf 56.5%
unpow256.5%
Simplified56.5%
Final simplification56.5%
herbie shell --seed 2023279
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))