arg/3 and setarg/3
I know it sounds crazy.
See my personal notes here. While not specifically about arg/3 it does give some useful details.
Also see the code that the notes are for in this post.
While I have not used these there are a few SWI-Prolog packs for matrix, e.g.