
(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}
(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.8%
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval99.2
Applied egg-rr99.2%
(FPCore (x y z) :precision binary64 (if (<= (* x x) 1e-47) (* y (* z -4.0)) (* x x)))
double code(double x, double y, double z) {
double tmp;
if ((x * x) <= 1e-47) {
tmp = y * (z * -4.0);
} 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) <= 1d-47) then
tmp = y * (z * (-4.0d0))
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) <= 1e-47) {
tmp = y * (z * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * x) <= 1e-47: tmp = y * (z * -4.0) else: tmp = x * x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * x) <= 1e-47) tmp = Float64(y * Float64(z * -4.0)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * x) <= 1e-47) tmp = y * (z * -4.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e-47], N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-47}:\\
\;\;\;\;y \cdot \left(z \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 9.9999999999999997e-48Initial program 100.0%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-lft-identityN/A
+-commutativeN/A
accelerator-lowering-fma.f6487.2
Simplified87.2%
+-rgt-identityN/A
+-rgt-identityN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6487.2
Applied egg-rr87.2%
if 9.9999999999999997e-48 < (*.f64 x x) Initial program 97.9%
Taylor expanded in x around inf
+-rgt-identityN/A
unpow2N/A
accelerator-lowering-fma.f6486.4
Simplified86.4%
+-rgt-identityN/A
*-lowering-*.f6486.4
Applied egg-rr86.4%
Final simplification86.8%
(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.8%
Taylor expanded in x around inf
+-rgt-identityN/A
unpow2N/A
accelerator-lowering-fma.f6457.8
Simplified57.8%
+-rgt-identityN/A
*-lowering-*.f6457.8
Applied egg-rr57.8%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 98.8%
Taylor expanded in x around inf
+-rgt-identityN/A
unpow2N/A
accelerator-lowering-fma.f6457.8
Simplified57.8%
+-rgt-identityN/A
*-lowering-*.f6457.8
Applied egg-rr57.8%
pow2N/A
pow-to-expN/A
*-commutativeN/A
count-2N/A
flip-+N/A
+-inversesN/A
+-inversesN/A
+-inversesN/A
+-inversesN/A
flip-+N/A
log-prodN/A
sqr-powN/A
metadata-evalN/A
unpow1N/A
rem-exp-log3.7
Applied egg-rr3.7%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 98.8%
Taylor expanded in x around inf
+-rgt-identityN/A
unpow2N/A
accelerator-lowering-fma.f6457.8
Simplified57.8%
+-rgt-identityN/A
*-lowering-*.f6457.8
Applied egg-rr57.8%
Applied egg-rr3.6%
herbie shell --seed 2024196
(FPCore (x y z)
:name "Graphics.Rasterific.QuadraticFormula:discriminant from Rasterific-0.6.1"
:precision binary64
(- (* x x) (* (* y 4.0) z)))