
(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 60.2%
Taylor expanded in x around 0
Applied rewrites68.8%
Taylor expanded in x around 0
Applied rewrites98.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y y) (* y z)))) (if (<= z -1.72e+81) t_0 (if (<= z 7.8e+29) (* x y) t_0))))
double code(double x, double y, double z) {
double t_0 = (y * y) - (y * z);
double tmp;
if (z <= -1.72e+81) {
tmp = t_0;
} else if (z <= 7.8e+29) {
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 <= (-1.72d+81)) then
tmp = t_0
else if (z <= 7.8d+29) 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 <= -1.72e+81) {
tmp = t_0;
} else if (z <= 7.8e+29) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y * y) - (y * z) tmp = 0 if z <= -1.72e+81: tmp = t_0 elif z <= 7.8e+29: 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 <= -1.72e+81) tmp = t_0; elseif (z <= 7.8e+29) 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 <= -1.72e+81) tmp = t_0; elseif (z <= 7.8e+29) 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, -1.72e+81], t$95$0, If[LessEqual[z, 7.8e+29], 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 -1.72 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+29}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.72000000000000002e81 or 7.79999999999999937e29 < z Initial program 63.3%
Taylor expanded in x around 0
Applied rewrites77.7%
Taylor expanded in x around 0
Applied rewrites95.1%
Taylor expanded in x around inf
Applied rewrites70.9%
if -1.72000000000000002e81 < z < 7.79999999999999937e29Initial program 58.1%
Taylor expanded in x around 0
Applied rewrites62.9%
Taylor expanded in x around 0
Applied rewrites72.8%
(FPCore (x y z) :precision binary64 (if (<= z 3.8e+197) (* x y) (* y y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.8e+197) {
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 <= 3.8d+197) 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 <= 3.8e+197) {
tmp = x * y;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.8e+197: tmp = x * y else: tmp = y * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.8e+197) 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 <= 3.8e+197) tmp = x * y; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.8e+197], N[(x * y), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.8 \cdot 10^{+197}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if z < 3.8000000000000001e197Initial program 59.4%
Taylor expanded in x around 0
Applied rewrites67.6%
Taylor expanded in x around 0
Applied rewrites57.3%
if 3.8000000000000001e197 < z Initial program 68.2%
Taylor expanded in x around 0
Applied rewrites81.8%
Taylor expanded in x around 0
Applied rewrites95.5%
Taylor expanded in x around inf
Applied rewrites86.4%
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 60.2%
Taylor expanded in x around 0
Applied rewrites68.8%
Taylor expanded in x around 0
Applied rewrites98.0%
Taylor expanded in x around inf
Applied rewrites42.2%
Taylor expanded in x around 0
Applied rewrites18.2%
(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 2024313
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, C"
:precision binary64
:alt
(! :herbie-platform default (* (- x z) y))
(- (- (+ (* x y) (* y y)) (* y z)) (* y y)))