
(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 (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
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -0.68)
t_0
(if (<= y 0.92)
(fma
(fma
(* y y)
(fma
y
(* y (fma (* y y) -0.001388888888888889 0.041666666666666664))
-0.5)
1.0)
x
(*
z
(fma
(fma (* y y) 0.008333333333333333 -0.16666666666666666)
(* y (* y y))
y)))
(if (<= y 3.5e+62) t_0 (* z (sin y)))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -0.68) {
tmp = t_0;
} else if (y <= 0.92) {
tmp = fma(fma((y * y), fma(y, (y * fma((y * y), -0.001388888888888889, 0.041666666666666664)), -0.5), 1.0), x, (z * fma(fma((y * y), 0.008333333333333333, -0.16666666666666666), (y * (y * y)), y)));
} else if (y <= 3.5e+62) {
tmp = t_0;
} else {
tmp = z * sin(y);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -0.68) tmp = t_0; elseif (y <= 0.92) tmp = fma(fma(Float64(y * y), fma(y, Float64(y * fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664)), -0.5), 1.0), x, Float64(z * fma(fma(Float64(y * y), 0.008333333333333333, -0.16666666666666666), Float64(y * Float64(y * y)), y))); elseif (y <= 3.5e+62) tmp = t_0; else tmp = Float64(z * sin(y)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.68], t$95$0, If[LessEqual[y, 0.92], N[(N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(z * N[(N[(N[(y * y), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.5e+62], t$95$0, N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.68:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.92:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right)\right)\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sin y\\
\end{array}
\end{array}
if y < -0.680000000000000049 or 0.92000000000000004 < y < 3.49999999999999984e62Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6463.4
Applied rewrites63.4%
if -0.680000000000000049 < y < 0.92000000000000004Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.6%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.6
Applied rewrites99.6%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.6
Applied rewrites99.6%
if 3.49999999999999984e62 < y Initial program 99.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6472.9
Applied rewrites72.9%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (<= z -9.2e-59) (fma 1.0 x (* z (sin y))) (if (<= z 2.7e-178) (* (cos y) x) (fma (sin y) z (* x 1.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e-59) {
tmp = fma(1.0, x, (z * sin(y)));
} else if (z <= 2.7e-178) {
tmp = cos(y) * x;
} else {
tmp = fma(sin(y), z, (x * 1.0));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -9.2e-59) tmp = fma(1.0, x, Float64(z * sin(y))); elseif (z <= 2.7e-178) tmp = Float64(cos(y) * x); else tmp = fma(sin(y), z, Float64(x * 1.0)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -9.2e-59], N[(1.0 * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.7e-178], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z + N[(x * 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\
\;\;\;\;\mathsf{fma}\left(1, x, z \cdot \sin y\right)\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, x \cdot 1\right)\\
\end{array}
\end{array}
if z < -9.19999999999999918e-59Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites83.1%
if -9.19999999999999918e-59 < z < 2.70000000000000009e-178Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6492.0
Applied rewrites92.0%
if 2.70000000000000009e-178 < z Initial program 99.7%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.7
Applied rewrites99.7%
lift-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
Applied rewrites86.5%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 1.0 x (* z (sin y))))) (if (<= z -9.2e-59) t_0 (if (<= z 2.7e-178) (* (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(1.0, x, (z * sin(y)));
double tmp;
if (z <= -9.2e-59) {
tmp = t_0;
} else if (z <= 2.7e-178) {
tmp = cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(1.0, x, Float64(z * sin(y))) tmp = 0.0 if (z <= -9.2e-59) tmp = t_0; elseif (z <= 2.7e-178) tmp = Float64(cos(y) * x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.2e-59], t$95$0, If[LessEqual[z, 2.7e-178], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, x, z \cdot \sin y\right)\\
\mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -9.19999999999999918e-59 or 2.70000000000000009e-178 < z Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites85.0%
if -9.19999999999999918e-59 < z < 2.70000000000000009e-178Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6492.0
Applied rewrites92.0%
Final simplification87.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -0.68)
t_0
(if (<= y 0.92)
(fma
(fma
(* y y)
(fma
y
(* y (fma (* y y) -0.001388888888888889 0.041666666666666664))
-0.5)
1.0)
x
(*
z
(fma
(fma (* y y) 0.008333333333333333 -0.16666666666666666)
(* y (* y y))
y)))
t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -0.68) {
tmp = t_0;
} else if (y <= 0.92) {
tmp = fma(fma((y * y), fma(y, (y * fma((y * y), -0.001388888888888889, 0.041666666666666664)), -0.5), 1.0), x, (z * fma(fma((y * y), 0.008333333333333333, -0.16666666666666666), (y * (y * y)), y)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -0.68) tmp = t_0; elseif (y <= 0.92) tmp = fma(fma(Float64(y * y), fma(y, Float64(y * fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664)), -0.5), 1.0), x, Float64(z * fma(fma(Float64(y * y), 0.008333333333333333, -0.16666666666666666), Float64(y * Float64(y * y)), y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.68], t$95$0, If[LessEqual[y, 0.92], N[(N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(z * N[(N[(N[(y * y), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.68:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.92:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.680000000000000049 or 0.92000000000000004 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6450.2
Applied rewrites50.2%
if -0.680000000000000049 < y < 0.92000000000000004Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.6%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.6
Applied rewrites99.6%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.6
Applied rewrites99.6%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (<= z 6.5e+114) (* x 1.0) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 6.5e+114) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
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 (z <= 6.5d+114) then
tmp = x * 1.0d0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 6.5e+114) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 6.5e+114: tmp = x * 1.0 else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 6.5e+114) tmp = Float64(x * 1.0); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 6.5e+114) tmp = x * 1.0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 6.5e+114], N[(x * 1.0), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.5 \cdot 10^{+114}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 6.5000000000000001e114Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-/.f64N/A
Applied rewrites99.6%
Taylor expanded in x around inf
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6495.7
Applied rewrites95.7%
Taylor expanded in y around 0
Applied rewrites40.5%
if 6.5000000000000001e114 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6449.9
Applied rewrites49.9%
Taylor expanded in z around inf
Applied rewrites34.5%
(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.f6452.0
Applied rewrites52.0%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * 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 * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6452.0
Applied rewrites52.0%
Taylor expanded in z around inf
Applied rewrites18.6%
herbie shell --seed 2024220
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))