Factor Documentation
|
Home
|
Glossary
|
Search
factorcode.org
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
v
a sequence of numbers
p
a positive real number
x
a 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
;