NeraSnow

55 Reputation

3 Badges

1 years, 337 days

MaplePrimes Activity


These are questions asked by NeraSnow

I wish to substitute only the base of the ifactor expression like the following

lst := [24300, 18907875, 151200, 147000]

[24300, 18907875, 151200, 147000]

(1)

map(ifactor, lst)

[``(2)^2*``(3)^5*``(5)^2, ``(3)^2*``(5)^3*``(7)^5, ``(2)^5*``(3)^3*``(5)^2*``(7), ``(2)^3*``(3)*``(5)^3*``(7)^2]

(2)

subs(2 = x, %)

[``(x)^x*``(3)^5*``(5)^x, ``(3)^x*``(5)^3*``(7)^5, ``(x)^5*``(3)^3*``(5)^x*``(7), ``(x)^3*``(3)*``(5)^3*``(7)^x]

(3)

I wish my results to be

[x^2*3^5*5^2, 3^2*5^3*7^5, 7*x^5*3^3*5^2, 3*x^3*5^3*7^2]

[6075*x^2, 18907875, 4725*x^5, 18375*x^3]

(4)

such that

subs(x = 2, %)

[24300, 18907875, 151200, 147000]

(5)

evalb(% = lst)

true

(6)

NULL

Download SubsExample.mw

If there a way to do that? I understand that there is a command ifactors which gives me more control, but the form of the result is rather inconvenient. I hope there is a more direct way to do the aforementioned operation.

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

I am slightly confused as I can't apply the seemingly correct function to a sequence. It seems like modp does not like my inverse. But I am not aware of any other way of finding the modular inverse.  

a := i -> (1025 - 2^(10 - 2^i))^(-1) mod (1025 - 2^(10 - 2*2^i));

proc (i) options operator, arrow; `mod`(1/(1025-2^(10-2^i)), 1025-2^(10-2*2^i)) end proc

(1)

a(1);

5

(2)

a(2);

17

(3)

map(i -> i + 1, {seq(1 .. 4)});

{2, 3, 4, 5}

(4)

map(i -> 1/(1025 - 2^(10 - 2^i)) mod (1025 - 2^(10 - 2*2^i)), {seq(1 .. 4)});

Error, invalid input: modp received 65599/64, which is not valid for its 2nd argument, m

 

map(a, {seq(1 .. 4)});

Error, invalid input: modp received 65599/64, which is not valid for its 2nd argument, m

 

NULL

NULL

Download example.mw

tot := 1:         
for z in 1, x, y, q^2, 3 do    
    tot += z;  
end do:  
tot;

When I run the code above, Maple gives me "Error, unterminated loop".

However, if I change the code to 

tot := 1;
for z in 1, x, y, q^2, 3 do
    tot := tot + z;
end do:
tot;

Maple computes the result correctly.

I don't see how the loop is unterminated. Am I not allowed to use operator assignments in loops?

I have the following example.

> A:= Vector(3,symbol=v)

A:= Vector(3,symbol=v)

>v[1]:= 5

v[1]:=5


> A

 Vector(3,symbol=v)

 

Is there any way such that v[1] is actually referring to the first element in the vector? In other words, changing v[1] actually modifies the vector A.

 

If the question does not make sense, then here is the actual scenario that I faced.

I need to solve a system of equations in the form of 

2 = c[2] + a[1],
2 = 2*c[3] + a[2],
-2 = -3*c[1] + a[3],
-1 = -2*c[2] + a[1],
-1 = -c[3] + a[2],
1 = a[3]

where a[i], c[i] refers to the entries in the vector.

solve returns the following:

[[a[1] = 1, a[2] = 0, a[3] = 1, c[1] = 1, c[2] = 1, c[3] = 1]]

I then did an assign(%). However, the entries in A and C are not changed. I want the answer returned by solve to be properly applied to the entries of the vectors.

1 2 Page 1 of 2