
(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 (- (* 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}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) (- z) x))) (if (<= z -1.7e+14) t_0 (if (<= z 6e-32) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), -z, x);
double tmp;
if (z <= -1.7e+14) {
tmp = t_0;
} else if (z <= 6e-32) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), Float64(-z), x) tmp = 0.0 if (z <= -1.7e+14) tmp = t_0; elseif (z <= 6e-32) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z) + x), $MachinePrecision]}, If[LessEqual[z, -1.7e+14], t$95$0, If[LessEqual[z, 6e-32], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, -z, x\right)\\
\mathbf{if}\;z \leq -1.7 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-32}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.7e14 or 6.0000000000000001e-32 < z Initial program 99.8%
Taylor expanded in y around 0
Simplified91.0%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-neg.f6491.0
Simplified91.0%
if -1.7e14 < z < 6.0000000000000001e-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 (* (sin y) (- z)))) (if (<= z -7.8e+141) t_0 (if (<= z 6.8e+86) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double tmp;
if (z <= -7.8e+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 = sin(y) * -z
if (z <= (-7.8d+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 = Math.sin(y) * -z;
double tmp;
if (z <= -7.8e+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 = math.sin(y) * -z tmp = 0 if z <= -7.8e+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(sin(y) * Float64(-z)) tmp = 0.0 if (z <= -7.8e+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 = sin(y) * -z; tmp = 0.0; if (z <= -7.8e+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[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[z, -7.8e+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 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -7.8 \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 < -7.79999999999999983e141 or 6.7999999999999995e86 < z Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6473.2
Simplified73.2%
if -7.79999999999999983e141 < z < 6.7999999999999995e86Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6480.4
Simplified80.4%
Final simplification78.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.15)
t_0
(if (<= y 0.078)
(fma
y
(* z (fma y (* y 0.16666666666666666) -1.0))
(fma (* x (* y y)) (fma (* y y) 0.041666666666666664 -0.5) x))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.15) {
tmp = t_0;
} else if (y <= 0.078) {
tmp = fma(y, (z * fma(y, (y * 0.16666666666666666), -1.0)), fma((x * (y * y)), fma((y * y), 0.041666666666666664, -0.5), x));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.15) tmp = t_0; elseif (y <= 0.078) tmp = fma(y, Float64(z * fma(y, Float64(y * 0.16666666666666666), -1.0)), fma(Float64(x * Float64(y * y)), fma(Float64(y * y), 0.041666666666666664, -0.5), x)); 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.15], t$95$0, If[LessEqual[y, 0.078], N[(y * N[(z * N[(y * N[(y * 0.16666666666666666), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * 0.041666666666666664 + -0.5), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.15:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.078:\\
\;\;\;\;\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(y, y \cdot 0.16666666666666666, -1\right), \mathsf{fma}\left(x \cdot \left(y \cdot y\right), \mathsf{fma}\left(y \cdot y, 0.041666666666666664, -0.5\right), x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.149999999999999994 or 0.0779999999999999999 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6453.4
Simplified53.4%
if -0.149999999999999994 < y < 0.0779999999999999999Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Simplified99.6%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.6
Simplified99.6%
Taylor expanded in x around 0
Simplified99.6%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 = x - (y * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6454.8
Simplified54.8%
Final simplification54.8%
(FPCore (x y z) :precision binary64 (* z (- y)))
double code(double x, double y, double z) {
return z * -y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * -y
end function
public static double code(double x, double y, double z) {
return z * -y;
}
def code(x, y, z): return z * -y
function code(x, y, z) return Float64(z * Float64(-y)) end
function tmp = code(x, y, z) tmp = z * -y; end
code[x_, y_, z_] := N[(z * (-y)), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(-y\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6454.8
Simplified54.8%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6414.9
Simplified14.9%
herbie shell --seed 2024215
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))