
(FPCore (x y z) :precision binary64 (+ (- (- (* x y) (* y z)) (* y y)) (* y y)))
double code(double x, double y, double z) {
return (((x * y) - (y * z)) - (y * y)) + (y * 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) - (y * z)) - (y * y)) + (y * y)
end function
public static double code(double x, double y, double z) {
return (((x * y) - (y * z)) - (y * y)) + (y * y);
}
def code(x, y, z): return (((x * y) - (y * z)) - (y * y)) + (y * y)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) - Float64(y * z)) - Float64(y * y)) + Float64(y * y)) end
function tmp = code(x, y, z) tmp = (((x * y) - (y * z)) - (y * y)) + (y * y); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y - y \cdot z\right) - y \cdot y\right) + y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (- (- (* x y) (* y z)) (* y y)) (* y y)))
double code(double x, double y, double z) {
return (((x * y) - (y * z)) - (y * y)) + (y * 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) - (y * z)) - (y * y)) + (y * y)
end function
public static double code(double x, double y, double z) {
return (((x * y) - (y * z)) - (y * y)) + (y * y);
}
def code(x, y, z): return (((x * y) - (y * z)) - (y * y)) + (y * y)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) - Float64(y * z)) - Float64(y * y)) + Float64(y * y)) end
function tmp = code(x, y, z) tmp = (((x * y) - (y * z)) - (y * y)) + (y * y); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y - y \cdot z\right) - y \cdot y\right) + y \cdot y
\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 62.8%
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 5.4e+162) (* x y) (* y y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 5.4e+162) {
tmp = x * y;
} else {
tmp = y * 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 <= 5.4d+162) then
tmp = x * y
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 5.4e+162) {
tmp = x * y;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5.4e+162: tmp = x * y else: tmp = y * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5.4e+162) tmp = Float64(x * y); else tmp = Float64(y * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 5.4e+162) tmp = x * y; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5.4e+162], N[(x * y), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.4 \cdot 10^{+162}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if z < 5.4000000000000003e162Initial program 61.8%
Taylor expanded in x around 0
Applied rewrites64.7%
Taylor expanded in x around 0
Applied rewrites60.8%
if 5.4000000000000003e162 < z Initial program 71.4%
Taylor expanded in x around 0
Applied rewrites78.6%
Taylor expanded in x around inf
Applied rewrites20.3%
(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 62.8%
Taylor expanded in x around 0
Applied rewrites66.3%
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, B"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (* (- x z) y))
(+ (- (- (* x y) (* y z)) (* y y)) (* y y)))