
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f6499.9
Simplified99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma z (sin y) x))) (if (<= z -1.7e+14) t_0 (if (<= z 5.6e-32) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(z, sin(y), x);
double tmp;
if (z <= -1.7e+14) {
tmp = t_0;
} else if (z <= 5.6e-32) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(z, sin(y), x) tmp = 0.0 if (z <= -1.7e+14) tmp = t_0; elseif (z <= 5.6e-32) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -1.7e+14], t$95$0, If[LessEqual[z, 5.6e-32], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(z, \sin y, x\right)\\
\mathbf{if}\;z \leq -1.7 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{-32}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.7e14 or 5.5999999999999998e-32 < z Initial program 99.8%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f6499.8
Simplified99.8%
Taylor expanded in y around 0
Simplified91.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-sin.f6491.0
Simplified91.0%
if -1.7e14 < z < 5.5999999999999998e-32Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6487.0
Simplified87.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (sin y)))) (if (<= z -9.2e+141) t_0 (if (<= z 6.8e+86) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (z <= -9.2e+141) {
tmp = t_0;
} else if (z <= 6.8e+86) {
tmp = x * 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 = z * sin(y)
if (z <= (-9.2d+141)) then
tmp = t_0
else if (z <= 6.8d+86) then
tmp = x * 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 = z * Math.sin(y);
double tmp;
if (z <= -9.2e+141) {
tmp = t_0;
} else if (z <= 6.8e+86) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) tmp = 0 if z <= -9.2e+141: tmp = t_0 elif z <= 6.8e+86: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (z <= -9.2e+141) tmp = t_0; elseif (z <= 6.8e+86) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); tmp = 0.0; if (z <= -9.2e+141) tmp = t_0; elseif (z <= 6.8e+86) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.2e+141], t$95$0, If[LessEqual[z, 6.8e+86], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;z \leq -9.2 \cdot 10^{+141}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+86}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -9.2000000000000006e141 or 6.7999999999999995e86 < z Initial program 99.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6473.1
Simplified73.1%
if -9.2000000000000006e141 < z < 6.7999999999999995e86Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6480.2
Simplified80.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.16)
t_0
(if (<= y 0.096)
(fma
x
(fma y (* y (fma (* y y) 0.041666666666666664 -0.5)) 1.0)
(*
z
(fma
(* y (fma y (* y 0.008333333333333333) -0.16666666666666666))
(* y y)
y)))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.16) {
tmp = t_0;
} else if (y <= 0.096) {
tmp = fma(x, fma(y, (y * fma((y * y), 0.041666666666666664, -0.5)), 1.0), (z * fma((y * fma(y, (y * 0.008333333333333333), -0.16666666666666666)), (y * y), y)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.16) tmp = t_0; elseif (y <= 0.096) tmp = fma(x, fma(y, Float64(y * fma(Float64(y * y), 0.041666666666666664, -0.5)), 1.0), Float64(z * fma(Float64(y * fma(y, Float64(y * 0.008333333333333333), -0.16666666666666666)), Float64(y * y), y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.16], t$95$0, If[LessEqual[y, 0.096], N[(x * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * 0.041666666666666664 + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + N[(z * N[(N[(y * N[(y * N[(y * 0.008333333333333333), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.16:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.096:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, 0.041666666666666664, -0.5\right), 1\right), z \cdot \mathsf{fma}\left(y \cdot \mathsf{fma}\left(y, y \cdot 0.008333333333333333, -0.16666666666666666\right), y \cdot y, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.160000000000000003 or 0.096000000000000002 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6453.2
Simplified53.2%
if -0.160000000000000003 < y < 0.096000000000000002Initial program 100.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64100.0
Simplified100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.7
Simplified99.7%
Taylor expanded in y around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.7
Simplified99.7%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6454.9
Simplified54.9%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6435.8
Simplified35.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6415.0
Simplified15.0%
Final simplification15.0%
herbie shell --seed 2024215
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))