diff options
| author | Simon-Kor <52245124+Simon-Kor@users.noreply.github.com> | 2024-05-28 17:36:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-28 17:36:49 +0200 |
| commit | 68598ccc2e420376a790b31b93efa7f18f91edf6 (patch) | |
| tree | 6ca3ecd36d8d84ea7153d74cab73361052d03565 | |
| parent | 266529fa1271a942920845072efb588c64c4aba3 (diff) | |
| parent | a08c4b2d7a7135029a588df542c18fdf07725075 (diff) | |
Merge pull request #2 from adelon/main
changes from main needs to be included
| -rw-r--r-- | latex/naproche.sty | 4 | ||||
| -rw-r--r-- | library/set.tex | 19 | ||||
| -rw-r--r-- | library/set/filter.tex | 64 | ||||
| -rw-r--r-- | library/set/powerset.tex | 16 | ||||
| -rw-r--r-- | library/topology/basis.tex | 36 | ||||
| -rw-r--r-- | library/topology/topological-space.tex | 10 | ||||
| -rw-r--r-- | source/Api.hs | 2 | ||||
| -rw-r--r-- | source/Syntax/Adapt.hs | 12 | ||||
| -rw-r--r-- | source/Syntax/Concrete/Keywords.hs | 4 | ||||
| -rw-r--r-- | source/Syntax/Token.hs | 60 |
10 files changed, 149 insertions, 78 deletions
diff --git a/latex/naproche.sty b/latex/naproche.sty index cb65fe7..476d3dd 100644 --- a/latex/naproche.sty +++ b/latex/naproche.sty @@ -11,7 +11,8 @@ % command for importing theories, no visible rendering \newcommand{\import}[1]{} \newcommand{\explanation}[1]{\quad\text{[#1]}} - +\usepackage{pbox} +\newcommand{\textbox}[1]{\pbox{28em}{#1}} @@ -87,6 +88,7 @@ \newcommand{\fld}[1]{\fun{field}#1} \newcommand{\fst}[1]{\fun{fst}#1} \newcommand{\funs}[2]{\fun{Fun}(#1,#2)} +\newcommand{\genOpens}[2]{\mathcal{O}_{#2}(#1)} \newcommand{\idempotents}[1]{\fun{Idempotent}(#1)} \newcommand{\identity}[1]{\fun{id}_{#1}} \newcommand{\img}[2]{#1^{\to}(#2)} diff --git a/library/set.tex b/library/set.tex index 33e5af4..2fd18ea 100644 --- a/library/set.tex +++ b/library/set.tex @@ -131,8 +131,7 @@ which applies it to goals of the form “$A = B$” and “$A \neq B$”. If $x$ and $y$ are empty, then $x = y$. \end{proposition} -\begin{proposition}% -\label{emptyset_subseteq} +\begin{proposition}\label{emptyset_subseteq} For all $a$ we have $\emptyset \subseteq a$. % LATER $\emptyset$ is a subset of every set. \end{proposition} @@ -266,8 +265,7 @@ The $\operatorname{\textsf{cons}}$ operation is determined by the following axio There exists $B\in C$ such that $A\in B$. \end{proof} -\begin{proposition}% -\label{unions_emptyset} +\begin{proposition}\label{unions_emptyset} $\unions{\emptyset} = \emptyset$. \end{proposition} @@ -553,13 +551,7 @@ The $\operatorname{\textsf{cons}}$ operation is determined by the following axio Follows by set extensionality. \end{proof} -\begin{proposition}% -\label{inter_subseteq} - $A\inter B\subseteq A$. -\end{proposition} - -\begin{proposition}% -\label{inter_emptyset} +\begin{proposition}\label{inter_emptyset} $A\inter\emptyset = \emptyset$. \end{proposition} \begin{proof} @@ -620,6 +612,11 @@ The $\operatorname{\textsf{cons}}$ operation is determined by the following axio Follows by set extensionality. \end{proof} +\begin{proposition}\label{inter_subseteq} + Suppose $A,B\subseteq C$. + Then $A\inter B\subseteq C$. +\end{proposition} + \begin{abbreviation}\label{closedunderinter} $T$ is closed under binary intersections iff for every $U,V\in T$ we have $U\inter V\in T$. diff --git a/library/set/filter.tex b/library/set/filter.tex index 2797d86..4537b81 100644 --- a/library/set/filter.tex +++ b/library/set/filter.tex @@ -3,6 +3,8 @@ \section{Filters} +\subsection{Definition and basic properties of filters} + \begin{abbreviation}\label{upwardclosed} $F$ is upward-closed in $S$ iff for all $A, B$ such that $A\subseteq B\subseteq S$ and $A\in F$ we have $B\in F$. @@ -11,21 +13,71 @@ \begin{definition}\label{filter} $F$ is a filter on $S$ iff $F$ is a family of subsets of $S$ - and $S$ is inhabited and $S\in F$ and $\emptyset\notin F$ and $F$ is closed under binary intersections and $F$ is upward-closed in $S$. \end{definition} +\begin{proposition}\label{filter_ext_complement} + Let $F, G$ be filters on $S$. + Suppose for all $A\subseteq S$ we have $S\setminus A\in F$ iff $S\setminus A\in G$. + Then $F = G$. +\end{proposition} +\begin{proof} + Follows by set extensionality. +\end{proof} + +\begin{proposition}\label{filter_inter_in_iff} + Let $F$ be a filter on $S$. + Suppose $A, B\subseteq S$. + Then $A\inter B\in F$ iff $A, B\in F$. +\end{proposition} +\begin{proof} + We have $A\inter B\subseteq A, B$. + Follows by \cref{filter}. +\end{proof} + +\begin{proposition}\label{filter_setminus_in} + Let $F$ be a filter on $S$. + Suppose $A\in F$. + Suppose $B\subseteq S$ and $S\setminus B\in F$. + Then $A\setminus B\in F$. +\end{proposition} +\begin{proof} + We have $A\subseteq S$. + Thus $A\setminus B = A\inter (S\setminus B)$ by \cref{setminus_eq_inter_complement}. + Now $S\setminus B\subseteq S$. + Follows by \cref{filter_inter_in_iff}. +\end{proof} + +\begin{proposition}\label{filter_in_iff_exists_subset} + Let $F$ be a filter on $S$. + Suppose $B\subseteq S$. + Then $B\in F$ iff there exists $A\subseteq B$ such that $A\in F$. +\end{proposition} + + +\subsection{Principal filters over a set} + \begin{definition}\label{principalfilter} $\principalfilter{S}{A} = \{X\in\pow{S}\mid A\subseteq X\}$. \end{definition} -%\begin{proposition}\label{principalfilter_domain_inhabited} -% Suppose $F$ is a filter on $S$. -% Then $S$ is inhabited. -%\end{proposition} +\begin{proposition}\label{principalfilter_iff} + Suppose $A, B\subseteq S$. + Then $B\in\principalfilter{S}{A}$ iff $A\subseteq B$. +\end{proposition} + +\begin{proposition}\label{principalfilter_bottom} + Suppose $A\subseteq S$. + Then $A\in\principalfilter{S}{A}$. +\end{proposition} + +\begin{proposition}\label{principalfilter_top} + Suppose $A\subseteq S$. + Then $S\in\principalfilter{S}{A}$. +\end{proposition} \begin{proposition}\label{principalfilter_is_filter} Suppose $A\subseteq S$. @@ -55,8 +107,6 @@ Suppose $X\notin\principalfilter{S}{A}$. Then $A\not\subseteq X$. \end{proposition} -\begin{proof} -\end{proof} \begin{definition}\label{maximalfilter} $F$ is a maximal filter on $S$ iff diff --git a/library/set/powerset.tex b/library/set/powerset.tex index 80da4cb..ec5866f 100644 --- a/library/set/powerset.tex +++ b/library/set/powerset.tex @@ -6,8 +6,7 @@ The powerset of $X$ denotes $\pow{X}$. \end{abbreviation} -\begin{axiom}% -\label{pow_iff} +\begin{axiom}\label{pow_iff} $B\in\pow{A}$ iff $B\subseteq A$. \end{axiom} @@ -47,6 +46,17 @@ Follows by \cref{pow_iff,unions_subseteq_of_powerset_is_subseteq}. \end{proof} + +\begin{proposition}\label{inter_powerset} + Let $A,B\in\pow{C}$. + Then $A\inter B\in\pow{C}$. +\end{proposition} +\begin{proof} + We have $A,B\subseteq C$ by \cref{pow_iff}. + $A\inter B\subseteq C$ by \cref{inter_subseteq}. + Follows by \cref{pow_iff}. +\end{proof} + \begin{proposition}\label{unions_powerset} $\unions{\pow{A}} = A$. \end{proposition} @@ -76,7 +86,7 @@ % LATER %\begin{proposition}\label{powerset_cons} -% Then $\pow{\cons{b}{A}} = \pow{A}\union \{\cons{b}{B}\mid B\in\pow{A}\}$. +% $\pow{\cons{b}{A}} = \pow{A}\union \{\cons{b}{B}\mid B\in\pow{A}\}$. %\end{proposition} \begin{proposition}\label{powerset_union_subseteq} diff --git a/library/topology/basis.tex b/library/topology/basis.tex index 6fc07d3..6fa9fbd 100644 --- a/library/topology/basis.tex +++ b/library/topology/basis.tex @@ -47,8 +47,8 @@ \end{definition} \begin{definition}\label{genopens} - $\genOpens{B}{X} = \{ U\in\pow{X} \mid \text{for all $x\in U$ there exists $V\in B$ - such that $x\in V\subseteq U$} \}$. + $\genOpens{B}{X} = \left\{ U\in\pow{X} \middle| \textbox{for all $x\in U$ there exists $V\in B$ + \\ such that $x\in V\subseteq U$}\right\}$. \end{definition} \begin{lemma}\label{emptyset_in_genopens} @@ -75,32 +75,25 @@ \end{proof} - - \begin{lemma}\label{inters_in_genopens} Assume $B$ is a topological basis for $X$. - Suppose $A, C\in \genOpens{B}{X}$. - + Assume $A, C\in \genOpens{B}{X}$. Then $(A\inter C) \in \genOpens{B}{X}$. \end{lemma} \begin{proof} - - Show $(A \inter C) \in \pow{X}$. - \begin{subproof} - Omitted. - \end{subproof} - + + We have $(A \inter C) \in \pow{X}$ by \cref{genopens,inter_powerset}. + Show for all $x\in (A\inter C)$ there exists $W \in B$ such that $x\in W$ and $W \subseteq (A\inter C)$. \begin{subproof} Fix $x \in (A\inter C)$. - $x \in A,C$. - There exist $V' \in B$ such that $x \in V'$ and $V' \subseteq A$ by \cref{genopens}. - There exist $V'' \in B$ such that $x \in V''$ and $V'' \subseteq C$ by \cref{genopens}. - $x \in (V' \inter V'')$. - There exist $W \in B$ such that $x \in W$ and $W \subseteq V'$ and $W \subseteq V''$. - + Then $x\in A,C$. + There exists $V' \in B$ such that $x \in V' \subseteq A$ by \cref{genopens}. + There exists $V'' \in B$ such that $x \in V''\subseteq C$ by \cref{genopens}. + There exists $W \in B$ such that $x \in W$ and $W \subseteq V'$ and $W \subseteq V''$. + Show $W \subseteq (A\inter C)$. \begin{subproof} %$W \subseteq v'$ and $W \subseteq V''$. @@ -111,11 +104,4 @@ %such that $x\in W$ and $W \subseteq (A\inter C)$. $(A\inter C) \in \genOpens{B}{X}$. - - \end{proof} - - - - - diff --git a/library/topology/topological-space.tex b/library/topology/topological-space.tex index e467d48..2bbdf09 100644 --- a/library/topology/topological-space.tex +++ b/library/topology/topological-space.tex @@ -11,7 +11,6 @@ such that \begin{enumerate} \item\label{opens_type} $\opens[X]$ is a family of subsets of $\carrier[X]$. - \item\label{emptyset_open} $\emptyset\in\opens[X]$. \item\label{carrier_open} $\carrier[X]\in\opens[X]$. \item\label{opens_inter} For all $A, B\in \opens[X]$ we have $A\inter B\in\opens[X]$. \item\label{opens_unions} For all $F\subseteq \opens[X]$ we have $\unions{F}\in\opens[X]$. @@ -26,6 +25,15 @@ $U$ is open in $X$ iff $U\in\opens[X]$. \end{abbreviation} +\begin{proposition}\label{emptyset_open} + Let $X$ be a topological space. + Then $\emptyset$ is open in $X$. +\end{proposition} +\begin{proof} + We have $\unions{\emptyset} = \emptyset\subseteq\opens[X]$ by \cref{unions_emptyset,emptyset_subseteq}. + Follows by \cref{opens_unions}. +\end{proof} + \begin{proposition}\label{union_open} Let $X$ be a topological space. Suppose $A$, $B$ are open. diff --git a/source/Api.hs b/source/Api.hs index 421a8eb..95d5c8c 100644 --- a/source/Api.hs +++ b/source/Api.hs @@ -94,7 +94,7 @@ findAndReadFile path = do homeDir <- getHomeDirectory currentDir <- getCurrentDirectory userLib <- (?? (homeDir </> "formalizations")) <$> lookupEnv "NAPROCHE_LIB" - srcLib <- (?? (homeDir </> "code/zf/library")) <$> lookupEnv "NAPROCHE_SCR_LIB" + srcLib <- (?? (homeDir </> "code/naproche-zf/library")) <$> lookupEnv "NAPROCHE_SCR_LIB" existsCurrent <- doesFileExist (currentDir </> path) existsUserLib <- doesFileExist (userLib </> path) diff --git a/source/Syntax/Adapt.hs b/source/Syntax/Adapt.hs index b1237d2..3a8b3d6 100644 --- a/source/Syntax/Adapt.hs +++ b/source/Syntax/Adapt.hs @@ -26,10 +26,14 @@ scanChunk ltoks = let toks = unLocated <$> ltoks matchOrErr re env pos = match re toks ?? error ("could not find lexical pattern in " <> env <> " at " <> sourcePosPretty pos) in case ltoks of - Located pos (BeginEnv "definition") : _ -> matchOrErr definition "definition" pos - Located pos (BeginEnv "abbreviation") : _ -> matchOrErr abbreviation "abbreviation" pos - Located pos (BeginEnv "struct") :_ -> matchOrErr struct "struct definition" pos - Located pos (BeginEnv "inductive") :_ -> matchOrErr inductive "inductive definition" pos + Located{startPos = pos, unLocated = BeginEnv "definition"} : _ -> + matchOrErr definition "definition" (pos) + Located{startPos = pos, unLocated = BeginEnv "abbreviation"} : _ -> + matchOrErr abbreviation "abbreviation" pos + Located{startPos = pos, unLocated = (BeginEnv "struct")} :_ -> + matchOrErr struct "struct definition" pos + Located{startPos = pos, unLocated = (BeginEnv "inductive")} :_ -> + matchOrErr inductive "inductive definition" pos _ -> [] adaptChunks :: [[Located Token]] -> Lexicon -> Lexicon diff --git a/source/Syntax/Concrete/Keywords.hs b/source/Syntax/Concrete/Keywords.hs index e0f577e..135cdac 100644 --- a/source/Syntax/Concrete/Keywords.hs +++ b/source/Syntax/Concrete/Keywords.hs @@ -203,7 +203,7 @@ _haveIntro = _thus <|> _particularly <|> _have _colon :: Prod r Text (Located Token) SourcePos _colon = symbol ":" ? ":" _pipe :: Prod r Text (Located Token) SourcePos -_pipe = symbol "|" <|> command "mid" ? "\\mid" +_pipe = (optional (command "middle") *> symbol "|") <|> command "mid" ? "\\mid" _comma :: Prod r Text (Located Token) SourcePos _comma = symbol "," ? "," _commaAnd :: Prod r Text (Located Token) SourcePos @@ -219,4 +219,4 @@ _eq = symbol "=" ? "=" _in :: Prod r Text (Located Token) SourcePos _in = symbol "∈" <|> command "in" ? "\\in" _subseteq :: Prod r Text (Located Token) SourcePos -_subseteq = command "subseteq" ? ":" +_subseteq = command "subseteq" ? "\\subseteq" diff --git a/source/Syntax/Token.hs b/source/Syntax/Token.hs index 1d13693..cb3f4cb 100644 --- a/source/Syntax/Token.hs +++ b/source/Syntax/Token.hs @@ -164,8 +164,17 @@ instance Pretty Token where data Located a = Located { startPos :: !SourcePos , unLocated :: !a + , postWhitespace :: Whitespace } deriving (Show) +data Whitespace = NoSpace | Space deriving (Show) + +collapseWhitespace :: [Whitespace] -> Whitespace +collapseWhitespace = \case + Space : _ -> Space + NoSpace : ws -> collapseWhitespace ws + [] -> NoSpace + instance Eq a => Eq (Located a) where (==) = (==) `on` unLocated instance Ord a => Ord (Located a) where compare = compare `on` unLocated @@ -178,32 +187,32 @@ toks = whitespace *> goNormal id <* eof r <- optional tok case r of Nothing -> pure (f []) - Just t@(Located _ (BeginEnv "math")) -> goMath (f . (t:)) - Just t@(Located _ (BeginEnv "align*")) -> goMath (f . (t:)) + Just t@Located{unLocated = BeginEnv "math"} -> goMath (f . (t:)) + Just t@Located{unLocated = BeginEnv "align*"} -> goMath (f . (t:)) Just t -> goNormal (f . (t:)) goText f = do r <- optional textToken case r of Nothing -> pure (f []) - Just t@(Located _ (BeginEnv "math")) -> goMathInText (f . (t:)) - Just t@(Located _ (EndEnv "text")) -> goMath (f . (t:)) - Just t@(Located _ (EndEnv "explanation")) -> goMath (f . (t:)) + Just t@Located{unLocated = BeginEnv "math"} -> goMathInText (f . (t:)) + Just t@Located{unLocated = EndEnv "text"} -> goMath (f . (t:)) + Just t@Located{unLocated = EndEnv "explanation"} -> goMath (f . (t:)) Just t -> goText (f . (t:)) goMath f = do r <- optional mathToken case r of Nothing -> pure (f []) - Just t@(Located _ (EndEnv "math")) -> goNormal (f . (t:)) - Just t@(Located _ (EndEnv "align*")) -> goNormal (f . (t:)) - Just t@(Located _ (BeginEnv "text")) -> goText (f . (t:)) - Just t@(Located _ (BeginEnv "explanation")) -> goText (f . (t:)) + Just t@Located{unLocated = EndEnv "math"} -> goNormal (f . (t:)) + Just t@Located{unLocated = EndEnv "align*"} -> goNormal (f . (t:)) + Just t@Located{unLocated = BeginEnv "text"} -> goText (f . (t:)) + Just t@Located{unLocated = BeginEnv "explanation"} -> goText (f . (t:)) Just t -> goMath (f . (t:)) goMathInText f = do r <- optional mathToken case r of Nothing -> pure (f []) - Just t@(Located _ (EndEnv "math")) -> goText (f . (t:)) - Just t@(Located _ (BeginEnv "text")) -> goText (f . (t:)) + Just t@(Located{unLocated = EndEnv "math"}) -> goText (f . (t:)) + Just t@(Located{unLocated = BeginEnv "text"}) -> goText (f . (t:)) Just t -> goMathInText (f . (t:)) {-# INLINE toks #-} @@ -219,7 +228,7 @@ mathToken = beginText :: Lexer (Located Token) beginText = lexeme do - Char.string "\\text{" + Char.string "\\text{" <|> Char.string "\\textbox{" setTextMode pure (BeginEnv "text") @@ -240,14 +249,14 @@ textToken = word <|> symbol <|> begin <|> end <|> textEnd <|> mathBegin <|> alig setMathMode pure (EndEnv "text") - opening' = lexeme (brace <|> group <|> paren <|> bracket) + opening' = lexeme (group <|> optional (Char.string "\\left") *> (brace <|> paren <|> bracket)) where brace = VisibleBraceL <$ lexeme (Char.string "\\{") group = InvisibleBraceL <$ lexeme (Char.char '{') <* modify' incrNesting paren = ParenL <$ lexeme (Char.char '(') bracket = BracketL <$ lexeme (Char.char '[') - closing' = lexeme (brace <|> group <|> paren <|> bracket) + closing' = lexeme (group <|> optional (Char.string "\\right") *> (brace <|> paren <|> bracket)) where brace = VisibleBraceR <$ lexeme (Char.string "\\}") group = InvisibleBraceR <$ lexeme (Char.char '}') <* modify' decrNesting @@ -408,7 +417,7 @@ end = lexeme do -- | Parses an opening delimiter. opening :: Lexer (Located Token) -opening = lexeme (paren <|> brace <|> group <|> bracket) +opening = lexeme (group <|> optional (Char.string "\\left") *> (paren <|> brace <|> bracket)) where brace = VisibleBraceL <$ lexeme (Char.string "\\{") group = InvisibleBraceL <$ lexeme (Char.char '{') @@ -417,7 +426,7 @@ opening = lexeme (paren <|> brace <|> group <|> bracket) -- | Parses a closing delimiter. closing :: Lexer (Located Token) -closing = lexeme (paren <|> brace <|> group <|> bracket) +closing = lexeme (group <|> optional (Char.string "\\right") *> (paren <|> brace <|> bracket)) where brace = VisibleBraceR <$ lexeme (Char.string "\\}") group = InvisibleBraceR <$ lexeme (Char.char '}') @@ -430,12 +439,17 @@ lexeme :: Lexer a -> Lexer (Located a) lexeme p = do start <- getSourcePos t <- p - whitespace - pure (Located start t) + w <- whitespace + pure (Located start t w) -space :: Lexer () -space = void (Char.char ' ' <|> Char.char '\n' <|> Char.char '\r') - <|> void (Char.string "\\ " <|> Char.string "\\\\" <|> Char.string "\\!" <|> Char.string "\\," <|> Char.string "\\:" <|> Char.string "\\;" <|> Char.string "\\;") +space :: Lexer Whitespace +space = Space <$ (Char.char ' ' <|> Char.char '\n' <|> Char.char '\r') + <|> Space <$ (Char.string "\\ " <|> Char.string "\\\\" <|> Char.string "\\!" <|> Char.string "\\," <|> Char.string "\\:" <|> Char.string "\\;" <|> Char.string "\\;") -whitespace :: Lexer () -whitespace = Lexer.space (void (some space)) (Lexer.skipLineComment "%") empty +whitespace :: Lexer Whitespace +whitespace = do + ws <- many (spaces <|> comment) + pure (collapseWhitespace ws) + where + spaces = collapseWhitespace <$> some space + comment = NoSpace <$ Lexer.skipLineComment "%" |
