This file is deprecated. See NEWS instead
lc(string)
- convert input string to lower caseglue(string, separator)
- glues the array of input strings together after removing quotessplit(string, separator, limit)
- split input string into array using separator up to limit timessplit2(string, separator)
- split input string into array using separatortc(string)
- convert input string to title casetoNumber(string)
- convert input string to a numbertrim(string)
- trim whitespace from both ends of input string after removing quotation marksuc(string)
- convert input string to upper casesum
function works on strings.See the NEWS for more details and examples.
select
operator has been renamed pick
. This was done because, Palamedes now supports SQL expressions that operate on matrices. See below for more info.select Name, Age from Person where Age > 39 order by Age desc
. There is support for natural joins and group-by clauses. See SQL for complete details.high
/low
and take
/drop
has changed (again), this time to make them work like other pipe expressions. The syntax is expression TAKE number
take
and drop
have new short forms ↑
and ↓
respectively.high
and low
have been expanded to work on JSON objects in addition to arrays. Given a JSON object, they return a new object with the highest/lowest number keys. Similarly, take
/drop
have been expanded to work on JSON objects---they will take/drop the given number of keys at random.gets
/set
.ceil
and floor
functions.after
operator a pipe so you can write Person group by Age after 34 after 1 after 0
without parens.JSON op JSON
form (in the r_op2
internal function) so that it produces a new JSON object whose keys are the union of the keys of its inputs. (In prior versions, the result was a JSON object whose keys were the intersection of the keys of its inputs.) If no value exists, then zero is assumed. This is very useful for calculating weighted sums of probability distributions. See the NEWS file for examples.all
and some
operators so that they work with JSON objects as inputs. They test whether all/some values in the object are true.Fixed bugs in the internal functions r_op1
and r_op2
used to thread operators over structured arguments. In cases where one argument was the empty array []
, an exception might have been thrown or a wrong result returned. See NEWS for more details.
mode
where the argument is an array. For example, mode [1..5]
was erroneously producing the result [1,2,3,4]
instead of []
.r_op1
and r_op2
used to thread operators over structured arguments. In cases where one argument was a JSON object, these functions weren't recursing when the key-value pairs themselves had structured values. For example, rat(stats(3d6))
wasn't applying rat
to the value [10,11]
of the key "mode".skew
function which computes the skewness. Unfortunately, several types of skewness are defined, and the terminology is confusing. For an input distribution, the formula we use is γ₁ = μ₃/(μ₂)^(3/2)
. For an input array, we compute the estimator g₁ = k₃/(k₂)^(3/2)
. For more info, please see the article on Skewness at Wolfram MathWorld.kurt
function to compute the kurtosis "excess". For an input distribution, the formula is γ₂ = μ₄/μ₂² - 3
. For an input array, we compute the estimator g₂ = k₄/k₂² - 3
. For more info, please see the article on Kurtosis at Wolfram MathWorld.mode
and argmax
where an error occurs if there is no mode/all values are modes.take
and drop
were echoed in reverse order.[]
eval
inside JSON objects such as mage gets {"name": "Gandalf", "abilities": eval(6#3d6)}
xerxes2 gets "stuff"
. Beware: x2
is still an exploding d2 dice roll, not a valid name for a variable!save
and load
commands.stringify
which converts array into a comma-separated string. No longer calls JSON.stringify internally.vars
so that it is a variable containing the expression table(ls())
function. See below for info about the new ls()
function.take
and drop
. Beware: Old form TAKE array, n
no longer works. There are now two forms: array TAKE n
or TAKE n, array
which may be written TAKE n FROM array
. More complicated forms of array are now permitted without parens. See NEWS for examples.seed()
function so that automatically generated seeds are simply the number of seconds since the beginning of the epoch. That makes it easier to save/load them.tableform()
and matrixform()
functions to work with save
and load
commands.concat
operator to work with two JSON objects. Overlapping properties in the second argument overwrite the first.\n
is replaced with a newline character.without
and alias s̄
(abbreviation for sine in Latin) operator for sampling without replacement from a universe with unequal probabilities. Operand is an array or JSON object in the form value1, prob1, ..., valueN, probN
. See NEWS for examples.#
: c̄
(abbreviation for cum in Latin) operator for sampling with replacementtrue
: otherwise
so that you can write expressions like lookup [p <= 50%, "this", p <= 100%, "that", otherwise, error "bug!"]
like
infix operator (synonym =~
, antonym !~
) to compare strings to regular expressions. Added like2()
function for use in outer()
function. See NEWS for examples.ls()
function. Returns JSON object which lists all variables. To show in tableform do one of the following: table(ls())
, ls() |> table
, or ls()//table
forget()
function to clear a variable.reset()
function to clear all variables and reset them to the system defaults.rename(a,b)
function to rename variable a to b.|
. There are two main ways to use it:'tril'i
do this: domain(ls()) like 'tril'i | domain(ls())
'tril'i
and their values in tableform do this domain(ls()) like 'tril'i | domain(ls()) | ls() |> table
cpt()
function. Returns JSON object which lists all conditional probabilities. Use with the table
function to put in tableform. Passing an argument to cpt such as cpt(1)
will clear/reset all conditional probabilities.length()
function to count length of string. length()
threads over arrays/matrices/tensors of strings. Note that count
will not work on strings.error()
function. Takes a string argument. It stops execution and throws and exception.argmin()
and argmax()
functions for arrays and objects. These return array of indices corresponding to min/max values.listify()
function. Converts array into a newline-separated string.Chisqcdf(x, df)
, tcdf(x, df)
, Gammacdf(x, alpha, beta)
, Betacdf(x, alpha, beta)
, Expocdf(x, lambda)
Chisqtest(M)
function which takes a contingency matrix and returns the chi-square statistic, degrees of freedom, and p-value.cov2(x1,x2)
function to find sample covariance between two arrays x1 and x2. The function cov(x1, x2, ..., xN)
will find the NxN sample covariance matrix.corr2(x1,x2)
function to find sample correlation between two arrays x1 and x2. The function corr(x1, x2, ..., xN)
will find the NxN sample correlation matrix.slope(x1,x2)
, interecept(x1,x2)
functions to find slope and intercept of simple linear regression between two arrays x1 (independent) and x2 (dependent). linreg(x1,x2)
returns the array containing the intercept and slope.se
function to finf the standard error of an array of values.skew
function. Applied to an array it returns the sample skew. Applied to a distribution it finds the poulation skew. This information is returned part of the stats
function.echo off
to the UI. Turns off command echoing. Turn back on with echo on
. Do not use on compund line with statements separated by semicolons.quiet on
to the UI. Turns off output. Turn back on with quiet off
. Do not use on compund line with statements separated by semicolons.stringify
function mostly for using arrays in calls to the print
functionExpanded support for Bayesian Networks. See the NEWS file for complete details and examples.
Preliminary support for conditional probabilities and Bayes' Rule. See the NEWS file for complete details and examples.
binom n, p
whereby the support was incorrectly taken to be [0 .. ∞]
instead of [0 .. n]
. The actual probabilities calculated over [0 .. n]
were correct, and the routine to generate binomial variates was correct./* M * N is a Hadamard/Schur/elementwise matrix product */
is now OK.NB.
which must be uppercase and include the trailing dot. Anything after this to the end-of-line is ignored. If you use mixed case, lowercase or forget the dot, then you'll either trigger a parser error or the juxtaposition operator.tableform()
and matrixform()
as well as the variables table_start
, table_end
, row_start
, row_end
, row_sep
, col_sep
and nl
to provide greater control how matrices are output. The function tableform()
outputs a matrix with verical bars (pipes) around each cell; matrixform()
restores the default matrix output; nl
is a newline character. See NEWS for examples.T
now performs matrix transpose. This is more cosmetically appealing alternative to the trans
function: M^T
does the same as trans M
.diag
function now takes an array and constructs a matrix with it on the diagonal, everything else zeroed out.car
, cdr
and cons
.ℏ ← 6.62606957e-34 / (2 * π)
¼
for 0.25, ½
for 0.5 and ¾
for 0.75.index
) for position of object in arrayin
) to be set membership. Used to be index of object in arraynotin
) for negation of set membershipimplies
for logical implication'
(ascii apostophe) as valid part of variable name, e.g., A'
for A prime. Note that 'A
is still quote A
, i.e., the definition of A
.≠
(unicode not equal) for !=
or ne
⊤
(unicode down tack) for true
⊥
(unicode up tack or falsum) for false
⇒
(unicode rightward double arrow) for ,
(comma)if
for lookup
while
block now returns last executed statementwhile
block was limited to 10 loops to prevent infinite loops; increased limit to 100,000 loops[a .. b]
now prints itself with whitespace around the double dot. BEWARE: In some cases, using a double dot immediately after a numeric subscript without intervening whitespace may produce an undesired result on some platforms.tensor(expr,q,m,n)
tensor constructor to create m-by-n-by-p tensor. It varies p
(flor "planes") over 0..q-1
, r
(for "rows") over 0..m-1
and c
(for "columns") over 0..n-1
and evaluates expr
at each point to get the value of the new tensor T[p,r,c]
. The expression expr
should be written in terms of the variables p, r and c. The values in these variables will not be permanently effected---they are saved and later restored.matrix(expr,m,n)
matrix constructor to create an m-by-n matrix. It varies r
(for "rows") over 0..m-1
and c
(for "columns") over 0..n-1
and evaluates expr
at each point to get the value of the new matrix M[r,c]
. The expression expr
should be written in terms of the variables r and c. The values in these variables will not be permanently effected---they are saved and later restored.array(expr,m)
matrix constructor to create an array of length m. It varies i
(for "index") over 0..m-1
and evaluates expr
at each point to get the value of the new array A[i]
. The expression expr
should be written in terms of the variables i. The values in this variable will not be permanently effected---it is saved and later restored.update(T,value,p,r,c)
, update(M,value,r,c)
and update(A,value,i)
functions. Updates the given object (tensor, matrix or array) with the given value at the given point, e.g., update(M,3,r,c)
sets M[r,c] = value
. But update
returns a new object---the old value of the object (T, M or A) is not effected.I(n)
function to create an n-by-n identity matrix.diag(M)
function to create an diagonal matrix from M. Off-diagonal elements are zeroed out. The Original matrix M is uneffected.σ²
is a valid variable name, and yₜ ← [0..10]; yⁱ ← e ^ yₜ
is a valid expression. Note: By themselves d, f, k, x, z are not valid variable names -- they are dice operators. But x₀, x₁, x², etc. are now valid names.1/6
is lexed as the NUMBER 0.1666666... whereas 1 / 6
is lexed as the EXPRESSION 1 '/' 6
. This is so I can write expressions like NB 5, 1/6
instead of NB 5, (1/6)
. I still need to write NB 5, (1/6^3+1/4)
. Note that 2/6^3
is (2/6)^3
but 2 / 6^3
is 2/(6^3)
. I'm not sure if I will keep this behavior or simply rewrite all the discrete probability distribution operators NB
, geom
, pois
and so on as functions, in which case I would always need to use outer parens around the arg list: NB(5, 1/6)
but could then write NB(5, 1/6^3+1/4)
without parens around the second arg. In short, this behavior is experimental and perhaps temporary. This behavior will be stabilized when the code moves from the alpha to the beta stage.Fixed a bug in prob(max(a,b))
and prob(min(a,b))
that could result in bogus results when arguments a,b not iid.
Calling mean[d6,d10,d20]
returns a scalar with the mean of the array containing elements sampled randomly from the d6, d10, and d20 dice distributions, so you'll get a different result each time. But mean(d6,d10,d20)
returns an array with the means of the d6, d10 and d20 dice distributions respectively. N.B. the difference is that [d6,d10,d20]
is an array whereas (d6,d10,d20)
is a tuple. Arrays are first class citizens in the Palamedes language. But tuples are just part of the grammar for function calls, only understood by the parser.
Additionally, mean[prob(d6),prob(d10),prob(d20)]
returns an array of means. And mean([[1, 2, 3], [1, 3, 5], [0, 10, 20]])
returns an array with the means of each row in the given matrix.
These tricks only works with the functions mean
, sd
and var
functions so far.
Added pair
function to turn a pair of arrays into an array of pairs.
Previously, min
and max
functions only computed probabilities for samples of iid random variables. Now they work on tuples or arrays of independent rv's, even if they're not identical, e.g., prob(max(2d6,3d6))//rat//table
or stats(max(4d6,5d6+1,7d6+1))//table
.
Added var
function to compute variance. Note that var [1..6]
computes the sample variance of the given array while var(d6)
computes the population variance of the d6 dice distribution. Added var
to the list of descriptive statistics returned by stats
.
This is just a quick summary of updates. See the NEWS file for details and examples.
Here is a brief summary of the major changes. Please see the NEWS file for details and examples:
pipe
, |>
, //
, ↦
.sci
function forces output to scientific notation.c(2,-3) cross c(1,2)//cstr
is OK, but ÷
operator for Euclidean division.http://palamedes.altervista.org?cmd=3d6
. Multi-line commands are supported if they are properly URI encoded, e.g., http://palamedes.altervista.org?cmd=score%20gets%203d6%0Ascore%0Atable(prob(score))
where %20
is the code for a space and %0A
is the code for a line break.…
or three dots ...
. The web- or CLI- GUI actually does the work of combining broken lines, while the lexer ignores the elipses as if they were whitespace.rat
function to attempt to rationalize floating point numbers. Given an input bigger than unity, it returns an improper fraction, not a mixed number. It depends on the tol
variable (initially set to 1/10^9), and stops approximating when abs(rat-input)<tol
, so decrease tol
(e.g., tol gets 1/10^12
) to get better precision. Internally, JavaScript's crappy floats are still used.~
operator so that with a number 0<=x<=1
returns the complement 1-x
, any other number: the opposite, booleans: the negation, and anything else: the identity.pi/2
.prod
function to behave more sensibly. See the NEWS file for details.ortho1
function. Given one n-vector, it returns a list of n-1 orthogonal vectors. Any linear combination of these vectors will also be orthogonal to the input.proj(v,u)
function to return the projection of vector v in the direction of vector u.ortho(u,v,w...)
function to perform Gram-Schmidt orthonormalization on a list of vectors u,v,w,etc.angle(u,v)
function to compute the angle between two vectors in radians.primes(n)
function to print the primes p <= min(n,1000).mixed
function to represent numbers as mixed fractions.commify
function to put commas in big numbers.human
function to try to make JavaScript floating-point numbers human-readable when they represent rational multiples of pi, fractions of square roots, etc.N
that generates random variates for the normal distribution so that it expects the variance as the second parameter N(μ, σ²)
rather than the standard deviation N(μ, σ)
normal
simply to N
.GBM(percentage_drift, percentage_volatility)
which sets up a function S(S0,t)
to compute value of a stochastic process S at time t given the starting value of S=S0 at time t=0 using geometric brownian motion with the constants percentage_drift
, and percentage_volatility
. Useful for simulating Random Walks. There is also a convenience function Wiener(t)
to implement the Wiener process. See the NEWS file for more details and examples.sum
function. Applied to a list of two or more matrices, it returns the matrix sum. Applied to one matrix, it returns to the row sums. Applied to a list of numbers, it returns their sum. Applied to a list of booleans, it returns the count of true values. Applied to a list of strings, it returns their lengths. Applied to a JSON object containing a probability distribution, it returns the convolution of distributions, i.e., distribution for the sum of corresponding random variables.trans
(transpose) function. For a matrix, it exchanges the rows and columns. For a tensor, the row become the columns, the columns become the planes, and the planes become the rows. It's undefined for any other inputs.inv
(inverse) function. Applied to a square, non-singular matrix, it attempts to invert it. Applied to a non-square matrix, it attempts to construct the pseudo-inverse. Applied to a list of matrices, it acts on each one. Applied to a vector of numbers, it returns the Moore-Penrose pseudo inverse. Applied to a list of strings, it reverses each one. Applied to a single nonzero number, it returns the reciprocal (multiplicative inverse). Applied to a string, it returns the reverse. Applied to a boolean, it returns the negation. Applied to an JSON object, it attempts to exchange keys and values, if the object is 1-to-1. In the future, we may implement a table with function inverses, so it will be possible to invert a function.rot
(rotate) function. rot
applied to a matrix reverses the FIRST axis, i.e., the order of the rows. Applied to a 3rd order tensor, it reverses the first axis, i.e., the planes; in other words, applied to a list of matrices, it reverses the order of the matrices. rot
applied to a string or a list of strings performs rot13.rev
(reverse) function. rev
applied to a vector, matrix or list of matrices, reverses the LAST axis, i.e., the columns. Applied to a string, it reverses the string. Applied to a number it returns the additive inverse. Applied to a boolean it returns the negation. Applied to a JSON object, it inverts the keys and values, if its 1-to-1.outer(function_name, list_1, list_2)
(outer product) function.outer
: plus
, minus
, times
, div
, mod
, pow
. E.g., outer(times, [1..12], [1..12])
constructs a multiplication table.inner(f,g,vector_1,vector_2)
.and2
, or2
, gcd2
, lcm2
, max2
, min2
. E.g., min
takes a list and returns it's minimal element, whereas min2
takes 2 lists and return a list containing the pairwise minimal elements. These functions should be used with outer
and inner
as opposed to the 1-argument versions, e.g., outer(lcm2, [1..12], [1..12])
constructs a table of LCMs for the numbers 1 to 12.round
takes optional 2nd argument, like fix
, but fix
adds extra zeros, but round
won't.norm(vector, "minkowski")
to compute the Minkowski "norm" of a vectornegfirst(vector)
function to change the sign of the first component of a vectorpair
function to pair up arguments. Signature may be (scalar, scalar)
, (scalar, array)
, (array, scalar)
or (array, array)
.apply
function. In conjunction with outer
, apply
makes it possible to apply a whole list of functions to a list of arguments to get a matrix of values.resize
function to reshape a scalar or vector into a matrix, e.g., reshape([3,3],0)
makes a 3x3 matrix of zeros, reshape([4,4],[1,0,0,0,0])
makes a 4x4 identity matrix.splice(array,position,howmanytoremove,values...)
function to modify array or matrix. Unlike JavaScript's splice function, this one is non-destructive and returns the resulting structure rather than the removed values.DdEeFfKkXxZz
as long as they are at least two letters long, and the second letter isn't a digit or an "F" or "f". That's so we can properly interpret input like d6
anddF
as dice throws rather than variables.1.0-a31
contains a corrected example.while(a){b;c;d}
to display as while(a){b,c,d}
with commas instead of semicolons.recur
operator to generate recurrences. E.g., recur (_1+_2),[0,1]
generates the Fibonacci sequence to ∞ which is set to 100 by default. The format is recur expr, initial
where expr
is an expression in parens. This expression may contain variables of the form _k
which get set to result[n-k]
where n
is the number of results accumulated so far. And initial
is the initial value of the result array. See the NEWS file for more detailed notes and examples.sqrt
function. This is different from root
which is a dyadic operator rather than a function, e.g., 3 root 10
produces the cube root of 10. In general, functions need parens, operators don't. But the sqrt
function is threadable over vectors/matrices/tensors, and parens are optional around things enclosed in square brackets, e.g., sqrt [0..4]
is OK. TMTOWTDI: sqrt(2)
produces the same result as 2 root 2
and √2
and 2^.5
cot
, coth
, csc
, csch
, sec
, sech
sign
function to return the sign of a number: 1, 0 or -1.fix(x,n)
function to display decimal numbers x with a fixed number n of decimal places. The number n defaults to 2. This function is threadable, so parens are optional around vectors and matrices as long as the default number of decimal places is used.size
function to return the size of its input: 0 means its a scalar; a positive number n
means its a vector of length n; and an array [m,n]
means its a matrix with m
rows and n
columns. Additionally, -1 indicates its a JSON object; -2 indicates its a JavaScript function; and -3 indicates its type is unknown.tr
. Input is a square matrix. Output is sum of diagonal elements. This is a non-threadable function--at most one input which must be in parens.norm
function to return the p-norm of a vector or matrix. By default, p is 2. But see the NEWS file for details.seed("prng seed string")
function to seed PRNG. Added seed
variable to track last seed value. Now it is possible to generate a predictable/repeatable pseudorandom number sequence by initializing your session with the same seed value. If you don't seed the PRNG, it will be autoseeded for you. This functionality incorporates David Bau's seedrandom.js Javascript module.-2
is parsed as -2
rather than -1 * 2
. The trade-off is that you must write Level - 1
with whitespace around the minus symbol, rather than Level-1
or you get a syntax error. 2 - -2
(=4) and 2 + -2
(=0) are syntactically OK. This change affects the D&D Men Attacking example, where the minus had been written without whilespace. In the future, I may change this so that 2-2
is again valid subtraction and ¯2
becomes the unary minus symbol as in 2-¯2
.abs
, ln
and floor
threading over arrays. So the expression abs [-0.1,.5,-.5,1,-2,3,-4]
yields [0.1, 0.5, 0.5, 1, 2, 3, 4]
instead of []
abs(-0.1)
is OK, but abs -0.1
is a syntax error. No parens necessary if threading over an array, so abs [-0.1,.5,-.5,1,-2,3,-4]
is OK. The functions that require parens are: U
, N
, Φ
, Phi
, probit
, abs
, acos
, acosh
, asin
, asinh
, atan
, atanh
, atan2
, ceil
, comb
, cos
, cosh
, exp
, floor
, ln
, log
, perm
, round
, sin
, sinh
, tan
, tanh
. This change affects the tali example, which used the comb
function without parens.U
, N
, Φ
, Phi
, probit
, abs
, acos
, acosh
, asin
, asinh
, atan
, atanh
, atan2
, ceil
, comb
, cos
, cosh
, exp
, floor
, ln
, log
, perm
, round
, sin
, sinh
, tan
, tanh
U
function to generate random variates from a continuous uniform distribution over given range. U()
defaults to U(0,1)
Phi
(or Φ
) function: Cumulative distribution function for standard normal distribution.probit
function: quantile function (or inverse cumulative distribution function) for standard normal distribution.N
function to generate random variates from a normal distribution. N()
defaults to the standard normal distribution N(0,1)
. Otherwise N(mu,sigma)
defaults to a normal distribution with mean mu
and standard deviation sigma
.U
, N
, Φ
, etc. are distinct from the variables U
, N
, Φ
, etc.log
function: base 10 logarithm. ln
is still base e
logarithmexp(x)
function as alternative to e^x
cos
, sin
, tan
. Added their inverses: acos
, asin
, atan
cosh
, sinh
, tanh
. Added their inverses: acosh
, asinh
, atanh
ceil
and round
functions. These are JavaScript implementations. May add alternative rounding functions in the future.inf
(or Inf
or INF
or ∞
) special variable used as upper limit for operations that compute a sequence, series or limit.$
. Question marks ?
may be used except in the initial position.domain
function that caused it to fail on singleton objects. This made the knucklebones example fail.union
in a way that breaks backward compatibility. See NEWS for details.concat
, powerset
and permute
array operators.intersect
, diff
(difference) and sdiff
(symmetric difference), respectively, ∩, \, and Δ.subset
/⊂ and subseteq
/⊆.all
/∀ and some
/∃ quantifiers that apply to arrays or matrices of boolean values.approx
/≈ equality comparison and the tol
variable which stores the tolerance to use to check approximations.prod
/Π operator to take the cartesian product of an array of arrays. Note that Π is uppercase pi, not to be confused with lowercase pi
/π which is the constant 3.141592653589793lcm
and gcd
functions. These each operate on an array of integers.cross
or × function. Note that × is not the letter "eks" x. Overloaded cross
to handle:trans
function to transpose an array or matrixdet
function to calculate determinant of matrixinv
function to do matrix inversematrix op matrix
matrix op array
matrix op scalar
The problem allowing numbers as strings is that it breaks comparisons, e.g.,
l@ubuntu:~/work/Palamedes$ node
> "9" > "20"
true
These bugs were breaking the OrderStatistics(pmf, n, k) for pmfs with domain elements > 10
string * number
, repeats the string number of timesroot
function+
operator when overloaded for string concatenationLast update: Fri Sep 23 2016