
(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 9 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
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) x (* (sin y) z)))
double code(double x, double y, double z) {
return fma(cos(y), x, (sin(y) * z));
}
function code(x, y, z) return fma(cos(y), x, Float64(sin(y) * z)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, \sin y \cdot z\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))) (t_1 (* (sin y) z)))
(if (<= y -5.4e+228)
t_0
(if (<= y -0.04)
t_1
(if (<= y 0.00055)
(fma y (fma -0.5 (* y x) z) x)
(if (<= y 1.85e+87) t_1 (if (<= y 3.1e+245) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = sin(y) * z;
double tmp;
if (y <= -5.4e+228) {
tmp = t_0;
} else if (y <= -0.04) {
tmp = t_1;
} else if (y <= 0.00055) {
tmp = fma(y, fma(-0.5, (y * x), z), x);
} else if (y <= 1.85e+87) {
tmp = t_1;
} else if (y <= 3.1e+245) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(sin(y) * z) tmp = 0.0 if (y <= -5.4e+228) tmp = t_0; elseif (y <= -0.04) tmp = t_1; elseif (y <= 0.00055) tmp = fma(y, fma(-0.5, Float64(y * x), z), x); elseif (y <= 1.85e+87) tmp = t_1; elseif (y <= 3.1e+245) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -5.4e+228], t$95$0, If[LessEqual[y, -0.04], t$95$1, If[LessEqual[y, 0.00055], N[(y * N[(-0.5 * N[(y * x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 1.85e+87], t$95$1, If[LessEqual[y, 3.1e+245], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := \sin y \cdot z\\
\mathbf{if}\;y \leq -5.4 \cdot 10^{+228}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.04:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.00055:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(-0.5, y \cdot x, z\right), x\right)\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+87}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+245}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -5.4000000000000003e228 or 1.85000000000000001e87 < y < 3.0999999999999999e245Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6465.4
Applied rewrites65.4%
if -5.4000000000000003e228 < y < -0.0400000000000000008 or 5.50000000000000033e-4 < y < 1.85000000000000001e87 or 3.0999999999999999e245 < y Initial program 99.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6470.8
Applied rewrites70.8%
if -0.0400000000000000008 < y < 5.50000000000000033e-4Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) z (* x 1.0)))) (if (<= z -5.9e-27) t_0 (if (<= z 860000000.0) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), z, (x * 1.0));
double tmp;
if (z <= -5.9e-27) {
tmp = t_0;
} else if (z <= 860000000.0) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), z, Float64(x * 1.0)) tmp = 0.0 if (z <= -5.9e-27) tmp = t_0; elseif (z <= 860000000.0) 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[(x * 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.9e-27], t$95$0, If[LessEqual[z, 860000000.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, z, x \cdot 1\right)\\
\mathbf{if}\;z \leq -5.9 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 860000000:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.8999999999999998e-27 or 8.6e8 < z Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites92.2%
if -5.8999999999999998e-27 < z < 8.6e8Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6482.5
Applied rewrites82.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 1.0 x (* (sin y) z)))) (if (<= z -5.9e-27) t_0 (if (<= z 860000000.0) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(1.0, x, (sin(y) * z));
double tmp;
if (z <= -5.9e-27) {
tmp = t_0;
} else if (z <= 860000000.0) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(1.0, x, Float64(sin(y) * z)) tmp = 0.0 if (z <= -5.9e-27) tmp = t_0; elseif (z <= 860000000.0) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * x + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.9e-27], t$95$0, If[LessEqual[z, 860000000.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, x, \sin y \cdot z\right)\\
\mathbf{if}\;z \leq -5.9 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 860000000:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.8999999999999998e-27 or 8.6e8 < z Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites92.2%
if -5.8999999999999998e-27 < z < 8.6e8Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6482.5
Applied rewrites82.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -22000000000.0)
t_0
(if (<= y 1300000.0)
(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 <= -22000000000.0) {
tmp = t_0;
} else if (y <= 1300000.0) {
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 <= -22000000000.0) tmp = t_0; elseif (y <= 1300000.0) 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, -22000000000.0], t$95$0, If[LessEqual[y, 1300000.0], 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 -22000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1300000:\\
\;\;\;\;\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 < -2.2e10 or 1.3e6 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6449.2
Applied rewrites49.2%
if -2.2e10 < y < 1.3e6Initial program 99.9%
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-*.f6495.4
Applied rewrites95.4%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (if (<= z -6.5e+74) (* y z) (if (<= z 1.6e+166) (* x 1.0) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.5e+74) {
tmp = y * z;
} else if (z <= 1.6e+166) {
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+74)) then
tmp = y * z
else if (z <= 1.6d+166) 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+74) {
tmp = y * z;
} else if (z <= 1.6e+166) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.5e+74: tmp = y * z elif z <= 1.6e+166: tmp = x * 1.0 else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.5e+74) tmp = Float64(y * z); elseif (z <= 1.6e+166) 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+74) tmp = y * z; elseif (z <= 1.6e+166) tmp = x * 1.0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.5e+74], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.6e+166], N[(x * 1.0), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+74}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+166}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -6.49999999999999962e74 or 1.59999999999999984e166 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6445.9
Applied rewrites45.9%
Taylor expanded in z around inf
Applied rewrites37.1%
if -6.49999999999999962e74 < z < 1.59999999999999984e166Initial program 99.8%
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.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
Applied rewrites48.1%
(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.8
Applied rewrites52.8%
(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.8
Applied rewrites52.8%
Taylor expanded in z around inf
Applied rewrites18.4%
herbie shell --seed 2024232
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))