
(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 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}
Initial program 62.6%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l-N/A
+-inversesN/A
--rgt-identity95.7
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* z y)))) (if (<= z -1.02e-44) t_0 (if (<= z 1.1e+53) (* x y) t_0))))
double code(double x, double y, double z) {
double t_0 = -(z * y);
double tmp;
if (z <= -1.02e-44) {
tmp = t_0;
} else if (z <= 1.1e+53) {
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 = -(z * y)
if (z <= (-1.02d-44)) then
tmp = t_0
else if (z <= 1.1d+53) 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 = -(z * y);
double tmp;
if (z <= -1.02e-44) {
tmp = t_0;
} else if (z <= 1.1e+53) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(z * y) tmp = 0 if z <= -1.02e-44: tmp = t_0 elif z <= 1.1e+53: tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(z * y)) tmp = 0.0 if (z <= -1.02e-44) tmp = t_0; elseif (z <= 1.1e+53) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(z * y); tmp = 0.0; if (z <= -1.02e-44) tmp = t_0; elseif (z <= 1.1e+53) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(z * y), $MachinePrecision])}, If[LessEqual[z, -1.02e-44], t$95$0, If[LessEqual[z, 1.1e+53], N[(x * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -z \cdot y\\
\mathbf{if}\;z \leq -1.02 \cdot 10^{-44}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+53}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.0199999999999999e-44 or 1.09999999999999999e53 < z Initial program 68.8%
Taylor expanded in x around 0
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6479.1
Applied rewrites79.1%
if -1.0199999999999999e-44 < z < 1.09999999999999999e53Initial program 55.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6482.6
Applied rewrites82.6%
Final simplification80.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 62.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6451.6
Applied rewrites51.6%
Final simplification51.6%
(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 2024216
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, B"
:precision binary64
:alt
(! :herbie-platform default (* (- x z) y))
(+ (- (- (* x y) (* y z)) (* y y)) (* y y)))