
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) x (* z (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), x, (z * cos(y)));
}
function code(x, y, z) return fma(sin(y), x, Float64(z * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos 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 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) * x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/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 (* (sin y) x)) (t_1 (* z (cos y))))
(if (<= y -8.5e+217)
t_0
(if (<= y -0.0085)
t_1
(if (<= y 0.00055)
(fma y (fma y (fma z -0.5 (* x (* y -0.16666666666666666))) x) z)
(if (<= y 4.6e+88) t_1 (if (<= y 8.2e+245) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double t_1 = z * cos(y);
double tmp;
if (y <= -8.5e+217) {
tmp = t_0;
} else if (y <= -0.0085) {
tmp = t_1;
} else if (y <= 0.00055) {
tmp = fma(y, fma(y, fma(z, -0.5, (x * (y * -0.16666666666666666))), x), z);
} else if (y <= 4.6e+88) {
tmp = t_1;
} else if (y <= 8.2e+245) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) t_1 = Float64(z * cos(y)) tmp = 0.0 if (y <= -8.5e+217) tmp = t_0; elseif (y <= -0.0085) tmp = t_1; elseif (y <= 0.00055) tmp = fma(y, fma(y, fma(z, -0.5, Float64(x * Float64(y * -0.16666666666666666))), x), z); elseif (y <= 4.6e+88) tmp = t_1; elseif (y <= 8.2e+245) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.5e+217], t$95$0, If[LessEqual[y, -0.0085], t$95$1, If[LessEqual[y, 0.00055], N[(y * N[(y * N[(z * -0.5 + N[(x * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[y, 4.6e+88], t$95$1, If[LessEqual[y, 8.2e+245], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
t_1 := z \cdot \cos y\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+217}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.0085:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.00055:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, -0.5, x \cdot \left(y \cdot -0.16666666666666666\right)\right), x\right), z\right)\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{+88}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+245}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.50000000000000021e217 or 4.6000000000000003e88 < y < 8.2000000000000001e245Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6464.7
Applied rewrites64.7%
if -8.50000000000000021e217 < y < -0.0085000000000000006 or 5.50000000000000033e-4 < y < 4.6000000000000003e88 or 8.2000000000000001e245 < y Initial program 99.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6472.0
Applied rewrites72.0%
if -0.0085000000000000006 < 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-fma.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -1.5e+62) t_0 (if (<= z 1.5e+41) (fma (sin y) x (* z 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -1.5e+62) {
tmp = t_0;
} else if (z <= 1.5e+41) {
tmp = fma(sin(y), x, (z * 1.0));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -1.5e+62) tmp = t_0; elseif (z <= 1.5e+41) tmp = fma(sin(y), x, Float64(z * 1.0)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.5e+62], t$95$0, If[LessEqual[z, 1.5e+41], N[(N[Sin[y], $MachinePrecision] * x + N[(z * 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -1.5 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+41}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z \cdot 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.5e62 or 1.4999999999999999e41 < z Initial program 99.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6492.5
Applied rewrites92.5%
if -1.5e62 < z < 1.4999999999999999e41Initial 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.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -22000000000.0)
t_0
(if (<= y 7000.0)
(fma y (fma y (fma z -0.5 (* x (* y -0.16666666666666666))) x) z)
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -22000000000.0) {
tmp = t_0;
} else if (y <= 7000.0) {
tmp = fma(y, fma(y, fma(z, -0.5, (x * (y * -0.16666666666666666))), x), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -22000000000.0) tmp = t_0; elseif (y <= 7000.0) tmp = fma(y, fma(y, fma(z, -0.5, Float64(x * Float64(y * -0.16666666666666666))), x), z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -22000000000.0], t$95$0, If[LessEqual[y, 7000.0], N[(y * N[(y * N[(z * -0.5 + N[(x * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -22000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7000:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, -0.5, x \cdot \left(y \cdot -0.16666666666666666\right)\right), x\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.2e10 or 7e3 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6448.6
Applied rewrites48.6%
if -2.2e10 < y < 7e3Initial 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
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6496.7
Applied rewrites96.7%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (if (<= x 5.2e+148) (* z 1.0) (* y x)))
double code(double x, double y, double z) {
double tmp;
if (x <= 5.2e+148) {
tmp = z * 1.0;
} else {
tmp = y * 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 <= 5.2d+148) then
tmp = z * 1.0d0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 5.2e+148) {
tmp = z * 1.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 5.2e+148: tmp = z * 1.0 else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= 5.2e+148) tmp = Float64(z * 1.0); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 5.2e+148) tmp = z * 1.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 5.2e+148], N[(z * 1.0), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.2 \cdot 10^{+148}:\\
\;\;\;\;z \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < 5.2e148Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6467.1
Applied rewrites67.1%
Taylor expanded in y around 0
Applied rewrites42.3%
if 5.2e148 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6459.7
Applied rewrites59.7%
Taylor expanded in y around inf
Applied rewrites47.5%
Final simplification42.9%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.0
Applied rewrites53.0%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.0
Applied rewrites53.0%
Taylor expanded in y around inf
Applied rewrites17.8%
Final simplification17.8%
herbie shell --seed 2024232
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))