├── aern-mpfr ├── demos │ ├── .gitignore │ └── Minimal.hs ├── Setup.lhs ├── src │ └── Numeric │ │ └── AERN │ │ └── RealArithmetic │ │ ├── Basis │ │ ├── MPFR │ │ │ ├── SpecialConst.hs │ │ │ ├── Utilities.hs │ │ │ ├── Effort.hs │ │ │ ├── ShowInternals.hs │ │ │ ├── ExactOps.hs │ │ │ ├── Elementary.hs │ │ │ └── Measures.hs │ │ └── MPFR.hs │ │ └── Interval │ │ └── MPFR.hs └── LICENCE ├── aern-poly-plot-gtk ├── demos │ └── .gitignore ├── Setup.hs ├── .gitignore ├── minmax16-n10-nooffset.pdf ├── minmax16-n10-withoffset.pdf ├── minmax16-n10-withpower4offset.pdf ├── LICENCE └── src │ └── Numeric │ └── AERN │ └── Poly │ └── IntPoly │ └── Plot.hs ├── FnView.glade ├── aern-temp ├── FnView.glade ├── benchmarks │ └── FnRepComparison │ │ ├── FunctionAbstraction.hs │ │ ├── runFnRepComparison.hs │ │ └── PolynomialApproximation.hs └── LICENCE ├── aern-real ├── Setup.hs ├── src │ └── Numeric │ │ └── AERN │ │ ├── RealArithmetic │ │ ├── NumericOrderRounding │ │ │ ├── Operators.hs │ │ │ └── SpecialConst.hs │ │ ├── RefinementOrderRounding │ │ │ ├── Operators.hs │ │ │ └── SpecialConst.hs │ │ ├── Auxiliary.hs │ │ ├── Bench.hs │ │ └── ExactOps.hs │ │ └── Misc │ │ └── IntegerArithmetic.hs ├── LICENCE └── aern-real.cabal ├── aern-interval ├── Setup.hs ├── src │ └── Numeric │ │ └── AERN │ │ ├── RealArithmetic │ │ └── Interval │ │ │ ├── .gitignore │ │ │ ├── ExactOps.hs │ │ │ ├── SpecialConst.hs │ │ │ ├── ElementaryFromBasis.hs │ │ │ └── Measures.hs │ │ └── Basics │ │ ├── Interval.hs │ │ └── Interval │ │ └── Arbitrary.hs ├── LICENCE └── aern-interval.cabal ├── aern-realfn ├── Setup.hs ├── LICENCE ├── src │ └── Numeric │ │ └── AERN │ │ ├── RmToRn │ │ ├── RefinementOrderRounding │ │ │ ├── ChebyshevPoly.hs │ │ │ └── BernsteinPoly.hs │ │ ├── Integration.hs │ │ └── New.hs │ │ └── RmToRn.hs └── aern-realfn.cabal ├── wiki-attach └── overview.jpg ├── aern-double ├── .gitignore ├── Setup.lhs ├── src │ └── Numeric │ │ └── AERN │ │ └── RealArithmetic │ │ ├── Basis │ │ ├── Double │ │ │ ├── ShowInternals.hs │ │ │ ├── SpecialConst.hs │ │ │ ├── Measures.hs │ │ │ └── NumericOrder.hs │ │ └── Double.hs │ │ └── Interval │ │ └── Double.hs ├── bench │ └── Main.hs ├── demos │ ├── Riemann.hs │ ├── Quadratic.hs │ ├── Zero.hs │ └── Minimal.hs └── LICENCE ├── aern-order ├── Setup.lhs ├── src │ └── Numeric │ │ └── AERN │ │ ├── Misc │ │ ├── Bool.hs │ │ ├── Debug.hs │ │ ├── Maybe.hs │ │ └── QuickCheck.hs │ │ ├── NumericOrder │ │ ├── Operators.hs │ │ └── Extrema.hs │ │ ├── RefinementOrder │ │ ├── Operators.hs │ │ ├── Extrema.hs │ │ └── IntervalLike.hs │ │ ├── Basics │ │ ├── ShowInternals.hs │ │ ├── Laws │ │ │ ├── Relation.hs │ │ │ ├── PartialRelation.hs │ │ │ ├── Utilities.hs │ │ │ └── Operation.hs │ │ ├── SizeLimits.hs │ │ └── Consistency.hs │ │ ├── NumericOrder.hs │ │ └── RefinementOrder.hs └── LICENCE ├── aern-ivp ├── .gitignore ├── shrinkwrap-doughnutsegm.png ├── LICENCE ├── demos │ ├── Enclosing_Zeno_plots-NAHS2015.txt │ └── demoPicardView.hs └── src │ └── Numeric │ └── AERN │ └── IVP │ └── Plot │ └── PicardView │ ├── Layout.hs │ └── State.hs ├── .hgtags ├── aern-mpfr-rounded ├── Setup.lhs ├── src │ └── Numeric │ │ └── AERN │ │ └── RealArithmetic │ │ ├── Basis │ │ ├── MPFR │ │ │ ├── SpecialConst.hs │ │ │ ├── Utilities.hs │ │ │ ├── ShowInternals.hs │ │ │ ├── ExactOps.hs │ │ │ ├── Elementary.hs │ │ │ └── Measures.hs │ │ └── MPFR.hs │ │ └── Interval │ │ └── MPFR.hs ├── LICENCE ├── aern-mpfr-rounded.cabal └── demos │ └── Minimal.hs ├── README.md ├── aern-fnreps ├── src │ ├── Main.hs │ └── FnReps │ │ ├── FunctionAbstraction.hs │ │ └── Polynomial │ │ └── UnaryChebSparse.hs ├── LICENCE └── aern-fnreps.cabal ├── install-nogtk.sh ├── install-nogtk-nompfr.sh ├── install-nompfr.sh ├── install-all.sh ├── LICENSE ├── aern-poly ├── LICENCE ├── src │ └── Numeric │ │ └── AERN │ │ └── Poly │ │ └── IntPoly │ │ ├── Differentiation.hs │ │ └── Elementary.hs ├── tests │ └── Main.hs └── aern-poly.cabal └── aern-realfn-plot-gtk ├── LICENCE ├── aern-realfn-plot-gtk.cabal └── src └── Numeric └── AERN └── RmToRn └── Plot ├── FnView.hs └── CairoDrawable.hs /aern-mpfr/demos/.gitignore: -------------------------------------------------------------------------------- 1 | /t 2 | -------------------------------------------------------------------------------- /aern-poly-plot-gtk/demos/.gitignore: -------------------------------------------------------------------------------- 1 | /t 2 | -------------------------------------------------------------------------------- /FnView.glade: -------------------------------------------------------------------------------- 1 | aern-realfn-plot-gtk/FnView.glade -------------------------------------------------------------------------------- /aern-temp/FnView.glade: -------------------------------------------------------------------------------- 1 | ../aern-realfn-plot-gtk/FnView.glade -------------------------------------------------------------------------------- /aern-real/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /aern-interval/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /aern-interval/src/Numeric/AERN/RealArithmetic/Interval/.gitignore: -------------------------------------------------------------------------------- 1 | /old 2 | -------------------------------------------------------------------------------- /aern-realfn/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /aern-poly-plot-gtk/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /wiki-attach/overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpsanders/aern/master/wiki-attach/overview.jpg -------------------------------------------------------------------------------- /aern-double/.gitignore: -------------------------------------------------------------------------------- 1 | /exp-strict-vs-nonstrict-int.png 2 | /exp-strict-vs-nonstrict-vs-unpacked-int.png 3 | -------------------------------------------------------------------------------- /aern-mpfr/Setup.lhs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env runhaskell 2 | > import Distribution.Simple 3 | > main = defaultMain 4 | -------------------------------------------------------------------------------- /aern-order/Setup.lhs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env runhaskell 2 | > import Distribution.Simple 3 | > main = defaultMain 4 | -------------------------------------------------------------------------------- /aern-double/Setup.lhs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env runhaskell 2 | > import Distribution.Simple 3 | > main = defaultMain 4 | -------------------------------------------------------------------------------- /aern-ivp/.gitignore: -------------------------------------------------------------------------------- 1 | /run-fall-30-2.sh 2 | /run-lorenz-20-8.sh 3 | /simple-uv-et*.pdf 4 | /run-lorenz-param.sh 5 | -------------------------------------------------------------------------------- /aern-poly-plot-gtk/.gitignore: -------------------------------------------------------------------------------- 1 | /sinsin.pdf 2 | /sinsinApprox.pdf 3 | /sinsinIntersectionZoom.pdf 4 | /plots 5 | -------------------------------------------------------------------------------- /.hgtags: -------------------------------------------------------------------------------- 1 | 7df8df9ce068e1e2bca8b9aa1ae85ab2d354f818 2011.1 2 | 9225f49ba81d330bdb250b3ad289e0fb12f28590 2011.1.0.2 3 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/Setup.lhs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env runhaskell 2 | > import Distribution.Simple 3 | > main = defaultMain 4 | -------------------------------------------------------------------------------- /aern-ivp/shrinkwrap-doughnutsegm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpsanders/aern/master/aern-ivp/shrinkwrap-doughnutsegm.png -------------------------------------------------------------------------------- /aern-poly-plot-gtk/minmax16-n10-nooffset.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpsanders/aern/master/aern-poly-plot-gtk/minmax16-n10-nooffset.pdf -------------------------------------------------------------------------------- /aern-poly-plot-gtk/minmax16-n10-withoffset.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpsanders/aern/master/aern-poly-plot-gtk/minmax16-n10-withoffset.pdf -------------------------------------------------------------------------------- /aern-poly-plot-gtk/minmax16-n10-withpower4offset.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpsanders/aern/master/aern-poly-plot-gtk/minmax16-n10-withpower4offset.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### This repository is in maintenance mode. See [aern2](https://github.com/michalkonecny/aern2), a rewrite. 2 | 3 | [AERN Homepage](http://michalkonecny.github.io/aern/_site/index.html) 4 | -------------------------------------------------------------------------------- /aern-fnreps/src/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Main 4 | Description : run all tests defined in the AERN-Real package 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | -} 12 | module Main where 13 | 14 | main = undefined -------------------------------------------------------------------------------- /aern-fnreps/src/FnReps/FunctionAbstraction.hs: -------------------------------------------------------------------------------- 1 | module FnReps.FunctionAbstraction where 2 | 3 | --import Numeric.AERN.MPFRBasis.Interval 4 | import Numeric.AERN.DoubleBasis.Interval 5 | 6 | type RA = DI 7 | 8 | class (Floating fn) => RF fn where 9 | evalMI :: fn -> RA -> RA 10 | constFn :: RA -> fn 11 | idFn :: fn 12 | weierstrassFn :: fn 13 | primitiveFn :: fn -> fn 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /install-nogtk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | (cd aern-order; cabal install --force-reinstalls) 4 | (cd aern-real; cabal install --force-reinstalls) 5 | (cd aern-interval; cabal install --force-reinstalls) 6 | (cd aern-double; cabal install --force-reinstalls) 7 | (cd aern-mpfr; cabal install --force-reinstalls) 8 | (cd aern-realfn; cabal install --force-reinstalls) 9 | (cd aern-poly; cabal install --force-reinstalls) 10 | -------------------------------------------------------------------------------- /install-nogtk-nompfr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | (cd aern-order; cabal install --force-reinstalls) 4 | (cd aern-real; cabal install --force-reinstalls) 5 | (cd aern-interval; cabal install --force-reinstalls) 6 | (cd aern-double; cabal install --force-reinstalls) 7 | (cd aern-mpfr; cabal install --force-reinstalls) 8 | (cd aern-realfn; cabal install --force-reinstalls) 9 | (cd aern-poly; cabal install --force-reinstalls) 10 | -------------------------------------------------------------------------------- /install-nompfr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | (cd aern-order; cabal install --force-reinstalls) 4 | (cd aern-real; cabal install --force-reinstalls) 5 | (cd aern-interval; cabal install --force-reinstalls) 6 | (cd aern-double; cabal install --force-reinstalls) 7 | (cd aern-realfn; cabal install --force-reinstalls) 8 | (cd aern-realfn-plot-gtk; cabal install --force-reinstalls) 9 | (cd aern-poly; cabal install --force-reinstalls) 10 | (cd aern-poly-plot-gtk; cabal install --force-reinstalls) 11 | (cd aern-ivp; cabal install --force-reinstalls) 12 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Misc/Bool.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Misc.Bool 3 | Description : miscellaneous boolean functions 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Miscellaneous boolean functions. 12 | -} 13 | module Numeric.AERN.Misc.Bool where 14 | 15 | (===>) :: Bool -> Bool -> Bool 16 | a ===> b = not a || b 17 | 18 | (<===>) :: Bool -> Bool -> Bool 19 | a <===> b = a == b 20 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/NumericOrder/Operators.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.NumericOrder.Operators 3 | Description : re-export of parent's operators for easier direct import 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Re-export of operators from the parent module for easier direct import. 12 | -} 13 | module Numeric.AERN.NumericOrder.Operators 14 | ( 15 | (==?), (<==>?), (?), (=?), (>?) 16 | ) 17 | where 18 | 19 | import Numeric.AERN.NumericOrder -------------------------------------------------------------------------------- /aern-temp/benchmarks/FnRepComparison/FunctionAbstraction.hs: -------------------------------------------------------------------------------- 1 | module FunctionAbstraction where 2 | 3 | import Numeric.AERN.MPFRBasis.Interval 4 | 5 | type R = Int -> MI 6 | 7 | class RF fn where 8 | build :: (Rational, Rational) -> Expression -> fn 9 | evalR :: fn -> R -> R 10 | evalMI :: fn -> MI -> MI 11 | integrate :: fn -> fn 12 | supportsIntegration :: fn -> Bool 13 | 14 | data Expression = 15 | ExprLit Rational 16 | | ExprVar 17 | | ExprPlus Expression Expression 18 | | ExprTimes Expression Expression 19 | | ExprNegate Expression 20 | | ExprExp Expression 21 | | ExprSqrt Expression 22 | | ExprAbs Expression 23 | 24 | 25 | -------------------------------------------------------------------------------- /install-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | (cd aern-order; cabal install --force-reinstalls) 4 | (cd aern-real; cabal install --force-reinstalls) 5 | (cd aern-interval; cabal install --force-reinstalls) 6 | (cd aern-double; cabal install --force-reinstalls) 7 | (cd aern-mpfr; cabal install --force-reinstalls) 8 | (cd aern-mpfr-rounded; cabal install --force-reinstalls) 9 | (cd aern-realfn; cabal install --force-reinstalls) 10 | (cd aern-realfn-plot-gtk; cabal install --force-reinstalls) 11 | (cd aern-poly; cabal install --force-reinstalls) 12 | (cd aern-poly-plot-gtk; cabal install --force-reinstalls) 13 | (cd aern-ivp; cabal install --force-reinstalls) 14 | (cd aern-temp; cabal install --force-reinstalls) 15 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/RefinementOrder/Operators.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RefinementOrder.Operators 3 | Description : re-export of parent's operators for easier direct import 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Re-export of operators from the parent module for easier direct import. 12 | -} 13 | module Numeric.AERN.RefinementOrder.Operators 14 | ( 15 | (|==?), (|<==>?), (|?), (|=?), (|>?), (⊏?), (⊑?), (⊒?), (⊐?), 16 | (<\/>?), (>\/?), (>⊔), (>\/<), (<⊔>), (>⊔<), (\/), (⊔), 18 | (), (>/\<), (<⊓>), (>⊓<), (/\), (⊓) 19 | ) 20 | where 21 | 22 | import Numeric.AERN.RefinementOrder -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/RealArithmetic/NumericOrderRounding/Operators.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.NumericOrderRounding.Operators 3 | Description : re-export of parent's operators for easier direct import 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Re-export of operators from the parent module for easier direct import. 12 | -} 13 | 14 | module Numeric.AERN.RealArithmetic.NumericOrderRounding.Operators 15 | ( 16 | (+.), (+^), (-.), (-^), 17 | (*.), (*^), (/.), (/^), 18 | (|+.), (|+^), (+.|), (+^|), 19 | (|*.), (|*^), (*.|), (*^|), 20 | (/.|), (/^|) 21 | ) 22 | where 23 | 24 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/NumericOrder/Extrema.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.NumericOrder.Extrema 3 | Description : types that have least and greatest elements 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Types that have least and greatest elements. 12 | 13 | This module is hidden and reexported via its parent NumericOrder. 14 | -} 15 | module Numeric.AERN.NumericOrder.Extrema where 16 | 17 | {-| 18 | A type with extrema. 19 | -} 20 | class (HasLeast t, HasGreatest t) => HasExtrema t 21 | 22 | {-| 23 | A type with a least element. 24 | -} 25 | class HasLeast t where 26 | least :: t -> t 27 | 28 | {-| 29 | A type with a greatest element. 30 | -} 31 | class HasGreatest t where 32 | greatest :: t -> t 33 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Basics/ShowInternals.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.Basics.Exception 4 | Description : formatting with optional display of internal components 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Formatting with optional display of internal components. 13 | -} 14 | 15 | module Numeric.AERN.Basics.ShowInternals where 16 | 17 | class ShowInternals t where 18 | type ShowInternalsIndicator t 19 | defaultShowIndicator :: t -> ShowInternalsIndicator t 20 | showInternals :: (ShowInternalsIndicator t) -> t -> String 21 | 22 | showUsingShowInternals :: (ShowInternals t) => t -> String 23 | showUsingShowInternals a = 24 | showInternals (defaultShowIndicator a) a 25 | 26 | 27 | -------------------------------------------------------------------------------- /aern-interval/src/Numeric/AERN/Basics/Interval.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.Basics.Interval 4 | Description : a minimal interval datatype 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | A minimal interval datatype and its instances. 13 | -} 14 | module Numeric.AERN.Basics.Interval 15 | ( 16 | module Numeric.AERN.Basics.Interval.Basics, 17 | module Numeric.AERN.Basics.Interval.Consistency, 18 | module Numeric.AERN.Basics.Interval.NumericOrder, 19 | module Numeric.AERN.Basics.Interval.RefinementOrder, 20 | ) 21 | where 22 | 23 | import Numeric.AERN.Basics.Interval.Basics 24 | import Numeric.AERN.Basics.Interval.Consistency 25 | import Numeric.AERN.Basics.Interval.NumericOrder 26 | import Numeric.AERN.Basics.Interval.RefinementOrder 27 | 28 | -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/RealArithmetic/RefinementOrderRounding/Operators.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 3 | Description : convenience operators and functions with default effort 4 | Description : re-export of parent's operators for easier direct import 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Re-export of operators from the parent module for easier direct import. 13 | -} 14 | 15 | module Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 16 | ( 17 | (>+<), (<+>), (>-<), (<->), 18 | (>*<), (<*>), (>/<), (), 19 | -- (>/+<), (), (/+), 20 | (>^<), (<^>), 21 | (|>+<), (|<+>), (|+), (>+<|), (<+>|), (+|), 22 | (|>*<), (|<*>), (|*), (>*<|), (<*>|), (*|), 23 | (>/<|), (|), (/|) 24 | ) 25 | where 26 | 27 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /aern-double/src/Numeric/AERN/RealArithmetic/Basis/Double/ShowInternals.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.Double.ShowInternals 4 | Description : showing Double values with mantissa and exponent 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Rounded arithmetic instances for Double. 13 | 14 | This is a private module reexported publicly via its parent. 15 | -} 16 | 17 | module Numeric.AERN.RealArithmetic.Basis.Double.ShowInternals where 18 | 19 | import Numeric.AERN.Basics.ShowInternals 20 | 21 | instance ShowInternals Double where 22 | type ShowInternalsIndicator Double = Bool 23 | defaultShowIndicator d = False 24 | showInternals True d = 25 | show d ++ "[" ++ show mantissa ++ "," ++ show exponent ++ "]" 26 | where 27 | (mantissa, exponent) = decodeFloat d 28 | showInternals False d = show d 29 | -------------------------------------------------------------------------------- /aern-double/src/Numeric/AERN/RealArithmetic/Basis/Double/SpecialConst.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.Double.SpecialConst 4 | Description : common constants such as pi 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Common constants such as pi. 13 | -} 14 | 15 | module Numeric.AERN.RealArithmetic.Basis.Double.SpecialConst where 16 | 17 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 18 | 19 | instance 20 | RoundedSpecialConstEffort Double 21 | where 22 | type SpecialConstEffortIndicator Double = () 23 | specialConstDefaultEffort _ = () 24 | 25 | instance 26 | RoundedSpecialConst Double 27 | where 28 | piUpEff _ _ = encodeFloat 7074237752028441 (-51) 29 | piDnEff _ _ = encodeFloat 7074237752028440 (-51) 30 | eUpEff _ _ = encodeFloat 6121026514868074 (-51) 31 | eDnEff _ _ = encodeFloat 6121026514868073 (-51) 32 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Basics/Laws/Relation.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Basics.Laws.Relation 3 | Description : common properties of relations 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Common properties of binary relations. 12 | -} 13 | module Numeric.AERN.Basics.Laws.Relation 14 | ( 15 | reflexive, transitive, symmetric, 16 | extrema 17 | ) 18 | where 19 | 20 | import Numeric.AERN.Misc.Bool 21 | 22 | --import qualified Algebra.Laws as NP -- numeric-prelude 23 | 24 | reflexive :: (t -> t -> Bool) -> t -> Bool 25 | reflexive (~~) e = 26 | e ~~ e == True 27 | 28 | symmetric :: (t -> t -> Bool) -> t -> t -> Bool 29 | symmetric (~~) e1 e2 = 30 | e1 ~~ e2 == e2 ~~ e1 31 | 32 | transitive :: (t -> t -> Bool) -> t -> t -> t -> Bool 33 | transitive (~~) e1 e2 e3 = 34 | ((e1 ~~ e2) && (e2 ~~ e3)) ===> (e1 ~~ e3) 35 | 36 | extrema (<=) bottom top e = 37 | bottom <= e && e <= top 38 | 39 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/RefinementOrder/Extrema.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RefinementOrder.Extrema 3 | Description : types that have top and bottom 4 | Copyright : (c) Michal Konecny, Jan Duracz 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Types that have top and bottom. 12 | 13 | This module is hidden and reexported via its parent RefinementOrder. 14 | -} 15 | module Numeric.AERN.RefinementOrder.Extrema where 16 | 17 | {-| 18 | A type with extrema. 19 | -} 20 | class (HasTop t, HasBottom t) => HasExtrema t 21 | 22 | {-| 23 | A type with a top element. 24 | -} 25 | class HasTop t where 26 | top :: t -> t 27 | 28 | {-| 29 | A type with a top element. 30 | -} 31 | class HasBottom t where 32 | bottom :: t -> t 33 | 34 | -- | Convenience Unicode notation for 'top' 35 | (⊤) :: (HasTop t) => t -> t 36 | (⊤) = top 37 | 38 | -- | Convenience Unicode notation for 'bottom' 39 | (⊥) :: (HasBottom t) => t -> t 40 | (⊥) = bottom 41 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR/SpecialConst.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst 4 | Description : common constants such as pi 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Common constants such as pi. 13 | -} 14 | 15 | module Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst where 16 | 17 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 18 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 19 | 20 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 21 | 22 | instance 23 | RoundedSpecialConstEffort MPFR 24 | where 25 | type SpecialConstEffortIndicator MPFR = MPFRPrec 26 | specialConstDefaultEffort sample = getPrecision sample 27 | 28 | instance 29 | RoundedSpecialConst MPFR 30 | where 31 | piUpEff prec _ = withPrec prec pi 32 | piDnEff prec _ = negate $ withPrecRoundDown prec (- pi) 33 | eUpEff prec _ = withPrec prec (exp 1) 34 | eDnEff prec _ = 1 /. (withPrec prec (exp (-1))) 35 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR/SpecialConst.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst 4 | Description : common constants such as pi 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Common constants such as pi. 13 | -} 14 | 15 | module Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst where 16 | 17 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Effort 18 | 19 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 20 | 21 | import qualified Data.Number.MPFR as M 22 | import Data.Number.MPFR (MPFR) 23 | import Data.Number.MPFR.Instances.Up 24 | 25 | instance 26 | RoundedSpecialConstEffort MPFR 27 | where 28 | type SpecialConstEffortIndicator MPFR = M.Precision 29 | specialConstDefaultEffort _ = 100 30 | 31 | instance 32 | RoundedSpecialConst MPFR 33 | where 34 | piUpEff prec _ = M.pi M.Up prec 35 | piDnEff prec _ = M.pi M.Down prec 36 | eUpEff prec _ = M.exp M.Up prec 1 37 | eDnEff prec _ = M.exp M.Down prec 1 38 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Utilities.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.Utilities 3 | Description : utilities for MPFR instances 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Utilities for MPFR instances. 12 | 13 | This is a hidden internal module. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Utilities where 17 | 18 | import qualified Data.Number.MPFR as M 19 | import Data.Number.MPFR (MPFR) 20 | import Data.Number.MPFR.Instances.Up 21 | 22 | import Numeric.AERN.Basics.Exception 23 | import Control.Exception 24 | 25 | detectNaNThrow :: String -> MPFR -> MPFR 26 | detectNaNThrow msg a 27 | | M.isNaN a = 28 | throw (AERNDomViolationException $ "domain violation in MPFR " ++ msg) 29 | | otherwise = a 30 | 31 | detectNaNUp :: String -> MPFR -> MPFR 32 | detectNaNUp _ a 33 | | M.isNaN a = 1/0 34 | | otherwise = a 35 | 36 | detectNaNDn :: String -> MPFR -> MPFR 37 | detectNaNDn _ a 38 | | M.isNaN a = -1/0 39 | | otherwise = a 40 | 41 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Utilities.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.Utilities 3 | Description : utilities for MPFR instances 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Utilities for MPFR instances. 12 | 13 | This is a hidden internal module. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Utilities where 17 | 18 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 19 | import Numeric.AERN.Basics.Exception 20 | import Control.Exception 21 | 22 | detectNaNThrow :: String -> MPFR -> MPFR 23 | detectNaNThrow msg a@(MPFR v) 24 | | isNaN v = 25 | throw (AERNDomViolationException $ "domain violation in MPFR " ++ msg) 26 | | otherwise = a 27 | 28 | detectNaNUp :: String -> MPFR -> MPFR 29 | detectNaNUp _ a@(MPFR v) 30 | | isNaN v = withPrec (getPrecision a) (1/0) 31 | | otherwise = a 32 | 33 | detectNaNDn :: String -> MPFR -> MPFR 34 | detectNaNDn _ a@(MPFR v) 35 | | isNaN v = withPrec (getPrecision a) (-1/0) 36 | | otherwise = a 37 | 38 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Effort.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.Effort 3 | Description : MPFR precision is an effort indicator 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | MPFR precision is an effort indicator. 12 | 13 | This is a private module reexported publicly via its parent. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Effort 17 | ( 18 | ) 19 | where 20 | 21 | import Numeric.AERN.Basics.Effort 22 | 23 | import qualified Data.Number.MPFR as M 24 | 25 | import Test.QuickCheck 26 | 27 | instance Arbitrary M.Precision where 28 | arbitrary = 29 | do 30 | p <- choose (10,1000) 31 | return (fromInteger $ toInteger (p :: Int)) 32 | 33 | instance EffortIndicator M.Precision where 34 | effortIncrementVariants p = [2*p + 1] 35 | effortRepeatIncrement (p1, p2) 36 | | p2 > 2*p1 = 2*p2 37 | | otherwise = p2 + (p2 - p1) 38 | effortIncrementSequence p = 39 | map (p +) fibsp2p 40 | where 41 | fibsp2p = scanl (+) p (p:fibsp2p) 42 | effortCombine = max 43 | 44 | 45 | -------------------------------------------------------------------------------- /aern-double/bench/Main.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : run all benchmarks defined in the AERN-Real package 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | -} 11 | module Main where 12 | 13 | import Numeric.AERN.RealArithmetic.Basis.Double 14 | import Numeric.AERN.RealArithmetic.Interval.Double 15 | import Numeric.AERN.RealArithmetic.Interval 16 | import Numeric.AERN.RealArithmetic.Interval.ElementaryFromFieldOps 17 | import Numeric.AERN.Basics.Interval 18 | 19 | import Numeric.AERN.Basics.Consistency 20 | import qualified Numeric.AERN.NumericOrder as NumOrd 21 | import qualified Numeric.AERN.RefinementOrder as RefOrd 22 | 23 | import Numeric.AERN.RealArithmetic.Measures 24 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 25 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 26 | 27 | import Numeric.AERN.Basics.Bench 28 | import Criterion.Main (defaultMain) 29 | import Criterion 30 | 31 | main = 32 | defaultMain -- With (criterionConfig "bench-Double" 20) $ 33 | [ 34 | ArithInOut.benchInOutExp ("DI", sampleDI) ArithInOut.benchExpAreasReal 35 | ] 36 | 37 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR/ShowInternals.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals 4 | Description : showing MPFR values with mantissa and exponent 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Rounded arithmetic instances for MPFR. 13 | 14 | This is a private module reexported publicly via its parent. 15 | -} 16 | 17 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals where 18 | 19 | import Numeric.AERN.Basics.ShowInternals 20 | 21 | import qualified Data.Number.MPFR as M 22 | import Data.Number.MPFR (MPFR) 23 | import Data.Number.MPFR.Instances.Up 24 | import qualified Data.Number.MPFR.Mutable as MM 25 | 26 | import Data.Word 27 | 28 | instance ShowInternals MPFR where 29 | type ShowInternalsIndicator MPFR = (Word, Bool) 30 | -- defaultShowIndicator d = (10000, True) 31 | defaultShowIndicator d = (40, False) 32 | showInternals (prec,True) d = 33 | M.toStringExp prec d ++ "[gran = " ++ show gran ++ "]" 34 | where 35 | gran = M.getPrec d 36 | showInternals (prec,False) d = M.toStringExp prec d 37 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR/ShowInternals.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals 4 | Description : showing MPFR values with mantissa and exponent 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Rounded arithmetic instances for MPFR. 13 | 14 | This is a private module reexported publicly via its parent. 15 | -} 16 | 17 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals where 18 | 19 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 20 | 21 | import Numeric.AERN.Basics.ShowInternals 22 | 23 | import Data.Word 24 | import Numeric (showGFloat) 25 | 26 | instance ShowInternals MPFR where 27 | type ShowInternalsIndicator MPFR = (Maybe Int, Bool) 28 | defaultShowIndicator d = (Just 40, False) 29 | showInternals (maybeDigits, shouldShowPrecision) d@(MPFR v) = 30 | floatS "" ++ precisionS 31 | where 32 | floatS = showGFloat maybeDigits v 33 | precisionS 34 | | shouldShowPrecision = "[prec = " ++ show gran ++ "]" 35 | | otherwise = "" 36 | gran = getPrecision d 37 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/NumericOrder.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.NumericOrder 3 | Description : classical and approximate lattices (<,max,min) 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Type classes representing classical as well as approximate 12 | Comparisons and lattices with the numerical order notation (<,max,min). 13 | 14 | This module is meant to be imported qualified. 15 | It is recommended to use the prefix NumOrd. 16 | -} 17 | module Numeric.AERN.NumericOrder 18 | ( 19 | module Numeric.AERN.NumericOrder.PartialComparison, 20 | module Numeric.AERN.NumericOrder.Arbitrary, 21 | module Numeric.AERN.NumericOrder.Arbitrary.Linear, 22 | module Numeric.AERN.NumericOrder.Extrema, 23 | module Numeric.AERN.NumericOrder.RoundedLattice, 24 | module Numeric.AERN.NumericOrder.RefinementRoundedLattice, 25 | ) 26 | where 27 | 28 | import Numeric.AERN.NumericOrder.PartialComparison 29 | import Numeric.AERN.NumericOrder.Arbitrary 30 | import Numeric.AERN.NumericOrder.Arbitrary.Linear 31 | import Numeric.AERN.NumericOrder.Extrema 32 | import Numeric.AERN.NumericOrder.RoundedLattice 33 | import Numeric.AERN.NumericOrder.RefinementRoundedLattice 34 | -------------------------------------------------------------------------------- /aern-double/demos/Riemann.hs: -------------------------------------------------------------------------------- 1 | 2 | module Main where 3 | 4 | import Numeric.AERN.DoubleBasis.RealIntervalApprox 5 | 6 | import Control.Monad.ST (ST, runST) 7 | 8 | type R = RealIntervalApprox 9 | type RI = RealIntervalApprox 10 | 11 | main = 12 | do 13 | putStrLn $ "riemann 0.1 (\\x -> x^2) (Interval 0 1) = " ++ 14 | show (riemann 0.1 (\x -> x^2) (0 1)) 15 | putStrLn "erf e x = 2/(sqrt pi) * riemann e (\\t -> exp (-t^2)) (0 x)" 16 | putStrLn $ "erf 0.001 1 = " ++ show (erf 0.001 1) 17 | 18 | -- compute the error function to within e accuracy 19 | erf :: R -> R -> R 20 | erf e x = 21 | 2/(sqrt piOut) * riemann e (\t -> exp (-t^2)) (0 x) 22 | 23 | -- compute the integral of f over d to within e accuracy 24 | riemann :: R -> (R -> R) -> RI -> R 25 | riemann e f d = 26 | riemann' e f (width d) [d] 0 27 | 28 | riemann' _ _ _ [] result = result 29 | riemann' e f initWidth (d:ds) result 30 | | reachedSufficientAccuracy = 31 | riemann' e f initWidth ds (dArea + result) 32 | | otherwise = 33 | riemann' e f initWidth (dl:dr:ds) result 34 | where 35 | reachedSufficientAccuracy = 36 | case dError True 38 | _ -> False 39 | dError = dWidth * (width fd) 40 | dArea = dWidth * fd 41 | fd = f d 42 | dWidth = width d 43 | (dl, dr) = bisect Nothing d 44 | 45 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/RefinementOrder.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RefinementOrder 3 | Description : classical and approximate domain bases and lattices (⊑⊑,⊓⊓,⊔⊔) 4 | Copyright : (c) Michal Konecny, Jan Duracz 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Type classes representing classical as well as approximate 12 | Comparisons, domain bases and lattices with the refinement order notation 13 | (⊑,⊓,⊔). 14 | 15 | This module is meant to be imported qualified. 16 | It is recommended to use the prefix RefOrd. 17 | -} 18 | module Numeric.AERN.RefinementOrder 19 | ( 20 | module Numeric.AERN.RefinementOrder.PartialComparison, 21 | module Numeric.AERN.RefinementOrder.Arbitrary, 22 | module Numeric.AERN.RefinementOrder.RoundedBasis, 23 | module Numeric.AERN.RefinementOrder.RoundedLattice, 24 | module Numeric.AERN.RefinementOrder.Extrema, 25 | module Numeric.AERN.RefinementOrder.IntervalLike, 26 | ) 27 | where 28 | 29 | import Numeric.AERN.RefinementOrder.PartialComparison 30 | import Numeric.AERN.RefinementOrder.Arbitrary 31 | import Numeric.AERN.RefinementOrder.RoundedBasis 32 | import Numeric.AERN.RefinementOrder.RoundedLattice 33 | import Numeric.AERN.RefinementOrder.Extrema 34 | import Numeric.AERN.RefinementOrder.IntervalLike 35 | -------------------------------------------------------------------------------- /aern-double/demos/Quadratic.hs: -------------------------------------------------------------------------------- 1 | 2 | module Main where 3 | 4 | import Numeric.AERN.DoubleBasis.RealApprox 5 | 6 | import Control.Monad.ST (runST) 7 | 8 | type R = RealApprox 9 | 10 | main = do 11 | putStrLn $ "quadratic 1 1 1 = " ++ show (quadratic 1 1 1) 12 | putStrLn $ "quadratic 1 2 1 = " ++ show (quadratic 1 2 1) 13 | putStrLn $ "quadratic 1 5 6 = " ++ show (quadratic 1 5 6) 14 | 15 | -- | 16 | -- Returns list such that the union of its members contains all 17 | -- real roots of each real polynomial u*x^2+v*x+w obtained by 18 | -- choosing coefficients u in a, v in b and w in c. 19 | quadratic :: R -> R -> R -> [R] 20 | quadratic a b c 21 | | certainlyZero discriminant = 22 | [doubleRoot] 23 | | certainlyNonnegative discriminant = 24 | [leftRoot,rightRoot] 25 | | certainlyNegative discriminant = 26 | [] 27 | | otherwise = 28 | [bottom] 29 | where 30 | discriminant = b^2-4*a*c 31 | doubleRoot = -b/(2*a) 32 | leftRoot = doubleRoot-sqrtDiscriminant/(2*a) -- (-b-sqrt(b^2-4*a*c))/(2*a) 33 | rightRoot = doubleRoot+sqrtDiscriminant/(2*a) -- (-b+sqrt(b^2-4*a*c))/(2*a) 34 | sqrtDiscriminant = sqrt discriminant 35 | 36 | 37 | certainlyZero x = 38 | case x ==? 0 of 39 | Just True -> True 40 | _ -> False 41 | 42 | certainlyNonnegative x = 43 | case x >=? 0 of 44 | Just True -> True 45 | _ -> False 46 | 47 | certainlyNegative x = 48 | case x True 50 | _ -> False 51 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR/ExactOps.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 3 | Description : one, zero, negation etc for MPFR numbers 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | One, zero, negation etc for MPFR numbers. 12 | 13 | This is a private module reexported publicly via its parent. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps where 17 | 18 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 19 | import Numeric.AERN.RealArithmetic.ExactOps 20 | 21 | import qualified Numeric.Rounded as R 22 | 23 | instance HasSampleFromContext MPFR where 24 | sampleFromContext = withPrec defaultPrecision 0 -- useless... 25 | 26 | instance HasZero MPFR where 27 | zero sample = withPrec (getPrecision sample) 0 28 | 29 | instance HasOne MPFR where 30 | one sample = withPrec (getPrecision sample) 1 31 | 32 | instance HasInfinities MPFR where 33 | plusInfinity sample = withPrec (getPrecision sample) $ 1/0 34 | minusInfinity sample = withPrec (getPrecision sample) $ -1/0 35 | excludesPlusInfinity a = (a /= plusInfinity a) 36 | excludesMinusInfinity a = (a /= minusInfinity a) 37 | 38 | instance Neg MPFR where 39 | neg = liftRoundedToMPFR1 negate 40 | 41 | 42 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR/ExactOps.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 3 | Description : one, zero, negation etc for MPFR numbers 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | One, zero, negation etc for MPFR numbers. 12 | 13 | This is a private module reexported publicly via its parent. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps where 17 | 18 | import Numeric.AERN.RealArithmetic.ExactOps 19 | 20 | import qualified Data.Number.MPFR as M 21 | import Data.Number.MPFR (MPFR) 22 | import Data.Number.MPFR.Instances.Up 23 | import qualified Data.Number.MPFR.Mutable as MM 24 | 25 | instance HasSampleFromContext MPFR where 26 | sampleFromContext = 0 27 | 28 | instance HasZero MPFR where 29 | zero sample = M.set M.Near (M.getPrec sample) 0 30 | 31 | instance HasOne MPFR where 32 | one sample = M.set M.Near (M.getPrec sample) 1 33 | 34 | instance HasInfinities MPFR where 35 | plusInfinity sample = M.set M.Near (M.getPrec sample) $ 1/0 36 | minusInfinity sample = M.set M.Near (M.getPrec sample) $ -1/0 37 | excludesPlusInfinity a = (a /= plusInfinity a) 38 | excludesMinusInfinity a = (a /= minusInfinity a) 39 | 40 | instance Neg MPFR where 41 | neg = negate 42 | 43 | 44 | -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/RealArithmetic/Auxiliary.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.Auxiliary 3 | Description : auxiliary generic operators and utilities 4 | Copyright : (c) Michal Konecny, Jan Duracz 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Auxiliary generic operators and utilities. 12 | 13 | This is a hidden internal module. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Auxiliary where 17 | 18 | import Numeric.AERN.RealArithmetic.ExactOps 19 | import Numeric.AERN.Basics.Exception 20 | 21 | import Control.Exception 22 | import Control.Monad.ST 23 | 24 | 25 | powerFromMult :: 26 | t {-^ unit of @*@ -} -> 27 | (t -> t -> t) {-^ associative binary operation @*@ -} -> 28 | t {-^ @x@ -} -> 29 | Int {-^ @n@ positive -} -> 30 | t {-^ product @x * x * ... * x@ of @n@ copies of @x@ -} 31 | powerFromMult one mult x n 32 | | n < 0 = throw $ AERNException "powerFromMult does not support negative exponents" 33 | | otherwise = p n 34 | where 35 | p n 36 | | n == 0 = one 37 | | n == 1 = x 38 | | otherwise = 39 | case even n of 40 | True -> 41 | powHalf `mult` powHalf 42 | False -> 43 | x `mult` (powHalf `mult` powHalf) 44 | where 45 | powHalf = p (n `div` 2) 46 | 47 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Elementary.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary 4 | Description : rounded elementary ops based on MPFR 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Rounded elementary ops based on MPFR. 13 | 14 | This is a private module reexported publicly via its parent. 15 | -} 16 | 17 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary 18 | () 19 | where 20 | 21 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Effort 22 | 23 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 24 | 25 | import qualified Data.Number.MPFR as M 26 | import Data.Number.MPFR (MPFR) 27 | import Data.Number.MPFR.Instances.Up () 28 | 29 | instance RoundedExponentiationEffort MPFR where 30 | type ExpEffortIndicator MPFR = () 31 | expDefaultEffort _ = () 32 | 33 | instance RoundedExponentiation MPFR where 34 | expUpEff _ d1 = 35 | M.exp M.Up (M.getPrec d1) d1 36 | expDnEff _ d1 = 37 | M.exp M.Down (M.getPrec d1) d1 38 | 39 | instance RoundedSquareRootEffort MPFR where 40 | type SqrtEffortIndicator MPFR = () 41 | sqrtDefaultEffort _ = () 42 | 43 | instance RoundedSquareRoot MPFR where 44 | sqrtUpEff _ d1 = 45 | M.sqrt M.Up (M.getPrec d1) d1 46 | sqrtDnEff _ d1 = 47 | M.sqrt M.Down (M.getPrec d1) d1 48 | 49 | 50 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Elementary.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary 4 | Description : rounded elementary ops based on MPFR 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Rounded elementary ops based on MPFR. 13 | 14 | This is a private module reexported publicly via its parent. 15 | -} 16 | 17 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary 18 | () 19 | where 20 | 21 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 22 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 23 | 24 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 25 | import Numeric.AERN.RealArithmetic.NumericOrderRounding.Operators 26 | 27 | instance RoundedExponentiationEffort MPFR where 28 | type ExpEffortIndicator MPFR = () 29 | expDefaultEffort _ = () 30 | 31 | instance RoundedExponentiation MPFR where 32 | expUpEff _ d1 = 33 | liftRoundedToMPFR1 exp d1 34 | expDnEff _ d1 = 35 | 1 /. (liftRoundedToMPFR1 exp (-d1)) 36 | 37 | instance RoundedSquareRootEffort MPFR where 38 | type SqrtEffortIndicator MPFR = () 39 | sqrtDefaultEffort _ = () 40 | 41 | instance RoundedSquareRoot MPFR where 42 | sqrtUpEff _ d1 = 43 | liftRoundedToMPFR1 sqrt d1 44 | sqrtDnEff _ d1 = 45 | 1 /. (liftRoundedToMPFR1 sqrt (1 /^ d1)) 46 | 47 | 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Michal Konecny 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /aern-double/demos/Zero.hs: -------------------------------------------------------------------------------- 1 | 2 | module Main where 3 | 4 | import Numeric.AERN.DoubleBasis.RealIntervalApprox 5 | import Numeric.AERN.DoubleBasis.MRealIntervalApprox 6 | 7 | import Control.Monad.ST (ST, runST) 8 | 9 | type RI = RealIntervalApprox 10 | 11 | main = 12 | do 13 | putStrLn $ "zero 0.1 (\\x -> x^2-0.5) (1 2) = " ++ 14 | show (zero 0.1 (\x -> x^2-0.5) (1 2)) 15 | putStrLn $ "zero 0.1 (\\x -> x^2-0.5) (0 1) = " ++ 16 | show (zero 0.1 (\x -> x^2-0.5) (0 1)) 17 | putStrLn $ "zero 0.01 (\\x -> x^2-0.5) (0 1) = " ++ 18 | show (zero 0.01 (\x -> x^2-0.5) (0 1)) 19 | putStrLn $ "zero 0.001 (\\x -> x^2-0.5) (0 1) = " ++ 20 | show (zero 0.001 (\x -> x^2-0.5) (0 1)) 21 | 22 | -- find leftmost zero of f in d to within e accuracy 23 | zero :: RI -> (RI -> RI) -> RI -> Maybe RI 24 | zero e f d = 25 | zero' e f [d] 26 | zero' :: RI -> (RI -> RI) -> [RI] -> Maybe RI 27 | zero' _ _ [] = Nothing 28 | zero' e f (d:ds) 29 | | imageContainsZero == Just False = 30 | zero' e f ds 31 | | imageContainsZero == Just True && reachedSufficientAccuracy = 32 | Just d 33 | | cannotSplit = 34 | error $ "zero: cannot split interval " ++ show d 35 | | otherwise = 36 | zero' e f (dl:dr:ds) 37 | where 38 | cannotSplit = (dl |==? d) == Just True || (dr |==? d) == Just True 39 | imageContainsZero = fd |<=? 0 40 | reachedSufficientAccuracy = 41 | case width fd True 43 | _ -> False 44 | (dl,dr) = bisect Nothing d 45 | fd = f d 46 | 47 | 48 | -------------------------------------------------------------------------------- /aern-double/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-fnreps/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-ivp/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-mpfr/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-order/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-poly/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-real/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-realfn/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-interval/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Basics/Laws/PartialRelation.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Basics.Laws.PartialRelation 3 | Description : common properties of partial relations 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Common properties of partial relations. 12 | -} 13 | module Numeric.AERN.Basics.Laws.PartialRelation 14 | ( 15 | partialReflexive, partialTransitive, partialSymmetric, 16 | partialOrderExtrema 17 | ) 18 | where 19 | 20 | import Numeric.AERN.Misc.Bool 21 | import Numeric.AERN.Misc.Maybe 22 | import Numeric.AERN.Basics.Laws.Operation 23 | import Numeric.AERN.Basics.Laws.Relation 24 | import Data.Maybe (isNothing) 25 | 26 | --import qualified Algebra.Laws as NP -- numeric-prelude 27 | 28 | partialReflexive :: (t -> t -> Maybe Bool) -> t -> Bool 29 | partialReflexive (~~?) e = 30 | trueOrNothing $ e ~~? e 31 | 32 | 33 | partialTransitive :: (t -> t -> Maybe Bool) -> t -> t -> t -> Bool 34 | partialTransitive (~~?) e1 e2 e3 = 35 | (and $ map defined [e1 ~~? e2, e2 ~~? e3, e1 ~~? e3]) ===> 36 | transitive (assumeTotal2 (~~?)) e1 e2 e3 37 | 38 | partialSymmetric :: (t -> t -> Maybe Bool) -> t -> t -> Bool 39 | partialSymmetric (~~?) e1 e2 = 40 | (and $ map defined [e1 ~~? e2, e2 ~~? e1]) ===> 41 | symmetric (assumeTotal2 (~~?)) e1 e2 42 | 43 | partialOrderExtrema (<=?) bottom top e = 44 | (trueOrNothing $ bottom <=? e) 45 | && 46 | (trueOrNothing $ e <=? top) 47 | -------------------------------------------------------------------------------- /aern-poly-plot-gtk/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-realfn-plot-gtk/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Michal Konecny 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-temp/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Michal Konecny, Eike Neumann 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the author nor the names of his contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 21 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Misc/Debug.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Misc.Debug 3 | Description : miscellaneous debugging functions 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Miscellaneous debugging functions. 12 | -} 13 | 14 | module Numeric.AERN.Misc.Debug where 15 | 16 | import System.IO.Unsafe 17 | 18 | unsafePrint msg val = 19 | unsafePerformIO $ 20 | do 21 | putStrLn $ "unsafe: " ++ msg 22 | return val 23 | 24 | unsafePrintReturn msg a = 25 | unsafePrint (msg ++ show a) a 26 | 27 | {-| Like 'and' except each boolean parameter has a message 28 | associated with it and if one of the parameters 29 | is false, its message is unsafely printed to the console. 30 | -} 31 | andUnsafeReportFirstFalse :: [(Bool, String)] -> Bool 32 | andUnsafeReportFirstFalse [] = True 33 | andUnsafeReportFirstFalse ((True, _) : rest) = andUnsafeReportFirstFalse rest 34 | andUnsafeReportFirstFalse ((False, msg) : _) = 35 | unsafePrint msg False 36 | 37 | {-| Like 'or' except each parameter has a message 38 | associated with it and if all of the parameters 39 | are false, all their messages are unsafely printed to the console. 40 | -} 41 | orUnsafeReportFalse :: [(Bool, String)] -> Bool 42 | orUnsafeReportFalse boolMsgList 43 | | notAllFalse = True 44 | | otherwise = 45 | unsafePrint allMessages False 46 | where 47 | notAllFalse = or boolList 48 | allMessages = unlines $ messageList 49 | (boolList, messageList) = unzip boolMsgList 50 | -------------------------------------------------------------------------------- /aern-fnreps/aern-fnreps.cabal: -------------------------------------------------------------------------------- 1 | Name: aern-fnreps 2 | Version: 0.5.0 3 | Cabal-Version: >= 1.8 4 | Build-Type: Simple 5 | License: BSD3 6 | License-File: LICENCE 7 | Author: Michal Konecny, Eike Neumann (Aston University) 8 | Copyright: (c) 2015 Michal Konecny, Eike Neumann 9 | Maintainer: mikkonecny@gmail.com 10 | Homepage: http://code.google.com/p/aern/ 11 | Stability: experimental 12 | Category: Data, Math 13 | Synopsis: compare real function representations 14 | Tested-with: GHC==7.8.4 15 | Description: Define and compare various representations of univariate continuous real functions. 16 | 17 | Library 18 | hs-source-dirs: src 19 | ghc-options: -Wall -rtsopts 20 | Build-Depends: 21 | base >= 4.4, 22 | containers >= 0.3, 23 | aern-order == 0.5.*, 24 | aern-real == 0.5.*, 25 | aern-interval == 0.5.*, 26 | aern-double == 0.5.*, 27 | unordered-containers, 28 | arithmoi 29 | exposed-modules: FnReps.FunctionAbstraction 30 | other-modules: 31 | FnReps.Polynomial.UnaryChebSparse, 32 | FnReps.Polynomial.UnaryChebSparse.DCTMultiplication 33 | 34 | executable fnreps 35 | Build-Depends: 36 | base >= 4.4, 37 | containers >= 0.3, 38 | aern-order == 0.5.*, 39 | aern-real == 0.5.*, 40 | aern-interval == 0.5.*, 41 | aern-mpfr-rounded == 0.5.*, 42 | unordered-containers, 43 | arithmoi 44 | hs-source-dirs: src 45 | ghc-options: -Wall -rtsopts 46 | main-is: Main.hs 47 | other-modules: FnReps.Polynomial.UnaryChebSparse.DCTMultiplication 48 | 49 | 50 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Misc/Maybe.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Misc.Maybe 3 | Description : utilities for partial predicates and partial operations 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Utilities for partial predicates and partial operations. 12 | -} 13 | module Numeric.AERN.Misc.Maybe where 14 | 15 | import Data.Maybe 16 | 17 | defined :: (Maybe t) -> Bool 18 | defined = isJust 19 | 20 | assumeTotal1 :: (t1 -> Maybe t) -> (t1 -> t) 21 | assumeTotal1 f a = 22 | case f a of Just res -> res 23 | 24 | assumeTotal2 :: (t2 -> t1 -> Maybe t) -> (t2 -> t1 -> t) 25 | assumeTotal2 f a b = 26 | case f a b of Just res -> res 27 | 28 | completeWith :: t -> (t2 -> t1 -> Maybe t) -> (t2 -> t1 -> t) 29 | completeWith e (*?) e2 e1 = 30 | case e2 *? e1 of Just r -> r; Nothing -> e 31 | 32 | trueOrNothing :: Maybe Bool -> Bool 33 | trueOrNothing = nothingOr True 34 | 35 | falseOrNothing :: Maybe Bool -> Bool 36 | falseOrNothing = nothingOr False 37 | 38 | nothingOr :: (Eq a) => a -> Maybe a -> Bool 39 | nothingOr _ Nothing = True 40 | nothingOr e1 (Just e2) = e1 == e2 41 | 42 | justButNot :: (Eq a) => a -> Maybe a -> Bool 43 | justButNot _ Nothing = False 44 | justButNot e1 (Just e2) = e1 /= e2 45 | 46 | (||?) :: Maybe Bool -> Maybe Bool -> Maybe Bool 47 | (||?) b1@(Just True) _ = b1 48 | (||?) _ b2@(Just True) = b2 49 | (||?) b1@(Just False) b2@(Just False) = b1 50 | (||?) _ _ = Nothing 51 | 52 | (&&?) :: Maybe Bool -> Maybe Bool -> Maybe Bool 53 | (&&?) b1@(Just False) _ = b1 54 | (&&?) _ b2@(Just False) = b2 55 | (&&?) b1@(Just True) b2@(Just True) = b1 56 | (&&?) _ _ = Nothing 57 | 58 | -------------------------------------------------------------------------------- /aern-realfn-plot-gtk/aern-realfn-plot-gtk.cabal: -------------------------------------------------------------------------------- 1 | Name: aern-realfn-plot-gtk 2 | Version: 0.5.0 3 | Cabal-Version: >= 1.8 4 | Build-Type: Simple 5 | License: BSD3 6 | License-File: LICENCE 7 | Author: Michal Konecny 8 | Copyright: (c) 2012 Michal Konecny 9 | Maintainer: mikkonecny@gmail.com 10 | Homepage: http://code.google.com/p/aern/ 11 | Stability: experimental 12 | Category: Data, Math 13 | Synopsis: cairo/gtk plotting of real function approximations 14 | Tested-with: GHC==7.6.3 15 | Description: 16 | A type class for cairo-plottable real function approximations 17 | and a gtk widget for plotting and interactively inspecting 18 | graphs of such approximations. 19 | 20 | Extra-Source-Files: 21 | FnView.glade 22 | 23 | Library 24 | hs-source-dirs: src 25 | Build-Depends: 26 | base >= 4.4, 27 | containers >= 0.3, 28 | gtk >= 0.12.0, 29 | cairo >= 0.12.0, 30 | stm >= 2.1.2.1, 31 | filepath >= 1.1.0.4, 32 | directory >= 1.0.1.1, 33 | aern-order == 0.5.*, 34 | aern-real == 0.5.*, 35 | aern-interval == 0.5.*, 36 | aern-realfn == 0.5.* 37 | exposed-modules: 38 | Numeric.AERN.RmToRn.Plot.Simple 39 | Numeric.AERN.RmToRn.Plot.Params 40 | Numeric.AERN.RmToRn.Plot.CairoDrawable 41 | Numeric.AERN.RmToRn.Plot.FromEval 42 | Numeric.AERN.RmToRn.Plot.FnView 43 | Numeric.AERN.RmToRn.Plot.FnView.New 44 | Numeric.AERN.RmToRn.Plot.FnView.FnData 45 | Numeric.AERN.RmToRn.Plot.FnView.State 46 | Numeric.AERN.RmToRn.Plot.FnView.Layout 47 | Numeric.AERN.RmToRn.Plot.FnView.WatchData 48 | Numeric.AERN.RmToRn.Plot.FnView.Canvas 49 | ghc-options: -Wall 50 | -------------------------------------------------------------------------------- /aern-double/src/Numeric/AERN/RealArithmetic/Basis/Double/Measures.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE UndecidableInstances #-} 3 | {-| 4 | Module : Numeric.AERN.RealArithmetic.Basis.Double.Measures 5 | Description : distance between Double numbers 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Distance between Double numbers. 14 | 15 | This is a private module reexported publicly via its parent. 16 | -} 17 | 18 | module Numeric.AERN.RealArithmetic.Basis.Double.Measures where 19 | 20 | import Numeric.AERN.RealArithmetic.Basis.Double.NumericOrder 21 | import Numeric.AERN.RealArithmetic.Basis.Double.FieldOps 22 | 23 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 24 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 25 | import Numeric.AERN.RealArithmetic.ExactOps 26 | import Numeric.AERN.RealArithmetic.Measures 27 | import Numeric.AERN.RealArithmetic.Interval.Double 28 | 29 | import Numeric.AERN.Basics.Interval 30 | 31 | instance HasDistance Double where 32 | type Distance Double = DI 33 | type DistanceEffortIndicator Double = ArithInOut.AddEffortIndicator DI 34 | distanceDefaultEffort d = ArithInOut.addDefaultEffort (sampleDI :: DI) 35 | distanceBetweenEff effort d1 d2 = 36 | -- | d1 == 1/0 && d2 == 1/0 = zero 37 | -- -- distance between two infinities is zero (beware: distance not continuous at infinities!) 38 | -- | d1 == -1/0 && d2 == -1/0 = zero 39 | -- | otherwise = 40 | ArithInOut.absOut (d2I <-> d1I) 41 | where 42 | d1I = Interval d1 d1 43 | d2I = Interval d2 d2 44 | -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/RealArithmetic/NumericOrderRounding/SpecialConst.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-| 4 | Module : Numeric.AERN.RealArithmetic.NumericOrderRounding.SpecialConst 5 | Description : support for common constants such as pi 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Support for common constants such as pi. 14 | 15 | This module is hidden and reexported via its parent NumericOrderRounding. 16 | -} 17 | 18 | module Numeric.AERN.RealArithmetic.NumericOrderRounding.SpecialConst where 19 | 20 | import Numeric.AERN.Basics.Effort 21 | 22 | class 23 | (EffortIndicator (SpecialConstEffortIndicator t)) 24 | => 25 | RoundedSpecialConstEffort t 26 | where 27 | type SpecialConstEffortIndicator t 28 | specialConstDefaultEffort :: t -> SpecialConstEffortIndicator t 29 | 30 | class (RoundedSpecialConstEffort t) => RoundedSpecialConst t where 31 | piUpEff :: (SpecialConstEffortIndicator t) -> t -> t 32 | piDnEff :: (SpecialConstEffortIndicator t) -> t -> t 33 | eUpEff :: (SpecialConstEffortIndicator t) -> t -> t 34 | eDnEff :: (SpecialConstEffortIndicator t) -> t -> t 35 | 36 | piUp :: (RoundedSpecialConst t) => t -> t 37 | piUp sample = piUpEff (specialConstDefaultEffort sample) sample 38 | 39 | piDn :: (RoundedSpecialConst t) => t -> t 40 | piDn sample = piDnEff (specialConstDefaultEffort sample) sample 41 | 42 | eUp :: (RoundedSpecialConst t) => t -> t 43 | eUp sample = eUpEff (specialConstDefaultEffort sample) sample 44 | 45 | eDn :: (RoundedSpecialConst t) => t -> t 46 | eDn sample = eDnEff (specialConstDefaultEffort sample) sample 47 | 48 | -------------------------------------------------------------------------------- /aern-interval/src/Numeric/AERN/RealArithmetic/Interval/ExactOps.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.Interval.ExactOps 3 | Description : exact zero, one and neg for intervals 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Exact zero, one and neg for intervals. 12 | 13 | This module is hidden and reexported via its parent Interval. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Interval.ExactOps 17 | () 18 | where 19 | 20 | import Numeric.AERN.Basics.Interval 21 | import qualified Numeric.AERN.NumericOrder as NumOrd 22 | import Numeric.AERN.RealArithmetic.ExactOps 23 | 24 | instance (HasSampleFromContext e) => HasSampleFromContext (Interval e) where 25 | sampleFromContext = Interval sampleE sampleE 26 | where 27 | sampleE = sampleFromContext 28 | 29 | instance (HasZero e, NumOrd.PartialComparison e) => HasZero (Interval e) where 30 | zero (Interval sampleE _) = Interval z z 31 | where 32 | z = zero sampleE 33 | 34 | instance (HasOne e) => HasOne (Interval e) where 35 | one (Interval sampleE _) = Interval o o 36 | where 37 | o = one sampleE 38 | 39 | instance (HasInfinities e) => HasInfinities (Interval e) where 40 | plusInfinity (Interval sampleE _) = Interval i i 41 | where 42 | i = plusInfinity sampleE 43 | minusInfinity (Interval sampleE _) = Interval i i 44 | where 45 | i = minusInfinity sampleE 46 | excludesPlusInfinity (Interval l r) = excludesPlusInfinity r 47 | excludesMinusInfinity (Interval l r) = excludesMinusInfinity l 48 | 49 | instance (Neg e) => Neg (Interval e) where 50 | neg (Interval l r) = Interval (neg r) (neg l) 51 | 52 | -------------------------------------------------------------------------------- /aern-fnreps/src/FnReps/Polynomial/UnaryChebSparse.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedLists #-} 2 | 3 | module FnReps.Polynomial.UnaryChebSparse where 4 | 5 | import FnReps.Polynomial.UnaryChebSparse.DCTMultiplication 6 | 7 | --import Numeric.AERN.MPFRBasis.Interval 8 | import Numeric.AERN.DoubleBasis.Interval () 9 | 10 | import qualified Data.HashMap.Strict as HM 11 | 12 | {-| 13 | Unary polynomials over the domain [-1,1] with interval coefficients in the Chebyshev basis. 14 | The interval coefficients are supposed to have a very small width. 15 | -} 16 | data UnaryChebSparse = 17 | UnaryChebSparse 18 | { 19 | unaryChebSparse_terms :: HM.HashMap Int RA 20 | } 21 | -- deriving (Show) 22 | 23 | instance Show UnaryChebSparse where 24 | show (UnaryChebSparse terms) = 25 | "(UnaryChebSparse " ++ show (HM.toList terms) ++ ")" 26 | 27 | instance Eq UnaryChebSparse where 28 | (==) = error "cannot compare UnaryChebSparse interval polynomials for equality, please use ==? instead of == etc." 29 | 30 | instance Ord UnaryChebSparse where 31 | compare = error "cannot compare UnaryChebSparse interval polynomials for equality, please use >? instead of > etc." 32 | 33 | instance Num UnaryChebSparse where 34 | fromInteger n = UnaryChebSparse (HM.singleton 0 (fromInteger n)) 35 | abs _ = error $ "abs not implemented for UnaryChebSparse interval polynomials." 36 | signum _ = error $ "signum not implemented for UnaryChebSparse interval polynomials." 37 | negate (UnaryChebSparse terms) = 38 | UnaryChebSparse $ fmap negate terms 39 | (UnaryChebSparse termsL) + (UnaryChebSparse termsR) = 40 | UnaryChebSparse $ HM.unionWith (+) termsL termsR 41 | (UnaryChebSparse terms1) * (UnaryChebSparse terms2) = 42 | UnaryChebSparse $ multiplyDCT_terms terms1 terms2 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Basics/Laws/Utilities.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Basics.Laws.Utilities 3 | Description : utilities for easier definitions of algebraic laws 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Utilities for easier definitions of algebraic laws. 12 | -} 13 | module Numeric.AERN.Basics.Laws.Utilities where 14 | 15 | import Numeric.AERN.Basics.Effort 16 | 17 | type Expr1 t = t -> t 18 | type Expr2 t = t -> t -> t 19 | type Expr3 t = t -> t -> t -> t 20 | 21 | type Expr1Eff ei t = ei -> t -> t 22 | type Expr2Eff ei t = ei -> t -> t -> t 23 | type Expr3Eff ei t = ei -> t -> t -> t -> t 24 | 25 | type UnaryOp t = t -> t 26 | type Op t = t -> t -> t 27 | type PartOp t = t -> t -> Maybe t 28 | 29 | type UnaryOpEff ei t = ei -> t -> t 30 | type OpEff ei t = ei -> t -> t -> t 31 | type PartOpEff ei t = ei -> t -> t -> Maybe t 32 | 33 | type Rel t = t -> t -> Bool 34 | type PRel t = t -> t -> Maybe Bool 35 | type PRelEff ei t = ei -> t -> t -> Maybe Bool 36 | 37 | type Expr1Op1 t = (Op t) -> Expr1 t 38 | type Expr1Op2 t = (Op t) -> Expr2 t 39 | type Expr1Op3 t = (Op t) -> Expr3 t 40 | type Expr2Op1 t = (Op t) -> (Op t) -> Expr1 t 41 | type Expr2Op2 t = (Op t) -> (Op t) -> Expr2 t 42 | type Expr2Op3 t = (Op t) -> (Op t) -> Expr3 t 43 | 44 | type Expr1UnaryOp1Eff ei t = (UnaryOpEff ei t) -> Expr1Eff ei t 45 | type Expr1Op1Eff ei t = (OpEff ei t) -> Expr1Eff ei t 46 | type Expr1Op2Eff ei t = (OpEff ei t) -> Expr2Eff ei t 47 | type Expr1Op3Eff ei t = (OpEff ei t) -> Expr3Eff ei t 48 | type Expr2Op1Eff ei1 ei2 t = (OpEff ei1 t) -> (OpEff ei2 t) -> Expr1Eff (ei1, ei2) t 49 | type Expr2Op2Eff ei1 ei2 t = (OpEff ei1 t) -> (OpEff ei2 t) -> Expr2Eff (ei1, ei2) t 50 | type Expr2Op3Eff ei1 ei2 t = (OpEff ei1 t) -> (OpEff ei2 t) -> Expr3Eff (ei1, ei2) t 51 | -------------------------------------------------------------------------------- /aern-interval/src/Numeric/AERN/RealArithmetic/Interval/SpecialConst.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE UndecidableInstances #-} 3 | {-# LANGUAGE FlexibleContexts #-} 4 | {-| 5 | Module : Numeric.AERN.RealArithmetic.Interval.SpecialConst 6 | Description : common constants such as pi 7 | Copyright : (c) Michal Konecny 8 | License : BSD3 9 | 10 | Maintainer : mikkonecny@gmail.com 11 | Stability : experimental 12 | Portability : portable 13 | 14 | Common constants such as pi. 15 | 16 | This module is hidden and reexported via its parent Interval. 17 | -} 18 | 19 | module Numeric.AERN.RealArithmetic.Interval.SpecialConst 20 | () 21 | where 22 | 23 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 24 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 25 | 26 | import Numeric.AERN.Basics.Interval 27 | 28 | instance (ArithUpDn.RoundedSpecialConstEffort e) => 29 | (ArithInOut.RoundedSpecialConstEffort (Interval e)) 30 | where 31 | type SpecialConstEffortIndicator (Interval e) = 32 | ArithUpDn.SpecialConstEffortIndicator e 33 | specialConstDefaultEffort (Interval l r) = 34 | ArithUpDn.specialConstDefaultEffort l 35 | 36 | instance (ArithUpDn.RoundedSpecialConst e) => 37 | (ArithInOut.RoundedSpecialConst (Interval e)) 38 | where 39 | piInEff effort (Interval sample _) = 40 | Interval (ArithUpDn.piUpEff effort sample) (ArithUpDn.piDnEff effort sample) 41 | piOutEff effort (Interval sample _) = 42 | Interval (ArithUpDn.piDnEff effort sample) (ArithUpDn.piUpEff effort sample) 43 | eInEff effort (Interval sample _) = 44 | Interval (ArithUpDn.eUpEff effort sample) (ArithUpDn.eDnEff effort sample) 45 | eOutEff effort (Interval sample _) = 46 | Interval (ArithUpDn.eDnEff effort sample) (ArithUpDn.eUpEff effort sample) 47 | 48 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Measures.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE UndecidableInstances #-} 3 | {-| 4 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.Measures 5 | Description : distance between MPFR numbers 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Distance between MPFR numbers. 14 | 15 | This is a private module reexported publicly via its parent. 16 | -} 17 | 18 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Measures where 19 | 20 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 21 | import Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder 22 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 23 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 24 | 25 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 26 | import Numeric.AERN.RealArithmetic.ExactOps 27 | import Numeric.AERN.RealArithmetic.Measures 28 | import Numeric.AERN.RealArithmetic.Interval 29 | import Numeric.AERN.RealArithmetic.Interval.MPFR 30 | 31 | import Numeric.AERN.Basics.Interval 32 | 33 | instance HasDistance MPFR where 34 | type Distance MPFR = MI 35 | type DistanceEffortIndicator MPFR = ArithInOut.AddEffortIndicator MI 36 | distanceDefaultEffort d = ArithInOut.addDefaultEffort (Interval d d) 37 | distanceBetweenEff effort d1 d2 = 38 | -- | d1 == 1/0 && d2 == 1/0 = zero 39 | -- -- distance between two infinities is zero (beware: distance not continuous at infinities!) 40 | -- | d1 == -1/0 && d2 == -1/0 = zero 41 | -- | otherwise = 42 | ArithInOut.absOut (d2I <-> d1I) 43 | where 44 | d1I = Interval d1 d1 45 | d2I = Interval d2 d2 46 | (<->) = ArithInOut.subtrOutEff effort 47 | -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/Misc/IntegerArithmetic.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Misc.IntegerArithmetic 3 | Description : miscellaneous integer arithmetic functions 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Miscellaneous integer arithmetic functions. 12 | -} 13 | 14 | module Numeric.AERN.Misc.IntegerArithmetic where 15 | 16 | intLogDown b n = fst $ intLog b n 17 | intLogUp b n = snd $ intLog b n 18 | 19 | intLog :: 20 | (Show n1, Num n1, Num n2, Ord n1, Integral n2) => 21 | n1 {-^ base -} -> 22 | n1 {-^ x -} -> 23 | (n2, n2) 24 | intLog b n 25 | | n == 1 = (0,0) 26 | | n > 1 && n < b = (0,1) 27 | | n >= b = 28 | bisect (lgDn, pwDn) (lgUp, pwUp) 29 | | otherwise = 30 | error $ "Numeric.ER.Misc: intLog: illegal argument n = " ++ show n 31 | where 32 | ((lgDn, pwDn), (lgUp, pwUp)) = 33 | findBounds (1, b) 34 | -- lgDn <= log_b n < lgUp; pwDn = b^lgDn; pwUp = b^lgUp 35 | findBounds (lg, pw) 36 | | n < pwNext = ((lg, pw), (lgNext, pwNext)) 37 | | otherwise = findBounds (lgNext, pwNext) 38 | where 39 | lgNext = 2 * lg 40 | pwNext = pw * pw 41 | bisect (lgDn, pwDn) (lgUp, pwUp) 42 | | pwDn == n = (lgDn, lgDn) 43 | | pwUp == n = (lgUp, lgUp) 44 | | lgDn == lgMid = (lgDn, lgUp) 45 | | lgUp == lgMid = (lgDn, lgUp) 46 | | n < pwMid = 47 | bisect (lgDn, pwDn) (lgMid, pwMid) 48 | | otherwise = 49 | bisect (lgMid, pwMid) (lgUp, pwUp) 50 | where 51 | lgMid = (lgDn + lgUp) `div` 2 52 | pwMid = pwDn * (b ^ (lgMid - lgDn)) 53 | 54 | binomial :: 55 | (Integral n) => 56 | n -> n -> n 57 | binomial n p | p >= 0 = 58 | (product [(n-p+1)..n]) 59 | `div` 60 | (product [1..p]) 61 | 62 | -------------------------------------------------------------------------------- /aern-temp/benchmarks/FnRepComparison/runFnRepComparison.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE DefaultSignatures, FlexibleInstances, UndecidableInstances #-} 3 | {-# LANGUAGE IncoherentInstances #-} 4 | module Main where 5 | 6 | import FunctionAbstraction 7 | 8 | import Numeric.AERN.MPFRBasis.Interval 9 | 10 | main :: IO () 11 | main = 12 | do 13 | putStrLn "runFnRepComparison not implemented yet" 14 | 15 | zeroUsingTrisection :: 16 | (RF fn) 17 | => 18 | fn -> 19 | Rational -> 20 | Rational -> 21 | R 22 | zeroUsingTrisection fn lOrig rOrig n = 23 | trisect lOrig rOrig initialPrecision 24 | where 25 | initialPrecision = 100 26 | trisect l r prec 27 | | resPreciseEnough = res 28 | | sign1 * sign2 < 0 = trisect m1 m2 prec 29 | | sign0 * sign1 < 0 = trisect l m1 prec 30 | | sign0 * sign2 < 0 = trisect l m2 prec 31 | | sign1 * sign3 < 0 = trisect m1 r prec 32 | | sign2 * sign3 < 0 = trisect m2 r prec 33 | | otherwise = trisect l r (2*prec) 34 | where 35 | res = p0 <\/> p3 36 | resPreciseEnough = (width res <=? 2^^(-n)) == Just True 37 | p0 = fromRationalWithPrec prec l 38 | p1 = fromRationalWithPrec prec m1 39 | p2 = fromRationalWithPrec prec m2 40 | p3 = fromRationalWithPrec prec r 41 | m1 = (l * 0.25) + (r * 0.75) 42 | m2 = (l * 0.75) + (r * 0.25) 43 | [value0, value1, value2, value3] = map (evalMI fn) [p0,p1,p2,p3] 44 | [sign0, sign1, sign2, sign3] = map getPseudoSign [value0,value1,value2,value3] 45 | where 46 | getPseudoSign :: MI -> Int 47 | getPseudoSign v = 48 | case (v 1 50 | (_, Just True) -> -1 51 | _ -> 0 52 | 53 | 54 | 55 | --preciseNearby :: MI -> MI 56 | --preciseNearby mi = 57 | -- fst $ getEndpoints mi -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Measures.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE UndecidableInstances #-} 3 | {-| 4 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR.Measures 5 | Description : distance between MPFR numbers 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Distance between MPFR numbers. 14 | 15 | This is a private module reexported publicly via its parent. 16 | -} 17 | 18 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Measures where 19 | 20 | import Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder 21 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 22 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 23 | 24 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 25 | import Numeric.AERN.RealArithmetic.ExactOps 26 | import Numeric.AERN.RealArithmetic.Measures 27 | import Numeric.AERN.RealArithmetic.Interval 28 | import Numeric.AERN.RealArithmetic.Interval.MPFR 29 | 30 | import Numeric.AERN.Basics.Interval 31 | 32 | import qualified Data.Number.MPFR as M 33 | import Data.Number.MPFR (MPFR) 34 | import Data.Number.MPFR.Instances.Up 35 | import qualified Data.Number.MPFR.Mutable as MM 36 | 37 | instance HasDistance MPFR where 38 | type Distance MPFR = MI 39 | type DistanceEffortIndicator MPFR = ArithInOut.AddEffortIndicator MI 40 | distanceDefaultEffort d = ArithInOut.addDefaultEffort (Interval d d) 41 | distanceBetweenEff effort d1 d2 = 42 | -- | d1 == 1/0 && d2 == 1/0 = zero 43 | -- -- distance between two infinities is zero (beware: distance not continuous at infinities!) 44 | -- | d1 == -1/0 && d2 == -1/0 = zero 45 | -- | otherwise = 46 | ArithInOut.absOut (d2I <-> d1I) 47 | where 48 | d1I = Interval d1 d1 49 | d2I = Interval d2 d2 50 | (<->) = ArithInOut.subtrOutEff effort 51 | -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/RealArithmetic/RefinementOrderRounding/SpecialConst.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-| 4 | Module : Numeric.AERN.RealArithmetic.RefinementOrderRounding.SpecialConst 5 | Description : support for common constants such as pi 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Support for common constants such as pi. 14 | 15 | This module is hidden and reexported via its parent RefinementOrderRounding. 16 | -} 17 | 18 | module Numeric.AERN.RealArithmetic.RefinementOrderRounding.SpecialConst where 19 | 20 | import Numeric.AERN.Basics.Effort 21 | 22 | --import Numeric.AERN.Misc.Debug 23 | 24 | class 25 | (EffortIndicator (SpecialConstEffortIndicator t)) 26 | => 27 | RoundedSpecialConstEffort t 28 | where 29 | type SpecialConstEffortIndicator t 30 | specialConstDefaultEffort :: t -> SpecialConstEffortIndicator t 31 | 32 | class (RoundedSpecialConstEffort t) => RoundedSpecialConst t where 33 | piInEff :: (SpecialConstEffortIndicator t) -> t -> t 34 | piOutEff :: (SpecialConstEffortIndicator t) -> t -> t 35 | eInEff :: (SpecialConstEffortIndicator t) -> t -> t 36 | eOutEff :: (SpecialConstEffortIndicator t) -> t -> t 37 | 38 | -- | Inward rounded pi with default effort 39 | piIn :: (RoundedSpecialConst t) => t -> t 40 | piIn sample = piInEff (specialConstDefaultEffort sample) sample 41 | 42 | -- | Outward rounded pi with default effort 43 | piOut :: (RoundedSpecialConst t) => t -> t 44 | piOut sample = piOutEff (specialConstDefaultEffort sample) sample 45 | 46 | -- | Inward rounded e with default effort 47 | eIn :: (RoundedSpecialConst t) => t -> t 48 | eIn sample = eInEff (specialConstDefaultEffort sample) sample 49 | 50 | -- | Outward rounded e with default effort 51 | eOut :: (RoundedSpecialConst t) => t -> t 52 | eOut sample = eOutEff (specialConstDefaultEffort sample) sample 53 | 54 | -------------------------------------------------------------------------------- /aern-realfn/src/Numeric/AERN/RmToRn/RefinementOrderRounding/ChebyshevPoly.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE ScopedTypeVariables #-} 3 | {-| 4 | Module : Numeric.AERN.RmToRn.RefinementOrderRounding.ChebyshevPoly 5 | Description : approximations of Chebyshev polynomials 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Approximations of Chebyshev polynomials. 14 | -} 15 | 16 | module Numeric.AERN.RmToRn.RefinementOrderRounding.ChebyshevPoly where 17 | 18 | import Numeric.AERN.RealArithmetic.ExactOps (HasOne(..)) 19 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 20 | 21 | import Debug.Trace 22 | _ = trace 23 | 24 | chebyshevOut :: 25 | (HasOne f, ArithInOut.RoundedRing f, Show f) 26 | => 27 | (ArithInOut.RingOpsEffortIndicator f) 28 | {-^ Effort indicator to guide the effort used for approximately computing the Chebyshev polynomials -} -> 29 | f {-^ @x@ - A function to substitute in the Chebyshev polynomial -} -> 30 | [f] {-^ @[T_0(x), T_1(x), T_2(x), ..]@ - The Chebyshev polynomials of all degrees -} 31 | chebyshevOut effRingF x = 32 | -- trace 33 | -- ( 34 | -- "chebyshevOut:" 35 | -- ++ "\n x = " ++ show x 36 | -- ++ "\n T_2(x) = " ++ (show $ result !! 2) 37 | -- ) 38 | result 39 | where 40 | result = 41 | chebyshevPolys c1 x 42 | chebyshevPolys tNminus2 tNminus1 = 43 | tNminus2 : (chebyshevPolys tNminus1 tN) 44 | where 45 | tN = (c2 ~<*>~ x ~<*>~ tNminus1) ~<->~ tNminus2 46 | c1 = (one sampleF) 47 | c2 = c1 ~<+>~ c1 48 | sampleF = x 49 | 50 | (~<+>~) = ArithInOut.addOutEff effAddF 51 | (~<->~) = ArithInOut.subtrOutEff effAddF 52 | (~<*>~) = ArithInOut.multOutEff effMultF 53 | 54 | effAddF = ArithInOut.ringEffortAdd sampleF effRingF 55 | effMultF = ArithInOut.ringEffortMult sampleF effRingF 56 | 57 | 58 | -------------------------------------------------------------------------------- /aern-realfn/src/Numeric/AERN/RmToRn/Integration.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RmToRn.Integration 4 | Description : integrators of function enclosures 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Integrators of function enclosures. 13 | -} 14 | 15 | module Numeric.AERN.RmToRn.Integration where 16 | 17 | import Numeric.AERN.RmToRn.Domain 18 | 19 | class RoundedIntegration f where 20 | type IntegrationEffortIndicator f 21 | integrationDefaultEffort :: f -> IntegrationEffortIndicator f 22 | {-| approximate the primitive function by integrating the given variable, 23 | starting at the left endpoint of its domain -} 24 | primitiveFunctionOutEff :: 25 | IntegrationEffortIndicator f -> 26 | f {-^ function @f@ -} -> 27 | (Var f) {-^ variable @x@ in the domain box of @f@ with values in @[l,r]@ -} -> 28 | f {-^ primitive function of @f(x,...)@ by @x@ with @f(l,...) = 0@ -} 29 | primitiveFunctionInEff :: 30 | IntegrationEffortIndicator f -> 31 | f {-^ function @f@ -} -> 32 | (Var f) {-^ variable @x@ in the domain box of @f@ with values in @[l,r]@ -} -> 33 | f {-^ primitive function of @f(x,...)@ by @x@ with @f(l,...) = 0@ -} 34 | 35 | primitiveFunctionOut :: 36 | RoundedIntegration f => 37 | f {-^ function @f@ -} -> 38 | (Var f) {-^ variable @x@ in the domain box of @f@ with values in @[l,r]@ -} -> 39 | f {-^ primitive function of @f(x,...)@ by @x@ with @f(l,...) = 0@ -} 40 | primitiveFunctionOut fn var = 41 | primitiveFunctionOutEff (integrationDefaultEffort fn) fn var 42 | 43 | primitiveFunctionIn :: 44 | RoundedIntegration f => 45 | f {-^ function @f@ -} -> 46 | (Var f) {-^ variable @x@ in the domain box of @f@ with values in @[l,r]@ -} -> 47 | f {-^ primitive function of @f(x,...)@ by @x@ with @f(l,...) = 0@ -} 48 | primitiveFunctionIn fn var = 49 | primitiveFunctionInEff (integrationDefaultEffort fn) fn var 50 | 51 | -------------------------------------------------------------------------------- /aern-double/src/Numeric/AERN/RealArithmetic/Basis/Double.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.Double 4 | Description : Instances for Double as interval endpoints. 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable (indirect FFI) 11 | 12 | Instances of Double required for serving as interval endpoints, 13 | namely providing granularity, Comparison, lattice, rounded field and 14 | rounded elementary operations. 15 | -} 16 | module Numeric.AERN.RealArithmetic.Basis.Double 17 | (sampleD, nanD) 18 | where 19 | 20 | import Numeric.AERN.RealArithmetic.Basis.Double.ShowInternals 21 | import Numeric.AERN.RealArithmetic.Basis.Double.NumericOrder 22 | import Numeric.AERN.RealArithmetic.Basis.Double.Conversion 23 | import Numeric.AERN.RealArithmetic.Basis.Double.FieldOps 24 | import Numeric.AERN.RealArithmetic.Basis.Double.MixedFieldOps 25 | import Numeric.AERN.RealArithmetic.Basis.Double.Measures 26 | import Numeric.AERN.RealArithmetic.Basis.Double.SpecialConst 27 | 28 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 29 | import Numeric.AERN.Basics.Exception 30 | 31 | instance HasLegalValues Double where 32 | maybeGetProblem d 33 | | isNaN d = Just "A NaN Double" 34 | -- | d == 1/0 = False 35 | -- | d == -1/0 = False 36 | | otherwise = Nothing 37 | 38 | instance RoundedReal Double where 39 | type RoundedRealEffortIndicator Double = () 40 | roundedRealDefaultEffort _ = () 41 | rrEffortComp _ _ = () 42 | rrEffortMinmax _ _ = () 43 | rrEffortDistance _ _ = () 44 | rrEffortToSelf _ _ = () 45 | rrEffortToInt _ _ = () 46 | rrEffortFromInt _ _ = () 47 | rrEffortToInteger _ _ = () 48 | rrEffortFromInteger _ _ = () 49 | rrEffortToDouble _ _ = () 50 | rrEffortFromDouble _ _ = () 51 | rrEffortToRational _ _ = () 52 | rrEffortFromRational _ _ = () 53 | rrEffortAbs _ _ = () 54 | rrEffortField _ _ = () 55 | rrEffortIntMixedField _ _ = () 56 | rrEffortIntegerMixedField _ _ = () 57 | rrEffortDoubleMixedField _ _ = () 58 | rrEffortRationalMixedField _ _ = () 59 | -------------------------------------------------------------------------------- /aern-realfn/src/Numeric/AERN/RmToRn/New.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-| 4 | Module : Numeric.AERN.RmToRn.New 5 | Description : constructors of basic functions 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Constructors of basic functions. 14 | -} 15 | 16 | module Numeric.AERN.RmToRn.New where 17 | 18 | import Numeric.AERN.RmToRn.Domain 19 | 20 | import Numeric.AERN.Basics.Effort 21 | import Numeric.AERN.Basics.SizeLimits 22 | 23 | 24 | 25 | class (HasDomainBox f, HasSizeLimits f) => HasProjections f where 26 | newProjection :: 27 | (SizeLimits f) {-^ limits of the new function -} -> 28 | [(Var f, Domain f)] {-^ the domain @box@ of the function -} -> 29 | (Var f) {-^ the variable @x@ being projected -} -> 30 | f {-^ @ \box -> x @ -} 31 | 32 | newProjectionFromSample :: 33 | (HasProjections f) => 34 | f -> (Var f) -> f 35 | newProjectionFromSample sampleF var = 36 | newProjection sizeLimits varDoms var 37 | where 38 | sizeLimits = getSizeLimits sampleF 39 | varDoms = getVarDoms sampleF 40 | 41 | class (HasDomainBox f, HasSizeLimits f) => HasConstFns f where 42 | newConstFn :: 43 | (SizeLimits f) {-^ limits of the new function -} -> 44 | [(Var f, Domain f)] {-^ the domain @box@ of the function -} -> 45 | (Domain f) {-^ the value @v@ of the constant function -} -> 46 | f {-^ @ \box -> v @ -} 47 | 48 | class (HasDomainBox f) => CanAddVariables f where 49 | addVariablesFront :: 50 | [(Var f, Domain f)] -> 51 | f -> 52 | f 53 | addVariablesBack :: 54 | [(Var f, Domain f)] -> 55 | f -> 56 | f 57 | 58 | class (HasDomainBox f) => CanRenameVariables f where 59 | renameVar :: (Var f) -> (Var f) -> f -> f 60 | renameVars :: (Var f -> Var f) -> f -> f 61 | 62 | newConstFnFromSample :: 63 | (HasConstFns f) => 64 | f -> (Domain f) -> f 65 | newConstFnFromSample sampleF value = 66 | newConstFn sizeLimits varDoms value 67 | where 68 | sizeLimits = getSizeLimits sampleF 69 | varDoms = getVarDoms sampleF 70 | 71 | -------------------------------------------------------------------------------- /aern-double/src/Numeric/AERN/RealArithmetic/Basis/Double/NumericOrder.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.Double.NumericOrder 4 | Description : numeric order instances for Double 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Numeric order Comparison and lattice instances for Double. 13 | 14 | This is a private module reexported publicly via its parent. 15 | -} 16 | module Numeric.AERN.RealArithmetic.Basis.Double.NumericOrder 17 | where 18 | 19 | import Prelude hiding (EQ,LT,GT) 20 | 21 | import Numeric.AERN.Basics.Exception 22 | import Control.Exception 23 | 24 | import Numeric.AERN.Basics.PartialOrdering 25 | import qualified Numeric.AERN.NumericOrder as NumOrd 26 | import Numeric.AERN.NumericOrder (MinmaxEffortIndicator) 27 | 28 | import Numeric.AERN.Basics.SizeLimits 29 | 30 | import Numeric.AERN.Misc.List 31 | import Numeric.AERN.Misc.Debug 32 | 33 | import Data.Maybe 34 | 35 | sampleD :: Double 36 | sampleD = 0 37 | 38 | nanD :: Double 39 | nanD = 0/0 40 | 41 | instance HasSizeLimits Double where 42 | type SizeLimits Double = () 43 | getSizeLimits _ = () 44 | defaultSizeLimits _ = () 45 | 46 | instance CanChangeSizeLimits Double where 47 | type SizeLimitsChangeEffort Double = () 48 | sizeLimitsChangeDefaultEffort _ = () 49 | changeSizeLimitsDnEff _ _ d = d 50 | changeSizeLimitsUpEff _ _ d = d 51 | changeSizeLimitsOutEff = error $ "AERN: changeSizeLimitsOutEff not defined for Double" 52 | changeSizeLimitsInEff = error $ "AERN: changeSizeLimitsInEff not defined for Double" 53 | 54 | instance NumOrd.HasLeast Double where 55 | least _ = - 1/0 56 | 57 | instance NumOrd.HasGreatest Double where 58 | greatest _ = 1/0 59 | 60 | instance NumOrd.HasExtrema Double where 61 | 62 | instance NumOrd.RoundedLatticeEffort Double where 63 | type MinmaxEffortIndicator Double = () 64 | minmaxDefaultEffort _ = () 65 | 66 | instance NumOrd.RoundedLattice Double where 67 | maxUpEff _ a b = Prelude.max a b 68 | maxDnEff = NumOrd.maxUpEff 69 | minUpEff _ a b = Prelude.min a b 70 | minDnEff = NumOrd.minUpEff 71 | 72 | -------------------------------------------------------------------------------- /aern-poly-plot-gtk/src/Numeric/AERN/Poly/IntPoly/Plot.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-# LANGUAGE FlexibleInstances #-} 4 | {-# LANGUAGE MultiParamTypeClasses #-} 5 | {-# LANGUAGE UndecidableInstances #-} 6 | {-| 7 | Module : Numeric.AERN.Poly.IntPoly.Plot 8 | Description : Cairo plotting support 9 | Copyright : (c) Michal Konecny 10 | License : BSD3 11 | 12 | Maintainer : mikkonecny@gmail.com 13 | Stability : experimental 14 | Portability : portable 15 | 16 | Cairo plotting support. 17 | -} 18 | 19 | module Numeric.AERN.Poly.IntPoly.Plot 20 | ( 21 | CairoDrawEffortIndicatorFnFromEval(..) 22 | ) 23 | where 24 | 25 | import Numeric.AERN.Poly.IntPoly 26 | 27 | import Numeric.AERN.RmToRn.Plot.CairoDrawable 28 | import Numeric.AERN.RmToRn.Plot.FromEval 29 | 30 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 31 | --import Numeric.AERN.RealArithmetic.RefinementOrderRounding.OpsImplicitEffort 32 | 33 | import qualified Numeric.AERN.RefinementOrder as RefOrd 34 | --import Numeric.AERN.RefinementOrder.OpsImplicitEffort 35 | 36 | import Numeric.AERN.Basics.Consistency 37 | 38 | --import Numeric.AERN.Misc.Debug 39 | 40 | instance 41 | (Show cf, 42 | RefOrd.IntervalLike cf, 43 | ArithInOut.RoundedReal cf, 44 | Ord var, 45 | Show var, 46 | HasAntiConsistency cf) 47 | => 48 | CairoDrawableFn (IntPoly var cf) 49 | where 50 | type CairoDrawFnEffortIndicator (IntPoly var cf) = 51 | IntPolyEffort cf 52 | cairoDrawFnDefaultEffort (IntPoly cfg _) = 53 | ipolycfg_effort cfg 54 | cairoDrawFnGraph effIP = 55 | cairoDrawFnGraphFromEval $ convertEff effIP 56 | cairoDrawFnParameteric effIP = 57 | cairoDrawFnParametericFromEval $ convertEff effIP 58 | 59 | convertEff :: 60 | HasConsistency cf 61 | => 62 | IntPolyEffort cf 63 | -> 64 | CairoDrawEffortIndicatorFnFromEval (IntPoly var cf) 65 | convertEff effIP = 66 | CairoDrawEffortIndicatorFnFromEval 67 | { 68 | draweff_evalF = effIP 69 | , 70 | draweff_realD = ipolyeff_cfRoundedRealEffort effIP 71 | , 72 | draweff_getEndpointsD = ipolyeff_cfGetEndpointsEffort effIP 73 | } 74 | 75 | -------------------------------------------------------------------------------- /aern-realfn/aern-realfn.cabal: -------------------------------------------------------------------------------- 1 | Name: aern-realfn 2 | Version: 0.5.0 3 | Cabal-Version: >= 1.8 4 | Build-Type: Simple 5 | License: BSD3 6 | License-File: LICENCE 7 | Author: Michal Konecny 8 | Copyright: (c) 2012 Michal Konecny 9 | Maintainer: mikkonecny@gmail.com 10 | Homepage: http://code.google.com/p/aern/ 11 | Stability: experimental 12 | Category: Data, Math 13 | Synopsis: arbitrary precision real function arithmetic 14 | Tested-with: GHC==7.6.3 15 | Description: 16 | Type classes abstracting typical operations for m-ary continuous real functions 17 | such as evaluation, composition, integration and automatic differentiation. 18 | The operations work on some approxmations of the exact entities which induce rounding. 19 | Two kinds of rounding are supported: rounding up-down in the numerical order 20 | or rounding in-out in a refinement order. 21 | . 22 | A concrete arithmetic of approximants of m-ary real functions 23 | is provided in the package aern-poly, using polynomials with interval coefficients. 24 | 25 | Library 26 | hs-source-dirs: src 27 | Build-Depends: 28 | base >= 4.4, 29 | containers >= 0.3, 30 | QuickCheck >= 2.4, 31 | test-framework >= 0.3.3, 32 | test-framework-quickcheck2 >= 0.2, 33 | random >= 1.0.0.2, 34 | aern-order == 0.5.*, 35 | aern-real == 0.5.*, 36 | aern-interval == 0.5.* 37 | exposed-modules: 38 | Numeric.AERN.RmToRn, 39 | Numeric.AERN.RmToRn.Differentiation, 40 | Numeric.AERN.RmToRn.Domain, 41 | Numeric.AERN.RmToRn.Evaluation, 42 | Numeric.AERN.RmToRn.Integration, 43 | Numeric.AERN.RmToRn.Interval, 44 | Numeric.AERN.RmToRn.Laws, 45 | Numeric.AERN.RmToRn.New, 46 | Numeric.AERN.RmToRn.NumericOrder.FromInOutRingOps.Arbitrary, 47 | Numeric.AERN.RmToRn.NumericOrder.FromInOutRingOps.Comparison, 48 | Numeric.AERN.RmToRn.NumericOrder.FromInOutRingOps.Minmax, 49 | Numeric.AERN.RmToRn.RefinementOrderRounding.BernsteinPoly, 50 | Numeric.AERN.RmToRn.RefinementOrderRounding.ChebyshevPoly, 51 | Numeric.AERN.RmToRn.RefinementOrderRounding.Reciprocal 52 | ghc-options: -Wall 53 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Basics/Laws/Operation.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.Basics.Laws.Relation 3 | Description : common properties of binary operations 4 | Copyright : (c) Michal Konecny 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Common properties of binary operations. 12 | -} 13 | module Numeric.AERN.Basics.Laws.Operation 14 | ( 15 | idempotent, commutative, associative, 16 | partialIdempotent, partialCommutative, partialAssociative, 17 | modular, leftDistributive, rightDistributive 18 | ) 19 | where 20 | 21 | import Numeric.AERN.Basics.Laws.Utilities 22 | 23 | --import qualified Algebra.Laws as NP -- numeric-prelude 24 | 25 | idempotent :: (Rel t) -> (Op t) -> t -> Bool 26 | idempotent (==) (*) e = 27 | (e * e) == e 28 | 29 | commutative :: (Rel t) -> (Op t) -> t -> t -> Bool 30 | commutative (==) (*) e1 e2 = 31 | (e1 * e2) == (e2 * e1) 32 | 33 | associative :: (Rel t) -> (Op t) -> t -> t -> t -> Bool 34 | associative (==) (*) e1 e2 e3 = 35 | ((e1 * e2) * e3) == (e1 * (e2 * e3)) 36 | 37 | modular :: (Rel t) -> (Op t) -> (Op t) -> t -> t -> t -> Bool 38 | modular (==) (/\) (\/) e1 e2 e3 = 39 | ((e1 /\ e3) \/ (e2 /\ e3)) == (((e1 /\ e3) \/ e2) /\ e3) 40 | 41 | leftDistributive :: (Rel t) -> (Op t) -> (Op t) -> t -> t -> t -> Bool 42 | leftDistributive (==) (/\) (\/) e1 e2 e3 = 43 | (e1 \/ (e2 /\ e3)) == ((e1 \/ e2) /\ (e1 \/ e3)) 44 | 45 | rightDistributive :: (Rel t) -> (Op t) -> (Op t) -> t -> t -> t -> Bool 46 | rightDistributive (==) (/\) (\/) e1 e2 e3 = 47 | ((e2 /\ e3) \/ e1) == ((e2 \/ e1) /\ (e3 \/ e1)) 48 | 49 | partialIdempotent :: (Rel t) -> (PartOp t) -> t -> Bool 50 | partialIdempotent (==) (*?) e = 51 | case e *? e of 52 | Just r -> r == e 53 | _ -> True 54 | 55 | partialCommutative :: (Rel t) -> (PartOp t) -> t -> t -> Bool 56 | partialCommutative (==) (*?) e1 e2 = 57 | case (e1 *? e2, e2 *? e1) of 58 | (Just e12, Just e21) -> e12 == e21 59 | _ -> True 60 | 61 | partialAssociative :: (Rel t) -> (PartOp t) -> t -> t -> t -> Bool 62 | partialAssociative (==) (*?) e1 e2 e3 = 63 | case (e1 *? e2, e2 *? e3) of 64 | (Just e12, Just e23) -> 65 | case (e12 *? e3, e1 *? e23) of 66 | (Just eLR, Just eRL) -> eLR == eRL 67 | _ -> True 68 | _ -> True 69 | 70 | -------------------------------------------------------------------------------- /aern-realfn-plot-gtk/src/Numeric/AERN/RmToRn/Plot/FnView.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-unused-do-bind #-} 2 | {-# LANGUAGE CPP #-} 3 | {-# LANGUAGE TypeFamilies #-} 4 | {-# LANGUAGE StandaloneDeriving #-} 5 | {-# LANGUAGE FlexibleContexts #-} 6 | {-# LANGUAGE UndecidableInstances #-} 7 | {-# LANGUAGE ScopedTypeVariables #-} 8 | #ifdef GLADE_DIR 9 | #else 10 | #define GLADE_DIR "./" 11 | #endif 12 | {-| 13 | Module : Numeric.AERN.RmToRn.Plot.FnView 14 | Description : a gtk widget inspecting cairo drawable functions 15 | Copyright : (c) Michal Konecny 16 | License : BSD3 17 | 18 | Maintainer : mikkonecny@gmail.com 19 | Stability : experimental 20 | Portability : portable 21 | 22 | A gtk widget inspecting function enclosures. 23 | -} 24 | module Numeric.AERN.RmToRn.Plot.FnView 25 | ( 26 | FnData (..), 27 | GraphOrParamPlotFn (..), 28 | FnMetaData (..), 29 | defaultFnData, 30 | defaultFnMetaData, 31 | new, 32 | plotToPDFFile, 33 | module Numeric.AERN.RmToRn.Plot.Simple, 34 | module Numeric.AERN.RmToRn.Plot.Params 35 | ) 36 | where 37 | 38 | import Numeric.AERN.RmToRn.Plot.FnView.New 39 | import Numeric.AERN.RmToRn.Plot.FnView.FnData 40 | import Numeric.AERN.RmToRn.Plot.FnView.State 41 | import Numeric.AERN.RmToRn.Plot.FnView.Layout 42 | import Numeric.AERN.RmToRn.Plot.FnView.WatchData 43 | import Numeric.AERN.RmToRn.Plot.FnView.Canvas 44 | 45 | import Numeric.AERN.RmToRn.Plot.Params 46 | import Numeric.AERN.RmToRn.Plot.Simple 47 | import Numeric.AERN.RmToRn.Plot.CairoDrawable (CairoDrawableFn(..)) 48 | 49 | import Numeric.AERN.RmToRn.Domain 50 | import Numeric.AERN.RmToRn.Evaluation 51 | 52 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 53 | --import Numeric.AERN.RealArithmetic.RefinementOrderRounding.OpsImplicitEffort 54 | 55 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 56 | 57 | import qualified Numeric.AERN.RefinementOrder as RefOrd 58 | --import Numeric.AERN.RefinementOrder.OpsImplicitEffort 59 | 60 | import Graphics.Rendering.Cairo as Cairo 61 | import qualified Graphics.UI.Gtk as Gtk 62 | --import Graphics.UI.Gtk (AttrOp((:=))) 63 | import qualified Graphics.UI.Gtk.Gdk.EventM as GdkEv 64 | 65 | import Control.Concurrent (forkIO) 66 | import Control.Concurrent.STM (TVar, newTVar, atomically, readTVar, writeTVar) -- as STM 67 | import Data.IORef 68 | 69 | import qualified System.FilePath as FilePath 70 | 71 | -------------------------------------------------------------------------------- /aern-ivp/demos/Enclosing_Zeno_plots-NAHS2015.txt: -------------------------------------------------------------------------------- 1 | This file describes how to reproduce the hybrid system enclosure plots in the journal paper: 2 | 3 | "Enclosing the Behavior of a Hybrid Automaton up to and Beyond a Zeno Point" 4 | by 5 | Michal Konečný, Walid Taha, Ferenc A. Bartha, Jan Duracz, Adam Duracz, Aaron D. Ames 6 | 7 | published in "Nonlinear Analysis: Hybrid Systems" in 2015. 8 | 9 | The plots produced by the commands below are essentially the same as those in the paper. Nevertheless, there are minor differences due to changes made to the plotting code in the course of making revisions to the paper. 10 | 11 | Figure 4 (a) 12 | command: 13 | simple-events bouncingBall 3.5 "PlotGraph[True](0,3.5,0,5)" GUI locate evtree 12 12 3 20 0 0 14 | approx computation time: 4 minutes 15 | Figure 4 (b) 16 | command: 17 | simple-events twoTanks 2.5 "PlotGraph[True,True](0,2.5,0,2)" GUI locate evtree 17 17 1 10 0 0 18 | approx computation time: 12 minutes 19 | Figure 4 (c) 20 | command: 21 | simple-events bouncingBallEnergy 3.5 "PlotGraph[True](0,3.5,0,5)" GUI locate evtree 12 12 3 20 0 0 22 | approx computation time: 39 minutes 23 | Figure 4 (d) 24 | command: 25 | simple-events twoTanksSum 2.5 "PlotGraph[True,True,True](0,2.5,0,2)" GUI locate evtree 17 17 1 10 0 0 26 | approx computation time: 27 minutes 27 | 28 | Figure 10 top: 29 | command: 30 | simple-events bouncingBallNewtonianGravityEnergy 2.8 "PlotGraph[True,True](0,3,-7,7)" GUI locate evtree 12 12 5 20 3 0 31 | approx computation time: 26 minutes 32 | Figure 10 bottom: 33 | command: 34 | simple-events bouncingBallNewtonianGravityEnergy 2.8 "PlotGraph[True,True](0,3,-7,7)" GUI locate evtree 6 6 5 20 3 0 35 | approx computation time: 6 minutes 36 | 37 | Figure 11 top: 38 | command: 39 | simple-events bouncingBallDragEnergy 2.7 "PlotGraph[True,True](0,3,-7,7)" GUI locate evtree 12 12 5 20 3 0 40 | approx computation time: 20 minutes 41 | Figure 11 bottom: 42 | command: 43 | simple-events bouncingBallDragEnergy 2.7 "PlotGraph[True,True](0,3,-7,7)" GUI locate evtree 6 6 5 20 3 0 44 | approx computation time: 4 minutes 45 | 46 | Figure 12 top: 47 | command: 48 | simple-events bouncingBallDragNewtonianGravityEnergy 2.5 "PlotGraph[True,True](0,3,-7,7)" GUI locate evtree 12 12 5 20 3 0 49 | approx computation time: 17 minutes 50 | Figure 12 bottom: 51 | command: 52 | simple-events bouncingBallDragNewtonianGravityEnergy 2.5 "PlotGraph[True,True](0,3,-7,7)" GUI locate evtree 6 6 5 20 3 0 53 | approx computation time: 6 minutes 54 | -------------------------------------------------------------------------------- /aern-ivp/src/Numeric/AERN/IVP/Plot/PicardView/Layout.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE StandaloneDeriving #-} 3 | {-# LANGUAGE FlexibleContexts #-} 4 | {-# LANGUAGE UndecidableInstances #-} 5 | {-| 6 | Module : Numeric.AERN.IVP.Plot.PicardView.Layout 7 | Description : layout of the PicardView window 8 | Copyright : (c) Michal Konecny 9 | License : BSD3 10 | 11 | Maintainer : mikkonecny@gmail.com 12 | Stability : experimental 13 | Portability : portable 14 | 15 | Internal module for PicardView. 16 | Layout of the PicardView window. 17 | 18 | NOT COMPLETED, CURRENTLY STALLED 19 | -} 20 | module Numeric.AERN.IVP.Plot.PicardView.Layout 21 | --( 22 | --) 23 | where 24 | 25 | --import Numeric.AERN.RmToRn.Plot.PicardView.State 26 | 27 | import qualified Graphics.UI.Gtk as Gtk 28 | 29 | import System.Directory (doesFileExist) 30 | 31 | --loadGlade :: 32 | -- FilePath -> 33 | -- IO Widgets 34 | --loadGlade gladeFileName = 35 | -- do 36 | -- gotGladeFile <- doesFileExist gladeFileName 37 | -- case gotGladeFile of 38 | -- True -> return () 39 | -- False -> error $ "aern-ivp: ...Plot.PicardView: glade file " ++ gladeFileName ++ " not found" 40 | -- Just xml <- Glade.xmlNew gladeFileName 41 | -- window <- Glade.xmlGetWidget xml Gtk.castToWindow "window1" 42 | -- segmentTable <- Glade.xmlGetWidget xml Gtk.castToTable "segmentTable1" 43 | -- nextPicardIterationButton <- Glade.xmlGetWidget xml Gtk.castToButton "nextPicardIterationButton1" 44 | -- nextSegmentButton <- Glade.xmlGetWidget xml Gtk.castToButton "nextSegmentButton1" 45 | -- undoButton <- Glade.xmlGetWidget xml Gtk.castToButton "undoButton1" 46 | -- return $ Widgets 47 | -- { 48 | -- window = window, 49 | -- segmentTable = segmentTable, 50 | -- nextPicardIterationButton = nextPicardIterationButton, 51 | -- nextSegmentButton = nextSegmentButton, 52 | -- undoButton = undoButton 53 | -- } 54 | 55 | data Widgets = 56 | Widgets 57 | { 58 | window :: Gtk.Window, 59 | segmentTable :: Gtk.Table, 60 | nextPicardIterationButton :: Gtk.Button, 61 | nextSegmentButton :: Gtk.Button, 62 | undoButton :: Gtk.Button 63 | } 64 | 65 | data PicardViewDynWidgets = 66 | PicardViewDynWidgets 67 | { 68 | iterationCountLabels :: [[Gtk.Label]], 69 | precisionLabels :: [[Gtk.Label]] 70 | } 71 | 72 | initPicardViewDynWidgets :: PicardViewDynWidgets 73 | initPicardViewDynWidgets = 74 | PicardViewDynWidgets [] [] 75 | 76 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Basics/SizeLimits.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-| 4 | Module : Numeric.AERN.Basics.SizeLimits 5 | Description : intrinsic size limit such as precision 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Intrinsic size limit such as precision. 14 | -} 15 | module Numeric.AERN.Basics.SizeLimits where 16 | 17 | import Numeric.AERN.Basics.Effort 18 | 19 | {-| 20 | An abstraction of concepts such as precision in MPFR numbers, maximum degree of a polynomial. 21 | An intrinsic limitation on the size or precision of a value and values derived 22 | from it by common operations. 23 | -} 24 | class HasSizeLimits f where 25 | type SizeLimits f 26 | getSizeLimits :: f -> SizeLimits f 27 | defaultSizeLimits :: f -> SizeLimits f 28 | 29 | {-| 30 | Ability to increase or decrease a size limit, leading to a value conversion. 31 | 32 | For most types, the instance will define either the Up/Dn operations 33 | or the In/Out operations and let the others throw an exception. 34 | -} 35 | class 36 | (EffortIndicator (SizeLimitsChangeEffort f)) 37 | => 38 | CanChangeSizeLimits f 39 | where 40 | type SizeLimitsChangeEffort f 41 | sizeLimitsChangeDefaultEffort :: f -> SizeLimitsChangeEffort f 42 | changeSizeLimitsDnEff :: SizeLimitsChangeEffort f -> SizeLimits f -> f -> f 43 | changeSizeLimitsUpEff :: SizeLimitsChangeEffort f -> SizeLimits f -> f -> f 44 | changeSizeLimitsOutEff :: SizeLimitsChangeEffort f -> SizeLimits f -> f -> f 45 | changeSizeLimitsInEff :: SizeLimitsChangeEffort f -> SizeLimits f -> f -> f 46 | 47 | changeSizeLimitsOut :: 48 | CanChangeSizeLimits f => 49 | SizeLimits f -> f -> f 50 | changeSizeLimitsOut limits a = 51 | changeSizeLimitsOutEff (sizeLimitsChangeDefaultEffort a) limits a 52 | 53 | changeSizeLimitsIn :: 54 | CanChangeSizeLimits f => 55 | SizeLimits f -> f -> f 56 | changeSizeLimitsIn limits a = 57 | changeSizeLimitsInEff (sizeLimitsChangeDefaultEffort a) limits a 58 | 59 | changeSizeLimitsDn :: 60 | CanChangeSizeLimits f => 61 | SizeLimits f -> f -> f 62 | changeSizeLimitsDn limits a = 63 | changeSizeLimitsDnEff (sizeLimitsChangeDefaultEffort a) limits a 64 | 65 | changeSizeLimitsUp :: 66 | CanChangeSizeLimits f => 67 | SizeLimits f -> f -> f 68 | changeSizeLimitsUp limits a = 69 | changeSizeLimitsUpEff (sizeLimitsChangeDefaultEffort a) limits a 70 | 71 | -------------------------------------------------------------------------------- /aern-double/src/Numeric/AERN/RealArithmetic/Interval/Double.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Interval.Double 4 | Description : Interval Double utilities and tests 5 | Copyright : (c) Michal Konecny, Jan Duracz 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Interval Double utilities and tests. 13 | -} 14 | module Numeric.AERN.RealArithmetic.Interval.Double 15 | ( 16 | DI, 17 | sampleDI, 18 | PositiveDI(..), 19 | width, 20 | bisect, 21 | module Numeric.AERN.Basics.Interval 22 | ) 23 | where 24 | 25 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 26 | 27 | import Numeric.AERN.Basics.Interval 28 | 29 | import Numeric.AERN.RealArithmetic.Interval 30 | 31 | import Numeric.AERN.RealArithmetic.Basis.Double.ShowInternals 32 | import Numeric.AERN.RealArithmetic.Basis.Double.FieldOps 33 | 34 | import qualified Numeric.AERN.NumericOrder as NumOrd 35 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 36 | 37 | import Test.QuickCheck 38 | 39 | type DI = Interval Double 40 | 41 | sampleDI :: DI 42 | sampleDI = Interval 0 0 43 | 44 | newtype PositiveDI = PositiveDI { unPositiveDI :: DI } 45 | 46 | instance Show PositiveDI where 47 | show (PositiveDI i) = show i 48 | 49 | instance Arbitrary PositiveDI 50 | where 51 | arbitrary = 52 | do 53 | NumOrd.UniformlyOrderedPair (l,r) <- arbitrary 54 | return $ PositiveDI (Interval (pos l) (pos r)) 55 | where 56 | pos e 57 | | e > 0 = e 58 | | e == 0 = 1 59 | | otherwise = (-e) 60 | 61 | {-| 62 | Calculate the width of an interval. 63 | The result may not be thin since the width calculation uses outwards rounding. 64 | -} 65 | width :: DI -> DI 66 | width i = 67 | irI <-> ilI 68 | where 69 | irI = Interval ir ir 70 | ilI = Interval il il 71 | Interval il ir = i 72 | 73 | {-| 74 | Split an interval into two subintervals that share only one point 75 | and whose union is the original interval. 76 | -} 77 | bisect :: 78 | Maybe Double {-^ optional parameter, indicating where to split the interval -} -> 79 | DI {-^ the interval to split -} -> 80 | (DI, DI) 81 | bisect maybeMidpoint i = 82 | (l,r) 83 | where 84 | r = Interval midpoint ir 85 | l = Interval il midpoint 86 | midpoint 87 | = case maybeMidpoint of 88 | Nothing -> 0.5*(il + ir) 89 | Just m -> m 90 | Interval il ir = i 91 | -------------------------------------------------------------------------------- /aern-realfn-plot-gtk/src/Numeric/AERN/RmToRn/Plot/CairoDrawable.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RmToRn.Plot.CairoDrawable 4 | Description : abstraction for drawing on a Cairo canvas 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Abstraction for drawing on a Cairo canvas. 13 | -} 14 | module Numeric.AERN.RmToRn.Plot.CairoDrawable 15 | ( 16 | CairoDrawableFn(..), 17 | ) 18 | where 19 | 20 | import Numeric.AERN.RmToRn.Plot.Params (CanvasParams,FnPlotStyle) 21 | 22 | import Numeric.AERN.RmToRn.Domain 23 | 24 | import Graphics.Rendering.Cairo (Render) 25 | 26 | class 27 | CairoDrawableFn f 28 | where 29 | type CairoDrawFnEffortIndicator f 30 | cairoDrawFnDefaultEffort :: 31 | f -> (CairoDrawFnEffortIndicator f) 32 | {-| 33 | Plot the graph of a uni-variate function on the active cairo canvas. 34 | A multi-variate function is transformed into an univariate function 35 | by ranging all other variables over their entire domains and taking 36 | the union of all the uni-variate functions thus obtained. 37 | -} 38 | cairoDrawFnGraph :: 39 | CairoDrawFnEffortIndicator f -> 40 | CanvasParams (Domain f) -> 41 | ((Domain f, Domain f) -> (Double, Double)) {-^ conversion from [0,1]^2 (origin bottom left) to screen coords -} -> 42 | FnPlotStyle -> 43 | Var f {-^ the variable to map to the horizontal axis; the remaining variables are all substituted with their full range -} -> 44 | [f] {-^ a function to plot, given piecewise -} -> 45 | Render () 46 | {-| 47 | Plot the graph of a uni-variate function on the active cairo canvas. 48 | A multi-variate function is transformed into an univariate function 49 | by ranging all other variables over their entire domains and taking 50 | the union of all the uni-variate functions thus obtained. 51 | -} 52 | cairoDrawFnParameteric :: 53 | CairoDrawFnEffortIndicator f -> 54 | CanvasParams (Domain f) -> 55 | ((Domain f, Domain f) -> (Double, Double)) {-^ conversion from [0,1]^2 (origin bottom left) to screen coords -} -> 56 | FnPlotStyle -> 57 | Var f {-^ the variable to parametrise by; the remaining variables are all substituted with their full range -} -> 58 | [Var f] {-^ variables that should not be substituted with their full domain but sampled, potentially resulting in a non-rectangular shape -} -> 59 | [(f, f)] {-^ one function to map to the x axis, one to the y axis, the function pair is given piecewise -} -> 60 | Render () 61 | 62 | -------------------------------------------------------------------------------- /aern-realfn/src/Numeric/AERN/RmToRn.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-# LANGUAGE MultiParamTypeClasses #-} 4 | {-| 5 | Module : Numeric.AERN.RmToRn 6 | Description : real function operations (except pointwise ones) 7 | Copyright : (c) Michal Konecny 8 | License : BSD3 9 | 10 | Maintainer : mikkonecny@gmail.com 11 | Stability : experimental 12 | Portability : portable 13 | 14 | Common real function operations (except pointwise ones). 15 | -} 16 | 17 | module Numeric.AERN.RmToRn 18 | ( 19 | module Numeric.AERN.RmToRn.Domain, 20 | module Numeric.AERN.RmToRn.New, 21 | module Numeric.AERN.RmToRn.Evaluation, 22 | module Numeric.AERN.RmToRn.Integration, 23 | module Numeric.AERN.RmToRn.Differentiation, 24 | RoundedRealFn(..) 25 | ) 26 | where 27 | 28 | import Numeric.AERN.RmToRn.Domain 29 | import Numeric.AERN.RmToRn.New 30 | import Numeric.AERN.RmToRn.Evaluation 31 | import Numeric.AERN.RmToRn.Integration 32 | import Numeric.AERN.RmToRn.Differentiation 33 | 34 | --import Numeric.AERN.RealArithmetic.ExactOps 35 | --import Numeric.AERN.RealArithmetic.Measures 36 | -- 37 | --import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 38 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 39 | -- 40 | --import qualified Numeric.AERN.NumericOrder as NumOrd 41 | import qualified Numeric.AERN.RefinementOrder as RefOrd 42 | -- 43 | --import Numeric.AERN.Basics.Effort 44 | 45 | {-| 46 | An aggregate class collecting together all functionality 47 | normally expected from approximations to real number functions 48 | such as polynomial enclosures. 49 | 50 | It also provides a single aggregate effort indicator type 51 | from which effort indicators for all the rounded operations can 52 | be extracted. 53 | -} 54 | class 55 | (ArithInOut.RoundedReal f, 56 | ArithInOut.RoundedReal (Domain f), 57 | RefOrd.IntervalLike (Domain f), 58 | HasDomainBox f, GeneratableVariables (Var f), 59 | HasConstFns f, HasProjections f, 60 | CanEvaluate f 61 | ) 62 | => 63 | RoundedRealFn f 64 | where 65 | type RoundedRealFnEffortIndicator f 66 | roundedRealFnDefaultEffort :: f -> RoundedRealFnEffortIndicator f 67 | fnEffortReal :: f -> (RoundedRealFnEffortIndicator f) -> (ArithInOut.RoundedRealEffortIndicator f) 68 | fnEffortDomReal :: f -> (RoundedRealFnEffortIndicator f) -> (ArithInOut.RoundedRealEffortIndicator (Domain f)) 69 | fnEffortDomGetEndpoints :: f -> (RoundedRealFnEffortIndicator f) -> (RefOrd.GetEndpointsEffortIndicator (Domain f)) 70 | fnEffortDomFromEndpoints :: f -> (RoundedRealFnEffortIndicator f) -> (RefOrd.FromEndpointsEffortIndicator (Domain f)) 71 | fnEffortEval :: f -> (RoundedRealFnEffortIndicator f) -> EvaluationEffortIndicator f 72 | 73 | -------------------------------------------------------------------------------- /aern-interval/src/Numeric/AERN/Basics/Interval/Arbitrary.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-# LANGUAGE UndecidableInstances #-} 4 | {-| 5 | Module : Numeric.AERN.Basics.Interval.Arbitrary 6 | Description : interval instances of arbitrary with area 7 | Copyright : (c) Michal Konecny, Jan Duracz 8 | License : BSD3 9 | 10 | Maintainer : mikkonecny@gmail.com 11 | Stability : experimental 12 | Portability : portable 13 | 14 | Interval instances of arbitrary with area. 15 | 16 | This is a hidden module reexported via its parent. 17 | -} 18 | module Numeric.AERN.Basics.Interval.Arbitrary where 19 | 20 | import Prelude hiding (EQ, LT, GT) 21 | 22 | import Numeric.AERN.Basics.Consistency 23 | import Numeric.AERN.Basics.Arbitrary 24 | 25 | import Numeric.AERN.Basics.Interval.Basics 26 | 27 | import qualified Numeric.AERN.NumericOrder as NumOrd 28 | import Numeric.AERN.NumericOrder.Operators 29 | 30 | instance 31 | (NumOrd.ArbitraryOrderedTuple e, 32 | NumOrd.RoundedLattice e, 33 | AreaHasForbiddenValues e, 34 | NumOrd.PartialComparison e) 35 | => 36 | ArbitraryWithArea (Interval e) 37 | where 38 | type Area (Interval e) = (Area e, AreaConsistencyConstraint) 39 | areaWhole (Interval l _) = (areaWhole l, AreaMaybeAllowOnlyWithConsistencyStatus Nothing) 40 | arbitraryInArea (area, AreaMaybeAllowOnlyWithConsistencyStatus maybeConsistencyStatus) = 41 | avoidForbidden (100 :: Int) 42 | where 43 | avoidForbidden maxTries = 44 | do 45 | e1 <- arbitraryInArea area 46 | e2 <- arbitraryInArea area 47 | let l = NumOrd.minDnEff (NumOrd.minmaxDefaultEffort e1) e1 e2 48 | let r = NumOrd.maxUpEff (NumOrd.minmaxDefaultEffort e1) e1 e2 49 | let result = case maybeConsistencyStatus of 50 | Nothing -> Interval e1 e2 51 | Just Consistent -> Interval l r 52 | Just Anticonsistent -> Interval r l 53 | Just Exact -> Interval l l 54 | case nothingForbiddenInsideInterval area result of 55 | True -> return result 56 | _ | maxTries > 0 -> avoidForbidden $ maxTries - 1 57 | _ -> error "aern-interval: internal error in arbitraryInArea: failed to avoid forbidden values" 58 | 59 | nothingForbiddenInsideInterval :: 60 | (NumOrd.PartialComparison e, 61 | AreaHasForbiddenValues e) 62 | => 63 | Area e -> Interval e -> Bool 64 | nothingForbiddenInsideInterval area interval = 65 | and $ map (notInside interval) $ areaGetForbiddenValues area 66 | where 67 | notInside (Interval l r) value = 68 | ((value ? r) == Just True) 71 | 72 | 73 | -------------------------------------------------------------------------------- /aern-interval/aern-interval.cabal: -------------------------------------------------------------------------------- 1 | Name: aern-interval 2 | Version: 0.5.0 3 | Cabal-Version: >= 1.8 4 | Build-Type: Simple 5 | License: BSD3 6 | License-File: LICENCE 7 | Author: Michal Konecny 8 | Copyright: (c) 2012 Michal Konecny, Jan Duracz 9 | Maintainer: mikkonecny@gmail.com 10 | Homepage: http://code.google.com/p/aern/ 11 | Stability: experimental 12 | Category: Data, Math 13 | Synopsis: arbitrary precision real interval arithmetic 14 | Tested-with: 15 | GHC==7.6.3 16 | Description: 17 | A concrete implementation for the refinement-order type classes from aern-real in the form 18 | of interval arithmetic. The arithmetic supports also anti-consistent 19 | intervals (ie @[l,r]@ with @l >= r@) and maintains monotonicity in the 20 | refinement order so that both inner and outer approximations of exact interval 21 | expressions can be safely computed. 22 | . 23 | The package aern-double makes it possible to use ordinary 24 | machine 'Double' values as endpoints, although limited to its fixed precision. 25 | The package aern-mpfr facilitates (via package hmpfr) 26 | the use of the MPFR arbitrary precision floating-point numbers as endpoints. 27 | . 28 | /This package does not compile with ghc 7.0.* due to a/ 29 | /compiler bug that has been fixed for the 7.2.1 release./ 30 | 31 | source-repository head 32 | type: mercurial 33 | location: http://code.google.com/p/aern/aern-interval 34 | 35 | source-repository this 36 | type: mercurial 37 | location: http://code.google.com/p/aern/aern-interval 38 | tag: release-0.5.0 39 | 40 | 41 | Library 42 | hs-source-dirs: src 43 | Build-Depends: 44 | base >= 4.4, 45 | QuickCheck >= 2.4, 46 | test-framework >= 0.3.3, 47 | test-framework-quickcheck2 >= 0.2, 48 | deepseq >= 1.1, 49 | aern-order == 0.5.*, 50 | aern-real == 0.5.* 51 | Exposed-modules: 52 | Numeric.AERN.Basics.Interval, 53 | Numeric.AERN.Basics.Interval.Arbitrary, 54 | Numeric.AERN.Basics.Interval.Basics, 55 | Numeric.AERN.Basics.Interval.Consistency, 56 | Numeric.AERN.Basics.Interval.NumericOrder, 57 | Numeric.AERN.Basics.Interval.RefinementOrder, 58 | Numeric.AERN.RealArithmetic.Interval, 59 | Numeric.AERN.RealArithmetic.Interval.Conversion, 60 | Numeric.AERN.RealArithmetic.Interval.Effort, 61 | Numeric.AERN.RealArithmetic.Interval.ElementaryFromBasis, 62 | Numeric.AERN.RealArithmetic.Interval.ElementaryFromFieldOps, 63 | Numeric.AERN.RealArithmetic.Interval.ExactOps, 64 | Numeric.AERN.RealArithmetic.Interval.FieldOps, 65 | Numeric.AERN.RealArithmetic.Interval.Floating, 66 | Numeric.AERN.RealArithmetic.Interval.Measures, 67 | Numeric.AERN.RealArithmetic.Interval.MixedFieldOps, 68 | Numeric.AERN.RealArithmetic.Interval.SpecialConst, 69 | Numeric.AERN.RealArithmetic.Interval.UpDnConversion 70 | ghc-options: -Wall 71 | 72 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Interval/MPFR.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Interval.MPFR 4 | Description : Interval MPFR utilities and tests 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Interval MPFR utilities and tests. 13 | -} 14 | module Numeric.AERN.RealArithmetic.Interval.MPFR 15 | where 16 | 17 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 18 | 19 | import Numeric.AERN.Basics.Interval 20 | 21 | import Numeric.AERN.RealArithmetic.Interval 22 | 23 | import Data.Number.MPFR (MPFR) 24 | import Data.Number.MPFR.Instances.Up 25 | 26 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals 27 | import Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder 28 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 29 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 30 | 31 | import qualified Numeric.AERN.NumericOrder as NumOrd 32 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 33 | 34 | import Test.QuickCheck 35 | 36 | type MI = Interval MPFR 37 | 38 | sampleMI :: MI 39 | sampleMI = Interval 0 0 40 | 41 | instance 42 | Convertible MPFR (Interval MPFR) 43 | where 44 | type ConvertEffortIndicator MPFR (Interval MPFR) = 45 | () 46 | convertDefaultEffort _ _ = () 47 | convertUpEff _ _ x = 48 | Just $ Interval x x 49 | convertDnEff _ _ x = 50 | Just $ Interval x x 51 | 52 | 53 | newtype PositiveMI = PositiveMI { unPositiveMI :: MI } 54 | 55 | instance Show PositiveMI where 56 | show (PositiveMI i) = show i 57 | 58 | instance Arbitrary PositiveMI 59 | where 60 | arbitrary = 61 | do 62 | NumOrd.UniformlyOrderedPair (l,h) <- arbitrary 63 | return $ PositiveMI (Interval (pos l) (pos h)) 64 | where 65 | pos e 66 | | e > 0 = e 67 | | e == 0 = 1 68 | | otherwise = (-e) 69 | 70 | {-| 71 | Calculate the width of an interval. 72 | The result may not be thin since the width calculation uses outwards rounding. 73 | -} 74 | width :: MI -> MI 75 | width i = 76 | irI <-> ilI 77 | where 78 | irI = Interval ir ir 79 | ilI = Interval il il 80 | Interval il ir = i 81 | 82 | {-| 83 | Split an interval into two subintervals that share only one point 84 | and whose union is the original interval. 85 | -} 86 | bisect :: 87 | Maybe MPFR {-^ optional parameter, indicating where to split the interval -} -> 88 | MI {-^ the interval to split -} -> 89 | (MI, MI) 90 | bisect maybeMidpoint i = 91 | (l,r) 92 | where 93 | r = Interval midpoint ir 94 | l = Interval il midpoint 95 | midpoint 96 | = case maybeMidpoint of 97 | Nothing -> 0.5*(il + ir) 98 | Just m -> m 99 | Interval il ir = i 100 | -------------------------------------------------------------------------------- /aern-double/demos/Minimal.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ExistentialQuantification #-} 2 | 3 | module Main where 4 | 5 | import Numeric.AERN.Basics.Effort 6 | 7 | import qualified Numeric.AERN.NumericOrder as NumOrd 8 | import Numeric.AERN.NumericOrder.Operators 9 | 10 | import qualified Numeric.AERN.RefinementOrder as RefOrd 11 | import Numeric.AERN.RefinementOrder.Operators 12 | 13 | import Numeric.AERN.RealArithmetic.ExactOps 14 | 15 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 16 | import Numeric.AERN.RealArithmetic.NumericOrderRounding.Operators 17 | 18 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 19 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 20 | 21 | import Numeric.AERN.RealArithmetic.Basis.Double 22 | import Numeric.AERN.RealArithmetic.Interval.Double 23 | import Numeric.AERN.RealArithmetic.Interval.ElementaryFromFieldOps 24 | 25 | import Numeric.AERN.Basics.ShowInternals 26 | 27 | import Control.Concurrent 28 | 29 | main = 30 | do 31 | -- setMachineRoundingModeUp 32 | -- not sure why the above is sometimes needed... 33 | -- the unsafePerformIO embedded in rounded ops sometimes 34 | -- does not work when run standalone, 35 | -- but they seem to work when run from ghci 36 | -- putStrLn $ "big = " ++ showInternals shouldShowInternals big 37 | -- putStrLn $ "t1 = " ++ showInternals shouldShowInternals t1 38 | -- putStrLn $ "t2 = " ++ showInternals shouldShowInternals t2 39 | putStrLn $ "exp 1 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp1efforts) 40 | putStrLn $ "exp 3 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp3efforts) 41 | putStrLn $ "exp 10 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp10efforts) 42 | putStrLn $ "exp 100 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp100efforts) 43 | putStrLn $ "exp 1000 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp1000efforts) 44 | return () 45 | 46 | shouldShowInternals = False 47 | 48 | exp1efforts :: [DI] 49 | exp1efforts = 50 | map (\n -> ArithInOut.expOutEff (expEffort n) c1) [1..20] 51 | 52 | exp3efforts :: [DI] 53 | exp3efforts = 54 | map (\n -> ArithInOut.expOutEff (expEffort n) c3) [1..20] 55 | 56 | exp10efforts :: [DI] 57 | exp10efforts = 58 | map (\n -> ArithInOut.expOutEff (expEffort n) c10) [1..20] 59 | 60 | exp100efforts :: [DI] 61 | exp100efforts = 62 | map (\n -> ArithInOut.expOutEff (expEffort n) c100) [1..20] 63 | 64 | exp1000efforts :: [DI] 65 | exp1000efforts = 66 | map (\n -> ArithInOut.expOutEff (expEffort n) c1000) [1..20] 67 | 68 | c1, c3, c10, c100, c1000 :: DI 69 | 70 | [c1,c3,c10,c100,c1000] = 71 | map (ArithInOut.convertOutEff () 0) ([1,3,10,100,1000] :: [Int]) 72 | 73 | 74 | expEffort n = 75 | expEffortDefault 76 | { 77 | expeff_taylorDeg = n 78 | } 79 | 80 | expEffortDefault = 81 | ArithInOut.expDefaultEffort t2 82 | 83 | big = 10E200 84 | 85 | t1 :: Double 86 | t1 = 1 +^ big 87 | 88 | t2 :: DI 89 | t2 = 90 | (1 :: Int) 91 | |<+> 92 | (ArithInOut.convertOutEff () 0 big) 93 | 94 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR 4 | Description : Instances for MPFR as interval endpoints. 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable (indirect FFI) 11 | 12 | Instances of MPFR required for serving as interval endpoints, 13 | namely providing granularity, Comparison, lattice, rounded field and 14 | rounded elementary operations. 15 | -} 16 | module Numeric.AERN.RealArithmetic.Basis.MPFR 17 | ( 18 | -- MPFR, MPFRPrec, 19 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Basics, 20 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals, 21 | module Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder, 22 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Conversion, 23 | module Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps, 24 | module Numeric.AERN.RealArithmetic.Basis.MPFR.MixedFieldOps, 25 | module Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst, 26 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary, 27 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Measures, 28 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 29 | ) 30 | where 31 | 32 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 33 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals 34 | import Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder 35 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Conversion 36 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 37 | import Numeric.AERN.RealArithmetic.Basis.MPFR.MixedFieldOps 38 | import Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst 39 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary 40 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Measures 41 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 42 | 43 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 44 | 45 | import Numeric.AERN.Basics.Effort 46 | import Numeric.AERN.Basics.Exception 47 | 48 | import Data.Word 49 | 50 | instance RoundedReal MPFR where 51 | type RoundedRealEffortIndicator MPFR = () 52 | roundedRealDefaultEffort _ = () 53 | rrEffortComp _ _ = () 54 | rrEffortMinmax _ _ = () 55 | rrEffortDistance _ p = () 56 | rrEffortToSelf _ _ = () 57 | rrEffortToInt _ _ = () 58 | rrEffortFromInt _ p = () 59 | rrEffortToInteger _ _ = () 60 | rrEffortFromInteger _ p = () 61 | rrEffortToDouble _ _ = () 62 | rrEffortFromDouble _ p = () 63 | rrEffortToRational _ _ = () 64 | rrEffortFromRational _ p = () 65 | rrEffortAbs _ _ = () 66 | rrEffortField _ p = () 67 | rrEffortIntMixedField _ _ = () 68 | rrEffortIntegerMixedField _ _ = () 69 | rrEffortDoubleMixedField _ _ = () 70 | rrEffortRationalMixedField _ _ = () 71 | 72 | instance HasLegalValues MPFR where 73 | maybeGetProblem d@(MPFR v) 74 | | isNaN v = Just "A NaN MPFR" 75 | -- | d == 1/0 = False 76 | -- | d == -1/0 = False 77 | | otherwise = Nothing 78 | 79 | 80 | -------------------------------------------------------------------------------- /aern-ivp/src/Numeric/AERN/IVP/Plot/PicardView/State.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE StandaloneDeriving #-} 3 | {-# LANGUAGE FlexibleContexts #-} 4 | {-# LANGUAGE UndecidableInstances #-} 5 | {-| 6 | Module : Numeric.AERN.IVP.Plot.PicardView.State 7 | Description : internal state of the PicardView application 8 | Copyright : (c) Michal Konecny 9 | License : BSD3 10 | 11 | Maintainer : mikkonecny@gmail.com 12 | Stability : experimental 13 | Portability : portable 14 | 15 | Internal module for PicardView. 16 | Internal state of the PicardView application. 17 | 18 | NOT COMPLETED, CURRENTLY STALLED 19 | -} 20 | module Numeric.AERN.IVP.Plot.PicardView.State 21 | --( 22 | --) 23 | where 24 | 25 | import Numeric.AERN.IVP.Specification.ODE 26 | 27 | import Numeric.AERN.RmToRn.Domain 28 | import Numeric.AERN.RmToRn.New 29 | 30 | import Numeric.AERN.RealArithmetic.ExactOps 31 | 32 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 33 | 34 | import qualified Numeric.AERN.RefinementOrder as RefOrd 35 | 36 | import Numeric.AERN.Misc.Debug 37 | 38 | data PicardViewState = 39 | PicardViewState 40 | { 41 | pcrdvstComputed :: [Int], 42 | pcrdvstRequested :: [Int] 43 | } 44 | 45 | type PicardViewFns f = 46 | [ -- list of segment information 47 | ([Domain f] -- initial values on this segment 48 | , 49 | [ -- list of Picard iterations for this segment 50 | ([f], -- the solution enclosure produced by this iteration 51 | Bool -- whether this enclosure is within the previous enclosure (if any) 52 | ) 53 | ] 54 | ) 55 | ] 56 | 57 | initState :: 58 | (ArithInOut.RoundedReal (Domain f), 59 | HasConstFns f) 60 | => 61 | f -> 62 | (ArithInOut.RoundedRealEffortIndicator (Domain f)) -> 63 | ODEIVP f -> 64 | (PicardViewFns f, PicardViewState) 65 | initState sampleF effReal ivp = 66 | ([(initialVals, [(mkInitialEnclosures sampleF effReal initialVals, False)])], 67 | PicardViewState 68 | { 69 | pcrdvstRequested = [1], 70 | pcrdvstComputed = [1] 71 | } 72 | ) 73 | where 74 | initialVals = odeivp_makeInitialValueFnVec ivp 75 | 76 | mkInitialEnclosures :: 77 | (ArithInOut.RoundedReal (Domain f), 78 | HasConstFns f) 79 | => 80 | f -> 81 | (ArithInOut.RoundedRealEffortIndicator (Domain f)) -> 82 | [Domain f] -> 83 | [f] 84 | mkInitialEnclosures sampleF effReal initialVals = 85 | map mkInitEncl initialVals 86 | where 87 | mkInitEncl initialVal = 88 | newConstFnFromSample sampleF $ initialVal <+> cm11 89 | where 90 | c1 = one sampleDom 91 | cm11 = (neg c1) c1 92 | 93 | () = RefOrd.meetOutEff effJoinMeet 94 | (<+>) = ArithInOut.addOutEff effAdd 95 | 96 | effJoinMeet = ArithInOut.rrEffortJoinMeet sampleDom effReal 97 | effAdd = 98 | ArithInOut.fldEffortAdd sampleDom $ ArithInOut.rrEffortField sampleDom effReal 99 | sampleDom = getSampleDomValue sampleF 100 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Interval/MPFR.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Interval.MPFR 4 | Description : Interval MPFR utilities and tests 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Interval MPFR utilities and tests. 13 | -} 14 | module Numeric.AERN.RealArithmetic.Interval.MPFR 15 | where 16 | 17 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 18 | 19 | import Numeric.AERN.Basics.Interval 20 | 21 | import Numeric.AERN.RealArithmetic.Interval 22 | 23 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 24 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals 25 | import Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder 26 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 27 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 28 | 29 | import qualified Numeric.AERN.NumericOrder as NumOrd 30 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 31 | 32 | import Test.QuickCheck 33 | 34 | type MI = Interval MPFR 35 | 36 | sampleMIWithPrec :: MPFRPrec -> MI 37 | sampleMIWithPrec prec = Interval z z 38 | where 39 | z = withPrec prec 0 40 | 41 | sampleMI :: MI 42 | sampleMI = sampleMIWithPrec defaultPrecision 43 | 44 | instance 45 | Convertible MPFR (Interval MPFR) 46 | where 47 | type ConvertEffortIndicator MPFR (Interval MPFR) = 48 | () 49 | convertDefaultEffort _ _ = () 50 | convertUpEff _ _ x = 51 | Just $ Interval x x 52 | convertDnEff _ _ x = 53 | Just $ Interval x x 54 | 55 | 56 | newtype PositiveMI = PositiveMI { unPositiveMI :: MI } 57 | 58 | instance Show PositiveMI where 59 | show (PositiveMI i) = show i 60 | 61 | instance Arbitrary PositiveMI 62 | where 63 | arbitrary = 64 | do 65 | NumOrd.UniformlyOrderedPair (l,h) <- arbitrary 66 | return $ PositiveMI (Interval (pos l) (pos h)) 67 | where 68 | pos e 69 | | e > 0 = e 70 | | e == 0 = 1 71 | | otherwise = (-e) 72 | 73 | {-| 74 | Calculate the width of an interval. 75 | The result may not be thin since the width calculation uses outwards rounding. 76 | -} 77 | width :: MI -> MI 78 | width i = 79 | irI <-> ilI 80 | where 81 | irI = Interval ir ir 82 | ilI = Interval il il 83 | Interval il ir = i 84 | 85 | {-| 86 | Split an interval into two subintervals that share only one point 87 | and whose union is the original interval. 88 | -} 89 | bisect :: 90 | Maybe MPFR {-^ optional parameter, indicating where to split the interval -} -> 91 | MI {-^ the interval to split -} -> 92 | (MI, MI) 93 | bisect maybeMidpoint i = 94 | (l,r) 95 | where 96 | r = Interval midpoint ir 97 | l = Interval il midpoint 98 | midpoint 99 | = case maybeMidpoint of 100 | Nothing -> 0.5*(il + ir) 101 | Just m -> m 102 | Interval il ir = i 103 | -------------------------------------------------------------------------------- /aern-poly/src/Numeric/AERN/Poly/IntPoly/Differentiation.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-orphans #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-# LANGUAGE ScopedTypeVariables #-} 4 | {-# LANGUAGE TypeFamilies #-} 5 | {-| 6 | Module : Numeric.AERN.Poly.IntPoly.Differentiation 7 | Description : symbolic differentiation of interval polynomials 8 | Copyright : (c) Michal Konecny 9 | License : BSD3 10 | 11 | Maintainer : mikkonecny@gmail.com 12 | Stability : experimental 13 | Portability : portable 14 | 15 | Symbolic differentiation of interval polynomials. 16 | -} 17 | 18 | module Numeric.AERN.Poly.IntPoly.Differentiation 19 | ( 20 | diffPolyOut 21 | ) 22 | where 23 | 24 | import Numeric.AERN.Poly.IntPoly.Config 25 | import Numeric.AERN.Poly.IntPoly.IntPoly 26 | import Numeric.AERN.Poly.IntPoly.New () 27 | 28 | import Numeric.AERN.RmToRn.Differentiation 29 | 30 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 31 | import Numeric.AERN.RealArithmetic.ExactOps 32 | 33 | import qualified Data.IntMap as IntMap 34 | 35 | instance 36 | (Ord var, ArithInOut.RoundedReal cf) 37 | => 38 | RoundedFakeDerivative (IntPoly var cf) 39 | where 40 | type FakeDerivativeEffortIndicator (IntPoly var cf) = 41 | IntPolyEffort cf 42 | fakeDerivativeDefaultEffort (IntPoly cfg _) = 43 | ipolycfg_effort cfg 44 | fakePartialDerivativeOutEff eff p var = diffPolyOut effCf var p 45 | where 46 | effCf = ipolyeff_cfRoundedRealEffort eff 47 | fakePartialDerivativeInEff = 48 | error "inner rounded fake derivative of IntPoly not implemented yet" 49 | 50 | {-| 51 | Symbolic differentiation of a polynomial by one of its variables. 52 | 53 | /Beware: The result does not enclose the derivative of any function 54 | approximated by the parameter polynomial. This function can be used 55 | only when the polynomial is seen as a itself, not as a function 56 | approximant./ 57 | -} 58 | diffPolyOut :: 59 | (Ord var, ArithInOut.RoundedReal cf) 60 | => 61 | (ArithInOut.RoundedRealEffortIndicator cf) {-^ effort indicator for coefficient operations -} -> 62 | var {-^ variable to differentiate by -} -> 63 | IntPoly var cf -> 64 | IntPoly var cf 65 | diffPolyOut effCf var (IntPoly cfg poly) = 66 | IntPoly cfg $ dp cfg poly 67 | where 68 | dp _cfg (IntPolyC _val) = IntPolyC $ zero sampleCf 69 | dp _cfg (IntPolyV x polys) 70 | | var == x = IntPolyV x $ polysMultiples 71 | where 72 | polysMultiples = 73 | IntMap.fromDistinctAscList $ 74 | map diffTerms $ 75 | IntMap.toAscList $ IntMap.delete 0 polys 76 | diffTerms (n,terms) = 77 | (n - 1, termsMapCoeffs (<*>| n) terms) 78 | dp cfg2 (IntPolyV x polys) 79 | = 80 | termsNormalise $ 81 | IntPolyV x $ IntMap.map (dp cfgR) polys 82 | where 83 | cfgR = cfgRemFirstVar cfg2 84 | 85 | (<*>|) = ArithInOut.mixedMultOutEff effMult 86 | effMult = ArithInOut.mxfldEffortMult sampleCf (1::Int) $ ArithInOut.rrEffortIntMixedField sampleCf effCf 87 | sampleCf = ipolycfg_sample_cf cfg 88 | -------------------------------------------------------------------------------- /aern-interval/src/Numeric/AERN/RealArithmetic/Interval/ElementaryFromBasis.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | --{-# LANGUAGE FlexibleContexts #-} 3 | {-| 4 | Module : Numeric.AERN.RealArithmetic.Interval.ElementaryFromBasis 5 | Description : elementary operations using basis-level operations 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Elementary operations using basis-level operations. 14 | -} 15 | 16 | module Numeric.AERN.RealArithmetic.Interval.ElementaryFromBasis where 17 | 18 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 19 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding 20 | ( 21 | ExpEffortIndicator, 22 | SqrtEffortIndicator 23 | ) 24 | 25 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 26 | 27 | import Numeric.AERN.Basics.Interval 28 | 29 | newtype IntervalElementaryFromBasis t = 30 | IntervalElementaryFromBasis { unIntervalElementaryFromBasis :: Interval t } 31 | 32 | asIntervalElementaryFromBasis :: 33 | ((IntervalElementaryFromBasis t) -> (IntervalElementaryFromBasis t)) 34 | -> 35 | ((Interval t) -> (Interval t)) 36 | asIntervalElementaryFromBasis op interval = 37 | unIntervalElementaryFromBasis $ op (IntervalElementaryFromBasis interval) 38 | 39 | instance (ArithUpDn.RoundedExponentiationEffort e) => 40 | (ArithInOut.RoundedExponentiationEffort (IntervalElementaryFromBasis e)) 41 | where 42 | type ExpEffortIndicator (IntervalElementaryFromBasis e) = 43 | ArithUpDn.ExpEffortIndicator e 44 | expDefaultEffort (IntervalElementaryFromBasis (Interval l _)) = ArithUpDn.expDefaultEffort l 45 | 46 | instance (ArithUpDn.RoundedExponentiation e) => 47 | (ArithInOut.RoundedExponentiation (IntervalElementaryFromBasis e)) 48 | where 49 | expInEff effort (IntervalElementaryFromBasis (Interval l r)) = 50 | IntervalElementaryFromBasis $ 51 | Interval (ArithUpDn.expUpEff effort l) (ArithUpDn.expDnEff effort r) 52 | expOutEff effort (IntervalElementaryFromBasis (Interval l r)) = 53 | IntervalElementaryFromBasis $ 54 | Interval (ArithUpDn.expDnEff effort l) (ArithUpDn.expUpEff effort r) 55 | 56 | instance (ArithUpDn.RoundedSquareRootEffort e) => 57 | (ArithInOut.RoundedSquareRootEffort (IntervalElementaryFromBasis e)) 58 | where 59 | type SqrtEffortIndicator (IntervalElementaryFromBasis e) = ArithUpDn.SqrtEffortIndicator e 60 | sqrtDefaultEffort (IntervalElementaryFromBasis (Interval l _)) = ArithUpDn.sqrtDefaultEffort l 61 | 62 | instance (ArithUpDn.RoundedSquareRoot e) => 63 | (ArithInOut.RoundedSquareRoot (IntervalElementaryFromBasis e)) 64 | where 65 | sqrtInEff effort (IntervalElementaryFromBasis (Interval l r)) = 66 | IntervalElementaryFromBasis $ 67 | Interval (ArithUpDn.sqrtUpEff effort l) (ArithUpDn.sqrtDnEff effort r) 68 | sqrtOutEff effort (IntervalElementaryFromBasis (Interval l r)) = 69 | IntervalElementaryFromBasis $ 70 | Interval (ArithUpDn.sqrtDnEff effort l) (ArithUpDn.sqrtUpEff effort r) 71 | -------------------------------------------------------------------------------- /aern-mpfr/src/Numeric/AERN/RealArithmetic/Basis/MPFR.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Basis.MPFR 4 | Description : Instances for MPFR as interval endpoints. 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable (indirect FFI) 11 | 12 | Instances of MPFR required for serving as interval endpoints, 13 | namely providing granularity, Comparison, lattice, rounded field and 14 | rounded elementary operations. 15 | -} 16 | module Numeric.AERN.RealArithmetic.Basis.MPFR 17 | ( 18 | M.MPFR, MM.MMPFR, M.Precision, 19 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Effort, 20 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals, 21 | module Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder, 22 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Conversion, 23 | module Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps, 24 | module Numeric.AERN.RealArithmetic.Basis.MPFR.MixedFieldOps, 25 | module Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst, 26 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary, 27 | module Numeric.AERN.RealArithmetic.Basis.MPFR.Measures, 28 | module Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 29 | ) 30 | where 31 | 32 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Effort 33 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals 34 | import Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder 35 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Conversion 36 | import Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps 37 | import Numeric.AERN.RealArithmetic.Basis.MPFR.MixedFieldOps 38 | import Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst 39 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary 40 | import Numeric.AERN.RealArithmetic.Basis.MPFR.Measures 41 | import Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps 42 | 43 | import Numeric.AERN.RealArithmetic.NumericOrderRounding 44 | 45 | import Numeric.AERN.Basics.Effort 46 | import Numeric.AERN.Basics.Exception 47 | 48 | import qualified Data.Number.MPFR as M 49 | import qualified Data.Number.MPFR.Mutable as MM 50 | 51 | import Data.Word 52 | 53 | instance RoundedReal M.MPFR where 54 | type RoundedRealEffortIndicator M.MPFR = M.Precision 55 | roundedRealDefaultEffort _ = 100 56 | rrEffortComp _ _ = () 57 | rrEffortMinmax _ _ = () 58 | rrEffortDistance _ p = () 59 | rrEffortToSelf _ _ = () 60 | rrEffortToInt _ _ = () 61 | rrEffortFromInt _ p = p 62 | rrEffortToInteger _ _ = () 63 | rrEffortFromInteger _ p = p 64 | rrEffortToDouble _ _ = () 65 | rrEffortFromDouble _ p = p 66 | rrEffortToRational _ _ = () 67 | rrEffortFromRational _ p = p 68 | rrEffortAbs _ _ = () 69 | rrEffortField _ p = () 70 | rrEffortIntMixedField _ _ = () 71 | rrEffortIntegerMixedField _ _ = () 72 | rrEffortDoubleMixedField _ _ = () 73 | rrEffortRationalMixedField _ _ = () 74 | 75 | instance HasLegalValues M.MPFR where 76 | maybeGetProblem d 77 | | M.isNaN d = Just "A NaN MPFR" 78 | -- | d == 1/0 = False 79 | -- | d == -1/0 = False 80 | | otherwise = Nothing 81 | 82 | 83 | -------------------------------------------------------------------------------- /aern-interval/src/Numeric/AERN/RealArithmetic/Interval/Measures.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-orphans #-} 2 | {-# LANGUAGE TypeFamilies #-} 3 | {-# LANGUAGE FlexibleContexts #-} 4 | {-# LANGUAGE UndecidableInstances #-} 5 | {-| 6 | Module : Numeric.AERN.RealArithmetic.Interval.Measures 7 | Description : distance and imprecision for intervals 8 | Copyright : (c) Michal Konecny 9 | License : BSD3 10 | 11 | Maintainer : mikkonecny@gmail.com 12 | Stability : experimental 13 | Portability : portable 14 | 15 | Distance and imprecision for intervals. 16 | 17 | This module is hidden and reexported via its parent Interval. 18 | -} 19 | 20 | module Numeric.AERN.RealArithmetic.Interval.Measures 21 | () 22 | where 23 | 24 | import Numeric.AERN.RealArithmetic.Interval.Effort 25 | 26 | import Numeric.AERN.RealArithmetic.Measures 27 | import Numeric.AERN.RealArithmetic.ExactOps 28 | 29 | import Numeric.AERN.Basics.Interval 30 | --import Numeric.AERN.Basics.Consistency 31 | 32 | import qualified 33 | Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 34 | 35 | import qualified 36 | Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 37 | 38 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators ((<+>)) 39 | 40 | import qualified 41 | Numeric.AERN.RefinementOrder as RefOrd 42 | import Numeric.AERN.RefinementOrder.Operators (()) 43 | 44 | import qualified 45 | Numeric.AERN.NumericOrder as NumOrd 46 | 47 | import qualified 48 | Numeric.AERN.Basics.PartialOrdering as POrd 49 | 50 | instance 51 | (ArithUpDn.RoundedReal e, 52 | ArithInOut.RoundedAdd (Distance e)) 53 | => 54 | HasDistance (Interval e) 55 | where 56 | type Distance (Interval e) = Distance e 57 | type DistanceEffortIndicator (Interval e) = 58 | IntervalRealEffort e 59 | distanceDefaultEffort i = 60 | defaultIntervalRealEffort i 61 | distanceBetweenEff effort (Interval l1 r1) (Interval l2 r2) = 62 | distL <+> distR -- addition with default effort 63 | where 64 | distL = distanceBetweenEff effGetDist l1 l2 65 | distR = distanceBetweenEff effGetDist r1 r2 66 | effGetDist = ArithUpDn.rrEffortDistance sampleE effortE 67 | sampleE = l1 68 | effortE = intrealeff_eRoundedReal effort 69 | 70 | instance 71 | (ArithUpDn.RoundedReal e, 72 | RefOrd.RoundedLattice (Distance e), Neg (Distance e)) 73 | => 74 | HasImprecision (Interval e) 75 | where 76 | type Imprecision (Interval e) = Distance e 77 | type ImprecisionEffortIndicator (Interval e) = 78 | IntervalRealEffort e 79 | imprecisionDefaultEffort i = 80 | defaultIntervalRealEffort i 81 | imprecisionOfEff effort (Interval l r) = 82 | case (NumOrd.pCompareEff effComp l r) of 83 | Just POrd.LT -> dist 84 | Just POrd.GT -> neg dist 85 | _ -> dist (neg dist) 86 | where 87 | dist = distanceBetweenEff effGetDist l r 88 | effGetDist = ArithUpDn.rrEffortDistance sampleE effortE 89 | effComp = ArithUpDn.rrEffortComp sampleE effortE 90 | sampleE = l 91 | effortE = intrealeff_eRoundedReal effort 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/aern-mpfr-rounded.cabal: -------------------------------------------------------------------------------- 1 | Name: aern-mpfr-rounded 2 | Version: 0.5.0 3 | Cabal-Version: >= 1.8 4 | Build-Type: Simple 5 | License: BSD3 6 | License-File: LICENCE 7 | Author: Michal Konecny 8 | Copyright: (c) 2015 Michal Konecny 9 | Maintainer: mikkonecny@gmail.com 10 | Homepage: http://code.google.com/p/aern/ 11 | Stability: experimental 12 | Category: Data, Math 13 | Synopsis: arbitrary precision real interval arithmetic 14 | Tested-with: 15 | GHC==7.8.3 16 | Description: 17 | This package provides bindings and tests for using arbitrary precision floating-point numbers 18 | provided by the library MPFR (via the Haskell library hmpfr) 19 | as endpoints for the /interval arithmetic/ defined in the package 20 | aern-interval, which implements the real number approximation abstractions 21 | provided by packages aern-order and aern-real. 22 | . 23 | Most users of this package will only need to import one end-user API module. 24 | At present one such module is available: 25 | . 26 | * "Numeric.AERN.MPFRBasis.Interval" gives full access to the interval type, 27 | including its MPFR endpoints. 28 | 29 | Library 30 | hs-source-dirs: src 31 | Build-Depends: 32 | base >= 4.4, 33 | QuickCheck >= 2.4, 34 | rounded >= 0.1, 35 | aern-order == 0.5.*, 36 | aern-real == 0.5.*, 37 | aern-interval == 0.5.* 38 | Exposed-modules: 39 | Numeric.AERN.MPFRBasis.Interval, 40 | Numeric.AERN.RealArithmetic.Basis.MPFR, 41 | Numeric.AERN.RealArithmetic.Interval.MPFR 42 | 43 | Other-modules: 44 | Numeric.AERN.RealArithmetic.Basis.MPFR.Conversion, 45 | Numeric.AERN.RealArithmetic.Basis.MPFR.Elementary, 46 | Numeric.AERN.RealArithmetic.Basis.MPFR.ExactOps, 47 | Numeric.AERN.RealArithmetic.Basis.MPFR.FieldOps, 48 | Numeric.AERN.RealArithmetic.Basis.MPFR.Measures, 49 | Numeric.AERN.RealArithmetic.Basis.MPFR.MixedFieldOps, 50 | Numeric.AERN.RealArithmetic.Basis.MPFR.NumericOrder, 51 | Numeric.AERN.RealArithmetic.Basis.MPFR.ShowInternals, 52 | Numeric.AERN.RealArithmetic.Basis.MPFR.SpecialConst, 53 | Numeric.AERN.RealArithmetic.Basis.MPFR.Utilities, 54 | Numeric.AERN.RealArithmetic.Basis.MPFR.Basics 55 | 56 | Executable testAERN-mpfr-rounded 57 | hs-source-dirs: src, tests 58 | main-is: Main.hs 59 | Build-Depends: 60 | base >= 4.4, 61 | QuickCheck >= 2.4, 62 | test-framework >= 0.3.3, 63 | test-framework-quickcheck2 >= 0.2, 64 | rounded >= 0.1, 65 | aern-order == 0.5.*, 66 | aern-real == 0.5.*, 67 | aern-interval == 0.5.* 68 | 69 | Executable demoAERN-mpfr-rounded-Minimal 70 | hs-source-dirs: src, demos 71 | main-is: Minimal.hs 72 | Build-Depends: 73 | base >= 4.4, 74 | QuickCheck >= 2.4, 75 | rounded >= 0.1, 76 | aern-order == 0.5.*, 77 | aern-real == 0.5.*, 78 | aern-interval == 0.5.* 79 | 80 | Executable demoAERN-mpfr-rounded-LogisticMap 81 | hs-source-dirs: src, demos 82 | main-is: LogisticMap.hs 83 | Build-Depends: 84 | base >= 4.4, 85 | QuickCheck >= 2.4, 86 | rounded >= 0.1, 87 | aern-order == 0.5.*, 88 | aern-real == 0.5.*, 89 | aern-interval == 0.5.* 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Misc/QuickCheck.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} 2 | {-| 3 | Module : Numeric.AERN.Misc.QuickCheck 4 | Description : miscellaneous utilities for QuickCheck 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | miscellaneous utilities for QuickCheck 13 | -} 14 | module Numeric.AERN.Misc.QuickCheck where 15 | 16 | import qualified Data.List as List 17 | import Test.QuickCheck 18 | import Test.QuickCheck.Gen (unGen) 19 | import qualified System.Random as R 20 | import qualified Test.QuickCheck.Random as QCR 21 | 22 | sampleOfLength :: 23 | (Gen a) -> 24 | Int -> 25 | IO [a] 26 | sampleOfLength gen n = 27 | do 28 | rnd0 <- QCR.newQCGen 29 | return [(m r n) | (r,n) <- rnds rnd0 `zip` [0,2..2*n] ] 30 | where 31 | m = unGen gen 32 | rnds rnd = rnd1 : rnds rnd2 33 | where (rnd1,rnd2) = R.split rnd 34 | 35 | {-| Run the generator with size increased by 1 (useful for avoiding 36 | too narrow selection at size 0 - in particular Double "randomly" generates 37 | 0 with probability 1 at size 0. 38 | -} 39 | incrSize :: Gen t -> Gen t 40 | incrSize gen = sized (\size -> resize (size + 1) gen) 41 | 42 | {-| 43 | Probability of True is @n/m@. Precondition: @0 Int {-^ @m@ -} -> Gen Bool 46 | arbitraryBoolRatio n m | 0 < n && n < m = 47 | frequency [(n, return True), (m - n, return False)] 48 | 49 | 50 | arbitraryOrder :: (Ord t) => [t] -> Gen [t] 51 | arbitraryOrder elems = 52 | do 53 | nums <- mapM (const arbitrary) elems 54 | return $ permuteBy (nums :: [Int]) elems 55 | where 56 | permuteBy nums elems = 57 | map snd $ List.sort $ zip nums elems 58 | 59 | {-| 60 | Have a fairly long and hairy sequence of elements of increasing complexity 61 | pre-generated and fixed and then pick from it randomly. 62 | This deals with the problem that the random generation takes a long time 63 | when the elements' construction is expensive, eg when functions are built 64 | using a fairly large sequence of multiplications and additions. 65 | -} 66 | fixedRandSeq :: 67 | (Int -> Int) -> Gen a -> [a] 68 | fixedRandSeq fixedRandSeqQuantityOfSize gen = 69 | aux 0 0 70 | where 71 | aux prevQuantity size 72 | = newSeqPortion ++ (aux currQuantity (size + 1)) 73 | where 74 | newSeqPortion 75 | = 76 | take (currQuantity - prevQuantity) $ 77 | map (\g -> unGen gen g size) 78 | randomGens 79 | currQuantity = fixedRandSeqQuantityOfSize size 80 | randomGens 81 | = map snd $ drop 13 $ iterate (R.next . snd) (0,g) 82 | g = QCR.mkQCGen 754657854089 -- no magic, just bashed at the keyboard at random 83 | 84 | class ArbitraryWithParam t param 85 | where 86 | arbitraryWithParam :: param -> Gen t 87 | 88 | instance 89 | (ArbitraryWithParam t param, 90 | Show t, 91 | Testable prop) 92 | => 93 | Testable (param, t -> prop) 94 | where 95 | property (param, fn) = 96 | forAll (arbitraryWithParam param) fn 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/RealArithmetic/Bench.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-| 3 | Module : Numeric.AERN.RealArithmetic.Bench 4 | Description : benchmarking utilities 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | 12 | Benchmarking utilities. 13 | -} 14 | 15 | module Numeric.AERN.RealArithmetic.Bench where 16 | 17 | import Numeric.AERN.Basics.Consistency 18 | import Numeric.AERN.NumericOrder.Operators 19 | 20 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 21 | 22 | import Numeric.AERN.RealArithmetic.ExactOps 23 | import Numeric.AERN.RealArithmetic.Measures 24 | 25 | import Numeric.AERN.Misc.Debug 26 | 27 | {-| Approximate the imprecision of an operation by measuring 28 | the distance between its outer rounded result and inner rounded result 29 | -} 30 | mkCommentImprecision1 :: 31 | (HasDistance t, 32 | ArithUpDn.Convertible (Distance t) Double, 33 | Show (Distance t)) => 34 | (ei -> t -> t) -> 35 | (ei -> t -> t) -> 36 | ei -> t -> String 37 | mkCommentImprecision1 opOut opIn effort a = 38 | show $ imprecisionD 39 | where 40 | imprecisionD :: Double 41 | imprecisionD = 42 | case ArithUpDn.convertUpEff (ArithUpDn.convertDefaultEffort imprecision sampleD) sampleD imprecision of 43 | Just imprecisionUp -> imprecisionUp 44 | Nothing -> error $ "mkCommentImprecision: cannot convert up to a Double: " ++ show imprecision 45 | sampleD = 0 :: Double 46 | imprecision = distanceBetweenEff (distanceDefaultEffort resultOut) resultOut resultIn 47 | resultOut = opOut effort a 48 | resultIn = opIn effort a 49 | 50 | mkCommentAreaImprecision op effort a = 51 | unsafePrint 52 | ( 53 | "mkCommentImprecision: " 54 | ++ "\n a = " ++ show a 55 | ++ "\n effort = " ++ show effort 56 | ++ "\n aE = " ++ show aE 57 | ++ "\n aD = " ++ show aD 58 | ++ "\n aExp = " ++ show aExp 59 | ++ "\n resultE = " ++ show resultE 60 | ++ "\n imprecisionE = " ++ show imprecisionE 61 | ++ "\n imprecisionD = " ++ show imprecisionD 62 | ++ "\n imprecisionExp = " ++ show imprecisionExp 63 | ++ "\n resultBinaryDigits = " ++ show resultBinaryDigits 64 | ) $ 65 | signOfaE ++ "x" ++ show aExp ++ "rd" ++ show resultBinaryDigits 66 | where 67 | signOfaE = 68 | case (aE >? zero, aE "+" 70 | (_, Just True) -> "-" 71 | _ -> "" 72 | aE = getThinRepresentative a 73 | Just aD = 74 | ArithUpDn.convertUpEff (ArithUpDn.convertDefaultEffort a sampleD) sampleD aE 75 | aExp = exponent aD 76 | 77 | resultE = op effort aE 78 | Just resultD = 79 | ArithUpDn.convertUpEff (ArithUpDn.convertDefaultEffort a sampleD) sampleD resultE 80 | resultExp = exponent resultD 81 | 82 | imprecisionE = 83 | imprecisionOfEff (imprecisionDefaultEffort a) resultE 84 | Just imprecisionD = 85 | ArithUpDn.convertUpEff (ArithUpDn.convertDefaultEffort imprecisionE sampleD) sampleD imprecisionE 86 | imprecisionExp = exponent imprecisionD 87 | 88 | resultBinaryDigits = resultExp - imprecisionExp 89 | 90 | imprecisionD, aD, resultD, sampleD :: Double 91 | sampleD = 0 92 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/RefinementOrder/IntervalLike.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-| 4 | Module : Numeric.AERN.RefinementOrder.IntervalLike 5 | Description : types with endpoints 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Types whose values have endpoints. 14 | -} 15 | 16 | module Numeric.AERN.RefinementOrder.IntervalLike where 17 | 18 | import Numeric.AERN.RefinementOrder.PartialComparison 19 | 20 | import Numeric.AERN.Basics.Exception 21 | import Numeric.AERN.Basics.Effort 22 | import Numeric.AERN.Basics.Laws.RoundedOperation 23 | 24 | import Numeric.AERN.Misc.Bool 25 | import Numeric.AERN.Misc.Maybe 26 | 27 | import Data.Maybe 28 | 29 | import Test.QuickCheck 30 | import Test.Framework (testGroup, Test) 31 | import Test.Framework.Providers.QuickCheck2 (testProperty) 32 | 33 | class 34 | (EffortIndicator (GetEndpointsEffortIndicator t), 35 | EffortIndicator (FromEndpointsEffortIndicator t)) 36 | => 37 | IntervalLike t 38 | where 39 | type GetEndpointsEffortIndicator t 40 | type FromEndpointsEffortIndicator t 41 | getEndpointsDefaultEffort :: t -> GetEndpointsEffortIndicator t 42 | fromEndpointsDefaultEffort :: t -> FromEndpointsEffortIndicator t 43 | -- getEndpointsInEff :: (GetEndpointsEffortIndicator t) -> t -> (t,t) 44 | -- getEndpointsInEff makes no sense as the endpoints are "thin" 45 | -- and an it makes little sense to approximate them inwards. 46 | getEndpointsOutEff :: (GetEndpointsEffortIndicator t) -> t -> (t,t) 47 | fromEndpointsInEff :: (FromEndpointsEffortIndicator t) -> (t,t) -> t 48 | fromEndpointsOutEff :: (FromEndpointsEffortIndicator t) -> (t,t) -> t 49 | 50 | -- versions with default effort 51 | --getEndpointsIn :: (IntervalLike t) => t -> (t,t) 52 | --getEndpointsIn a = getEndpointsInEff (getEndpointsDefaultEffort a) a 53 | getEndpointsOut :: (IntervalLike t) => t -> (t,t) 54 | getEndpointsOut a = getEndpointsOutEff (getEndpointsDefaultEffort a) a 55 | fromEndpointsIn :: (IntervalLike t) => (t,t) -> t 56 | fromEndpointsIn p@(l,r) = fromEndpointsInEff (fromEndpointsDefaultEffort l) p 57 | fromEndpointsOut :: (IntervalLike t) => (t,t) -> t 58 | fromEndpointsOut p@(l,r) = fromEndpointsOutEff (fromEndpointsDefaultEffort l) p 59 | 60 | propEndpointsFromGet :: 61 | (IntervalLike t, Show t, 62 | HasLegalValues t, PartialComparison t) 63 | => 64 | t -> 65 | (GetEndpointsEffortIndicator t) -> 66 | (FromEndpointsEffortIndicator t) -> 67 | (PartialCompareEffortIndicator t) -> 68 | t -> Bool 69 | propEndpointsFromGet _ effGet effFrom effComp e = 70 | outerFromGet && innerFromGet 71 | where 72 | outerFromGet = 73 | leqIfDefined "outer (from.get) endpoints" (pLeqEff effComp) 74 | (fromEndpointsOutEff effFrom $ getEndpointsOutEff effGet e) e 75 | innerFromGet = 76 | leqIfDefined "inner (from.get) endpoints" (pLeqEff effComp) 77 | e (fromEndpointsInEff effFrom $ getEndpointsOutEff effGet e) 78 | 79 | testsEndpoints :: 80 | (Arbitrary t, Show t, Eq t, 81 | IntervalLike t, 82 | HasLegalValues t, PartialComparison t) 83 | => 84 | (String, t) -> Test 85 | testsEndpoints (name, sample) = 86 | testGroup (name ++ " consistency flip") 87 | [ 88 | testProperty "interval <-> endpoints" (propEndpointsFromGet sample) 89 | ] 90 | -------------------------------------------------------------------------------- /aern-poly/tests/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-| 3 | Module : Main 4 | Description : run all tests defined in the AERN-Real package 5 | Copyright : (c) Michal Konecny 6 | License : BSD3 7 | 8 | Maintainer : mikkonecny@gmail.com 9 | Stability : experimental 10 | Portability : portable 11 | -} 12 | module Main where 13 | 14 | import Numeric.AERN.Poly.IntPoly 15 | import Numeric.AERN.Poly.IntPoly.Interval 16 | 17 | import Numeric.AERN.RmToRn.New 18 | import Numeric.AERN.RmToRn.Domain 19 | import Numeric.AERN.RmToRn.Laws (testsEval, testsFnNumCompare, testsFieldPointwise) 20 | --import Numeric.AERN.RmToRn.Evaluation 21 | 22 | import Numeric.AERN.RealArithmetic.Basis.Double () 23 | import Numeric.AERN.RealArithmetic.Basis.MPFR () 24 | import Numeric.AERN.Basics.Interval 25 | 26 | -- import Numeric.AERN.RealArithmetic.Interval 27 | -- import Numeric.AERN.RealArithmetic.Interval.Mutable 28 | -- import Numeric.AERN.RealArithmetic.Interval.ElementaryDirect 29 | --import Numeric.AERN.RealArithmetic.Interval.ElementaryFromBasis 30 | --import Numeric.AERN.Basics.Interval 31 | 32 | --import Numeric.AERN.Basics.Consistency 33 | import Numeric.AERN.Basics.Arbitrary 34 | --import qualified Numeric.AERN.NumericOrder as NumOrd 35 | --import qualified Numeric.AERN.RefinementOrder as RefOrd 36 | import Numeric.AERN.RefinementOrder.Operators 37 | 38 | --import Numeric.AERN.RealArithmetic.Measures 39 | --import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 40 | --import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 41 | --import Numeric.AERN.RealArithmetic.RefinementOrderRounding.OpsDefaultEffort 42 | 43 | import Test.Framework (defaultMain, Test) 44 | 45 | --import qualified Data.Map as Map 46 | 47 | --type CF = Interval MPFR 48 | type CF = Interval Double 49 | type Poly = IntPoly String CF 50 | type PI = Interval Poly 51 | 52 | polyTypeName :: String 53 | polyTypeName = "P(DI)" 54 | 55 | polyIntervalTypeName :: String 56 | polyIntervalTypeName = "PI(DI)" 57 | 58 | main :: IO () 59 | main = 60 | do 61 | defaultMain tests 62 | 63 | tests :: [Test] 64 | tests = testsPoly 65 | 66 | testsPoly :: [Test] 67 | testsPoly = 68 | [ 69 | testsEval (polyTypeName, samplePoly) areaPoly 70 | , 71 | testsEval (polyIntervalTypeName, samplePI) areaPI 72 | , 73 | testsFnNumCompare (polyTypeName, samplePoly) areaPoly 74 | , 75 | testsFieldPointwise (polyIntervalTypeName, samplePI) areaPI 76 | ] 77 | 78 | areaPI :: Area PI 79 | areaPI = (areaPoly, AreaMaybeAllowOnlyWithConsistencyStatus Nothing) 80 | 81 | areaPoly :: Area Poly 82 | areaPoly = areaWhole samplePoly 83 | 84 | --sampleD = 1 :: Double 85 | sampleI :: Integer 86 | sampleI = 1 87 | sampleR :: Rational 88 | sampleR = 1 89 | 90 | samplePoly :: Poly 91 | samplePoly = newConstFn limits varDoms 0 92 | 93 | samplePI :: PI 94 | samplePI = Interval samplePoly samplePoly 95 | 96 | limits :: IntPolySizeLimits CF 97 | limits = 98 | (defaultIntPolySizeLimits 0 () 2) 99 | { 100 | ipolylimits_cf_limits = (), 101 | ipolylimits_maxdeg = 4, 102 | ipolylimits_maxsize = 30 103 | } 104 | 105 | varDoms :: [(Var Poly, CF)] 106 | varDoms = zip vars doms 107 | 108 | vars :: [Var Poly] 109 | vars = ["x", "y"] 110 | 111 | doms :: [CF] 112 | doms = [(0 1), 0 1] 113 | 114 | --doms = [(0 1)] 115 | --vars = ["x"] 116 | -------------------------------------------------------------------------------- /aern-poly/aern-poly.cabal: -------------------------------------------------------------------------------- 1 | Name: aern-poly 2 | Version: 0.5.0 3 | Cabal-Version: >= 1.8 4 | Build-Type: Simple 5 | License: BSD3 6 | License-File: LICENCE 7 | Author: Michal Konecny (Aston University) 8 | Copyright: (c) 2010 Michal Konecny 9 | Maintainer: mikkonecny@gmail.com 10 | Homepage: http://code.google.com/p/aern/ 11 | Stability: experimental 12 | Category: Data, Math 13 | Synopsis: arbitrary precision real interval arithmetic 14 | Tested-with: GHC==7.6.3 15 | Description: Multi-variate polynomials with in-out-rounded point-wise arithmetic 16 | and common operations for continous functions, including evalution, 17 | composition and integration. 18 | Any in-out-rounded real approximation can be used as coefficients. 19 | (Typically the coefficients are intervals with Double or MPFR endpoints.) 20 | . 21 | These polynomials typically encode function enclosures with two polynomial 22 | boundaries. 23 | 24 | Library 25 | hs-source-dirs: src 26 | ghc-options: -Wall -rtsopts 27 | Build-Depends: 28 | base >= 4.4, 29 | containers >= 0.3, 30 | QuickCheck >= 2.4, 31 | aern-order == 0.5.*, 32 | aern-real == 0.5.*, 33 | aern-interval == 0.5.*, 34 | aern-realfn == 0.5.* 35 | exposed-modules: Numeric.AERN.Poly.IntPoly, 36 | Numeric.AERN.Poly.IntPoly.Interval 37 | other-modules: 38 | Numeric.AERN.Poly.IntPoly.Addition, 39 | Numeric.AERN.Poly.IntPoly.Composition, 40 | Numeric.AERN.Poly.IntPoly.Config, 41 | Numeric.AERN.Poly.IntPoly.Conversion, 42 | Numeric.AERN.Poly.IntPoly.Differentiation, 43 | Numeric.AERN.Poly.IntPoly.Evaluation, 44 | Numeric.AERN.Poly.IntPoly.IntPoly, 45 | Numeric.AERN.Poly.IntPoly.Integration, 46 | Numeric.AERN.Poly.IntPoly.Minmax, 47 | Numeric.AERN.Poly.IntPoly.Multiplication, 48 | Numeric.AERN.Poly.IntPoly.Division, 49 | Numeric.AERN.Poly.IntPoly.New, 50 | Numeric.AERN.Poly.IntPoly.NumericOrder, 51 | Numeric.AERN.Poly.IntPoly.Reduction, 52 | Numeric.AERN.Poly.IntPoly.RefinementOrder, 53 | Numeric.AERN.Poly.IntPoly.Show, 54 | Numeric.AERN.Poly.IntPoly.SpecialConst, 55 | Numeric.AERN.Poly.IntPoly.Elementary, 56 | Numeric.AERN.Poly.IntPoly.UpDnField 57 | 58 | executable testAERN-Poly 59 | Build-Depends: 60 | base >= 4.4, 61 | containers >= 0.3, 62 | QuickCheck >= 2.4, 63 | test-framework >= 0.3.3, 64 | test-framework-quickcheck2 >= 0.2, 65 | aern-order == 0.5.*, 66 | aern-real == 0.5.*, 67 | aern-interval == 0.5.*, 68 | aern-double == 0.5.*, 69 | aern-mpfr == 0.5.*, 70 | aern-realfn == 0.5.*, 71 | aern-poly == 0.5.* 72 | hs-source-dirs: tests 73 | ghc-options: -Wall -rtsopts 74 | main-is: Main.hs 75 | 76 | executable minimal 77 | build-depends: 78 | base >= 4.4, 79 | containers >= 0.3, 80 | aern-order == 0.5.*, 81 | aern-real == 0.5.*, 82 | aern-interval == 0.5.*, 83 | aern-double == 0.5.*, 84 | aern-realfn == 0.5.*, 85 | aern-poly == 0.5.* 86 | hs-source-dirs: 87 | demos 88 | ghc-options: -Wall -rtsopts 89 | main-is: minimal.hs 90 | 91 | -------------------------------------------------------------------------------- /aern-temp/benchmarks/FnRepComparison/PolynomialApproximation.hs: -------------------------------------------------------------------------------- 1 | module PolynomialApproximation where 2 | 3 | import FunctionAbstraction 4 | 5 | import Numeric.AERN.RmToRn 6 | 7 | import Numeric.AERN.Poly.IntPoly 8 | 9 | import Numeric.AERN.MPFRBasis.Interval 10 | 11 | import qualified Numeric.AERN.RefinementOrder as RefOrd (fromEndpointsOut) 12 | import Numeric.AERN.RealArithmetic.Measures (imprecisionOf) 13 | import Numeric.AERN.Basics.Effort 14 | 15 | type Poly = IntPoly String MI 16 | 17 | {-| An effective real function of one variable. 18 | The Int parameter @n@ gives the following bound on the width 19 | of the resulting polynomial enclosure: @ <= 2^(-n)@ 20 | -} 21 | newtype PolyReal = PolyReal (Int -> Poly) 22 | 23 | instance RF PolyReal where 24 | build = buildPolyReal 25 | evalMI = evalMIPolyReal 26 | 27 | buildPolyReal :: (Rational, Rational) -> Expression -> PolyReal 28 | buildPolyReal (lRat, rRat) expr = PolyReal $ aux expr 29 | where 30 | aux (ExprLit aRat) n = 31 | newConstFn limits varDoms aMI 32 | where 33 | aMI = aSeq !! n 34 | aSeq = fromRationalWithIncreasingAccuracy aRat 35 | (limits, varDoms) = buildLimitsVarDoms n (getPrec aMI) 36 | aux (ExprVar) n = 37 | newProjection limits varDoms "x" 38 | where 39 | (limits, varDoms) = buildLimitsVarDoms n 100 40 | 41 | lSeq = fromRationalWithIncreasingAccuracy lRat 42 | rSeq = fromRationalWithIncreasingAccuracy rRat 43 | 44 | buildLimitsVarDoms :: Int -> Precision -> (IntPolySizeLimits MI, [(String, MI)]) 45 | buildLimitsVarDoms n coeffPrecision = 46 | (limits, varDoms) 47 | where 48 | limits = 49 | (defaultIntPolySizeLimits 0 coeffPrecision 1) 50 | { 51 | ipolylimits_maxdeg = 10, 52 | ipolylimits_maxsize = 11 53 | } 54 | varDoms = zip vars doms 55 | where 56 | vars = ["x"] 57 | doms = [RefOrd.fromEndpointsOut (lMI, rMI)] 58 | lMI = lSeq !! n 59 | rMI = rSeq !! n 60 | 61 | 62 | evalMIPolyReal :: PolyReal -> MI -> MI 63 | evalMIPolyReal (PolyReal polySeq) x = 64 | -- evaluate on successive polynomials until: 65 | -- - the accuracy of the result has not improved significantly several times in a row (how many times?) 66 | -- - significant improvement = 67 | -- for non-exact x: improvement of at least 1% of width of x 68 | -- for exact x: improvement of at least 69 | undefined -- TODO 70 | 71 | fromRationalWithIncreasingAccuracy :: Rational -> [MI] 72 | fromRationalWithIncreasingAccuracy a = 73 | adjustRate (0 :: Int) $ 74 | map withPrec precisionSequence 75 | where 76 | withPrec p = fromRationalWithPrec p a 77 | precisionSequence = effortIncrementSequence initPrec 78 | where 79 | initPrec = 50 80 | adjustRate i l@(h : t) 81 | | hAccurateEnough = h : (adjustRate (i+1) l) 82 | | otherwise = adjustRate i t 83 | where 84 | hAccurateEnough 85 | | i == 0 = 86 | (imprecisionOf h <=? one) == Just True 87 | -- this case is required to avoid the following trap: 88 | -- two^^(0) = 1 with MPFR precision 100 89 | | otherwise = 90 | (imprecisionOf h <=? two^^(-i)) == Just True 91 | where 92 | one = fromRationalWithPrec (getPrec h) 1 93 | two = fromRationalWithPrec (getPrec h) 2 94 | adjustRate _ _ = error "internal error in fromRationalWithIncreasingAccuracy" 95 | 96 | -------------------------------------------------------------------------------- /aern-mpfr-rounded/demos/Minimal.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ExistentialQuantification #-} 2 | 3 | module Main where 4 | 5 | import Numeric.AERN.Basics.Effort 6 | 7 | import qualified Numeric.AERN.NumericOrder as NumOrd 8 | import Numeric.AERN.NumericOrder.Operators 9 | 10 | import qualified Numeric.AERN.RefinementOrder as RefOrd 11 | import Numeric.AERN.RefinementOrder.Operators 12 | 13 | import Numeric.AERN.RealArithmetic.ExactOps 14 | 15 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 16 | import Numeric.AERN.RealArithmetic.NumericOrderRounding.Operators 17 | 18 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 19 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 20 | 21 | import Numeric.AERN.RealArithmetic.Basis.MPFR 22 | import Numeric.AERN.RealArithmetic.Interval.MPFR 23 | --import Numeric.AERN.RealArithmetic.Interval.ElementaryFromBasis 24 | import Numeric.AERN.RealArithmetic.Interval.ElementaryFromFieldOps 25 | 26 | import Numeric.AERN.Basics.Interval 27 | import Numeric.AERN.Basics.ShowInternals 28 | import Numeric.AERN.Basics.SizeLimits 29 | 30 | import Control.Concurrent 31 | 32 | main = 33 | do 34 | putStrLn $ "oo - oo = " ++ showInternals shouldShowInternals inftyMinusInftyOut 35 | putStrLn $ "00 = " ++ showInternals shouldShowInternals zeroOverZeroOut 36 | putStrLn $ "0>/<0 = " ++ showInternals shouldShowInternals zeroOverZeroIn 37 | putStrLn $ "exp 1 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp1efforts) 38 | putStrLn $ "exp 3 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp3efforts) 39 | putStrLn $ "exp 10 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp10efforts) 40 | putStrLn $ "exp 100 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp100efforts) 41 | putStrLn $ "exp 1000 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp1000efforts) 42 | return () 43 | 44 | shouldShowInternals = (Just 100, False) 45 | 46 | precision :: MPFRPrec 47 | precision = 100 48 | 49 | sample :: MI 50 | sample = sampleMIWithPrec precision 51 | 52 | inftyMinusInftyOut :: MI 53 | inftyMinusInftyOut = 54 | plusInfinity sample <-> plusInfinity sample 55 | 56 | zeroOverZeroOut :: MI 57 | zeroOverZeroOut = 58 | zero sample zero sample 59 | 60 | zeroOverZeroIn :: MI 61 | zeroOverZeroIn = 62 | zero sample >/< zero sample 63 | 64 | oneOverZeroOut :: MI 65 | oneOverZeroOut = 66 | one sample zero sample 67 | 68 | oneOverZeroIn :: MI 69 | oneOverZeroIn = 70 | one sample >/< zero sample 71 | 72 | exp1efforts :: [MI] 73 | exp1efforts = 74 | map (\n -> ArithInOut.expOutEff (expEffort n) (one sample)) [1..20] 75 | 76 | exp3efforts :: [MI] 77 | exp3efforts = 78 | map (\n -> ArithInOut.expOutEff (expEffort n) three) [1..20] 79 | 80 | exp10efforts :: [MI] 81 | exp10efforts = 82 | map (\n -> ArithInOut.expOutEff (expEffort n) ten) [1..20] 83 | 84 | exp100efforts :: [MI] 85 | exp100efforts = 86 | map (\n -> ArithInOut.expOutEff (expEffort n) hundred) [1..20] 87 | 88 | exp1000efforts :: [MI] 89 | exp1000efforts = 90 | map (\n -> ArithInOut.expOutEff (expEffort n) thousand) [1..20] 91 | 92 | three, ten, hundred, thousand :: MI 93 | 94 | [three, ten, hundred, thousand] = 95 | map (ArithInOut.convertOutEff () sample) ([3,10,100,1000] :: [Int]) 96 | 97 | 98 | expEffort n = 99 | expEffortDefault 100 | { 101 | expeff_taylorDeg = n 102 | } 103 | 104 | expEffortDefault = 105 | ArithInOut.expDefaultEffort three 106 | 107 | 108 | -------------------------------------------------------------------------------- /aern-mpfr/demos/Minimal.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ExistentialQuantification #-} 2 | 3 | module Main where 4 | 5 | import Numeric.AERN.Basics.Effort 6 | 7 | import qualified Numeric.AERN.NumericOrder as NumOrd 8 | import Numeric.AERN.NumericOrder.Operators 9 | 10 | import qualified Numeric.AERN.RefinementOrder as RefOrd 11 | import Numeric.AERN.RefinementOrder.Operators 12 | 13 | import Numeric.AERN.RealArithmetic.ExactOps 14 | 15 | import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn 16 | import Numeric.AERN.RealArithmetic.NumericOrderRounding.Operators 17 | 18 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 19 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators 20 | 21 | import Numeric.AERN.RealArithmetic.Basis.MPFR 22 | import Numeric.AERN.RealArithmetic.Interval.MPFR 23 | --import Numeric.AERN.RealArithmetic.Interval.ElementaryFromBasis 24 | import Numeric.AERN.RealArithmetic.Interval.ElementaryFromFieldOps 25 | 26 | import Numeric.AERN.Basics.Interval 27 | import Numeric.AERN.Basics.ShowInternals 28 | import Numeric.AERN.Basics.SizeLimits 29 | 30 | import Control.Concurrent 31 | 32 | main = 33 | do 34 | putStrLn $ "oo - oo = " ++ showInternals shouldShowInternals inftyMinusInftyOut 35 | putStrLn $ "00 = " ++ showInternals shouldShowInternals zeroOverZeroOut 36 | putStrLn $ "0>/<0 = " ++ showInternals shouldShowInternals zeroOverZeroIn 37 | putStrLn $ "exp 1 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp1efforts) 38 | putStrLn $ "exp 3 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp3efforts) 39 | putStrLn $ "exp 10 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp10efforts) 40 | putStrLn $ "exp 100 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp100efforts) 41 | putStrLn $ "exp 1000 = \n" ++ (unlines $ map (showInternals shouldShowInternals) exp1000efforts) 42 | return () 43 | 44 | shouldShowInternals = (30,False) 45 | 46 | precision :: Precision 47 | precision = 100 48 | 49 | sample :: MI 50 | sample = changeSizeLimitsDnEff () precision 0 51 | 52 | inftyMinusInftyOut :: MI 53 | inftyMinusInftyOut = 54 | plusInfinity sample <-> plusInfinity sample 55 | 56 | zeroOverZeroOut :: MI 57 | zeroOverZeroOut = 58 | zero sample zero sample 59 | 60 | zeroOverZeroIn :: MI 61 | zeroOverZeroIn = 62 | zero sample >/< zero sample 63 | 64 | oneOverZeroOut :: MI 65 | oneOverZeroOut = 66 | one sample zero sample 67 | 68 | oneOverZeroIn :: MI 69 | oneOverZeroIn = 70 | one sample >/< zero sample 71 | 72 | exp1efforts :: [MI] 73 | exp1efforts = 74 | map (\n -> ArithInOut.expOutEff (expEffort n) (one sample)) [1..20] 75 | 76 | exp3efforts :: [MI] 77 | exp3efforts = 78 | map (\n -> ArithInOut.expOutEff (expEffort n) three) [1..20] 79 | 80 | exp10efforts :: [MI] 81 | exp10efforts = 82 | map (\n -> ArithInOut.expOutEff (expEffort n) ten) [1..20] 83 | 84 | exp100efforts :: [MI] 85 | exp100efforts = 86 | map (\n -> ArithInOut.expOutEff (expEffort n) hundred) [1..20] 87 | 88 | exp1000efforts :: [MI] 89 | exp1000efforts = 90 | map (\n -> ArithInOut.expOutEff (expEffort n) thousand) [1..20] 91 | 92 | three, ten, hundred, thousand :: MI 93 | 94 | [three, ten, hundred, thousand] = 95 | map (ArithInOut.convertOutEff precision sample) ([3,10,100,1000] :: [Int]) 96 | 97 | 98 | expEffort n = 99 | expEffortDefault 100 | { 101 | expeff_taylorDeg = n 102 | } 103 | 104 | expEffortDefault = 105 | ArithInOut.expDefaultEffort three 106 | 107 | 108 | -------------------------------------------------------------------------------- /aern-realfn/src/Numeric/AERN/RmToRn/RefinementOrderRounding/BernsteinPoly.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE ScopedTypeVariables #-} 3 | {-| 4 | Module : Numeric.AERN.RmToRn.RefinementOrderRounding.BernsteinPoly 5 | Description : approximations of Bernstein polynomials 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Approximations of Bernstein polynomials. 14 | -} 15 | 16 | module Numeric.AERN.RmToRn.RefinementOrderRounding.BernsteinPoly where 17 | 18 | import Numeric.AERN.RmToRn.Domain (HasDomainBox(..)) 19 | 20 | import Numeric.AERN.RealArithmetic.ExactOps (HasOne(..)) 21 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 22 | 23 | --import Numeric.AERN.Misc.IntegerArithmetic 24 | 25 | import Debug.Trace 26 | _ = trace 27 | 28 | bernsteinOut :: 29 | (HasDomainBox f, HasOne f, 30 | ArithInOut.RoundedRing f, 31 | ArithInOut.RoundedMixedMultiply f (Domain f), 32 | ArithInOut.RoundedReal (Domain f), 33 | Show f, Show (Domain f)) 34 | => 35 | (ArithInOut.RingOpsEffortIndicator f, 36 | ArithInOut.RoundedRealEffortIndicator (Domain f), 37 | ArithInOut.MixedMultEffortIndicator f (Domain f)) 38 | {-^ Effort indicators to guide the effort used for approximately computing the Bernstein polynomial -} -> 39 | f {-^ @x@ - a function to substitute in the Bernstein polynomial -} -> 40 | Int {-^ @n@ - the degree of the Bernstein polynomial -} -> 41 | Int {-^ @p@ - the index of the Bernstein polynomial -} -> 42 | f {-^ @b_{p,n}(x)@ - The Bernstein polynomial of degree @n@ and index @p@ -} 43 | bernsteinOut (effRingF, effRealD, effMultFD) x n p = 44 | -- trace 45 | -- ( 46 | -- "bernsteinOut:" 47 | -- ++ "\n x = " ++ show x 48 | -- ++ "\n n = " ++ show n 49 | -- ++ "\n p = " ++ show p 50 | -- ++ "\n (n p) = " ++ show binomialOut 51 | -- ++ "\n result = " ++ show result 52 | -- ) 53 | result 54 | where 55 | result = 56 | (binomialOut) .<*>~ 57 | ((x ~<^> p) ~<*>~ ((c1 ~<->~ x) ~<^> (n-p))) 58 | binomialOut 59 | | 0 <= p && p <= n = 60 | productNdownP .. factorialP 61 | | otherwise = 62 | error $ 63 | "bernsteinOut called with illegal parameters:" 64 | ++ "\n n = " ++ show n 65 | ++ "\n p = " ++ show p 66 | where 67 | factorialP = 68 | foldl (.<*>|) (one sampleD) [2..p] 69 | productNdownP = 70 | foldl (.<*>|) (one sampleD) [(n-p+1)..n] 71 | 72 | c1 = (one sampleF) 73 | sampleF = x 74 | sampleD = getSampleDomValue sampleF 75 | 76 | -- (~<+>~) = ArithInOut.addOutEff effAddF 77 | (~<->~) = ArithInOut.subtrOutEff effAddF 78 | (~<*>~) = ArithInOut.multOutEff effMultF 79 | (~<^>) = ArithInOut.powerToNonnegIntOutEff effPowF 80 | (.<*>~) = flip $ ArithInOut.mixedMultOutEff effMultFD 81 | 82 | (..) = ArithInOut.divOutEff effDivD 83 | (.<*>|) = ArithInOut.mixedMultOutEff effMultIntD 84 | 85 | effAddF = ArithInOut.ringEffortAdd sampleF effRingF 86 | effMultF = ArithInOut.ringEffortMult sampleF effRingF 87 | effPowF = ArithInOut.ringEffortPow sampleF effRingF 88 | effDivD = 89 | ArithInOut.fldEffortDiv sampleD $ 90 | ArithInOut.rrEffortField sampleD effRealD 91 | effMultIntD = 92 | ArithInOut.mxfldEffortMult sampleD (1::Int) $ 93 | ArithInOut.rrEffortIntMixedField sampleD effRealD 94 | 95 | 96 | -------------------------------------------------------------------------------- /aern-real/aern-real.cabal: -------------------------------------------------------------------------------- 1 | Name: aern-real 2 | Version: 0.5.0 3 | Cabal-Version: >= 1.8 4 | Build-Type: Simple 5 | License: BSD3 6 | License-File: LICENCE 7 | Author: Michal Konecny 8 | Copyright: (c) 2012 Michal Konecny, Jan Duracz 9 | Maintainer: mikkonecny@gmail.com 10 | Homepage: http://code.google.com/p/aern/ 11 | Stability: experimental 12 | Category: Data, Math 13 | Synopsis: arbitrary precision real interval arithmetic 14 | Tested-with: 15 | GHC==7.6.3 16 | Description: 17 | Type classes abstracting typical approximate real number arithmetic operations 18 | including rounded 19 | field operations and common elementary operations. 20 | Two kinds of rounding are supported: rounding up/down in the numerical order 21 | or rounding in/out in a refinement order. 22 | . 23 | A concrete implementation of in-out-rounded operations 24 | is given for intervals in the package aern-interval. 25 | Concrete implementations of up-down-rounded operations is 26 | given in aern-double for ordinary 'Double' 27 | fixed-precision numbers and in aern-mpfr for arbitary precision 28 | floating-point numbers. These numbers can serve as interval endpoints. 29 | . 30 | /This package does not compile with ghc 7.0.* due to a/ 31 | /compiler bug that has been fixed for the 7.2.1 release./ 32 | 33 | source-repository head 34 | type: mercurial 35 | location: http://code.google.com/p/aern/aern-real 36 | 37 | source-repository this 38 | type: mercurial 39 | location: http://code.google.com/p/aern/aern-real 40 | tag: release-0.5.0 41 | 42 | 43 | Library 44 | hs-source-dirs: src concepts 45 | ghc-options: -Wall 46 | Build-Depends: 47 | base >= 4.4, 48 | QuickCheck >= 2.4, 49 | test-framework >= 0.3.3, 50 | test-framework-quickcheck2 >= 0.2, 51 | criterion >= 0.5, 52 | aern-order == 0.5.* 53 | Exposed-modules: 54 | Numeric.AERN.Misc.IntegerArithmetic, 55 | Numeric.AERN.RealArithmetic.Auxiliary, 56 | Numeric.AERN.RealArithmetic.Bench, 57 | Numeric.AERN.RealArithmetic.ExactOps, 58 | Numeric.AERN.RealArithmetic.Laws, 59 | Numeric.AERN.RealArithmetic.Measures, 60 | Numeric.AERN.RealArithmetic.NumericOrderRounding, 61 | Numeric.AERN.RealArithmetic.NumericOrderRounding.Operators, 62 | Numeric.AERN.RealArithmetic.NumericOrderRounding.ElementaryFromFieldOps.Sqrt, 63 | Numeric.AERN.RealArithmetic.RefinementOrderRounding, 64 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.Operators, 65 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.ElementaryFromFieldOps.Exponentiation, 66 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.ElementaryFromFieldOps.SineCosine 67 | Other-modules: 68 | BinaryOpsSimplified, 69 | Numeric.AERN.RealArithmetic.NumericOrderRounding.Conversion, 70 | Numeric.AERN.RealArithmetic.NumericOrderRounding.Elementary, 71 | Numeric.AERN.RealArithmetic.NumericOrderRounding.FieldOps, 72 | Numeric.AERN.RealArithmetic.NumericOrderRounding.SpecialConst, 73 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.Conversion, 74 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.Elementary, 75 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.FieldOps, 76 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.MixedFieldOps, 77 | Numeric.AERN.RealArithmetic.RefinementOrderRounding.SpecialConst, 78 | Numeric.AERN.RealArithmetic.NumericOrderRounding.MixedFieldOps 79 | 80 | -------------------------------------------------------------------------------- /aern-real/src/Numeric/AERN/RealArithmetic/ExactOps.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Numeric.AERN.RealArithmetic.ExactOps 3 | Description : access to exact zero and one 4 | Copyright : (c) Michal Konecny, Jan Duracz 5 | License : BSD3 6 | 7 | Maintainer : mikkonecny@gmail.com 8 | Stability : experimental 9 | Portability : portable 10 | 11 | Access to exact zero and one. 12 | -} 13 | module Numeric.AERN.RealArithmetic.ExactOps where 14 | 15 | import Prelude hiding (EQ, LT, GT) 16 | import Numeric.AERN.Basics.PartialOrdering 17 | 18 | import Control.Monad.ST 19 | import Data.STRef 20 | 21 | import qualified Numeric.AERN.NumericOrder as NumOrd 22 | 23 | import Data.Ratio 24 | 25 | class HasSampleFromContext t where 26 | sampleFromContext :: t 27 | 28 | class HasZero t where 29 | zero :: t -> t 30 | 31 | pNonnegNonposEff effort a = 32 | (nonneg, nonpos) 33 | where 34 | (_, nonneg, _, nonpos) = 35 | pPosNonnegNegNonposEff effort a 36 | 37 | pPosNonnegNegNonposEff effort a = 38 | (infoGT, infoGEQ, infoLT, infoLEQ) 39 | where 40 | info = NumOrd.pCompareInFullEff effort a (zero a) 41 | infoLT = pOrdInfLT info 42 | infoGT = pOrdInfGT info 43 | infoLEQ = pOrdInfLEQ info 44 | infoGEQ = pOrdInfGEQ info 45 | 46 | class HasOne t where 47 | one :: t -> t 48 | 49 | class HasInfinities t where 50 | plusInfinity :: t -> t 51 | minusInfinity :: t -> t 52 | excludesPlusInfinity :: t -> Bool 53 | excludesMinusInfinity :: t -> Bool 54 | excludesInfinity :: t -> Bool 55 | excludesInfinity a = 56 | excludesMinusInfinity a && excludesPlusInfinity a 57 | 58 | class Neg t where 59 | neg :: t -> t 60 | 61 | propNegFlip :: 62 | (Eq t, Neg t) => 63 | t -> t -> Bool 64 | propNegFlip _ e = 65 | neg (neg e) == e 66 | 67 | -- instances for some common types: 68 | 69 | instance HasSampleFromContext Int where sampleFromContext = 0 70 | instance HasZero Int where zero _ = 0 71 | instance HasOne Int where one _ = 1 72 | instance Neg Int where neg = negate 73 | 74 | instance HasSampleFromContext Integer where sampleFromContext = 0 75 | instance HasZero Integer where zero _ = 0 76 | instance HasOne Integer where one _ = 1 77 | instance Neg Integer where neg = negate 78 | 79 | instance (HasSampleFromContext t, HasOne t, Integral t) => 80 | HasSampleFromContext (Ratio t) 81 | where 82 | sampleFromContext = sampleN % (one sampleN) 83 | where 84 | sampleN = sampleFromContext 85 | instance (HasZero t, HasOne t, Integral t) => 86 | HasZero (Ratio t) 87 | where 88 | zero sample = (zero sampleN) % (one sampleN) 89 | where 90 | sampleN = numerator sample 91 | instance (HasOne t, Integral t) => 92 | HasOne (Ratio t) 93 | where 94 | one sample = (one sampleN) % (one sampleN) 95 | where 96 | sampleN = numerator sample 97 | instance (Integral t) => Neg (Ratio t) where neg = negate 98 | 99 | instance HasSampleFromContext Double where sampleFromContext = 0 100 | instance HasZero Double where zero _ = 0 101 | instance HasOne Double where one _ = 1 102 | instance Neg Double where neg = negate 103 | 104 | instance HasInfinities Double where 105 | plusInfinity _ = 1/0 106 | minusInfinity _ = -1/0 107 | excludesPlusInfinity a = (a /= (plusInfinity a)) 108 | excludesMinusInfinity a = (a /= (minusInfinity a)) 109 | 110 | instance HasSampleFromContext Char 111 | where 112 | sampleFromContext = 'S' 113 | instance HasSampleFromContext t => HasSampleFromContext [t] 114 | where 115 | sampleFromContext = [sampleFromContext] 116 | -------------------------------------------------------------------------------- /aern-poly/src/Numeric/AERN/Poly/IntPoly/Elementary.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-orphans #-} 2 | {-# LANGUAGE TypeFamilies #-} 3 | {-# LANGUAGE FlexibleContexts #-} 4 | {-# LANGUAGE UndecidableInstances #-} 5 | {-| 6 | Module : Numeric.AERN.Poly.IntPoly.Elementary 7 | Description : out-rounded exp, sine, cosine etc on IntPoly 8 | Copyright : (c) Michal Konecny 9 | License : BSD3 10 | 11 | Maintainer : mikkonecny@gmail.com 12 | Stability : experimental 13 | Portability : portable 14 | 15 | Outwards-rounded exp, sine, cosine etc on IntPoly. Works only with relatively thin IntPolys. 16 | -} 17 | 18 | module Numeric.AERN.Poly.IntPoly.Elementary 19 | -- ( 20 | -- ) 21 | where 22 | 23 | import Numeric.AERN.Poly.IntPoly.IntPoly 24 | import Numeric.AERN.Poly.IntPoly.Conversion 25 | import Numeric.AERN.Poly.IntPoly.Addition 26 | import Numeric.AERN.Poly.IntPoly.Multiplication 27 | import Numeric.AERN.Poly.IntPoly.New () 28 | import Numeric.AERN.Poly.IntPoly.Show () 29 | 30 | import Numeric.AERN.RmToRn.New 31 | import Numeric.AERN.RmToRn.Domain 32 | 33 | import qualified 34 | Numeric.AERN.RealArithmetic.RefinementOrderRounding 35 | as ArithInOut 36 | 37 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.ElementaryFromFieldOps.SineCosine 38 | 39 | import qualified 40 | Numeric.AERN.RealArithmetic.NumericOrderRounding 41 | as ArithUpDn 42 | 43 | import Numeric.AERN.RealArithmetic.NumericOrderRounding.ElementaryFromFieldOps.Sqrt 44 | 45 | import Numeric.AERN.RealArithmetic.ExactOps 46 | 47 | --import Numeric.AERN.RealArithmetic.Interval () 48 | 49 | import Numeric.AERN.Basics.Interval 50 | import Numeric.AERN.Basics.SizeLimits 51 | 52 | 53 | import qualified 54 | Numeric.AERN.RefinementOrder 55 | as RefOrd 56 | --import Numeric.AERN.RefinementOrder.OpsDefaultEffort 57 | 58 | import Numeric.AERN.Basics.Consistency 59 | 60 | instance 61 | (Ord var, Show var, 62 | cf ~ Interval e, 63 | ArithInOut.RoundedReal cf, 64 | HasAntiConsistency cf, 65 | Show cf, Show (SizeLimits cf)) 66 | => 67 | ArithInOut.RoundedSineCosineEffort (IntPoly var cf) 68 | where 69 | type SineCosineEffortIndicator (IntPoly var cf) = 70 | SineCosineThinEffortIndicator (IntPoly var cf) cf 71 | sincosDefaultEffort sampleP = 72 | sineCosineThinDefaultEffort sampleP sampleCf 3 73 | where 74 | sampleCf = getSampleDomValue sampleP 75 | 76 | instance 77 | (Ord var, Show var, 78 | cf ~ Interval e, 79 | real ~ IntPoly var cf, 80 | ArithInOut.RoundedReal cf, 81 | HasAntiConsistency cf, 82 | ArithInOut.RoundedAdd real, 83 | ArithInOut.RoundedMultiply real, 84 | ArithInOut.RoundedPowerToNonnegInt real, 85 | Show cf, Show (SizeLimits cf)) 86 | => 87 | ArithInOut.RoundedSineCosine (IntPoly var cf) 88 | where 89 | sinOutEff eff p = sineTaylorAt0 eff sampleCf p 90 | where 91 | sampleCf = getSampleDomValue p 92 | cosOutEff eff p = cosineTaylorAt0 eff sampleCf p 93 | where 94 | sampleCf = getSampleDomValue p 95 | 96 | instance 97 | (Ord var, Show var, 98 | cf ~ Interval e, 99 | real ~ IntPoly var cf, 100 | ArithUpDn.RoundedReal real, 101 | ArithInOut.RoundedReal cf, 102 | HasAntiConsistency cf, 103 | Show cf, Show (SizeLimits cf)) 104 | => 105 | ArithInOut.RoundedSquareRootEffort (IntPoly var cf) 106 | where 107 | type SqrtEffortIndicator (IntPoly var cf) = 108 | SqrtThinEffortIndicator (IntPoly var cf) 109 | sqrtDefaultEffort sampleP = 110 | sqrtThinDefaultEffort sampleP 5 111 | 112 | -------------------------------------------------------------------------------- /aern-ivp/demos/demoPicardView.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Numeric.AERN.RmToRn.Basis.Polynomial.IntPoly 4 | 5 | import qualified Numeric.AERN.RmToRn.Plot.PicardView as PV 6 | import Numeric.AERN.RmToRn.Plot.CairoDrawable 7 | 8 | import Numeric.AERN.RmToRn.New 9 | import Numeric.AERN.RmToRn.Evaluation 10 | 11 | import Numeric.AERN.RealArithmetic.Basis.Double 12 | --import Numeric.AERN.RealArithmetic.Basis.MPFR 13 | import Numeric.AERN.Basics.Interval 14 | 15 | import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut 16 | import Numeric.AERN.RealArithmetic.RefinementOrderRounding.OpsDefaultEffort 17 | 18 | import Numeric.AERN.RealArithmetic.ExactOps 19 | 20 | import qualified Numeric.AERN.RefinementOrder as RefOrd 21 | import Numeric.AERN.RefinementOrder.OpsDefaultEffort 22 | 23 | import qualified Numeric.AERN.NumericOrder as NumOrd 24 | import Numeric.AERN.NumericOrder.OpsDefaultEffort 25 | 26 | import Numeric.AERN.Basics.Consistency 27 | import Numeric.AERN.Basics.ShowInternals 28 | 29 | import Numeric.AERN.Misc.Debug 30 | 31 | import qualified Graphics.UI.Gtk as Gtk 32 | 33 | import qualified Control.Concurrent as Concurrent 34 | import Control.Concurrent.STM 35 | 36 | import qualified Data.Map as Map 37 | import qualified Data.List as List 38 | 39 | 40 | --type CF = Interval MPFR 41 | type CF = Interval Double 42 | type Poly = IntPoly String CF 43 | 44 | main = 45 | do 46 | -- Gtk.initGUI 47 | -- enable multithreaded GUI: 48 | Gtk.unsafeInitGUIForThreadedRTS 49 | Gtk.timeoutAddFull 50 | (Concurrent.yield >> Concurrent.yield >> Concurrent.yield >> return True) 51 | Gtk.priorityDefaultIdle 20 52 | -- putStrLn "plot main: calling PV.new" 53 | let ivp = ivpPendulum 54 | PV.new samplePoly effDrawFn eff eff ivp Nothing 55 | -- putStrLn "plot main: PV.new completed" 56 | Gtk.mainGUI 57 | 58 | ivpPendulum :: PV.IVP Poly 59 | ivpPendulum = 60 | PV.IVP 61 | { 62 | PV.ivpInitialValues = [cf0], 63 | PV.ivpVectorField = id 64 | } 65 | 66 | showP p = showPoly id show p -- ++ " [" ++ show p ++ "]" 67 | 68 | c1,c0,x,c01,c10,cHalf,cHalf1,cOneOver16,cSevenOver16,cOneMinusOneOver16, samplePoly :: Poly 69 | x = newProjection cfg dombox "x" 70 | c0 = newConstFn cfg dombox 0 71 | c1 = newConstFn cfg dombox 1 72 | cHalf = newConstFn cfg dombox 0.5 73 | cHalf1 = newConstFn cfg dombox $ 0.5 1 74 | cOneOver16 = newConstFn cfg dombox $ 0.5^4 75 | cSevenOver16 = newConstFn cfg dombox $ 7 * 0.5^4 76 | cOneMinusOneOver16 = newConstFn cfg dombox $ 15 * 0.5^4 77 | c01 = newConstFn cfg dombox $ 0 1 78 | c10 = newConstFn cfg dombox $ 1 <\/> 0 79 | 80 | samplePoly = x 81 | 82 | --eff = (100, (100,())) -- MPFR 83 | eff = ArithInOut.roundedRealDefaultEffort (0:: CF) 84 | effNumComp = NumOrd.pCompareDefaultEffort x 85 | effRefComp = RefOrd.pCompareDefaultEffort x 86 | minmaxUpDnEff = minmaxUpDnDefaultEffortIntPolyWithBezierDegree 10 x 87 | minmaxInOutEff = minmaxInOutDefaultEffortIntPolyWithBezierDegree 10 x 88 | effDrawFn = cairoDrawFnDefaultEffort samplePoly 89 | 90 | 91 | evalOpsOutCf = evalOpsOut eff x (0::CF) 92 | 93 | cfg = 94 | IntPolyCfg 95 | { 96 | ipolycfg_vars = vars, 97 | ipolycfg_domsLZ = doms, 98 | ipolycfg_domsLE = replicate (length vars) (0 :: CF), 99 | ipolycfg_sample_cf = 0 :: CF, 100 | ipolycfg_maxdeg = 4, 101 | ipolycfg_maxsize = 30 102 | } 103 | 104 | dombox = Map.fromList $ zip vars doms 105 | 106 | vars = ["x"] 107 | 108 | doms :: [CF] 109 | doms = [(0 1)] 110 | 111 | constructCF :: Double -> Double -> CF 112 | constructCF l r = 113 | RefOrd.fromEndpointsOut (cf0 <+>| l, cf0 <+>| r) 114 | cf0 = 0 :: CF 115 | -------------------------------------------------------------------------------- /aern-order/src/Numeric/AERN/Basics/Consistency.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeFamilies #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-| 4 | Module : Numeric.AERN.Basics.Consistency 5 | Description : types with consistent and inconsistent values 6 | Copyright : (c) Michal Konecny 7 | License : BSD3 8 | 9 | Maintainer : mikkonecny@gmail.com 10 | Stability : experimental 11 | Portability : portable 12 | 13 | Types with consistent and inconsistent values. 14 | -} 15 | 16 | module Numeric.AERN.Basics.Consistency where 17 | 18 | import Numeric.AERN.Basics.Effort 19 | 20 | import Numeric.AERN.Misc.Bool 21 | import Numeric.AERN.Misc.Maybe 22 | 23 | import Data.Maybe 24 | 25 | import Test.QuickCheck 26 | import Test.Framework (testGroup, Test) 27 | import Test.Framework.Providers.QuickCheck2 (testProperty) 28 | 29 | data ConsistencyStatus = 30 | Inconsistent -- ie neither Consistent nor Anticonsistent 31 | | Consistent 32 | | Anticonsistent 33 | | Exact -- ie both Consistent and Anticonsistent 34 | deriving (Eq, Show) 35 | 36 | class 37 | (EffortIndicator (ConsistencyEffortIndicator t)) 38 | => 39 | HasConsistency t 40 | where 41 | type ConsistencyEffortIndicator t 42 | consistencyDefaultEffort :: t -> ConsistencyEffortIndicator t 43 | getConsistencyEff :: (ConsistencyEffortIndicator t) -> t -> Maybe ConsistencyStatus 44 | isConsistentEff :: (ConsistencyEffortIndicator t) -> t -> Maybe Bool 45 | isConsistentEff eff e = 46 | case getConsistencyEff eff e of 47 | Just Consistent -> Just True 48 | Just Exact -> Just True 49 | Just _ -> Just False 50 | _ -> Nothing 51 | isExactEff :: (ConsistencyEffortIndicator t) -> t -> Maybe Bool 52 | isExactEff eff e = 53 | case getConsistencyEff eff e of 54 | Just Exact -> Just True 55 | Just _ -> Just False 56 | _ -> Nothing 57 | 58 | isExact :: (HasConsistency t) => t -> Maybe Bool 59 | isExact e = 60 | isExactEff (consistencyDefaultEffort e) e 61 | 62 | class (HasConsistency t) => HasAntiConsistency t where 63 | isAntiConsistentEff :: (ConsistencyEffortIndicator t) -> t -> Maybe Bool 64 | isAntiConsistentEff eff e = 65 | case getConsistencyEff eff e of 66 | Just Anticonsistent -> Just True 67 | Just Exact -> Just True 68 | Just _ -> Just False 69 | _ -> Nothing 70 | flipConsistency :: t -> t 71 | 72 | class HasThinRepresentative t where 73 | -- get a value that is both consistent and anticonsistent 74 | -- as well as close to the argument value 75 | getThinRepresentative :: t -> t 76 | 77 | propFlipConsistency :: 78 | (HasAntiConsistency t, Eq t) => t -> (ConsistencyEffortIndicator t) -> t -> Bool 79 | propFlipConsistency _ effort e = 80 | (defined eConsistent && defined eFAntiConsistent) 81 | ===> 82 | (fromJust eConsistent <===> fromJust eFAntiConsistent) 83 | where 84 | eF = flipConsistency e 85 | eConsistent = isConsistentEff effort e 86 | eFAntiConsistent = isAntiConsistentEff effort eF 87 | 88 | propConsistencyFlipSelfInverse :: 89 | (HasAntiConsistency t, Eq t) => t -> t -> Bool 90 | propConsistencyFlipSelfInverse _ e = 91 | e == (flipConsistency $ flipConsistency e) 92 | 93 | testsConsistency :: 94 | (Arbitrary t, Show t, Eq t, 95 | HasAntiConsistency t) 96 | => 97 | (String, t) -> Test 98 | testsConsistency (name, sample) = 99 | testGroup (name ++ " consistency flip") 100 | [ 101 | testProperty "con<->anticon" (propFlipConsistency sample) 102 | , 103 | testProperty "self inverse" (propConsistencyFlipSelfInverse sample) 104 | ] 105 | --------------------------------------------------------------------------------