Fix bugs reported by the DL tutorial wrote by Nicolas

There are 2 bugs: 
 (1) Connection pattern bug:
  The logic in the connection pattern should be : if out1 is an input to out2, and x is an input to out1 then x is an input of out2
   The implementation used to be : if out1 is an input to out2 and x is an input to out2 then x is an input of out1, which is wrong


 (2) Push dot optimization 
 For the optimization to work, one  of the inputs of the pattern has to be a sequence. The bug happened when both inputs where sequences, because I had to if/else branches and in the first if I checked if input 1 is a sequence and arrange the code according,  in the second if I checked first if input 2 is a sequence. When both where sequences, I do the first steps considering input 1 the sequence, and then the rest of the steps considering input 2 sequence .. which results in the wrong shapes. 

Ideally one would implement this as a special case on its own, that avoids the scan.