
(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.7%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.7
Applied egg-rr99.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) z x))) (if (<= z -1.02e-69) t_0 (if (<= z 2.9e-102) (* 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 <= -1.02e-69) {
tmp = t_0;
} else if (z <= 2.9e-102) {
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 <= -1.02e-69) tmp = t_0; elseif (z <= 2.9e-102) 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, -1.02e-69], t$95$0, If[LessEqual[z, 2.9e-102], 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 -1.02 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{-102}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.02000000000000005e-69 or 2.89999999999999986e-102 < z Initial program 99.7%
Taylor expanded in y around 0
Simplified83.5%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f6483.5
Applied egg-rr83.5%
if -1.02000000000000005e-69 < z < 2.89999999999999986e-102Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6491.6
Simplified91.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -1.7e-28) t_0 (if (<= x 1.6e-152) (* (sin y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.7e-28) {
tmp = t_0;
} else if (x <= 1.6e-152) {
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.7d-28)) then
tmp = t_0
else if (x <= 1.6d-152) 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.7e-28) {
tmp = t_0;
} else if (x <= 1.6e-152) {
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.7e-28: tmp = t_0 elif x <= 1.6e-152: 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.7e-28) tmp = t_0; elseif (x <= 1.6e-152) 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.7e-28) tmp = t_0; elseif (x <= 1.6e-152) 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.7e-28], t$95$0, If[LessEqual[x, 1.6e-152], 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.7 \cdot 10^{-28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-152}:\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.7e-28 or 1.60000000000000006e-152 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6480.3
Simplified80.3%
if -1.7e-28 < x < 1.60000000000000006e-152Initial program 99.7%
Taylor expanded in x around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6474.9
Simplified74.9%
Final simplification78.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -740.0)
t_0
(if (<= y 0.11)
(+
x
(*
z
(fma
(fma
y
(* y (fma (* y y) -0.0001984126984126984 0.008333333333333333))
-0.16666666666666666)
(* y (* y y))
y)))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -740.0) {
tmp = t_0;
} else if (y <= 0.11) {
tmp = x + (z * fma(fma(y, (y * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), (y * (y * y)), y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -740.0) tmp = t_0; elseif (y <= 0.11) tmp = Float64(x + Float64(z * fma(fma(y, Float64(y * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), Float64(y * Float64(y * y)), y))); 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, -740.0], t$95$0, If[LessEqual[y, 0.11], N[(x + N[(z * N[(N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -740:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.11:\\
\;\;\;\;x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -740 or 0.110000000000000001 < y Initial program 99.5%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6453.6
Simplified53.6%
if -740 < y < 0.110000000000000001Initial program 100.0%
Taylor expanded in y around 0
Simplified100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
Simplified98.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.5e+186) (* y z) (if (<= z 2.4e+135) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.5e+186) {
tmp = y * z;
} else if (z <= 2.4e+135) {
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 <= (-1.5d+186)) then
tmp = y * z
else if (z <= 2.4d+135) 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 <= -1.5e+186) {
tmp = y * z;
} else if (z <= 2.4e+135) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.5e+186: tmp = y * z elif z <= 2.4e+135: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.5e+186) tmp = Float64(y * z); elseif (z <= 2.4e+135) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.5e+186) tmp = y * z; elseif (z <= 2.4e+135) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.5e+186], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.4e+135], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+186}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{+135}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.49999999999999991e186 or 2.39999999999999997e135 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6448.5
Simplified48.5%
Taylor expanded in z around inf
*-commutativeN/A
*-lowering-*.f6433.8
Simplified33.8%
if -1.49999999999999991e186 < z < 2.39999999999999997e135Initial program 99.7%
Taylor expanded in y around 0
Simplified45.6%
Final simplification42.7%
(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.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6451.1
Simplified51.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.7%
Taylor expanded in y around 0
Simplified38.5%
herbie shell --seed 2024198
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))