Table of Contents

Introduction

Set of general usage routines.
 Version 1.13 - 2006/12/30 
Author: Ricardo M. Forno
Direct inquiries and bug reports to: rmforno@tutopia.com
I place these routines in the public domain.
Some of them are derived from native functions in the APL language.
The functions are designed for speed and generality.
The functions are ordered not alphabetically nor by application area, but
 according to dependencies among them.

Table of Contents

Topic

Description

IndexAlphabetical list of all items.
ENCODING / DECODING ROUTINESencoding and decoding routines
MATHmath routines
MISCELLANEOUS ROUTINESmiscellaneous routines
SORTING ROUTINESsorting routines
STATISTICS / PROBABILITIES ROUTINESstatistics and probabilities routines
STRING / SEQUENCE ROUTINES string/sequence manipulation routines

Table of Contents

ENCODING / DECODING ROUTINES

encoding and decoding routines


  • func AnyBase1(atom a, integer len, integer base)   Encodes an atom in a specified numbering base system, with 1-character symbols
  • func AnyBase2(atom a, integer len, integer base)   Encodes an atom in a specified numbering base system, with 2-character symbols
  • func AnyBaseN(atom a, integer len, integer base)   Encodes an atom in a specified numbering base system, with N-character symbols
  • func BaseEvaluation(object a, integer base)   Evaluates a number coded in a specified numbering system
  • func Decode(sequence z, object c)   Decodes a sequence, represented in a numeric (possibly variable) base system into the number it represents
  • func Encode(atom a, object c)   Encodes a number into a numbering (possibly variable) base system
  • func Hexa(atom a, integer len)   Overcomes a shortcoming of printf() to show numbers in hexadecimal notation
  • func Octal(atom a, integer len)   Overcomes a shortcoming of printf() to show numbers in octal notation

    Table of Contents

    MATH

    math routines


  • func Abs(object a)   Computes the absolute value of the argument's elements
  • func And(object a)   Computes the compound 'and' for all argument's elements
  • func And_bits(object a)   Computes the compound 'and_bits' for all argument's elements
  • func Ceil(object a)   Computes next higher argument's integers
  • func CeilTowardsInfinity(object a)   Computes integer greater or equal to argument in absolute value, but with the original sign
  • func Divide(object a)    Alternately divides/multiplies argument's elements
  • func Divisors(atom a)   Obtains all possible divisors of its argument
  • func FloorTowardsZero(object a)   Computes integer less or equal to argument in absolute value, but with the original sign
  • func Frac(object a)   Computes the fractional part of the argument elements
  • func Interpolate(atom x, atom diff, atom last, sequence y)    Interpolates/extrapolates a function given as a sequence
  • func Log10(object a)   Obtains the base 10 logarithms of the atoms in its argument
  • func Max(object a)   Computes the maximum value among all the argument's elements
  • func Mcd(sequence s)   Obtains the Maximum Common Divisor of all the elements of its argument
  • func Mcd2(atom d, atom r)   Obtains the Maximum Common Divisor of two numbers
  • func Mcm(sequence s)   Obtains the Minimum Common Multiple of all the elements of its argument
  • func Mcm2(atom a, atom b)   Obtains the Minimum Common Multiple of two numbers
  • func Min(object a)   Computes the minimum value among all the argument's elements
  • func Or(object a)   Computes the compound 'or' for all argument's elements
  • func Or_bits(object a)   Computes the compound 'or_bits' for all argument's elements
  • func Prime(atom a)   Determines if a number is prime or not
  • func PrimeFactors(atom a)   Obtains the prime factors of its argument
  • func Product(object a)   Multiplies together all the argument's elements
  • func Residue(object a, object d)   Variation of remainder(), giving different results for non-positive arguments
  • func Round(object a)   Rounds argument's elements to the nearest integer
  • func RoundCents(object a, object cent)   Rounds argument's elements to a specified precision
  • func Sign(object a)   Obtains the signs of the argument's elements. Sign is -1, 0 or 1
  • func Subtract(object a)   Sums the argument's elements with alternate signs
  • func Sum(object a)   Computes the sum of all the argument's elements
  • func Xor(object a)   Computes the compound 'xor' (i.e., !=) for all argument's elements
  • func Xor_bits(object a)   Computes the compound 'xor_bits' for all argument's elements

    Table of Contents

    MISCELLANEOUS ROUTINES

    miscellaneous routines


  • func Apply1(integer id, object a)   Applies a 1-parameter function with id # 'id' to all elements of 'a', recursively
  • func Apply2(integer id, object a, object b)   Applies a 2-parameter function with id # 'id' to all elements of 'a' and 'b', recursively
  • func BinSeek(object x, sequence s, integer min, integer max)   Finds the index of the first argument in the second argument, between the indexes indicated by the third and fourth arguments
  • func CountEqual(sequence base, sequence look)   Counts the number of times each element of the second argument is in the first argument
  • func CountGreater(sequence base, sequence look)   Counts the number of times each element of the second argument is greater than the elements in the first argument
  • func CountGreaterEqual(sequence base, sequence look)   Counts the number of times each element of the second argument is greater or equal to the elements in the first argument
  • func CountLower(sequence base, sequence look)   Counts the number of times each element of the second argument is lower than the elements in the first argument
  • func CountLowerEqual(sequence base, sequence look)   Counts the number of times each element of the second argument is lower or equal to the elements in the first argument
  • func CountNotEqual(sequence base, sequence look)   Counts the number of times each element of the second argument is not equal to the elements in the first argument
  • func In(sequence base, sequence look)   shows unique elements of 'look' matching elements of 'base'
  • func IndexGenerator(integer n)   Generates a simple sequence with the numbers from 1 to the argument
  • func IndexOf(sequence base, sequence look)   Obtains the indexes of the second argument's elements in the first argument
  • func InnerProduct(integer id1, integer id2, object a, object b)   Applies two 2-parameter functions with ids # 'id1' and 'id2' to arguments 'a' and 'b' as in matrix multiplication
  • func MaxDepth(object o)   Obtains the maximum depth of an object
  • func Membership(sequence base, sequence look)   Finds if the elements of the second argument are in the first argument
  • func MultipleFind(object o, sequence t)   Obtains the list of indexes of the first argument in the second one
  • func MultipleMatch(sequence s, sequence t)   Obtains the list of indexes of the first argument in slices of the second one
  • func NotIn(sequence base, sequence look)   shows unique elements of 'look' not matching elements of 'base'
  • func OuterProduct(integer id, object a, object b)   Applies a 2-parameter function with id # 'id' to all possible pairings of elements of a and b
  • func RangeFind(object x, sequence s, integer pos1, integer pos2)   Gets the index of an object in a sequence between bounds
  • func Ravel(object a)   Generates a simple sequence with all the argument's elements
  • func Reduce(integer id, object a)   Applies a 2-parameter function with id # 'id' to successive pairs of elements of 'a', recursively
  • func ReshapeAs(object s, object f)   Reshapes (re-structures) the first argument in the shape (structure) of the second argument
  • func Scan(integer id, object a)   Applies a 2-parameter function with id # 'id' to successive pairs of elements of 'a' in cumulative fashion, recursively
  • func Structure(object o)   Gets the structure of its argument
  • func Unique(sequence a)   Sorts the elements of its argument and discards duplicates

    Table of Contents

    SORTING ROUTINES

    sorting routines


  • func GradeDown(sequence s, integer n)   Sorts data in descending fashion by a Von Neumann merge method
  • func GradeDownNWay(sequence s, integer n)   Sorts data in descending fashion by a Von Neumann merge method
  • func GradeUp(sequence s, integer n)   Sorts data in ascending fashion by a Von Neumann merge method
  • func GradeUpNWay(sequence s, integer n)   Sorts data in ascending fashion by a Von Neumann merge method
  • func SortUp(sequence s)   Sorts data in ascending fashion by a Von Neumann merge method
  • func SortUpNWay(sequence s)   Sorts data in ascending fashion by a Von Neumann merge method

    Table of Contents

    STATISTICS / PROBABILITIES ROUTINES

    statistics and probabilities routines


  • func BetaDistr(atom b, atom c)   Gives a random real number according to the Euler's Beta probability distribution
  • func Biasto1Distr(integer times, integer max)   Gives a biased random integer
  • func BiastoMaxDistr(integer times, integer max)   Gives a biased random integer
  • func BilateralExpDistr()   Gives a random real number according to the Bilateral probability distribution
  • func CauchyDistr()   Gives a random real number according to the Cauchy probability distribution
  • func Deal(integer upto, integer howmany)   Obtains a sequence of non-repeating random integers
  • func Deal1(integer upto, integer howmany)   Obtains a sequence of non-repeating random integers
  • func DealFast(integer upto, integer howmany)    Generates non-repeating random integers by an algorithm that does not use much memory / CPU time
  • func DealFast2(integer upto, integer howmany)    Generates non-repeating random integers by an algorithm that does not use much memory / CPU time
  • func DealSorted(integer upto, integer howmany)   Obtains an ordered sequence of non-repeating random integers
  • func DealSorted1(integer upto, integer howmany)   Obtains an ordered sequence of non-repeating random integers
  • func DoubleExp(atom a, atom b, atom c, atom d, atom x)   Maps the range 0 to 1 into the same one, using a Double Exponential function
  • func ExponentialDistr()   Gives a random real number according to the Exponential probability distribution
  • func GammaDistr(integer spread)   Gives a random real number according to the Gamma probability distribution
  • func GaussDistr(atom mean, atom dev)   Gives a random real number according to the Gauss probability distribution
  • func HypCosDistr()   Gives a random real number according to the Hyperbolic Cosine probability distribution
  • func Linear0Distr()   Gives a random real number according to the Linear probability distribution, with highest value at 0
  • func Linear1Distr()   Gives a random real number according to the Linear probability distribution, with highest value at 1
  • func LogisticDistr()   Gives a random real number according to the Logistic probability distribution
  • func Mapdiv(object min, object dif, object a)   Maps real numbers in the range 0 1 to the range from min to min + dif, using a division method
  • func Mapfromminf(object a)   Maps real numbers in the range -infinity 0 +infinity to -1 0 1
  • func Maplin(object min, object dif, object a)   Linearly maps real numbers in the range 0 1 to the range from min to min + dif
  • func Maplog(object min, object dif, object a)   Logarithmically maps real numbers in the range 0 1 to the range from min to min + dif
  • func Mapto01(object a)   Maps real numbers from the range -1 0 1 to 0 0.5 1
  • func Mapto101(object a)   Maps real numbers from the range 0 0.5 1 to -1 0 1
  • func Maptoinf(object a)   Maps real numbers in the range 0 0.5 1 to 0 1 +infinity
  • func Maptominf(object a)   Maps real numbers in the range -1 0 1 to -infinity 0 +infinity
  • func Maptoone(object a)   Maps real numbers in the range 0 1 +infinity to 0 0.5 1
  • func Marsaglia()   Generates random integers by the MacLaren & Marsaglia method
  • func OneCyclePermutation(integer n)   Obtains a random one-cycle permutation of the integers up to n
  • func Permutation(sequence set, integer size, integer which)   Obtains a permutation of the elements of a set
  • func PoissonDistr(atom spread)   Gives a random integer according to the Poisson probability distribution
  • func Random(integer seed)   Generates random integers by a different algorithm
  • func RandomPermutation(integer n)   Obtains a random permutation of the integers up to n
  • func Scramble(sequence s)   Scrambles, that is, disorders a sequence
  • func Smallint()   Gives a random small integer, biased towards low values
  • func TriangleDistr()   Gives a random real number according to the Triangular probability distribution, with highest value at 1
  • func WeibullDistr(atom denshape)   Gives a random real number according to the Weibull probability distribution

    Table of Contents

    STRING / SEQUENCE ROUTINES

    string/sequence manipulation routines


  • func Drop(sequence s, integer n)   Drops a specified number of elements from the first argument
  • func Expand(sequence s, sequence a)   More or less the inverse of Replicate()
  • func Index(sequence s, object r)   The second argument atoms act as indexes to select elements of the first argument
  • func RemoveAllElements(sequence goal, object look)   Removes every element in the first argument matching the second argument
  • func RemoveAllSlices(sequence goal, sequence look)   Removes every slice in the first argument matching the second argument
  • func RemoveAllSlicesX(sequence goal, sequence look)   Removes every slice in the first argument matching the second argument
  • func RemoveFirstElement(sequence goal, object look)   Removes the first object in the first argument matching the second argument
  • func RemoveFirstSlice(sequence goal, sequence look)   Removes the first slice in the first argument matching the second argument
  • func ReplaceAllElements(sequence goal, object look, object new)   Replaces every element in the first argument matching the second argument by the third argument
  • func ReplaceAllSlices(sequence goal, sequence look, sequence new)   Replaces every slice in the first argument matching the second argument by the third argument
  • func ReplaceFirstElement(sequence goal, object look, object new)   Replaces the first element in the first argument matching the second argument by the third argument
  • func ReplaceFirstSlice(sequence goal, sequence look, sequence new)   Replaces the first slice in the first argument matching the second argument by the third argument
  • func Replicate(object r, object s)    Selects / replicates elements of the second argument according to the first argument
  • func ReplicateNR(object r, object s)    Selects / replicates elements of the second argument according to the first argument
  • func Reverse(sequence s)   Reverses the order of a sequence
  • func Rotate(sequence s, integer n)   Rotates a sequence a specified number of places
  • func Select(sequence s, sequence r)   The second argument sub-sequences act as indexes to select elements of the first argument
  • func Take(sequence s, integer n)   Takes a specified number of elements from the first argument

    Table of Contents

    [func]
    Abs
    (object a)

    Computes the absolute value of the argument's elements

    Returns: Argument if argument >= 0, -argument otherwise

    Category: MATH

    Returns the absolute value of the corresponding elements in the argument. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function Abs(object a)
      return (2 * (a > 0) - 1) * a
    end function
    
    Example: Abs({0,7.67,-8.45}) gives {0,7.67,8.45}

    See Also: And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    And
    (object a)

    Computes the compound 'and' for all argument's elements

    Returns: Integer valued 0 or 1, representing the compound 'and' of all argument's elements

    Category: MATH

    Returns as an atom the compound 'and' of all the elements of the argument, no matter how deeply nested they are. Recall that for the logical functions, every value different from 0 is 1 (true), and 0 is false. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function And(object a)
      atom b
      if atom(a) then
          return a and 1
      end if
      b = 1
      for i = 1 to length(a) do
          b = b and And(a[i])
          if not b then
              return 0
          end if
      end for
      return b
    end function
    
    Examples: And({7, 2, -6.76}) gives 1. And({9,0,-4}) gives 0. 1 is returned for empty arguments. For atoms, 0 is returned if the atom is 0, 1 otherwise

    See Also: Abs, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    And_bits
    (object a)

    Computes the compound 'and_bits' for all argument's elements

    Returns: Integer (not necessarily an Euphoria-integer) representing the compound 'and_bits' of all argument's elements

    Category: MATH

    Returns as an atom the compound 'and_bits' of all the elements of the argument, no matter how deeply nested they are. For example, And_bits({6, 7, 11}) is 2. This is computed as follows: using only 4 bits for simplicity, 6 is 0110 and 7 is 0111 in binary. Then and_bits(6, 7) is computed as 0 and 0 = 0, 1 and 1 = 1, 1 and 1 = 1, 0 and 1 = 0, that is, 0110 = 6. Then and_bits(6, 11) is computed as 0110 and 1011 = 0010 = 2. #FFFFFFFF is returned for void arguments. For non-integers less than 2^32, the integer part (rounded towards zero) is used. For numbers equal or greater than 2^32 or less than -(2^31), and_bits crashes. These are features of the Euphoria language, not of the present function. New speed-up thanks to ideas from Jiri and Pete (Eberlein?). The old version was:

    global function And_bits(object a)
      atom b
      if atom(a) then
          return and_bits(a, #FFFFFFFF)
      end if
      b = #FFFFFFFF
      for i = 1 to length(a) do
          b = and_bits (b, And_bits(a[i]))
      end for
      return b
    end function
    

    See Also: Abs, And, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    AnyBase1
    (atom a, integer len, integer base)

    Encodes an atom in a specified numbering base system, with 1-character symbols

    Returns: Sequence containing the encoded number

    Category: ENCODING / DECODING ROUTINES

    This function codes an atom 'a' into the numbering system having base 'base', giving a result with length 'len'. The floor() of 'a' is taken if 'a' is a fraction. Each result digit is taken from a sequence comprising digits from 0 to 9 and letters from A to Z. Negative values of 'a' are shown in complement form. If 'len' is less or equal to 0, an empty string is returned. If 'base' is less than 2 or greater than the length of LETTERS, an atom valued -1 is returned. Example: AnyBase1(5, 4, 2) gives "0101"

    See Also: AnyBase2, AnyBaseN, BaseEvaluation, Decode, Encode, Hexa, Octal


    Table of Contents

    [func]
    AnyBase2
    (atom a, integer len, integer base)

    Encodes an atom in a specified numbering base system, with 2-character symbols

    Returns: Sequence containing the encoded number

    Category: ENCODING / DECODING ROUTINES

    This function codes an atom 'a' into the numbering system with base 'base', giving a result with length 'len'. The floor of 'a' is taken if 'a' is a fraction. Each result 'digit' is formed by 2 real digits in decimal notation. This is intended to represent codes with large bases, say from 37 to 100. So, the actual length of the result is twice the specified length. Negative values of 'a' are shown in complement form. If 'len' is less than 0, an empty string is returned. If 'base' is less than 2 or greater than 100, an atom valued -1 is returned. Example: AnyBase2(3456789, 8, 43) gives "0000000100202319"

    See Also: AnyBase1, AnyBaseN, BaseEvaluation, Decode, Encode, Hexa, Octal


    Table of Contents

    [func]
    AnyBaseN
    (atom a, integer len, integer base)

    Encodes an atom in a specified numbering base system, with N-character symbols

    Returns: Sequence containing the encoded number

    Category: ENCODING / DECODING ROUTINES

    This function codes an atom 'a' into the numbering system with base 'base', giving a result with length 'len'. The floor of 'a' is taken if 'a' is a fraction. Each result 'digit' is formed by N real digits in decimal notation, where N is the minimum size necessary to accommodate digits in the 'base' numbering system. So, the actual length of the result is N times the specified length. Negative values of 'a' are shown in complement form. If 'len' is less than 0, an empty string is returned. If base is less than 2, an atom valued -1 is returned. Example: AnyBase(1234567890, 4, 1000) gives "001234567890"

    See Also: AnyBase1, AnyBase2, BaseEvaluation, Decode, Encode, Hexa, Octal


    Table of Contents

    [func]
    Apply1
    (integer id, object a)

    Applies a 1-parameter function with id # 'id' to all elements of 'a', recursively

    Returns: Result of applying the function

    Category: MISCELLANEOUS ROUTINES

    Example: Apply1(routine_id("Random", {56, 34})) gives {384104, 233206} The result has the same structure of the argument. A similar routine appears in the Euphoria documentation, under routine_id.

    See Also: Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Apply2
    (integer id, object a, object b)

    Applies a 2-parameter function with id # 'id' to all elements of 'a' and 'b', recursively

    Returns: Result of applying the function

    Category: MISCELLANEOUS ROUTINES

    Example: Apply2(routine_id("Mcd2", {6, 8}, {4, 9})) gives {2, 1} If both arguments are atoms, the result is an atom. If one is a sequence and the other an atom, the result is a sequence with the same length as the argument that is a sequence. If both arguments are sequences with the same length, the result is a sequence of this length. If both arguments are sequences, but their lengths are not equal, the result is a sequence having as length the minimum common multiple of the two sequences' lengths. The elements of the result are obtained applying one sequence to the other, shifted as necessary. For example: Apply2(routine_id("Mcd2", {12, 28}, {24, 14, 36}) gives {12,14,12,4,2,4}. This rule is recursively applied if the elements are not atoms. The applied function may be anyone, with the proviso that: 1) It has exactly 2 parameters. 2) These parameters are defined, each one, either as objects, atoms or integers, but not sequences, since the application will be carried to the lowest level, that is, atoms, and an attempt to pass an atom to a sequence will fail. If you want to apply a primitive operation such as addition (+) or remainder(), this operation should be wrapped within a user-defined function, because it is not possible to get a routine_id for primitive operations. For example: function add(atom a, atom b) return a + b end function This routine uses the Mcm2() routine, that uses the Mcd2() routine.

    See Also: Apply1, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    BaseEvaluation
    (object a, integer base)

    Evaluates a number coded in a specified numbering system

    Returns: An atom resulting from the evaluation of a number coded in a specified numeric base system

    Category: ENCODING / DECODING ROUTINES

    This function evaluates a number 'a' coded in the numbering system with base 'base'. The elements of 'a' should belong to the constant LETTERS. If 'a' is an atom, it is previously converted to a sequence. If any element from 'a' is not found in LETTERS[1..base], then an empty sequence is returned. Otherwise, an atom with the calculated value is returned. Result is an integer, but not necessarily an Euphoria integer (less than 2^31). No provision is made to allow for negative numbers. They are assumed to be written in complement notation, so representing valid positive numbers. If a number is presumed to be negative by the user, he/she should perform the conversion as needed. Example: BaseEvaluation("0101", 2) gives 5

    See Also: AnyBase1, AnyBase2, AnyBaseN, Decode, Encode, Hexa, Octal


    Table of Contents

    [func]
    BetaDistr
    (atom b, atom c)

    Gives a random real number according to the Euler's Beta probability distribution

    Returns: A random real number between 0.0 and 1.0

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: BetaDistr(0.4, 0.2) may give 0.104106 The b and c parameters are probabilities, and then should be between 0 and 1. b controls the probability of values near 0, and c near 1. The resulting probability distribution is a curve with both ends higher than the middle section.

    See Also: Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Biasto1Distr
    (integer times, integer max)

    Gives a biased random integer

    Returns: A random integer between 1 and max, biased 'times' towards 1

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Biasto1Distr(3, 50) may give 4 This distribution peaks at 1, diminishing upwards. 'times' is the number of times it is iterated, that is, the amount of biasing, and 'max' is the maximum possible result.

    See Also: BetaDistr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    BiastoMaxDistr
    (integer times, integer max)

    Gives a biased random integer

    Returns: A random integer between 1 and max, biased 'times' towards 'max'

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: BiastoMaxDistr(3, 50) may give 47 This distribution peaks at max, diminishing downwards. 'times' is the number of times it is iterated, that is, the amount of biasing, and 'max' is the maximum possible result.

    See Also: BetaDistr, Biasto1Distr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    BilateralExpDistr
    ()

    Gives a random real number according to the Bilateral probability distribution

    Returns: A random real number between -infinity and +infinity, centered at 0

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: BilateralExpDistr() may give -1.436541 This distribution has a sharp peak at 0.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    BinSeek
    (object x, sequence s, integer min, integer max)

    Finds the index of the first argument in the second argument, between the indexes indicated by the third and fourth arguments

    Returns: Index of the first argument in the second argument, between two other indexes

    Category: MISCELLANEOUS ROUTINES

    Finds index of 'x' in 's' between indexes 'min' and 'max'. 's' should be sorted in ascending fashion. If 'x' is not found, it returns the negative of the position where it would have to be inserted (like EDS). For performance reasons, 'min' and 'max' are not checked for validity, and hence out of range values will cause the routine to crash. Examples: BinSeek(16,{1,5,8,16,22,30},2,6) gives 4. BinSeek(7,{1,5,8,16,22,30},2,6) gives -3.

    See Also: Apply1, Apply2, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    CauchyDistr
    ()

    Gives a random real number according to the Cauchy probability distribution

    Returns: A random real number between -infinity and +infinity, centered at 0

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: CauchyDistr() may give 3.765932 This distribution peaks smoothly at 0 and has a shape similar to the Normal (Gaussian) distribution, but with higher probabilities for values very far from the middle point.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Ceil
    (object a)

    Computes next higher argument's integers

    Returns: Integers greater or equal to argument's elements

    Category: MATH

    Returns the integers that are greater or equal to each element in the argument. New speed-up thanks to Jiri and Pete (Eberlein?) The old version was:

    global function Ceil(object a)
      return - floor(- a)
    end function
    
    Example: Ceil({8,-5,3.14,4.89,-7.62,-4.3}) gives {8,-5,4,5,-7,-4}

    See Also: Abs, And, And_bits, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    CeilTowardsInfinity
    (object a)

    Computes integer greater or equal to argument in absolute value, but with the original sign

    Returns: Integers greater or equal to the argument's elements in absolute value, but with the original sign

    Category: MATH

    Returns the integers greater or equal to the argument's elements in absolute value but with the corresponding sign. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function CeilTowardsInfinity(object a)
      object b
      b = 1 - 2 * (a > 0)
      return b * floor(a * b)
    end function
    
    Example: CeilTowardsInfinity({5.67,-56,-1.37}) gives {6,-56,-2}

    See Also: Abs, And, And_bits, Ceil, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    CountEqual
    (sequence base, sequence look)

    Counts the number of times each element of the second argument is in the first argument

    Returns: Number of times each element of the second argument is in the first argument

    Category: MISCELLANEOUS ROUTINES

    This function obtains the number of times each of the elements in 'look' is in 'base'. This function calls the GradeUp() routine. The algorithm used is much faster than a brute-force approach. The result is a sequence of integers with the length of 'look'. Example: CountEqual({3,5,3,8},{1,8,3}) gives {0,1,2}

    See Also: Apply1, Apply2, BinSeek, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    CountGreater
    (sequence base, sequence look)

    Counts the number of times each element of the second argument is greater than the elements in the first argument

    Returns: Number of times each element of the second argument is greater than the elements in the first argument

    Category: MISCELLANEOUS ROUTINES

    This function obtains the number of times each of the elements in 'look' is greater than the elements in 'base'. This function calls the GradeUp() routine. The algorithm used is much faster than a brute-force approach. The result is a sequence of integers with the length of 'look'. Example: CountGreater({3,5,2,8},{1,8,3}) gives {0,3,1}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    CountGreaterEqual
    (sequence base, sequence look)

    Counts the number of times each element of the second argument is greater or equal to the elements in the first argument

    Returns: Number of times each element of the second argument is greater or equal to the elements in the first argument

    Category: MISCELLANEOUS ROUTINES

    This function obtains the number of times each of the elements in 'look' is greater or equal the elements in 'base'. This function calls the GradeUp() routine. The algorithm used is much faster than a brute-force approach. The result is a sequence of integers with the length of 'look'. Example: CountGreaterEqual({3,5,2,8},{1,8,3}) gives {0,4,2}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    CountLower
    (sequence base, sequence look)

    Counts the number of times each element of the second argument is lower than the elements in the first argument

    Returns: Number of times each element of the second argument is lower than the elements in the first argument

    Category: MISCELLANEOUS ROUTINES

    This function obtains the number of times each of the elements in 'look' is lower than the elements in 'base'. This function calls the CountGreaterEqual() routine, which in turn calls GradeUp(). The algorithm used is much faster than a brute-force approach. The result is a sequence of integers with the length of 'look'. Example: CountLower({3,5,2,8},{1,8,3}) gives {4,0,2}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    CountLowerEqual
    (sequence base, sequence look)

    Counts the number of times each element of the second argument is lower or equal to the elements in the first argument

    Returns: Number of times each element of the second argument is lower or equal to the elements in the first argument

    Category: MISCELLANEOUS ROUTINES

    This function obtains the number of times each of the elements in 'look' is lower or equal the elements in 'base'. This function calls the CountGreater() routine, which in turn calls GradeUp(). The algorithm used is much faster than a brute-force approach. The result is a sequence of integers with the length of 'look'. Example: CountLowerEqual({3,5,2,8},{1,8,3}) gives {4,1,3}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    CountNotEqual
    (sequence base, sequence look)

    Counts the number of times each element of the second argument is not equal to the elements in the first argument

    Returns: Number of times each element of the second argument is not equal to the elements in the first argument

    Category: MISCELLANEOUS ROUTINES

    This function obtains the number of times each of the elements in 'look' is not equal to the elements in 'base'. This function calls the CountGreaterEqual() routine, which in turn calls GradeUp(). The algorithm used is much faster than a brute-force approach. The result is a sequence of integers with the length of 'look'. Example: CountNotEqual({3,5,3,8},{1,8,3}) gives {4,3,2}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Deal
    (integer upto, integer howmany)

    Obtains a sequence of non-repeating random integers

    Returns: Sequence of non-repeating random integers

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence containing 'howmany' random non-repeating integers from 1..upto. 'howmany' must be less or equal than 'upto'. Otherwise, the function crashes. If 'upto' is too big, memory problems may occur. In such a case, you may use DealSorted (see below) and then apply Scramble (see also below) to the resulting sequence if necessary. Example: Deal(20, 5) might give {6,18,1,7,14} To repeat results (for program testing), initialize the seed by means of set_rand() before using the routine.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Deal1
    (integer upto, integer howmany)

    Obtains a sequence of non-repeating random integers

    Returns: Sequence of non-repeating random integers

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence containing 'howmany' random non-repeating integers from 1..upto. 'howmany' must be less or equal than 'upto'. Otherwise, the function enters an unending loop. This function does not present memory problems, but its running time may be greater than the one for Deal(). Example: Deal1(20, 5) might give {6,18,1,7,14} To repeat results (for program testing), initialize the seed by means of set_rand() before using the routine.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    DealFast
    (integer upto, integer howmany)

    Generates non-repeating random integers by an algorithm that does not use much memory / CPU time

    Returns: Sequence of non-repeating random numbers

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence of 'howmany' random integers, without repetition, taken from 1..upto. If hownany > upto, it starts repeating numbers cyclically. This algorithm (for which I have no good justification, but it works) is faster than any other (except when 'howmany' and 'upto' are small, due to its larger initialization time). It also uses the minimum amount of storage. It does not allow for the generation of all possible permutations. It does not satisfy randomness tests. For an even faster execution, when 'upto' is fixed, you may previously call subroutine calcpot3(), get hold of its result, and provide it as an additional parameter instead of calling calcpot3() inside the main routine. This algorithm can be easily modified to treat the problem of synonyms while accessing a file through hashing routines. You can provide the hashed key as an argument to the set_rand() function, getting the first location to try. If the bin is full, you can get the next location to try by iterating the formula u = remainder(x - 2 * u, pot3). This way, you can scan the whole file without inspecting any location more than once, and without scanning successive locations, which tends to develop clusters. Example: DealFast(30, 7) might give {15,27,5,12,26,1,20}

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    DealFast2
    (integer upto, integer howmany)

    Generates non-repeating random integers by an algorithm that does not use much memory / CPU time

    Returns: Sequence of non-repeating random numbers

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence of 'howmany' random integers, without repetition, taken from 1..upto. If hownany > upto, it starts repeating numbers cyclically. This algorithm (for which I have no good justification, but it works) is faster than any other (except when 'howmany' and 'upto' are small, due to its larger initialization time). It also uses the minimum amount of storage. It does not allow for the generation of all possible permutations. It does not satisfy some randomness tests. It is similar to DealFast, but even faster This algorithm can be easily modified to treat the problem of synonyms while accessing a file through hashing routines. You can provide the hashed key as an argument to the set_rand() function, getting the first location to try. If the bin is full, you can get the next location to try by iterating the formula u = and_bits(x - 3 * u, z). This way, you can scan the whole file without inspecting any location more than once, and without scanning successive locations, which tends to develop clusters. Example: DealFast2(30, 7) might give {15,27,5,12,26,1,20}

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    DealSorted
    (integer upto, integer howmany)

    Obtains an ordered sequence of non-repeating random integers

    Returns: Sequence of non-repeating, ordered random integers

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence containing 'howmany' non-repeating, ordered integers from 1..upto. Algorithm taken and adapted from Jon Bentley's "Programming Pearls", page 118, who in turn took it from Donald Knuth's "Semi numerical Algorithms". When 'howmany' is much smaller than 'upto', it is faster to use the Deal() function followed by a sort, for example SortUp(). Example: DealSorted(20,5) might give {4,7,8,17,19} To repeat results (for program testing), initialize the seed by means of set_rand() before using the routine.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    DealSorted1
    (integer upto, integer howmany)

    Obtains an ordered sequence of non-repeating random integers

    Returns: Sequence of non-repeating, ordered random integers

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence containing 'howmany' ordered random non-repeating integers from 1..upto. 'howmany' must be less or equal than 'upto'. Otherwise, the routine enters an unending loop. This function does not present memory problems and is faster than DealSorted() when 'upto' is much greater than 'howmany'. It calls BinSeek(). Example: DealSorted1(35, 7) might give {3,10,12,21,29,30,32} To repeat results (for program testing), initialize the seed by means of set_rand() before using the routine.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Decode
    (sequence z, object c)

    Decodes a sequence, represented in a numeric (possibly variable) base system into the number it represents

    Returns: Value decoded according to its representation and the base

    Category: ENCODING / DECODING ROUTINES

    This function decodes a sequence 'z' representing a number coded in the variable base numeration 'c' into the number it represents. If 'c' is an atom, it is previously transformed into an one-element sequence. 'c' and 'z' should have the same length; if not, an error is reported. Normally, both 'c' and 'z' are simple sequences, but they may be compound ones, with the restriction that all their elements are either atoms, or sequences sharing the same structure; normal Euphoria rules governing mixed operations among atoms and sequences then apply. The result may be an atom or a sequence, depending on c being a simple sequence or a compound one. If lengths do not match, the function aborts with code 1. The function may crash if the restrictions are not observed. This function has been borrowed from the APL language. Example: Decode ({24, 60, 60}, {1, 1, 1}) gives 3661. That is, 1 hour 1 minute 1 second equals 3661 seconds

    See Also: AnyBase1, AnyBase2, AnyBaseN, BaseEvaluation, Encode, Hexa, Octal


    Table of Contents

    [func]
    Divide
    (object a)

    Alternately divides/multiplies argument's elements

    Returns: Division between all argument's elements grouped from right to left

    Category: MATH

    Returns as an atom the division of all the elements of the argument, no matter how deeply nested they are. This function can be useful for computing certain mathematical formulae. Example: Divide({5,4,2}) is 5/(4/2), giving 2.5, which is the same as (5/4)*2 The nested sequences are computed previously to its use in higher level sequences. This function does not crash if a divisor is 0. Rather, the result of an intermediate or final operation with a zero divisor is 1, plus or minus infinity, respectively for 0, positive or negative dividends. That is, 0/0 is 1, 5/0 is plus infinity, -3/0 is minus infinity. Any number divided into plus or minus infinity is 0. Infinity divided into infinity results in nan or -nan (not a number). This is useful to bypass the problem of zero divisors. 1 is returned for empty arguments.

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Divisors
    (atom a)

    Obtains all possible divisors of its argument

    Returns: Sequence containing an ordered list of the divisors of its argument

    Category: MATH

    Returns a sequence containing an ordered list of divisors of 'a', including 1 and 'a' itself. {1} is returned for arguments lower than or equal to 1, greater than 2^53, or fractions. This routine calls the functions PrimeFactors() and SortUp(). Example: Divisors(60) gives {1,2,3,4,5,6,10,15,20,30,60}

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    DoubleExp
    (atom a, atom b, atom c, atom d, atom x)

    Maps the range 0 to 1 into the same one, using a Double Exponential function

    Returns: A number in the range 0 to 1

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: DoubleExp(0.47, 3.0, 3.5, 0.52, 0.7) gives 0.685301 This function is mostly used in studies and simulation of population (of anything) growth. Coefficients a and d should be around 0.5; coefficients b and c should be between 1 and 5, approximately.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Drop
    (sequence s, integer n)

    Drops a specified number of elements from the first argument

    Returns: Sequence 's' without the first 'n' elements

    Category: STRING / SEQUENCE ROUTINES

    The result is a sequence containing the remaining elements of 's' after the first 'n' elements are dropped. If 'n' is negative, the elements dropped are the last Abs(n). When Abs(n) is greater than the length of 's', the result is the null sequence. A similar native function exists in the APL language. Examples: Drop({1,2,3,4,5}, 2) gives {3,4,5}. Drop({1,2,3,4,5}, -2) gives {1,2,3}. Drop("ABCD", 7) gives {}.

    See Also: Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    Encode
    (atom a, object c)

    Encodes a number into a numbering (possibly variable) base system

    Returns: Sequence containing the number coded in the numeric base system

    Category: ENCODING / DECODING ROUTINES

    This function encodes atom 'a' in the variable base numeration represented by object 'c'. If 'c' is an atom, it is previously transformed into a one-element sequence. Normally 'c' should be a simple sequence, but it may be a composite one, with the restriction that all its elements are either atoms, or sequences sharing the same structure; normal Euphoria rules for mixed operations among atoms and sequences are then applied. If 'a' is not an integer, its fractional part will appear together with the last "digit". Negative values will be represented in complement form. The result is always a sequence, either a simple or a compound one, depending on 'c' being a simple or a compound sequence. The function may crash if the restrictions are not observed. This function has been borrowed from the APL language. Example: Encode ({24, 60, 60}, 3661) gives {1, 1, 1}. That is, 3661 seconds are 1 hour 1 minute 1 second

    See Also: AnyBase1, AnyBase2, AnyBaseN, BaseEvaluation, Decode, Hexa, Octal


    Table of Contents

    [func]
    Expand
    (sequence s, sequence a)

    More or less the inverse of Replicate()

    Returns: Second argument with zero atoms added under control of the first argument

    Category: STRING / SEQUENCE ROUTINES

    This function is more or less the inverse of Replicate(). The number of non-zero atoms in 's' at each nesting level must be equal to the length of the corresponding element in 'a'. A non-zero atom in 's' selects the corresponding element in 'a', and a zero atom inserts a zero atom into the result. If the assumptions are not meet, the routine aborts with code 1. A non-recursive Expand is not needed because the depth of the result is identical to the depth of 'a'. A similar native function exists in the APL language. Example: Expand({1, 0, 1}, {10, 20}) gives {10, 0, 20}

    See Also: Drop, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    ExponentialDistr
    ()

    Gives a random real number according to the Exponential probability distribution

    Returns: A random real number between 0 and +infinity

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: ExponentialDistr() may give 1.1156438 This distribution has a sharp peak at 0, and diminishes fast for higher values. See Smallint() function for integer results.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    FloorTowardsZero
    (object a)

    Computes integer less or equal to argument in absolute value, but with the original sign

    Returns: Integers less or equal to the argument's elements in absolute value, but with the original sign

    Category: MATH

    Returns the integers less or equal to the argument elements in absolute value but with the corresponding sign. This is easier to understand than to describe. The function name tells it all. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function FloorTowardsZero(object a)
      object b
      b = 2 * (a > 0) - 1
      return b * floor(a * b)
    end function
    
    Example: FloorTowardsZero({2.3,-5.65,-8}) gives {2,-5,-8}

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Frac
    (object a)

    Computes the fractional part of the argument elements

    Returns: Fractional part of the argument's elements

    Category: MATH

    Returns the fractional part of the argument's elements. The fraction has the sign of the corresponding element. New speed-up thanks to ideas from Jiri and Pete (Eberlein?). The old version was:

    global function Frac(object a)
      object b
      b = 2 * (a > 0) - 1
      return a - b * floor(a * b)
    end function
    
    Example: Frac({6.12,8,-3.43}) gives {0.12,0,-0.43}

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    GammaDistr
    (integer spread)

    Gives a random real number according to the Gamma probability distribution

    Returns: A random real number between 0 and +infinity

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: GammaDistr(5) may give 2.878646 This distribution starts with a 0 value at 0, then increases up to a maximum and then decreases for higher values.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    GaussDistr
    (atom mean, atom dev)

    Gives a random real number according to the Gauss probability distribution

    Returns: A random real number between -infinity and +infinity, centered at 'mean'

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: GaussDistr(10.0, 2.0) may give 9.569933 This is the Normal distribution, centered at 'mean' and with standard deviation 'dev'. The algorithm simulates an actual measure taken a number of times. It has been established that using 12 as the number of simulated measures gives enough approximation to the exact values of the distribution.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    GradeDown
    (sequence s, integer n)

    Sorts data in descending fashion by a Von Neumann merge method

    Returns: Either the sorted data or the indexes that sort the data

    Category: SORTING ROUTINES

    This function is a merge-sort of the Von Neumann kind, that is, first generates variable length sequences and then merges them. While it is more complex than the merge-sort provided in Euphoria demo ALLSORTS, it has some advantages: 1) According to the argument 'n' being zero or not zero, it respectively gives the indexes of the sorted elements of 's' or the elements themselves. The sorted indexes are useful when one sorts by a key but wants to sort the remaining data, that for example resides in a "parallel" sequence. You can see an example of index use in the IndexOf() routine that follows. 2) This sort is faster than most sorts in demo ALLSORTS for RANDOM data. Its performance is about equal to the standard sort provided with Euphoria (Shell sort). However, its main advantage is being MUCH FASTER than most sorts for data that are nearly ordered, either in NORMAL or REVERSE order, or in large chunks of data ordered both ways. 3) It is stable, that is, it preserves the original order among equal elements. Some of the other sorts are not stable (quick_sort, for example). This is not important if the output consists in the elements themselves, but it matters if the output consists in the indexes. While GradeUp() sorts in ascending order, this one sorts in descending order. When returning the data, the result is the same as the one for GradeUp() reversed, but this is not the case when the indexes are returned and there are equal elements in the data. Examples: GradeDown("mahabc", 1) gives "mhcbaa". GradeDown("mahabc", 0) gives {1,3,6,5,2,4}. Notice that this is NOT {2,4,5,6,3,1} reversed (see GradeUp()).

    See Also: GradeDownNWay, GradeUp, GradeUpNWay, SortUp, SortUpNWay


    Table of Contents

    [func]
    GradeDownNWay
    (sequence s, integer n)

    Sorts data in descending fashion by a Von Neumann merge method

    Returns: Either the sorted data or the indexes that sort the data

    Category: SORTING ROUTINES

    This function is a merge-sort of the Von Neumann kind, that is, first generates variable length sequences and then merges them. It uses a non-iterative N-way merge, that is, it merges the sequences developed in the previous step in a single N-way pass. It is somewhat slower than the 2-way iterative merge for sequences consisting solely of atoms, but somewhat faster for sequences of strings. Its main usefulness consists in adapting it to external sorting, where sorted sequences are previously written to disk, either to one or several files, and then merged. In this environment, it is probably the fastest available technique. This function may be used as an Index Sort. The argument 'n' signals with 0 that the result will consist of the indexes of the sorted elements, and with any integer not null that the result will consist of the elements themselves. The input data is in sequence 's'. This function sorts in reverse order, while GradeUpNWay() does so in ascending order. Please see the comments and examples in GradeUp() and GradeDown() for further details.

    See Also: GradeDown, GradeUp, GradeUpNWay, SortUp, SortUpNWay


    Table of Contents

    [func]
    GradeUp
    (sequence s, integer n)

    Sorts data in ascending fashion by a Von Neumann merge method

    Returns: Either the sorted data or the indexes that sort the data

    Category: SORTING ROUTINES

    This function is a merge-sort of the Von Neumann kind, that is, first generates variable length sequences and then merges them. While it is more complex than the merge-sort provided in Euphoria demo ALLSORTS, it has some advantages: 1) According to the argument 'n' being zero or not zero, it respectively gives the indexes of the sorted elements of 's' or the elements themselves. The sorted indexes are useful when one sorts by a key but wants to sort the remaining data, that for example resides in a "parallel" sequence. You can see an example of index use in the IndexOf() routine that follows. 2) This sort is faster than most sorts in demo ALLSORTS for RANDOM data. Its performance is about equal to the standard sort provided with Euphoria (Shell sort). However, its main advantage is being MUCH FASTER than most sorts for data that are nearly ordered, either in NORMAL or REVERSE order, or in large chunks of data ordered both ways. 3) It is stable, that is, it preserves the original order among equal elements. Some of the other sorts are not stable (quick_sort, for example). This is not important if the output consists in the elements themselves, but it matters if the output consists in the indexes. Examples: GradeUp("mahabc", 1) gives "aabchm". GradeUp("mahabc", 0) gives {2,4,5,6,3,1}.

    See Also: GradeDown, GradeDownNWay, GradeUpNWay, SortUp, SortUpNWay


    Table of Contents

    [func]
    GradeUpNWay
    (sequence s, integer n)

    Sorts data in ascending fashion by a Von Neumann merge method

    Returns: Either the sorted data or the indexes that sort the data

    Category: SORTING ROUTINES

    This function is a merge-sort of the Von Neumann kind, that is, first generates variable length sequences and then merges them. It uses a non-iterative N-way merge, that is, it merges the sequences developed in the previous step in a single N-way pass. It is somewhat slower than the 2-way iterative merge for sequences consisting solely of atoms, but somewhat faster for sequences of strings. Its main usefulness consists in adapting it to external sorting, where sorted sequences are previously written to disk, either to one or several files, and then merged. In this environment, it is probably the fastest available technique. This function may be used as an Index Sort. The argument 'n' signals with 0 that the result will consist of the indexes of the sorted elements, and with any integer not null that the result will consist of the elements themselves. The input data is in sequence 's'. Please see the comments and examples in GradeUp() for further details.

    See Also: GradeDown, GradeDownNWay, GradeUp, SortUp, SortUpNWay


    Table of Contents

    [func]
    Hexa
    (atom a, integer len)

    Overcomes a shortcoming of printf() to show numbers in hexadecimal notation

    Returns: The hexadecimal representation of a number, even when its value is greater than #FFFFFFFF

    Category: ENCODING / DECODING ROUTINES

    printf() with %x format has an upper limit to show numbers coded as hexadecimal. This function overcomes this problem. Argument 'a' is the number to be shown in hexadecimal notation, and 'len' is the length of the resulting string. The floor of 'a' is taken if 'a' is a fraction. Negative values of 'a' are shown in complement form. Example: Hexa(255, 3) gives "0FF"

    See Also: AnyBase1, AnyBase2, AnyBaseN, BaseEvaluation, Decode, Encode, Octal


    Table of Contents

    [func]
    HypCosDistr
    ()

    Gives a random real number according to the Hyperbolic Cosine probability distribution

    Returns: A random real number between -infinity and +infinity, centered at 0

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: HypCosDistr() may give -1.248058 This distribution peaks smoothly at 0, and has a bell shape similar to the Cauchy and Gauss distributions.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    In
    (sequence base, sequence look)

    shows unique elements of 'look' matching elements of 'base'

    Returns: Unique elements of 'look' matching elements in 'base', sorted

    Category: MISCELLANEOUS ROUTINES

    Returns the unique elements of 'look' that match elements in 'base', in the form of a sorted sequence. Notice that In(a, b) returns the same result as In(b, a). If you want to get unsorted non-unique elements, please make the replacement indicated in the routine. This function calls the Unique() and IndexOf() routines, that in turn call the SortUp() routine. Example: In("xcxfgi", "bxcncp") gives "cx".

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Index
    (sequence s, object r)

    The second argument atoms act as indexes to select elements of the first argument

    Returns: Elements of 's' selected by indexes in 'r'

    Category: STRING / SEQUENCE ROUTINES

    The result is obtained selecting elements of 's' with the atoms of 'r' used as indexes. When an index is not valid because it is negative, zero, or it exceeds the length of 's', the routine crashes. The value of a non-integer index is taken as its floor(). The structure of the result is a compound of both the structure of 'r' and the structure of 's'. The outer structure is the one of 'r', and each element of it has the structure of the corresponding element of 's'. A similar native function exists in the APL language. Examples: Index({10,20,30,40}, {3,2,3,1,1}) gives {30,20,30,10,10}. Index({10,{20,30}}, {1,{2,1}}) gives {10,{{20,30},10}}.

    See Also: Drop, Expand, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    IndexGenerator
    (integer n)

    Generates a simple sequence with the numbers from 1 to the argument

    Returns: A sequence with the numbers from 1 to n

    Category: MISCELLANEOUS ROUTINES

    This function returns a simple sequence formed by the integers from 1 to 'n'. If n <= 0, the result is an empty sequence. A similar native function exists in the APL language. Thanks to Antoine Tammer for a speed-up. Example: IndexGenerator(5) gives {1,2,3,4,5}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    IndexOf
    (sequence base, sequence look)

    Obtains the indexes of the second argument's elements in the first argument

    Returns: Indexes of the second argument's elements in the first argument

    Category: MISCELLANEOUS ROUTINES

    This function obtains the indexes of elements of 'look' in 'base'. The result is a sequence of integers with the length of 'look'. If an element of 'look' is not in 'base', then its index is 0. This is similar to the standard function 'find', but it works on every element of the 'look' sequence. As it previously sorts both sequences, it is usually faster than performing a loop of find's. This function calls the GradeUp() routine. A similar native function exists in the APL language. Example: IndexOf({4,0,9,4,0,5},{5,2,0}) gives {6,0,2}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    InnerProduct
    (integer id1, integer id2, object a, object b)

    Applies two 2-parameter functions with ids # 'id1' and 'id2' to arguments 'a' and 'b' as in matrix multiplication

    Returns: An object, resulting from applying the function

    Category: MISCELLANEOUS ROUTINES

    Example: InnerProduct(routine_id("Mcd2"),routine_id("Mcm2"),{6,8},{12,28)) gives 4 This function produces what is known as 'vector multiplication'. Usually, vector multiplication is computed by actually multiplying together corresponding pairs of elements of both vectors and then adding up the products. This operation is used, for example, to compute the total amount of a bill, multiplying the unit price of each item by its quantity and then adding up the products. But you can use this in other ways: to see if all the elements of a vector are greater than the corresponding elements of the other vector (second operation: greater than, first operation: and), to obtain the maximum of all minimum, etc. Please see the comments for Reduce and Apply2() routines regarding how the function is applied to the elements of the sequences. This routine uses Reduce() and Apply2(), that in turn use Mcm2(), using Mcd2(). A similar function exists in the APL language.

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Insert
    (sequence s, sequence t, integer start)

    Inserts a sequence into another

    Returns: The original sequence with the new one inserted at the specified start point

    Category: STRING / SEQUENCE

    This function returns the sequence formed by inserting sequence 't' into sequence 's' at the index 'start'. If 'start' is less than 1, or it exceeds the length of 's', the insertion takes place respectively at the start or at the end of 's', padding with spaces for the difference in starting or ending points. Speed up thanks to a suggestion by Derek Parnell. Example: Insert("1234567890", "ABC", 4) gives "123ABC4567890"

    See Also: InsertOne, Overlap, PrepareAscii, Remove, Substring, TranslateString, TrimBoth, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    InsertOne
    (sequence s, object o, integer index)

    Inserts an object into a sequence, at a specified point

    Returns: The original sequence with the object inserted at the given point

    Category: STRING / SEQUENCE

    This function returns the sequence formed by inserting object 'o' into sequence 's' at the index 'index'. If 'index' is less than 1, or it exceeds the length of 's', the insertion takes place respectively at the start or at the end of 's', padding with spaces for the difference in starting or ending points. Speed up thanks to a suggestion by Derek Parnell. Example: InsertOne({1,2,3,4,5}, {10,20}, 3) gives {1,2,{10,20},3,4,5}

    See Also: Insert, Overlap, PrepareAscii, Remove, Substring, TranslateString, TrimBoth, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    Interpolate
    (atom x, atom diff, atom last, sequence y)

    Interpolates/extrapolates a function given as a sequence

    Returns: Interpolated/extrapolated value corresponding to an argument

    Category: MATH

    Given a sequence 'y' representing values of y(x), where the x's are equally spaced by an amount 'diff'; a value of x named 'last' corresponding to the last element of sequence 'y'; and an argument 'x', this function computes the interpolated/extrapolated value of 'y' corresponding to 'x'. It uses Newton's difference method. Example: Interpolate(1, 2, 8, {10,14,30,64,122,210,334}) returns 45.375 This means that for x = {-4,-2,0,2,4,6,8} with last value 8 and constant difference 2 between elements, if the corresponding values of y are {10,14,30,64,122,210,334}, then for x = 1.0 the interpolated value of y is 45.375

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Linear0Distr
    ()

    Gives a random real number according to the Linear probability distribution, with highest value at 0

    Returns: A random real number between 0.0 and 1.0

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Linear0Distr() may give 0.156743 This distribution peaks at 0, and decreases linearly to 1 with value 0.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Linear1Distr
    ()

    Gives a random real number according to the Linear probability distribution, with highest value at 1

    Returns: A random real number between 0.0 and 1.0

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Linear1Distr() may give 0.876592 This distribution starts at 0 with value 0, and increases linearly to 1.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Log10
    (object a)

    Obtains the base 10 logarithms of the atoms in its argument

    Returns: Base 10 logarithms of atoms in the argument, with its same structure

    Category: MATH

    This function gets the base 10 logarithms of the atoms in 'a'. It uses the constant LOG10, which is the natural logarithm of 10. It crashes if given arguments containing non-positive numbers, like 'log' does. New speed-up thanks to ideas from Jiri and Pete (Eberlein?). The old version was.

    global function Log10(object a)
       return log(a) / LOG10 --where LOG10 was log(10) 
    end function
    
    Example: Log10({0.1,1,10,100,1000}) gives {-1,0,1,2,3}

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    LogisticDistr
    ()

    Gives a random real number according to the Logistic probability distribution

    Returns: A random real number between -infinity and +infinity

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: LogisticDistr() may give -0.117543 This distribution peaks smoothly at 0, and has a bell shape similar to the Cauchy and Gauss distributions.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Mapdiv
    (object min, object dif, object a)

    Maps real numbers in the range 0 1 to the range from min to min + dif, using a division method

    Returns: Real number in the range min to min + dif

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Mapdiv(10, 20, 0.1) gives 10.71428571 This function is similar to the previous one, but it produces a steeper, even less linear result.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Mapfromminf
    (object a)

    Maps real numbers in the range -infinity 0 +infinity to -1 0 1

    Returns: Real number in the range -1 0 1

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Mapfromminf(1) gives 0.5

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Maplin
    (object min, object dif, object a)

    Linearly maps real numbers in the range 0 1 to the range from min to min + dif

    Returns: Real number in the range min to min + dif

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Maplin(10, 20, 0.1) gives 12

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Maplog
    (object min, object dif, object a)

    Logarithmically maps real numbers in the range 0 1 to the range from min to min + dif

    Returns: Real number in the range min to min + dif

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Maplog(10, 20, 0.1) gives 11.16123174 This function is useful to deal with quantities that increase or decrease proportionally to their own values, like frequencies (pitches) of musical scale notes, sound decibels, luminance, etc.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Mapto01
    (object a)

    Maps real numbers from the range -1 0 1 to 0 0.5 1

    Returns: Real number in the range 0 0.5 1

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Mapto01(0) gives 0.5

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Mapto101
    (object a)

    Maps real numbers from the range 0 0.5 1 to -1 0 1

    Returns: Real number in the range -1 0 1

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Mapto101(0.5) gives 0

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Maptoinf
    (object a)

    Maps real numbers in the range 0 0.5 1 to 0 1 +infinity

    Returns: Real number in the range 0 1 +infinity

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Maptoinf(0.5) gives 1 Warning: the argument may approximate 1, but must not reach it.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Maptominf
    (object a)

    Maps real numbers in the range -1 0 1 to -infinity 0 +infinity

    Returns: Real number in the range -infinity 0 +infinity

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Maptominf(0.5) gives 1 Warning: the argument may approximate 1 or -1, but must not reach it.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Maptoone
    (object a)

    Maps real numbers in the range 0 1 +infinity to 0 0.5 1

    Returns: Real number in the range 0 0.5 1

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Maptoone(1) gives 0.5

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Marsaglia
    ()

    Generates random integers by the MacLaren & Marsaglia method

    Returns: A random integer between 1 and MAXINT

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Marsaglia() may give 475866323 This function generates random numbers by the MacLaren & Marsaglia method. It would be better to use two independent methods to generate indexes into the table and for the numbers themselves. The Random() routine could be used to this end.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Max
    (object a)

    Computes the maximum value among all the argument's elements

    Returns: Atom that is the maximum value among the argument's elements

    Category: MATH

    Returns as an atom the maximum value among all the elements of the argument, no matter how deeply nested they are. The constant MINF is minus infinity, and it is returned for empty arguments. Example: Max({7,56,-89,9.08}) gives 56

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    MaxDepth
    (object o)

    Obtains the maximum depth of an object

    Returns: An integer valued as the maximum depth of the argument

    Category: MISCELLANEOUS ROUTINES

    Returns the maximum depth of object 'o'. Atoms have depth 0. Simple sequences (comprising only atoms) have depth 1. Sequences comprising only simple sequences and atoms have depth 2. Etc. Examples: MaxDepth(6) gives 0. MaxDepth("Abc") gives 1. MaxDepth({8,{7,8},6,7}) gives 2.

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Mcd
    (sequence s)

    Obtains the Maximum Common Divisor of all the elements of its argument

    Returns: Maximum Common Divisor of all its argument's elements

    Category: MATH

    Returns the Maximum Common Divisor of the elements of a simple sequence. This routine calls function Mcd2(). Please see the comments for Mcd2(). For null sequences, it returns plus infinity. Change "sequence s" to "SimpleSequence s" to force type checking. Example: Mcd({9,12,6}) gives 3

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Mcd2
    (atom d, atom r)

    Obtains the Maximum Common Divisor of two numbers

    Returns: Maximum Common Divisor of both arguments

    Category: MATH

    Returns the Maximum Common Divisor of two numbers. Usually applied to Euphoria integers, but may be applied to integers greater than 2^31. If applied to non-integers or negative values, result is not consistent. There is no problem with 0 valued arguments. It uses the Euclid's algorithm. Example: Mcd2(6,8) gives 2

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Mcm
    (sequence s)

    Obtains the Minimum Common Multiple of all the elements of its argument

    Returns: Minimum Common Multiple of all its argument's elements

    Category: MATH

    Returns the Minimum Common Multiple of the elements of a simple sequence. This routine calls function Mcm2(), which in turn calls Mcd2(). Please see the comments for Mcd2(). For null sequences, it returns 1. Change "sequence s" to "SimpleSequence s" to force type checking. Example: Mcm({6,4,12,5}) gives 60

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Mcm2
    (atom a, atom b)

    Obtains the Minimum Common Multiple of two numbers

    Returns: Minimum Common Multiple of both arguments

    Category: MATH

    Returns the Minimum Common Multiple of 2 numbers. This routine calls function Mcd2(). Please see the comments for Mcd2(). Example: Mcm2(6,4) gives 12

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Membership
    (sequence base, sequence look)

    Finds if the elements of the second argument are in the first argument

    Returns: Sequence of 1's and 0's according to elements of the second argument being in the first argument or not

    Category: MISCELLANEOUS ROUTINES

    This function is similar to IndexOf() (see before), but it returns, instead of the indexes, a value of 1 if the corresponding element of 'look' is in 'base', and a 0 otherwise. It calls the IndexOf() routine, which in turn calls GradeUp(). A similar native function exists in the APL language. Example: Membership("ANJLNA", "R1ALNA2K") gives {0,0,1,1,1,1,0,0}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Min
    (object a)

    Computes the minimum value among all the argument's elements

    Returns: Atom that is the minimum value among the argument's elements

    Category: MATH

    Returns as an atom the minimum value among all the elements of the argument, no matter how deeply nested they are. The constant PINF is plus infinity, and it is returned for empty arguments. Example: Min({3.1416,8,-2.56,1.78}) gives -2.56

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    []
    Miscellaneous Notes

    Category: Miscellaneous Notes


    Table of Contents

    [func]
    MultipleFind
    (object o, sequence t)

    Obtains the list of indexes of the first argument in the second one

    Returns: A sequence containing the indexes of the first argument in the second one

    Category: MISCELLANEOUS ROUTINES

    This function finds object 'o' in sequence 't', returning a sequence containing the indexes of all findings. Example: MultipleFind("ZACHARY", 'A') gives {2,5}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    MultipleMatch
    (sequence s, sequence t)

    Obtains the list of indexes of the first argument in slices of the second one

    Returns: A sequence containing the ordered indexes of the first argument in slices of the second one

    Category: MISCELLANEOUS ROUTINES

    This function matches sequence 's' against slices of sequence 't', returning a sequence containing the indexes of all matches. Example: MultipleMatch("ZAAAABCAAX", "AA") gives {2,3,4,8}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    NotIn
    (sequence base, sequence look)

    shows unique elements of 'look' not matching elements of 'base'

    Returns: Unique elements of 'look' not matching elements in 'base', sorted

    Category: MISCELLANEOUS ROUTINES

    Returns the unique elements of 'look' not matching elements in 'base', in the form of a sorted sequence. If you want to get unsorted non-unique elements, please make the replacement indicated in the routine. This function calls the Unique() and IndexOf() routines, that in turn call the SortUp() routine. Example: NotIn("zacszr", "cazzcv") gives "rsz".

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Octal
    (atom a, integer len)

    Overcomes a shortcoming of printf() to show numbers in octal notation

    Returns: The octal representation of a number, even when its value cannot be seen with printf()

    Category: ENCODING / DECODING ROUTINES

    printf() with %o format has an upper limit to show numbers coded as octal. This function overcomes this problem. Argument 'a' is the number to be shown in octal notation, and 'len' is the length of the resulting string. The floor of 'a' is taken if 'a' is a fraction. Negative values of 'a' are shown in complement form. Example: Octal(65, 3) gives "101"

    See Also: AnyBase1, AnyBase2, AnyBaseN, BaseEvaluation, Decode, Encode, Hexa


    Table of Contents

    [func]
    OneCyclePermutation
    (integer n)

    Obtains a random one-cycle permutation of the integers up to n

    Returns: A sequence containing a one-cycle random permutation of the integers up to n

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence containing a one-cycle random permutation of the integers from 1 to the argument. Following the chain of elements of a permutation, taken as indexes of the permutation itself, it is possible to get a number of disjoint cycles. If there is a single cycle, the permutation has some useful properties in probability theory and in computational tasks. Example: OneCyclePermutation(5) may give {3,5,2,1,4}

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Or
    (object a)

    Computes the compound 'or' for all argument's elements

    Returns: Integer valued 0 or 1, representing the compound 'or' of all argument's elements

    Category: MATH

    Returns as an atom the compound 'or' of all the elements of the argument, no matter how deeply nested they are. Recall that for the logical functions, every value different from 0 is 1 (true), and 0 is false. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function Or(object a)
      atom b
      if atom(a) then
          return a or 0
      end if
      b = 0
      for i = 1 to length(a) do
          b = b or Or(a[i])
          if b then
              return 1
          end if
      end for
      return b
    end function
    
    Examples: Or({4, -6.765, 0}) gives 1. Or({0,0,0}) gives 0. 0 is returned for empty arguments. For atoms, 0 is returned if the atom is 0, 1 otherwise

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Or_bits
    (object a)

    Computes the compound 'or_bits' for all argument's elements

    Returns: Integer (not necessarily an Euphoria-integer) representing the compound 'or_bits' of all argument's elements

    Category: MATH

    Returns as an atom the compound 'or_bits' of all the elements of the argument, no matter how deeply nested they are. For example, Or_bits({6, 7, 11}) is 15. This is computed as follows: using only 4 bits for simplicity, 6 is 0110 and 7 is 0111 in binary. Then or_bits(6, 7) is computed as 0 or 0 = 0, 1 or 1 = 1, 1 or 1 = 1, 0 or 1 = 1, that is, 0111 = 7. Then or_bits(7, 11) is computed as 0111 or 1011 = 1111 = 15. Zero is returned for void arguments. For non-integers less than 2^32, the integer part (rounded towards zero) is used. For numbers equal or greater than 2^32 or less than -(2^31), or_bits crashes. These are features of the Euphoria language, not of the present function. New speed-up thanks to ideas from Jiri and Pete (Eberlein?). The old version was:

    global function Or_bits(object a)
      atom b
      if atom(a) then
          return or_bits(a, #0)
      end if
      b = #0
      for i = 1 to length(a) do
          b = or_bits(b, Or_bits(a[i]))
      end for
      return b
    end function
    

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    OuterProduct
    (integer id, object a, object b)

    Applies a 2-parameter function with id # 'id' to all possible pairings of elements of a and b

    Returns: An object, resulting from applying the function

    Category: MISCELLANEOUS ROUTINES

    Example: OuterProduct(routine_id("Mcd2", {3, 6, 10}, {4, 9})) gives {{1,3},{2,3},{2,1}} If the two arguments are atoms, the result is an atom. If one is an atom and the other a sequence, the result is a sequence having the length of the sequence argument. If both arguments are sequences, the result is a bidimensional matrix, that is, a sequence of sequences. The number of second order sequences (the 'rows') is equal to the length of the first argument, and the number of elements in the second order sequences is equal to the length of the second argument. This function produces what is called a 'Cartesian product'. Please see the comments for Reduce and Apply2() routines regarding how the function is applied to the elements of the sequences. This routine uses Apply2(), that in turn uses Mcm2(), using Mcd2(). A similar function exists in the APL language.

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Overlap
    (sequence s, sequence t, integer start)

    Replaces part of a sequence by another sequence

    Returns: The original sequence with the specified part replaced by another sequence

    Category: STRING / SEQUENCE

    This function returns a sequence where a slice of 's' has been replaced by 't'. This can be done with a simple slice assignation in Euphoria, but here we consider that the point of overlap could be outside 's'. 'start' is the starting point of overlap. Speed up thanks to a suggestion by Derek Parnell. Example: Overlap("1234567890", "ABCD", 5) gives "1234ABCD90"

    See Also: Insert, InsertOne, PrepareAscii, Remove, Substring, TranslateString, TrimBoth, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    Permutation
    (sequence set, integer size, integer which)

    Obtains a permutation of the elements of a set

    Returns: A sequence containing a specified permutation of the argument sequence

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence containing the permutation with size 'size', numbered 'which', from the set 'set'. The set is any sequence of objects, and so is the result. 'which' starts at 1 and goes to the number of existing permutations of this size. If 'which' is out of bounds, an atom containing -1 is returned. Thanks to Henri Goffin for a correction. Example: Permutation("ABCDE", 3, 4) gives "ACB"

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    PoissonDistr
    (atom spread)

    Gives a random integer according to the Poisson probability distribution

    Returns: A random integer from 0 to +infinite

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: PoissonDistr(4.5) may give 3 This distribution has a peak at a certain value of the returned integer, and it diminishes at both sides. See Smallint() function

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, Random, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    PrepareAscii
    (sequence old, sequence new)

    Generates a replacement table to be used by the next routine

    Returns: Sequence to be used as a replacement table by TranslateString()

    Category: STRING / SEQUENCE

    Sequence 'old' should contain the characters to be replaced, and sequence 'new' should contain the corresponding replacements. Both sequences should have the same length and contain only atoms valued from 1 to 255 inclusive. (Actually 'new' could be longer than 'old' and have sequences or atoms with any value as its elements). No verification takes place in this respect, and consequently the routine will crash if the assumptions are not met. This routine should be executed before TranslateString(), and its result used as the second argument ('table') of TranslateString(). If TranslateString() is to be executed repeatedly with the same 'table', the present routine can be run only once before the loop. Example: table = PrepareAscii("AEIOU", "aeiou") When using 'table' with TranslateString(), 'A' will be translated to 'A', etc.

    See Also: Insert, InsertOne, Overlap, Remove, Substring, TranslateString, TrimBoth, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    Prime
    (atom a)

    Determines if a number is prime or not

    Returns: 1 if the argument is prime, 0 if not

    Category: MATH

    There are some faster (but complex) methods especially for large arguments. For arguments that are negative, greater than 2^53 (maximum integer within an atom), or fractions, 0 is returned. 1 is considered to be prime. Examples: Prime(53) gives 1. Prime(143) gives 0.

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    PrimeFactors
    (atom a)

    Obtains the prime factors of its argument

    Returns: Prime factors of its argument, with possible repetitions

    Category: MATH

    Returns a sequence containing an ordered list of prime factors of 'a', with possible repetitions. There are some faster (but complex) methods especially for large arguments. A null sequence is returned for arguments lower than 2, greater than 2^53 (maximum integer within an atom), or fractions. The always-present factor 1 is not included. Example: PrimeFactors(60) gives {2,2,3,5}

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Product
    (object a)

    Multiplies together all the argument's elements

    Returns: Product of all argument's elements

    Category: MATH

    Returns as an atom the product of all the elements of the argument, no matter how deeply nested they are. For an empty argument, it returns 1 (1 is multiplication's identity element). Example: Product({4,{8,7},0.1}) gives 22.4

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Random
    (integer seed)

    Generates random integers by a different algorithm

    Returns: A random integer between 1 and M

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Random(5674372) gives 265813144 This function generates pseudo-random numbers by a different algorithm. The maximum possible number generated is M - 1, a little below MAXINT. Useful to provide a method with a different period of repetition. As the seed is provided as an argument, this may be used to have two or more independent threads of random numbers.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, RandomPermutation, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    RandomPermutation
    (integer n)

    Obtains a random permutation of the integers up to n

    Returns: A sequence containing a random permutation of the integers up to n

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns a sequence containing a random permutation of the integers from 1 to the argument. Example: RandomPermutation(5) may give {3,5,2,4,1}

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, Scramble, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    RangeFind
    (object x, sequence s, integer pos1, integer pos2)

    Gets the index of an object in a sequence between bounds

    Returns: Index of an object into a sequence between specified bounds

    Category: MISCELLANEOUS ROUTINES

    Returns the position of object 'x' in sequence 's', for elements of 's' between 'pos1' and 'pos2'. If 'x' is not found between 'pos1' and 'pos2' inclusive, 0 is returned. From a post by Chris Bensler. Thanks to him. Example: RangeFind('M', "AZMIMIYTR", 2, 7) gives 3

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, Ravel, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Ravel
    (object a)

    Generates a simple sequence with all the argument's elements

    Returns: A simple sequence containing all the argument's elements

    Category: MISCELLANEOUS ROUTINES

    The result is the argument 'raveled', that is, a sequence of all the elements of the argument irrespective of the nesting level, in the same order as in the argument. A similar native function exists in the APL language. Examples: Ravel({1,2,3},4,{5,{6,7},8,9}) gives {1,2,3,4,5,6,7,8,9}. Ravel(8.89) gives {8.89}.

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Reduce, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Reduce
    (integer id, object a)

    Applies a 2-parameter function with id # 'id' to successive pairs of elements of 'a', recursively

    Returns: An object, resulting from applying the function

    Category: MISCELLANEOUS ROUTINES

    Example: Reduce(routine_id("Mcd2", {10, 24, 18})) gives 2 The function is applied as explained under Apply2(). So, if the result is a sequence, its length will be the minimum common multiple of the lengths of all its elements, and this is carried out recursively to nested levels. Using this routine with compound sequences may give unexpected results and very long sequences, so be careful. Please see Apply2() for details. On the other hand, it may be used, for example, in the same manner as the Sum() routine, to add up all the elements of a simple sequence, but replacing the primitive operator + by a user-defined one, for example the maximum of two numbers. The function is applied backwards, starting at the last pair of elements. If the function is commutative (as for example the multiplication), this has no effect. This routine uses the Apply2() routine, that in turn uses the Mcm2() routine, using the Mcd2() routine. A similar function exists in the APL language.

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, ReshapeAs, Scan, Structure, Unique


    Table of Contents

    [func]
    Remove
    (sequence s, integer start, integer len)

    Removes a subsequence from a sequence, from a specified start point and of a specified length

    Returns: The argument without a subsequence given by its start point and length

    Category: STRING / SEQUENCE

    This routine returns the sequence 's' with the chunk starting at 'start' and of length 'len' removed. For 'len' <= 0, nothing is removed. The cases where 'start' < 1 or the end of the chunk to be removed surpasses the end of 's' are handled as if a hollow punch with the corresponding characteristics were operated on 's'. So, not always the removed portion will have a length 'len'. Example: Remove("1234567890", 3, 4) gives "127890"

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Substring, TranslateString, TrimBoth, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    RemoveAllElements
    (sequence goal, object look)

    Removes every element in the first argument matching the second argument

    Returns: First argument without every element matching the second argument

    Category: STRING / SEQUENCE ROUTINES

    Example: RemoveAllElements("012316541", '1') gives "023654"

    See Also: Drop, Expand, Index, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    RemoveAllSlices
    (sequence goal, sequence look)

    Removes every slice in the first argument matching the second argument

    Returns: First argument without every slice matching the second argument

    Category: STRING / SEQUENCE ROUTINES

    Please notice that, in spite of all matching slices having been removed, some slices identical to the second argument might remain! This is a consequence of the method used: slices are removed from left to right without backing up, and so some fragments can stick together forming new matching slices. If it is needed to eliminate these new generation slices, the function RemoveAllSlicesX(), slightly slower, should be used (see below), or the present function should be repeated until no more matching slices remain. Example: RemoveAllSlices("AABBCABD", "AB") gives "ABCD" Notice that this is an example of the above mentioned quirk.

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    RemoveAllSlicesX
    (sequence goal, sequence look)

    Removes every slice in the first argument matching the second argument

    Returns: First argument without every slice matching the second argument

    Category: STRING / SEQUENCE ROUTINES

    This function overcomes the problem mentioned in RemoveAllSlices(). This is done by iterating the removal from the beginning and not from the last point reached. This can also be attained by repeated use of RemoveFirstSlice(). The result of this function might be different from the one attained by repeating RemoveAllSlices() until no more matches remain, because the order of removal is not necessarily the same. The user may select the method he/she sees best fit for his/her purpose: single use of RemoveAllSlices, repeated use of same, or use of the present routine. Example: RemoveAllSlicesX("AABBCABD", "AB") gives "CD"

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    RemoveFirstElement
    (sequence goal, object look)

    Removes the first object in the first argument matching the second argument

    Returns: First argument without the first element matching the second argument

    Category: STRING / SEQUENCE ROUTINES

    If no matching element is found, the result is the first argument unmodified. Example: RemoveFirstElement("ABCDCE", 'C') gives "ABDCE"

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    RemoveFirstSlice
    (sequence goal, sequence look)

    Removes the first slice in the first argument matching the second argument

    Returns: First argument without the first slice matching the second argument

    Category: STRING / SEQUENCE ROUTINES

    If no matching slice is found, the result is the first argument unmodified. Example: RemoveFirstSlice("XZAbCAbED", "Ab") gives "XZCAbED"

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    ReplaceAllElements
    (sequence goal, object look, object new)

    Replaces every element in the first argument matching the second argument by the third argument

    Returns: First argument with every element matching the second argument replaced by the third argument

    Category: STRING / SEQUENCE ROUTINES

    Please notice that, after executing this function, it is possible that elements matching the second argument remain in the result. This will happen if the third argument is equal to the second argument, and it is normally an user mistake. Example: ReplaceAllElements("012316541", '1', '9') gives "092396549"

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    ReplaceAllSlices
    (sequence goal, sequence look, sequence new)

    Replaces every slice in the first argument matching the second argument by the third argument

    Returns: First argument with every slice matching the second argument replaced by the third argument

    Category: STRING / SEQUENCE ROUTINES

    Please notice that some slice matching the second argument might remain in the result, because the third argument might be equal to the second or contain a copy of such, or a slice equal to the second argument could be formed by parts of the old content and parts of the third argument. It is impossible to replace such slices without the risk of entering an unending loop. The user may attempt to do that, repeating the present function, but controlling that the length of the result does not grow without bound. Example: ReplaceAllSlices1("ABCCXBCMZ", "BC", "B") gives "ABCXBMZ" Notice that this is an example of the above mentioned quirk.

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    ReplaceFirstElement
    (sequence goal, object look, object new)

    Replaces the first element in the first argument matching the second argument by the third argument

    Returns: First argument with first element matching second argument replaced by third argument

    Category: STRING / SEQUENCE ROUTINES

    If no matching element is found, the result is the first argument unmodified. Example: ReplaceFirstElement("ABCBCBS", 'B', 'b') gives "AbCBCBS"

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    ReplaceFirstSlice
    (sequence goal, sequence look, sequence new)

    Replaces the first slice in the first argument matching the second argument by the third argument

    Returns: First argument with the first slice matching the second argument replaced by the third argument

    Category: STRING / SEQUENCE ROUTINES

    If no matching slice is found, result is the first argument unmodified. Example: ReplaceFirstSlice("MAbCAbED", "Ab", "123") gives "M123CAbED"

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, Replicate, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    Replicate
    (object r, object s)

    Selects / replicates elements of the second argument according to the first argument

    Returns: Selected / replicated elements of 's' according to 'r'

    Category: STRING / SEQUENCE ROUTINES

    The atoms of 'r' select the corresponding objects in 's' (either atoms or sequences). Except for the possible correspondence of atoms in 'r' with sub-sequences in 's', the structure of both arguments must be the same. Atoms in 'r' are rounded to integers. An atom of value 'n' in 'r' results in 'n' copies of the corresponding object in 's'. When 'n' is 0, the result is the null sequence. When 'n' is negative, the result is Abs(n) zeroes. When a sequence in 'r' corresponds to an atom in 's', the routine aborts with code 1. When a sequence in 'r' corresponds to a different length sequence in 's', the routine aborts with code 2. The nesting depth of the result is one level higher than that of 's'. A similar native function exists in the APL language. Example: Replicate({1, 2, 0}, {{10,20},30,40}) gives {{{10,20}},{30,30},{}}

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, ReplicateNR, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    ReplicateNR
    (object r, object s)

    Selects / replicates elements of the second argument according to the first argument

    Returns: Selected / replicated elements of 's' according to 'r'

    Category: STRING / SEQUENCE ROUTINES

    This is a non-recursive version of Replicate(), normally more useful. The atoms of 'r' select the corresponding objects in 's' (either atoms or sequences). The length of both arguments must be the same, and 'r' must be a simple sequence (a sequence containing only atoms). Atoms in 'r' are rounded to integers. An atom of value 'n' in 'r' results in 'n' copies of the corresponding object in 's'. When 'n' is 0, the result is the null sequence. When 'n' is negative, the result is Abs(n) zeroes. If the length of 'r' and 's' are not the same, the routine aborts with code 1. If 'r' contains any sequence, the routine aborts with code 2. The nesting depth of the result is the same as that of 's'. A similar native function exists in the APL language. Examples: ReplicateNR({1, 2, 0}, {{10,20},30,40}) gives {{10,20},30,30}. ReplicateNR({1, 0, 1, 0), "ABCD") gives "AC".

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, Reverse, Rotate, Select, Take


    Table of Contents

    [func]
    ReshapeAs
    (object s, object f)

    Reshapes (re-structures) the first argument in the shape (structure) of the second argument

    Returns: The first argument reshaped as the second argument

    Category: MISCELLANEOUS ROUTINES

    This function reshapes (re-structures) object 's' in the shape (structure) of object 'f'. It takes the atoms in 's' in the order they appear and formats the set in the shape of object 'f'. If 's' has more atoms than 'f', the remaining ones are discarded. If 's' has fewer atoms than 'f', the atoms of 's' are used cyclically to fill the structure. If 's' contains no atoms and 'f' has some, the routine aborts with code 1. This routine uses the local variable Count and calls the local routine ReshapeAs1(). It also calls Ravel(). A similar native function exists in the APL language. Example: ReshapeAs({1,{2,3},4,5}, {{9,7,6},{8},{7,5},7}) gives {{1,2,3},{4},{5,1},2}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, Scan, Structure, Unique


    Table of Contents

    [func]
    Residue
    (object a, object d)

    Variation of remainder(), giving different results for non-positive arguments

    Returns: Residue of the division of 'a' into 'd'

    Category: MATH

    This function is a variation of remainder(). It gives always positive residues except for negative divisors (d), instead of giving negative residues for negative dividends (a) as does remainder. It also allows for a zero divisor, giving then a result equal to the dividend. This function definition has been borrowed from the APL language, and is employed to profit in functions like Rotate() (see next). 'a' and 'd' must be both atoms or sequences of the same length, or one of them must be an atom and the other a sequence. This is taken recursively as in built-in Euphoria operations. Example: Residue({3.43,-4.2,-5.23,-3.41,4,6},{2,1.7,-3,0,0,-4}) gives {1.43,0.9,-2.23,-3.41,4,-2}, while remainder({3.43,-4.2,-5.23,-3.41,4,6},{2,1.7,-3,0,0,-4}) crashes due to zero divisors. Eliminating the zero divisors, remainder({3.43,-4.2,-5.23,6},{2,1.7,-3,-4}) gives {1.43,-0.8,-2.23,2}. Notice the difference with Residue() in the second and the last elements

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Round, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Reverse
    (sequence s)

    Reverses the order of a sequence

    Returns: Sequence 's' reversed

    Category: STRING / SEQUENCE ROUTINES

    This function is simpler and usually slightly faster than the one provided with Euphoria. Example: Reverse("ABCD") gives "DCBA"

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Rotate, Select, Take


    Table of Contents

    [func]
    Rotate
    (sequence s, integer n)

    Rotates a sequence a specified number of places

    Returns: First argument rotated the number of places specified by the second argument

    Category: STRING / SEQUENCE ROUTINES

    The result is the sequence 's' rotated 'n' places, which means that 'n' elements are taken from its beginning and fed at the end. For 'n' negative, -n elements are taken from the end and fed at the beginning. This function calls the Residue() function. This function definition has been borrowed from the APL language. Examples: Rotate("abcdefg", 2) gives "cdefgab". Rotate("12345678", -3) gives "67812345".

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Select, Take


    Table of Contents

    [func]
    Round
    (object a)

    Rounds argument's elements to the nearest integer

    Returns: Argument's elements rounded to the nearest integer

    Category: MATH

    Returns the elements of the argument rounded to the nearest integer. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function Round(object a)
      return floor(a + 0.5)
    end function
    
    Example: Round({4.12,4.67,-5.8.-5.21}) gives {4,5,-6,-5}

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, RoundCents, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    RoundCents
    (object a, object cent)

    Rounds argument's elements to a specified precision

    Returns: First argument's elements rounded according to the second argument

    Category: MATH

    Returns the first argument elements rounded according to the second argument. For example, if cent = 100, it will round to 2 decimals. This is more useful than specifying 2 decimals, because one can round to other values. If it is desired to round for example to 5 cents, it will suffice to use cent = 20. Values for 'cent' that are fractions or that do not divide 10, 100, 1000, etc., do not make much sense in this respect. Negative values are rounded as expected. The Euphoria rules for matching object's lengths are applied. If they are not satisfied, the function aborts with code 1. New speed-up thanks to ideas from Jiri and Pete (Eberlein?). The old version was:

    global function RoundCents(object a, object cent)
       return floor(a * cent + 0.5) / cent 
    end function
    
    Example: RoundCents(39.876954, 100) gives 39.88

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, Sign, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Scan
    (integer id, object a)

    Applies a 2-parameter function with id # 'id' to successive pairs of elements of 'a' in cumulative fashion, recursively

    Returns: A sequence, resulting from applying the function

    Category: MISCELLANEOUS ROUTINES

    Example: Scan(routine_id("Mcd2", {10, 24, 18})) gives {2, 6, 18} This routine returns all the intermediate results of applying the function to successive pairs of elements. It runs backwards. Please see the comments for Reduce and Apply2() routines. This routine uses Apply2(), that in turn uses Mcm2(), using Mcd2(). A similar function exists in the APL language.

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Structure, Unique


    Table of Contents

    [func]
    Scramble
    (sequence s)

    Scrambles, that is, disorders a sequence

    Returns: The argument in random order

    Category: STATISTICS / PROBABILITIES ROUTINES

    Returns sequence 's' scrambled, that is, the resulting sequence contains the elements of 's' in random order. Example: Scramble("Mandrake") might give "kadnMare"

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Smallint, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    Select
    (sequence s, sequence r)

    The second argument sub-sequences act as indexes to select elements of the first argument

    Returns: Elements of 's' selected by sequences of indexes in 'r'

    Category: STRING / SEQUENCE ROUTINES

    The result is obtained selecting elements of 's' by means of the sub-sequences of 'r'. When an index is not valid because it is negative, zero, or it exceeds the length of 's', or when the structure of 'r' is not valid, the routine crashes. The value of a non-integer index is taken as its floor(). The result is a sequence of elements or sub-elements of 's' as specified by 'r'. Each element of 'r' must be a simple sequence containing indexes. Each element of 'r' selects sequences or atoms from 's' by applying its indexes successively to 's'. Examples: Select({10,20,30,40}, {{3},{2},{3},{1},{1}}) gives {30,20,30,10,10}. Select({10,{20,30}}, {{1},{2,1}}) gives {10,20}.

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Take


    Table of Contents

    [func]
    Sign
    (object a)

    Obtains the signs of the argument's elements. Sign is -1, 0 or 1

    Returns: -1 for argument < 0, 0 for argument = 0, 1 for argument > 0

    Category: MATH

    Returns -1 if the corresponding element is < 0, 0 if it is = 0, and 1 if it is > 0. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function Sign(object a)
      return (a > 0) - (a < 0)
    end function
    
    Example: Sign({8.4,-7,0}) gives {1,-1,0}

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Subtract, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Smallint
    ()

    Gives a random small integer, biased towards low values

    Returns: A random small integer starting at 1

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: Smallint() may give 1, or 2, etc., with diminishing probability for larger values. The maximum possible result is 30

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, TriangleDistr, WeibullDistr


    Table of Contents

    [func]
    SortUp
    (sequence s)

    Sorts data in ascending fashion by a Von Neumann merge method

    Returns: The sorted data

    Category: SORTING ROUTINES

    This function is a merge-sort of the Von Neumann kind, that is, first generates variable length sequences and then merges them. The input data is in sequence 's'. While it is more complex than the sorts provided in Euphoria demo ALLSORTS, it is as fast as the Shell sort for random data, but much faster for nearly ordered data in either normal or reverse order, or comprising long sequences of data ordered in any of these ways. It uses more memory than most sorts. Example: SortUp({6,8,6,0,-8,3}) gives {-8,0,3,6,6,8}}

    See Also: GradeDown, GradeDownNWay, GradeUp, GradeUpNWay, SortUpNWay


    Table of Contents

    [func]
    SortUpNWay
    (sequence s)

    Sorts data in ascending fashion by a Von Neumann merge method

    Returns: The sorted data

    Category: SORTING ROUTINES

    This function is a merge-sort of the Von Neumann kind, that is, first generates variable length sequences and then merges them. The input data is in sequence 's'. It uses a non-iterative N-way merge, that is, it merges the sequences developed in the previous step in a single N-way pass. It is somewhat slower than the 2-way iterative merge for sequences consisting solely of atoms, but somewhat faster for sequences of strings. Its main usefulness consists in adapting it to external sorting, where sorted sequences are previously written to disk, either to one or several files, and then merged. In this environment, it is probably the fastest available technique. This application shall wait some time before it is programmed...;-) Example: SortUpNWay({6,8,6,0,-8,3}) gives {-8,0,3,6,6,8}}

    See Also: GradeDown, GradeDownNWay, GradeUp, GradeUpNWay, SortUp


    Table of Contents

    [func]
    Structure
    (object o)

    Gets the structure of its argument

    Returns: Structure of argument, signaled by 0's for each argument's element

    Category: MISCELLANEOUS ROUTINES

    This function returns the structure of object 'o', that is, an object that has a 0 corresponding to each element of 'o'. Example: Structure({3,{9,7,0},{{9,7}}}) gives {0,{0,0,0},{{9,7}}}

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Unique


    Table of Contents

    [func]
    Substring
    (sequence s, integer start, integer len)

    Gets a subsequence from a sequence from a specified start position and with a specified length

    Returns: A sequence taken from another sequence from a start position and with a given length

    Category: STRING / SEQUENCE

    This function returns a slice of sequence 's', starting at position 'start' with a length 'len'. Negative and null values for 'start' and 'len', and 'len' greater than the length of 's', as well as an empty sequence 's', are accepted. If 'start' < 1, a head of as many spaces as needed is prepended. A tail of spaces is appended if necessary to complete 'len'. The only case in which the result's length will differ from 'len' is when 'len' < 0, being then null. Example: Substring("1234567890", 3, 4) gives "3456"

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Remove, TranslateString, TrimBoth, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    Subtract
    (object a)

    Sums the argument's elements with alternate signs

    Returns: Sum of all argument's elements with alternate signs

    Category: MATH

    Returns as an atom the sum of all the elements of the argument, with alternate signs, no matter how deeply nested they are. This function can be useful for computing certain mathematical series. Example: Subtract({5,3,2}) is 5-(3-2), giving 4 Assume you have a sequence s = {1,2,3,4,5,6,7}. Then Subtract(1 / s) gives 1/1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + 1/7, a kind of series used in mathematics. The nested sequences are computed previously to its use in higher level sequences. Zero is returned for empty arguments.

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Sum, Xor, Xor_bits


    Table of Contents

    [func]
    Sum
    (object a)

    Computes the sum of all the argument's elements

    Returns: Atom containing the sum of all argument's elements

    Category: MATH

    Returns as an atom the sum of all the elements of the argument, no matter how deeply nested they are. Zero is returned for empty arguments. Example: Sum({5.1,{6.7,5},4}) gives 20.8

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Xor, Xor_bits


    Table of Contents

    [func]
    Take
    (sequence s, integer n)

    Takes a specified number of elements from the first argument

    Returns: The first 'n' elements of sequence 's'

    Category: STRING / SEQUENCE ROUTINES

    The result is a sequence containing the first 'n' elements of 's'. If 'n' is negative, the result is a sequence of the last -n elements of 's'. If the absolute value of 'n' is greater than the length of 's', 0-valued elements are added, either at the end ('n' positive) or at the beginning ('n' negative) up to complete Abs(n) elements. A similar native function exists in the APL language. Examples: Take({1,2,3,4}, 2) gives {1,2}. Take({{4,5},6,7}, -5) gives {0,0,{4,5},6,7}. Take({1,2,3}, 0) gives {}.

    See Also: Drop, Expand, Index, RemoveAllElements, RemoveAllSlices, RemoveAllSlicesX, RemoveFirstElement, RemoveFirstSlice, ReplaceAllElements, ReplaceAllSlices, ReplaceFirstElement, ReplaceFirstSlice, Replicate, ReplicateNR, Reverse, Rotate, Select


    Table of Contents

    [func]
    TranslateString
    (sequence data, sequence table)

    Translates ASCII data according to a replacement table

    Returns: First argument translated according to the second argument

    Category: STRING / SEQUENCE

    'table' should have been generated by PrepareAscii(). 'data' should contain only atoms valued from 1 to 255 inclusive. Otherwise, the routine will crash. These restrictions are imposed in order to gain speed. For testing purposes, a type could be used to check 'data', for example, and it could be later disabled by "without type check" during production. Example: new_name = TranslateString("AOTEAROA", table) Result will be: "aoTeaRoa".

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Remove, Substring, TrimBoth, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    TriangleDistr
    ()

    Gives a random real number according to the Triangular probability distribution, with highest value at 1

    Returns: A random real number between 0.0 and 1.0

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: TriangleDistr() may give 0.675449 This distribution starts at 0 with value 0, increases linearly to 0.5, and then decreases to 1.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, WeibullDistr


    Table of Contents

    [func]
    TrimBoth
    (sequence s)

    Trims whitespace at both ends of a string

    Returns: The argument without whitespace at both ends

    Category: STRING / SEQUENCE

    Change "sequence s" to "String s" to force type checking. Example: TrimBoth(" E u ") gives "E u"

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Remove, Substring, TranslateString, TrimHead, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    TrimHead
    (sequence s)

    Trims whitespace in front of a string

    Returns: The argument without whitespace at the beginning

    Category: STRING / SEQUENCE

    Change "sequence s" to "String s" to force type checking. Example: TrimHead(" E u ") gives "E u "

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Remove, Substring, TranslateString, TrimBoth, TrimTail, type SimpleSequence, type String


    Table of Contents

    [func]
    TrimTail
    (sequence s)

    Trims whitespace at end of a string

    Returns: The argument without whitespace at the end

    Category: STRING / SEQUENCE

    Change "sequence s" to "String s" to force type checking. Example: TrimTail(" E u ") gives " E u"

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Remove, Substring, TranslateString, TrimBoth, TrimHead, type SimpleSequence, type String


    Table of Contents

    [func]
    type SimpleSequence
    (object o)

    A type that checks that its argument is a sequence containing only atoms

    Returns: 1 if its argument is a simple sequence, 0 otherwise

    Category: STRING / SEQUENCE

    Returns 1 if the depth of object 'o' is 1; else it returns 0. Examples: SimpleSequence(9) returns 0. SimpleSequence({{8,7},0}) returns 0. SimpleSequence({6,8,9}) returns 1.

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Remove, Substring, TranslateString, TrimBoth, TrimHead, TrimTail, type String


    Table of Contents

    [func]
    type String
    (sequence s)

    Checks whether a sequence is composed only by integers between 0 and 255

    Returns: 1 or 0 according to its argument being a sequence in which all its elements are integers between 0 and 255, or not

    Category: STRING / SEQUENCE

    Returns 1 if all the elements of 's' are integers between 0 and 255; else it returns 0. Examples: String({6,46,9,243}) returns 1. String({456,34}) returns 0. String({{8,9}}) returns 0.

    See Also: Insert, InsertOne, Overlap, PrepareAscii, Remove, Substring, TranslateString, TrimBoth, TrimHead, TrimTail, type SimpleSequence


    Table of Contents

    [func]
    Unique
    (sequence a)

    Sorts the elements of its argument and discards duplicates

    Returns: Sorted argument without duplicates

    Category: MISCELLANEOUS ROUTINES

    Returns the elements of 'a' that are different from each other, in the form of a sorted sequence. This function calls the SortUp() routine. Example: Unique("wiwopo") gives "iopw"

    See Also: Apply1, Apply2, BinSeek, CountEqual, CountGreater, CountGreaterEqual, CountLower, CountLowerEqual, CountNotEqual, In, IndexGenerator, IndexOf, InnerProduct, MaxDepth, Membership, MultipleFind, MultipleMatch, NotIn, OuterProduct, RangeFind, Ravel, Reduce, ReshapeAs, Scan, Structure


    Table of Contents

    [func]
    WeibullDistr
    (atom denshape)

    Gives a random real number according to the Weibull probability distribution

    Returns: A random real number between 0 and +infinity

    Category: STATISTICS / PROBABILITIES ROUTINES

    Example: WeibullDistr(1.0) may give 10.621601 This distribution has an asymmetric bell shape; starts at a low value, then peaks smoothly, and then decreases. 'denshape' controls the shape of the curve.

    See Also: BetaDistr, Biasto1Distr, BiastoMaxDistr, BilateralExpDistr, CauchyDistr, Deal, Deal1, DealFast, DealFast2, DealSorted, DealSorted1, DoubleExp, ExponentialDistr, GammaDistr, GaussDistr, HypCosDistr, Linear0Distr, Linear1Distr, LogisticDistr, Mapdiv, Mapfromminf, Maplin, Maplog, Mapto01, Mapto101, Maptoinf, Maptominf, Maptoone, Marsaglia, OneCyclePermutation, Permutation, PoissonDistr, Random, RandomPermutation, Scramble, Smallint, TriangleDistr


    Table of Contents

    [func]
    Xor
    (object a)

    Computes the compound 'xor' (i.e., !=) for all argument's elements

    Returns: Integer valued 0 or 1, representing the compound 'xor' of all argument's elements

    Category: MATH

    Returns as an atom the compound 'xor' of all the elements of the argument, no matter how deeply nested they are. 'xor' is a (non-existing in Euphoria) operation equivalent to != (not equal). Recall that for the logical functions, every value different from 0 is 1 (true), and 0 is false. Examples: Xor({4, -6.765, 0}) gives 0. Xor({0,0,10}) gives 1. New speed-up thanks to Jiri and Pete (Eberlein?). The old version was:

    global function Xor(object a)
      atom b
      if atom(a) then
          return a != 0
      end if
      b = 0
      for i = 1 to length(a) do
          b = b != Xor(a[i])
      end for
      return b
    end function
    
    0 is returned for empty arguments. For atoms, 0 is returned if the atom is 0, 1 otherwise.

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor_bits


    Table of Contents

    [func]
    Xor_bits
    (object a)

    Computes the compound 'xor_bits' for all argument's elements

    Returns: Integer (not necessarily an Euphoria-integer) representing the compound 'xor_bits' of all argument's elements

    Category: MATH

    Returns as an atom the compound 'xor_bits' of all the elements of the argument, no matter how deeply nested they are. For example, Xor_bits({6, 7, 11}) is 10. This is computed as follows: using only 4 bits for simplicity, 6 is 0110 and 7 is 0111 in binary. Then or_bits(6, 7) is computed as 0 xor 0 = 0, 1 xor 1 = 0, 1 xor 1 = 0, 0 xor 1 = 1, that is, 0001 = 1. Then or_bits(1, 11) is computed as 0001 or 1011 = 1010 = 10. Zero is returned for void arguments. For non-integers less than 2^32, the integer part (rounded towards zero) is used. For numbers equal or greater than 2^32 or less than -(2^31), xor_bits crashes. These are features of the Euphoria language, not of the present function. New speed-up thanks to ideas from Jiri and Pete (Eberlein?). The old version was:

    global function Xor_bits(object a)
      atom b
      if atom(a) then
          return xor_bits(a, #0)
      end if
      b = #0
      for i = 1 to length(a) do
          b = xor_bits(b, Xor_bits(a[i]))
      end for
      return b
    end function
    

    See Also: Abs, And, And_bits, Ceil, CeilTowardsInfinity, Divide, Divisors, FloorTowardsZero, Frac, Interpolate, Log10, Max, Mcd, Mcd2, Mcm, Mcm2, Min, Or, Or_bits, Prime, PrimeFactors, Product, Residue, Round, RoundCents, Sign, Subtract, Sum, Xor


    Table of Contents

    Index

    Abs [func] Computes the absolute value of the argument's elements
    And [func] Computes the compound 'and' for all argument's elements
    And_bits [func] Computes the compound 'and_bits' for all argument's elements
    AnyBase1 [func] Encodes an atom in a specified numbering base system, with 1-character symbols
    AnyBase2 [func] Encodes an atom in a specified numbering base system, with 2-character symbols
    AnyBaseN [func] Encodes an atom in a specified numbering base system, with N-character symbols
    Apply1 [func] Applies a 1-parameter function with id # 'id' to all elements of 'a', recursively
    Apply2 [func] Applies a 2-parameter function with id # 'id' to all elements of 'a' and 'b', recursively
    BaseEvaluation [func] Evaluates a number coded in a specified numbering system
    BetaDistr [func] Gives a random real number according to the Euler's Beta probability distribution
    Biasto1Distr [func] Gives a biased random integer
    BiastoMaxDistr [func] Gives a biased random integer
    BilateralExpDistr [func] Gives a random real number according to the Bilateral probability distribution
    BinSeek [func] Finds the index of the first argument in the second argument, between the indexes indicated by the third and fourth arguments
    CauchyDistr [func] Gives a random real number according to the Cauchy probability distribution
    Ceil [func] Computes next higher argument's integers
    CeilTowardsInfinity [func] Computes integer greater or equal to argument in absolute value, but with the original sign
    CountEqual [func] Counts the number of times each element of the second argument is in the first argument
    CountGreater [func] Counts the number of times each element of the second argument is greater than the elements in the first argument
    CountGreaterEqual [func] Counts the number of times each element of the second argument is greater or equal to the elements in the first argument
    CountLower [func] Counts the number of times each element of the second argument is lower than the elements in the first argument
    CountLowerEqual [func] Counts the number of times each element of the second argument is lower or equal to the elements in the first argument
    CountNotEqual [func] Counts the number of times each element of the second argument is not equal to the elements in the first argument
    Deal [func] Obtains a sequence of non-repeating random integers
    Deal1 [func] Obtains a sequence of non-repeating random integers
    DealFast [func] Generates non-repeating random integers by an algorithm that does not use much memory / CPU time
    DealFast2 [func] Generates non-repeating random integers by an algorithm that does not use much memory / CPU time
    DealSorted [func] Obtains an ordered sequence of non-repeating random integers
    DealSorted1 [func] Obtains an ordered sequence of non-repeating random integers
    Decode [func] Decodes a sequence, represented in a numeric (possibly variable) base system into the number it represents
    Divide [func] Alternately divides/multiplies argument's elements
    Divisors [func] Obtains all possible divisors of its argument
    DoubleExp [func] Maps the range 0 to 1 into the same one, using a Double Exponential function
    Drop [func] Drops a specified number of elements from the first argument
    Encode [func] Encodes a number into a numbering (possibly variable) base system
    ENCODING / DECODING ROUTINES
    Expand [func] More or less the inverse of Replicate()
    ExponentialDistr [func] Gives a random real number according to the Exponential probability distribution
    FloorTowardsZero [func] Computes integer less or equal to argument in absolute value, but with the original sign
    Frac [func] Computes the fractional part of the argument elements
    GammaDistr [func] Gives a random real number according to the Gamma probability distribution
    GaussDistr [func] Gives a random real number according to the Gauss probability distribution
    GradeDown [func] Sorts data in descending fashion by a Von Neumann merge method
    GradeDownNWay [func] Sorts data in descending fashion by a Von Neumann merge method
    GradeUp [func] Sorts data in ascending fashion by a Von Neumann merge method
    GradeUpNWay [func] Sorts data in ascending fashion by a Von Neumann merge method
    Hexa [func] Overcomes a shortcoming of printf() to show numbers in hexadecimal notation
    HypCosDistr [func] Gives a random real number according to the Hyperbolic Cosine probability distribution
    In [func] shows unique elements of 'look' matching elements of 'base'
    Index [func] The second argument atoms act as indexes to select elements of the first argument
    IndexGenerator [func] Generates a simple sequence with the numbers from 1 to the argument
    IndexOf [func] Obtains the indexes of the second argument's elements in the first argument
    InnerProduct [func] Applies two 2-parameter functions with ids # 'id1' and 'id2' to arguments 'a' and 'b' as in matrix multiplication
    Insert [func] Inserts a sequence into another
    InsertOne [func] Inserts an object into a sequence, at a specified point
    Interpolate [func] Interpolates/extrapolates a function given as a sequence
    Linear0Distr [func] Gives a random real number according to the Linear probability distribution, with highest value at 0
    Linear1Distr [func] Gives a random real number according to the Linear probability distribution, with highest value at 1
    Log10 [func] Obtains the base 10 logarithms of the atoms in its argument
    LogisticDistr [func] Gives a random real number according to the Logistic probability distribution
    Mapdiv [func] Maps real numbers in the range 0 1 to the range from min to min + dif, using a division method
    Mapfromminf [func] Maps real numbers in the range -infinity 0 +infinity to -1 0 1
    Maplin [func] Linearly maps real numbers in the range 0 1 to the range from min to min + dif
    Maplog [func] Logarithmically maps real numbers in the range 0 1 to the range from min to min + dif
    Mapto01 [func] Maps real numbers from the range -1 0 1 to 0 0.5 1
    Mapto101 [func] Maps real numbers from the range 0 0.5 1 to -1 0 1
    Maptoinf [func] Maps real numbers in the range 0 0.5 1 to 0 1 +infinity
    Maptominf [func] Maps real numbers in the range -1 0 1 to -infinity 0 +infinity
    Maptoone [func] Maps real numbers in the range 0 1 +infinity to 0 0.5 1
    Marsaglia [func] Generates random integers by the MacLaren & Marsaglia method
    MATH
    Max [func] Computes the maximum value among all the argument's elements
    MaxDepth [func] Obtains the maximum depth of an object
    Mcd [func] Obtains the Maximum Common Divisor of all the elements of its argument
    Mcd2 [func] Obtains the Maximum Common Divisor of two numbers
    Mcm [func] Obtains the Minimum Common Multiple of all the elements of its argument
    Mcm2 [func] Obtains the Minimum Common Multiple of two numbers
    Membership [func] Finds if the elements of the second argument are in the first argument
    Min [func] Computes the minimum value among all the argument's elements
    Miscellaneous Notes []
    MISCELLANEOUS ROUTINES
    MultipleFind [func] Obtains the list of indexes of the first argument in the second one
    MultipleMatch [func] Obtains the list of indexes of the first argument in slices of the second one
    NotIn [func] shows unique elements of 'look' not matching elements of 'base'
    Octal [func] Overcomes a shortcoming of printf() to show numbers in octal notation
    OneCyclePermutation [func] Obtains a random one-cycle permutation of the integers up to n
    Or [func] Computes the compound 'or' for all argument's elements
    Or_bits [func] Computes the compound 'or_bits' for all argument's elements
    OuterProduct [func] Applies a 2-parameter function with id # 'id' to all possible pairings of elements of a and b
    Overlap [func] Replaces part of a sequence by another sequence
    Permutation [func] Obtains a permutation of the elements of a set
    PoissonDistr [func] Gives a random integer according to the Poisson probability distribution
    PrepareAscii [func] Generates a replacement table to be used by the next routine
    Prime [func] Determines if a number is prime or not
    PrimeFactors [func] Obtains the prime factors of its argument
    Product [func] Multiplies together all the argument's elements
    Random [func] Generates random integers by a different algorithm
    RandomPermutation [func] Obtains a random permutation of the integers up to n
    RangeFind [func] Gets the index of an object in a sequence between bounds
    Ravel [func] Generates a simple sequence with all the argument's elements
    Reduce [func] Applies a 2-parameter function with id # 'id' to successive pairs of elements of 'a', recursively
    Remove [func] Removes a subsequence from a sequence, from a specified start point and of a specified length
    RemoveAllElements [func] Removes every element in the first argument matching the second argument
    RemoveAllSlices [func] Removes every slice in the first argument matching the second argument
    RemoveAllSlicesX [func] Removes every slice in the first argument matching the second argument
    RemoveFirstElement [func] Removes the first object in the first argument matching the second argument
    RemoveFirstSlice [func] Removes the first slice in the first argument matching the second argument
    ReplaceAllElements [func] Replaces every element in the first argument matching the second argument by the third argument
    ReplaceAllSlices [func] Replaces every slice in the first argument matching the second argument by the third argument
    ReplaceFirstElement [func] Replaces the first element in the first argument matching the second argument by the third argument
    ReplaceFirstSlice [func] Replaces the first slice in the first argument matching the second argument by the third argument
    Replicate [func] Selects / replicates elements of the second argument according to the first argument
    ReplicateNR [func] Selects / replicates elements of the second argument according to the first argument
    ReshapeAs [func] Reshapes (re-structures) the first argument in the shape (structure) of the second argument
    Residue [func] Variation of remainder(), giving different results for non-positive arguments
    Reverse [func] Reverses the order of a sequence
    Rotate [func] Rotates a sequence a specified number of places
    Round [func] Rounds argument's elements to the nearest integer
    RoundCents [func] Rounds argument's elements to a specified precision
    Scan [func] Applies a 2-parameter function with id # 'id' to successive pairs of elements of 'a' in cumulative fashion, recursively
    Scramble [func] Scrambles, that is, disorders a sequence
    Select [func] The second argument sub-sequences act as indexes to select elements of the first argument
    Sign [func] Obtains the signs of the argument's elements. Sign is -1, 0 or 1
    Smallint [func] Gives a random small integer, biased towards low values
    SORTING ROUTINES
    SortUp [func] Sorts data in ascending fashion by a Von Neumann merge method
    SortUpNWay [func] Sorts data in ascending fashion by a Von Neumann merge method
    STATISTICS / PROBABILITIES ROUTINES
    STRING / SEQUENCE ROUTINES
    Structure [func] Gets the structure of its argument
    Substring [func] Gets a subsequence from a sequence from a specified start position and with a specified length
    Subtract [func] Sums the argument's elements with alternate signs
    Sum [func] Computes the sum of all the argument's elements
    Take [func] Takes a specified number of elements from the first argument
    TranslateString [func] Translates ASCII data according to a replacement table
    TriangleDistr [func] Gives a random real number according to the Triangular probability distribution, with highest value at 1
    TrimBoth [func] Trims whitespace at both ends of a string
    TrimHead [func] Trims whitespace in front of a string
    TrimTail [func] Trims whitespace at end of a string
    type SimpleSequence [func] A type that checks that its argument is a sequence containing only atoms
    type String [func] Checks whether a sequence is composed only by integers between 0 and 255
    Unique [func] Sorts the elements of its argument and discards duplicates
    WeibullDistr [func] Gives a random real number according to the Weibull probability distribution
    Xor [func] Computes the compound 'xor' (i.e., !=) for all argument's elements
    Xor_bits [func] Computes the compound 'xor_bits' for all argument's elements