
(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 7 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 (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.8%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.9
Applied egg-rr99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -3.8e+210)
t_0
(if (<= y -0.015)
(* (cos y) z)
(if (<= y 0.035) (fma y (fma z (* y -0.5) x) z) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -3.8e+210) {
tmp = t_0;
} else if (y <= -0.015) {
tmp = cos(y) * z;
} else if (y <= 0.035) {
tmp = fma(y, fma(z, (y * -0.5), x), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -3.8e+210) tmp = t_0; elseif (y <= -0.015) tmp = Float64(cos(y) * z); elseif (y <= 0.035) tmp = fma(y, fma(z, Float64(y * -0.5), x), z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.8e+210], t$95$0, If[LessEqual[y, -0.015], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 0.035], N[(y * N[(z * N[(y * -0.5), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -3.8 \cdot 10^{+210}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.015:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;y \leq 0.035:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot -0.5, x\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.80000000000000028e210 or 0.035000000000000003 < y Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6456.0
Simplified56.0%
if -3.80000000000000028e210 < y < -0.014999999999999999Initial program 99.7%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6457.1
Simplified57.1%
if -0.014999999999999999 < y < 0.035000000000000003Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0
Simplified100.0%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) x z))) (if (<= x -4.8e-28) t_0 (if (<= x 2.2e-152) (* (cos y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), x, z);
double tmp;
if (x <= -4.8e-28) {
tmp = t_0;
} else if (x <= 2.2e-152) {
tmp = cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), x, z) tmp = 0.0 if (x <= -4.8e-28) tmp = t_0; elseif (x <= 2.2e-152) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision]}, If[LessEqual[x, -4.8e-28], t$95$0, If[LessEqual[x, 2.2e-152], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, x, z\right)\\
\mathbf{if}\;x \leq -4.8 \cdot 10^{-28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-152}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.8000000000000004e-28 or 2.19999999999999985e-152 < x Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.9
Applied egg-rr99.9%
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.9
Applied egg-rr99.9%
Taylor expanded in y around 0
Simplified88.2%
if -4.8000000000000004e-28 < x < 2.19999999999999985e-152Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6493.7
Simplified93.7%
Final simplification90.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -52000000.0)
t_0
(if (<= y 0.0054) (fma (* y (* z -0.5)) y (fma y x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -52000000.0) {
tmp = t_0;
} else if (y <= 0.0054) {
tmp = fma((y * (z * -0.5)), y, fma(y, x, z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -52000000.0) tmp = t_0; elseif (y <= 0.0054) tmp = fma(Float64(y * Float64(z * -0.5)), y, fma(y, x, z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -52000000.0], t$95$0, If[LessEqual[y, 0.0054], N[(N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision] * y + N[(y * x + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -52000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0054:\\
\;\;\;\;\mathsf{fma}\left(y \cdot \left(z \cdot -0.5\right), y, \mathsf{fma}\left(y, x, z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.2e7 or 0.0054000000000000003 < y Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6453.8
Simplified53.8%
if -5.2e7 < y < 0.0054000000000000003Initial program 100.0%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.7
Applied egg-rr99.7%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6497.6
Simplified97.6%
remove-double-divN/A
distribute-rgt-inN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f6497.8
Applied egg-rr97.8%
(FPCore (x y z) :precision binary64 (if (<= x 4.5e+191) z (* y x)))
double code(double x, double y, double z) {
double tmp;
if (x <= 4.5e+191) {
tmp = z;
} 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 <= 4.5d+191) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 4.5e+191) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 4.5e+191: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= 4.5e+191) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 4.5e+191) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 4.5e+191], z, N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.5 \cdot 10^{+191}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < 4.5000000000000002e191Initial program 99.8%
Taylor expanded in y around 0
Simplified43.1%
if 4.5000000000000002e191 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6475.2
Simplified75.2%
Taylor expanded in y around 0
*-lowering-*.f6434.8
Simplified34.8%
Final simplification42.2%
(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
accelerator-lowering-fma.f6451.2
Simplified51.2%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
Simplified40.3%
herbie shell --seed 2024198
(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))))