
(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 (if (<= z -4.6e+129) (* z (sin y)) (if (<= z 3.4e-62) (* x (cos y)) (* (fma (/ (sin y) x) z 1.0) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e+129) {
tmp = z * sin(y);
} else if (z <= 3.4e-62) {
tmp = x * cos(y);
} else {
tmp = fma((sin(y) / x), z, 1.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -4.6e+129) tmp = Float64(z * sin(y)); elseif (z <= 3.4e-62) tmp = Float64(x * cos(y)); else tmp = Float64(fma(Float64(sin(y) / x), z, 1.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -4.6e+129], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.4e-62], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision] * z + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+129}:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-62}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sin y}{x}, z, 1\right) \cdot x\\
\end{array}
\end{array}
if z < -4.59999999999999981e129Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6482.0
Applied rewrites82.0%
if -4.59999999999999981e129 < z < 3.39999999999999988e-62Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6486.8
Applied rewrites86.8%
if 3.39999999999999988e-62 < z Initial program 99.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
unpow1N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
pow2N/A
pow-powN/A
lower-pow.f64N/A
lower-pow.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval41.8
Applied rewrites41.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6493.9
Applied rewrites93.9%
Taylor expanded in y around 0
Applied rewrites75.9%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (<= y -0.45) (* z (sin y)) (if (<= y 90000.0) (fma (fma (* x y) -0.5 z) y x) (* x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.45) {
tmp = z * sin(y);
} else if (y <= 90000.0) {
tmp = fma(fma((x * y), -0.5, z), y, x);
} else {
tmp = x * cos(y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -0.45) tmp = Float64(z * sin(y)); elseif (y <= 90000.0) tmp = fma(fma(Float64(x * y), -0.5, z), y, x); else tmp = Float64(x * cos(y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -0.45], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 90000.0], N[(N[(N[(x * y), $MachinePrecision] * -0.5 + z), $MachinePrecision] * y + x), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.45:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{elif}\;y \leq 90000:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot y, -0.5, z\right), y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if y < -0.450000000000000011Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6461.2
Applied rewrites61.2%
if -0.450000000000000011 < y < 9e4Initial 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.8
Applied rewrites98.8%
if 9e4 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6461.1
Applied rewrites61.1%
Final simplification81.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.0155)
t_0
(if (<= y 90000.0) (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 <= -0.0155) {
tmp = t_0;
} else if (y <= 90000.0) {
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 <= -0.0155) tmp = t_0; elseif (y <= 90000.0) 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, -0.0155], t$95$0, If[LessEqual[y, 90000.0], 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 -0.0155:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 90000:\\
\;\;\;\;\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.0155 or 9e4 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6449.2
Applied rewrites49.2%
if -0.0155 < y < 9e4Initial 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-*.f6499.3
Applied rewrites99.3%
Final simplification75.4%
(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.f6455.1
Applied rewrites55.1%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\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%
unpow1N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
pow2N/A
pow-powN/A
lower-pow.f64N/A
lower-pow.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval49.2
Applied rewrites49.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6493.8
Applied rewrites93.8%
Taylor expanded in y around 0
Applied rewrites45.3%
(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.f6455.1
Applied rewrites55.1%
Taylor expanded in z around inf
Applied rewrites13.9%
herbie shell --seed 2024249
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))