
(FPCore (x y z) :precision binary64 (- (- (+ (* x y) (* y y)) (* y z)) (* y y)))
double code(double x, double y, double z) {
return (((x * y) + (y * y)) - (y * z)) - (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 * y)) - (y * z)) - (y * y)
end function
public static double code(double x, double y, double z) {
return (((x * y) + (y * y)) - (y * z)) - (y * y);
}
def code(x, y, z): return (((x * y) + (y * y)) - (y * z)) - (y * y)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) + Float64(y * y)) - Float64(y * z)) - Float64(y * y)) end
function tmp = code(x, y, z) tmp = (((x * y) + (y * y)) - (y * z)) - (y * y); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + y \cdot y\right) - y \cdot z\right) - y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (- (+ (* x y) (* y y)) (* y z)) (* y y)))
double code(double x, double y, double z) {
return (((x * y) + (y * y)) - (y * z)) - (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 * y)) - (y * z)) - (y * y)
end function
public static double code(double x, double y, double z) {
return (((x * y) + (y * y)) - (y * z)) - (y * y);
}
def code(x, y, z): return (((x * y) + (y * y)) - (y * z)) - (y * y)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) + Float64(y * y)) - Float64(y * z)) - Float64(y * y)) end
function tmp = code(x, y, z) tmp = (((x * y) + (y * y)) - (y * z)) - (y * y); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + y \cdot y\right) - y \cdot z\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 rewrites69.3%
Taylor expanded in x around 0
Applied rewrites97.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y y) (* y z)))) (if (<= z -8.5e-17) t_0 (if (<= z 2.05e+130) (* x y) t_0))))
double code(double x, double y, double z) {
double t_0 = (y * y) - (y * z);
double tmp;
if (z <= -8.5e-17) {
tmp = t_0;
} else if (z <= 2.05e+130) {
tmp = x * y;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (y * y) - (y * z)
if (z <= (-8.5d-17)) then
tmp = t_0
else if (z <= 2.05d+130) then
tmp = x * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * y) - (y * z);
double tmp;
if (z <= -8.5e-17) {
tmp = t_0;
} else if (z <= 2.05e+130) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y * y) - (y * z) tmp = 0 if z <= -8.5e-17: tmp = t_0 elif z <= 2.05e+130: tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y * y) - Float64(y * z)) tmp = 0.0 if (z <= -8.5e-17) tmp = t_0; elseif (z <= 2.05e+130) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * y) - (y * z); tmp = 0.0; if (z <= -8.5e-17) tmp = t_0; elseif (z <= 2.05e+130) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -8.5e-17], t$95$0, If[LessEqual[z, 2.05e+130], N[(x * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot y - y \cdot z\\
\mathbf{if}\;z \leq -8.5 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.05 \cdot 10^{+130}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.5e-17 or 2.04999999999999989e130 < z Initial program 70.9%
Taylor expanded in x around 0
Applied rewrites83.0%
Taylor expanded in x around 0
Applied rewrites93.8%
Taylor expanded in x around inf
Applied rewrites72.5%
if -8.5e-17 < z < 2.04999999999999989e130Initial program 58.0%
Taylor expanded in x around 0
Applied rewrites61.1%
Taylor expanded in x around 0
Applied rewrites76.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 rewrites67.3%
Taylor expanded in x around 0
Applied rewrites60.8%
if 5.4000000000000003e162 < z Initial program 71.4%
Taylor expanded in x around 0
Applied rewrites85.7%
Taylor expanded in x around 0
Applied rewrites92.9%
Taylor expanded in x around inf
Applied rewrites87.7%
Taylor expanded in x around 0
Applied rewrites20.3%
(FPCore (x y z) :precision binary64 (* y y))
double code(double x, double y, double z) {
return 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 = y * y
end function
public static double code(double x, double y, double z) {
return y * y;
}
def code(x, y, z): return y * y
function code(x, y, z) return Float64(y * y) end
function tmp = code(x, y, z) tmp = y * y; end
code[x_, y_, z_] := N[(y * y), $MachinePrecision]
\begin{array}{l}
\\
y \cdot y
\end{array}
Initial program 62.8%
Taylor expanded in x around 0
Applied rewrites69.3%
Taylor expanded in x around 0
Applied rewrites97.7%
Taylor expanded in x around inf
Applied rewrites40.4%
Taylor expanded in x around 0
Applied rewrites13.9%
(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, C"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (* (- x z) y))
(- (- (+ (* x y) (* y y)) (* y z)) (* y y)))