The gradient calculation is correct.
When you set a[0] = value, the first value of the tt array is not modified.
Then, the computation of l1 never uses this first value of tt so its gradient will be 0.