⍝ ZZ36_Regression.tc
⍝ ----------------------------------

      )CLEAR
CLEAR WS

      )IN qq111.atf

      )FNS
and                             b2                      lshift                  not
or                              quantum_add_scratch     quantum_bmeasure        quantum_cexp
quantum_cnot                    quantum_cond_phase      quantum_cond_phase_inv  quantum_dot_product
quantum_dot_product_noconj      quantum_frac_approx     quantum_gate1           quantum_get_state
quantum_getwidth                quantum_hadamard        quantum_inverse_mod     quantum_kronecker
quantum_measure                 quantum_new_qureg       quantum_normalize       quantum_phase_kick
quantum_phase_scale             quantum_print_qureg     quantum_print_timeop    quantum_prob
quantum_r_x                     quantum_r_y             quantum_r_z             quantum_sigma_x
quantum_sigma_y                 quantum_sigma_z         quantum_state_collapse  quantum_swaptheleads
quantum_swaptheleads_omnuln     quantum_toffoli         quantum_walsh           rshift
xor

      )VARS
MAX_UNSIGNED    qp1     qq  qq1     qq2     qq3     qq4     qr1     qr2     qr3

      ⎕CR 'quantum_dot_product'
 z←reg1 quantum_dot_product reg2;filtstate;s1;s2;siz1;nullpos;f1               
 siz1←(1⊃reg1)                                                                 
 →((⍴3⊃reg1)=⍬)/∆1                                                             
 ⊢filtstate←(3⊃reg1)(quantum_get_state⍤0 1)reg2 ⍝ contains positions in reg2   
 nullpos←filtstate⍳¯1                                                          
 ⍎(nullpos≠siz1)/'filtstate[nullpos]←¯1' ⍝ only positions in reg2 found in reg1
 s1←(2⊃reg1)                                                                   
 s2←(2⊃reg2)                                                                   
 f1←1+filtstate                                                                
 f1[(f1>1)/⍳⍴f1]←1                                                             
 z←+/(+(s1[f1/⍳siz1]))×s2[(filtstate>¯1)/filtstate]                            
 →0                                                                            
∆1:filtstate←(⍳(1⊃reg1))(quantum_get_state⍤0 1)reg2                            
 filtstate←(filtstate>¯1)/filtstate                                            
 s1←(2⊃reg1)                                                                   
 s2←(2⊃reg2)                                                                   
 z←+/(+(s1[filtstate/⍳(1⊃reg1)]))×s2[filtstate]                                

