Imagine one wants to represent the and function for any number of qubits in Dirac notation. The and gate flips the target qubit if all the control qubits are in state 1. This is its matrix representation : $$\begin {bmatrix} 1 & 0 & 0 & \cdots & 0 & 0 \\ 0 & 1 & 0 & \cdots & 0 & 0\\ 0 & 0 & \ddots & & \vdots & \vdots \\ \vdots & \vdots & & 1 & 0 & 0 \\ 0 & 0 & \cdots & 0 & 0 & 1 \\ 0 & 0 & \cdots & 0 & 1 & 0 \\ \end{bmatrix}$$
It can be decomposed into two parts : $$\begin{bmatrix} 1 & 0 & 0 & \cdots & 0 & 0 \\ 0 & 1 & 0 & \cdots & 0 & 0\\ 0 & 0 & \ddots & & \vdots & \vdots \\ \vdots & \vdots & & 1 & 0 & 0 \\ 0 & 0 & \cdots & 0 & 0 & 0 \\ 0 & 0 & \cdots & 0 & 0 & 0 \\ \end{bmatrix}= \begin{bmatrix} 1 & 0 & \cdots & 0 & 0 \\ 0 & 1 & \cdots & 0 & 0\\ \vdots & \vdots & \ddots & & \vdots \\ 0 & 0 & & 1 & 0 \\ 0 & 0 & \cdots & 0 & 0 \\ \end{bmatrix} \otimes I = \begin{bmatrix} 1 & 0 & \cdots & 0 & 0 \\ 0 & 1 & \cdots & 0 & 0\\ \vdots & \vdots & \ddots & & \vdots \\ 0 & 0 & & 1 & 0 \\ 0 & 0 & \cdots & 0 & 1 \\ \end{bmatrix} \otimes I- \begin{bmatrix} 0 & 0 & \cdots & 0 & 0 \\ 0 & 0 & \cdots & 0 & 0\\ \vdots & \vdots & \ddots & & \vdots \\ 0 & 0 & & 0 & 0 \\ 0 & 0 & \cdots & 0 & 1 \\ \end{bmatrix} \otimes I = (I-|1\cdots1\rangle\langle1\cdots1| ) \otimes I \tag{1}$$ and $$\begin {bmatrix} 0 & 0 & 0 & \cdots & 0 & 0 \\ 0 & 0 & 0 & \cdots & 0 & 0\\ 0 & 0 & \ddots & & \vdots & \vdots \\ \vdots & \vdots & & 0 & 0 & 0 \\ 0 & 0 & \cdots & 0 & 0 & 1 \\ 0 & 0 & \cdots & 0 & 1 & 0 \\ \end{bmatrix} = \begin{bmatrix} 0 & 0 & \cdots & 0 & 0 \\ 0 & 0 & \cdots & 0 & 0\\ \vdots & \vdots & \ddots & & \vdots \\ 0 & 0 & & 0 & 0 \\ 0 & 0 & \cdots & 0 & 1 \\ \end{bmatrix} \otimes X = |1\cdots1\rangle\langle1\cdots1| \otimes X \tag{2}$$ So combining (1) and (2), we get : $$U_{and} = (I-|1\cdots1\rangle\langle1\cdots1| ) \otimes I + |1\cdots1\rangle\langle1\cdots1| \otimes X$$
This is still pretty easy to see, the example complicates a lot when we have an or gate : $$U_{or} = U_{or} = |0...0\rangle\langle 0...0|\otimes I + \big(I - |0...0\rangle\langle 0...0|\big) \otimes X$$ which applies the X gate on the target qubit if there is at least 1 control qubits in the $|1\rangle$ state.
My question is : is there any way to see these transformations in Dirac notation to use them in a program ? To gain some intuition on the decomposition.