Skip to content

Commit c2dba0e

Browse files
committed
Use environment-based coderefs
1 parent 483cae3 commit c2dba0e

33 files changed

Lines changed: 360 additions & 140 deletions

packages/coderefs.sty

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,9 @@
2121
}
2222
}
2323

24-
\cs_new_protected:Nn \nb_coderef_write:n
24+
\NewDocumentCommand \ManualCodeRef {v}
2525
{
26-
\begin{displayquote}
27-
\small
28-
\texttt{#1}
29-
\normalsize
30-
\end{displayquote}
31-
}
32-
33-
\NewDocumentCommand \WriteCodeRefText {v}
34-
{
35-
\nb_coderef_write:n {#1}
36-
}
37-
38-
\NewDocumentCommand \WriteCodeRef {m}
39-
{
40-
\nb_coderef_write:n {\GetCodeRef{#1}}
26+
#1
4127
}
4228

4329
\NewDocumentEnvironment {CodeRefDisplay} {}

text/binomial_coefficients.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ \section{Binomial coefficients}\label{sec:binomial_coefficients}
430430
\end{definition}
431431
\begin{comments}
432432
\item These matrices are implemented in \cite{notebook:code}, in the module
433-
\WriteCodeRefText{combinatorics.binomial}
433+
\begin{CodeRefDisplay}
434+
\ManualCodeRef{combinatorics.binomial}
435+
\end{CodeRefDisplay}
434436
\end{comments}
435437

436438
\begin{example}\label{ex:con:pascals_triangle}

text/boolean_functions.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ \section{Boolean functions}\label{sec:boolean_functions}
114114
\end{algorithm}
115115
\begin{comments}
116116
\item This algorithm is implemented in \cite{notebook:code} as
117-
\WriteCodeRef{alg:infer_zhegalkin_polynomial}
117+
\begin{CodeRefDisplay}
118+
\GetCodeRef{alg:infer_zhegalkin_polynomial}
119+
\end{CodeRefDisplay}
118120
\end{comments}
119121
\begin{defproof}
120122
We will prove correctness by induction. The base case \( n = 0 \) is vacuous, so suppose that \( n > 0 \) and that the algorithm is correct for less than \( n \) variables.

text/curry_howard_correspondence.tex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ \section{Curry-Howard correspondence}\label{sec:curry_howard_correspondence}
652652
\end{algorithm}
653653
\begin{comments}
654654
\item This algorithm is implemented in \cite{notebook:code} as
655-
\WriteCodeRef{alg:type_derivation_to_proof_tree}
655+
\begin{CodeRefDisplay}
656+
\GetCodeRef{alg:type_derivation_to_proof_tree}
657+
\end{CodeRefDisplay}
656658

657659
\item When restricted to arrow types, this algorithm works just as well for \hyperref[def:lambda_term]{untyped} or even \hyperref[rem:mixed_lambda_term]{mixed} \( \muplambda \)-terms.
658660
\end{comments}
@@ -685,7 +687,9 @@ \section{Curry-Howard correspondence}\label{sec:curry_howard_correspondence}
685687
\end{algorithm}
686688
\begin{comments}
687689
\item This algorithm is implemented in \cite{notebook:code} as
688-
\WriteCodeRef{alg:proof_tree_to_type_derivation}
690+
\begin{CodeRefDisplay}
691+
\GetCodeRef{alg:proof_tree_to_type_derivation}
692+
\end{CodeRefDisplay}
689693
\end{comments}
690694

691695
\begin{example}\label{ex:con:curry_howard_correspondence}

text/digit_based_operations.tex

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ \section{Digit-based operations}\label{sec:digit_based_operations}
5050
\end{algorithm}
5151
\begin{comments}
5252
\item This algorithm is implemented in \cite{notebook:code} as
53-
\WriteCodeRef{alg:integer_radix_expansion}
53+
\begin{CodeRefDisplay}
54+
\GetCodeRef{alg:integer_radix_expansion}
55+
\end{CodeRefDisplay}
5456
\end{comments}
5557

5658
\paragraph{Digit-based integer arithmetic}
@@ -100,7 +102,9 @@ \section{Digit-based operations}\label{sec:digit_based_operations}
100102
\begin{comments}
101103
\item The term \( q_k \) \enquote{carries} either \( -1 \), \( 0 \) or \( 1 \) to be used in the next step.
102104
\item This algorithm is implemented in \cite{notebook:code} as
103-
\WriteCodeRef{alg:addition_with_carrying}
105+
\begin{CodeRefDisplay}
106+
\GetCodeRef{alg:addition_with_carrying}
107+
\end{CodeRefDisplay}
104108
\end{comments}
105109
\begin{defproof}
106110
\SubProof{Proof that \( q_k \) is either \( -1 \), \( 0 \) or \( 1 \)} We will show by induction on \( k \) that \( q_k \) is either \( -1 \), \( 0 \) or \( 1 \). Note that, since \( b \geq 2 \), we have
@@ -246,7 +250,9 @@ \section{Digit-based operations}\label{sec:digit_based_operations}
246250
\end{algorithm}
247251
\begin{comments}
248252
\item This algorithm is implemented in \cite{notebook:code} as
249-
\WriteCodeRef{alg:single_digit_multiplication_with_carrying}
253+
\begin{CodeRefDisplay}
254+
\GetCodeRef{alg:single_digit_multiplication_with_carrying}
255+
\end{CodeRefDisplay}
250256
\end{comments}
251257
\begin{defproof}
252258
The proof of correctness is similar, but much simpler than that of \fullref{alg:integer_radix_expansion}.
@@ -359,7 +365,9 @@ \section{Digit-based operations}\label{sec:digit_based_operations}
359365
\end{algorithm}
360366
\begin{comments}
361367
\item This algorithm is implemented in \cite{notebook:code} as
362-
\WriteCodeRef{alg:multi_digit_multiplication_with_carrying}
368+
\begin{CodeRefDisplay}
369+
\GetCodeRef{alg:multi_digit_multiplication_with_carrying}
370+
\end{CodeRefDisplay}
363371
\end{comments}
364372

365373
\begin{algorithm}[Long division]\label{alg:long_integer_division}
@@ -423,7 +431,9 @@ \section{Digit-based operations}\label{sec:digit_based_operations}
423431
\end{algorithm}
424432
\begin{comments}
425433
\item This algorithm is implemented in \cite{notebook:code} as
426-
\WriteCodeRef{alg:long_integer_division}
434+
\begin{CodeRefDisplay}
435+
\GetCodeRef{alg:long_integer_division}
436+
\end{CodeRefDisplay}
427437
\end{comments}
428438
\begin{defproof}
429439
The guard steps \fullref{alg:long_integer_division/n_guard} and \fullref{alg:long_integer_division/m_guard} allow us to assume that \( n \geq 0 \) and \( m \geq 0 \).

text/first_order_logic.tex

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ \section{First-order logic}\label{sec:first_order_logic}
133133
\item We implicitly associate with each propositional formula an \hyperref[con:abstract_syntax_tree]{abstract syntax tree} --- see \cref{def:fol_term_ast}. The grammar of first-order terms is unambiguous as shown via \cref{thm:fol_term_grammar/unambiguous}, which makes it possible to perform proofs via \fullref{thm:induction_on_abstract_syntax}.
134134

135135
\item First-order terms are implemented in \cite{notebook:code}, in the module
136-
\WriteCodeRefText{logic.terms}
136+
\begin{CodeRefDisplay}
137+
\ManualCodeRef{logic.terms}
138+
\end{CodeRefDisplay}
137139

138140
A parser is implemented in
139-
\WriteCodeRefText{logic.parsing}
141+
\begin{CodeRefDisplay}
142+
\ManualCodeRef{logic.parsing}
143+
\end{CodeRefDisplay}
140144
\end{comments}
141145

142146
\begin{remark}\label{rem:fol_application_notation}
@@ -232,7 +236,9 @@ \section{First-order logic}\label{sec:first_order_logic}
232236
\begin{comments}
233237
\item As discussed in \cref{rem:fol_application_notation}, we allow translation to change the notation of symbols.
234238
\item This algorithm is implemented in \cite{notebook:code} as
235-
\WriteCodeRef{alg:fol_term_signature_translation}
239+
\begin{CodeRefDisplay}
240+
\GetCodeRef{alg:fol_term_signature_translation}
241+
\end{CodeRefDisplay}
236242
\end{comments}
237243

238244
\paragraph{First-order formulas}
@@ -267,10 +273,14 @@ \section{First-order logic}\label{sec:first_order_logic}
267273
\item Within the metalanguage, we will denote abstract formulas via \( \varphi \), \( \psi \), \( \theta \) and other letters in accordance with \cref{rem:mathematical_logic_conventions/greek_alphabet}. This convention will later lead us to a formal definition of formula schemas in \cref{def:fol_formula_schema}.
268274

269275
\item First-order formulas are implemented in \cite{notebook:code}, in the module
270-
\WriteCodeRefText{logic.formulas}
276+
\begin{CodeRefDisplay}
277+
\ManualCodeRef{logic.formulas}
278+
\end{CodeRefDisplay}
271279

272280
A parser is implemented in
273-
\WriteCodeRefText{logic.parsing}
281+
\begin{CodeRefDisplay}
282+
\ManualCodeRef{logic.parsing}
283+
\end{CodeRefDisplay}
274284
\end{comments}
275285

276286
\begin{proposition}\label{thm:fol_formula_grammar}
@@ -384,7 +394,9 @@ \section{First-order logic}\label{sec:first_order_logic}
384394
\item As discussed in \cref{rem:fol_application_notation}, we allow exchanging prefix and infix symbols.
385395

386396
\item This algorithm is implemented in \cite{notebook:code} as
387-
\WriteCodeRef{alg:fol_formula_signature_translation}
397+
\begin{CodeRefDisplay}
398+
\GetCodeRef{alg:fol_formula_signature_translation}
399+
\end{CodeRefDisplay}
388400
\end{comments}
389401

390402
\paragraph{Variable binding}
@@ -545,7 +557,9 @@ \section{First-order logic}\label{sec:first_order_logic}
545557
\item The term \enquote{denotation} is inspired by Russell's theory of denotations discussed in \cref{con:denotation}. It is used inconsistently in the literature. See \cref{rem:model_theory_structure_terminology}.
546558

547559
\item This algorithm is implemented in \cite{notebook:code} as
548-
\WriteCodeRef{alg:fol_term_denotation}
560+
\begin{CodeRefDisplay}
561+
\GetCodeRef{alg:fol_term_denotation}
562+
\end{CodeRefDisplay}
549563
\end{comments}
550564

551565
\begin{definition}\label{def:fol_parameterized_term_denotation}
@@ -614,7 +628,9 @@ \section{First-order logic}\label{sec:first_order_logic}
614628
\item The term \enquote{denotation} is inspired by Russell's theory of denotations discussed in \cref{con:denotation}. It is used inconsistently in the literature. See \cref{rem:model_theory_structure_terminology}.
615629

616630
\item This algorithm is implemented in \cite{notebook:code} as
617-
\WriteCodeRef{alg:fol_formula_denotation}
631+
\begin{CodeRefDisplay}
632+
\GetCodeRef{alg:fol_formula_denotation}
633+
\end{CodeRefDisplay}
618634
\end{comments}
619635

620636
\begin{remark}\label{rem:fol_empty_universe/semantics}
@@ -715,7 +731,9 @@ \section{First-order logic}\label{sec:first_order_logic}
715731
\end{definition}
716732
\begin{comments}
717733
\item Structures are implemented in \cite{notebook:code}, in the module
718-
\WriteCodeRefText{logic.structure}
734+
\begin{CodeRefDisplay}
735+
\ManualCodeRef{logic.structure}
736+
\end{CodeRefDisplay}
719737

720738
\item The definition is based on \bycite[def. 2.6.3]{Hinman2005Logic}, with small adjustments made for the intuitionistic treatment of formal equality.
721739
\end{comments}
@@ -734,7 +752,9 @@ \section{First-order logic}\label{sec:first_order_logic}
734752
\item Reducts are also compatible with \hyperref[def:fol_theory/morphism]{theory morphisms} --- see \cref{thm:def:fol_theory/theory_morphism_reduct}.
735753

736754
\item Reducts are implemented in \cite{notebook:code}, in the module
737-
\WriteCodeRefText{logic.structure.reduct}
755+
\begin{CodeRefDisplay}
756+
\ManualCodeRef{logic.structure.reduct}
757+
\end{CodeRefDisplay}
738758
\end{comments}
739759

740760
\begin{proposition}\label{thm:fol_structure_reduct_denotation}
@@ -890,7 +910,9 @@ \section{First-order logic}\label{sec:first_order_logic}
890910
\item Of course, this extension will only be valid when the propositional variables are in the domain of the atomic translation map.
891911

892912
\item This algorithm is implemented in \cite{notebook:code} as
893-
\WriteCodeRef{alg:fol_propositional_formula_translation}
913+
\begin{CodeRefDisplay}
914+
\GetCodeRef{alg:fol_propositional_formula_translation}
915+
\end{CodeRefDisplay}
894916
\end{comments}
895917

896918
\begin{proposition}\label{thm:fol_propositional_formula_translation_semantics}
@@ -940,7 +962,9 @@ \section{First-order logic}\label{sec:first_order_logic}
940962
\end{remark}
941963
\begin{comments}
942964
\item This is the approach we have used to implement propositional logic in \cite{notebook:code}, in the module
943-
\WriteCodeRefText{logic.propositional}
965+
\begin{CodeRefDisplay}
966+
\ManualCodeRef{logic.propositional}
967+
\end{CodeRefDisplay}
944968
\end{comments}
945969

946970
\paragraph{Quantifier duality}
@@ -955,7 +979,9 @@ \section{First-order logic}\label{sec:first_order_logic}
955979
\end{algorithm}
956980
\begin{comments}
957981
\item This algorithm is implemented in \cite{notebook:code} as
958-
\WriteCodeRef{alg:fol_formula_dualization}
982+
\begin{CodeRefDisplay}
983+
\GetCodeRef{alg:fol_formula_dualization}
984+
\end{CodeRefDisplay}
959985
\end{comments}
960986
\begin{defproof}
961987
We will use \fullref{thm:induction_on_abstract_syntax} on \( \varphi \) to show that \( \Bracks{\oline{M}(\varphi)}_\mscrX^v = \oline{\Bracks{\varphi}_\mscrX^v} \) for every variable assignment \( v \) in every structure \( \mscrX = (X, I) \).

text/first_order_natural_deduction.tex

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
1717
\end{algorithm}
1818
\begin{comments}
1919
\item This algorithm is implemented in \cite{notebook:code} as
20-
\WriteCodeRef{alg:fol_formula_substitution}
20+
\begin{CodeRefDisplay}
21+
\GetCodeRef{alg:fol_formula_substitution}
22+
\end{CodeRefDisplay}
2123

2224
\item This substitution is defined as to have the properties listed in \cref{rem:variable_binding_properties}; we elaborate on this in \fullref{thm:alg:fol_formula_substitution}.
2325
\end{comments}
@@ -394,7 +396,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
394396
\end{definition}
395397
\begin{comments}
396398
\item Term schemas are implemented in \cite{notebook:code}, in the module
397-
\WriteCodeRefText{logic.terms}
399+
\begin{CodeRefDisplay}
400+
\ManualCodeRef{logic.terms}
401+
\end{CodeRefDisplay}
398402
\end{comments}
399403

400404
\begin{definition}\label{def:fol_formula_schema}\mimprovised
@@ -418,7 +422,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
418422
\item Small Greek identifiers are used for both term and formula placeholders, but in practice they do not cause confusion.
419423
\item First-order formula schemas directly extend their \hyperref[def:propositional_formula_schema]{propositional counterparts}.
420424
\item Formulas schemas are implemented in \cite{notebook:code}, in the module
421-
\WriteCodeRefText{logic.formulas}
425+
\begin{CodeRefDisplay}
426+
\ManualCodeRef{logic.formulas}
427+
\end{CodeRefDisplay}
422428
\end{comments}
423429

424430
\begin{definition}\label{def:atomic_fol_instantiation}\mimprovised
@@ -438,7 +444,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
438444
\begin{comments}
439445
\item Of course, an application of an instantiation is only valid if the placeholders are in its domain.
440446
\item This algorithm is implemented in \cite{notebook:code} as
441-
\WriteCodeRef{alg:fol_term_schema_instantiation}
447+
\begin{CodeRefDisplay}
448+
\GetCodeRef{alg:fol_term_schema_instantiation}
449+
\end{CodeRefDisplay}
442450
\end{comments}
443451

444452
\begin{algorithm}[First-order formula instantiation]\label{alg:fol_formula_schema_instantiation}
@@ -464,7 +472,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
464472
\item A variant of this algorithm, in which certain instantiations are considered invalid, is presented in \cref{rem:sequent_calculus_eigenvariables}.
465473

466474
\item This algorithm is implemented in \cite{notebook:code} as
467-
\WriteCodeRef{alg:fol_formula_schema_instantiation}
475+
\begin{CodeRefDisplay}
476+
\GetCodeRef{alg:fol_formula_schema_instantiation}
477+
\end{CodeRefDisplay}
468478
\end{comments}
469479

470480
\paragraph{Abstract natural deduction}
@@ -530,7 +540,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
530540
Fix an \hyperref[def:atomic_fol_instantiation]{atomic schema instantiation} \( \BbbI \) and a list \( (P_1, \ldots, P_n) \) of proof trees such that, for \( i = 1, \ldots, n \), the conclusion of \( P_k \) is \( \Phi_k[\BbbI] \). As in the propositional case, for a suitable choice \( d \) of dischargeable assumptions, we have a unique rule application tree \( P_d \).
531541

532542
Describing the eigenvariables of \( P_d \) requires additional coherence conditions. They are enforced programmatically in \cite{notebook:code}, in the function
533-
\WriteCodeRef{def:fol_natural_deduction_proof_tree}
543+
\begin{CodeDefDisplay}
544+
\GetCodeRef{def:fol_natural_deduction_proof_tree}
545+
\end{CodeDefDisplay}
534546

535547
We also describe some of them below:
536548
\begin{thmenum}[series=def:fol_natural_deduction_proof_tree/application]
@@ -598,7 +610,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
598610
Gentzen presents only two rules featuring eigenvariables, in which the variables must satisfy slightly differing constraints. We formalize Gentzen's rules in \cref{def:fol_natural_deduction} and adapt them for \hyperref[def:higher_order_logic]{higher-order logic} in \cref{def:hol_natural_deduction}.
599611

600612
\item Natural deduction proof trees are implemented in \cite{notebook:code}, in the module
601-
\WriteCodeRefText{logic.deduction}
613+
\begin{CodeRefDisplay}
614+
\ManualCodeRef{logic.deduction}
615+
\end{CodeRefDisplay}
602616
\end{comments}
603617

604618
\begin{proposition}\label{thm:def:fol_natural_deduction_proof_tree}
@@ -682,7 +696,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
682696
\item We will use this algorithm to show compatibility of propositional and first-order derivation relations in \cref{thm:fol_propositional_formula_translation_entailment}.
683697

684698
\item This algorithm is implemented in \cite{notebook:code} as
685-
\WriteCodeRef{alg:fol_propositional_proof_tree_translation}
699+
\begin{CodeRefDisplay}
700+
\GetCodeRef{alg:fol_propositional_proof_tree_translation}
701+
\end{CodeRefDisplay}
686702
\end{comments}
687703

688704
\paragraph{Concrete natural deduction}
@@ -771,7 +787,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
771787
\item The two equality rules are more concise and flexible, but less explicit than those from \cref{thm:fol_natural_deduction_equality}.
772788

773789
\item These precise rules are used in \cite{notebook:code}, in the module
774-
\WriteCodeRefText{logic.classical_logic}
790+
\begin{CodeRefDisplay}
791+
\ManualCodeRef{logic.classical_logic}
792+
\end{CodeRefDisplay}
775793
\end{comments}
776794

777795
\begin{example}\label{ex:def:fol_natural_deduction}
@@ -903,7 +921,9 @@ \section{First-order natural deduction}\label{sec:first_order_natural_deduction}
903921
\end{example}
904922
\begin{comments}
905923
\item Many of these examples are verified programmatically in \cite{notebook:code}, in the module
906-
\WriteCodeRefText{logic.deduction.test_proof_tree}
924+
\begin{CodeRefDisplay}
925+
\ManualCodeRef{logic.deduction.test_proof_tree}
926+
\end{CodeRefDisplay}
907927
\end{comments}
908928

909929
\begin{remark}\label{rem:dependent_products_and_forall_quantifier_rules}

0 commit comments

Comments
 (0)