02-20-2018, 10:29 AM
Hello, porting a code of Xcas to primeCAS detect an error in the extraction of elements, problem only present in cas mode
////////////////////////
In HOME mode:
The extraction of an element (i, j) is done by means of a "coordinate" with parentheses () or brackets [], where (i,j) == [i,j]
Example:
M1:=[[1,2],
[3,4]];
M1(i,j)==M1[i,j]
with ()
m1[[ ( i=1, j=1 ) =1, ( i=1, j=2 ) =2 ],
[ ( i=2, j=1 ) =3, ( i=2, j=2 ) =4 ]]
M1(0,0) returns "Error: Invalid input" // OK
M1(1,1) returns 1 // OK
M1(1,2) returns 2 // OK
M1(2,1) returns 2 // OK
M1(2,2) returns 4 // OK
M1(3,3) returns "Error: Invalid input" // OK
[ M1(1,1), M1(1,2), M1(2,1), M1(2,2) ] returns [1,2,3,4] // ok
Now with []
M1[0,0] returns "Error: Invalid input" // OK
M1[1,1] returns 1 // OK
M1[1,2] returns 2 // OK
M1[2,1] returns 3 // OK
M1[2,2] returns 4 // OK
M1[3,3] returns "Error: Invalid input" // OK
[ M1[1,1], M1[1,2], M1[2,1], M1[2,2] ] returns [1,2,3,4] // ok
/////////////////////////////////////////////
In CAS mode:
The parenthesis () is used to extract the standard position, starting at 1.1
[[ (1,1), (1,2) ],
[ (2,1), (2,2) ]]
M1:=
[[1,2],
[3,4]];
m1[[ ( i=1, j=1 ) =1, ( i=1, j=2 ) =2 ],
[ ( i=2, j=1 ) =3, ( i=2, j=2 ) =4 ]]
and the bracket [] is used to extract the position starting at 0.0, Very important to be used in certain algorithms, where you need to index from (0,0)
[[ (0,0), (0,1) ],
[ (1,0), (1,1) ]]
m1[[ [i=0, j=0] =1, [i=0, j=1] =2 ],
[ [i=1, j=0] =3, [i=1, j=1] =4 ]]
m1(i,j)==m1[i-1,j-1]
m1[i,j]==m1(i+1,j+1)
m1:=[[1,2],
[3,4]];
with ()
m1(0,0) returns "Index out of range Error: Invalid dimension" // ok
m1(1,1) returns 1 // OK
m1(2,1) returns 3 // OK
m1(1,2) returns 2 // OK
m1(2,2) returns 4 // OK
m1(3,1) returns "E" // must return. "Index out of range Error: Invalid dimension"
m1(3,2) returns "r" // ?
m1(3,3) returns "r" // ?
m1(3,4) returns "o" // ?
m1(3,5) returns "r" // ?
///////////
Now with []
m1[0,0] returns input: m1[-1,0] output: 4 // error.
ok // m1(i+1,j+1) == m1(0+1,0+1) == m1(1,1) = 1
m1[1,1] returns input: m1[0,1] output: 1 // error
ok => m1(i+1,j+1) == m1(1+1,1+1) == m1(2,2) = 4
m1[2,2] returns input:m1[1,2] output: 4 // error
ok => m1(i+1,j+1) == m1(2+1,2+1) == m1(3,3) = //"Error: Invalid input"
////////////////////////
In HOME mode:
The extraction of an element (i, j) is done by means of a "coordinate" with parentheses () or brackets [], where (i,j) == [i,j]
Example:
M1:=[[1,2],
[3,4]];
M1(i,j)==M1[i,j]
with ()
m1[[ ( i=1, j=1 ) =1, ( i=1, j=2 ) =2 ],
[ ( i=2, j=1 ) =3, ( i=2, j=2 ) =4 ]]
M1(0,0) returns "Error: Invalid input" // OK
M1(1,1) returns 1 // OK
M1(1,2) returns 2 // OK
M1(2,1) returns 2 // OK
M1(2,2) returns 4 // OK
M1(3,3) returns "Error: Invalid input" // OK
[ M1(1,1), M1(1,2), M1(2,1), M1(2,2) ] returns [1,2,3,4] // ok
Now with []
M1[0,0] returns "Error: Invalid input" // OK
M1[1,1] returns 1 // OK
M1[1,2] returns 2 // OK
M1[2,1] returns 3 // OK
M1[2,2] returns 4 // OK
M1[3,3] returns "Error: Invalid input" // OK
[ M1[1,1], M1[1,2], M1[2,1], M1[2,2] ] returns [1,2,3,4] // ok
/////////////////////////////////////////////
In CAS mode:
The parenthesis () is used to extract the standard position, starting at 1.1
[[ (1,1), (1,2) ],
[ (2,1), (2,2) ]]
M1:=
[[1,2],
[3,4]];
m1[[ ( i=1, j=1 ) =1, ( i=1, j=2 ) =2 ],
[ ( i=2, j=1 ) =3, ( i=2, j=2 ) =4 ]]
and the bracket [] is used to extract the position starting at 0.0, Very important to be used in certain algorithms, where you need to index from (0,0)
[[ (0,0), (0,1) ],
[ (1,0), (1,1) ]]
m1[[ [i=0, j=0] =1, [i=0, j=1] =2 ],
[ [i=1, j=0] =3, [i=1, j=1] =4 ]]
m1(i,j)==m1[i-1,j-1]
m1[i,j]==m1(i+1,j+1)
m1:=[[1,2],
[3,4]];
with ()
m1(0,0) returns "Index out of range Error: Invalid dimension" // ok
m1(1,1) returns 1 // OK
m1(2,1) returns 3 // OK
m1(1,2) returns 2 // OK
m1(2,2) returns 4 // OK
m1(3,1) returns "E" // must return. "Index out of range Error: Invalid dimension"
m1(3,2) returns "r" // ?
m1(3,3) returns "r" // ?
m1(3,4) returns "o" // ?
m1(3,5) returns "r" // ?
///////////
Now with []
m1[0,0] returns input: m1[-1,0] output: 4 // error.
ok // m1(i+1,j+1) == m1(0+1,0+1) == m1(1,1) = 1
m1[1,1] returns input: m1[0,1] output: 1 // error
ok => m1(i+1,j+1) == m1(1+1,1+1) == m1(2,2) = 4
m1[2,2] returns input:m1[1,2] output: 4 // error
ok => m1(i+1,j+1) == m1(2+1,2+1) == m1(3,3) = //"Error: Invalid input"