p-norm ( v p -- x )
Factor documentation > Factor handbook > The language > Numbers > Vector operations > Vector arithmetic
Prev:normalize ( u -- v )
Next:distance ( u v -- x )


Vocabulary
math.vectors

Inputs and outputs
va sequence of numbers
pa positive real number
xa non-negative real number


Word description
Computes the length of a mathematical vector in L^p space.

Definition
USING: combinators kernel math sequences ;

IN: math.vectors

: p-norm ( v p -- x )
{
{ [ dup 1 = ] [ drop l1-norm ] }
{ [ dup 2 = ] [ drop norm ] }
{ [ dup fp-infinity? ] [ drop supremum ] }
[ p-norm-default ]
} cond ;