
(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 (sin y) x (* z (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), x, (z * cos(y)));
}
function code(x, y, z) return fma(sin(y), x, Float64(z * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -8.2e+44) t_0 (if (<= z 4.5e+68) (fma (sin y) x (* 1.0 z)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -8.2e+44) {
tmp = t_0;
} else if (z <= 4.5e+68) {
tmp = fma(sin(y), x, (1.0 * z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -8.2e+44) tmp = t_0; elseif (z <= 4.5e+68) tmp = fma(sin(y), x, Float64(1.0 * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -8.2e+44], t$95$0, If[LessEqual[z, 4.5e+68], N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -8.2 \cdot 10^{+44}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+68}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.1999999999999993e44 or 4.5000000000000003e68 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6491.3
Applied rewrites91.3%
if -8.1999999999999993e44 < z < 4.5000000000000003e68Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites87.0%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (sin y)))) (if (<= x -2.8e+122) t_0 (if (<= x 5.4e+146) (* z (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (x <= -2.8e+122) {
tmp = t_0;
} else if (x <= 5.4e+146) {
tmp = z * cos(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 = x * sin(y)
if (x <= (-2.8d+122)) then
tmp = t_0
else if (x <= 5.4d+146) then
tmp = z * cos(y)
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.sin(y);
double tmp;
if (x <= -2.8e+122) {
tmp = t_0;
} else if (x <= 5.4e+146) {
tmp = z * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if x <= -2.8e+122: tmp = t_0 elif x <= 5.4e+146: tmp = z * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (x <= -2.8e+122) tmp = t_0; elseif (x <= 5.4e+146) tmp = Float64(z * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (x <= -2.8e+122) tmp = t_0; elseif (x <= 5.4e+146) tmp = z * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.8e+122], t$95$0, If[LessEqual[x, 5.4e+146], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;x \leq -2.8 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.4 \cdot 10^{+146}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.8e122 or 5.39999999999999977e146 < x Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6470.8
Applied rewrites70.8%
if -2.8e122 < x < 5.39999999999999977e146Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6481.9
Applied rewrites81.9%
Final simplification78.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= y -2200000.0) t_0 (if (<= y 0.000155) (fma y x z) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -2200000.0) {
tmp = t_0;
} else if (y <= 0.000155) {
tmp = fma(y, x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -2200000.0) tmp = t_0; elseif (y <= 0.000155) tmp = fma(y, x, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2200000.0], t$95$0, If[LessEqual[y, 0.000155], N[(y * x + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -2200000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.000155:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.2e6 or 1.55e-4 < y Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6456.8
Applied rewrites56.8%
if -2.2e6 < y < 1.55e-4Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (<= x 3.2e+147) (* 1.0 z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.2e+147) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
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 <= 3.2d+147) then
tmp = 1.0d0 * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 3.2e+147) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3.2e+147: tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3.2e+147) tmp = Float64(1.0 * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 3.2e+147) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3.2e+147], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.2 \cdot 10^{+147}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 3.19999999999999979e147Initial program 99.8%
lift-+.f64N/A
flip-+N/A
clear-numN/A
associate-/r/N/A
flip3--N/A
clear-numN/A
Applied rewrites54.1%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6495.8
Applied rewrites95.8%
Taylor expanded in y around 0
Applied rewrites42.6%
if 3.19999999999999979e147 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6449.2
Applied rewrites49.2%
Taylor expanded in z around 0
Applied rewrites34.6%
Final simplification41.4%
(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.f6448.7
Applied rewrites48.7%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * 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 * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6448.7
Applied rewrites48.7%
Taylor expanded in z around 0
Applied rewrites13.6%
Final simplification13.6%
herbie shell --seed 2024267
(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))))