packages feed

aern2-real 0.2.11.0 → 0.2.12.0

raw patch · 3 files changed

+87/−4 lines, 3 files

Files

aern2-real.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.35.0. -- -- see: https://github.com/sol/hpack  name:           aern2-real-version:        0.2.11.0+version:        0.2.12.0 synopsis:       Real numbers as convergent sequences of intervals description:    Please see the README on GitHub at <https://github.com/michalkonecny/aern2/#readme> category:       Math@@ -13,7 +13,7 @@ bug-reports:    https://github.com/michalkonecny/aern2/issues author:         Michal Konecny maintainer:     mikkonecny@gmail.com-copyright:      2015-2021 Michal Konecny+copyright:      2015-2023 Michal Konecny license:        BSD3 license-file:   LICENSE build-type:     Simple
changelog.md view
@@ -1,5 +1,9 @@ # Change log for aern2-real +* current+* v 0.2.12 2023-04-07+  * more instances for if-then-else with CKleenean+  * or_countable and and_countable for CKleenean * v 0.2.11 2022-08-25   * left-first and/or for CKleeneans * v 0.2.10 2022-08-20
src/AERN2/Real/CKleenean.hs view
@@ -13,7 +13,7 @@ -} module AERN2.Real.CKleenean (-  CKleenean, CanBeCKleenean, ckleenean+  CKleenean, CanBeCKleenean, ckleenean, CanAndOrCountable(..) ) where @@ -54,6 +54,54 @@   and2 = lift2LeftFirst and2   or2 = lift2LeftFirst or2 +instance (CanAndOrAsymmetric Bool t2) => CanAndOrAsymmetric Bool (CSequence t2) where+  type AndOrType Bool  (CSequence t2) = CSequence (AndOrType Bool t2)+  and2 = liftT1 and2+  or2 = liftT1 or2++instance (CanAndOrAsymmetric Kleenean t2) => CanAndOrAsymmetric Kleenean (CSequence t2) where+  type AndOrType Kleenean  (CSequence t2) = CSequence (AndOrType Kleenean t2)+  and2 = liftT1 and2+  or2 = liftT1 or2++instance (CanAndOrAsymmetric t1 Bool) => CanAndOrAsymmetric (CSequence t1) Bool where+  type AndOrType (CSequence t1)  Bool = CSequence (AndOrType t1 Bool)+  and2 = lift1T and2+  or2 = lift1T or2++instance (CanAndOrAsymmetric t1 Kleenean) => CanAndOrAsymmetric (CSequence t1) Kleenean where+  type AndOrType (CSequence t1)  Kleenean = CSequence (AndOrType t1 Kleenean)+  and2 = lift1T and2+  or2 = lift1T or2++class CanAndOrCountable t where+  or_countable :: (Integer -> t) -> t+  and_countable :: (Integer -> t) -> t++instance +  CanAndOrCountable CKleenean+  where+  or_countable = lift_countable or2+  and_countable = lift_countable and2++lift_countable :: (CN Kleenean -> CN Kleenean -> CN Kleenean) -> (Integer -> CKleenean) -> CKleenean+lift_countable op s = CSequence $ map withFuel [0..]+    where+    withFuel n = +      -- try the n'th result of the first n CKleenean's+      -- s00  s01 ... *s0n*+      -- s10  s11 ... *s1n*+      -- ...  ...     ...+      -- sn0  sn1 ... *snn*+      (foldl op (cn TrueOrFalse) (map ((!! n) . unCSequence . s) [0..(n-1)]))+      `op`+      -- try first n results of the n'th CKleenean+      -- .  s00    s01  ...  s0n+      -- .  s10    s11  ...  s1n+      -- .  ...    ...       ...+      -- . *sn0*  *sn1* ... *snn*+      (foldl op (cn TrueOrFalse) (take (n+1) (unCSequence $ s n)))+ instance CanSelect CKleenean where   type SelectType CKleenean = CN Bool   select (CSequence s1) (CSequence s2) = aux s1 s2@@ -74,3 +122,34 @@   ifThenElse (CSequence sc) (CSequence s1) (CSequence s2) = (CSequence r)     where     r = zipWith3 ifThenElse sc s1 s2++instance (HasIfThenElse CKleenean t1, HasIfThenElse CKleenean t2) =>+  HasIfThenElse CKleenean (t1, t2)+  where+  type IfThenElseType CKleenean (t1, t2) = (IfThenElseType CKleenean t1, IfThenElseType CKleenean t2)+  ifThenElse s (a1, b1) (a2, b2) =+    (ifThenElse s a1 a2, ifThenElse s b1 b2)++instance (HasIfThenElse CKleenean t) =>+  HasIfThenElse CKleenean (Maybe t)+  where+  type IfThenElseType CKleenean (Maybe t) = Maybe (IfThenElseType CKleenean t)+  ifThenElse _s Nothing Nothing = Nothing+  ifThenElse s (Just v1) (Just v2) = Just (ifThenElse s v1 v2)+  ifThenElse _ _ _ = +    error "ifThenElse with a sequence of Kleeneans and Maybe: branches clash: Just vs Nothing"++instance (HasIfThenElse CKleenean t) =>+  HasIfThenElse CKleenean [t]+  where+  type IfThenElseType CKleenean [t] = [IfThenElseType CKleenean t]+  ifThenElse _s [] [] = []+  ifThenElse s (h1:t1) (h2:t2) = (ifThenElse s h1 h2) : (ifThenElse s t1 t2)+  ifThenElse _ _ _ = +    error "ifThenElse with a sequence of Kleeneans and lists: branches clash: lists of different lengths"++instance (HasIfThenElse CKleenean v) =>+  HasIfThenElse CKleenean (k -> v)+  where+  type IfThenElseType CKleenean (k -> v) = k -> (IfThenElseType CKleenean v)+  ifThenElse s f1 f2 = \k -> ifThenElse s (f1 k) (f2 k)