A graphical approach to relational reasoning