
(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%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 1.0 z (* x (sin y))))) (if (<= x -6e-61) t_0 (if (<= x 2.7e-17) (* (cos y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(1.0, z, (x * sin(y)));
double tmp;
if (x <= -6e-61) {
tmp = t_0;
} else if (x <= 2.7e-17) {
tmp = cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(1.0, z, Float64(x * sin(y))) tmp = 0.0 if (x <= -6e-61) tmp = t_0; elseif (x <= 2.7e-17) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6e-61], t$95$0, If[LessEqual[x, 2.7e-17], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{if}\;x \leq -6 \cdot 10^{-61}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-17}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.00000000000000024e-61 or 2.7000000000000001e-17 < x Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites90.7%
if -6.00000000000000024e-61 < x < 2.7000000000000001e-17Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6491.4
Applied rewrites91.4%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (cos y) z))) (if (<= z -4.2e-128) t_0 (if (<= z 1.65e-65) (* x (sin y)) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double tmp;
if (z <= -4.2e-128) {
tmp = t_0;
} else if (z <= 1.65e-65) {
tmp = x * sin(y);
} 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 = cos(y) * z
if (z <= (-4.2d-128)) then
tmp = t_0
else if (z <= 1.65d-65) then
tmp = x * sin(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.cos(y) * z;
double tmp;
if (z <= -4.2e-128) {
tmp = t_0;
} else if (z <= 1.65e-65) {
tmp = x * Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * z tmp = 0 if z <= -4.2e-128: tmp = t_0 elif z <= 1.65e-65: tmp = x * math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * z) tmp = 0.0 if (z <= -4.2e-128) tmp = t_0; elseif (z <= 1.65e-65) tmp = Float64(x * sin(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = cos(y) * z; tmp = 0.0; if (z <= -4.2e-128) tmp = t_0; elseif (z <= 1.65e-65) tmp = x * sin(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -4.2e-128], t$95$0, If[LessEqual[z, 1.65e-65], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
\mathbf{if}\;z \leq -4.2 \cdot 10^{-128}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{-65}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.2000000000000002e-128 or 1.6500000000000001e-65 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6480.6
Applied rewrites80.6%
if -4.2000000000000002e-128 < z < 1.6500000000000001e-65Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6480.5
Applied rewrites80.5%
Final simplification80.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.025)
t_0
(if (<= y 0.078) (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 <= -0.025) {
tmp = t_0;
} else if (y <= 0.078) {
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 <= -0.025) tmp = t_0; elseif (y <= 0.078) 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, -0.025], t$95$0, If[LessEqual[y, 0.078], 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 -0.025:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.078:\\
\;\;\;\;\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 < -0.025000000000000001 or 0.0779999999999999999 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6450.5
Applied rewrites50.5%
if -0.025000000000000001 < y < 0.0779999999999999999Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= z -8e-163) z (if (<= z 1.6e-66) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8e-163) {
tmp = z;
} else if (z <= 1.6e-66) {
tmp = y * x;
} else {
tmp = 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 <= (-8d-163)) then
tmp = z
else if (z <= 1.6d-66) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -8e-163) {
tmp = z;
} else if (z <= 1.6e-66) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8e-163: tmp = z elif z <= 1.6e-66: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8e-163) tmp = z; elseif (z <= 1.6e-66) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8e-163) tmp = z; elseif (z <= 1.6e-66) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8e-163], z, If[LessEqual[z, 1.6e-66], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-163}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-66}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -7.99999999999999939e-163 or 1.59999999999999991e-66 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6479.9
Applied rewrites79.9%
Taylor expanded in y around 0
Applied rewrites50.9%
*-rgt-identity50.9
Applied rewrites50.9%
if -7.99999999999999939e-163 < z < 1.59999999999999991e-66Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6445.7
Applied rewrites45.7%
Taylor expanded in y around inf
lower-*.f6434.6
Applied rewrites34.6%
Final simplification45.5%
(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
lower-fma.f6453.4
Applied rewrites53.4%
(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 x around 0
lower-*.f64N/A
lower-cos.f6460.6
Applied rewrites60.6%
Taylor expanded in y around 0
Applied rewrites38.7%
*-rgt-identity38.7
Applied rewrites38.7%
herbie shell --seed 2024219
(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))))