
(FPCore (x y z) :precision binary64 (- (+ (- (* x y) (* y y)) (* y y)) (* y z)))
double code(double x, double y, double z) {
return (((x * y) - (y * y)) + (y * y)) - (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 * y) - (y * y)) + (y * y)) - (y * z)
end function
public static double code(double x, double y, double z) {
return (((x * y) - (y * y)) + (y * y)) - (y * z);
}
def code(x, y, z): return (((x * y) - (y * y)) + (y * y)) - (y * z)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) - Float64(y * y)) + Float64(y * y)) - Float64(y * z)) end
function tmp = code(x, y, z) tmp = (((x * y) - (y * y)) + (y * y)) - (y * z); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y - y \cdot y\right) + y \cdot y\right) - y \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ (- (* x y) (* y y)) (* y y)) (* y z)))
double code(double x, double y, double z) {
return (((x * y) - (y * y)) + (y * y)) - (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 * y) - (y * y)) + (y * y)) - (y * z)
end function
public static double code(double x, double y, double z) {
return (((x * y) - (y * y)) + (y * y)) - (y * z);
}
def code(x, y, z): return (((x * y) - (y * y)) + (y * y)) - (y * z)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) - Float64(y * y)) + Float64(y * y)) - Float64(y * z)) end
function tmp = code(x, y, z) tmp = (((x * y) - (y * y)) + (y * y)) - (y * z); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y - y \cdot y\right) + y \cdot y\right) - y \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x y) (* y z)))
double code(double x, double y, double z) {
return (x * y) - (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 * y) - (y * z)
end function
public static double code(double x, double y, double z) {
return (x * y) - (y * z);
}
def code(x, y, z): return (x * y) - (y * z)
function code(x, y, z) return Float64(Float64(x * y) - Float64(y * z)) end
function tmp = code(x, y, z) tmp = (x * y) - (y * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y - y \cdot z
\end{array}
Initial program 68.9%
Taylor expanded in x around 0
Applied rewrites66.3%
Taylor expanded in x around 0
Applied rewrites97.7%
(FPCore (x y z) :precision binary64 (if (<= z -6.2e-17) (+ (* x y) (* y y)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.2e-17) {
tmp = (x * y) + (y * y);
} else {
tmp = x * y;
}
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 (z <= (-6.2d-17)) then
tmp = (x * y) + (y * y)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6.2e-17) {
tmp = (x * y) + (y * y);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.2e-17: tmp = (x * y) + (y * y) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.2e-17) tmp = Float64(Float64(x * y) + Float64(y * y)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.2e-17) tmp = (x * y) + (y * y); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.2e-17], N[(N[(x * y), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{-17}:\\
\;\;\;\;x \cdot y + y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -6.1999999999999997e-17Initial program 78.3%
Taylor expanded in x around 0
Applied rewrites17.5%
Taylor expanded in x around 0
Applied rewrites31.4%
if -6.1999999999999997e-17 < z Initial program 66.0%
Taylor expanded in x around 0
Applied rewrites41.0%
Taylor expanded in x around 0
Applied rewrites44.3%
Taylor expanded in x around 0
Applied rewrites64.6%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 68.9%
Taylor expanded in x around 0
Applied rewrites35.5%
Taylor expanded in x around 0
Applied rewrites39.6%
Taylor expanded in x around 0
Applied rewrites54.5%
(FPCore (x y z) :precision binary64 (* (- x z) y))
double code(double x, double y, double z) {
return (x - z) * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - z) * y
end function
public static double code(double x, double y, double z) {
return (x - z) * y;
}
def code(x, y, z): return (x - z) * y
function code(x, y, z) return Float64(Float64(x - z) * y) end
function tmp = code(x, y, z) tmp = (x - z) * y; end
code[x_, y_, z_] := N[(N[(x - z), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(x - z\right) \cdot y
\end{array}
herbie shell --seed 2024321
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, D"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (* (- x z) y))
(- (+ (- (* x y) (* y y)) (* y y)) (* y z)))