| Copyright | (C) 2025 Alexey Tochin |
|---|---|
| License | BSD3 (see the file LICENSE) |
| Maintainer | Alexey Tochin <Alexey.Tochin@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Debug.SimpleExpr.Utils.Algebra
Description
Inegral power type class and instances.
Synopsis
- class MultiplicativeAction a b
- (*|) :: MultiplicativeAction a b => a -> b -> b
- class Convolution a b c
- (|*|) :: Convolution a b c => a -> b -> c
- class AlgebraicPower a b
- type IntPower a = AlgebraicPower Int a
- type IntegerPower a = AlgebraicPower Integer a
- type NaturalPower a = AlgebraicPower Natural a
- type FloatPower a = AlgebraicPower Float a
- type DoublePower a = AlgebraicPower Double a
- (^^) :: AlgebraicPower a b => b -> a -> b
- (^) :: AlgebraicPower Integer a => a -> Integer -> a
- square :: AlgebraicPower Integer a => a -> a
- qube :: AlgebraicPower Integer a => a -> a
- splitIntoN :: Int -> [a] -> [[a]]
- splitInto4 :: [a] -> ([a], [a], [a], [a])
Documentation
class MultiplicativeAction a b Source #
Type class for multiplicative actions.
This class defines a method for multiplying a value of type b
by a value of type a producing a value of type b.
Examples
>>>(2 :: Int) *| (3 :: Float) :: Float6.0
>>>(2 :: Int) *| (3 :: Float, 4 :: Double) :: (Float, Double)(6.0,8.0)
>>>(2 :: Natural) *| [3, 4, 5] :: [Int][6,8,10]
>>>(2 :: Natural) *| Data.Vector.fromList [3, 4, 5] :: Data.Vector.Vector Int[6,8,10]
>>>(2 :: Natural) *| [(3, 4), (5, 6), (7, 8)] :: [(Int, Int)][(6,8),(10,12),(14,16)]
>>>(2 :: Natural) *| Data.Vector.fromList [[3, 4], [], [5]] :: Data.Vector.Vector [Int][[6,8],[],[10]]
Minimal complete definition
Instances
(*|) :: MultiplicativeAction a b => a -> b -> b Source #
Left multiplicative action operator that preserve the type on the right hand side.
class Convolution a b c Source #
Type class for convolution operations that support nested structures.
Examples
>>>[1,1,1] |*| [1,2,0] :: Int3
>>>([1,1,1], Data.Vector.fromList [1, 2]) |*| ([1,2,0], Data.Vector.fromList [0, 2]) :: Int7
Minimal complete definition
Instances
(|*|) :: Convolution a b c => a -> b -> c Source #
The convolution operator that combines values of type a and b.
class AlgebraicPower a b Source #
Type class for power operations.
This class defines a method for raising a value of type a to a power
of type b.
It is usefull to deistinguish, for example,
the integral power defined as a repetative multiplication
(^^) or (^) from the general power operation.
Examples
>>>import Debug.SimpleExpr (variable, SE, simplify)>>>import GHC.Base (($))>>>import GHC.Real (Rational)>>>import qualified NumHask
>>>x = variable "x"
>>>(^^ 2) xx^2
>>>(NumHask.^^ 2) (x)x*x
>>>(^^ 2) (3 :: Float)9.0
>>>(2.0 :: Double) ^^ (3.5 :: Float)11.313708498984761
For lists, vectors and other containers, the power operation is applied element-wise: >>> (^^ 2) [0, 1, 2, 3] :: [Int] [0,1,4,9]
Minimal complete definition
Instances
type IntPower a = AlgebraicPower Int a Source #
Int type alias for AlgebraicPower.
type IntegerPower a = AlgebraicPower Integer a Source #
Integer type alias for AlgebraicPower.
type NaturalPower a = AlgebraicPower Natural a Source #
Natural type alias for AlgebraicPower.
type FloatPower a = AlgebraicPower Float a Source #
Float type alias for AlgebraicPower.
type DoublePower a = AlgebraicPower Double a Source #
Double type alias for AlgebraicPower.
(^^) :: AlgebraicPower a b => b -> a -> b Source #
square :: AlgebraicPower Integer a => a -> a Source #
Square a value.
qube :: AlgebraicPower Integer a => a -> a Source #
Qube a value.
splitIntoN :: Int -> [a] -> [[a]] Source #
Split a list into n lists by taking every n-th element.
Examples
>>>splitIntoN 3 [0..11][[0,3,6,9],[1,4,7,10],[2,5,8,11]]
splitInto4 :: [a] -> ([a], [a], [a], [a]) Source #
Split a list into n lists by taking every n-th element.
Examples
>>>splitInto4 [0..11]([0,4,8],[1,5,9],[2,6,10],[3,7,11])