Problem: extracting elements on CAS mode
|
02-20-2018, 10:29 AM
(This post was last modified: 07-20-2018 05:20 PM by compsystems.)
Post: #1
|
|||
|
|||
Problem: extracting elements on CAS mode
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" |
|||
07-20-2018, 05:11 PM
(This post was last modified: 07-20-2018 09:32 PM by compsystems.)
Post: #2
|
|||
|
|||
RE: Problem: extracting elements on CAS mode
Now inform:
Python compatibility enabled. List index will start at 0, run index:=1 ... or 0 to disable Python compatibility. index:=0; returns "[] index start 0" M1:=[[1,2], [3,4]]; M1(0,0) returns "Error: Invalid input" // ok M1(1,1) returns 1 // ok M1[0,0] returns input: M1[0,1] output [[1,2],[3,4]] // ? index:=1; returns "[] index start 0" M1:=[[1,2], [3,4]]; M1(0,0) returns "Error: Invalid input" M1(1,1) returns 1 M1[0,0] returns input: M1[-1, 0] output: [[1,2],[3,4]] // ? |
|||
07-20-2018, 05:44 PM
Post: #3
|
|||
|
|||
RE: Problem: extracting elements on CAS mode
If you have CAS programs in Python syntax, this will enable Python compatibility mode, i.e. list indices will start at 0 for CAS variables when using [] notation. List indices with () are not concerned and should be used for non-CAS variables like M1.
Run index:=1 or of:=1 for indices starting at 1 in [], index:=0 or of:=0 for indices starting at 0. |
|||
07-20-2018, 09:29 PM
(This post was last modified: 07-20-2018 09:53 PM by compsystems.)
Post: #4
|
|||
|
|||
RE: Problem: extracting elements on CAS mode
ok ^
index:=0; "abc"[2]; returns "[] index start 0" History input: "abc"(3) output "c" // ok, but the history input must be "abc"(2) and not "abc"(3) a pos 0 b pos 1 c pos 2 index:=1; "abc"[2]; returns input: "abc"(2) output "b" // ok // calling index id content returns index [enter] x:"Error: Bad Argument Value" // m1:=[[1,2], [3,4]]; m1(3,1) returns "m" ? |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)