tropical (empty) → 0.0.0.0
raw patch · 5 files changed
+136/−0 lines, 5 filesdep +basedep +semiring-simplesetup-changed
Dependencies added: base, semiring-simple
Files
- LICENSE +29/−0
- README.md +16/−0
- Setup.hs +2/−0
- src/Data/Semiring/Tropical.hs +53/−0
- tropical.cabal +36/−0
+ LICENSE view
@@ -0,0 +1,29 @@+Copyright (c) 2014, Peter Harpending. <pharpend2@gmail.com>+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++1. Redistributions of source code must retain the above copyright+notice, this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the copyright holder nor the names of its+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+HOLDER 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,16 @@+Tropical+========++Tropical numbers are the same as real numbers, except the operations are+different. You can compound these operations, and get tropical vectors,+tropical matrices, etc. This package is a Haskell library dealing with+tropical things.++For more information on tropical geometry, see+<https://en.wikipedia.org/wiki/Tropical_geometry>.++Contributing+------------++Anyone who wants to contribute is more than welcome. This library is+BSD-licensed, so you can pretty much do what you want with it.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Semiring/Tropical.hs view
@@ -0,0 +1,53 @@+{-|+Module : Data.Semiring.Tropical+Description : The definition of tropicality+Copyright : 2014, Peter Harpending.+License : BSD3+Maintainer : Peter Harpending <pharpend2@gmail.com>+Stability : experimental+Portability : Linux++This file just contains the minimal definition of "tropical," meaning+any tropical object has to be an ordered semiring.++-}++module Data.Semiring.Tropical where++import Data.Semiring++-- |Tropical numbers are like real numbers, except zero is the same+-- thing as Infinity, and you can't subtract.+data Real t => Tropical t = Tropical { realValue :: t } -- ^Any tropical number+ | Infinity -- ^Infinity+ deriving (Eq, Ord, Show)++type Operator a = a -> a -> a++instance Real a => Semiring (Tropical a) where+ -- |Tropical addition is the same as taking the minimum+ a .+. b = min a b+ -- |Tropical multiplication is the same as the sum+ a .*. b+ | Infinity==a || Infinity==b = Infinity+ | otherwise = Tropical $ (realValue a) + (realValue b)++ -- |Infinity acts like zero.+ zero = Infinity+ -- |Zero acts like one.+ one = Tropical 0++-- |Tropical division. Remember, if Infinity is tropical zero, then+-- you can't divide by it!+(./.) :: Real a => Operator (Tropical a)+_ ./. Infinity = undefined+Infinity ./. _ = Infinity+a ./. b = Tropical $ (realValue a) - (realValue b)++-- -- |Tropical exponentiation - same as classical multiplication. A+-- -- mildly interesting correlary is that tropical exponentiation is+-- -- commutative. That is, y .^. x = x .^. y, for x and y tropical.+(.^.) :: Real a => Operator (Tropical a)+a .^. b+ | Infinity==a || Infinity==b = Infinity+ | otherwise = Tropical $ (realValue a) * (realValue b)
+ tropical.cabal view
@@ -0,0 +1,36 @@+-- Initial tropical.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: tropical+version: 0.0.0.0+synopsis: A library for tropical mathematics.+description:+ Tropical numbers are the same as real numbers, except the operations are+ different. See the documentation for more information.+license: BSD3+license-file: LICENSE+author: Peter Harpending+maintainer: Peter Harpending <pharpend2@gmail.com>+copyright: 2014, Peter Harpending.+category: Math+build-type: Simple+extra-source-files:+ README.md+ , LICENSE+cabal-version: >=1.10++library+ exposed-modules:+ Data.Semiring.Tropical+ -- other-modules: + -- other-extensions: + build-depends:+ base >=4.7 && <4.8+ , semiring-simple >=0.2+ hs-source-dirs: src/+ default-language: Haskell2010+ ghc-options: -Wall++source-repository head+ type: git+ location: https://github.com/pharpend/tropical.git