
(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 (* y (- x z)))
double code(double x, double y, double z) {
return y * (x - z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * (x - z)
end function
public static double code(double x, double y, double z) {
return y * (x - z);
}
def code(x, y, z): return y * (x - z)
function code(x, y, z) return Float64(y * Float64(x - z)) end
function tmp = code(x, y, z) tmp = y * (x - z); end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x - z\right)
\end{array}
Initial program 61.7%
+-commutativeN/A
associate--l-N/A
associate-+r-N/A
distribute-rgt-outN/A
distribute-lft-outN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
+-commutativeN/A
associate--r+N/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
--lowering--.f64100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- 0.0 z)))) (if (<= z -1.36e-17) t_0 (if (<= z 3.3e-28) (* y x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (0.0 - z);
double tmp;
if (z <= -1.36e-17) {
tmp = t_0;
} else if (z <= 3.3e-28) {
tmp = y * x;
} 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 * (0.0d0 - z)
if (z <= (-1.36d-17)) then
tmp = t_0
else if (z <= 3.3d-28) then
tmp = y * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (0.0 - z);
double tmp;
if (z <= -1.36e-17) {
tmp = t_0;
} else if (z <= 3.3e-28) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (0.0 - z) tmp = 0 if z <= -1.36e-17: tmp = t_0 elif z <= 3.3e-28: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(0.0 - z)) tmp = 0.0 if (z <= -1.36e-17) tmp = t_0; elseif (z <= 3.3e-28) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (0.0 - z); tmp = 0.0; if (z <= -1.36e-17) tmp = t_0; elseif (z <= 3.3e-28) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(0.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.36e-17], t$95$0, If[LessEqual[z, 3.3e-28], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(0 - z\right)\\
\mathbf{if}\;z \leq -1.36 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.3 \cdot 10^{-28}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.36e-17 or 3.3000000000000002e-28 < z Initial program 75.4%
+-commutativeN/A
associate--l-N/A
associate-+r-N/A
distribute-rgt-outN/A
distribute-lft-outN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
+-commutativeN/A
associate--r+N/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6476.6%
Simplified76.6%
sub0-negN/A
+-lft-identityN/A
flip3-+N/A
metadata-evalN/A
+-lft-identityN/A
distribute-neg-fracN/A
Applied egg-rr76.6%
if -1.36e-17 < z < 3.3000000000000002e-28Initial program 44.6%
+-commutativeN/A
associate--l-N/A
associate-+r-N/A
distribute-rgt-outN/A
distribute-lft-outN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
+-commutativeN/A
associate--r+N/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6483.1%
Simplified83.1%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 61.7%
+-commutativeN/A
associate--l-N/A
associate-+r-N/A
distribute-rgt-outN/A
distribute-lft-outN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
+-commutativeN/A
associate--r+N/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6453.4%
Simplified53.4%
(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 2024145
(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)))