[ Comparing and Sorting | Reference Manual | Alphabetic Index ]

# number_merge(+List1, +List2, -List3)

Succeeds if List3 is a merged list of List1 and List2. If both lists are sorted, List3 will be sorted.

List1
  List of numeric terms.
List2
  List of numeric terms.
List3
  List of numeric terms or variable.

## Description

Used to merge the sorted lists List1 and List2 to give the sorted list List3.

For two lists [e1,e2,e3] and [f1,f2,f3], e1 is compared to f1. The lower (dictated by numerical ordering) is put into List3, and the process continued with the remaining input lists. This process continues until both lists are exhausted.

In particular, this will merge two sorted lists into a sorted list.

The sort is done according to numerical ordering of terms as opposed to merge/3 which uses the standard ordering of terms. Duplicates are not removed. See sort/4 for a discussion of the differences between numerical and standard ordering of numeric types.

number_merge(A, B, M) is equivalent to merge(0, $=<, A, B, M).

### Modes and Determinism

- number_merge(+, +, -) is det

### Exceptions

(4) instantiation fault
  List1 or List2 is not ground.
(5) type error
  List1 or List2 contains non-numeric elements.

## Examples

    Success:
          number_merge([2,4,6],[1,3,5],L).
                                (gives L=[1,2,3,4,5,6]).
          number_merge([f(1),f(7)],[f(8),f(10)],L).
                              (gives L=[f(1),f(7),f(8),f(10)]).
          number_merge([f(5),f(8)],[f(1),f(2),f(2),f(5),f(8)],L).
                (gives L=[f(1),f(2),f(2),f(5),f(5),f(8),f(8)]).
          number_merge([a,w],[a,b,b,r,w],L).
                (gives L=[a,a,b,b,r,w,w]).
          number_merge([f(2),f(1)],[f(3),f(8)],L).
                (gives L=[f(2),f(1),f(3),f(8)]).

    Fail:
          number_merge([2,4,6],[1,3,5],[1,2,3,4,5]).

## See Also

merge / 3, merge / 5