table() data

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

table() data

Message par compsystems » mar. févr. 19, 2019 11:49 pm

Hello

tbl2:=table(
[0,0] = 9,
[0,1] = 8,
[1,0] = 7,
[1,1] = 6
)
tbl2[0,0], tbl2[0,1], tbl2[1,0], tbl2[1,1] returns 9,8,7,6
makevector( tbl2[0,0], tbl2[0,1], tbl2[1,0], tbl2[1,1] ) returns [9,8,7,6]
matrix( tbl2 ) returns [[ 9, 8 ], [ 7, 6 ]]
tbl2[0,0] returns 9
tbl2[2,0] returns 0, must return Error: out of index


tbl3:=table(
[0,0] = [9,8,7],
[0,1] = [6,5],
[1,0] = 4,
[1,1] = 3
)
tbl3[0,0] returns 0, I think it must return [9,8,7]

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: table() data

Message par parisse » mer. févr. 20, 2019 12:42 pm

table is used to represent sparse matrices, that's why if an index is not in the table, access to this index returns 0.
You can not use list=list inside a table instruction, because list=list is evaluated, for example the first one as [[0,0]=9,[0,0]=8,[0,0]=7]. You have to run varname[index]:=value.

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: table() data

Message par compsystems » mer. févr. 20, 2019 8:47 pm

in the future think about supporting the index from 1

A:=[[9,8],[7,6]]; table(A) returns
// index [0,0]

table(
[0,0] = 9,
[0,1] = 8,
[1,0] = 7,
[1,1] = 6
)

// index [1,1]

table(
[[1,1]] = 9,
[[1,2]] = 8,
[[2,1]] = 7,
[[2,2]] = 6
)

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: table() data

Message par compsystems » ven. févr. 22, 2019 2:09 am

Code : Tout sélectionner

tblA := table( "float_1" = 5.0 , "integer_2" = 5, "complex_4" = 3+4*i, "identifier_6" = var01, "list_7" = [9,[8,7],[6,5,4]],  "symbolic_8" = x+y*i , "rational_9" = 3/4,  "string_12" = "Hello",  "set_2" = set[ a, b ,a, c ], "polynomial_10" = poly1[ 1, -6, 11, -6 ] , "matrix" = [[1,2],[3,4]], "vector" = [9,8,7,6,5,4], "function_13" = f(x):=x+1  )
[enter]
table( … )
tblA[ "float_1" ], tblA[ "integer_2" ], tblA[ "complex_4" ], tblA[ "identifier_6" ], tblA[ "list_7" ], tblA[ "symbolic_8" ], tblA[ "rational_9" ], tblA[ "string_12" ], tblA[ "function_13" ],  tblA[ "set_2" ],  tblA[  "polynomial_10" ], tblA[  "matrix"  ],  tblA[  "vector"  ]

[enter]
5.0, 5, 3+4*i, var01, [9,8,7], x+i*y, 3/4, "Hello", (x)->x+1, set[a,b,c], poly1[1,-6,11,-6], [[1,2],[3,4]], [9,8,7,6,5,4]

type( tblA[ "float_1" ] ), type( tblA[ "integer_2" ] ), type( tblA[ "complex_4" ] ), type( tblA[ "identifier_6" ] ), type( tblA[ "list_7" ] ), type( tblA[ "symbolic_8" ] ), type( tblA[ "rational_9" ] ), type( tblA[ "string_12" ] ), type( tblA[ "function_13" ] ), subtype( tblA[ "set_2" ] ), subtype( tblA[  "polynomial_10"  ]), type( tblA[  "matrix"  ]), type( tblA[  "vector"  ]), type( tblA) 
[enter]

real, integer, complex, identifier, vector, expression, rational, string, func, vector, 2, 10, vector, DOM_MAP
the DOM_MAP type does not yet have its synonym in lowercase 'table'. I think that the subtype() cmd should also return an identifier name, as
'set':2, 'sequence':1, 'polynomial':10 and then with +0 get its numerical value

Répondre