
(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 8 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 egg-rr99.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-cos.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) z x))) (if (<= z -2.45e-130) t_0 (if (<= z 3.8e-113) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), z, x);
double tmp;
if (z <= -2.45e-130) {
tmp = t_0;
} else if (z <= 3.8e-113) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), z, x) tmp = 0.0 if (z <= -2.45e-130) tmp = t_0; elseif (z <= 3.8e-113) 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 + x), $MachinePrecision]}, If[LessEqual[z, -2.45e-130], t$95$0, If[LessEqual[z, 3.8e-113], 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\right)\\
\mathbf{if}\;z \leq -2.45 \cdot 10^{-130}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-113}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.45000000000000009e-130 or 3.79999999999999983e-113 < 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
Simplified90.3%
if -2.45000000000000009e-130 < z < 3.79999999999999983e-113Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6496.9
Simplified96.9%
Final simplification92.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) z)))
(if (<= y -0.0046)
t_0
(if (<= y 0.5)
(fma y (fma y (fma x -0.5 (* -0.16666666666666666 (* y z))) z) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double tmp;
if (y <= -0.0046) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = fma(y, fma(y, fma(x, -0.5, (-0.16666666666666666 * (y * z))), z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * z) tmp = 0.0 if (y <= -0.0046) tmp = t_0; elseif (y <= 0.5) tmp = fma(y, fma(y, fma(x, -0.5, Float64(-0.16666666666666666 * Float64(y * z))), z), x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -0.0046], t$95$0, If[LessEqual[y, 0.5], N[(y * N[(y * N[(x * -0.5 + N[(-0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
\mathbf{if}\;y \leq -0.0046:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, -0.5, -0.16666666666666666 \cdot \left(y \cdot z\right)\right), z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0045999999999999999 or 0.5 < y Initial program 99.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6459.8
Simplified59.8%
if -0.0045999999999999999 < y < 0.5Initial 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.4
Simplified99.4%
Final simplification80.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -75000000.0)
t_0
(if (<= y 0.088)
(fma y (fma y (fma x -0.5 (* -0.16666666666666666 (* y z))) z) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -75000000.0) {
tmp = t_0;
} else if (y <= 0.088) {
tmp = fma(y, fma(y, fma(x, -0.5, (-0.16666666666666666 * (y * z))), z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -75000000.0) tmp = t_0; elseif (y <= 0.088) tmp = fma(y, fma(y, fma(x, -0.5, Float64(-0.16666666666666666 * Float64(y * z))), 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, -75000000.0], t$95$0, If[LessEqual[y, 0.088], N[(y * N[(y * N[(x * -0.5 + N[(-0.16666666666666666 * N[(y * z), $MachinePrecision]), $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 -75000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.088:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, -0.5, -0.16666666666666666 \cdot \left(y \cdot z\right)\right), z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.5e7 or 0.087999999999999995 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6443.4
Simplified43.4%
if -7.5e7 < y < 0.087999999999999995Initial 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-*.f6497.0
Simplified97.0%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (<= z -2e+115) (* y z) (if (<= z 4e+258) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e+115) {
tmp = y * z;
} else if (z <= 4e+258) {
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 <= (-2d+115)) then
tmp = y * z
else if (z <= 4d+258) 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 <= -2e+115) {
tmp = y * z;
} else if (z <= 4e+258) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2e+115: tmp = y * z elif z <= 4e+258: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2e+115) tmp = Float64(y * z); elseif (z <= 4e+258) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2e+115) tmp = y * z; elseif (z <= 4e+258) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2e+115], N[(y * z), $MachinePrecision], If[LessEqual[z, 4e+258], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{+115}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+258}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2e115 or 4.00000000000000023e258 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6447.9
Simplified47.9%
Taylor expanded in z around inf
lower-*.f6437.4
Simplified37.4%
if -2e115 < z < 4.00000000000000023e258Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6468.5
Simplified68.5%
Taylor expanded in y around 0
Simplified49.4%
*-rgt-identity49.4
Applied egg-rr49.4%
(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.1
Simplified55.1%
(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.f6456.3
Simplified56.3%
Taylor expanded in y around 0
Simplified40.0%
*-rgt-identity40.0
Applied egg-rr40.0%
herbie shell --seed 2024207
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))