Link Search Menu Expand Document
\( % cbs-katex.sty % \newcommand{\STYLE}[2]{\htmlClass{cbs-#1}{#2}} \newcommand{\DECL}[3]{\htmlId{#1:#2}{#3}} \newcommand{\REF}[3]{\href{###1:#2}{#3}} \newcommand{\HYPER}[5]{\href{#1/#2/index.html###3:#4}{#5}} % \SHADE{MATH} can be defined to produce a shaded background to highlight % inline MATH in running text: \newcommand{\SHADE}[1]{#1} % \KEY{TEXT}, \STRING{TEXT}, \ATOM{TEXT}, \LEX{TEXT} can be used in math mode: \newcommand{\KEY}[1]{\textsf{\textit{\STYLE{Key}{#1}}}} \newcommand{\STRING}[1]{\textsf{``\texttt{#1}''}} \newcommand{\ATOM}[1]{\textsf{`\texttt{#1}'}} \newcommand{\LEX}[1]{\textsf{\STYLE{Key}{`}\texttt{#1}\STYLE{Key}{'}}} % The following commands produce ASCII characters that are treated specially by LaTeX: \newcommand{\HASH}{\char`\#} \newcommand{\DOLLAR}{\char`\$} \newcommand{\PERCENT}{\char`\%} \newcommand{\AMPERSAND}{\char`\&} \newcommand{\APOSTROPHE}{\char`\'} \newcommand{\BACKSLASH}{\char`\\} \newcommand{\CARET}{\char`\^} \newcommand{\UNDERSCORE}{\char`\_} \newcommand{\GRAVE}{\char`\`} \newcommand{\LEFTBRACE}{\char`\{} \newcommand{\RIGHTBRACE}{\char`\}} \newcommand{\TILDE}{\textasciitilde} % {\char`\~} % \NAME{name} highlights the name; % \NAMEDECL{name} declares Name.name as the target of links to name; % \NAMEREF{name} links name to the target Name.name in the current file; % \NAMEHYPER{url}{file}{name} links name to Name.name at url/file/file.pdf. % Similarly for \VAR{partvariable}, \SYN{syntaxname}, \SEM{semanticsName}, % and \SECT{sectionnumber} % The kerns in \SUB and \VAR avoid overlaps with primes: \newcommand{\SUB}[1]{_{\kern-2mu\STYLE{PartVariable}{\textsf{#1}}}} % PLAIN \newcommand{\VAR}[1]{\STYLE{PartVariable}{\textsf{\textit{#1}\kern2mu}}} \newcommand{\NAME}[1]{\STYLE{Name}{\textsf{#1}}} \newcommand{\SYN}[1]{\STYLE{SyntaxName}{\textsf{#1}}} \newcommand{\SEM}[1]{\STYLE{SemanticsName}{\textsf{#1}}} \newcommand{\SECT}[1]{\STYLE{SectionNumber}{\textsf{#1}}} % DECL \newcommand{\VARDECL}[1]{\DECL{PartVariable}{#1}{\VAR{#1}}} \newcommand{\NAMEDECL}[1]{\DECL{Name}{#1}{\NAME{#1}}} \newcommand{\SYNDECL}[1]{\DECL{SyntaxName}{#1}{\SYN{#1}}} \newcommand{\SEMDECL}[1]{\DECL{SemanticsName}{#1}{\SEM{#1}}} \newcommand{\SECTDECL}[1]{\DECL{SectionNumber}{#1}{\textsf{#1}}} % REF \newcommand{\VARREF}[1]{\REF{PartVariable}{#1}{\VAR{#1}}} \newcommand{\NAMEREF}[1]{\REF{Name}{#1}{\NAME{#1}}} \newcommand{\SYNREF}[1]{\REF{SyntaxName}{#1}{\SYN{#1}}} \newcommand{\SEMREF}[1]{\REF{SemanticsName}{#1}{\SEM{#1}}} \newcommand{\SECTREF}[1]{\REF{SectionNumber}{#1}{\SECT{#1}}} % HYPER \newcommand{\VARHYPER}[3]{\HYPER{#1}{#2}{PartVariable}{#3}{\VAR{#3}}} \newcommand{\NAMEHYPER}[3]{\HYPER{#1}{#2}{Name}{#3}{\NAME{#3}}} \newcommand{\SYNHYPER}[3]{\HYPER{#1}{#2}{SyntaxName}{#3}{\SYN{#3}}} \newcommand{\SEMHYPER}[3]{\HYPER{#1}{#2}{SemanticsName}{#3}{\SEM{#3}}} \newcommand{\SECTHYPER}[3]{\HYPER{#1}{#2}{SectionNumber}{#3}{\SECT{#3}}} % \LEFTPHRASE MATH \RIGHTPHRASE produces [[ MATH ]] with proper brackets: \newcommand{\LEFTPHRASE}{\llbracket} \newcommand{\RIGHTPHRASE}{\rrbracket} % \LEFTGROUP MATH \RIGHTGROUP produces ( MATH ) where the parentheses are % highlighted the same as keywords: \newcommand{\LEFTGROUP}{\STYLE{Key}{(}} \newcommand{\RIGHTGROUP}{\STYLE{Key}{)}} % MATH\PLUS produces a superscript + % MATH\STAR produces a superscript * % MATH\QUERY produces a superscript ? \newcommand{\PLUS}{{}^{\texttt{+}}} \newcommand{\STAR}{{}^{\texttt{*}}} \newcommand{\QUERY}{{}^{\texttt{?}}} % \RULE{& PREMISE \\ & ...}{& FORMULA ... \\ & ...} produces an inference rule % with separately aligned premises and conclusion % PREMISE % ... % ----------- % FORMULA ... % ... \newcommand{\RULE}[2] {\frac{\begin{aligned}#1\end{aligned}}{\begin{aligned}#2\end{aligned}}} % \AXIOM{& FORMULA ... \\ & ...} produces an aligned formula % % FORMULA ... % ... \newcommand{\AXIOM}[1]{\begin{aligned}#1\end{aligned}} % \TO TYPE produces => TYPE \newcommand{\TO}{\mathop{\Rightarrow}} % TERM \TRANS TERM produces TERM ---> TERM \newcommand{\TRANS}{\longrightarrow} % TERM \xrightarrow{LABEL} TERM puts the label above the long arrow % \)

Funcons-beta : Bits.cbs | PLAIN | PDF

OUTLINE

Bits and bit vectors

\[\begin{align*} [ \ \KEY{Type} \quad & \NAMEREF{bits} \\ \KEY{Datatype} \quad & \NAMEREF{bit-vectors} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector} \\ \KEY{Type} \quad & \NAMEREF{bytes} \\ \KEY{Alias} \quad & \NAMEREF{octets} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-not} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-and} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-or} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-xor} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-shift-left} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-logical-shift-right} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-arithmetic-shift-right} \\ \KEY{Funcon} \quad & \NAMEREF{integer-to-bit-vector} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-to-integer} \\ \KEY{Funcon} \quad & \NAMEREF{bit-vector-to-natural} \\ \KEY{Funcon} \quad & \NAMEREF{unsigned-bit-vector-maximum} \\ \KEY{Funcon} \quad & \NAMEREF{signed-bit-vector-maximum} \\ \KEY{Funcon} \quad & \NAMEREF{signed-bit-vector-minimum} \\ \KEY{Funcon} \quad & \NAMEREF{is-in-signed-bit-vector} \\ \KEY{Funcon} \quad & \NAMEREF{is-in-unsigned-bit-vector} \ ] \end{align*}\]

Bits

\[\begin{align*} \KEY{Type} \quad & \NAMEDECL{bits} \leadsto \NAMEHYPER{../../Primitive}{Booleans}{booleans} \end{align*}\]

\(\SHADE{\NAMEHYPER{../../Primitive}{Booleans}{false}}\) represents the absence of a bit, \(\SHADE{\NAMEHYPER{../../Primitive}{Booleans}{true}}\) its presence.

Bit vectors

\[\begin{align*} \KEY{Datatype} \quad \NAMEDECL{bit-vectors}( \VAR{N} : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) \ ::= \ & \NAMEDECL{bit-vector}( \_ : \NAMEREF{bits}^{\VAR{N}}) \end{align*}\] \[\begin{align*} \KEY{Type} \quad & \NAMEDECL{bytes} \leadsto \NAMEREF{bit-vectors} ( 8 ) \\ \KEY{Alias} \quad & \NAMEDECL{octets} = \NAMEREF{bytes} \end{align*}\] \[\begin{align*} \KEY{Meta-variables} \quad & \VAR{BT} <: \NAMEREF{bit-vectors} ( \_ ) \end{align*}\] \[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-not}( \_ : \VAR{BT}) : \TO \VAR{BT} \end{align*}\] \[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-and}( \_ : \VAR{BT}, \_ : \VAR{BT}) : \TO \VAR{BT} \end{align*}\] \[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-or}( \_ : \VAR{BT}, \_ : \VAR{BT}) : \TO \VAR{BT} \end{align*}\] \[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-xor}( \_ : \VAR{BT}, \_ : \VAR{BT}) : \TO \VAR{BT} \end{align*}\]

The above four funcons are the natural extensions of funcons from \(\SHADE{\NAMEHYPER{../../Primitive}{Booleans}{booleans}}\) to \(\SHADE{\NAMEREF{bit-vectors} ( \VAR{N} )}\) of the same length.

\[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-shift-left}( \_ : \VAR{BT}, \_ : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \VAR{BT} \end{align*}\] \[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-logical-shift-right}( \_ : \VAR{BT}, \_ : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \VAR{BT} \end{align*}\] \[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-arithmetic-shift-right}( \_ : \VAR{BT}, \_ : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \VAR{BT} \end{align*}\] \[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{integer-to-bit-vector}( \_ : \NAMEHYPER{../../Primitive}{Integers}{integers}, \VAR{N} : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \NAMEREF{bit-vectors} ( \VAR{N} ) \end{align*}\]

\(\SHADE{\NAMEREF{integer-to-bit-vector} ( \VAR{M}, \VAR{N} )}\) converts an integer \(\SHADE{\VAR{M}}\) to a bit-vector of length \(\SHADE{\VAR{N}}\), using Two’s Complement representation. If the integer is out of range of the representation, it will wrap around (modulo 2^N).

\[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-to-integer}( \_ : \VAR{BT}) : \TO \NAMEHYPER{../../Primitive}{Integers}{integers} \end{align*}\]

\(\SHADE{\NAMEREF{bit-vector-to-integer} ( \VAR{B} )}\) interprets a bit-vector \(\SHADE{\VAR{BV}}\) as an integer in Two’s Complement representation.

\[\begin{align*} \KEY{Built-in Funcon} \quad & \NAMEDECL{bit-vector-to-natural}( \_ : \VAR{BT}) : \TO \NAMEHYPER{../../Primitive}{Integers}{natural-numbers} \end{align*}\]

\(\SHADE{\NAMEREF{bit-vector-to-natural} ( \VAR{BV} )}\) interprets a bit-vector \(\SHADE{\VAR{BV}}\) as a natural number in unsigned representation.

\[\begin{align*} \KEY{Funcon} \quad & \NAMEDECL{unsigned-bit-vector-maximum}( \VAR{N} : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \TO \NAMEHYPER{../../Primitive}{Integers}{natural-numbers} \\&\quad \leadsto \NAMEHYPER{../../Primitive}{Integers}{integer-subtract} ( \NAMEHYPER{../../Primitive}{Integers}{integer-power} ( 2, \VAR{N} ), 1 ) \end{align*}\] \[\begin{align*} \KEY{Funcon} \quad & \NAMEDECL{signed-bit-vector-maximum}( \VAR{N} : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \TO \NAMEHYPER{../../Primitive}{Integers}{integers} \\&\quad \leadsto \NAMEHYPER{../../Primitive}{Integers}{integer-subtract} ( \NAMEHYPER{../../Primitive}{Integers}{integer-power} ( 2, \NAMEHYPER{../../Primitive}{Integers}{integer-subtract} ( \VAR{N}, 1 ) ), 1 ) \end{align*}\] \[\begin{align*} \KEY{Funcon} \quad & \NAMEDECL{signed-bit-vector-minimum}( \VAR{N} : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \TO \NAMEHYPER{../../Primitive}{Integers}{integers} \\&\quad \leadsto \NAMEHYPER{../../Primitive}{Integers}{integer-negate} ( \NAMEHYPER{../../Primitive}{Integers}{integer-power} ( 2, \NAMEHYPER{../../Primitive}{Integers}{integer-subtract} ( \VAR{N}, 1 ) ) ) \end{align*}\] \[\begin{align*} \KEY{Funcon} \quad & \NAMEDECL{is-in-signed-bit-vector}( \VAR{M} : \NAMEHYPER{../../Primitive}{Integers}{integers}, \VAR{N} : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \TO \NAMEHYPER{../../Primitive}{Booleans}{booleans} \\&\quad \leadsto \NAMEHYPER{../../Primitive}{Booleans}{and} ( \\&\quad\quad\quad\quad \NAMEHYPER{../../Primitive}{Integers}{integer-is-less-or-equal} ( \VAR{M}, \NAMEREF{signed-bit-vector-maximum} ( \VAR{N} ) ), \\&\quad\quad\quad\quad \NAMEHYPER{../../Primitive}{Integers}{integer-is-greater-or-equal} ( \VAR{M}, \NAMEREF{signed-bit-vector-minimum} ( \VAR{N} ) ) ) \end{align*}\] \[\begin{align*} \KEY{Funcon} \quad & \NAMEDECL{is-in-unsigned-bit-vector}( \VAR{M} : \NAMEHYPER{../../Primitive}{Integers}{integers}, \VAR{N} : \NAMEHYPER{../../Primitive}{Integers}{natural-numbers}) : \TO \NAMEHYPER{../../Primitive}{Booleans}{booleans} \\&\quad \leadsto \NAMEHYPER{../../Primitive}{Booleans}{and} ( \\&\quad\quad\quad\quad \NAMEHYPER{../../Primitive}{Integers}{integer-is-less-or-equal} ( \VAR{M}, \NAMEREF{unsigned-bit-vector-maximum} ( \VAR{N} ) ), \\&\quad\quad\quad\quad \NAMEHYPER{../../Primitive}{Integers}{integer-is-greater-or-equal} ( \VAR{M}, 0 ) ) \end{align*}\]