packages feed

cl3-hmatrix-interface (empty) → 1.0.0.0

raw patch · 6 files changed

+184/−0 lines, 6 filesdep +basedep +cl3dep +hmatrixsetup-changed

Dependencies added: base, cl3, hmatrix

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for cl3-hmatrix-interface++## 1.0.0.0  -- 2018-5-26++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, Nathan Waivio++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Nathan Waivio nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,12 @@++# Cl3 interface to/from HMatrix++A simple interface supporting to/from: Matrix (Complex Double).++The exported functions make use of the isomorphism between APS and M(2,C) and are:+*  toHMatrix+*  fromHMatrix++++
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cl3-hmatrix-interface.cabal view
@@ -0,0 +1,81 @@+-- Initial cl3-hmatrix-interface.cabal generated by cabal init.  For further documentation, +-- see http://haskell.org/cabal/users-guide/++-- The name of the package.+name:                cl3-hmatrix-interface++-- The package version.  See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- https://wiki.haskell.org/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             1.0.0.0++-- A short (one-line) description of the package.+synopsis:            Interface to/from Cl3 and HMatrix.++-- A longer description of the package.+description:         Haskell Library implementing standard interface functions for the Algebra of Physical Space Cl(3,0) and HMatrix   ++-- URL for the project homepage or repository.+homepage:            https://github.com/waivio/cl3-hmatrix-interface++bug-reports:         https://github.com/waivio/cl3-hmatrix-interface/issues++-- The license under which the package is released.+license:             BSD3++-- The file containing the license text.+license-file:        LICENSE++-- The package author(s).+author:              Nathan Waivio++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer:          Nathan Waivio <nathan.waivio@gmail.com>++-- A copyright notice.+copyright:           Copyright (C) 2018 Nathan Waivio++category:            Math, Algebra++build-type:          Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+extra-source-files:  ChangeLog.md, README.md++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.10++source-repository head+  type:     git+  location: https://github.com/waivio/cl3-hmatrix-interface.git++library+  -- Modules exported by the library.+  exposed-modules:+    Algebra.Geometric.Cl3.HMatrixInterface+  +  -- Compiler options+  ghc-options: -Wall -O2+  +  -- LANGUAGE extensions used by modules in this package.+  other-extensions:+    Unsafe,+    ViewPatterns+  +  -- Other library packages from which modules are imported.+  build-depends:       +    base >=4.8 && <5,+    cl3 >=1.0 && <2,+    hmatrix >=0.16 && <1+  +  -- Directories containing source files.+  hs-source-dirs:      src+  +  -- Base language which the package is written in.+  default-language:    Haskell2010+
+ src/Algebra/Geometric/Cl3/HMatrixInterface.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE ViewPatterns #-}+++--------------------------------------------------------------------------------------------+-- |+-- Copyright   :  (C) 2018 Nathan Waivio+-- License     :  BSD3+-- Maintainer  :  Nathan Waivio <nathan.waivio@gmail.com>+-- Stability   :  Stable+-- Portability :  unportable+-- +-- Interface functions of Cl3 types to/from HMatrix. +-- +-------------------------------------------------------------------+++module Algebra.Geometric.Cl3.HMatrixInterface+(+ toHMatrix, + fromHMatrix+) where++import safe Algebra.Geometric.Cl3 (Cl3(..), toAPS, reduce)+import Numeric.LinearAlgebra.Data (Matrix, atIndex, (><))+import safe Data.Complex (Complex(..))++-- | 'toHMatrix' Convert a Cl3 Cliffor to a HMatrix Matrix+toHMatrix :: Cl3 -> Matrix (Complex Double)+toHMatrix (toAPS -> APS a0 a1 a2 a3 a23 a31 a12 a123) = +  let a = (a0+a3) :+ (a123+a12)+      b = (a1+a31) :+ (a23-a2)+      c = (a1-a31) :+ (a23+a2)+      d = (a0-a3) :+ (a123-a12)+  in (2><2) [a,b,c,d]+toHMatrix _ = error "Pattern Matching failure of toHMatrix for the toAPS/APS View Pattern"++-- | 'fromHMatrix' Convert from a HMatrix Matrix (2x2 Complex Double hopefully...) to a Cl3 Cliffor+fromHMatrix :: Matrix (Complex Double) -> Cl3+fromHMatrix mat =+  let (a :+ ai) = mat `atIndex` (0,0)+      (b :+ bi) = mat `atIndex` (0,1)+      (c :+ ci) = mat `atIndex` (1,0)+      (d :+ di) = mat `atIndex` (1,1)+      a0 = (a + d) / 2+      a1 = (b + c) / 2+      a2 = (ci - bi) / 2+      a3 = (a - d) / 2+      a23 = (ci + bi) / 2+      a31 = (b - c) / 2+      a12 = (ai - di) / 2+      a123 = (ai + di) / 2+  in reduce (APS a0 a1 a2 a3 a23 a31 a12 a123)+