
(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 (fma (- z) y (* y x)))
double code(double x, double y, double z) {
return fma(-z, y, (y * x));
}
function code(x, y, z) return fma(Float64(-z), y, Float64(y * x)) end
code[x_, y_, z_] := N[((-z) * y + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, y, y \cdot x\right)
\end{array}
Initial program 62.4%
sqr-neg62.4%
cancel-sign-sub62.4%
+-commutative62.4%
+-commutative62.4%
*-commutative62.4%
*-commutative62.4%
associate--l+62.4%
associate-+r+71.9%
sqr-neg71.9%
distribute-lft-neg-out71.9%
sub-neg71.9%
+-inverses98.0%
+-lft-identity98.0%
*-commutative98.0%
distribute-lft-out--100.0%
Simplified100.0%
sub-neg100.0%
distribute-rgt-in98.0%
*-commutative98.0%
Applied egg-rr98.0%
distribute-lft-neg-out98.0%
unsub-neg98.0%
*-commutative98.0%
Applied egg-rr98.0%
sub-neg98.0%
+-commutative98.0%
*-commutative98.0%
distribute-lft-neg-in98.0%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.55e+103)
(and (not (<= x -4.8e+74)) (or (<= x -1.25e-26) (not (<= x 6e+23)))))
(* y x)
(* z (- y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e+103) || (!(x <= -4.8e+74) && ((x <= -1.25e-26) || !(x <= 6e+23)))) {
tmp = y * x;
} else {
tmp = z * -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 ((x <= (-1.55d+103)) .or. (.not. (x <= (-4.8d+74))) .and. (x <= (-1.25d-26)) .or. (.not. (x <= 6d+23))) then
tmp = y * x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e+103) || (!(x <= -4.8e+74) && ((x <= -1.25e-26) || !(x <= 6e+23)))) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e+103) or (not (x <= -4.8e+74) and ((x <= -1.25e-26) or not (x <= 6e+23))): tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e+103) || (!(x <= -4.8e+74) && ((x <= -1.25e-26) || !(x <= 6e+23)))) tmp = Float64(y * x); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.55e+103) || (~((x <= -4.8e+74)) && ((x <= -1.25e-26) || ~((x <= 6e+23))))) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e+103], And[N[Not[LessEqual[x, -4.8e+74]], $MachinePrecision], Or[LessEqual[x, -1.25e-26], N[Not[LessEqual[x, 6e+23]], $MachinePrecision]]]], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{+103} \lor \neg \left(x \leq -4.8 \cdot 10^{+74}\right) \land \left(x \leq -1.25 \cdot 10^{-26} \lor \neg \left(x \leq 6 \cdot 10^{+23}\right)\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -1.5500000000000001e103 or -4.80000000000000017e74 < x < -1.25000000000000005e-26 or 6.0000000000000002e23 < x Initial program 68.5%
sqr-neg68.5%
cancel-sign-sub68.5%
+-commutative68.5%
+-commutative68.5%
*-commutative68.5%
*-commutative68.5%
associate--l+68.5%
associate-+r+74.3%
sqr-neg74.3%
distribute-lft-neg-out74.3%
sub-neg74.3%
+-inverses96.3%
+-lft-identity96.3%
*-commutative96.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 86.7%
*-commutative86.7%
Simplified86.7%
if -1.5500000000000001e103 < x < -4.80000000000000017e74 or -1.25000000000000005e-26 < x < 6.0000000000000002e23Initial program 55.4%
sqr-neg55.4%
cancel-sign-sub55.4%
+-commutative55.4%
+-commutative55.4%
*-commutative55.4%
*-commutative55.4%
associate--l+55.4%
associate-+r+69.2%
sqr-neg69.2%
distribute-lft-neg-out69.2%
sub-neg69.2%
+-inverses100.0%
+-lft-identity100.0%
*-commutative100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around 0 85.4%
mul-1-neg85.4%
distribute-rgt-neg-out85.4%
Simplified85.4%
Final simplification86.1%
(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 62.4%
sqr-neg62.4%
cancel-sign-sub62.4%
+-commutative62.4%
+-commutative62.4%
*-commutative62.4%
*-commutative62.4%
associate--l+62.4%
associate-+r+71.9%
sqr-neg71.9%
distribute-lft-neg-out71.9%
sub-neg71.9%
+-inverses98.0%
+-lft-identity98.0%
*-commutative98.0%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(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 62.4%
sqr-neg62.4%
cancel-sign-sub62.4%
+-commutative62.4%
+-commutative62.4%
*-commutative62.4%
*-commutative62.4%
associate--l+62.4%
associate-+r+71.9%
sqr-neg71.9%
distribute-lft-neg-out71.9%
sub-neg71.9%
+-inverses98.0%
+-lft-identity98.0%
*-commutative98.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 57.5%
*-commutative57.5%
Simplified57.5%
Final simplification57.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 2023314
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, C"
:precision binary64
:herbie-target
(* (- x z) y)
(- (- (+ (* x y) (* y y)) (* y z)) (* y y)))