
(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 (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-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))) (t_1 (* x (fma z (/ (sin y) x) 1.0))))
(if (<= x -1.85e+47)
t_0
(if (<= x -1.8e-214)
t_1
(if (<= x 9e-223) (* (sin y) z) (if (<= x 0.42) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = x * fma(z, (sin(y) / x), 1.0);
double tmp;
if (x <= -1.85e+47) {
tmp = t_0;
} else if (x <= -1.8e-214) {
tmp = t_1;
} else if (x <= 9e-223) {
tmp = sin(y) * z;
} else if (x <= 0.42) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(x * fma(z, Float64(sin(y) / x), 1.0)) tmp = 0.0 if (x <= -1.85e+47) tmp = t_0; elseif (x <= -1.8e-214) tmp = t_1; elseif (x <= 9e-223) tmp = Float64(sin(y) * z); elseif (x <= 0.42) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(z * N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.85e+47], t$95$0, If[LessEqual[x, -1.8e-214], t$95$1, If[LessEqual[x, 9e-223], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[x, 0.42], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := x \cdot \mathsf{fma}\left(z, \frac{\sin y}{x}, 1\right)\\
\mathbf{if}\;x \leq -1.85 \cdot 10^{+47}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.8 \cdot 10^{-214}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-223}:\\
\;\;\;\;\sin y \cdot z\\
\mathbf{elif}\;x \leq 0.42:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.8500000000000002e47 or 0.419999999999999984 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6490.7
Applied rewrites90.7%
if -1.8500000000000002e47 < x < -1.8e-214 or 8.99999999999999935e-223 < x < 0.419999999999999984Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
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.f6492.7
Applied rewrites92.7%
Taylor expanded in y around 0
Applied rewrites83.0%
if -1.8e-214 < x < 8.99999999999999935e-223Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6494.3
Applied rewrites94.3%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -1.66e-37) t_0 (if (<= x 5.5e-139) (* (sin y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.66e-37) {
tmp = t_0;
} else if (x <= 5.5e-139) {
tmp = sin(y) * z;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (x <= (-1.66d-37)) then
tmp = t_0
else if (x <= 5.5d-139) then
tmp = sin(y) * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (x <= -1.66e-37) {
tmp = t_0;
} else if (x <= 5.5e-139) {
tmp = Math.sin(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -1.66e-37: tmp = t_0 elif x <= 5.5e-139: tmp = math.sin(y) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -1.66e-37) tmp = t_0; elseif (x <= 5.5e-139) tmp = Float64(sin(y) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -1.66e-37) tmp = t_0; elseif (x <= 5.5e-139) tmp = sin(y) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.66e-37], t$95$0, If[LessEqual[x, 5.5e-139], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -1.66 \cdot 10^{-37}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-139}:\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.6599999999999999e-37 or 5.4999999999999997e-139 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6482.9
Applied rewrites82.9%
if -1.6599999999999999e-37 < x < 5.4999999999999997e-139Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6481.0
Applied rewrites81.0%
Final simplification82.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.085)
t_0
(if (<= y 0.112)
(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 = x * cos(y);
double tmp;
if (y <= -0.085) {
tmp = t_0;
} else if (y <= 0.112) {
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(x * cos(y)) tmp = 0.0 if (y <= -0.085) tmp = t_0; elseif (y <= 0.112) 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[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.085], t$95$0, If[LessEqual[y, 0.112], 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 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.085:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.112:\\
\;\;\;\;\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 < -0.0850000000000000061 or 0.112000000000000002 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6450.5
Applied rewrites50.5%
if -0.0850000000000000061 < y < 0.112000000000000002Initial 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-*.f64100.0
Applied rewrites100.0%
Final simplification75.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.8e-69) x (if (<= x 5.2e-139) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-69) {
tmp = x;
} else if (x <= 5.2e-139) {
tmp = y * z;
} else {
tmp = x;
}
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 <= (-1.8d-69)) then
tmp = x
else if (x <= 5.2d-139) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-69) {
tmp = x;
} else if (x <= 5.2e-139) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.8e-69: tmp = x elif x <= 5.2e-139: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.8e-69) tmp = x; elseif (x <= 5.2e-139) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.8e-69) tmp = x; elseif (x <= 5.2e-139) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.8e-69], x, If[LessEqual[x, 5.2e-139], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-69}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-139}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.80000000000000009e-69 or 5.1999999999999996e-139 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6481.6
Applied rewrites81.6%
Taylor expanded in y around 0
Applied rewrites51.6%
*-rgt-identity51.6
Applied rewrites51.6%
if -1.80000000000000009e-69 < x < 5.1999999999999996e-139Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6449.0
Applied rewrites49.0%
Taylor expanded in z around inf
lower-*.f6435.6
Applied rewrites35.6%
(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.4
Applied rewrites53.4%
(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 x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6461.4
Applied rewrites61.4%
Taylor expanded in y around 0
Applied rewrites39.9%
*-rgt-identity39.9
Applied rewrites39.9%
herbie shell --seed 2024219
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))