Difference between revisions of "Zip Command"

From GeoGebra Manual
Jump to: navigation, search
m
m (typo in interlink)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
<noinclude>{{Manual Page|version=5}}</noinclude>{{command|list}}
 
<noinclude>{{Manual Page|version=5}}</noinclude>{{command|list}}
;Zip[ <Expression>, <Var1>, <List1>, <Var2>, <List2>, ...]:Creates [[Lists|list]] of objects obtained by substitution of variables in the expression by elements of corresponding lists. Length of the resulting list is minimum of lengths of input lists.
+
;Zip( <Expression>, <Var1>, <List1>, <Var2>, <List2>, ...):Creates [[Lists|list]] of objects obtained by substitution of variables in the expression by elements of corresponding lists. If the number of variables matches the number of lists, each variable is taken from the following list. If the number of variables exceeds number of lists by one, the last variable takes values from 1, 2, 3, ..., ''k'' where ''k'' is the length of the shortest list.  Length of the resulting list is minimum of lengths of input lists.  
:{{example|1=Let P, Q, R, S be some points. <code>Zip[Midpoint[A, B], A, {P, Q}, B, {R, S}]</code> returns a list containing [[Midpoint Command|midpoints]] of segments ''PR'' and ''QS''.}}
+
:{{example|1=Let P, Q, R, S be some points. <code>Zip(Midpoint(A, B), A, {P, Q}, B, {R, S})</code> returns a list containing [[Midpoint Command|midpoints]] of segments ''PR'' and ''QS''.}}
:{{example|1=Let ''list1={x^2, x^3, x^6}'' be a list of polynomials. <code>Zip[Degree[a], a, list1]</code> returns the list ''{2, 3, 6}''.}}
+
:{{example|1=Let ''list1={x^2, x^3, x^6}'' be a list of polynomials. <code>Zip(Degree(a), a, list1)</code> returns the list ''{2, 3, 6}''.}}
 +
:{{example|1=Let ''list1={1, 2, 5}'' be a list of numbers. <code>Zip(Simplify(a*x^(b-1)), a, list1,b)</code> returns the list ''{1, 2x, 5x²}''.}}
  
 
{{Note|In each list the elements must be of the same type.}}
 
{{Note|In each list the elements must be of the same type.}}
 +
 +
==New possibility  > 5.0.258 , functions allowed as variables==
 +
:{{example|1=<code>Zip(f(2), f, {x+1,x+3})</code> returns the list ''{3, 5}''.}}

Latest revision as of 16:21, 12 September 2018


Zip( <Expression>, <Var1>, <List1>, <Var2>, <List2>, ...)
Creates list of objects obtained by substitution of variables in the expression by elements of corresponding lists. If the number of variables matches the number of lists, each variable is taken from the following list. If the number of variables exceeds number of lists by one, the last variable takes values from 1, 2, 3, ..., k where k is the length of the shortest list. Length of the resulting list is minimum of lengths of input lists.
Example: Let P, Q, R, S be some points. Zip(Midpoint(A, B), A, {P, Q}, B, {R, S}) returns a list containing midpoints of segments PR and QS.
Example: Let list1={x^2, x^3, x^6} be a list of polynomials. Zip(Degree(a), a, list1) returns the list {2, 3, 6}.
Example: Let list1={1, 2, 5} be a list of numbers. Zip(Simplify(a*x^(b-1)), a, list1,b) returns the list {1, 2x, 5x²}.


Note: In each list the elements must be of the same type.

New possibility > 5.0.258 , functions allowed as variables

Example: Zip(f(2), f, {x+1,x+3}) returns the list {3, 5}.

Comments

It's actually enough to provide a single list to Zip(). This makes it a shorter alternative to Sequence() when all you want is to traverse a list. For example, Zip(a^2, a, listOfNumbers) is much shorter than Sequence(Element(listOfNumbers, a)^2, a, 1, Length(listOfNumbers)) (albeit in this case it's easier to just do listOfNumbers^2.)

Note Hint: Zip() is similar to a construct known as "map" in other programming languages.
© 2024 International GeoGebra Institute