
(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 3 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 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 61.5%
Taylor expanded in x around 0
*-commutativeN/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7) (not (<= x 3e-109))) (* x y) (* (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7) || !(x <= 3e-109)) {
tmp = x * y;
} 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 <= (-3.7d0)) .or. (.not. (x <= 3d-109))) then
tmp = x * y
else
tmp = -z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7) || !(x <= 3e-109)) {
tmp = x * y;
} else {
tmp = -z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7) or not (x <= 3e-109): tmp = x * y else: tmp = -z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.7) || !(x <= 3e-109)) tmp = Float64(x * y); else tmp = Float64(Float64(-z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.7) || ~((x <= 3e-109))) tmp = x * y; else tmp = -z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.7], N[Not[LessEqual[x, 3e-109]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[((-z) * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \lor \neg \left(x \leq 3 \cdot 10^{-109}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\end{array}
\end{array}
if x < -3.7000000000000002 or 3.00000000000000021e-109 < x Initial program 67.9%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-out--N/A
lower-fma.f64N/A
lower--.f6471.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6471.9
Applied rewrites71.9%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f6477.3
Applied rewrites77.3%
Taylor expanded in x around inf
lower-*.f6476.2
Applied rewrites76.2%
if -3.7000000000000002 < x < 3.00000000000000021e-109Initial program 52.0%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6486.7
Applied rewrites86.7%
Final simplification80.4%
(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 61.5%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-out--N/A
lower-fma.f64N/A
lower--.f6464.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6464.7
Applied rewrites64.7%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f6469.3
Applied rewrites69.3%
Taylor expanded in x around inf
lower-*.f6454.2
Applied rewrites54.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 2024337
(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)))