
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) z (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), z, Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * z + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) x (* z (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), x, (z * sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(z * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -1.65e+171)
t_0
(if (<= y -0.84)
(* z (sin y))
(if (<= y 8e-20) (fma (fma (* x y) -0.5 z) y x) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -1.65e+171) {
tmp = t_0;
} else if (y <= -0.84) {
tmp = z * sin(y);
} else if (y <= 8e-20) {
tmp = fma(fma((x * y), -0.5, z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1.65e+171) tmp = t_0; elseif (y <= -0.84) tmp = Float64(z * sin(y)); elseif (y <= 8e-20) tmp = fma(fma(Float64(x * y), -0.5, z), y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.65e+171], t$95$0, If[LessEqual[y, -0.84], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8e-20], N[(N[(N[(x * y), $MachinePrecision] * -0.5 + z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{+171}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.84:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot y, -0.5, z\right), y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.64999999999999996e171 or 7.99999999999999956e-20 < y Initial program 99.7%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6439.7
lift-*.f64N/A
*-commutativeN/A
Applied rewrites39.7%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-cos.f6464.4
Applied rewrites64.4%
if -1.64999999999999996e171 < y < -0.839999999999999969Initial program 99.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6460.8
Applied rewrites60.8%
if -0.839999999999999969 < y < 7.99999999999999956e-20Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.9
Applied rewrites98.9%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) z (* 1.0 x)))) (if (<= z -7.8e-143) t_0 (if (<= z 1.52e-99) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), z, (1.0 * x));
double tmp;
if (z <= -7.8e-143) {
tmp = t_0;
} else if (z <= 1.52e-99) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), z, Float64(1.0 * x)) tmp = 0.0 if (z <= -7.8e-143) tmp = t_0; elseif (z <= 1.52e-99) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z + N[(1.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.8e-143], t$95$0, If[LessEqual[z, 1.52e-99], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{-143}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.52 \cdot 10^{-99}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.80000000000000007e-143 or 1.51999999999999999e-99 < z Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites85.6%
if -7.80000000000000007e-143 < z < 1.51999999999999999e-99Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6438.2
lift-*.f64N/A
*-commutativeN/A
Applied rewrites38.2%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-cos.f6494.7
Applied rewrites94.7%
Final simplification88.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))))
(if (<= y -0.84)
t_0
(if (<= y 8.6e+24) (fma (fma (* x y) -0.5 z) y x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (y <= -0.84) {
tmp = t_0;
} else if (y <= 8.6e+24) {
tmp = fma(fma((x * y), -0.5, z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (y <= -0.84) tmp = t_0; elseif (y <= 8.6e+24) tmp = fma(fma(Float64(x * y), -0.5, z), y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.84], t$95$0, If[LessEqual[y, 8.6e+24], N[(N[(N[(x * y), $MachinePrecision] * -0.5 + z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;y \leq -0.84:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.6 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot y, -0.5, z\right), y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.839999999999999969 or 8.59999999999999975e24 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6445.7
Applied rewrites45.7%
if -0.839999999999999969 < y < 8.59999999999999975e24Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6497.5
Applied rewrites97.5%
Final simplification73.0%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.9
Applied rewrites53.9%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return 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 = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.9
Applied rewrites53.9%
Taylor expanded in x around 0
Applied rewrites17.4%
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
return 0.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.0d0
end function
public static double code(double x, double y, double z) {
return 0.0;
}
def code(x, y, z): return 0.0
function code(x, y, z) return 0.0 end
function tmp = code(x, y, z) tmp = 0.0; end
code[x_, y_, z_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
flip-+N/A
lower-/.f64N/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6457.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.2
Applied rewrites57.2%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites26.6%
Taylor expanded in x around 0
Applied rewrites2.9%
herbie shell --seed 2024332
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))