
(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 6 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}
(FPCore (x y z) :precision binary64 (fma y (* z -4.0) (* x x)))
double code(double x, double y, double z) {
return fma(y, (z * -4.0), (x * x));
}
function code(x, y, z) return fma(y, Float64(z * -4.0), Float64(x * x)) end
code[x_, y_, z_] := N[(y * N[(z * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z \cdot -4, x \cdot x\right)
\end{array}
Initial program 98.4%
sub-neg98.4%
+-commutative98.4%
associate-*l*98.4%
distribute-rgt-neg-in98.4%
fma-def99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (fma x x (* z (* y -4.0))))
double code(double x, double y, double z) {
return fma(x, x, (z * (y * -4.0)));
}
function code(x, y, z) return fma(x, x, Float64(z * Float64(y * -4.0))) end
code[x_, y_, z_] := N[(x * x + N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, z \cdot \left(y \cdot -4\right)\right)
\end{array}
Initial program 98.4%
fma-neg98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
distribute-rgt-neg-in98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (x y z)
:precision binary64
(if (or (<= (* x x) 4e-38)
(and (not (<= (* x x) 4.1e+63)) (<= (* x x) 2.6e+113)))
(* -4.0 (* y z))
(* x x)))
double code(double x, double y, double z) {
double tmp;
if (((x * x) <= 4e-38) || (!((x * x) <= 4.1e+63) && ((x * x) <= 2.6e+113))) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
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) <= 4d-38) .or. (.not. ((x * x) <= 4.1d+63)) .and. ((x * x) <= 2.6d+113)) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * x) <= 4e-38) || (!((x * x) <= 4.1e+63) && ((x * x) <= 2.6e+113))) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * x) <= 4e-38) or (not ((x * x) <= 4.1e+63) and ((x * x) <= 2.6e+113)): tmp = -4.0 * (y * z) else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(x * x) <= 4e-38) || (!(Float64(x * x) <= 4.1e+63) && (Float64(x * x) <= 2.6e+113))) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * x) <= 4e-38) || (~(((x * x) <= 4.1e+63)) && ((x * x) <= 2.6e+113))) tmp = -4.0 * (y * z); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 4e-38], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 4.1e+63]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 2.6e+113]]], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{-38} \lor \neg \left(x \cdot x \leq 4.1 \cdot 10^{+63}\right) \land x \cdot x \leq 2.6 \cdot 10^{+113}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.9999999999999998e-38 or 4.09999999999999993e63 < (*.f64 x x) < 2.5999999999999999e113Initial program 100.0%
Taylor expanded in x around 0 85.4%
if 3.9999999999999998e-38 < (*.f64 x x) < 4.09999999999999993e63 or 2.5999999999999999e113 < (*.f64 x x) Initial program 96.8%
Taylor expanded in x around inf 84.5%
unpow284.5%
Simplified84.5%
Final simplification85.0%
(FPCore (x y z)
:precision binary64
(if (<= (* x x) 2.9e-42)
(* y (* z -4.0))
(if (<= (* x x) 1.05e+60)
(* x x)
(if (<= (* x x) 7e+112) (* -4.0 (* y z)) (* x x)))))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.9e-42) {
tmp = y * (z * -4.0);
} else if ((x * x) <= 1.05e+60) {
tmp = x * x;
} else if ((x * x) <= 7e+112) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
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) <= 2.9d-42) then
tmp = y * (z * (-4.0d0))
else if ((x * x) <= 1.05d+60) then
tmp = x * x
else if ((x * x) <= 7d+112) then
tmp = (-4.0d0) * (y * z)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 2.9e-42) {
tmp = y * (z * -4.0);
} else if ((x * x) <= 1.05e+60) {
tmp = x * x;
} else if ((x * x) <= 7e+112) {
tmp = -4.0 * (y * z);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 2.9e-42: tmp = y * (z * -4.0) elif (x * x) <= 1.05e+60: tmp = x * x elif (x * x) <= 7e+112: tmp = -4.0 * (y * z) else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 2.9e-42) tmp = Float64(y * Float64(z * -4.0)); elseif (Float64(x * x) <= 1.05e+60) tmp = Float64(x * x); elseif (Float64(x * x) <= 7e+112) tmp = Float64(-4.0 * Float64(y * z)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 2.9e-42) tmp = y * (z * -4.0); elseif ((x * x) <= 1.05e+60) tmp = x * x; elseif ((x * x) <= 7e+112) tmp = -4.0 * (y * z); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.9e-42], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1.05e+60], N[(x * x), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 7e+112], N[(-4.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.9 \cdot 10^{-42}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{elif}\;x \cdot x \leq 1.05 \cdot 10^{+60}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \cdot x \leq 7 \cdot 10^{+112}:\\
\;\;\;\;-4 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.9000000000000003e-42Initial program 100.0%
Taylor expanded in x around 0 86.1%
expm1-log1p-u59.3%
expm1-udef28.4%
log1p-udef28.4%
add-exp-log55.2%
Applied egg-rr55.2%
+-commutative55.2%
associate--l+86.1%
*-commutative86.1%
metadata-eval86.1%
associate-*l*86.2%
Simplified86.2%
if 2.9000000000000003e-42 < (*.f64 x x) < 1.0500000000000001e60 or 6.99999999999999994e112 < (*.f64 x x) Initial program 96.8%
Taylor expanded in x around inf 84.5%
unpow284.5%
Simplified84.5%
if 1.0500000000000001e60 < (*.f64 x x) < 6.99999999999999994e112Initial program 100.0%
Taylor expanded in x around 0 75.6%
Final simplification85.0%
(FPCore (x y z) :precision binary64 (- (* x x) (* z (* y 4.0))))
double code(double x, double y, double z) {
return (x * x) - (z * (y * 4.0));
}
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) - (z * (y * 4.0d0))
end function
public static double code(double x, double y, double z) {
return (x * x) - (z * (y * 4.0));
}
def code(x, y, z): return (x * x) - (z * (y * 4.0))
function code(x, y, z) return Float64(Float64(x * x) - Float64(z * Float64(y * 4.0))) end
function tmp = code(x, y, z) tmp = (x * x) - (z * (y * 4.0)); end
code[x_, y_, z_] := N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - z \cdot \left(y \cdot 4\right)
\end{array}
Initial program 98.4%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (* x x))
double code(double x, double y, double z) {
return x * x;
}
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
public static double code(double x, double y, double z) {
return x * x;
}
def code(x, y, z): return x * x
function code(x, y, z) return Float64(x * x) end
function tmp = code(x, y, z) tmp = x * x; end
code[x_, y_, z_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 98.4%
Taylor expanded in x around inf 52.0%
unpow252.0%
Simplified52.0%
Final simplification52.0%
herbie shell --seed 2023200
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))