
(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 7 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 (* z (sin y))))
(if (<= y -1.8e+114)
t_0
(if (<= y -230000000000.0)
(* (cos y) x)
(if (<= y 1.8)
(fma
(fma
y
(*
y
(fma
y
(* y (fma (* y y) -0.001388888888888889 0.041666666666666664))
-0.5))
1.0)
x
(* y z))
t_0)))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (y <= -1.8e+114) {
tmp = t_0;
} else if (y <= -230000000000.0) {
tmp = cos(y) * x;
} else if (y <= 1.8) {
tmp = fma(fma(y, (y * fma(y, (y * fma((y * y), -0.001388888888888889, 0.041666666666666664)), -0.5)), 1.0), x, (y * z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (y <= -1.8e+114) tmp = t_0; elseif (y <= -230000000000.0) tmp = Float64(cos(y) * x); elseif (y <= 1.8) tmp = fma(fma(y, Float64(y * fma(y, Float64(y * fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664)), -0.5)), 1.0), x, Float64(y * z)); 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, -1.8e+114], t$95$0, If[LessEqual[y, -230000000000.0], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 1.8], N[(N[(y * N[(y * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;y \leq -1.8 \cdot 10^{+114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -230000000000:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{elif}\;y \leq 1.8:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.8e114 or 1.80000000000000004 < y Initial program 99.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6458.9
Applied rewrites58.9%
if -1.8e114 < y < -2.3e11Initial program 99.4%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6469.9
Applied rewrites69.9%
if -2.3e11 < y < 1.80000000000000004Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
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
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f6498.0
Applied rewrites98.0%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.0
Applied rewrites98.0%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 1.0 x (* z (sin y))))) (if (<= z -7.8e-13) t_0 (if (<= z 7.1e-158) (* (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 <= -7.8e-13) {
tmp = t_0;
} else if (z <= 7.1e-158) {
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 <= -7.8e-13) tmp = t_0; elseif (z <= 7.1e-158) 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, -7.8e-13], t$95$0, If[LessEqual[z, 7.1e-158], 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 -7.8 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.1 \cdot 10^{-158}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.80000000000000009e-13 or 7.10000000000000003e-158 < 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 rewrites86.3%
if -7.80000000000000009e-13 < z < 7.10000000000000003e-158Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6493.2
Applied rewrites93.2%
Final simplification88.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -45000.0)
t_0
(if (<= y 3.3e-11)
(fma y (fma y (fma x -0.5 (* (* y z) -0.16666666666666666)) z) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -45000.0) {
tmp = t_0;
} else if (y <= 3.3e-11) {
tmp = fma(y, fma(y, fma(x, -0.5, ((y * z) * -0.16666666666666666)), z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -45000.0) tmp = t_0; elseif (y <= 3.3e-11) tmp = fma(y, fma(y, fma(x, -0.5, Float64(Float64(y * z) * -0.16666666666666666)), z), x); 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, -45000.0], t$95$0, If[LessEqual[y, 3.3e-11], N[(y * N[(y * N[(x * -0.5 + N[(N[(y * z), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -45000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, -0.5, \left(y \cdot z\right) \cdot -0.16666666666666666\right), z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -45000 or 3.3000000000000002e-11 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6448.9
Applied rewrites48.9%
if -45000 < y < 3.3000000000000002e-11Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification73.3%
(FPCore (x y z) :precision binary64 (if (<= z -2.1e+37) (* y z) (if (<= z 2.7e+248) (- (- x)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e+37) {
tmp = y * z;
} else if (z <= 2.7e+248) {
tmp = -(-x);
} 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 <= (-2.1d+37)) then
tmp = y * z
else if (z <= 2.7d+248) then
tmp = -(-x)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e+37) {
tmp = y * z;
} else if (z <= 2.7e+248) {
tmp = -(-x);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.1e+37: tmp = y * z elif z <= 2.7e+248: tmp = -(-x) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.1e+37) tmp = Float64(y * z); elseif (z <= 2.7e+248) tmp = Float64(-Float64(-x)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.1e+37) tmp = y * z; elseif (z <= 2.7e+248) tmp = -(-x); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.1e+37], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.7e+248], (-(-x)), N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{+37}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+248}:\\
\;\;\;\;-\left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.1000000000000001e37 or 2.69999999999999989e248 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.1
Applied rewrites53.1%
Taylor expanded in z around inf
Applied rewrites40.7%
if -2.1000000000000001e37 < z < 2.69999999999999989e248Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.3
Applied rewrites51.3%
Taylor expanded in x around -inf
Applied rewrites50.7%
Taylor expanded in x around inf
Applied rewrites46.7%
(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.f6451.7
Applied rewrites51.7%
(FPCore (x y z) :precision binary64 (- (- x)))
double code(double x, double y, double z) {
return -(-x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -(-x)
end function
public static double code(double x, double y, double z) {
return -(-x);
}
def code(x, y, z): return -(-x)
function code(x, y, z) return Float64(-Float64(-x)) end
function tmp = code(x, y, z) tmp = -(-x); end
code[x_, y_, z_] := (-(-x))
\begin{array}{l}
\\
-\left(-x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.7
Applied rewrites51.7%
Taylor expanded in x around -inf
Applied rewrites47.5%
Taylor expanded in x around inf
Applied rewrites39.5%
herbie shell --seed 2024226
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))