Question: Invalid left hand side in assignment - issue with Vector size?

I was trying to assign a Vector to a Vector inside a procedure. However, when the Vector has a size of 5, I was able to do that. But not when the Vector has a size of 7.

I have the following example. I can't assign the Vector over when the Vector has a size of 7 as shown in oneStep_egcd2.  But I can do that when the size is 5 in oneStep_egcd. Copying the contents over using a for loop works as expected. 

 

a:= 17; b:= 5;

17

 

5

(1)

 

# <s, a, t, b, g>
prev := <1, a, 0, b, a>;

Vector(5, {(1) = 1, (2) = 17, (3) = 0, (4) = 5, (5) = 17})

(2)

curr := <0, a, 1, b, b>;

Vector(5, {(1) = 0, (2) = 17, (3) = 1, (4) = 5, (5) = 5})

(3)

oneStep_egcd := proc(prev::Vector, curr::Vector)
    local q, t1, t2, t3;
    if (curr[5] <> 0) then
        q := iquo(prev[5], curr[5]);
        t1, t2, t3 := prev[1] - curr[1] * q, prev[3] - curr[3] * q, prev[5] - curr[5] * q;
        prev = curr;
        curr[1], curr[3], curr[5] := t1, t2, t3;
    end if:
end proc:

oneStep_egcd(prev, curr)

1, -3, 2

(4)

NULL

NULL

# <s, expr_s, a, t, expr_t, b, g>
prev := <1, 1, a, 0, 0, b, a>;

Vector(7, {(1) = 1, (2) = 1, (3) = 17, (4) = 0, (5) = 0, (6) = 5, (7) = 17})

(5)

curr := <0, 0, a, 1, 1, b, b>;

Vector(7, {(1) = 0, (2) = 0, (3) = 17, (4) = 1, (5) = 1, (6) = 5, (7) = 5})

(6)

oneStep_egcd2 := proc(prev::Vector, curr::Vector)
    local q, sb_q, t1, t2, t4, t5, t7;
    if (curr[7] <> 0) then
        q := iquo(prev[7], curr[7]);
        sb_q := (q);
        t1 := prev[1] - curr[1] * q;
        t2 := prev[2] - curr[2] * q;
        t4 := prev[4] - curr[4] * q;
        t5 := prev[5] - curr[5] * q;
        t7 := prev[7] - curr[7] * q;
        prev := curr;
        curr[1], curr[2], curr[4], curr[5], curr[7] := t1, t2, t4, t5, t7;
    end if:
end proc:

oneStep_egcd2(prev, curr)

Error, (in oneStep_egcd2) invalid left hand side in assignment

 

NULL

oneStep_egcd3 := proc(prev::Vector, curr::Vector)
    local q, sb_q, t1, t2, t4, t5, t7, i;
    if (curr[7] <> 0) then
        q := iquo(prev[7], curr[7]);
        sb_q := (q);
        t1 := prev[1] - curr[1] * q;
        t2 := prev[2] - curr[2] * q;
        t4 := prev[4] - curr[4] * q;
        t5 := prev[5] - curr[5] * q;
        t7 := prev[7] - curr[7] * q;
        for i to 7 do
            prev[i] := curr[i];
        end do;
        curr[1], curr[2], curr[4], curr[5], curr[7] := t1, t2, t4, t5, t7;
    end if:
end proc:

oneStep_egcd3(prev, curr)

1, 1, -3, -3, 2

(7)

NULL

Download ErrorExample.mw

Please Wait...