Parent-Child object relationship expressed as Matrix math?[solved]

Given what I need to simulate parenting using code, how do I do that using Matrices? What data on both objects I need to get, what order of matrix multiplication, etc? (Disclaimer: I barely understand working with matrices. Examples of code are preferable)

Found it out by myself. Should’ve described my task more accurately.
I wanted one bone to rotate around another, but only while the “parent” rotation is altered. So because of this second condition, direct parenting or constraints were out of the question. In the end, I made the script that runs on scene update (, detects when the “parent” rotates or not, then stores the “child”'s local space matrix when “parent” is inactive (ChildOffset = parent.matrix.inverted() * child.matrix) and finally, while “parent” is rotated, updates the position and rotation for “child” based on this stored offset (child.matrix = parent.matrix * ChildOffset). Works well, but now I have problem with Blender crashing every time I use Undo