mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.0t10
This commit is contained in:
58
help/sort
58
help/sort
@@ -23,7 +23,7 @@ DESCRIPTION
|
||||
If x is a matrix, the matrix returned by sort(x) has the same
|
||||
dimension and index limits as x, but for the sorting, x is treated
|
||||
as a one-dimensional array indexed only by the double- bracket
|
||||
notation. Then for both lists and matrices, if x has size n, it
|
||||
notation. Then for both lists and matrices, if x has size n, it
|
||||
may be identified with the array:
|
||||
|
||||
(x[[0]], x[[1]], ..., x[[n-1]])
|
||||
@@ -49,7 +49,7 @@ DESCRIPTION
|
||||
with earlier values b using the integer-valued function precedes();
|
||||
if precedes(a,b) is nonzero, which we may consider as "true",
|
||||
a is "moved" to just before b; if precedes(a,b) is zero, i.e. "false",
|
||||
a remains after b. Until the sorting is completed, other similar
|
||||
a remains after b. Until the sorting is completed, other similar
|
||||
pairs (a,b) are compared and if and only if precedes(a,b) is true,
|
||||
a is moved to before b or b is moved to after a. We may
|
||||
say that the intention of precedes(a,b) being nonzero is that a should
|
||||
@@ -59,13 +59,13 @@ DESCRIPTION
|
||||
but to guarantee fulfilment of the intentions just described,
|
||||
precedes() should satisfy the conditions:
|
||||
|
||||
(1) For all a, b, c, precedes(a,b) implies precedes(a,c) || precedes (c,b),
|
||||
(1) For all a, b, c, precedes(a,b) implies precedes(a,c) || precedes (c,b),
|
||||
|
||||
(2) For all a, b, precedes(a,b) implies !precedes(b,a).
|
||||
(2) For all a, b, precedes(a,b) implies !precedes(b,a).
|
||||
|
||||
Condition (1) is equivalent to transitivity of !precedes():
|
||||
|
||||
(1)' For all a,b,c, !precedes(a,b) && !precedes(b,c) implies !precedes(a,c).
|
||||
(1)' For all a,b,c, !precedes(a,b) && !precedes(b,c) implies !precedes(a,c).
|
||||
|
||||
(1) and (2) together imply transitivity of precedes():
|
||||
|
||||
@@ -95,14 +95,14 @@ DESCRIPTION
|
||||
not y_j1 precedes or follows y_j2 will be determined by the
|
||||
sorting algorithm by methods that are difficult to describe;
|
||||
such a situation may be acceptable to a user not concerned with
|
||||
the order of occurrences of a and b in the result. To permit
|
||||
the order of occurrences of a and b in the result. To permit
|
||||
this, we may now describe the role of precedes(a,b) by the rules:
|
||||
|
||||
precedes(a,b) && !precedes(b,a): a is to precede b;
|
||||
|
||||
!precedes(a,b) && !precedes(b,a): order of a and b not to be changed;
|
||||
|
||||
precedes(a,b) && precedes(b,a): order of a and b may be changed.
|
||||
precedes(a,b) && precedes(b,a): order of a and b may be changed.
|
||||
|
||||
Under the condition (1), the result of sort(x) will accord with these rules.
|
||||
|
||||
@@ -119,13 +119,13 @@ DESCRIPTION
|
||||
null, numbers or strings, precedes(a,b) is given by (a < b).
|
||||
(If a and b are both null, they are considered to be equal, so
|
||||
a < b then returns zero.) For null values, numbers and
|
||||
strings, this definition has the properties (1) and (2)
|
||||
discussed above.
|
||||
strings, this definition has the properties (1) and (2)
|
||||
discussed above.
|
||||
|
||||
If a and b are both xx-objects, a < b is defined to mean
|
||||
xx_rel(a,b) < 0; such a definition does not
|
||||
necessarily give < the properties usually expected -
|
||||
transitivity and antisymmetry. In such cases, sort(x)
|
||||
transitivity and antisymmetry. In such cases, sort(x)
|
||||
may not give the results expected by the "intentions" of
|
||||
the comparisons expressed by "a < b".
|
||||
|
||||
@@ -180,7 +180,7 @@ DESCRIPTION
|
||||
iseven(a) Even numbers in possibly changed order
|
||||
before odd numbers in unchanged order.
|
||||
|
||||
iseven(a) && isoddd(b) Even numbers in unchanged order before
|
||||
iseven(a) && isoddd(b) Even numbers in unchanged order before
|
||||
odd numbers in unchanged order.
|
||||
|
||||
iseven(a) ? iseven(b) ? a < b : 1 : 0
|
||||
@@ -211,34 +211,34 @@ EXAMPLES
|
||||
> print sort(A)
|
||||
|
||||
list (5 elements, 5 nonzero):
|
||||
[[0]] = 1
|
||||
[[1]] = 2
|
||||
[[2]] = 2
|
||||
[[3]] = 4
|
||||
[[4]] = 7
|
||||
[[0]] = 1
|
||||
[[1]] = 2
|
||||
[[2]] = 2
|
||||
[[3]] = 4
|
||||
[[4]] = 7
|
||||
|
||||
> B = list("pear", 2, null(), -3, "orange", null(), "apple", 0)
|
||||
> print sort(B)
|
||||
|
||||
list (8 elements, 7 nonzero):
|
||||
[[0]] = NULL
|
||||
[[1]] = NULL
|
||||
[[2]] = -3
|
||||
[[3]] = 0
|
||||
[[4]] = 2
|
||||
[[5]] = "apple"
|
||||
[[6]] = "orange"
|
||||
[[7]] = "pear"
|
||||
[[0]] = NULL
|
||||
[[1]] = NULL
|
||||
[[2]] = -3
|
||||
[[3]] = 0
|
||||
[[4]] = 2
|
||||
[[5]] = "apple"
|
||||
[[6]] = "orange"
|
||||
[[7]] = "pear"
|
||||
|
||||
> define precedes(a,b) = (iseven(a) && isodd(b))
|
||||
> print sort(A)
|
||||
|
||||
list (5 elements, 5 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 4
|
||||
[[2]] = 2
|
||||
[[3]] = 1
|
||||
[[4]] = 7
|
||||
[[0]] = 2
|
||||
[[1]] = 4
|
||||
[[2]] = 2
|
||||
[[3]] = 1
|
||||
[[4]] = 7
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
Reference in New Issue
Block a user