
(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 6 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-cos.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied egg-rr99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))))
(if (<= y -0.32)
t_0
(if (<= y 0.08)
(fma
(fma
(* y y)
(fma
(* y y)
(fma (* y y) -0.001388888888888889 0.041666666666666664)
-0.5)
1.0)
x
(* y z))
(if (<= y 3.65e+193) t_0 (* (cos y) x))))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (y <= -0.32) {
tmp = t_0;
} else if (y <= 0.08) {
tmp = fma(fma((y * y), fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, (y * z));
} else if (y <= 3.65e+193) {
tmp = t_0;
} else {
tmp = cos(y) * x;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (y <= -0.32) tmp = t_0; elseif (y <= 0.08) tmp = fma(fma(Float64(y * y), fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, Float64(y * z)); elseif (y <= 3.65e+193) tmp = t_0; else tmp = Float64(cos(y) * x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.32], t$95$0, If[LessEqual[y, 0.08], N[(N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.65e+193], t$95$0, N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;y \leq -0.32:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.08:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot z\right)\\
\mathbf{elif}\;y \leq 3.65 \cdot 10^{+193}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if y < -0.320000000000000007 or 0.0800000000000000017 < y < 3.6500000000000001e193Initial program 99.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6458.3
Simplified58.3%
if -0.320000000000000007 < y < 0.0800000000000000017Initial program 100.0%
lift-cos.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied egg-rr100.0%
Taylor expanded in y around 0
lower-*.f6499.4
Simplified99.4%
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.4
Simplified99.4%
if 3.6500000000000001e193 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6468.6
Simplified68.6%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) z x))) (if (<= z -3e-16) t_0 (if (<= z 8.5e-147) (* (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), z, x);
double tmp;
if (z <= -3e-16) {
tmp = t_0;
} else if (z <= 8.5e-147) {
tmp = cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), z, x) tmp = 0.0 if (z <= -3e-16) tmp = t_0; elseif (z <= 8.5e-147) tmp = Float64(cos(y) * x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -3e-16], t$95$0, If[LessEqual[z, 8.5e-147], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, z, x\right)\\
\mathbf{if}\;z \leq -3 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-147}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.99999999999999994e-16 or 8.5000000000000002e-147 < z 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 egg-rr99.8%
Taylor expanded in y around 0
Simplified89.1%
*-rgt-identity89.1
Applied egg-rr89.1%
if -2.99999999999999994e-16 < z < 8.5000000000000002e-147Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6489.5
Simplified89.5%
Final simplification89.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -170000.0)
t_0
(if (<= y 0.045)
(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 <= -170000.0) {
tmp = t_0;
} else if (y <= 0.045) {
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 <= -170000.0) tmp = t_0; elseif (y <= 0.045) 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, -170000.0], t$95$0, If[LessEqual[y, 0.045], 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 -170000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.045:\\
\;\;\;\;\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 < -1.7e5 or 0.044999999999999998 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6446.7
Simplified46.7%
if -1.7e5 < y < 0.044999999999999998Initial 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.0
Simplified99.0%
Final simplification74.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.f6455.0
Simplified55.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 x around 0
lower-*.f64N/A
lower-sin.f6440.0
Simplified40.0%
Taylor expanded in y around 0
lower-*.f6415.9
Simplified15.9%
herbie shell --seed 2024208
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))