Coinductive foundations of infinitary rewriting and infinitary equational logic