
(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 8 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
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) * x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -0.75)
t_0
(if (<= y 0.48)
(+
(*
x
(fma
(fma
y
(* y (fma (* y y) -0.0001984126984126984 0.008333333333333333))
-0.16666666666666666)
(* y (* y y))
y))
(fma
(* z (* y y))
(fma
(* y y)
(fma y (* y -0.001388888888888889) 0.041666666666666664)
-0.5)
z))
(if (<= y 3.1e+63) t_0 (* z (cos y)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -0.75) {
tmp = t_0;
} else if (y <= 0.48) {
tmp = (x * fma(fma(y, (y * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), (y * (y * y)), y)) + fma((z * (y * y)), fma((y * y), fma(y, (y * -0.001388888888888889), 0.041666666666666664), -0.5), z);
} else if (y <= 3.1e+63) {
tmp = t_0;
} else {
tmp = z * cos(y);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -0.75) tmp = t_0; elseif (y <= 0.48) tmp = Float64(Float64(x * fma(fma(y, Float64(y * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), Float64(y * Float64(y * y)), y)) + fma(Float64(z * Float64(y * y)), fma(Float64(y * y), fma(y, Float64(y * -0.001388888888888889), 0.041666666666666664), -0.5), z)); elseif (y <= 3.1e+63) tmp = t_0; else tmp = Float64(z * cos(y)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.75], t$95$0, If[LessEqual[y, 0.48], N[(N[(x * 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] + N[(N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * -0.001388888888888889), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.1e+63], t$95$0, N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -0.75:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.48:\\
\;\;\;\;x \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) + \mathsf{fma}\left(z \cdot \left(y \cdot y\right), \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot -0.001388888888888889, 0.041666666666666664\right), -0.5\right), z\right)\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if y < -0.75 or 0.47999999999999998 < y < 3.1000000000000001e63Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6463.5
Applied rewrites63.5%
if -0.75 < y < 0.47999999999999998Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
Applied rewrites99.7%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
lower-fma.f64N/A
Applied rewrites99.7%
if 3.1000000000000001e63 < y Initial program 99.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6472.8
Applied rewrites72.8%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -2.6e+98) t_0 (if (<= z 5.6e-30) (fma (sin y) x (* z 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.6e+98) {
tmp = t_0;
} else if (z <= 5.6e-30) {
tmp = fma(sin(y), x, (z * 1.0));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.6e+98) tmp = t_0; elseif (z <= 5.6e-30) tmp = fma(sin(y), x, Float64(z * 1.0)); 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, -2.6e+98], t$95$0, If[LessEqual[z, 5.6e-30], N[(N[Sin[y], $MachinePrecision] * x + N[(z * 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.6 \cdot 10^{+98}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{-30}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z \cdot 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.6e98 or 5.59999999999999977e-30 < z Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6485.7
Applied rewrites85.7%
if -2.6e98 < z < 5.59999999999999977e-30Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites89.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -0.75)
t_0
(if (<= y 0.48)
(+
(*
x
(fma
(fma
y
(* y (fma (* y y) -0.0001984126984126984 0.008333333333333333))
-0.16666666666666666)
(* y (* y y))
y))
(fma
(* z (* y y))
(fma
(* y y)
(fma y (* y -0.001388888888888889) 0.041666666666666664)
-0.5)
z))
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -0.75) {
tmp = t_0;
} else if (y <= 0.48) {
tmp = (x * fma(fma(y, (y * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), (y * (y * y)), y)) + fma((z * (y * y)), fma((y * y), fma(y, (y * -0.001388888888888889), 0.041666666666666664), -0.5), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -0.75) tmp = t_0; elseif (y <= 0.48) tmp = Float64(Float64(x * fma(fma(y, Float64(y * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), Float64(y * Float64(y * y)), y)) + fma(Float64(z * Float64(y * y)), fma(Float64(y * y), fma(y, Float64(y * -0.001388888888888889), 0.041666666666666664), -0.5), z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.75], t$95$0, If[LessEqual[y, 0.48], N[(N[(x * 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] + N[(N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * -0.001388888888888889), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -0.75:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.48:\\
\;\;\;\;x \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) + \mathsf{fma}\left(z \cdot \left(y \cdot y\right), \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot -0.001388888888888889, 0.041666666666666664\right), -0.5\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.75 or 0.47999999999999998 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6450.2
Applied rewrites50.2%
if -0.75 < y < 0.47999999999999998Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
Applied rewrites99.7%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
lower-fma.f64N/A
Applied rewrites99.7%
Final simplification74.8%
(FPCore (x y z) :precision binary64 (if (<= z -9.8e-110) (* z 1.0) (if (<= z 7.1e-143) (* y x) (* z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.8e-110) {
tmp = z * 1.0;
} else if (z <= 7.1e-143) {
tmp = y * x;
} else {
tmp = z * 1.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) :: tmp
if (z <= (-9.8d-110)) then
tmp = z * 1.0d0
else if (z <= 7.1d-143) then
tmp = y * x
else
tmp = z * 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9.8e-110) {
tmp = z * 1.0;
} else if (z <= 7.1e-143) {
tmp = y * x;
} else {
tmp = z * 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.8e-110: tmp = z * 1.0 elif z <= 7.1e-143: tmp = y * x else: tmp = z * 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.8e-110) tmp = Float64(z * 1.0); elseif (z <= 7.1e-143) tmp = Float64(y * x); else tmp = Float64(z * 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.8e-110) tmp = z * 1.0; elseif (z <= 7.1e-143) tmp = y * x; else tmp = z * 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.8e-110], N[(z * 1.0), $MachinePrecision], If[LessEqual[z, 7.1e-143], N[(y * x), $MachinePrecision], N[(z * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.8 \cdot 10^{-110}:\\
\;\;\;\;z \cdot 1\\
\mathbf{elif}\;z \leq 7.1 \cdot 10^{-143}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot 1\\
\end{array}
\end{array}
if z < -9.7999999999999995e-110 or 7.10000000000000033e-143 < z Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6475.9
Applied rewrites75.9%
Taylor expanded in y around 0
Applied rewrites47.0%
if -9.7999999999999995e-110 < z < 7.10000000000000033e-143Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6452.4
Applied rewrites52.4%
Taylor expanded in y around inf
Applied rewrites36.6%
Final simplification43.8%
(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.f6451.5
Applied rewrites51.5%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.5
Applied rewrites51.5%
Taylor expanded in y around inf
Applied rewrites17.0%
Final simplification17.0%
herbie shell --seed 2024220
(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))))