simple-expr-0.2.0.0: Minimalistic toolkit for simple mathematical expression.
Copyright(C) 2025 Alexey Tochin
LicenseBSD3 (see the file LICENSE)
MaintainerAlexey Tochin <Alexey.Tochin@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Debug.SimpleExpr.Utils.Algebra

Description

Inegral power type class and instances.

Synopsis

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

Expand
>>> (2 :: Int) *| (3 :: Float) :: Float
6.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

Instances details
Integral a => MultiplicativeAction a Int16 Source #

Int16 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Int16 -> Int16 Source #

Integral a => MultiplicativeAction a Int32 Source #

Int32 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Int32 -> Int32 Source #

Integral a => MultiplicativeAction a Int64 Source #

Int64 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Int64 -> Int64 Source #

Integral a => MultiplicativeAction a Int8 Source #

Int8 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Int8 -> Int8 Source #

Integral a => MultiplicativeAction a Word16 Source #

Word16 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Word16 -> Word16 Source #

Integral a => MultiplicativeAction a Word32 Source #

Word32 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Word32 -> Word32 Source #

Integral a => MultiplicativeAction a Word64 Source #

Word64 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Word64 -> Word64 Source #

Integral a => MultiplicativeAction a Word8 Source #

Word8 instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Word8 -> Word8 Source #

Integral a => MultiplicativeAction a SimpleExpr Source #

SimpleExpr instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> SimpleExpr -> SimpleExpr Source #

Integral a => MultiplicativeAction a Integer Source #

Integer instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Integer -> Integer Source #

Integral a => MultiplicativeAction a Natural Source #

Natural instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Natural -> Natural Source #

Real a => MultiplicativeAction a Double Source #

Double instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Double -> Double Source #

Real a => MultiplicativeAction a Float Source #

Float instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Float -> Float Source #

Integral a => MultiplicativeAction a Int Source #

Int instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Int -> Int Source #

Integral a => MultiplicativeAction a Word Source #

Word instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Word -> Word Source #

MultiplicativeAction a b => MultiplicativeAction a (Stream b) Source #

Stream instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Stream b -> Stream b Source #

MultiplicativeAction a b => MultiplicativeAction a (Identity b) Source #

Identity instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Identity b -> Identity b Source #

(Show b, MultiplicativeAction a b) => MultiplicativeAction a (Traced b) Source # 
Instance details

Defined in Debug.SimpleExpr.Utils.Traced

Methods

(*|) :: a -> Traced b -> Traced b Source #

MultiplicativeAction a b => MultiplicativeAction a (Vector b) Source #

Boxed vector Vector instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Vector b -> Vector b Source #

MultiplicativeAction a b => MultiplicativeAction a [b] Source #

List `[]` instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> [b] -> [b] Source #

(MultiplicativeAction a b0, MultiplicativeAction a b1) => MultiplicativeAction a (b0, b1) Source #

Tuple instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> (b0, b1) -> (b0, b1) Source #

MultiplicativeAction a b => MultiplicativeAction a (Vector Vector n b) Source #

Unboxed vector Vector instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> Vector Vector n b -> Vector Vector n b Source #

(MultiplicativeAction a b0, MultiplicativeAction a b1, MultiplicativeAction a b2) => MultiplicativeAction a (b0, b1, b2) Source #

Triple instance of MultiplicativeAction a.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(*|) :: a -> (b0, b1, b2) -> (b0, b1, b2) Source #

(*|) :: 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

Expand
>>> [1,1,1] |*| [1,2,0] :: Int
3
>>> ([1,1,1], Data.Vector.fromList [1, 2]) |*| ([1,2,0], Data.Vector.fromList [0, 2]) :: Int
7

Minimal complete definition

(|*|)

Instances

Instances details
Num a => Convolution Int16 Int16 a Source #

Int16 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Int16 -> Int16 -> a Source #

Num a => Convolution Int32 Int32 a Source #

Int32 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Int32 -> Int32 -> a Source #

Num a => Convolution Int64 Int64 a Source #

Int64 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Int64 -> Int64 -> a Source #

Num a => Convolution Int8 Int8 a Source #

Int8 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Int8 -> Int8 -> a Source #

Num a => Convolution Word16 Word16 a Source #

Word16 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Word16 -> Word16 -> a Source #

Num a => Convolution Word32 Word32 a Source #

Word32 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Word32 -> Word32 -> a Source #

Num a => Convolution Word64 Word64 a Source #

Word64 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Word64 -> Word64 -> a Source #

Num a => Convolution Word8 Word8 a Source #

Word8 instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Word8 -> Word8 -> a Source #

Num a => Convolution Integer Integer a Source #

Integer instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Integer -> Integer -> a Source #

Num a => Convolution Natural Natural a Source #

Natural instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Natural -> Natural -> a Source #

Fractional a => Convolution Double Double a Source #

Double instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Double -> Double -> a Source #

Fractional a => Convolution Float Float a Source #

Float instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Float -> Float -> a Source #

Num a => Convolution Int Int a Source #

Int instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Int -> Int -> a Source #

Num a => Convolution Word Word a Source #

Word instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Word -> Word -> a Source #

Convolution a b c => Convolution (Identity a) (Identity b) c Source #

Identity instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Identity a -> Identity b -> c Source #

(Convolution a b c, Additive c) => Convolution (Vector a) (Vector b) c Source #

Boxed vector Vector instance of Convolution. Smaller vector is efficently treated as padded with zeros.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Vector a -> Vector b -> c Source #

(Convolution a b c, Additive c) => Convolution [a] [b] c Source #

List `[]` instance of Convolution. Shorter list is efficently treated as padded with zeros.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: [a] -> [b] -> c Source #

(Convolution a0 b0 c, Convolution a1 b1 c, Additive c) => Convolution (a0, a1) (b0, b1) c Source #

Tuple instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: (a0, a1) -> (b0, b1) -> c Source #

(Convolution a b c, Additive c) => Convolution (Vector Vector n a) (Vector Vector n b) c Source #

Unboxed vector Vector instance of Convolution. Smaller vector is efficently treated as padded with zeros.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: Vector Vector n a -> Vector Vector n b -> c Source #

(Convolution a0 b0 c, Convolution a1 b1 c, Convolution a2 b2 c, Additive c) => Convolution (a0, a1, a2) (b0, b1, b2) c Source #

Triple instance of Convolution.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(|*|) :: (a0, a1, a2) -> (b0, b1, b2) -> c Source #

(|*|) :: 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

Expand
>>> import Debug.SimpleExpr (variable, SE, simplify)
>>> import GHC.Base (($))
>>> import GHC.Real (Rational)
>>> import qualified NumHask
>>> x = variable "x"
>>> (^^ 2) x
x^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

Instances details
AlgebraicPower Integer SimpleExpr Source #

AlgebraicPower instance for raising SimpleExpr values to Integer exponents.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Integral a => AlgebraicPower a Int8 Source #

Int8 instance of AlgebraicPower typeclass.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Int8 -> a -> Int8 Source #

Integral a => AlgebraicPower a Integer Source #

Integer instance of AlgebraicPower typeclass.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Integer -> a -> Integer Source #

Real a => AlgebraicPower a Double Source #

Double instance of AlgebraicPower typeclass for raising Double values to Real exponents.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Double -> a -> Double Source #

Real a => AlgebraicPower a Float Source #

Float instace of AlgebraicPower typeclass.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Float -> a -> Float Source #

Integral a => AlgebraicPower a Int Source #

Int instance of AlgebraicPower typeclass.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Int -> a -> Int Source #

(Field a, AlgebraicPower Natural a, MultiplicativeAction Natural a) => AlgebraicPower Integer (Complex a) Source #

Complex number Complex instance of AlgebraicPower for raising to Integer exponents.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Complex a -> Integer -> Complex a Source #

(Ring a, AlgebraicPower Natural a, MultiplicativeAction Natural a) => AlgebraicPower Natural (Complex a) Source #

Complex number Complex instance of AlgebraicPower for raising to Natural exponents.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Complex a -> Natural -> Complex a Source #

(Show b, AlgebraicPower a b) => AlgebraicPower a (Traced b) Source # 
Instance details

Defined in Debug.SimpleExpr.Utils.Traced

Methods

(^^) :: Traced b -> a -> Traced b Source #

AlgebraicPower b a => AlgebraicPower b (Stream a) Source #

AlgebraicPower instance for raising streams to powers.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Stream a -> b -> Stream a Source #

AlgebraicPower b a => AlgebraicPower b (Identity a) Source #

Identity instance of AlgebraicPower typeclass.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Identity a -> b -> Identity a Source #

AlgebraicPower b a => AlgebraicPower b (Vector a) Source #

AlgebraicPower instance for raising boxed vectors to powers.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Vector a -> b -> Vector a Source #

(AlgebraicPower b a, Unbox a) => AlgebraicPower b (Vector a) Source #

AlgebraicPower instance for raising unboxed vectors to powers.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Vector a -> b -> Vector a Source #

AlgebraicPower b a => AlgebraicPower b (Maybe a) Source #

Maybe instance of AlgebraicPower typeclass.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Maybe a -> b -> Maybe a Source #

AlgebraicPower b a => AlgebraicPower b [a] Source #

AlgebraicPower instance for raising lists to powers.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: [a] -> b -> [a] Source #

(AlgebraicPower b a0, AlgebraicPower b a1) => AlgebraicPower b (a0, a1) Source #

AlgebraicPower instance for raising tuples to powers.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: (a0, a1) -> b -> (a0, a1) Source #

(AlgebraicPower b a, Vector v a) => AlgebraicPower b (Vector v n a) Source #

AlgebraicPower instance for raising sized vectors to powers.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: Vector v n a -> b -> Vector v n a Source #

(AlgebraicPower b a0, AlgebraicPower b a1, AlgebraicPower b a2) => AlgebraicPower b (a0, a1, a2) Source #

AlgebraicPower instance for raising triples to powers.

Instance details

Defined in Debug.SimpleExpr.Utils.Algebra

Methods

(^^) :: (a0, a1, a2) -> b -> (a0, a1, a2) Source #

(^^) :: AlgebraicPower a b => b -> a -> b Source #

(^) :: AlgebraicPower Integer a => a -> Integer -> a Source #

Infix synonym for (^^).

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

Expand
>>> 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

Expand
>>> splitInto4 [0..11]
([0,4,8],[1,5,9],[2,6,10],[3,7,11])