
(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.8
Applied egg-rr99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.0057)
t_0
(if (<= y 0.0026)
(fma y (fma z (* y -0.5) x) z)
(if (<= y 1e+238) t_0 (* (cos y) z))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.0057) {
tmp = t_0;
} else if (y <= 0.0026) {
tmp = fma(y, fma(z, (y * -0.5), x), z);
} else if (y <= 1e+238) {
tmp = t_0;
} else {
tmp = cos(y) * z;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -0.0057) tmp = t_0; elseif (y <= 0.0026) tmp = fma(y, fma(z, Float64(y * -0.5), x), z); elseif (y <= 1e+238) tmp = t_0; else tmp = Float64(cos(y) * z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0057], t$95$0, If[LessEqual[y, 0.0026], N[(y * N[(z * N[(y * -0.5), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[y, 1e+238], t$95$0, N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -0.0057:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0026:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot -0.5, x\right), z\right)\\
\mathbf{elif}\;y \leq 10^{+238}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if y < -0.0057000000000000002 or 0.0025999999999999999 < y < 1e238Initial program 99.5%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f6456.2
Simplified56.2%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
sin-lowering-sin.f6456.2
Applied egg-rr56.2%
if -0.0057000000000000002 < y < 0.0025999999999999999Initial 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%
if 1e238 < y Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6469.7
Simplified69.7%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) x z))) (if (<= x -4.4e-71) t_0 (if (<= x 1.45e-77) (* (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.4e-71) {
tmp = t_0;
} else if (x <= 1.45e-77) {
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.4e-71) tmp = t_0; elseif (x <= 1.45e-77) 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.4e-71], t$95$0, If[LessEqual[x, 1.45e-77], 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.4 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-77}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.39999999999999995e-71 or 1.4499999999999999e-77 < x Initial program 99.8%
Taylor expanded in y around 0
Simplified87.9%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f6487.9
Applied egg-rr87.9%
if -4.39999999999999995e-71 < x < 1.4499999999999999e-77Initial program 99.7%
+-commutativeN/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 z around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6492.7
Simplified92.7%
Final simplification89.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)))
(if (<= y -43.0)
t_0
(if (<= y 0.5)
(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 = cos(y) * z;
double tmp;
if (y <= -43.0) {
tmp = t_0;
} else if (y <= 0.5) {
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(cos(y) * z) tmp = 0.0 if (y <= -43.0) tmp = t_0; elseif (y <= 0.5) 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[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -43.0], t$95$0, If[LessEqual[y, 0.5], 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 := \cos y \cdot z\\
\mathbf{if}\;y \leq -43:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;\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 < -43 or 0.5 < y Initial program 99.6%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.6
Applied egg-rr99.6%
Taylor expanded in z around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6448.2
Simplified48.2%
if -43 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6498.7
Simplified98.7%
Final simplification73.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.3e+190) (* y x) (if (<= x 6.2e+199) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+190) {
tmp = y * x;
} else if (x <= 6.2e+199) {
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 <= (-1.3d+190)) then
tmp = y * x
else if (x <= 6.2d+199) 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 <= -1.3e+190) {
tmp = y * x;
} else if (x <= 6.2e+199) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+190: tmp = y * x elif x <= 6.2e+199: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+190) tmp = Float64(y * x); elseif (x <= 6.2e+199) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e+190) tmp = y * x; elseif (x <= 6.2e+199) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+190], N[(y * x), $MachinePrecision], If[LessEqual[x, 6.2e+199], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+190}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{+199}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.30000000000000005e190 or 6.19999999999999971e199 < x Initial program 99.8%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f6488.0
Simplified88.0%
Taylor expanded in y around 0
*-lowering-*.f6445.7
Simplified45.7%
if -1.30000000000000005e190 < x < 6.19999999999999971e199Initial program 99.7%
Taylor expanded in y around 0
Simplified40.9%
Final simplification41.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
accelerator-lowering-fma.f6451.8
Simplified51.8%
(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
Simplified35.1%
herbie shell --seed 2024195
(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))))