
(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 10 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 (sin y) (- z) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) x (- (* (sin y) z))))
double code(double x, double y, double z) {
return fma(cos(y), x, -(sin(y) * z));
}
function code(x, y, z) return fma(cos(y), x, Float64(-Float64(sin(y) * z))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, -\sin y \cdot z\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) - (sin(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 * cos(y)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))) (t_1 (- (* (sin y) z))))
(if (<= y -3.6e+217)
t_0
(if (<= y -0.1)
t_1
(if (<= y 0.00055)
(fma y (fma y (fma z (* y 0.16666666666666666) (* x -0.5)) (- z)) x)
(if (<= y 6.8e+86) t_1 (if (<= y 7.5e+245) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = -(sin(y) * z);
double tmp;
if (y <= -3.6e+217) {
tmp = t_0;
} else if (y <= -0.1) {
tmp = t_1;
} else if (y <= 0.00055) {
tmp = fma(y, fma(y, fma(z, (y * 0.16666666666666666), (x * -0.5)), -z), x);
} else if (y <= 6.8e+86) {
tmp = t_1;
} else if (y <= 7.5e+245) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(-Float64(sin(y) * z)) tmp = 0.0 if (y <= -3.6e+217) tmp = t_0; elseif (y <= -0.1) tmp = t_1; elseif (y <= 0.00055) tmp = fma(y, fma(y, fma(z, Float64(y * 0.16666666666666666), Float64(x * -0.5)), Float64(-z)), x); elseif (y <= 6.8e+86) tmp = t_1; elseif (y <= 7.5e+245) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])}, If[LessEqual[y, -3.6e+217], t$95$0, If[LessEqual[y, -0.1], t$95$1, If[LessEqual[y, 0.00055], N[(y * N[(y * N[(z * N[(y * 0.16666666666666666), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 6.8e+86], t$95$1, If[LessEqual[y, 7.5e+245], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := -\sin y \cdot z\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+217}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.1:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.00055:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot 0.16666666666666666, x \cdot -0.5\right), -z\right), x\right)\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+86}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+245}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.6000000000000002e217 or 6.7999999999999995e86 < y < 7.5e245Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6464.0
Applied rewrites64.0%
if -3.6000000000000002e217 < y < -0.10000000000000001 or 5.50000000000000033e-4 < y < 6.7999999999999995e86 or 7.5e245 < y Initial program 99.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6472.1
Applied rewrites72.1%
if -0.10000000000000001 < y < 5.50000000000000033e-4Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x 1.0) (* (sin y) z)))) (if (<= z -5.9e-27) t_0 (if (<= z 650000000.0) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * 1.0) - (sin(y) * z);
double tmp;
if (z <= -5.9e-27) {
tmp = t_0;
} else if (z <= 650000000.0) {
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 = (x * 1.0d0) - (sin(y) * z)
if (z <= (-5.9d-27)) then
tmp = t_0
else if (z <= 650000000.0d0) 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 = (x * 1.0) - (Math.sin(y) * z);
double tmp;
if (z <= -5.9e-27) {
tmp = t_0;
} else if (z <= 650000000.0) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 1.0) - (math.sin(y) * z) tmp = 0 if z <= -5.9e-27: tmp = t_0 elif z <= 650000000.0: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 1.0) - Float64(sin(y) * z)) tmp = 0.0 if (z <= -5.9e-27) tmp = t_0; elseif (z <= 650000000.0) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 1.0) - (sin(y) * z); tmp = 0.0; if (z <= -5.9e-27) tmp = t_0; elseif (z <= 650000000.0) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 1.0), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.9e-27], t$95$0, If[LessEqual[z, 650000000.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot 1 - \sin y \cdot z\\
\mathbf{if}\;z \leq -5.9 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 650000000:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.8999999999999998e-27 or 6.5e8 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites92.3%
if -5.8999999999999998e-27 < z < 6.5e8Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6482.5
Applied rewrites82.5%
Final simplification87.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -22000000000.0)
t_0
(if (<= y 1300000.0)
(fma y (fma y (fma z (* y 0.16666666666666666) (* x -0.5)) (- z)) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -22000000000.0) {
tmp = t_0;
} else if (y <= 1300000.0) {
tmp = fma(y, fma(y, fma(z, (y * 0.16666666666666666), (x * -0.5)), -z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -22000000000.0) tmp = t_0; elseif (y <= 1300000.0) tmp = fma(y, fma(y, fma(z, Float64(y * 0.16666666666666666), Float64(x * -0.5)), Float64(-z)), 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, -22000000000.0], t$95$0, If[LessEqual[y, 1300000.0], N[(y * N[(y * N[(z * N[(y * 0.16666666666666666), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -22000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1300000:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot 0.16666666666666666, x \cdot -0.5\right), -z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.2e10 or 1.3e6 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6448.9
Applied rewrites48.9%
if -2.2e10 < y < 1.3e6Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6495.4
Applied rewrites95.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y z)))) (if (<= z -2.4e+73) t_0 (if (<= z 1.4e+160) (* x 1.0) t_0))))
double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -2.4e+73) {
tmp = t_0;
} else if (z <= 1.4e+160) {
tmp = x * 1.0;
} 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 = -(y * z)
if (z <= (-2.4d+73)) then
tmp = t_0
else if (z <= 1.4d+160) then
tmp = x * 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -2.4e+73) {
tmp = t_0;
} else if (z <= 1.4e+160) {
tmp = x * 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(y * z) tmp = 0 if z <= -2.4e+73: tmp = t_0 elif z <= 1.4e+160: tmp = x * 1.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * z)) tmp = 0.0 if (z <= -2.4e+73) tmp = t_0; elseif (z <= 1.4e+160) tmp = Float64(x * 1.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(y * z); tmp = 0.0; if (z <= -2.4e+73) tmp = t_0; elseif (z <= 1.4e+160) tmp = x * 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * z), $MachinePrecision])}, If[LessEqual[z, -2.4e+73], t$95$0, If[LessEqual[z, 1.4e+160], N[(x * 1.0), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot z\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+160}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.40000000000000002e73 or 1.4e160 < z Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6446.0
Applied rewrites46.0%
Taylor expanded in x around 0
Applied rewrites36.8%
if -2.40000000000000002e73 < z < 1.4e160Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6455.2
Applied rewrites55.2%
Taylor expanded in x around inf
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
Applied rewrites48.1%
Final simplification45.1%
(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(Float64(-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
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.8
Applied rewrites52.8%
Applied rewrites52.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-*.f6452.8
Applied rewrites52.8%
Final simplification52.8%
(FPCore (x y z) :precision binary64 (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1
\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-*.f6452.8
Applied rewrites52.8%
Taylor expanded in x around inf
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f6492.7
Applied rewrites92.7%
Taylor expanded in y around 0
Applied rewrites37.9%
herbie shell --seed 2024232
(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))))