Head , Tail , Length , Nth , DestructiveReverse , List , UnList , Listify , Concat , Delete , Insert , DestructiveInsert , DestructiveDelete , Replace , DestructiveReplace , FlatCopy , Contains , Find , Append , DestructiveAppend , RemoveDuplicates , Push , Pop , PopFront , PopBack , Swap , Count , Intersection , Union , Difference , FillList , Drop , Take , Partition , Assoc , AssocIndices , Flatten , UnFlatten , Type , NrArgs , BubbleSort , Table , TableForm , MapSingle , Map , RandomIntegerVector , MakeVector , Select , List operations

List operations

Most objects that can be of variable size are represented as lists (linked lists internally). Yacas does implement arrays, which are faster when the number of elements in a collection of objects doesn't change. Operations on lists have better support in the current system.


Head

Internal function
Calling Sequence:
Head(list)
Parameters:
list - a list
Description:
Returns the first element of a list.
Examples:
In> Head({a,b,c})
Out> a;
See Also:
Tail , Length ,


Tail

Internal function
Calling Sequence:
Tail(list)
Parameters:
list - a list
Description:
Returns a list without its first element.
Examples:
In> Tail({a,b,c})
Out> {b,c};
See Also:
Head , Length ,


Length

Internal function
Calling Sequence:
Length(object)
Parameters:
object - a list, array or string
Description:
Length returns the length of a list. This function also works on strings and arrays.
Examples:
In> Length({a,b,c})
Out> 3;
In> Length("abcdef");
Out> 6;
See Also:
Head , Tail , Nth ,


Nth({list},index)

Nth({list},index) : Returns the element in the list "{list}" at position "index", where the first element is 1.


DestructiveReverse({list})

DestructiveReverse({list}) : Returns the list {list} in reverse order. The list is reversed in place, so the original is changed into nonsense. Use FlatCopy to avoid this.


List(...)

List(...) : Returns a list with ... as its elements, after they were evaluated. This is the same as entering "{...};".


UnList({list})

UnList({list}) : Changes the list {list} into an expression specified in the elements of the list. This means the first element is treated as the command, and the elements following are the arguments to that command. "{list}" is evaluated before the operation is performed. Example: "UnList({Cos,x});" would evaluate to "Cos(x);".


Listify(expression)

Listify(expression) : Inverse of UnList: it converts the expression "expression" into a list. Eg. "Listify(a(b));" evaluates to "{a,b};".


Concat(...)

Concat(...) : concatenates the lists in ... after evaluation. Eg. "Concat({a,b},{c,d});" returns "{a,b,c,d};".


Delete({list},index)

Delete({list},index) : Deletes an element at position "index" from the list "{list}", and returns that list. "{list}" and "index" are evaluated first. The first index in list is 1.


Insert({list},index,element)

Evaluates arguments, and inserts "element" in "{list}" at position "index", where position 1 means insert at the front of the existing list. The result is returned, and the original list is left unchanged.


DestructiveInsert({list},index,element)

DestructiveInsert({list},index,element) : The Destructive... versions actually perform the operations on the original lists. So, if a variable is bound to a list, the list the variable points to is actually modified. This is more efficient memory-wise and in execution if the same variable is going to be set to the result.


DestructiveDelete({list},index)

DestructiveDelete({list},index) : The Destructive... versions actually perform the operations on the original lists. So, if a variable is bound to a list, the list the variable points to is actually modified. This is more efficient memory-wise and in execution if the same variable is going to be set to the result.


Replace({list},index,element)

This replaces an element, much like calling Delete and Insert in sequence.


DestructiveReplace({list},index,element)

This replaces an element, much like calling DestructiveDelete and DestructiveInsert in sequence.


FlatCopy({list})

FlatCopy({list}) : Copying of the contents of a list. It is not recursed into, only the first level is copied. This is useful in combination with the destructive commands that actually modify lists in place (for efficiency).


Contains({list},element)

Contains({list},element) : Returns whether "{list}" contains element "element".


Find(list,item)

Find(list,item) : returns the index of item in the list. Example: Find({a,b,c,d},c) returns 3.


Append({list},element)

Append({list},element) : Append an element {{I:element}} to list {{I:{list} }}.


DestructiveAppend({list},element)

DestructiveAppend({list},element) : Append an element {{I:element}} to list {{I:{list} }}.


RemoveDuplicates({list})

RemoveDuplicates({list}) : Returns a list with exactly one occurrence of each element that is also in "{list}".


Push(stack,element)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.


Pop(stack,index)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.


PopFront(stack)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.


PopBack(stack)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.


Swap({list},i1,i2)

Swap({list},i1,i2) : Swap elements with indices "i1" and "i2" in the list "{list}".


Count({list},element)

Count({list},element) : Returns number of occurrences of "element" in "{list}".


Intersection({list1},{list2})

Intersection({list1},{list2}) : returns the intersection of two lists. Example : "Intersection({a,b},{b,c});" would evaluate to "{b};".


Union({list1},{list2})

Union({list1},{list2}) : returns the union of two lists. Example : "Union({a,b},{b,c});" would evaluate to "{a,b,c};".


Difference({list1},{list2})

Difference({list1},{list2}) : returns the difference of two lists.


FillList(aItem, aLength)

FillList(aItem, aLength) : create a list with length aLength, filling it with aItem. Example: "FillList(0,5)" returns {0,0,0,0,0}


Drop(list,which)

Drop( list, n ) gives 'list' with its first n elements dropped
Drop( list, -n ) gives 'list' with its last n elements dropped
Drop( list, {m,n} ) gives 'list' with elements m through n dropped


Take(list,which)

Take( list, n ) gives the first n elements of 'list'
Take( list, -n ) gives the last n elements of 'list'
Take( list, {m,n} ) elements m through n of 'list'


Partition( list, n )

Partition( list, n ) partitions 'list' into non-overlapping sublists of length n


Assoc(key,assoclist)

Treat assoclist as a traditional assoc list well known from Lisp, and return the element stored with key. This functionality is probably best accessed through the [ ] operator.


AssocIndices(list)

Return the list of keys in the associated list assoclist.


Flatten

Standard math library
Calling Sequence:
Flatten(expression,operator)
Parameters:
expression - an expression
operator - string with the contents of an infix operator.
Description:
Flatten flattens an expression with respect to a specific operator, converting the result into a list. This is useful for unnesting an expression. Flatten is typically used in simple simplification schemes.
Examples:
In> Flatten(a+b*c+d,"+");
Out> {a,b*c,d};
In> Flatten({a,{b,c},d},"List");
Out> {a,b,c,d};
See Also:
UnFlatten ,


UnFlatten

Standard math library
Calling Sequence:
UnFlatten(list,operator,identity)
Parameters:
list - list of objects the operator is to work on operator - infix operator identity - identity of the operator
Description:
UnFlatten is the inverse operation of Flatten. Given a list, it can be turned into an expression representing for instance the addition of these elements by calling UnFlatten with "+" as argument to operator, and 0 as argument to identity (0 is the identity for addition, since a+0=a). For multiplication the identity element would be 1.
Examples:
In> UnFlatten({a,b,c},"+",0)
Out> a+b+c;
In> UnFlatten({a,b,c},"*",1)
Out> a*b*c;
See Also:
Flatten ,


Type(expression)

Type(expression) : Returns a string representation of the type of "expression". "Type(Cos(x));" would evaluate to "Cos", for instance.


NrArgs(expression)

NrArgs(expression) : Returns number of arguments in top-level function of "expression". "NrArgs(Cos(x));" would evaluate to "1".


BubbleSort({list},"compare")

BubbleSort({list},"compare") : Sort the list {list}, using "compare" as the operator to compare elements. "compare" gives the relation that should be true for neighbouring elements in the list after sorting.


Table(body,var,from,to,step)

Table(body,var,from,to,step) : Generate a list of values from "body", by assigning variable "var" values from "from" upto "to", incrementing "step" each time.


TableForm({list})

Tableform({list}) : TableForm writes out a list in a nicer readable form, eg. one line for each element in the list.


MapSingle("operator",{list})

MapSingle("operator",{list}) : MapSingle performs Apply on every item in {list}, returning a list of the results.


Map("operator",{lists})

Map("operator",{lists}) : {lists} should be a list of lists each the same size. Map performs Apply on every set of items in {lists}, returning a list of the results. Eg. Map("+",{{a,b},{c,d}}) would return {a+c,b+d}.


RandomIntegerVector(nr,from,to)

RandomIntegerVector(nr,from,to) : generate a vector of random integers p in the range [from,to] (including from and to).


MakeVector(var,n)

MakeVector(var,n) : return a vector of unique numbered variable names. Example:
In> MakeVector(a,3)
Out> {a1,a2,a3};


Select(predicate,list)

Select(predicate,list) : return a sublist of list, containing all elements for which the predicate returned after applying the predicate on that list element. Example:
In> Select("IsInteger",{a,b,2,c,3,d,4,e,f})
Out> {2,3,4};