Skip to content

Commit cef1445

Browse files
committed
Added new natural number syntax operations
1 parent 5c738c6 commit cef1445

File tree

6 files changed

+456
-68
lines changed

6 files changed

+456
-68
lines changed

src/HOL/Const.hs

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ bit1Name = Name naturalNamespace "bit1"
154154
divName :: Name
155155
divName = Name naturalNamespace "div"
156156

157+
dividesName :: Name
158+
dividesName = Name naturalNamespace "divides"
159+
157160
geName :: Name
158161
geName = Name naturalNamespace ">="
159162

src/HOL/Name.hs

+16-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import qualified Data.Maybe as Maybe
1717
import Data.Set (Set)
1818
import qualified Data.Set as Set
1919

20+
import HOL.Util (mkUnsafe1)
21+
2022
-------------------------------------------------------------------------------
2123
-- Namespaces
2224
-------------------------------------------------------------------------------
@@ -37,18 +39,28 @@ data Name =
3739
-- The global namespace (contains all type and term variable names)
3840
-------------------------------------------------------------------------------
3941

40-
global :: Namespace
41-
global = Namespace []
42+
globalNamespace :: Namespace
43+
globalNamespace = Namespace []
44+
45+
isGlobalNamespace :: Namespace -> Bool
46+
isGlobalNamespace ns = ns == globalNamespace
4247

4348
mkGlobal :: String -> Name
44-
mkGlobal = Name global
49+
mkGlobal = Name globalNamespace
4550

4651
destGlobal :: Name -> Maybe String
47-
destGlobal (Name ns s) = if ns == global then Just s else Nothing
52+
destGlobal (Name ns s) = if isGlobalNamespace ns then Just s else Nothing
53+
54+
destGlobalUnsafe :: Name -> String
55+
destGlobalUnsafe = mkUnsafe1 "HOL.Name.destGlobal" destGlobal
4856

4957
isGlobal :: Name -> Bool
5058
isGlobal = Maybe.isJust . destGlobal
5159

60+
mapGlobal :: (String -> String) -> Name -> Name
61+
mapGlobal f (Name ns s) | isGlobalNamespace ns = Name ns (f s)
62+
mapGlobal _ n = n
63+
5264
-------------------------------------------------------------------------------
5365
-- Fresh names
5466
-------------------------------------------------------------------------------

src/HOL/Print.hs

+11-33
Original file line numberDiff line numberDiff line change
@@ -410,28 +410,6 @@ instance Printable Term where
410410
negationTable =
411411
[(Const.negName, Nothing)]
412412

413-
-------------------------------------------------------------------------
414-
-- Operators of a given arity
415-
-------------------------------------------------------------------------
416-
417-
destUnaryOp :: Term -> Maybe (Const,Term)
418-
destUnaryOp tm = do
419-
(t,x) <- Term.destApp tm
420-
(c,_) <- Term.destConst t
421-
return (c,x)
422-
423-
destBinaryOp :: Term -> Maybe (Const,Term,Term)
424-
destBinaryOp tm = do
425-
(t,y) <- Term.destApp tm
426-
(c,x) <- destUnaryOp t
427-
return (c,x,y)
428-
429-
destTernaryOp :: Term -> Maybe (Const,Term,Term,Term)
430-
destTernaryOp tm = do
431-
(t,z) <- Term.destApp tm
432-
(c,x,y) <- destBinaryOp t
433-
return (c,x,y,z)
434-
435413
-------------------------------------------------------------------------
436414
-- Infix operators
437415
-------------------------------------------------------------------------
@@ -461,7 +439,7 @@ instance Printable Term where
461439

462440
destInfix :: Term -> Maybe (InfixOp,Term,Term)
463441
destInfix tm = do
464-
(c,x,y) <- destBinaryOp tm
442+
(c,x,y) <- Term.destBinaryOp tm
465443
i <- lookupOp (Term.typeOf x) (Const.name c)
466444
return (i,x,y)
467445
where
@@ -492,7 +470,7 @@ instance Printable Term where
492470

493471
destForall :: Term -> Maybe (Var,Term)
494472
destForall tm = do
495-
(c,t) <- destUnaryOp tm
473+
(c,t) <- Term.destUnaryOp tm
496474
(v,b) <- Term.destAbs t
497475
guard (Const.name c == Const.forallName)
498476
return (v,b)
@@ -541,7 +519,7 @@ instance Printable Term where
541519

542520
destQuantifier :: Term -> Maybe (Const,Term,Term)
543521
destQuantifier tm = do
544-
(c,vb) <- destUnaryOp tm
522+
(c,vb) <- Term.destUnaryOp tm
545523
(v,b) <- destAbs vb
546524
return (c,v,b)
547525

@@ -588,7 +566,7 @@ instance Printable Term where
588566

589567
destNegation :: Term -> Maybe (PrefixOp,Term)
590568
destNegation tm = do
591-
(c,t) <- destUnaryOp tm
569+
(c,t) <- Term.destUnaryOp tm
592570
p <- Map.lookup (Const.name c) negations
593571
return (p,t)
594572

@@ -607,7 +585,7 @@ instance Printable Term where
607585

608586
destCond :: Term -> Maybe (Term,Term,Term)
609587
destCond tm = do
610-
(c,x,y,z) <- destTernaryOp tm
588+
(c,x,y,z) <- Term.destTernaryOp tm
611589
guard (Const.name c == Const.condName)
612590
return (x,y,z)
613591

@@ -674,7 +652,7 @@ instance Printable Term where
674652

675653
destFromNatural :: Term -> Maybe Term
676654
destFromNatural tm = do
677-
(c,t) <- destUnaryOp tm
655+
(c,t) <- Term.destUnaryOp tm
678656
guard (Set.member (Const.name c) fromNaturals)
679657
return t
680658

@@ -692,7 +670,7 @@ instance Printable Term where
692670

693671
destBit :: Term -> Maybe (Bool,Term)
694672
destBit tm = do
695-
(c,t) <- destUnaryOp tm
673+
(c,t) <- Term.destUnaryOp tm
696674
fmap (flip (,) t) $ bit (Const.name c)
697675
where
698676
bit n = if n == Const.bit0Name then Just False
@@ -722,7 +700,7 @@ instance Printable Term where
722700

723701
destPair :: Term -> Maybe (Term,Term)
724702
destPair tm = do
725-
(c,x,y) <- destBinaryOp tm
703+
(c,x,y) <- Term.destBinaryOp tm
726704
guard (Const.name c == Const.pairName)
727705
return (x,y)
728706

@@ -744,19 +722,19 @@ instance Printable Term where
744722

745723
destFromPredicate :: Term -> Maybe Term
746724
destFromPredicate tm = do
747-
(c,t) <- destUnaryOp tm
725+
(c,t) <- Term.destUnaryOp tm
748726
guard (Const.name c == Const.fromPredicateName)
749727
return t
750728

751729
destConj :: Term -> Maybe (Term,Term)
752730
destConj tm = do
753-
(c,x,y) <- destBinaryOp tm
731+
(c,x,y) <- Term.destBinaryOp tm
754732
guard (Const.name c == Const.conjName)
755733
return (x,y)
756734

757735
destExists :: Term -> Maybe (Var,Term)
758736
destExists tm = do
759-
(c,t) <- destUnaryOp tm
737+
(c,t) <- Term.destUnaryOp tm
760738
(v,b) <- Term.destAbs t
761739
guard (Const.name c == Const.existsName)
762740
return (v,b)

0 commit comments

Comments
 (0)