# HG changeset patch # User e155702 # Date 1550349599 -32400 # Node ID 0e8b9646d43f90eb51f8df05f13e7811bb6c1c4a # Parent 8f5d263c219b185e37716679146928d1835853ac add final_pre diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/Makefile Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,36 @@ +# Created by Daichi Toma on Nov 16, 2011 + +TARGET=finalPre + +LATEX=platex +BIBTEX=pbibtex +DVIPDF=dvipdfmx -p a4 +#You need setting "-l" option if You think You get a landscape PDF +#DVIPDF_OPT=-l + +#Embed fonts +#DVIPDF_OPT=-f hiraginoEmbed.map + +.SUFFIXES: .tex .dvi .pdf + +.tex.dvi: + $(LATEX) $< + $(BIBTEX) $(TARGET) + $(LATEX) $< + $(LATEX) $< + +.dvi.pdf: + $(DVIPDF) $(DVIPDF_OPT) $< + + +all: $(TARGET).pdf + open $(TARGET).pdf + +dvi: $(TARGET).dvi + +pdf: $(TARGET).pdf + + +clean: + rm -f *.dvi *.aux *.log *.ps *.gz *.bbl *.blg *.toc *~ *.core + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/auto/midterm.el --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/auto/midterm.el Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,31 @@ +(TeX-add-style-hook + "midterm" + (lambda () + (TeX-add-to-alist 'LaTeX-provided-class-options + '(("jarticle" "twocolumn" "twoside" "9.5pt"))) + (TeX-add-to-alist 'LaTeX-provided-package-options + '(("graphicx" "dvipdfmx"))) + (add-to-list 'LaTeX-verbatim-environments-local "lstlisting") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "path") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "url") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "lstinline") + (add-to-list 'LaTeX-verbatim-macros-with-delims-local "path") + (add-to-list 'LaTeX-verbatim-macros-with-delims-local "url") + (add-to-list 'LaTeX-verbatim-macros-with-delims-local "lstinline") + (TeX-run-style-hooks + "latex2e" + "dummy" + "jarticle" + "jart10" + "graphicx" + "picins" + "fancyhdr" + "abstract" + "url" + "bussproofs" + "listings" + "jlisting") + (LaTeX-add-bibliographies + "reference")) + :latex) + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/bussproofs.sty --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/bussproofs.sty Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,1136 @@ +% +\def\BPmessage{Proof Tree (bussproofs) style macros. Version 1.1.} +% bussproofs.sty. Version 1.1 +% (c) 1994,1995,1996,2004,2005,2006, 2011. +% Copyright retained by Samuel R. Buss. +% +% ==== Legal statement: ==== +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt. +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/1 or later. +% +% This work has the LPPL maintenance status 'maintained'. +% +% The Current Maintainer of the work is Sam Buss. +% +% This work consists of bussproofs.sty. +% ===== +% Informal summary of legal situation: +% This software may be used and distributed freely, except that +% if you make changes, you must change the file name to be different +% than bussproofs.sty to avoid compatibility problems. +% The terms of the LaTeX Public License are the legally controlling terms +% and override any contradictory terms of the "informal situation". +% +% Please report comments and bugs to sbuss@ucsd.edu. +% +% Thanks to Felix Joachimski for making changes to let these macros +% work in plain TeX in addition to LaTeX. Nothing has been done +% to see if they work in AMSTeX. The comments below mostly +% are written for LaTeX, however. +% July 2004, version 0.7 +% - bug fix, right labels with descenders inserted too much space. +% Thanks to Peter Smith for finding this bug, +% see http://www.phil.cam.ac.uk/teaching_staff/Smith/LaTeX/ +% March 2005, version 0.8. +% Added a default definition for \fCenter at Denis Kosygin's +% suggestion. +% September 2005, version 0.9. +% Fixed some subtle spacing problems, by adding %'s to the end of +% few lines where they were inadvertantly omitted. Thanks to +% Arnold Beckmann for finding and fixing this problem. +% April 2006, version 0.9.1. Updated comments and testbp2.tex file. +% No change to the actual macros. +% June 2006, version 1.0. The first integer numbered release. +% New feature: root of proof may now be at the bottom instead of +% at just the top. Thanks to Alex Hertel for the suggestion to implement +% this. +% June 2011, version 1.1. +% New feature: 4-ary and 5-ary inferences. Thanks to Thomas Strathmann +% for taking the initiative to implement these. +% Four new commands: QuaternaryInf(C) and QuinaryInf(C). +% Bug fix: \insertBetweenHyps now works for proofs with root at top and +% three or more hypotheses.. + +% A good exposition of how to use bussproofs.sty (version 0.9) has been written +% by Peter Smith and is available on the internet. +% The comments below also describe the features of bussproofs.sty, +% including user-modifiable parameters. + +% bussproofs.sty allows the construction of proof trees in the +% style of the sequent calculus and many other proof systems +% One novel feature of these macros is they support the horizontal +% alignment according to some center point specified with the +% command \fCenter. This is the style often used in sequent +% calculus proofs. +% Proofs are specified in left-to-right traversal order. +% For example a proof +% A B +% ----- +% D C +% --------- +% E +% +% if given in the order D,A,B,C,E. Each line in the proof is +% specified according to the arity of the inference which generates +% it. Thus, E would be specified with a \BinaryInf or \BinaryInfC +% command. +% +% The above proof tree could be displayed with the commands: +% +% \AxiomC{D} +% \AxiomC{A} +% \AxiomC{B} +% \BinaryInfC{C} +% \BinaryInfC{E} +% \DisplayProof +% +% Inferences in a proof may be nullary (axioms), unary, binary, or +% trinary. +% +% IMPORTANT: You must give the \DisplayProof command to make the proof +% be printed. To display a centered proof on a line by itself, +% put the proof inside \begin{center} ... \end{center}. +% +% There are two styles for specifying horizontal centering of +% lines (formulas or sequents) in a proof. One format \AxiomC{...} +% just centers the formula {...} in the usual way. The other +% format is \Axiom$...\fCenter...$. Here, the \fCenter specifies +% the center of the formula. (It is permissable for \fCenter to +% generate typeset material; in fact, I usually define it to generate +% the sequent arrow.) In unary inferences, the \fCenter +% positions will be vertically aligned in the upper and lower lines of +% the inference. Unary, Binary, Trinary inferences are specified +% with the same format as Axioms. The two styles of centering +% lines may be combined in a single proof. +% +% By using the optional \EnableBpAbbreviations command, various +% abbreviated two or three letter commands are enabled. This allows, +% in particular: +% \AX and \AXC for \Axiom and \AxiomC, (resp.), +% \DP for \DisplayProof, +% \BI and \BIC for \BinaryInf and \BinaryInfC, +% \UI and \UIC for \UnaryInf and \UnaryInfC, +% \TI and \TIC for \TrinaryInf and \TrinaryInfC, +% \LL and \RL for \LeftLabel and \RightLabel. +% See the source code below for additional abbreviations. +% The enabling of these short abbreviations is OPTIONAL, since +% there is the possibility of conflicting with names from other +% macro packages. +% +% By default, the inferences have single horizontal lines (scores) +% This can be overridden using the \doubleLine, \noLine commands. +% These two commands affect only the next inference. You can make +% make a permanent override that applies to the rest of the current +% proof using \alwaysDoubleLine and \alwaysNoLine. \singleLine +% and \alwaysSingleLine work in the analogous way. +% +% The macros do their best to give good placements of for the +% parts of the proof. Several macros allow you to override the +% defaults. These are \insertBetweenHyps{...} which overrides +% the default spacing between hypotheses of Binary and Trinary +% inferences with {...}. And \kernHyps{...} specifies a distance +% to shift the whole block of hypotheses to the right (modifying +% the default center position. +% Other macros set the vertical placement of the whole proof. +% The default is to try to do a good job of placement for inferences +% included in text. Two other useful macros are: \bottomAlignProof +% which aligns the hbox output by \DisplayProof according to the base +% of the bottom line of the proof, and \centerAlignProof which +% does a precise center vertical alignment. +% +% Often, one wishes to place a label next to an inference, usually +% to specify the type of inference. These labels can be placed +% by using the commands \LeftLabel{...} and \RightLabel{...} +% immediately before the command which specifies the inference. +% For example, to generate +% +% A B +% --------- X +% C +% +% use the commands +% \AxiomC{A} +% \AxiomC{B} +% \RightLabel{X} +% \BinaryInfC{C} +% \DisplayProof +% +% The \DisplayProof command just displays the proof as a text +% item. This allows you to put proofs anywhere normal text +% might appear; for example, in a paragraph, in a table, in +% a tabbing environment, etc. When displaying a proof as inline text, +% you should write \DisplayProof{} (with curly brackets) so that +% LaTeX will not "eat" the white space following the \DisplayProof +% command. +% For displaying proofs in a centered display: Do not use the \[...\] +% construction (nor $$...$$). Instead use +% \begin{center} ... \DisplayProof\end{center}. +% Actually there is a better construction to use instead of the +% \begin{center}...\DisplayProof\end{center}. This is to +% write +% \begin{prooftree} ... \end{prooftree}. +% Note there is no \DisplayProof used for this: the +% \end{prooftree} automatically supplies the \DisplayProof +% command. +% +% Warning: Any commands that set line types or set vertical or +% horizontal alignment that are given AFTER the \DisplayProof +% command will affect the next proof, no matter how distant. + + + + +% Usages: +% ======= +% +% \Axiom$\fCenter$ +% +% \AxiomC{\fCenter$ +% +% \UnaryInfC{} +% +% \BinaryInf$\fCenter$ +% +% \BinaryInfC{} +% +% \TrinaryInf$\fCenter$ +% +% \TrinaryInfC{} +% +% \QuaternaryInf$\fCenter$ +% +% \QuaternaryInfC{} +% +% \QuinaryInf$\fCenter$ +% +% \QuinaryInfC{} +% +% \LeftLabel{} - Puts as a label to the left +% of the next inference line. (Works even if +% \noLine is used too.) +% +% \RightLabel{} - Puts as a label to the right of the +% next inference line. (Also works with \noLine.) +% +% \DisplayProof - outputs the whole proof tree (and finishes it). +% The proof tree is output as an hbox. +% +% +% \kernHyps{} - Slides the upper hypotheses right distance +% (This is similar to shifting conclusion left) +% - kernHyps works with Unary, Binary and Trinary +% inferences and with centered or uncentered sequents. +% - Negative values for are permitted. +% +% \insertBetweenHyps{...} - {...} will be inserted between the upper +% hypotheses of a Binary or Trinary Inferences. +% It is possible to use negative horizontal space +% to push them closer together (and even overlap). +% This command affects only the next inference. +% +% \doubleLine - Makes the current (ie, next) horizontal line doubled +% +% \alwaysDoubleLine - Makes lines doubled for rest of proof +% +% \singleLine - Makes the current (ie, next) line single +% +% \alwaysSingleLine - Undoes \alwaysDoubleLine or \alwaysNoLine. +% +% \noLine - Make no line at all at current (ie next) inference. +% +% \alwaysNoLine - Makes no lines for rest of proof. (Untested) +% +% \solidLine - Does solid horizontal line for current inference +% +% \dottedLine - Does dotted horizontal line for current inference +% +% \dashedLine - Does dashed horizontal line for current inference +% +% \alwaysSolidLine - Makes the indicated change in line type, permanently +% \alwaysDashedLine until end of proof or until overridden. +% \alwaysDottedLine +% +% \bottomAlignProof - Vertically align proof according to its bottom line. +% \centerAlignProof - Vertically align proof proof precisely in its center. +% \normalAlignProof - Overrides earlier bottom/center AlignProof commands. +% The default alignment will look good in most cases, +% whether the proof is displayed or is +% in-line. Other alignments may be more +% appropriate when putting proofs in tables or +% pictures, etc. For custom alignments, use +% TeX's raise commands. +% +% \rootAtTop - specifies that proofs have their root a the top. That it, +% proofs will be "upside down". +% \rootAtBottom - (default) Specifies that proofs have root at the bottom +% The \rootAtTop and \rootAtBottom commands apply *only* to the +% current proof. If you want to make them persistent, use one of +% the next two commands: +% \alwaysRootAtTop +% \alwaysRootAtBottom (default) +% + +% Optional short abbreviations for commands: +\def\EnableBpAbbreviations{% + \let\AX\Axiom + \let\AXC\AxiomC + \let\UI\UnaryInf + \let\UIC\UnaryInfC + \let\BI\BinaryInf + \let\BIC\BinaryInfC + \let\TI\TrinaryInf + \let\TIC\TrinaryInfC + \let\QI\QuaternaryInf + \let\QIC\QuaternaryInfC + \let\QuI\QuinaryInf + \let\QuIC\QuinaryInfC + \let\LL\LeftLabel + \let\RL\RightLabel + \let\DP\DisplayProof +} + +% Parameters which control the style of the proof trees. +% The user may wish to override these parameters locally or globally. +% BUT DON'T CHANGE THE PARAMETERS BY CHANGING THIS FILE (to avoid +% future incompatibilities). Instead, you should change them in your +% TeX document right after including this style file in the +% header material of your LaTeX document. + +\def\ScoreOverhang{4pt} % How much underlines extend out +\def\ScoreOverhangLeft{\ScoreOverhang} +\def\ScoreOverhangRight{\ScoreOverhang} + +\def\extraVskip{2pt} % Extra space above and below lines +\def\ruleScoreFiller{\hrule} % Horizontal rule filler. +\def\dottedScoreFiller{\hbox to4pt{\hss.\hss}} +\def\dashedScoreFiller{\hbox to2.8mm{\hss\vrule width1.4mm height0.4pt depth0.0pt\hss}} +\def\defaultScoreFiller{\ruleScoreFiller} % Default horizontal filler. +\def\defaultBuildScore{\buildSingleScore} % In \singleLine mode at start. + +\def\defaultHypSeparation{\hskip.2in} % Used if \insertBetweenHyps isn't given + +\def\labelSpacing{3pt} % Horizontal space separating labels and lines + +\def\proofSkipAmount{\vskip.8ex plus.8ex minus.4ex} + % Space above and below a prooftree display. + +\def\defaultRootPosition{\buildRootBottom} % Default: Proofs root at bottom +%\def\defaultRootPosition{\buildRootTop} % Makes all proofs upside down + +\ifx\fCenter\undefined +\def\fCenter{\relax} +\fi + +% +% End of user-modifiable parameters. +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Here are some internal paramenters and defaults. Not really intended +% to be user-modifiable. + +\def\theHypSeparation{\defaultHypSeparation} +\def\alwaysScoreFiller{\defaultScoreFiller} % Horizontal filler. +\def\alwaysBuildScore{\defaultBuildScore} +\def\theScoreFiller{\alwaysScoreFiller} % Horizontal filler. +\def\buildScore{\alwaysBuildScore} %This command builds the score. +\def\hypKernAmt{0pt} % Initial setting for kerning the hypotheses. + +\def\defaultLeftLabel{} +\def\defaultRightLabel{} + +\def\myTrue{Y} +\def\bottomAlignFlag{N} +\def\centerAlignFlag{N} +\def\defaultRootAtBottomFlag{Y} +\def\rootAtBottomFlag{Y} + +% End of internal parameters and defaults. + +\expandafter\ifx\csname newenvironment\endcsname\relax% +% If in TeX: +\message{\BPmessage} +\def\makeatletter{\catcode`\@=11\relax} +\def\makeatother{\catcode`\@=12\relax} +\makeatletter +\def\newcount{\alloc@0\count\countdef\insc@unt} +\def\newdimen{\alloc@1\dimen\dimendef\insc@unt} +\def\newskip{\alloc@2\skip\skipdef\insc@unt} +\def\newbox{\alloc@4\box\chardef\insc@unt} +\makeatother +\else +% If in LaTeX +\typeout{\BPmessage} +\newenvironment{prooftree}% +{\begin{center}\proofSkipAmount \leavevmode}% +{\DisplayProof \proofSkipAmount \end{center} } +\fi + +\def\thecur#1{\csname#1\number\theLevel\endcsname} + +\newcount\theLevel % This counter is the height of the stack. +\global\theLevel=0 % Initialized to zero +\newcount\myMaxLevel +\global\myMaxLevel=0 +\newbox\myBoxA % Temporary storage boxes +\newbox\myBoxB +\newbox\myBoxC +\newbox\myBoxD +\newbox\myBoxLL % Boxes for the left label and the right label. +\newbox\myBoxRL +\newdimen\thisAboveSkip %Internal use: amount to skip above line +\newdimen\thisBelowSkip %Internal use: amount to skip below line +\newdimen\newScoreStart % More temporary storage. +\newdimen\newScoreEnd +\newdimen\newCenter +\newdimen\displace +\newdimen\leftLowerAmt% Amount to lower left label +\newdimen\rightLowerAmt% Amount to lower right label +\newdimen\scoreHeight% Score height +\newdimen\scoreDepth% Score Depth +\newdimen\htLbox% +\newdimen\htRbox% +\newdimen\htRRbox% +\newdimen\htRRRbox% +\newdimen\htAbox% +\newdimen\htCbox% + +\setbox\myBoxLL=\hbox{\defaultLeftLabel}% +\setbox\myBoxRL=\hbox{\defaultRightLabel}% + +\def\allocatemore{% + \ifnum\theLevel>\myMaxLevel% + \expandafter\newbox\curBox% + \expandafter\newdimen\curScoreStart% + \expandafter\newdimen\curCenter% + \expandafter\newdimen\curScoreEnd% + \global\advance\myMaxLevel by1% + \fi% +} + +\def\prepAxiom{% + \advance\theLevel by1% + \edef\curBox{\thecur{myBox}}% + \edef\curScoreStart{\thecur{myScoreStart}}% + \edef\curCenter{\thecur{myCenter}}% + \edef\curScoreEnd{\thecur{myScoreEnd}}% + \allocatemore% +} + +\def\Axiom$#1\fCenter#2${% + % Get level and correct names set. + \prepAxiom% + % Define the boxes + \setbox\myBoxA=\hbox{$\mathord{#1}\fCenter\mathord{\relax}$}% + \setbox\myBoxB=\hbox{$#2$}% + \global\setbox\curBox=% + \hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\unhcopy\myBoxB\hskip\ScoreOverhangRight\relax}% + % Set the relevant dimensions for the boxes + \global\curScoreStart=0pt \relax + \global\curScoreEnd=\wd\curBox \relax + \global\curCenter=\wd\myBoxA \relax + \global\advance \curCenter by \ScoreOverhangLeft% + \ignorespaces +} + +\def\AxiomC#1{ % Note argument not in math mode + % Get level and correct names set. + \prepAxiom% + % Define the box. + \setbox\myBoxA=\hbox{#1}% + \global\setbox\curBox =% + \hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\hskip\ScoreOverhangRight\relax}% + % Set the relevant dimensions for the boxes + \global\curScoreStart=0pt \relax + \global\curScoreEnd=\wd\curBox \relax + \global\curCenter=.5\wd\curBox \relax + \global\advance \curCenter by \ScoreOverhangLeft% + \ignorespaces +} + +\def\prepUnary{% + \ifnum \theLevel<1 + \errmessage{Hypotheses missing!} + \fi% + \edef\curBox{\thecur{myBox}}% + \edef\curScoreStart{\thecur{myScoreStart}}% + \edef\curCenter{\thecur{myCenter}}% + \edef\curScoreEnd{\thecur{myScoreEnd}}% +} + +\def\UnaryInf$#1\fCenter#2${% + \prepUnary% + \buildConclusion{#1}{#2}% + \joinUnary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\UnaryInfC#1{ + \prepUnary% + \buildConclusionC{#1}% + %Align and join the curBox and the new box into one vbox. + \joinUnary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\prepBinary{% + \ifnum\theLevel<2 + \errmessage{Hypotheses missing!} + \fi% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\BinaryInf$#1\fCenter#2${% + \prepBinary% + \buildConclusion{#1}{#2}% + \joinBinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\BinaryInfC#1{% + \prepBinary% + \buildConclusionC{#1}% + \joinBinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\prepTrinary{% + \ifnum\theLevel<3 + \errmessage{Hypotheses missing!} + \fi% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\ccurBox{\thecur{myBox}}% Set up names of center hypothesis + \edef\ccurScoreStart{\thecur{myScoreStart}}% + \edef\ccurCenter{\thecur{myCenter}}% + \edef\ccurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\TrinaryInf$#1\fCenter#2${% + \prepTrinary% + \buildConclusion{#1}{#2}% + \joinTrinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\TrinaryInfC#1{% + \prepTrinary% + \buildConclusionC{#1}% + \joinTrinary% + \resetInferenceDefaults% + \ignorespaces% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\def\prepQuaternary{% + \ifnum\theLevel<4 + \errmessage{Hypotheses missing!} + \fi% + \edef\rrcurBox{\thecur{myBox}}% Set up names of very right hypothesis + \edef\rrcurScoreStart{\thecur{myScoreStart}}% + \edef\rrcurCenter{\thecur{myCenter}}% + \edef\rrcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\ccurBox{\thecur{myBox}}% Set up names of center hypothesis + \edef\ccurScoreStart{\thecur{myScoreStart}}% + \edef\ccurCenter{\thecur{myCenter}}% + \edef\ccurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\QuaternaryInf$#1\fCenter#2${% + \prepQuaternary% + \buildConclusion{#1}{#2}% + \joinQuaternary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\QuaternaryInfC#1{% + \prepQuaternary% + \buildConclusionC{#1}% + \joinQuaternary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\joinQuaternary{% Construct the quarterary inference into a vbox. + % Join the four hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rrcurScoreEnd% + \advance\lcurScoreEnd by\wd\rcurBox% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\ccurBox% + \advance\lcurScoreEnd by3\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\ccurBox% + \unhcopy\myBoxA\box\rcurBox + \unhcopy\myBoxA\box\rrcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htCbox = \ht\ccurBox% + \htRbox = \ht\rcurBox% + \htRRbox = \ht\rrcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\copy\myBoxA\lower\htCbox\box\ccurBox% + \lower\htAbox\copy\myBoxA\lower\htRbox\box\rcurBox% + \lower\htAbox\copy\myBoxA\lower\htRRbox\box\rrcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\def\prepQuinary{% + \ifnum\theLevel<5 + \errmessage{Hypotheses missing!} + \fi% + \edef\rrrcurBox{\thecur{myBox}}% Set up names of very very right hypothesis + \edef\rrrcurScoreStart{\thecur{myScoreStart}}% + \edef\rrrcurCenter{\thecur{myCenter}}% + \edef\rrrcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\rrcurBox{\thecur{myBox}}% Set up names of very right hypothesis + \edef\rrcurScoreStart{\thecur{myScoreStart}}% + \edef\rrcurCenter{\thecur{myCenter}}% + \edef\rrcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\ccurBox{\thecur{myBox}}% Set up names of center hypothesis + \edef\ccurScoreStart{\thecur{myScoreStart}}% + \edef\ccurCenter{\thecur{myCenter}}% + \edef\ccurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\QuinaryInf$#1\fCenter#2${% + \prepQuinary% + \buildConclusion{#1}{#2}% + \joinQuinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\QuinaryInfC#1{% + \prepQuinary% + \buildConclusionC{#1}% + \joinQuinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\joinQuinary{% Construct the quinary inference into a vbox. + % Join the five hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rrrcurScoreEnd% + \advance\lcurScoreEnd by\wd\rrcurBox% + \advance\lcurScoreEnd by\wd\rcurBox% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\ccurBox% + \advance\lcurScoreEnd by4\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\ccurBox% + \unhcopy\myBoxA\box\rcurBox + \unhcopy\myBoxA\box\rrcurBox + \unhcopy\myBoxA\box\rrrcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htCbox = \ht\ccurBox% + \htRbox = \ht\rcurBox% + \htRRbox = \ht\rrcurBox% + \htRRRbox = \ht\rrrcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\copy\myBoxA\lower\htCbox\box\ccurBox% + \lower\htAbox\copy\myBoxA\lower\htRbox\box\rcurBox% + \lower\htAbox\copy\myBoxA\lower\htRRbox\box\rrcurBox% + \lower\htAbox\copy\myBoxA\lower\htRRRbox\box\rrrcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\def\buildConclusion#1#2{% Build lower sequent w/ center at \fCenter position. + % Define the boxes + \setbox\myBoxA=\hbox{$\mathord{#1}\fCenter\mathord{\relax}$}% + \setbox\myBoxB=\hbox{$#2$}% + % Put them together in \myBoxC + \setbox\myBoxC =% + \hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\unhcopy\myBoxB\hskip\ScoreOverhangRight\relax}% + % Calculate the center of the \myBoxC string. + \newScoreStart=0pt \relax% + \newCenter=\wd\myBoxA \relax% + \advance \newCenter by \ScoreOverhangLeft% + \newScoreEnd=\wd\myBoxC% +} + +\def\buildConclusionC#1{% Build lower sequent w/o \fCenter present. + % Define the box. + \setbox\myBoxA=\hbox{#1}% + \setbox\myBoxC =% + \hbox{\hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\hskip\ScoreOverhangRight\relax}}% + % Calculate kerning to line up centers + \newScoreStart=0pt \relax% + \newCenter=.5\wd\myBoxC \relax% + \newScoreEnd=\wd\myBoxC% + \advance \newCenter by \ScoreOverhangLeft% +} + +\def\joinUnary{%Align and join \curBox and \myBoxC into a single vbox + \global\advance\curCenter by -\hypKernAmt% + \ifnum\curCenter<\newCenter% + \displace=\newCenter% + \advance \displace by -\curCenter% + \kernUpperBox% + \else% + \displace=\curCenter% + \advance \displace by -\newCenter% + \kernLowerBox% + \fi% + \ifnum \newScoreStart < \curScoreStart % + \global \curScoreStart = \newScoreStart \fi% + \ifnum \curScoreEnd < \newScoreEnd % + \global \curScoreEnd = \newScoreEnd \fi% + % Leave room for the left label. + \ifnum \curScoreStart<\wd\myBoxLL% + \global\displace = \wd\myBoxLL% + \global\advance\displace by -\curScoreStart% + \kernUpperBox% + \kernLowerBox% + \fi% + % Draw the score + \buildScore% + % Form the score and labels into a box. + \buildScoreLabels% + % Form the new box and its dimensions + \ifx\rootAtBottomFlag\myTrue% + \buildRootBottom% + \else% + \buildRootTop% + \fi% + \global \curScoreStart=\newScoreStart% + \global \curScoreEnd=\newScoreEnd% + \global \curCenter=\newCenter% +} + +\def\buildRootBottom{% + \global \setbox \curBox =% + \vbox{\box\curBox% + \vskip\thisAboveSkip \relax% + \nointerlineskip\box\myBoxD% + \vskip\thisBelowSkip \relax% + \nointerlineskip\box\myBoxC}% +} + +\def\buildRootTop{% + \global \setbox \curBox =% + \vbox{\box\myBoxC% + \vskip\thisAboveSkip \relax% + \nointerlineskip\box\myBoxD% + \vskip\thisBelowSkip \relax% + \nointerlineskip\box\curBox}% +} + +\def\kernUpperBox{% + \global\setbox\curBox =% + \hbox{\hskip\displace\box\curBox}% + \global\advance \curScoreStart by \displace% + \global\advance \curScoreEnd by \displace% + \global\advance\curCenter by \displace% +} + +\def\kernLowerBox{% + \global\setbox\myBoxC =% + \hbox{\hskip\displace\unhbox\myBoxC}% + \global\advance \newScoreStart by \displace% + \global\advance \newScoreEnd by \displace% + \global\advance\newCenter by \displace% +} + +\def\joinBinary{% Construct the binary inference into a vbox. + % Join the two hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rcurScoreEnd% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\rcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htRbox = \ht\rcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\box\myBoxA\lower\htRbox\box\rcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +\def\joinTrinary{% Construct the trinary inference into a vbox. + % Join the three hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rcurScoreEnd% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\ccurBox% + \advance\lcurScoreEnd by2\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\ccurBox% + \unhcopy\myBoxA\box\rcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htCbox = \ht\ccurBox% + \htRbox = \ht\rcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\copy\myBoxA\lower\htCbox\box\ccurBox% + \lower\htAbox\copy\myBoxA\lower\htRbox\box\rcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +\def\DisplayProof{% + % Display (and purge) the proof tree. + % Choose the appropriate vertical alignment. + \ifnum \theLevel=1 \relax \else%x + \errmessage{Proof tree badly specified.}% + \fi% + \edef\curBox{\thecur{myBox}}% + \ifx\bottomAlignFlag\myTrue% + \displace=0pt% + \else% + \displace=.5\ht\curBox% + \ifx\centerAlignFlag\myTrue\relax + \else% + \advance\displace by -3pt% + \fi% + \fi% + \leavevmode% + \lower\displace\hbox{\copy\curBox}% + \global\theLevel=0% + \global\def\alwaysBuildScore{\defaultBuildScore}% Restore "always" + \global\def\alwaysScoreFiller{\defaultScoreFiller}% Restore "always" + \global\def\bottomAlignFlag{N}% + \global\def\centerAlignFlag{N}% + \resetRootPosition + \resetInferenceDefaults% + \ignorespaces +} + +\def\buildSingleScore{% Make an hbox with a single score. + \displace=\curScoreEnd% + \advance \displace by -\curScoreStart% + \global\setbox \myBoxD =% + \hbox to \displace{\expandafter\xleaders\theScoreFiller\hfill}% + %\global\setbox \myBoxD =% + %\hbox{\hskip\curScoreStart\relax \box\myBoxD}% +} + +\def\buildDoubleScore{% Make an hbox with a double score. + \buildSingleScore% + \global\setbox\myBoxD=% + \hbox{\hbox to0pt{\copy\myBoxD\hss}\raise2pt\copy\myBoxD}% +} + +\def\buildNoScore{% Make an hbox with no score (raise a little anyway) + \global\setbox\myBoxD=\hbox{\vbox{\vskip1pt}}% +} + +\def\doubleLine{% + \gdef\buildScore{\buildDoubleScore}% Set next score to this type + \ignorespaces +} +\def\alwaysDoubleLine{% + \gdef\alwaysBuildScore{\buildDoubleScore}% Do double for rest of proof. + \gdef\buildScore{\buildDoubleScore}% Set next score to be double + \ignorespaces +} +\def\singleLine{% + \gdef\buildScore{\buildSingleScore}% Set next score to be single + \ignorespaces +} +\def\alwaysSingleLine{% + \gdef\alwaysBuildScore{\buildSingleScore}% Do single for rest of proof. + \gdef\buildScore{\buildSingleScore}% Set next score to be single + \ignorespaces +} +\def\noLine{% + \gdef\buildScore{\buildNoScore}% Set next score to this type + \ignorespaces +} +\def\alwaysNoLine{% + \gdef\alwaysBuildScore{\buildNoScore}%Do nolines for rest of proof. + \gdef\buildScore{\buildNoScore}% Set next score to be blank + \ignorespaces +} +\def\solidLine{% + \gdef\theScoreFiller{\ruleScoreFiller}% Use solid horizontal line. + \ignorespaces +} +\def\alwaysSolidLine{% + \gdef\alwaysScoreFiller{\ruleScoreFiller}% Do solid for rest of proof + \gdef\theScoreFiller{\ruleScoreFiller}% Use solid horizontal line. + \ignorespaces +} +\def\dottedLine{% + \gdef\theScoreFiller{\dottedScoreFiller}% Use dotted horizontal line. + \ignorespaces +} +\def\alwaysDottedLine{% + \gdef\alwaysScoreFiller{\dottedScoreFiller}% Do dotted for rest of proof + \gdef\theScoreFiller{\dottedScoreFiller}% Use dotted horizontal line. + \ignorespaces +} +\def\dashedLine{% + \gdef\theScoreFiller{\dashedScoreFiller}% Use dashed horizontal line. + \ignorespaces +} +\def\alwaysDashedLine{% + \gdef\alwaysScoreFiller{\dashedScoreFiller}% Do dashed for rest of proof + \gdef\theScoreFiller{\dashedScoreFiller}% Use dashed horizontal line. + \ignorespaces +} +\def\kernHyps#1{% + \gdef\hypKernAmt{#1}% + \ignorespaces +} +\def\insertBetweenHyps#1{% + \gdef\theHypSeparation{#1}% + \ignorespaces +} + +\def\centerAlignProof{% + \def\centerAlignFlag{Y}% + \def\bottomAlignFlag{N}% + \ignorespaces +} +\def\bottomAlignProof{% + \def\centerAlignFlag{N}% + \def\bottomAlignFlag{Y}% + \ignorespaces +} +\def\normalAlignProof{% + \def\centerAlignFlag{N}% + \def\bottomAlignFlag{N}% + \ignorespaces +} + +\def\LeftLabel#1{% + \global\setbox\myBoxLL=\hbox{{#1}\hskip\labelSpacing}% + \ignorespaces +} +\def\RightLabel#1{% + \global\setbox\myBoxRL=\hbox{\hskip\labelSpacing #1}% + \ignorespaces +} + +\def\buildScoreLabels{% + \scoreHeight = \ht\myBoxD% + \scoreDepth = \dp\myBoxD% + \leftLowerAmt=\ht\myBoxLL% + \advance \leftLowerAmt by -\dp\myBoxLL% + \advance \leftLowerAmt by -\scoreHeight% + \advance \leftLowerAmt by \scoreDepth% + \leftLowerAmt=.5\leftLowerAmt% + \rightLowerAmt=\ht\myBoxRL% + \advance \rightLowerAmt by -\dp\myBoxRL% + \advance \rightLowerAmt by -\scoreHeight% + \advance \rightLowerAmt by \scoreDepth% + \rightLowerAmt=.5\rightLowerAmt% + \displace = \curScoreStart% + \advance\displace by -\wd\myBoxLL% + \global\setbox\myBoxD =% + \hbox{\hskip\displace% + \lower\leftLowerAmt\copy\myBoxLL% + \box\myBoxD% + \lower\rightLowerAmt\copy\myBoxRL}% + \global\thisAboveSkip = \ht\myBoxLL% + \global\advance \thisAboveSkip by -\leftLowerAmt% + \global\advance \thisAboveSkip by -\scoreHeight% + \ifnum \thisAboveSkip<0 % + \global\thisAboveSkip=0pt% + \fi% + \displace = \ht\myBoxRL% + \advance \displace by -\rightLowerAmt% + \advance \displace by -\scoreHeight% + \ifnum \displace<0 % + \displace=0pt% + \fi% + \ifnum \displace>\thisAboveSkip % + \global\thisAboveSkip=\displace% + \fi% + \global\thisBelowSkip = \dp\myBoxLL% + \global\advance\thisBelowSkip by \leftLowerAmt% + \global\advance\thisBelowSkip by -\scoreDepth% + \ifnum\thisBelowSkip<0 % + \global\thisBelowSkip = 0pt% + \fi% + \displace = \dp\myBoxRL% + \advance\displace by \rightLowerAmt% + \advance\displace by -\scoreDepth% + \ifnum\displace<0 % + \displace = 0pt% + \fi% + \ifnum\displace>\thisBelowSkip% + \global\thisBelowSkip = \displace% + \fi% + \global\thisAboveSkip = -\thisAboveSkip% + \global\thisBelowSkip = -\thisBelowSkip% + \global\advance\thisAboveSkip by\extraVskip% Extra space above line + \global\advance\thisBelowSkip by\extraVskip% Extra space below line +} + +\def\resetInferenceDefaults{% + \global\def\theHypSeparation{\defaultHypSeparation}% + \global\setbox\myBoxLL=\hbox{\defaultLeftLabel}% + \global\setbox\myBoxRL=\hbox{\defaultRightLabel}% + \global\def\buildScore{\alwaysBuildScore}% + \global\def\theScoreFiller{\alwaysScoreFiller}% + \gdef\hypKernAmt{0pt}% Restore to zero kerning. +} + + +\def\rootAtBottom{% + \global\def\rootAtBottomFlag{Y}% +} + +\def\rootAtTop{% + \global\def\rootAtBottomFlag{N}% +} + +\def\resetRootPosition{% + \global\edef\rootAtBottomFlag{\defaultRootAtBottomFlag} +} + +\def\alwaysRootAtBottom{% + \global\def\defaultRootAtBottomFlag{Y} + \rootAtBottom +} + +\def\alwaysRootAtTop{% + \global\def\defaultRootAtBottomFlag{N} + \rootAtTop +} + + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/dummy.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/dummy.tex Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,61 @@ + +%%% jdummy.def +% +\DeclareRelationFont{JY1}{mc}{it}{}{OT1}{cmr}{it}{} +\DeclareRelationFont{JT1}{mc}{it}{}{OT1}{cmr}{it}{} +\DeclareFontShape{JY1}{mc}{m}{it}{<5> <6> <7> <8> <9> <10> sgen*min + <10.95><12><14.4><17.28><20.74><24.88> min10 + <-> min10}{} +\DeclareFontShape{JT1}{mc}{m}{it}{<5> <6> <7> <8> <9> <10> sgen*tmin + <10.95><12><14.4><17.28><20.74><24.88> tmin10 + <-> tmin10}{} +\DeclareRelationFont{JY1}{mc}{sl}{}{OT1}{cmr}{sl}{} +\DeclareRelationFont{JT1}{mc}{sl}{}{OT1}{cmr}{sl}{} +\DeclareFontShape{JY1}{mc}{m}{sl}{<5> <6> <7> <8> <9> <10> sgen*min + <10.95><12><14.4><17.28><20.74><24.88> min10 + <-> min10}{} +\DeclareFontShape{JT1}{mc}{m}{sl}{<5> <6> <7> <8> <9> <10> sgen*tmin + <10.95><12><14.4><17.28><20.74><24.88> tmin10 + <-> tmin10}{} +\DeclareRelationFont{JY1}{mc}{sc}{}{OT1}{cmr}{sc}{} +\DeclareRelationFont{JT1}{mc}{sc}{}{OT1}{cmr}{sc}{} +\DeclareFontShape{JY1}{mc}{m}{sc}{<5> <6> <7> <8> <9> <10> sgen*min + <10.95><12><14.4><17.28><20.74><24.88> min10 + <-> min10}{} +\DeclareFontShape{JT1}{mc}{m}{sc}{<5> <6> <7> <8> <9> <10> sgen*tmin + <10.95><12><14.4><17.28><20.74><24.88> tmin10 + <-> tmin10}{} +\DeclareRelationFont{JY1}{gt}{it}{}{OT1}{cmbx}{it}{} +\DeclareRelationFont{JT1}{gt}{it}{}{OT1}{cmbx}{it}{} +\DeclareFontShape{JY1}{mc}{bx}{it}{<5> <6> <7> <8> <9> <10> sgen*goth + <10.95><12><14.4><17.28><20.74><24.88> goth10 + <-> goth10}{} +\DeclareFontShape{JT1}{mc}{bx}{it}{<5> <6> <7> <8> <9> <10> sgen*tgoth + <10.95><12><14.4><17.28><20.74><24.88> tgoth10 + <-> tgoth10}{} +\DeclareRelationFont{JY1}{gt}{sl}{}{OT1}{cmbx}{sl}{} +\DeclareRelationFont{JT1}{gt}{sl}{}{OT1}{cmbx}{sl}{} +\DeclareFontShape{JY1}{mc}{bx}{sl}{<5> <6> <7> <8> <9> <10> sgen*goth + <10.95><12><14.4><17.28><20.74><24.88> goth10 + <-> goth10}{} +\DeclareFontShape{JT1}{mc}{bx}{sl}{<5> <6> <7> <8> <9> <10> sgen*tgoth + <10.95><12><14.4><17.28><20.74><24.88> tgoth10 + <-> tgoth10}{} +\DeclareRelationFont{JY1}{gt}{sc}{}{OT1}{cmbx}{sc}{} +\DeclareRelationFont{JT1}{gt}{sc}{}{OT1}{cmbx}{sc}{} +\DeclareFontShape{JY1}{mc}{bx}{sc}{<5> <6> <7> <8> <9> <10> sgen*goth + <10.95><12><14.4><17.28><20.74><24.88> goth10 + <-> goth10}{} +\DeclareFontShape{JT1}{mc}{bx}{sc}{<5> <6> <7> <8> <9> <10> sgen*tgoth + <10.95><12><14.4><17.28><20.74><24.88> tgoth10 + <-> tgoth10}{} +\DeclareRelationFont{JY1}{gt}{it}{}{OT1}{cmr}{it}{} +\DeclareRelationFont{JT1}{gt}{it}{}{OT1}{cmr}{it}{} +\DeclareFontShape{JY1}{gt}{m}{it}{<5> <6> <7> <8> <9> <10> sgen*goth + <10.95><12><14.4><17.28><20.74><24.88> goth10 + <-> goth10}{} +\DeclareFontShape{JT1}{gt}{m}{it}{<5> <6> <7> <8> <9> <10> sgen*tgoth + <10.95><12><14.4><17.28><20.74><24.88> tgoth10 + <-> tgoth10}{} +\endinput +%%%% end of jdummy.def diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/fancyhdr.sty --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/fancyhdr.sty Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,236 @@ +%% +%% This is file `fancyhdr.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% fancyhdr.dtx (with options: `fancyhdr') +%% +%% This is a generated file. +%% +%% This file may be distributed and/or modified under the conditions of +%% the LaTeX Project Public License, either version 1.3 of this license +%% or (at your option) any later version. The latest version of this +%% license is in: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% and version 1.3 or later is part of all distributions of LaTeX version +%% 2005/12/01 or later. +%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{fancyhdr}% + [2017/06/30 v3.9a + Extensive control of page headers and footers]% +% Copyright (C) 1994-2016 by Piet van Oostrum +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\def\if@nch@mpty#1{\def\temp@a{#1}\ifx\temp@a\@empty} +\def\f@nch@def#1#2{\if@nch@mpty{#2}\f@nch@gbl\def#1{\leavevmode}\else + \f@nch@gbl\def#1{#2\strut}\fi} +\let\f@nch@gbl\global +\def\f@nch@errmsg#1{% + \ifx\PackageError\undefined \errmessage{#1}\else + \PackageError{Fancyhdr}{#1}{}\fi} +\def\f@nch@warning#1{% + \ifx\PackageWarning\undefined \errmessage{#1}\else + \PackageWarning{Fancyhdr}{#1}{}\fi} +\def\f@nch@forc#1#2#3{\expandafter\f@rc\expandafter#1\expandafter{#2}{#3}} +\def\f@rc#1#2#3{\def\temp@ty{#2}\ifx\@empty\temp@ty\else + \f@nch@rc#1#2\f@nch@rc{#3}\fi} +\def\f@nch@rc#1#2#3\f@nch@rc#4{\def#1{#2}#4\f@rc#1{#3}{#4}} +\newcommand{\f@nch@for}[3]{\edef\@fortmp{#2}% + \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}} +\newcommand\f@nch@default[3]{% + \edef\temp@a{\lowercase{\edef\noexpand\temp@a{#3}}}\temp@a \def#1{}% + \f@nch@forc\tmpf@ra{#2}% + {\expandafter\f@nch@ifin\tmpf@ra\temp@a{\edef#1{#1\tmpf@ra}}{}}% + \ifx\@empty#1\def#1{#2}\fi} +\newcommand{\f@nch@ifin}[4]{% + \edef\temp@a{#2}\def\temp@b##1#1##2\temp@b{\def\temp@b{##1}}% + \expandafter\temp@b#2#1\temp@b\ifx\temp@a\temp@b #4\else #3\fi} +\newcommand{\fancyhead}[2][]{\f@nch@fancyhf\fancyhead h[#1]{#2}}% +\newcommand{\fancyfoot}[2][]{\f@nch@fancyhf\fancyfoot f[#1]{#2}}% +\newcommand{\fancyhf}[2][]{\f@nch@fancyhf\fancyhf {}[#1]{#2}}% +\newcommand{\fancyheadoffset}[2][]{\f@nch@fancyhfoffs\fancyheadoffset h[#1]{#2}}% +\newcommand{\fancyfootoffset}[2][]{\f@nch@fancyhfoffs\fancyfootoffset f[#1]{#2}}% +\newcommand{\fancyhfoffset}[2][]{\f@nch@fancyhfoffs\fancyhfoffset {}[#1]{#2}}% +\def\f@nch@fancyhf#1#2[#3]#4{% + \def\temp@c{}% + \f@nch@forc\tmpf@ra{#3}% + {\expandafter\f@nch@ifin\tmpf@ra{eolcrhf,EOLCRHF}% + {}{\edef\temp@c{\temp@c\tmpf@ra}}}% + \ifx\@empty\temp@c\else \f@nch@errmsg{Illegal char `\temp@c' in + \string#1 argument: [#3]}% + \fi \f@nch@for\temp@c{#3}% + {\f@nch@default\f@nch@@eo{eo}\temp@c \if@twoside\else \if\f@nch@@eo + e\f@nch@warning {\string#1's `E' option without twoside option is + useless}\fi\fi \f@nch@default\f@nch@@lcr{lcr}\temp@c + \f@nch@default\f@nch@@hf{hf}{#2\temp@c}% + \f@nch@forc\f@nch@eo\f@nch@@eo + {\f@nch@forc\f@nch@lcr\f@nch@@lcr + {\f@nch@forc\f@nch@hf\f@nch@@hf + {\expandafter\f@nch@def\csname + f@nch@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname {#4}}}}}} +\def\f@nch@fancyhfoffs#1#2[#3]#4{% + \def\temp@c{}% + \f@nch@forc\tmpf@ra{#3}% + {\expandafter\f@nch@ifin\tmpf@ra{eolrhf,EOLRHF}% + {}{\edef\temp@c{\temp@c\tmpf@ra}}}% + \ifx\@empty\temp@c\else \f@nch@errmsg{Illegal char `\temp@c' in + \string#1 argument: [#3]}% + \fi \f@nch@for\temp@c{#3}% + {\f@nch@default\f@nch@@eo{eo}\temp@c \if@twoside\else \if\f@nch@@eo + e\f@nch@warning {\string#1's `E' option without twoside option is + useless}\fi\fi \f@nch@default\f@nch@@lcr{lr}\temp@c + \f@nch@default\f@nch@@hf{hf}{#2\temp@c}% + \f@nch@forc\f@nch@eo\f@nch@@eo + {\f@nch@forc\f@nch@lcr\f@nch@@lcr + {\f@nch@forc\f@nch@hf\f@nch@@hf + {\expandafter\setlength\csname + f@nch@O@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname {#4}}}}}% + \f@nch@setoffs} +\newcommand{\lhead}[2][\f@nch@olh]% + {\f@nch@def\f@nch@olh{#2}\f@nch@def\f@nch@elh{#1}} +\newcommand{\chead}[2][\f@nch@och]% + {\f@nch@def\f@nch@och{#2}\f@nch@def\f@nch@ech{#1}} +\newcommand{\rhead}[2][\f@nch@orh]% + {\f@nch@def\f@nch@orh{#2}\f@nch@def\f@nch@erh{#1}} +\newcommand{\lfoot}[2][\f@nch@olf]% + {\f@nch@def\f@nch@olf{#2}\f@nch@def\f@nch@elf{#1}} +\newcommand{\cfoot}[2][\f@nch@ocf]% + {\f@nch@def\f@nch@ocf{#2}\f@nch@def\f@nch@ecf{#1}} +\newcommand{\rfoot}[2][\f@nch@orf]% + {\f@nch@def\f@nch@orf{#2}\f@nch@def\f@nch@erf{#1}} +\newlength{\f@nch@headwidth} \let\headwidth\f@nch@headwidth +\newlength{\f@nch@O@elh} +\newlength{\f@nch@O@erh} +\newlength{\f@nch@O@olh} +\newlength{\f@nch@O@orh} +\newlength{\f@nch@O@elf} +\newlength{\f@nch@O@erf} +\newlength{\f@nch@O@olf} +\newlength{\f@nch@O@orf} +\newcommand{\headrulewidth}{0.4pt} +\newcommand{\footrulewidth}{0pt} +\@ifundefined{footruleskip}% + {\newcommand{\footruleskip}{.3\normalbaselineskip}}{} +\newcommand{\plainheadrulewidth}{0pt} +\newcommand{\plainfootrulewidth}{0pt} +\newif\if@fancyplain \@fancyplainfalse +\def\fancyplain#1#2{\if@fancyplain#1\else#2\fi} +\headwidth=-123456789sp +\let\f@nch@raggedleft\raggedleft +\let\f@nch@raggedright\raggedright +\let\f@nch@centering\centering +\let\f@nch@everypar\everypar +\def\f@nch@reset{\f@nch@everypar{}\restorecr\endlinechar=13 + \let\\\@normalcr \let\raggedleft\f@nch@raggedleft + \let\raggedright\f@nch@raggedright \let\centering\f@nch@centering + \def\baselinestretch{1}% + \hsize=\headwidth + \def\nouppercase##1{{\let\uppercase\relax\let\MakeUppercase\relax + \expandafter\let\csname MakeUppercase \endcsname\relax##1}}% + \ifx\undefined\@newbaseline % NFSS not present; 2.09 or 2e + \ifx\@normalsize\undefined \normalsize % for ucthesis.cls + \else \@normalsize \fi \else % NFSS (2.09) present + \@newbaseline% + \fi} +\fancyhf{} +\if@twoside + \fancyhead[el,or]{\fancyplain{}{\slshape\rightmark}} + \fancyhead[er,ol]{\fancyplain{}{\slshape\leftmark}} +\else + \fancyhead[l]{\fancyplain{}{\slshape\rightmark}} + \fancyhead[r]{\fancyplain{}{\slshape\leftmark}} +\fi +\fancyfoot[c]{\rmfamily\thepage} % page number +\def\f@nch@vbox#1#2{\setbox0\vbox{#2}\ifdim\ht0>#1\f@nch@warning + {\string#1 is too small (\the#1): ^^J Make it at least \the\ht0.^^J We + now make it that large for the rest of the document.^^J This may + cause the page layout to be inconsistent, however\@gobble}% + \dimen0=#1\global\setlength{#1}{\ht0}\ht0=\dimen0\fi \box0} +\def\f@nch@head#1#2#3#4#5{#1\hbox to\headwidth{\f@nch@reset + \f@nch@vbox\headheight{\hbox + {\rlap{\parbox[b]{\headwidth}{\raggedright#2}}\hfill + \parbox[b]{\headwidth}{\centering#3}\hfill + \llap{\parbox[b]{\headwidth}{\raggedleft#4}}}\headrule}}#5} +\def\f@nch@foot#1#2#3#4#5{#1\hbox to\headwidth{\f@nch@reset + \f@nch@vbox\footskip{\footrule + \hbox{\rlap{\parbox[t]{\headwidth}{\raggedright#2}}\hfill + \parbox[t]{\headwidth}{\centering#3}\hfill + \llap{\parbox[t]{\headwidth}{\raggedleft#4}}}}}#5} +\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi + \hrule\@height\headrulewidth\@width\headwidth + \vskip-\headrulewidth}} +\def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi + \vskip-\footruleskip\vskip-\footrulewidth + \hrule\@width\headwidth\@height\footrulewidth\vskip\footruleskip}} +\def\ps@fancy{% + \@ifundefined{@chapapp}{\let\@chapapp\chaptername}{}% for amsbook +\@ifundefined{MakeUppercase}{\def\MakeUppercase{\uppercase}}{}% +\ifx\chapter\@undefined \def\sectionmark##1{\markboth + {\MakeUppercase{\ifnum \c@secnumdepth>\z@ \thesection\hskip 1em\relax + \fi ##1}}{}}% +\def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne + \thesubsection\hskip 1em\relax \fi ##1}}% +\else \def\chaptermark##1{\markboth {\MakeUppercase{\ifnum + \c@secnumdepth>\m@ne \@chapapp\ \thechapter. \ \fi ##1}}{}}% +\def\sectionmark##1{\markright{\MakeUppercase{\ifnum \c@secnumdepth >\z@ + \thesection. \ \fi ##1}}}% +\fi +\ps@@fancy +\gdef\ps@fancy{\@fancyplainfalse\ps@@fancy}% +\ifdim\headwidth<0sp + \global\advance\headwidth123456789sp\global\advance\headwidth\textwidth +\fi} +\def\ps@fancyplain{\ps@fancy \let\ps@plain\ps@plain@fancy} +\def\ps@plain@fancy{\@fancyplaintrue\ps@@fancy} +\let\ps@@empty\ps@empty +\def\ps@@fancy{% + \ps@@empty + \def\@mkboth{\protect\markboth}% + \def\@oddhead{\f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh}% + \def\@oddfoot{\f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf}% + \def\@evenhead{\f@nch@head\f@nch@Oelh\f@nch@elh\f@nch@ech\f@nch@erh\f@nch@Oerh}% + \def\@evenfoot{\f@nch@foot\f@nch@Oelf\f@nch@elf\f@nch@ecf\f@nch@erf\f@nch@Oerf}% +} +\def\f@nch@Oolh{\if@reversemargin\hss\else\relax\fi} +\def\f@nch@Oorh{\if@reversemargin\relax\else\hss\fi} +\let\f@nch@Oelh\f@nch@Oorh +\let\f@nch@Oerh\f@nch@Oolh +\let\f@nch@Oolf\f@nch@Oolh +\let\f@nch@Oorf\f@nch@Oorh +\let\f@nch@Oelf\f@nch@Oelh +\let\f@nch@Oerf\f@nch@Oerh +\def\f@nch@offsolh{\headwidth=\textwidth\advance\headwidth\f@nch@O@olh + \advance\headwidth\f@nch@O@orh\hskip-\f@nch@O@olh} +\def\f@nch@offselh{\headwidth=\textwidth\advance\headwidth\f@nch@O@elh + \advance\headwidth\f@nch@O@erh\hskip-\f@nch@O@elh} +\def\f@nch@offsolf{\headwidth=\textwidth\advance\headwidth\f@nch@O@olf + \advance\headwidth\f@nch@O@orf\hskip-\f@nch@O@olf} +\def\f@nch@offself{\headwidth=\textwidth\advance\headwidth\f@nch@O@elf + \advance\headwidth\f@nch@O@erf\hskip-\f@nch@O@elf} +\def\f@nch@setoffs{% + \f@nch@gbl\let\headwidth\f@nch@headwidth + \f@nch@gbl\let\f@nch@Oolh\f@nch@offsolh + \f@nch@gbl\let\f@nch@Oelh\f@nch@offselh \f@nch@gbl\let\f@nch@Oorh\hss + \f@nch@gbl\let\f@nch@Oerh\hss \f@nch@gbl\let\f@nch@Oolf\f@nch@offsolf + \f@nch@gbl\let\f@nch@Oelf\f@nch@offself \f@nch@gbl\let\f@nch@Oorf\hss + \f@nch@gbl\let\f@nch@Oerf\hss +} +\newif\iff@nch@footnote +\AtBeginDocument{% + \let\latex@makecol\@makecol + \def\@makecol{\ifvoid\footins\f@nch@footnotefalse\else\f@nch@footnotetrue\fi + \let\topfloat\@toplist\let\botfloat\@botlist\latex@makecol}% +} +\newcommand\iftopfloat[2]{\ifx\topfloat\empty #2\else #1\fi}% +\newcommand\ifbotfloat[2]{\ifx\botfloat\empty #2\else #1\fi}% +\newcommand\iffloatpage[2]{\if@fcolmade #1\else #2\fi}% +\newcommand\iffootnote[2]{\iff@nch@footnote #1\else #2\fi}% +\newcommand{\fancypagestyle}[2]{% + \@namedef{ps@#1}{\let\f@nch@gbl\relax#2\relax\ps@fancy}} +\endinput +%% +%% End of file `fancyhdr.sty'. diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/fig/goto.pdf Binary file final_pre/fig/goto.pdf has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/finalPre.pdf Binary file final_pre/finalPre.pdf has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/finalPre.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/finalPre.tex Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,231 @@ +\documentclass[twocolumn,twoside,9.5pt]{jarticle} +\usepackage[dvipdfmx]{graphicx} +\usepackage{picins} +\usepackage{fancyhdr} +%\pagestyle{fancy} +\usepackage{abstract} +\usepackage{url} +\usepackage{bussproofs} +\usepackage{listings,jlisting} +\lhead{\parpic{\includegraphics[height=1zw,keepaspectratio,bb=0 0 251 246]{../pic/emblem-bitmap.pdf}}琉球大学主催 工学部情報工学科 中間発表予稿} +\rhead{} +\cfoot{} + +\setlength{\topmargin}{-1in \addtolength{\topmargin}{15mm}} +\setlength{\headheight}{0mm} +\setlength{\headsep}{5mm} +\setlength{\oddsidemargin}{-1in \addtolength{\oddsidemargin}{11mm}} +\setlength{\evensidemargin}{-1in \addtolength{\evensidemargin}{21mm}} +\setlength{\textwidth}{181mm} +\setlength{\textheight}{261mm} +\setlength{\footskip}{0mm} +\pagestyle{empty} + +\lstset{ + frame=single, + keepspaces=true, + breaklines=true, + xleftmargin=0zw, + xrightmargin=0zw, + framerule=.2pt, + columns=[l]{fullflexible}, + language={}, + tabsize=4, + lineskip=-0.5zw, + escapechar={@}, +} + + +\input{dummy.tex} +\renewcommand{\abstractname}{Abstract} +\begin{document} + +\title{Agda と継続を用いたプログラムの検証 \\ Verification of program using Continuation by Agda} +\author{145750B 氏名 {外間}{政尊} 指導教員 : 河野 真治} +\date{} +\twocolumn [ +\maketitle +\begin{onecolabstract} + + % 高い信頼性を持つことは重要である。 + % 私たちはプログラムの信頼性を高めるためにCodeGear、DataGearという単位でプログラ + % ムを書くことを提案している。 + % そのためにCodeGear、DataGearという単位を使える言語 CbC を開発している。 + % CbC では既存の実装でのデータの取扱が複雑になっている。 + % そのためにDataGearとCodeGearを Interface という単位でまとめた。 + % これら単位をAgdaでも使えるようにし、CbC で記述した Stackや Tree を Agda に + % 変換した。 + % この論文ではそれらに対して幾つかの部分的な証明を試みた。 + + + High reliability is important in Program. + we are proposing programing units of CodeGear, DataGear for increase + the reliability. + we are deceloping Continuation based C (CbC) that can use units CodeGear and + DataGear. + In CbC, the handling of data in existing implementations is complicated. + for that purpose, we can provide a interface mechanisms which are packages of + CodeGears and DataGears. + we made these units and interface available for Agda. + In this papaer, we converted Stack and Tree using the interface discribe in + CbC to Agda, and we tried several proofs on them. + + +\end{onecolabstract}] +\thispagestyle{fancy} + +% ソフトウェアの信頼性の保証 +%   CbC の話(CG,DGの話も) +%   メタ計算を分けてる +% context (Meta DataGear) +% そのために interface +% Agda でも interfece を実装して検証した + +\section{ソフトウェアの信頼性の保証} +ソフトウェアの信頼性を保証することは重要である。現在ソフトウェアの信頼性を保証す +る方法として代表的なものはモデル検査と、定理証明が存在している。定理証明支援器と +して有名なものとしては Agda\cite{agda} が存在する。 + +当研究室では検証しやすいプログラムの単位として、 CodeGear と DataGear という単位 +を用いるプログラミングスタイルを提案している。 +また、 CodeGear 、 DataGear という単位を用いてプログラミングする言語として +Countinuation based C (以下 CbC) を開発している。 +% 本研究では、検証や証明に直接使用できる言語として CbC を用いる。 + +CbC では通常の計算とメタ計算を分けて記述している。 +しかし、CodeGear で DataGear を扱う際、 Context と呼ばれる CodeGear、 DataGear の +リスト等を持っている Meta DataGear を経由する。 +通常の CodeGear から Meta DataGear である Context を直接扱えると、ユーザーがメタ +計算をノーマルレベルで自由に記述できてしまい、信頼性を損なう。そのため、 CbC +では Context を通して、次の CodeGear に接続する Meta CodeGear である stub + CodeGear を定義している。 + +CbC で実装していくにつれて特殊な stub CodeGear の記述が複雑になった。 +そこで既存の実装をモジュールとして扱うために Interface という仕組みを導入した。 +Interface では、DataGear に対しての操作(API)を CodeGear とその CodeGear で扱われ +ている DataGearの集合を抽象的に表現した Meta DataGear として定義されている。 + +本研究では CbCで使われている Interface を含めて証明を行うために、 Agda 上で +Interface の定義、実装を行なった。 +また Interface を含めた Stack と Tree の部分的な証明を行なった。 + +\section{Countinuation based C (CbC)} +Continuation based C (CbC) とは、当研究室で開発されているプログラミング言語である。 +CbC は C 言語とほぼおなじ構文を持つが、 C の関数の代わりに CodeGear を用いて処理 +を記述する。 +CodeGear は関数定義の先頭に $\_\_code$ をつけて定義する。 +CodeGear は処理の単位でそれらの状態を goto で遷移して記述する。この goto による処理の遷移を継続と呼ぶ。 +DataGear は CodeGear が扱うデータの単位であり、処理に必要なデータが全て入っている。次の CodeGear に処理を移す際は、 goto の後に CodeGear 名と DataGear を指定する。 +CbC ではこの継続処理がメタ計算として定義されており、通常計算である CodeGear を変 +更することなく検証や資源管理等の記述を行うことができる。 +例として CbC の簡単な例をソースコード\ref{src:goto}に、流れを図\ref{fig:code_simple}示す。 + +\lstinputlisting[label=src:goto, caption=CbCコードの例]{./src/goto.cbc} + +\begin{figure}[htpb] + \begin{center} + \scalebox{0.7}[0.7]{\includegraphics{fig/codesegment.pdf}} + \end{center} + \caption{ソースコード\ref{src:goto}の流れ} + \label{fig:code_simple} +\end{figure} + +ソースコード\ref{src:goto}では cs0、 cs1 が CodeGear で a+b が cs0 の Output DataGear であり、 +cs1 の Input DataGear になる。 +流れ\ref{fig:code_simple}は cs0 から cs1 へ継続した後、 cs0 には戻らずに次の継 +続に指定された CodeGear へ継続する。 + +\section{Agda} +Agda とは定理証明支援器であり依存型を関数プログラミング言語である。 +依存型とは型も第一級オブジェクトとする型システムであり、型の型や型を引数に取る関数、値を取って型を返す関数などが記述することができる。 +CbC を Agda に変換する場合 DataGear はレコード型、 CodeGear は Agda での通常関数 +として定義できる。 +ソースコード\ref{src:goto} で示した CbC の簡単な例を Agda に変換したものをソースコー +ド\ref{src:agda-css}に示す。 + +\lstinputlisting[label=src:agda-css, caption= Agda における CodeSegment の定義] +{src/CodeSegments.agda} + +Agda のコードで関数を定義するときは関数名、型を記述した後に関数本体を指定する。 +関数の型では → または \verb/->/ を使い定義し、関数本体は関数名の後に$=$をつけて +記述する。 +DataGear はレコード型で表記できるため Agda 上で DataGear を定義することが可能で +ある。 + % 定義をする際は record キーワードのあとにレコード名、 +% 型、 where の後に field キーワードを入れ、フィールド名 : 型名 と列挙する。レコー +% ドを構築する際は record キーワードの後に {} 内部に fileName = value の形で列挙 +% していく。複数の値を列挙する際は ; で区切る。 +% Agda での DataGear の定義の例を以下のソースコード\ref{src:agda-ds}示す +% \lstinputlisting[label=src:agda-ds, caption=Agda における DataSegment の定義] {src/DataSegment.agda} +このように CbC のコードを Agda に変換し、証明を行う。 + +\section{CbC における Interface の定義} +CbC で実装していくにつれ、stub CodeGear の記述が煩雑になった。 +そのため 既存の実装を モジュールとして扱うため Interface を導入した。 +Interface は DataGear に対して何らかの操作(API)を行う CodeGear とその +CodeGear で使われる DataGear の集合を抽象化した メタレベルの DataGear +として定義した。例として Stack での Interface の実装(ソースコード\ref{src:interface})を示す。 + +\lstinputlisting[label=src:interface, caption=CbCでのStack-Interfaceの実装] {src/singleLinkedStackInterface.cbc} + +元の実装の push では Stack を指定する必要があるが、 +Interface での実装は push 先の Stack が stackImpl として扱 +われている。この stackImpl は呼ばれた時の Stack と同じになる。 +これにより、 ユーザーは実行時に Stack を指定する必要がなくなる。 +このように Interface 記述をすることで CbC で通常記述する必要がある一定の部分を省略し呼び出 +しが容易になる。 + + +\section{Agda における Interface の定義、実装} +Agda でも CbC と同様に Interface の定義、実装した。 +例として Agda で実装した Stack-interface の一部をみる。 +Stack の定義はソースコード\ref{src:agda-interface}、実装は ソースコード +\ref{src:agda-single-linked-stack} +として書かれている。それを Stack 側から interface を通して呼び出している。 + +\lstinputlisting[label=src:agda-interface, caption=Agda における Stack +-Interface の定義の一部] {src/AgdaInterface.agda} + +\lstinputlisting[label=src:agda-single-linked-stack, caption=Agda における Stack +-Interface の実装の一部] {src/AgdaSingleLinkedStack.agda} + +\section{Agda による Interface 部分を含めた Stack の部分的な証明} +今回は Interface を通した Stack で push +、 pop などの操作が正しく行われるかの証明を行った。 +ここでの証明とは Stack が特定の性質を持つことを保証することである。 + +Stack の処理として様々な性質が存在するが、ここでは +「どのような状態の Stack でも、値を push した後 pop した値は直前 +に入れた値と一致する」という性質を証明した。 + +まず始めに不定状態の Stack をソースコード~\ref{src:agda-in-some-state} +で定義した。 stackInSomeState は不定状態の Stack を定義する関数である。 +ソースコード~\ref{src:agda-proof}の証明ではこの stackInSomeState に対し +て、 push を2回行い、 pop2 をして取れたデータは push したデータと同じものになる +ことの証明している。 + + \lstinputlisting[label=src:agda-in-some-state, caption=不定なStackの定義]{src/AgdaStackSomeState.agda} + + \lstinputlisting[label=src:agda-proof, caption=push$->$push$->$pop2 の証明]{src/AgdaProof.agda} + +stackInSomeState は引数として s を取っていて、不定な Stack そこに x 、 y の2つのデー +タを push している。また、 pop2 で取れたデータは y1 、 x1 となっていて両方が +Just で返ってくるかつ、 x と x1 、 y と y1 がそれぞれ合同であることが仮定として +型に書いた。関数本体で返る値は$ x \equiv x1 と y \equiv y1$で両方共に成り立つ為、 + refl で推論が通る。 +これにより、抽象化した Stack に対して push を2回行い、 pop を行うと push したものと同じも +のを受け取れることが証明できた。 + +\section{まとめ} +本研究では CodeGear、 DataGear を用いたプログラミング手法を用いて、Agda で +Interface を用いたプログラムを実装、検証した。 +また、 CbC で記述した時には細かく分かっていなかった Interface の型が明確に +なった。 +今後の課題としては、Tree 側では証明が複雑化し、うまく証明できていないことと、 +Hoare Logic 用いての証明を行えるように、CodeGear、DataGear をベースにした Hoare +Logic を Agda 上で定義し、実際に証明を行うことなどが挙げられる。 + +\nocite{*} +\bibliographystyle{junsrt} +\bibliography{reference} +\end{document} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/jlisting.sty --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/jlisting.sty Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,216 @@ +\NeedsTeXFormat{LaTeX2e} +\def\filedate{2006/02/20} +\def\fileversion{0.2} +\ProvidesPackage{jlisting}[\filedate\space\fileversion\space(Thor)] +% +\newcount\lst@nextchar +\let\lst@@ProcessSpace\lst@ProcessSpace +\def\lst@ProcessSpace#1{% + \lst@check@chartype{#1}% + \lst@@ProcessSpace + \lst@whitespacetrue} +\let\lst@@ProcessLetter\lst@ProcessLetter +\def\lst@ProcessLetter#1#2{% + \lst@check@chartype{#2}% + {\lst@@ProcessLetter{#1}}% + \relax} +\let\lst@@ProcessDigit\lst@ProcessDigit +\def\lst@ProcessDigit#1#2{% + \lst@check@chartype{#2}% + {\lst@@ProcessDigit{#1}}% + \relax} +\let\lst@@ProcessOther\lst@ProcessOther +\def\lst@ProcessOther#1#2{% + \lst@check@chartype{#2}% + {\lst@@ProcessOther{#1}}% + \relax} +\let\lst@@ProcessTabulator\lst@ProcessTabulator +\def\lst@ProcessTabulator#1{% + \lst@check@chartype{#1}% + \lst@@ProcessTabulator + \relax} +\def\lst@check@chartype#1#2#3{% + \edef\@tempa{\lst@nextchar=`\string#1\relax}% + \afterassignment\remove@to@nnil + \@tempa\@nnil + #2% + \ifnum\lst@nextchar<\@cclvi + #3% + \else + \lst@ifletter \else \lst@OutputOther \fi + \lst@whitespacefalse + \expandafter\lst@AppendJchar + \fi + #1} +\def\lst@AppendJchar#1#2{% + \lst@check@chartype{#2}% + {\advance\lst@length\@ne\lst@Append{#1}}% + \relax} +\def\lst@check@chartype@BOL#1{% + \edef\@tempa{\lst@nextchar=`\string#1\relax}% + \afterassignment\remove@to@nnil + \@tempa\@nnil + \ifnum\lst@nextchar<\@cclvi\else + \lst@whitespacefalse + \expandafter\lst@AppendJchar + \fi + #1} +\def\lst@InputListing#1{% + \begingroup + \lsthk@PreSet \gdef\lst@intname{#1}% + \expandafter\lstset\expandafter{\lst@set}% + \lsthk@DisplayStyle + \catcode\active=\active + \lst@Init\relax \let\lst@gobble\z@ + \lst@SkipToFirst + \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}% + \else \let\lst@next\@empty + \fi + \lst@next + \lst@DeInit + \endgroup} +\newread\lst@inputfile +\def\lst@get@filecontents#1{% + \let\lst@filecontents\@empty + \openin\lst@inputfile=#1\relax + \let\@lst@get@filecontents@prevline\relax + \lst@get@filecontents@loop + \closein\lst@inputfile + \lst@filecontents\empty} +\def\lst@get@filecontents@loop{% + \read\lst@inputfile to\@lst@get@filecontents@currline + \ifx\@lst@get@filecontents@prevline\relax\else + \expandafter\expandafter\expandafter\def + \expandafter\expandafter\expandafter\lst@filecontents + \expandafter\expandafter\expandafter{% + \expandafter\lst@filecontents\@lst@get@filecontents@prevline}% + \fi + \let\@lst@get@filecontents@prevline\@lst@get@filecontents@currline + \ifeof\lst@inputfile\else + \expandafter\lst@get@filecontents@loop + \fi} +%%% [$B$3$N=hM}$b!$AjEv6/0z$G$9!%(B] +\def\lst@BOLGobble{% + \ifnum\lst@gobble>\z@ + \@tempcnta\lst@gobble\relax + \expandafter\lst@BOLGobble@ + \else + \expandafter\lst@check@chartype@BOL + \fi} +\def\lst@BOLGobble@#1{% + \let\lst@next#1% + \ifx \lst@next\relax\else + \ifx \lst@next\lst@MProcessListing\else + \ifx \lst@next\lst@ProcessFormFeed\else + \ifx \lst@next\lstenv@backslash + \let\lst@next\lstenv@BOLGobble@@ + \else + \let\lst@next\lst@BOLGobble@@ + \ifx #1\lst@ProcessTabulator + \advance\@tempcnta-\lst@tabsize\relax + \ifnum\@tempcnta<\z@ + \lst@length-\@tempcnta \lst@PreGotoTabStop + \fi + \else + \edef\@tempa{\lst@nextchar=`\string#1\relax}% + \@tempa + \ifnum\lst@nextchar<\@cclvi\else + \advance\@tempcnta\m@ne + \fi + \advance\@tempcnta\m@ne + \fi + \fi \fi \fi \fi + \lst@next} +\def\lst@BOLGobble@@{% + \ifnum\@tempcnta>\z@ + \expandafter\lst@BOLGobble@ + \else + \expandafter\lst@check@chartype@BOL + \fi +} +% +% \begin{$B=$@5;v9`(B}{1.3} +% $B$A$g$C$H$7$?=$@5(B +\gdef\lst@breakProcessOther#1{\lst@ProcessOther#1} +% $B%=!<%9%3!<%IL\:\$7$^$7$?!#(B + +\begin{quote} + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21172.html}\\ + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21184.html}\\ + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21189.html}\\ + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21197.html} +\end{quote} + + Copyright $B$O5H1JE/H~;a$K$"$k$N$@$H;W$$$^$9!%(B + +\section{$B99?7MzNr(B}% ChageLogs + +\begin{description} + \item[ver.~0.1 (2004/03/24)] + $B$H$j$"$($:8x3+!%(B + \item[ver.~0.2 (2006/02/20)] + \verb|\lst@breakProcessOther| $BL?Na$NDj5A$NDI2C!%(B +\end{description} + +\section{$B%=!<%9%3!<%I(B} +\par\narrowbaselines +\verbatiminput{jlisting.sty} +\end{document} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/modus-ponens/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/modus-ponens/Makefile Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,37 @@ +# Settings +TARGET=modus-ponens +BIBTEX=echo # pbibtex +BB=extractbb + +vpath pdf fig +FIGURES=$(wildcard fig/*.pdf) +FIGURES_FOR_TEX=$(subst .pdf,.xbb,$(FIGURES)) + +# dependencies +$(TARGET).pdf : $(TARGET).dvi + dvipdfmx $< + +$(TARGET).dvi : $(wildcard *.tex) $(FIGURES_FOR_TEX) $(SOURCES_FOR_TEX) + platex $(TARGET).tex + $(BIBTEX) $(TARGET) + platex $(TARGET).tex + platex $(TARGET).tex + +%.xbb: %.pdf + $(BB) $< + + +# commands +.PHONY : clean all open remake + +clean: + rm -f *.dvi *.aux *.log *.pdf *.ps *.gz *.bbl *.blg *.toc *~ *.core *.cpt *.lof *.lot *.lol *.bbl *.blg + +all: $(TARGET).pdf + +open: $(TARGET).pdf + open $(TARGET).pdf + +remake: + make clean + make all diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/modus-ponens/bussproofs.sty --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/modus-ponens/bussproofs.sty Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,1136 @@ +% +\def\BPmessage{Proof Tree (bussproofs) style macros. Version 1.1.} +% bussproofs.sty. Version 1.1 +% (c) 1994,1995,1996,2004,2005,2006, 2011. +% Copyright retained by Samuel R. Buss. +% +% ==== Legal statement: ==== +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt. +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/1 or later. +% +% This work has the LPPL maintenance status 'maintained'. +% +% The Current Maintainer of the work is Sam Buss. +% +% This work consists of bussproofs.sty. +% ===== +% Informal summary of legal situation: +% This software may be used and distributed freely, except that +% if you make changes, you must change the file name to be different +% than bussproofs.sty to avoid compatibility problems. +% The terms of the LaTeX Public License are the legally controlling terms +% and override any contradictory terms of the "informal situation". +% +% Please report comments and bugs to sbuss@ucsd.edu. +% +% Thanks to Felix Joachimski for making changes to let these macros +% work in plain TeX in addition to LaTeX. Nothing has been done +% to see if they work in AMSTeX. The comments below mostly +% are written for LaTeX, however. +% July 2004, version 0.7 +% - bug fix, right labels with descenders inserted too much space. +% Thanks to Peter Smith for finding this bug, +% see http://www.phil.cam.ac.uk/teaching_staff/Smith/LaTeX/ +% March 2005, version 0.8. +% Added a default definition for \fCenter at Denis Kosygin's +% suggestion. +% September 2005, version 0.9. +% Fixed some subtle spacing problems, by adding %'s to the end of +% few lines where they were inadvertantly omitted. Thanks to +% Arnold Beckmann for finding and fixing this problem. +% April 2006, version 0.9.1. Updated comments and testbp2.tex file. +% No change to the actual macros. +% June 2006, version 1.0. The first integer numbered release. +% New feature: root of proof may now be at the bottom instead of +% at just the top. Thanks to Alex Hertel for the suggestion to implement +% this. +% June 2011, version 1.1. +% New feature: 4-ary and 5-ary inferences. Thanks to Thomas Strathmann +% for taking the initiative to implement these. +% Four new commands: QuaternaryInf(C) and QuinaryInf(C). +% Bug fix: \insertBetweenHyps now works for proofs with root at top and +% three or more hypotheses.. + +% A good exposition of how to use bussproofs.sty (version 0.9) has been written +% by Peter Smith and is available on the internet. +% The comments below also describe the features of bussproofs.sty, +% including user-modifiable parameters. + +% bussproofs.sty allows the construction of proof trees in the +% style of the sequent calculus and many other proof systems +% One novel feature of these macros is they support the horizontal +% alignment according to some center point specified with the +% command \fCenter. This is the style often used in sequent +% calculus proofs. +% Proofs are specified in left-to-right traversal order. +% For example a proof +% A B +% ----- +% D C +% --------- +% E +% +% if given in the order D,A,B,C,E. Each line in the proof is +% specified according to the arity of the inference which generates +% it. Thus, E would be specified with a \BinaryInf or \BinaryInfC +% command. +% +% The above proof tree could be displayed with the commands: +% +% \AxiomC{D} +% \AxiomC{A} +% \AxiomC{B} +% \BinaryInfC{C} +% \BinaryInfC{E} +% \DisplayProof +% +% Inferences in a proof may be nullary (axioms), unary, binary, or +% trinary. +% +% IMPORTANT: You must give the \DisplayProof command to make the proof +% be printed. To display a centered proof on a line by itself, +% put the proof inside \begin{center} ... \end{center}. +% +% There are two styles for specifying horizontal centering of +% lines (formulas or sequents) in a proof. One format \AxiomC{...} +% just centers the formula {...} in the usual way. The other +% format is \Axiom$...\fCenter...$. Here, the \fCenter specifies +% the center of the formula. (It is permissable for \fCenter to +% generate typeset material; in fact, I usually define it to generate +% the sequent arrow.) In unary inferences, the \fCenter +% positions will be vertically aligned in the upper and lower lines of +% the inference. Unary, Binary, Trinary inferences are specified +% with the same format as Axioms. The two styles of centering +% lines may be combined in a single proof. +% +% By using the optional \EnableBpAbbreviations command, various +% abbreviated two or three letter commands are enabled. This allows, +% in particular: +% \AX and \AXC for \Axiom and \AxiomC, (resp.), +% \DP for \DisplayProof, +% \BI and \BIC for \BinaryInf and \BinaryInfC, +% \UI and \UIC for \UnaryInf and \UnaryInfC, +% \TI and \TIC for \TrinaryInf and \TrinaryInfC, +% \LL and \RL for \LeftLabel and \RightLabel. +% See the source code below for additional abbreviations. +% The enabling of these short abbreviations is OPTIONAL, since +% there is the possibility of conflicting with names from other +% macro packages. +% +% By default, the inferences have single horizontal lines (scores) +% This can be overridden using the \doubleLine, \noLine commands. +% These two commands affect only the next inference. You can make +% make a permanent override that applies to the rest of the current +% proof using \alwaysDoubleLine and \alwaysNoLine. \singleLine +% and \alwaysSingleLine work in the analogous way. +% +% The macros do their best to give good placements of for the +% parts of the proof. Several macros allow you to override the +% defaults. These are \insertBetweenHyps{...} which overrides +% the default spacing between hypotheses of Binary and Trinary +% inferences with {...}. And \kernHyps{...} specifies a distance +% to shift the whole block of hypotheses to the right (modifying +% the default center position. +% Other macros set the vertical placement of the whole proof. +% The default is to try to do a good job of placement for inferences +% included in text. Two other useful macros are: \bottomAlignProof +% which aligns the hbox output by \DisplayProof according to the base +% of the bottom line of the proof, and \centerAlignProof which +% does a precise center vertical alignment. +% +% Often, one wishes to place a label next to an inference, usually +% to specify the type of inference. These labels can be placed +% by using the commands \LeftLabel{...} and \RightLabel{...} +% immediately before the command which specifies the inference. +% For example, to generate +% +% A B +% --------- X +% C +% +% use the commands +% \AxiomC{A} +% \AxiomC{B} +% \RightLabel{X} +% \BinaryInfC{C} +% \DisplayProof +% +% The \DisplayProof command just displays the proof as a text +% item. This allows you to put proofs anywhere normal text +% might appear; for example, in a paragraph, in a table, in +% a tabbing environment, etc. When displaying a proof as inline text, +% you should write \DisplayProof{} (with curly brackets) so that +% LaTeX will not "eat" the white space following the \DisplayProof +% command. +% For displaying proofs in a centered display: Do not use the \[...\] +% construction (nor $$...$$). Instead use +% \begin{center} ... \DisplayProof\end{center}. +% Actually there is a better construction to use instead of the +% \begin{center}...\DisplayProof\end{center}. This is to +% write +% \begin{prooftree} ... \end{prooftree}. +% Note there is no \DisplayProof used for this: the +% \end{prooftree} automatically supplies the \DisplayProof +% command. +% +% Warning: Any commands that set line types or set vertical or +% horizontal alignment that are given AFTER the \DisplayProof +% command will affect the next proof, no matter how distant. + + + + +% Usages: +% ======= +% +% \Axiom$\fCenter$ +% +% \AxiomC{\fCenter$ +% +% \UnaryInfC{} +% +% \BinaryInf$\fCenter$ +% +% \BinaryInfC{} +% +% \TrinaryInf$\fCenter$ +% +% \TrinaryInfC{} +% +% \QuaternaryInf$\fCenter$ +% +% \QuaternaryInfC{} +% +% \QuinaryInf$\fCenter$ +% +% \QuinaryInfC{} +% +% \LeftLabel{} - Puts as a label to the left +% of the next inference line. (Works even if +% \noLine is used too.) +% +% \RightLabel{} - Puts as a label to the right of the +% next inference line. (Also works with \noLine.) +% +% \DisplayProof - outputs the whole proof tree (and finishes it). +% The proof tree is output as an hbox. +% +% +% \kernHyps{} - Slides the upper hypotheses right distance +% (This is similar to shifting conclusion left) +% - kernHyps works with Unary, Binary and Trinary +% inferences and with centered or uncentered sequents. +% - Negative values for are permitted. +% +% \insertBetweenHyps{...} - {...} will be inserted between the upper +% hypotheses of a Binary or Trinary Inferences. +% It is possible to use negative horizontal space +% to push them closer together (and even overlap). +% This command affects only the next inference. +% +% \doubleLine - Makes the current (ie, next) horizontal line doubled +% +% \alwaysDoubleLine - Makes lines doubled for rest of proof +% +% \singleLine - Makes the current (ie, next) line single +% +% \alwaysSingleLine - Undoes \alwaysDoubleLine or \alwaysNoLine. +% +% \noLine - Make no line at all at current (ie next) inference. +% +% \alwaysNoLine - Makes no lines for rest of proof. (Untested) +% +% \solidLine - Does solid horizontal line for current inference +% +% \dottedLine - Does dotted horizontal line for current inference +% +% \dashedLine - Does dashed horizontal line for current inference +% +% \alwaysSolidLine - Makes the indicated change in line type, permanently +% \alwaysDashedLine until end of proof or until overridden. +% \alwaysDottedLine +% +% \bottomAlignProof - Vertically align proof according to its bottom line. +% \centerAlignProof - Vertically align proof proof precisely in its center. +% \normalAlignProof - Overrides earlier bottom/center AlignProof commands. +% The default alignment will look good in most cases, +% whether the proof is displayed or is +% in-line. Other alignments may be more +% appropriate when putting proofs in tables or +% pictures, etc. For custom alignments, use +% TeX's raise commands. +% +% \rootAtTop - specifies that proofs have their root a the top. That it, +% proofs will be "upside down". +% \rootAtBottom - (default) Specifies that proofs have root at the bottom +% The \rootAtTop and \rootAtBottom commands apply *only* to the +% current proof. If you want to make them persistent, use one of +% the next two commands: +% \alwaysRootAtTop +% \alwaysRootAtBottom (default) +% + +% Optional short abbreviations for commands: +\def\EnableBpAbbreviations{% + \let\AX\Axiom + \let\AXC\AxiomC + \let\UI\UnaryInf + \let\UIC\UnaryInfC + \let\BI\BinaryInf + \let\BIC\BinaryInfC + \let\TI\TrinaryInf + \let\TIC\TrinaryInfC + \let\QI\QuaternaryInf + \let\QIC\QuaternaryInfC + \let\QuI\QuinaryInf + \let\QuIC\QuinaryInfC + \let\LL\LeftLabel + \let\RL\RightLabel + \let\DP\DisplayProof +} + +% Parameters which control the style of the proof trees. +% The user may wish to override these parameters locally or globally. +% BUT DON'T CHANGE THE PARAMETERS BY CHANGING THIS FILE (to avoid +% future incompatibilities). Instead, you should change them in your +% TeX document right after including this style file in the +% header material of your LaTeX document. + +\def\ScoreOverhang{4pt} % How much underlines extend out +\def\ScoreOverhangLeft{\ScoreOverhang} +\def\ScoreOverhangRight{\ScoreOverhang} + +\def\extraVskip{2pt} % Extra space above and below lines +\def\ruleScoreFiller{\hrule} % Horizontal rule filler. +\def\dottedScoreFiller{\hbox to4pt{\hss.\hss}} +\def\dashedScoreFiller{\hbox to2.8mm{\hss\vrule width1.4mm height0.4pt depth0.0pt\hss}} +\def\defaultScoreFiller{\ruleScoreFiller} % Default horizontal filler. +\def\defaultBuildScore{\buildSingleScore} % In \singleLine mode at start. + +\def\defaultHypSeparation{\hskip.2in} % Used if \insertBetweenHyps isn't given + +\def\labelSpacing{3pt} % Horizontal space separating labels and lines + +\def\proofSkipAmount{\vskip.8ex plus.8ex minus.4ex} + % Space above and below a prooftree display. + +\def\defaultRootPosition{\buildRootBottom} % Default: Proofs root at bottom +%\def\defaultRootPosition{\buildRootTop} % Makes all proofs upside down + +\ifx\fCenter\undefined +\def\fCenter{\relax} +\fi + +% +% End of user-modifiable parameters. +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Here are some internal paramenters and defaults. Not really intended +% to be user-modifiable. + +\def\theHypSeparation{\defaultHypSeparation} +\def\alwaysScoreFiller{\defaultScoreFiller} % Horizontal filler. +\def\alwaysBuildScore{\defaultBuildScore} +\def\theScoreFiller{\alwaysScoreFiller} % Horizontal filler. +\def\buildScore{\alwaysBuildScore} %This command builds the score. +\def\hypKernAmt{0pt} % Initial setting for kerning the hypotheses. + +\def\defaultLeftLabel{} +\def\defaultRightLabel{} + +\def\myTrue{Y} +\def\bottomAlignFlag{N} +\def\centerAlignFlag{N} +\def\defaultRootAtBottomFlag{Y} +\def\rootAtBottomFlag{Y} + +% End of internal parameters and defaults. + +\expandafter\ifx\csname newenvironment\endcsname\relax% +% If in TeX: +\message{\BPmessage} +\def\makeatletter{\catcode`\@=11\relax} +\def\makeatother{\catcode`\@=12\relax} +\makeatletter +\def\newcount{\alloc@0\count\countdef\insc@unt} +\def\newdimen{\alloc@1\dimen\dimendef\insc@unt} +\def\newskip{\alloc@2\skip\skipdef\insc@unt} +\def\newbox{\alloc@4\box\chardef\insc@unt} +\makeatother +\else +% If in LaTeX +\typeout{\BPmessage} +\newenvironment{prooftree}% +{\begin{center}\proofSkipAmount \leavevmode}% +{\DisplayProof \proofSkipAmount \end{center} } +\fi + +\def\thecur#1{\csname#1\number\theLevel\endcsname} + +\newcount\theLevel % This counter is the height of the stack. +\global\theLevel=0 % Initialized to zero +\newcount\myMaxLevel +\global\myMaxLevel=0 +\newbox\myBoxA % Temporary storage boxes +\newbox\myBoxB +\newbox\myBoxC +\newbox\myBoxD +\newbox\myBoxLL % Boxes for the left label and the right label. +\newbox\myBoxRL +\newdimen\thisAboveSkip %Internal use: amount to skip above line +\newdimen\thisBelowSkip %Internal use: amount to skip below line +\newdimen\newScoreStart % More temporary storage. +\newdimen\newScoreEnd +\newdimen\newCenter +\newdimen\displace +\newdimen\leftLowerAmt% Amount to lower left label +\newdimen\rightLowerAmt% Amount to lower right label +\newdimen\scoreHeight% Score height +\newdimen\scoreDepth% Score Depth +\newdimen\htLbox% +\newdimen\htRbox% +\newdimen\htRRbox% +\newdimen\htRRRbox% +\newdimen\htAbox% +\newdimen\htCbox% + +\setbox\myBoxLL=\hbox{\defaultLeftLabel}% +\setbox\myBoxRL=\hbox{\defaultRightLabel}% + +\def\allocatemore{% + \ifnum\theLevel>\myMaxLevel% + \expandafter\newbox\curBox% + \expandafter\newdimen\curScoreStart% + \expandafter\newdimen\curCenter% + \expandafter\newdimen\curScoreEnd% + \global\advance\myMaxLevel by1% + \fi% +} + +\def\prepAxiom{% + \advance\theLevel by1% + \edef\curBox{\thecur{myBox}}% + \edef\curScoreStart{\thecur{myScoreStart}}% + \edef\curCenter{\thecur{myCenter}}% + \edef\curScoreEnd{\thecur{myScoreEnd}}% + \allocatemore% +} + +\def\Axiom$#1\fCenter#2${% + % Get level and correct names set. + \prepAxiom% + % Define the boxes + \setbox\myBoxA=\hbox{$\mathord{#1}\fCenter\mathord{\relax}$}% + \setbox\myBoxB=\hbox{$#2$}% + \global\setbox\curBox=% + \hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\unhcopy\myBoxB\hskip\ScoreOverhangRight\relax}% + % Set the relevant dimensions for the boxes + \global\curScoreStart=0pt \relax + \global\curScoreEnd=\wd\curBox \relax + \global\curCenter=\wd\myBoxA \relax + \global\advance \curCenter by \ScoreOverhangLeft% + \ignorespaces +} + +\def\AxiomC#1{ % Note argument not in math mode + % Get level and correct names set. + \prepAxiom% + % Define the box. + \setbox\myBoxA=\hbox{#1}% + \global\setbox\curBox =% + \hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\hskip\ScoreOverhangRight\relax}% + % Set the relevant dimensions for the boxes + \global\curScoreStart=0pt \relax + \global\curScoreEnd=\wd\curBox \relax + \global\curCenter=.5\wd\curBox \relax + \global\advance \curCenter by \ScoreOverhangLeft% + \ignorespaces +} + +\def\prepUnary{% + \ifnum \theLevel<1 + \errmessage{Hypotheses missing!} + \fi% + \edef\curBox{\thecur{myBox}}% + \edef\curScoreStart{\thecur{myScoreStart}}% + \edef\curCenter{\thecur{myCenter}}% + \edef\curScoreEnd{\thecur{myScoreEnd}}% +} + +\def\UnaryInf$#1\fCenter#2${% + \prepUnary% + \buildConclusion{#1}{#2}% + \joinUnary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\UnaryInfC#1{ + \prepUnary% + \buildConclusionC{#1}% + %Align and join the curBox and the new box into one vbox. + \joinUnary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\prepBinary{% + \ifnum\theLevel<2 + \errmessage{Hypotheses missing!} + \fi% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\BinaryInf$#1\fCenter#2${% + \prepBinary% + \buildConclusion{#1}{#2}% + \joinBinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\BinaryInfC#1{% + \prepBinary% + \buildConclusionC{#1}% + \joinBinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\prepTrinary{% + \ifnum\theLevel<3 + \errmessage{Hypotheses missing!} + \fi% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\ccurBox{\thecur{myBox}}% Set up names of center hypothesis + \edef\ccurScoreStart{\thecur{myScoreStart}}% + \edef\ccurCenter{\thecur{myCenter}}% + \edef\ccurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\TrinaryInf$#1\fCenter#2${% + \prepTrinary% + \buildConclusion{#1}{#2}% + \joinTrinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\TrinaryInfC#1{% + \prepTrinary% + \buildConclusionC{#1}% + \joinTrinary% + \resetInferenceDefaults% + \ignorespaces% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\def\prepQuaternary{% + \ifnum\theLevel<4 + \errmessage{Hypotheses missing!} + \fi% + \edef\rrcurBox{\thecur{myBox}}% Set up names of very right hypothesis + \edef\rrcurScoreStart{\thecur{myScoreStart}}% + \edef\rrcurCenter{\thecur{myCenter}}% + \edef\rrcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\ccurBox{\thecur{myBox}}% Set up names of center hypothesis + \edef\ccurScoreStart{\thecur{myScoreStart}}% + \edef\ccurCenter{\thecur{myCenter}}% + \edef\ccurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\QuaternaryInf$#1\fCenter#2${% + \prepQuaternary% + \buildConclusion{#1}{#2}% + \joinQuaternary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\QuaternaryInfC#1{% + \prepQuaternary% + \buildConclusionC{#1}% + \joinQuaternary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\joinQuaternary{% Construct the quarterary inference into a vbox. + % Join the four hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rrcurScoreEnd% + \advance\lcurScoreEnd by\wd\rcurBox% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\ccurBox% + \advance\lcurScoreEnd by3\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\ccurBox% + \unhcopy\myBoxA\box\rcurBox + \unhcopy\myBoxA\box\rrcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htCbox = \ht\ccurBox% + \htRbox = \ht\rcurBox% + \htRRbox = \ht\rrcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\copy\myBoxA\lower\htCbox\box\ccurBox% + \lower\htAbox\copy\myBoxA\lower\htRbox\box\rcurBox% + \lower\htAbox\copy\myBoxA\lower\htRRbox\box\rrcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\def\prepQuinary{% + \ifnum\theLevel<5 + \errmessage{Hypotheses missing!} + \fi% + \edef\rrrcurBox{\thecur{myBox}}% Set up names of very very right hypothesis + \edef\rrrcurScoreStart{\thecur{myScoreStart}}% + \edef\rrrcurCenter{\thecur{myCenter}}% + \edef\rrrcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\rrcurBox{\thecur{myBox}}% Set up names of very right hypothesis + \edef\rrcurScoreStart{\thecur{myScoreStart}}% + \edef\rrcurCenter{\thecur{myCenter}}% + \edef\rrcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\rcurBox{\thecur{myBox}}% Set up names of right hypothesis + \edef\rcurScoreStart{\thecur{myScoreStart}}% + \edef\rcurCenter{\thecur{myCenter}}% + \edef\rcurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\ccurBox{\thecur{myBox}}% Set up names of center hypothesis + \edef\ccurScoreStart{\thecur{myScoreStart}}% + \edef\ccurCenter{\thecur{myCenter}}% + \edef\ccurScoreEnd{\thecur{myScoreEnd}}% + \advance\theLevel by-1% + \edef\lcurBox{\thecur{myBox}}% Set up names of left hypothesis + \edef\lcurScoreStart{\thecur{myScoreStart}}% + \edef\lcurCenter{\thecur{myCenter}}% + \edef\lcurScoreEnd{\thecur{myScoreEnd}}% +} + +\def\QuinaryInf$#1\fCenter#2${% + \prepQuinary% + \buildConclusion{#1}{#2}% + \joinQuinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\QuinaryInfC#1{% + \prepQuinary% + \buildConclusionC{#1}% + \joinQuinary% + \resetInferenceDefaults% + \ignorespaces% +} + +\def\joinQuinary{% Construct the quinary inference into a vbox. + % Join the five hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rrrcurScoreEnd% + \advance\lcurScoreEnd by\wd\rrcurBox% + \advance\lcurScoreEnd by\wd\rcurBox% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\ccurBox% + \advance\lcurScoreEnd by4\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\ccurBox% + \unhcopy\myBoxA\box\rcurBox + \unhcopy\myBoxA\box\rrcurBox + \unhcopy\myBoxA\box\rrrcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htCbox = \ht\ccurBox% + \htRbox = \ht\rcurBox% + \htRRbox = \ht\rrcurBox% + \htRRRbox = \ht\rrrcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\copy\myBoxA\lower\htCbox\box\ccurBox% + \lower\htAbox\copy\myBoxA\lower\htRbox\box\rcurBox% + \lower\htAbox\copy\myBoxA\lower\htRRbox\box\rrcurBox% + \lower\htAbox\copy\myBoxA\lower\htRRRbox\box\rrrcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\def\buildConclusion#1#2{% Build lower sequent w/ center at \fCenter position. + % Define the boxes + \setbox\myBoxA=\hbox{$\mathord{#1}\fCenter\mathord{\relax}$}% + \setbox\myBoxB=\hbox{$#2$}% + % Put them together in \myBoxC + \setbox\myBoxC =% + \hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\unhcopy\myBoxB\hskip\ScoreOverhangRight\relax}% + % Calculate the center of the \myBoxC string. + \newScoreStart=0pt \relax% + \newCenter=\wd\myBoxA \relax% + \advance \newCenter by \ScoreOverhangLeft% + \newScoreEnd=\wd\myBoxC% +} + +\def\buildConclusionC#1{% Build lower sequent w/o \fCenter present. + % Define the box. + \setbox\myBoxA=\hbox{#1}% + \setbox\myBoxC =% + \hbox{\hbox{\hskip\ScoreOverhangLeft\relax% + \unhcopy\myBoxA\hskip\ScoreOverhangRight\relax}}% + % Calculate kerning to line up centers + \newScoreStart=0pt \relax% + \newCenter=.5\wd\myBoxC \relax% + \newScoreEnd=\wd\myBoxC% + \advance \newCenter by \ScoreOverhangLeft% +} + +\def\joinUnary{%Align and join \curBox and \myBoxC into a single vbox + \global\advance\curCenter by -\hypKernAmt% + \ifnum\curCenter<\newCenter% + \displace=\newCenter% + \advance \displace by -\curCenter% + \kernUpperBox% + \else% + \displace=\curCenter% + \advance \displace by -\newCenter% + \kernLowerBox% + \fi% + \ifnum \newScoreStart < \curScoreStart % + \global \curScoreStart = \newScoreStart \fi% + \ifnum \curScoreEnd < \newScoreEnd % + \global \curScoreEnd = \newScoreEnd \fi% + % Leave room for the left label. + \ifnum \curScoreStart<\wd\myBoxLL% + \global\displace = \wd\myBoxLL% + \global\advance\displace by -\curScoreStart% + \kernUpperBox% + \kernLowerBox% + \fi% + % Draw the score + \buildScore% + % Form the score and labels into a box. + \buildScoreLabels% + % Form the new box and its dimensions + \ifx\rootAtBottomFlag\myTrue% + \buildRootBottom% + \else% + \buildRootTop% + \fi% + \global \curScoreStart=\newScoreStart% + \global \curScoreEnd=\newScoreEnd% + \global \curCenter=\newCenter% +} + +\def\buildRootBottom{% + \global \setbox \curBox =% + \vbox{\box\curBox% + \vskip\thisAboveSkip \relax% + \nointerlineskip\box\myBoxD% + \vskip\thisBelowSkip \relax% + \nointerlineskip\box\myBoxC}% +} + +\def\buildRootTop{% + \global \setbox \curBox =% + \vbox{\box\myBoxC% + \vskip\thisAboveSkip \relax% + \nointerlineskip\box\myBoxD% + \vskip\thisBelowSkip \relax% + \nointerlineskip\box\curBox}% +} + +\def\kernUpperBox{% + \global\setbox\curBox =% + \hbox{\hskip\displace\box\curBox}% + \global\advance \curScoreStart by \displace% + \global\advance \curScoreEnd by \displace% + \global\advance\curCenter by \displace% +} + +\def\kernLowerBox{% + \global\setbox\myBoxC =% + \hbox{\hskip\displace\unhbox\myBoxC}% + \global\advance \newScoreStart by \displace% + \global\advance \newScoreEnd by \displace% + \global\advance\newCenter by \displace% +} + +\def\joinBinary{% Construct the binary inference into a vbox. + % Join the two hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rcurScoreEnd% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\rcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htRbox = \ht\rcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\box\myBoxA\lower\htRbox\box\rcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +\def\joinTrinary{% Construct the trinary inference into a vbox. + % Join the three hypotheses's boxes into one hbox. + \setbox\myBoxA=\hbox{\theHypSeparation}% + \lcurScoreEnd=\rcurScoreEnd% + \advance\lcurScoreEnd by\wd\lcurBox% + \advance\lcurScoreEnd by\wd\ccurBox% + \advance\lcurScoreEnd by2\wd\myBoxA% + \displace=\lcurScoreEnd% + \advance\displace by -\lcurScoreStart% + \lcurCenter=.5\displace% + \advance\lcurCenter by\lcurScoreStart% + \ifx\rootAtBottomFlag\myTrue% + \setbox\lcurBox=% + \hbox{\box\lcurBox\unhcopy\myBoxA\box\ccurBox% + \unhcopy\myBoxA\box\rcurBox}% + \else% + \htLbox = \ht\lcurBox% + \htAbox = \ht\myBoxA% + \htCbox = \ht\ccurBox% + \htRbox = \ht\rcurBox% + \setbox\lcurBox=% + \hbox{\lower\htLbox\box\lcurBox% + \lower\htAbox\copy\myBoxA\lower\htCbox\box\ccurBox% + \lower\htAbox\copy\myBoxA\lower\htRbox\box\rcurBox}% + \fi% + % Adjust center of upper hypotheses according to how much + % the lower sequent is off-center. + \displace=\newCenter% + \advance\displace by -.5\newScoreStart% + \advance\displace by -.5\newScoreEnd% + \advance\lcurCenter by \displace% + %Align and join the curBox and the two hypotheses's box into one vbox. + \edef\curBox{\lcurBox}% + \edef\curScoreStart{\lcurScoreStart}% + \edef\curScoreEnd{\lcurScoreEnd}% + \edef\curCenter{\lcurCenter}% + \joinUnary% +} + +\def\DisplayProof{% + % Display (and purge) the proof tree. + % Choose the appropriate vertical alignment. + \ifnum \theLevel=1 \relax \else%x + \errmessage{Proof tree badly specified.}% + \fi% + \edef\curBox{\thecur{myBox}}% + \ifx\bottomAlignFlag\myTrue% + \displace=0pt% + \else% + \displace=.5\ht\curBox% + \ifx\centerAlignFlag\myTrue\relax + \else% + \advance\displace by -3pt% + \fi% + \fi% + \leavevmode% + \lower\displace\hbox{\copy\curBox}% + \global\theLevel=0% + \global\def\alwaysBuildScore{\defaultBuildScore}% Restore "always" + \global\def\alwaysScoreFiller{\defaultScoreFiller}% Restore "always" + \global\def\bottomAlignFlag{N}% + \global\def\centerAlignFlag{N}% + \resetRootPosition + \resetInferenceDefaults% + \ignorespaces +} + +\def\buildSingleScore{% Make an hbox with a single score. + \displace=\curScoreEnd% + \advance \displace by -\curScoreStart% + \global\setbox \myBoxD =% + \hbox to \displace{\expandafter\xleaders\theScoreFiller\hfill}% + %\global\setbox \myBoxD =% + %\hbox{\hskip\curScoreStart\relax \box\myBoxD}% +} + +\def\buildDoubleScore{% Make an hbox with a double score. + \buildSingleScore% + \global\setbox\myBoxD=% + \hbox{\hbox to0pt{\copy\myBoxD\hss}\raise2pt\copy\myBoxD}% +} + +\def\buildNoScore{% Make an hbox with no score (raise a little anyway) + \global\setbox\myBoxD=\hbox{\vbox{\vskip1pt}}% +} + +\def\doubleLine{% + \gdef\buildScore{\buildDoubleScore}% Set next score to this type + \ignorespaces +} +\def\alwaysDoubleLine{% + \gdef\alwaysBuildScore{\buildDoubleScore}% Do double for rest of proof. + \gdef\buildScore{\buildDoubleScore}% Set next score to be double + \ignorespaces +} +\def\singleLine{% + \gdef\buildScore{\buildSingleScore}% Set next score to be single + \ignorespaces +} +\def\alwaysSingleLine{% + \gdef\alwaysBuildScore{\buildSingleScore}% Do single for rest of proof. + \gdef\buildScore{\buildSingleScore}% Set next score to be single + \ignorespaces +} +\def\noLine{% + \gdef\buildScore{\buildNoScore}% Set next score to this type + \ignorespaces +} +\def\alwaysNoLine{% + \gdef\alwaysBuildScore{\buildNoScore}%Do nolines for rest of proof. + \gdef\buildScore{\buildNoScore}% Set next score to be blank + \ignorespaces +} +\def\solidLine{% + \gdef\theScoreFiller{\ruleScoreFiller}% Use solid horizontal line. + \ignorespaces +} +\def\alwaysSolidLine{% + \gdef\alwaysScoreFiller{\ruleScoreFiller}% Do solid for rest of proof + \gdef\theScoreFiller{\ruleScoreFiller}% Use solid horizontal line. + \ignorespaces +} +\def\dottedLine{% + \gdef\theScoreFiller{\dottedScoreFiller}% Use dotted horizontal line. + \ignorespaces +} +\def\alwaysDottedLine{% + \gdef\alwaysScoreFiller{\dottedScoreFiller}% Do dotted for rest of proof + \gdef\theScoreFiller{\dottedScoreFiller}% Use dotted horizontal line. + \ignorespaces +} +\def\dashedLine{% + \gdef\theScoreFiller{\dashedScoreFiller}% Use dashed horizontal line. + \ignorespaces +} +\def\alwaysDashedLine{% + \gdef\alwaysScoreFiller{\dashedScoreFiller}% Do dashed for rest of proof + \gdef\theScoreFiller{\dashedScoreFiller}% Use dashed horizontal line. + \ignorespaces +} +\def\kernHyps#1{% + \gdef\hypKernAmt{#1}% + \ignorespaces +} +\def\insertBetweenHyps#1{% + \gdef\theHypSeparation{#1}% + \ignorespaces +} + +\def\centerAlignProof{% + \def\centerAlignFlag{Y}% + \def\bottomAlignFlag{N}% + \ignorespaces +} +\def\bottomAlignProof{% + \def\centerAlignFlag{N}% + \def\bottomAlignFlag{Y}% + \ignorespaces +} +\def\normalAlignProof{% + \def\centerAlignFlag{N}% + \def\bottomAlignFlag{N}% + \ignorespaces +} + +\def\LeftLabel#1{% + \global\setbox\myBoxLL=\hbox{{#1}\hskip\labelSpacing}% + \ignorespaces +} +\def\RightLabel#1{% + \global\setbox\myBoxRL=\hbox{\hskip\labelSpacing #1}% + \ignorespaces +} + +\def\buildScoreLabels{% + \scoreHeight = \ht\myBoxD% + \scoreDepth = \dp\myBoxD% + \leftLowerAmt=\ht\myBoxLL% + \advance \leftLowerAmt by -\dp\myBoxLL% + \advance \leftLowerAmt by -\scoreHeight% + \advance \leftLowerAmt by \scoreDepth% + \leftLowerAmt=.5\leftLowerAmt% + \rightLowerAmt=\ht\myBoxRL% + \advance \rightLowerAmt by -\dp\myBoxRL% + \advance \rightLowerAmt by -\scoreHeight% + \advance \rightLowerAmt by \scoreDepth% + \rightLowerAmt=.5\rightLowerAmt% + \displace = \curScoreStart% + \advance\displace by -\wd\myBoxLL% + \global\setbox\myBoxD =% + \hbox{\hskip\displace% + \lower\leftLowerAmt\copy\myBoxLL% + \box\myBoxD% + \lower\rightLowerAmt\copy\myBoxRL}% + \global\thisAboveSkip = \ht\myBoxLL% + \global\advance \thisAboveSkip by -\leftLowerAmt% + \global\advance \thisAboveSkip by -\scoreHeight% + \ifnum \thisAboveSkip<0 % + \global\thisAboveSkip=0pt% + \fi% + \displace = \ht\myBoxRL% + \advance \displace by -\rightLowerAmt% + \advance \displace by -\scoreHeight% + \ifnum \displace<0 % + \displace=0pt% + \fi% + \ifnum \displace>\thisAboveSkip % + \global\thisAboveSkip=\displace% + \fi% + \global\thisBelowSkip = \dp\myBoxLL% + \global\advance\thisBelowSkip by \leftLowerAmt% + \global\advance\thisBelowSkip by -\scoreDepth% + \ifnum\thisBelowSkip<0 % + \global\thisBelowSkip = 0pt% + \fi% + \displace = \dp\myBoxRL% + \advance\displace by \rightLowerAmt% + \advance\displace by -\scoreDepth% + \ifnum\displace<0 % + \displace = 0pt% + \fi% + \ifnum\displace>\thisBelowSkip% + \global\thisBelowSkip = \displace% + \fi% + \global\thisAboveSkip = -\thisAboveSkip% + \global\thisBelowSkip = -\thisBelowSkip% + \global\advance\thisAboveSkip by\extraVskip% Extra space above line + \global\advance\thisBelowSkip by\extraVskip% Extra space below line +} + +\def\resetInferenceDefaults{% + \global\def\theHypSeparation{\defaultHypSeparation}% + \global\setbox\myBoxLL=\hbox{\defaultLeftLabel}% + \global\setbox\myBoxRL=\hbox{\defaultRightLabel}% + \global\def\buildScore{\alwaysBuildScore}% + \global\def\theScoreFiller{\alwaysScoreFiller}% + \gdef\hypKernAmt{0pt}% Restore to zero kerning. +} + + +\def\rootAtBottom{% + \global\def\rootAtBottomFlag{Y}% +} + +\def\rootAtTop{% + \global\def\rootAtBottomFlag{N}% +} + +\def\resetRootPosition{% + \global\edef\rootAtBottomFlag{\defaultRootAtBottomFlag} +} + +\def\alwaysRootAtBottom{% + \global\def\defaultRootAtBottomFlag{Y} + \rootAtBottom +} + +\def\alwaysRootAtTop{% + \global\def\defaultRootAtBottomFlag{N} + \rootAtTop +} + + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/modus-ponens/modus-ponens.pdf Binary file final_pre/modus-ponens/modus-ponens.pdf has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/modus-ponens/modus-ponens.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/modus-ponens/modus-ponens.svg Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,322 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/modus-ponens/modus-ponens.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/modus-ponens/modus-ponens.tex Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,56 @@ +% {{{ settings +% vim:set fileencoding=utf8: +\documentclass[10pt]{jarticle} + +\usepackage{amsmath} +\usepackage{cprotect} +\usepackage{listings} +\usepackage{moreverb} +\usepackage{url} +\usepackage{bussproofs} +\usepackage[dvipdfmx]{graphicx} + +% equation number with section number +\makeatletter +\renewcommand{\theequation}{\arabic{section}-\arabic{equation}} +\@addtoreset{equation}{section} +\makeatother + +\setlength{\textwidth}{179mm} +\setlength{\textheight}{251mm} +\setlength{\topmargin}{-2cm} +\setlength{\oddsidemargin}{-1cm} +\setlength{\evensidemargin}{-1cm} + +% }}} + +\pagenumbering{gobble} + +\begin{document} + +\title{} +\author{} +\date{} + +\begin{prooftree} + \AxiomC{ $ [A] $ $_{(1)}$} + \AxiomC{ [$ (A \Rightarrow B) \land (B \Rightarrow C)$] $_{(2)}$ } + \RightLabel{ $ \land 1 \mathcal{E} $ } + \UnaryInfC{ $ (A \Rightarrow B) $ } + \RightLabel{ $ \Rightarrow \mathcal{E} $} + \BinaryInfC{ $ B $ } + + \AxiomC{ [$ (A \Rightarrow B) \land (B \Rightarrow C)$] $_{(2)}$ } + \RightLabel{ $ \land 2 \mathcal{E} $ } + \UnaryInfC{ $ (B \Rightarrow C) $ } + + \RightLabel{ $ \Rightarrow \mathcal{E} $} + \BinaryInfC{ $ C $ } + \RightLabel{ $ \Rightarrow \mathcal{I} _{(1)}$} + \UnaryInfC{ $ A \Rightarrow C $} + \RightLabel{ $ \Rightarrow \mathcal{I} _{(2)}$} + \UnaryInfC{ $ ((A \Rightarrow B) \land (B \Rightarrow C)) \Rightarrow (A \Rightarrow C) $} +\end{prooftree} + +\end{document} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/picins.sty --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/picins.sty Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,578 @@ +% PICINS.STY --- Style File zum Einbinden von Bildern +% Autor: J. Bleser, E. Lang +% Hochschulrechenzentrum +% Technische Hochschule Darmstadt +% !!! Dieses Style-File ist urheberrechtlich geschuetzt !!! +% !!! Aenderungen nur mit Zustimmung der Autoren !!! +\message{Option `picins' Version 3.0 Sep. 1992, TH Darmstadt/HRZ} +\newbox\@BILD% +\newbox\@TEXT% +\newdimen\d@breite% +\newdimen\d@hoehe% +\newdimen\d@xoff% +\newdimen\d@yoff% +\newdimen\d@shad% +\newdimen\d@dash% +\newdimen\d@boxl% +\newdimen\d@pichskip% +\newdimen\d@tmp +\newdimen\d@tmpa +\newdimen\d@bskip +\newdimen\hsiz@% +\newdimen\p@getot@l% +\newcount\c@breite +\newcount\c@hoehe +\newcount\c@xoff +\newcount\c@yoff +\newcount\c@pos +\newcount\c@shad +\newcount\c@dash +\newcount\c@boxl +\newcount\c@zeilen% +\newcount\@changemode% +\newcount\c@piccaption% +\newcount\c@piccaptionpos% +\newcount\c@picpos +\newcount\c@whole% +\newcount\c@half% +\newcount\c@tmp +\newcount\c@tmpa +\newcount\c@tmpb +\newcount\c@tmpc +\newcount\c@tmpd +\newskip\d@leftskip +\newif\if@list \@listfalse% +\newif\if@offset% + + +\c@piccaptionpos=1% +\c@picpos=0 +\d@shad=4pt% +\d@dash=4pt% +\d@boxl=10pt% +\d@pichskip=1em% +\@changemode=0% +\def\@captype{figure}% +\let\old@par=\par% + +\def\pichskip#1{\d@pichskip #1\relax} + + +\def\shadowthickness#1{\d@shad #1\relax} + + +\def\dashlength#1{\d@dash #1\relax} + + +\def\boxlength#1{\d@boxl #1\relax} + + +\def\picchangemode{\@changemode=1}% +\def\nopicchangemode{\@changemode=0}% + + +\def\piccaptionoutside{\c@piccaptionpos=1}% +\def\piccaptioninside{\c@piccaptionpos=2}% +\def\piccaptionside{\c@piccaptionpos=3}% +\def\piccaptiontopside{\c@piccaptionpos=4}% + +\def\piccaption{\@ifnextchar [{\@piccaption}{\@piccaption[]}} +\def\@piccaption[#1]#2{\c@piccaption=1\def\sh@rtf@rm{#1}\def\capti@nt@xt{#2}} +\def\make@piccaption{% + \hsiz@\d@breite% + \ifnum\c@piccaptionpos=2% + \advance\hsiz@ -2\fboxsep% + \fi% + \ifnum\c@piccaptionpos>2% + \hsiz@\hsize\advance\hsiz@-\d@breite\advance\hsiz@-\d@pichskip% + \fi% + \setbox\@TEXT=\vbox{\hsize\hsiz@\caption[\sh@rtf@rm]{\capti@nt@xt}}% +} + + + +\def\newcaption{\refstepcounter\@captype\@dblarg{\@newcaption\@captype}} +\long\def\@newcaption#1[#2]#3{% + \old@par% + \addcontentsline{\csname ext@#1\endcsname }{#1}% + {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}} + \begingroup\@parboxrestore\normalsize% + \@newmakecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\old@par% + \endgroup% +} +\long\def\@newmakecaption#1#2{% + \vskip 10pt% + \setbox\@tempboxa \hbox {#1: #2}% + \ifdim \wd\@tempboxa >\hsize% + \setbox0=\hbox{#1: }\dimen0=\hsize\advance\dimen0 by-\wd0 + \setbox1=\vtop{\hsize=\dimen0 #2} + \hbox{\box0 \box1} + \par + \else \hbox to\hsize {\hfil \box \@tempboxa \hfil} + \fi +} + + + + + +\def\parpic{% + \@ifnextchar ({\iparpic}{\iparpic(0pt,0pt)} +} +\def\iparpic(#1,#2){% + \@ifnextchar ({\@offsettrue\iiparpic(#1,#2)}% + {\@offsetfalse\iiparpic(#1,#2)(0pt,0pt)} +} +\def\iiparpic(#1,#2)(#3,#4){% + \@ifnextchar [{\iiiparpic(#1,#2)(#3,#4)}{\iiiparpic(#1,#2)(#3,#4)[l]} +} +\def\iiiparpic(#1,#2)(#3,#4)[#5]{% + \@ifnextchar [{\ivparpic(#1,#2)(#3,#4)[#5]}{\ivparpic(#1,#2)(#3,#4)[#5][]} +} +\def\ivparpic(#1,#2)(#3,#4)[#5][#6]#7{% + \let\par=\old@par\par% + \hangindent0pt\hangafter1% + \setbox\@BILD=\hbox{#7}% + \d@breite=#1\d@breite=\the\d@breite% + \ifdim\d@breite=0pt\d@breite=\wd\@BILD\fi% + \c@breite=\d@breite\divide\c@breite by65536% + \multiply\c@piccaption\c@piccaptionpos% + \d@hoehe=#2\d@hoehe=\the\d@hoehe% + \ifdim\d@hoehe=0pt\d@hoehe=\ht\@BILD\advance\d@hoehe by\dp\@BILD\fi% + \c@hoehe=\d@hoehe\divide\c@hoehe by65536% + \d@xoff=#3\c@xoff=\d@xoff\divide\c@xoff by65536% + \d@yoff=\d@hoehe% + \advance\d@yoff by-#4\c@yoff=\d@yoff\divide\c@yoff by65536% + \c@pos=1\unitlength1pt% + \if@offset% + \setbox\@BILD=\hbox{% + \begin{picture}(\c@breite,\c@hoehe)% + \put(0,0){\makebox(\c@breite,\c@hoehe){}}% + \put(\c@xoff,\c@yoff){\box\@BILD}% + \end{picture}% + }% + \else% + \setbox\@BILD=\hbox{% + \begin{picture}(\c@breite,\c@hoehe)% + \put(0,0){\makebox(\c@breite,\c@hoehe)[#6]{\box\@BILD}}% + \end{picture}% + }% + \fi% + \ifnum\c@piccaption=2% + \make@piccaption% + \advance\d@hoehe\ht\@TEXT\advance\d@hoehe\dp\@TEXT% + \c@hoehe=\d@hoehe\divide\c@hoehe by65536% + \setbox\@BILD=\vbox{\box\@BILD\vspace{-5pt}% + \hbox{\hspace{\fboxsep}\box\@TEXT}% + \vspace{4pt}}% + \fi% + \@tfor\@tempa := #5\do{% + \if\@tempa f\setbox\@BILD=\hbox{\Rahmen(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa s\setbox\@BILD=\hbox{\Schatten(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa o\setbox\@BILD=\hbox{\Oval(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa d\setbox\@BILD=\hbox{\Strich(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa x\setbox\@BILD=\hbox{\Kasten(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa l\c@pos=1\fi% + \if\@tempa r\c@pos=2\fi% + }% + \ifnum\c@piccaption=1% + \make@piccaption% + \advance\d@hoehe\ht\@TEXT\advance\d@hoehe\dp\@TEXT% + \c@hoehe=\d@hoehe\divide\c@hoehe by65536% + \setbox\@BILD=\vbox{\box\@BILD\vspace{-5pt}\hbox{\box\@TEXT}\vspace{4pt}}% + \fi% + \ifodd\count0\c@picpos=0\else\c@picpos=\@changemode\fi% + \pagetotal=\the\pagetotal% + \d@tmp=\pagegoal\advance\d@tmp by-\pagetotal\advance\d@tmp by-\baselineskip% + \ifdim\d@hoehe>\d@tmp% + \vskip 0pt plus\d@hoehe\relax\pagebreak[3]\vskip 0pt plus-\d@hoehe\relax% + \ifnum\c@picpos=1\c@picpos=0\else\c@picpos=\@changemode\fi% + \fi% + \ifnum\c@picpos=1\ifnum\c@pos=1\c@pos=2\else\c@pos=1\fi\fi% + \ifnum\@listdepth>0 + \@listtrue\parshape 0% + \advance\hsize -\rightmargin% + \d@leftskip \leftskip% + \leftskip \@totalleftmargin% + \if@inlabel\rule{\linewidth}{0pt}\vskip-\baselineskip\relax\fi% + \else\@listfalse\medskip% + \fi% + \if@list\d@tmpa=\linewidth\else\d@tmpa=\hsize\fi% + \ifnum\c@piccaption=3% + \make@piccaption% + \d@tmp\ht\@TEXT\advance\d@tmp\dp\@TEXT% + \ifdim\d@hoehe>\d@tmp% + \setbox\@TEXT=\vbox to\d@hoehe{\vfill\box\@TEXT\vspace{.2\baselineskip}\vfill}% + \else% + \setbox\@BILD=\vbox to\d@tmp{\vfill\box\@BILD\vfill}% + \d@hoehe\d@tmp% + \fi% + \fi% + \ifnum\c@piccaption=4% + \make@piccaption% + \d@tmp\ht\@TEXT\advance\d@tmp\dp\@TEXT% + \setbox\@TEXT=\vbox to\d@hoehe{\vspace{-10pt}\box\@TEXT\vfil}% + \advance\d@hoehe-\d@tmp% + \fi% + \ifnum\c@pos=1\d@tmpa=0pt% + \ifnum\c@piccaption>2% + \setbox\@BILD=\hbox{\box\@BILD\hspace{\d@pichskip}\hbox{\box\@TEXT}}% + \fi% + \else\advance\d@tmpa by-\wd\@BILD\d@breite=-\d@breite% + \ifnum\c@piccaption>2% + \d@tmpa=0pt% + \setbox\@BILD=\hbox{\hbox{\box\@TEXT}\hspace{\d@pichskip}\box\@BILD}% + \fi% + \fi% + \p@getot@l\the\pagetotal% + \d@bskip\d@hoehe\advance\d@bskip by\parskip\advance\d@bskip by.3\baselineskip% + {\noindent\hspace*{\d@tmpa}\relax% + \box\@BILD\nopagebreak\vskip-\d@bskip\relax\nopagebreak}% + \d@tmp=-\d@hoehe\divide\d@tmp by\baselineskip% + \c@zeilen=\d@tmp\advance\c@zeilen by-1% + \ifdim\d@breite<0pt\advance\d@breite by-\d@pichskip% + \else\advance\d@breite by\d@pichskip% + \fi% + \hangindent=\d@breite% + \hangafter=\c@zeilen% + \let\par=\x@par% + \ifnum\c@piccaption=3% + \hangindent0pt\hangafter1\let\par=\old@par% + \vskip\d@hoehe\vskip.2\baselineskip% + \fi% + \c@piccaption=0% +} + + + + +\newdimen\ptoti +\newdimen\ptotii +\def\x@par{% + \ptoti\pagetotal% + \old@par% + \ptotii\pagetotal% + \ifdim\ptoti=\ptotii% + \d@tmp\d@hoehe% + \else% + \d@tmp\baselineskip% + \multiply\d@tmp by\prevgraf% + \advance\d@tmp by\parskip% + \global\advance\d@hoehe by-\d@tmp\d@tmp=\d@hoehe% + \fi% + \ifdim\d@hoehe>0pt% + \divide\d@tmp by\baselineskip\c@zeilen=-\d@tmp\advance\c@zeilen by-1% + \c@zeilen=\the\c@zeilen% + \else\c@zeilen=0 + \fi + \ifnum\c@zeilen<0\hangafter=\c@zeilen\hangindent=\d@breite% + \else\let\par=\old@par% + \hangindent 0pt% + \leftskip \d@leftskip% + \if@list\parshape \@ne \@totalleftmargin \linewidth% + \advance\hsize \rightmargin% + \fi% + \fi% +} + + +\def\picskip#1{% + \let\par=\old@par% + \par% + \pagetotal\the\pagetotal% + \c@tmp=#1\relax% + \ifnum\c@tmp=0% + \d@tmp\baselineskip\multiply\d@tmp by\prevgraf\advance\d@tmp\parskip% + \ifdim\p@getot@l<\pagetotal + \advance\d@hoehe by-\d@tmp\advance\d@hoehe by1ex% + \ifdim\d@hoehe>0pt\vspace*{\d@hoehe}\fi% + \fi% + \ifdim\p@getot@l=\pagetotal% + \advance\d@hoehe by-\d@tmp\advance\d@hoehe by1ex% + \ifdim\d@hoehe>0pt\vspace*{\d@hoehe}\fi% + \fi% + \else\hangafter=-\c@tmp\hangindent=\d@breite% + \fi% + \leftskip \d@leftskip% + \if@list\parshape \@ne \@totalleftmargin \linewidth% + \advance\hsize \rightmargin% + \fi% +} + + + + + + +\def\hpic{% + \@ifnextchar ({\ihpic}{\ihpic(0pt,0pt)} +} +\def\ihpic(#1,#2){% + \@ifnextchar ({\@offsettrue\iihpic(#1,#2)}% + {\@offsetfalse\iihpic(#1,#2)(0pt,0pt)} +} +\def\iihpic(#1,#2)(#3,#4){% + \@ifnextchar [{\iiihpic(#1,#2)(#3,#4)}{\iiihpic(#1,#2)(#3,#4)[l]} +} +\def\iiihpic(#1,#2)(#3,#4)[#5]{% + \@ifnextchar [{\ivhpic(#1,#2)(#3,#4)[#5]}{\ivhpic(#1,#2)(#3,#4)[#5][]} +} +\def\ivhpic(#1,#2)(#3,#4)[#5][#6]#7{% + \setbox\@BILD=\hbox{#7}% + \d@breite=#1\d@breite=\the\d@breite% + \ifdim\d@breite=0pt\d@breite=\wd\@BILD\fi% + \c@breite=\d@breite\divide\c@breite by65536% + \d@hoehe=#2\d@hoehe=\the\d@hoehe% + \ifdim\d@hoehe=0pt\d@hoehe=\ht\@BILD\advance\d@hoehe by\dp\@BILD\fi% + \c@hoehe=\d@hoehe\divide\c@hoehe by65536% + \d@xoff=#3\c@xoff=\d@xoff\divide\c@xoff by65536% + \d@yoff=\d@hoehe% + \advance\d@yoff by-#4\c@yoff=\d@yoff\divide\c@yoff by65536% + \c@pos=0\d@tmpa=\parindent\parindent=0pt\unitlength1pt% + \if@offset + \setbox\@BILD=\hbox{% + \begin{picture}(\c@breite,\c@hoehe)% + \put(0,0){\makebox(\c@breite,\c@hoehe){}}% + \put(\c@xoff,\c@yoff){\box\@BILD}% + \end{picture}% + }% + \else% + \setbox\@BILD=\hbox{% + \begin{picture}(\c@breite,\c@hoehe)% + \put(0,0){\makebox(\c@breite,\c@hoehe)[#6]{\box\@BILD}}% + \end{picture}% + }% + \fi% + \@tfor\@tempa := #5\do{% + \if\@tempa f\setbox\@BILD=\hbox{\Rahmen(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa s\setbox\@BILD=\hbox{\Schatten(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa o\setbox\@BILD=\hbox{\Oval(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa d\setbox\@BILD=\hbox{\Strich(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa x\setbox\@BILD=\hbox{\Kasten(\c@breite,\c@hoehe){\box\@BILD}}\fi% + \if\@tempa t\c@pos=1\fi% + \if\@tempa b\c@pos=2\fi% + }% + \ifnum\c@pos=0\parbox{\d@breite}{\makebox[0cm]{}\\\box\@BILD\smallskip}\fi% + \ifnum\c@pos=1\parbox[t]{\d@breite}{\makebox[0cm]{}\\\box\@BILD\smallskip}\fi% + \ifnum\c@pos=2\parbox[b]{\d@breite}{\makebox[0cm]{}\\\box\@BILD\smallskip}\fi% + \parindent=\d@tmpa% +} + + + + + + +\def\Rahmen(#1,#2)#3{% + \c@whole=\@wholewidth\divide\c@whole by65536% + \c@half=\@halfwidth\divide\c@half by65536% + \c@tmpa=#1\advance\c@tmpa by\c@whole\advance\c@tmpa by\c@whole% + \c@tmpb=#2\advance\c@tmpb by\c@whole\advance\c@tmpb by\c@whole% + \begin{picture}(\c@tmpa,\c@tmpb)% + \put(\c@whole,\c@half){\framebox(#1,#2){#3}}% + \end{picture}% + \global\advance\d@breite by2\@wholewidth% + \global\advance\d@hoehe by2\@wholewidth% +} + + +\def\Schatten(#1,#2)#3{% + \c@whole=\@wholewidth\divide\c@whole by65536% + \c@half=\@halfwidth\divide\c@half by65536% + \c@shad=\d@shad\divide\c@shad by65536% + \c@tmp=\c@whole\advance\c@tmp by\c@whole\c@tmpd=\c@tmp% + \advance\c@tmp by\c@shad% + \advance\c@tmpd by#1% + \advance\c@half by\c@shad% + \c@tmpa=#1\advance\c@tmpa by\c@tmp% + \c@tmpb=#2\advance\c@tmpb by\c@tmp% + \begin{picture}(\c@tmpa,\c@tmpb)% + \put(\c@whole,\c@half){\framebox(#1,#2){#3}}% + \put(\c@shad,0){\rule{\c@tmpd pt}{\c@shad pt}}% + \put(\c@tmpd,0){\rule{\c@shad pt}{#2 pt}}% + \end{picture}% + \global\advance\d@breite by2\@wholewidth\global\advance\d@breite by\d@shad% + \global\advance\d@hoehe by2\@wholewidth\global\advance\d@hoehe by\d@shad% +} + + +\def\Oval(#1,#2)#3{% + \@wholewidth=0.4pt% + \c@tmpa=\the#1\divide\c@tmpa by2% + \c@tmpb=\the#2\divide\c@tmpb by2% + \begin{picture}(#1,#2)% + \put(\c@tmpa,\c@tmpb){\oval(#1,#2)}% + \put(0.4,0.4){#3}% + \end{picture}% + \global\advance\d@breite by1pt\global\advance\d@hoehe by1pt% +} + + +\def\Strich(#1,#2)#3{% + \c@whole=\@wholewidth\divide\c@whole by65536% + \c@half=\@halfwidth\divide\c@half by65536% + \c@dash=\d@dash\divide\c@dash by65536% + \c@tmp=\c@whole\advance\c@tmp by\c@whole% + \c@tmpa=#1\advance\c@tmpa by\c@tmp% + \c@tmpb=#2\advance\c@tmpb by\c@tmp% + \c@tmpc=#1\advance\c@tmpc by\c@whole% + \c@tmpd=#2\advance\c@tmpd by\c@whole% + \begin{picture}(\c@tmpa,\c@tmpb)% + \put(\c@half,\c@half){\dashbox{\c@dash}(\c@tmpc,\c@tmpd){#3}}% + \end{picture}% + \global\advance\d@breite by2\@wholewidth% + \global\advance\d@hoehe by2\@wholewidth% +} + + +\def\Kasten(#1,#2)#3{% + \@wholewidth=0.4pt% + \c@boxl=\d@boxl\divide\c@boxl by65536\c@boxl=\the\c@boxl% + \c@tmpa=#1\advance\c@tmpa by\c@boxl% + \c@tmpb=#2\advance\c@tmpb by\c@boxl% + \c@tmp=#2% + \begin{picture}(\c@tmpa,\c@tmpb)% + \put(0,\c@boxl){\framebox(#1,#2){#3}}% + \put(\c@boxl,0){\line(-1,1){\c@boxl}}% + \put(\c@boxl,0){\line(1,0){#1}\line(-1,1){\c@boxl}}% + \put(\c@boxl,0){\put(#1,0){\line(0,1){\c@tmp}% + \put(0,\c@tmp){\line(-1,1){\c@boxl}}}}% + \end{picture}% + \global\advance\d@breite by\d@boxl% + \global\advance\d@hoehe by\d@boxl% +} + + + + + +\newbox\env@box% +\newdimen\d@envdp +\newcount\c@hsize +\newcount\c@envdp +\newdimen\d@envb + +\long\def\frameenv{\@ifnextchar [{\@frameenv}{\@frameenv[\textwidth]}} +\long\def\@frameenv[#1]{% + \hsiz@=\textwidth \textwidth=#1 \d@envb=#1 + \advance\textwidth by-2\@wholewidth + \advance\textwidth by-2\fboxsep + \hsize=\textwidth \linewidth=\textwidth + \setbox\env@box=\vbox\bgroup}% +\def\endframeenv{% + \egroup% + \hsize=\hsiz@ \textwidth=\hsiz@ \linewidth=\hsiz@ + \c@breite=\d@envb \divide\c@breite by65536 + \advance\d@envb by-2\@wholewidth + \c@hsize=\d@envb \divide\c@hsize by65536% + \d@envdp=\dp\env@box \advance\d@envdp by\ht\env@box% + \advance\d@envdp by2\fboxsep% + \d@hoehe=\d@envdp \advance\d@hoehe by2\@wholewidth + \c@hoehe=\d@hoehe \divide\c@hoehe by65536 + \c@envdp=\d@envdp \divide\c@envdp by65536% + \c@tmp=\@wholewidth \divide\c@tmp by65536 + \vskip\@wholewidth% + \unitlength 1pt\noindent% + \begin{picture}(\c@breite,\c@hoehe)(0,0) + \put(\c@tmp,\c@tmp){\framebox(\c@hsize,\c@envdp){\box\env@box}} + \end{picture}% +} + + + +\long\def\shadowenv{\@ifnextchar [{\@shadowenv}{\@shadowenv[\textwidth]}} +\long\def\@shadowenv[#1]{% + \hsiz@=\textwidth \textwidth=#1 \d@envb=#1 + \advance\textwidth by-2\@wholewidth + \advance\textwidth by-2\fboxsep + \advance\textwidth by-\d@shad% + \hsize=\textwidth \linewidth=\textwidth + \setbox\env@box=\vbox\bgroup}% +\def\endshadowenv{% + \egroup + \hsize=\hsiz@ \textwidth=\hsiz@ \linewidth=\hsiz@ + \d@tmpa=\d@envb + \c@breite=\d@envb \divide\c@breite by65536 + \advance\d@envb by-2\@wholewidth \advance\d@envb by-\d@shad + \c@hsize=\d@envb \divide\c@hsize by65536% + \d@envdp=\dp\env@box \advance\d@envdp by\ht\env@box% + \advance\d@envdp by2\fboxsep% + \c@envdp=\d@envdp \divide\c@envdp by65536% + \d@hoehe=\d@envdp + \advance\d@hoehe by2\@wholewidth \advance\d@hoehe by\d@shad + \c@hoehe=\d@hoehe \divide\c@hoehe by65536 + \c@shad =\d@shad \divide\c@shad by65536 + \c@tmp=\@wholewidth \divide\c@tmp by65536 + \advance\d@tmpa by-2\d@shad + \c@xoff =\d@tmpa \divide\c@xoff by65536 + \advance\c@xoff by\c@shad \advance\c@xoff by-1 + \advance\d@envdp by\@wholewidth + \vskip\@halfwidth + \unitlength 1pt\noindent% + \begin{picture}(\c@breite,\c@hoehe)(0,0) + \put(\c@tmp,\c@shad){\framebox(\c@hsize,\c@envdp){\box\env@box}} + \put(\c@shad,0){\rule{\d@tmpa}{\d@shad}}% + \put(\c@xoff,0){\rule{\d@shad}{\d@envdp}}% + \end{picture}% + \vskip\@halfwidth +} + + +\long\def\dashenv{\@ifnextchar [{\@dashenv}{\@dashenv[\textwidth]}} +\long\def\@dashenv[#1]{% + \hsiz@=\textwidth \textwidth=#1 \d@envb=#1 + \advance\textwidth by-2\@wholewidth \advance\textwidth by-2\fboxsep + \hsize=\textwidth \linewidth=\textwidth + \setbox\env@box=\vbox\bgroup}% +\long\def\enddashenv{% + \egroup + \hsize=\hsiz@ \textwidth=\hsiz@ \linewidth=\hsiz@ + \c@breite=\d@envb \divide\c@breite by65536 + \advance\d@envb by-\@wholewidth + \c@hsize=\d@envb \divide\c@hsize by65536% + \d@envdp=\dp\env@box \advance\d@envdp by\ht\env@box% + \advance\d@envdp by2\fboxsep% + \advance\d@envdp by\@wholewidth + \d@hoehe=\d@envdp \advance\d@hoehe by2\@wholewidth + \c@hoehe=\d@hoehe \divide\c@hoehe by65536 + \c@envdp=\d@envdp \divide\c@envdp by65536% + \c@dash=\d@dash \divide\c@dash by65536% + \c@whole=\@wholewidth \divide\c@whole by65536 + \c@half=\@halfwidth \divide\c@half by 65536 + \noindent\unitlength 1pt + \begin{picture}(\c@breite,\c@hoehe)(0,0) + \put(\c@half,\c@whole){\dashbox{\c@dash}(\c@hsize,\c@envdp){\box\env@box}} + \end{picture}% +} + + +\long\def\ovalenv{\@ifnextchar [{\@ovalenv}{\@ovalenv[\textwidth]}}% +\long\def\@ovalenv[#1]{% + \hsiz@=\textwidth \textwidth=#1 \d@envb=#1 + \advance\textwidth by-4\fboxsep + \hsize=\textwidth \linewidth=\textwidth + \setbox\env@box=\vbox\bgroup}% +\long\def\endovalenv{% + \egroup + \hsize=\hsiz@ \textwidth=\hsiz@ \linewidth=\hsiz@ + \@wholewidth=0.4pt + \c@breite=\d@envb \divide\c@breite by65536 + \advance\d@envb by-2\@wholewidth + \c@hsize=\d@envb \divide\c@hsize by65536% + \d@envdp=\dp\env@box \advance\d@envdp by\ht\env@box% + \advance\d@envdp by4\fboxsep% + \c@envdp=\d@envdp \divide\c@envdp by65536% + \d@hoehe=\d@envdp \advance\d@hoehe by2\@wholewidth + \c@hoehe=\d@hoehe \divide\c@hoehe by65536 + \c@tmpa=\c@hsize \divide\c@tmpa by2% + \c@tmpb=\c@envdp \divide\c@tmpb by2% + \d@tmpa=2\fboxsep \advance\d@tmpa by\@wholewidth + \c@xoff=\d@tmpa \divide\c@xoff by65536% + \advance\d@tmpa by\dp\env@box + \c@yoff=\d@tmpa \divide\c@yoff by65536% + \unitlength 1pt\noindent + \begin{picture}(\c@breite,\c@hoehe)(0,0) + \put(\c@tmpa,\c@tmpb){\oval(\c@hsize,\c@envdp)} + \put(\c@xoff,\c@yoff){\box\env@box}% + \end{picture}% +} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/reference.bib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/reference.bib Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,33 @@ +@Misc{Yasutaka:2016, + author = "{比嘉 健太, 河野 真治}", + title = "{メタ計算を用いた Continuation based C の検証手法}", + journal = "琉球大学工学部情報工学科平成 28 年度学位論文", + year = 2016 +} + +@Misc{Tatsuki:2016, + author = "{伊波 立樹, 東恩納 琢偉, 河野 真治}", + title = "{Code Gear 、Data Gear に基づく OS のプロトタイプ}", + journal = "{情報処理学会システムソフトウェアとオペレーティングシステム研究会}", + year = 2016 +} + +@Misc{kaito:2015, + author = "{徳森 海斗, 河野 真治}", + title = "{LLVM Clang 上の Continuation based C コンパイラ の改良}", + journal = "{琉球大学工学部情報工学科平成 27 年度学位論文}", + year = 2015 +} + +@misc{agda, + title = {The Agda wiki}, + howpublished = {\url{http://wiki.portal.chalmers.se/agda/pmwiki.php}}, + note = {Accessed: 2018/2/20(Tue)} +} + + +@misc{agda-documentation, + title = {Welcome to Agda’s documentation! — Agda 2.5.3 documentation}, + howpublished = {\url{http://agda.readthedocs.io/en/v2.5.3/index.html}}, + note = {Accessed: 2018/2/20(Tue)} +} \ No newline at end of file diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaBasics.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaBasics.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,1 @@ +module AgdaBasics where diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaBasics.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaBasics.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,1 @@ +module AgdaBasics where diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaBool.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaBool.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +data Bool : Set where + true : Bool + false : Bool diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaDebug.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaDebug.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,32 @@ +open import Level renaming (suc to succ ; zero to Zero ) + +module AgdaDebug where + +open import stack + +open import Relation.Binary.PropositionalEquality +open import Relation.Binary.Core +open import Data.Nat +open import Function + + +open SingleLinkedStack +open Stack + +testStack07 : {m : Level } -> Maybe (Element ℕ) +testStack07 = pushSingleLinkedStack emptySingleLinkedStack 1 (\s -> pushSingleLinkedStack s 2 (\s -> top s)) + +testStack08 = pushSingleLinkedStack emptySingleLinkedStack 1 + $ \s -> pushSingleLinkedStack s 2 + $ \s -> pushSingleLinkedStack s 3 + $ \s -> pushSingleLinkedStack s 4 + $ \s -> pushSingleLinkedStack s 5 + $ \s -> top s + + +testStack10 = pushStack emptySingleLinkedStack 1 + $ \s -> pushStack 2 + $ \s -> pushStack 3 + $ \s -> pushStack 4 + $ \s -> pushStack 5 + $ \s -> top s diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaDebug.agdai Binary file final_pre/src/AgdaDebug.agdai has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaElem.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaElem.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +elem : {A : Set} {{eqA : Eq A}} → A → List A → Bool +elem {{eqA}} x (y ∷ xs) = (Eq._==_ eqA x y) || (elem {{eqA}} x xs) +elem x [] = false diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaElemApply.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaElemApply.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +listHas4 : Bool +listHas4 = elem 4 (3 ∷ 2 ∷ 5 ∷ 4 ∷ []) -- true + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaFunction.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaFunction.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,2 @@ +f : Bool -> Bool +f x = true diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaId.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaId.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,5 @@ +identity : (A : Set) -> A -> A +identity A x = x + +identity-zero : Nat +identity-zero = identity Nat zero diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaImplicitId.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaImplicitId.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,11 @@ +id : {A : Set} -> A -> A +id x = x + +id-zero : Nat +id-zero = id zero + +id' : {A : Set} -> A -> A +id' {A} x = x + +id-true : Bool +id-true = id {Bool} true diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaImport.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaImport.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,6 @@ +import Data.Nat -- import module +import Data.Bool as B -- renamed module +import Data.List using (head) -- import Data.head function +import Level renaming (suc to S) -- import module with rename suc to S +import Data.String hiding (_++_) -- import module without _++_ +open import Data.List -- import and expand Data.List diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaInstance.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaInstance.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,9 @@ +_==Nat_ : Nat -> Nat -> Bool +zero ==Nat zero = true +(suc n) ==Nat zero = false +zero ==Nat (suc m) = false +(suc n) ==Nat (suc m) = n ==Nat m + +instance + natHas== : Eq Nat + natHas== = record { _==_ = _==Nat_} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaInterface.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaInterface.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,6 @@ +record Stack {n m : Level } (a : Set n ) {t : Set m } (si : Set n ) : Set (m Level.⊔ n) where + field + stack : si + stackMethods : StackMethods {n} {m} a {t} si + pushStack : a -> (Stack a si -> t) -> t + pushStack d next = push (stackMethods ) (stack ) d (\s1 -> next (record {stack = s1 ; stackMethods = stackMethods } )) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaInterface.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaInterface.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,35 @@ +open import Level renaming (suc to succ ; zero to Zero ) +module AgdaInterface where + +data Maybe {n : Level } (a : Set n) : Set n where + Nothing : Maybe a + Just : a @$\rightarrow$@ Maybe a + +record StackMethods {n m : Level } (a : Set n ) {t : Set m }(stackImpl : Set n ) : Set (m Level.@$\sqcup$@ n) where + field + push : stackImpl @$\rightarrow$@ a @$\rightarrow$@ (stackImpl @$\rightarrow$@ t) @$\rightarrow$@ t + pop : stackImpl @$\rightarrow$@ (stackImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + pop2 : stackImpl @$\rightarrow$@ (stackImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + get : stackImpl @$\rightarrow$@ (stackImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + get2 : stackImpl @$\rightarrow$@ (stackImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + clear : stackImpl @$\rightarrow$@ (stackImpl @$\rightarrow$@ t) @$\rightarrow$@ t +open StackMethods + +record Stack {n m : Level } (a : Set n ) {t : Set m } (si : Set n ) : Set (m Level.@$\sqcup$@ n) where + field + stack : si + stackMethods : StackMethods {n} {m} a {t} si + pushStack : a @$\rightarrow$@ (Stack a si @$\rightarrow$@ t) @$\rightarrow$@ t + pushStack d next = push (stackMethods ) (stack ) d (\s1 @$\rightarrow$@ next (record {stack = s1 ; stackMethods = stackMethods } )) + popStack : (Stack a si @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + popStack next = pop (stackMethods ) (stack ) (\s1 d1 @$\rightarrow$@ next (record {stack = s1 ; stackMethods = stackMethods }) d1 ) + pop2Stack : (Stack a si @$\rightarrow$@ Maybe a @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + pop2Stack next = pop2 (stackMethods ) (stack ) (\s1 d1 d2 @$\rightarrow$@ next (record {stack = s1 ; stackMethods = stackMethods }) d1 d2) + getStack : (Stack a si @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + getStack next = get (stackMethods ) (stack ) (\s1 d1 @$\rightarrow$@ next (record {stack = s1 ; stackMethods = stackMethods }) d1 ) + get2Stack : (Stack a si @$\rightarrow$@ Maybe a @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + get2Stack next = get2 (stackMethods ) (stack ) (\s1 d1 d2 @$\rightarrow$@ next (record {stack = s1 ; stackMethods = stackMethods }) d1 d2) + clearStack : (Stack a si @$\rightarrow$@ t) @$\rightarrow$@ t + clearStack next = clear (stackMethods ) (stack ) (\s1 @$\rightarrow$@ next (record {stack = s1 ; stackMethods = stackMethods } )) + +open Stack diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaInterface.agdai Binary file final_pre/src/AgdaInterface.agdai has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaLambda.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaLambda.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,5 @@ +not-apply : Bool -> Bool +not-apply = (\b -> not b) -- use lambda + +not-apply : Bool -> Bool +not-appy b = not b -- not use lambda diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaModusPonens.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaModusPonens.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,2 @@ +f : {A B C : Set} -> ((A -> B) × (B -> C)) -> (A -> C) +f = \p x -> (snd p) ((fst p) x) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaNPushNPop.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaNPushNPop.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,13 @@ +n-push : {m : Meta} {{_ : M.DataSegment Meta}} (n : ℕ) -> M.CodeSegment Meta Meta +n-push {{mm}} (zero) = M.cs {{mm}} {{mm}} id +n-push {m} {{mm}} (suc n) = M.cs {{mm}} {{mm}} (\m -> M.exec {{mm}} {{mm}} (n-push {m} {{mm}} n) (pushOnce m)) + +n-pop : {m : Meta} {{_ : M.DataSegment Meta}} (n : ℕ) -> M.CodeSegment Meta Meta +n-pop {{mm}} (zero) = M.cs {{mm}} {{mm}} id +n-pop {m} {{mm}} (suc n) = M.cs {{mm}} {{mm}} (\m -> M.exec {{mm}} {{mm}} (n-pop {m} {{mm}} n) (popOnce m)) + +pop-n-push-type : ℕ -> ℕ -> ℕ -> SingleLinkedStack ℕ -> Set₁ +pop-n-push-type n cn ce s = M.exec (M.csComp {meta} (M.cs popOnce) (n-push {meta} (suc n))) meta + ≡ M.exec (n-push {meta} n) meta + where + meta = id-meta cn ce s diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaNPushNPopProof.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaNPushNPopProof.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,58 @@ +pop-n-push-type : ℕ -> ℕ -> ℕ -> SingleLinkedStack ℕ -> Set₁ +pop-n-push-type n cn ce s = M.exec (M.csComp (M.cs popOnce) (n-push (suc n))) meta + ≡ M.exec (n-push n) meta + where + meta = id-meta cn ce s + +pop-n-push : (n cn ce : ℕ) -> (s : SingleLinkedStack ℕ) -> pop-n-push-type n cn ce s +pop-n-push zero cn ce s = refl +pop-n-push (suc n) cn ce s = begin + M.exec (M.csComp (M.cs popOnce) (n-push (suc (suc n)))) (id-meta cn ce s) + ≡⟨ refl ⟩ + M.exec (M.csComp (M.cs popOnce) (M.csComp (n-push (suc n)) (M.cs pushOnce))) (id-meta cn ce s) + ≡⟨ exec-comp (M.cs popOnce) (M.csComp (n-push (suc n)) (M.cs pushOnce)) (id-meta cn ce s) ⟩ + M.exec (M.cs popOnce) (M.exec (M.csComp (n-push (suc n)) (M.cs pushOnce)) (id-meta cn ce s)) + ≡⟨ cong (\x -> M.exec (M.cs popOnce) x) (exec-comp (n-push (suc n)) (M.cs pushOnce) (id-meta cn ce s)) ⟩ + M.exec (M.cs popOnce) (M.exec (n-push (suc n))(M.exec (M.cs pushOnce) (id-meta cn ce s))) + ≡⟨ refl ⟩ + M.exec (M.cs popOnce) (M.exec (n-push (suc n)) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))}))) + ≡⟨ sym (exec-comp (M.cs popOnce) (n-push (suc n)) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))}))) ⟩ + M.exec (M.csComp (M.cs popOnce) (n-push (suc n))) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})) + ≡⟨ pop-n-push n cn ce (record {top = just (cons ce (SingleLinkedStack.top s))}) ⟩ + M.exec (n-push n) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})) + ≡⟨ refl ⟩ + M.exec (n-push n) (pushOnce (id-meta cn ce s)) + ≡⟨ refl ⟩ + M.exec (n-push n) (M.exec (M.cs pushOnce) (id-meta cn ce s)) + ≡⟨ refl ⟩ + M.exec (n-push (suc n)) (id-meta cn ce s) + ∎ + + + +n-push-pop-type : ℕ -> ℕ -> ℕ -> SingleLinkedStack ℕ -> Set₁ +n-push-pop-type n cn ce st = M.exec (M.csComp (n-pop n) (n-push n)) meta ≡ meta + where + meta = id-meta cn ce st + +n-push-pop : (n cn ce : ℕ) -> (s : SingleLinkedStack ℕ) -> n-push-pop-type n cn ce s +n-push-pop zero cn ce s = refl +n-push-pop (suc n) cn ce s = begin + M.exec (M.csComp (n-pop (suc n)) (n-push (suc n))) (id-meta cn ce s) + ≡⟨ refl ⟩ + M.exec (M.csComp (M.cs (\m -> M.exec (n-pop n) (popOnce m))) (n-push (suc n))) (id-meta cn ce s) + ≡⟨ exec-comp (M.cs (\m -> M.exec (n-pop n) (popOnce m))) (n-push (suc n)) (id-meta cn ce s) ⟩ + M.exec (M.cs (\m -> M.exec (n-pop n) (popOnce m))) (M.exec (n-push (suc n)) (id-meta cn ce s)) + ≡⟨ refl ⟩ + M.exec (n-pop n) (popOnce (M.exec (n-push (suc n)) (id-meta cn ce s))) + ≡⟨ refl ⟩ + M.exec (n-pop n) (M.exec (M.cs popOnce) (M.exec (n-push (suc n)) (id-meta cn ce s))) + ≡⟨ cong (\x -> M.exec (n-pop n) x) (sym (exec-comp (M.cs popOnce) (n-push (suc n)) (id-meta cn ce s))) ⟩ + M.exec (n-pop n) (M.exec (M.csComp (M.cs popOnce) (n-push (suc n))) (id-meta cn ce s)) + ≡⟨ cong (\x -> M.exec (n-pop n) x) (pop-n-push n cn ce s) ⟩ + M.exec (n-pop n) (M.exec (n-push n) (id-meta cn ce s)) + ≡⟨ sym (exec-comp (n-pop n) (n-push n) (id-meta cn ce s)) ⟩ + M.exec (M.csComp (n-pop n) (n-push n)) (id-meta cn ce s) + ≡⟨ n-push-pop n cn ce s ⟩ + id-meta cn ce s + ∎ diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaNat.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaNat.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +data Nat : Set where + zero : Nat + suc : Nat -> Nat diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaNot.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaNot.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +not : Bool -> Bool +not true = false +not false = true diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaParameterizedModule.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaParameterizedModule.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +module Sort (A : Set) (_<_ : A -> A -> Bool) where +sort : List A -> List A +sort = -- 実装は省略 ... + +-- Parameterized Module により N.sort や B.sort が可能 +open import Sort Nat Nat._<_ as N +open import Sort Bool Bool._<_ as B diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaPattern.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaPattern.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +not : Bool -> Bool +not false = true +not x = false diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaPlus.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaPlus.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +_+_ : Nat -> Nat -> Nat +zero + m = m +suc n + m = suc (n + m) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaProduct.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaProduct.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,8 @@ +data _×_ (A B : Set) : Set where + <_,_> : A -> B -> A × B + +fst : {A B : Set} -> A × B -> A +fst < a , _ > = a + +snd : {A B : Set} -> A × B -> B +snd < _ , b > = b diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaProp.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaProp.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,2 @@ +prop : Bool +prop = true diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaPushPop.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaPushPop.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,28 @@ +pushSingleLinkedStack : Meta -> Meta +pushSingleLinkedStack m = M.exec (liftMeta n) (record m {stack = (push s e) }) + where + n = Meta.nextCS m + s = Meta.stack m + e = Context.element (Meta.context m) + push : SingleLinkedStack A -> Maybe A -> SingleLinkedStack A + push s nothing = s + push s (just x) = record {top = just (cons x (top s))} + +popSingleLinkedStack : Meta -> Meta +popSingleLinkedStack m = M.exec (liftMeta n) (record m {stack = (st m) ; context = record con {element = (elem m)}}) + where + n = Meta.nextCS m + con = Meta.context m + elem : Meta -> Maybe A + elem record {stack = record { top = (just (cons x _)) }} = just x + elem record {stack = record { top = nothing }} = nothing + st : Meta -> SingleLinkedStack A + st record {stack = record { top = (just (cons _ s)) }} = record {top = s} + st record {stack = record { top = nothing }} = record {top = nothing} + + +pushSingleLinkedStackCS : M.CodeSegment Meta Meta +pushSingleLinkedStackCS = M.cs pushSingleLinkedStack + +popSingleLinkedStackCS : M.CodeSegment Meta Meta +popSingleLinkedStackCS = M.cs popSingleLinkedStack diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaPushPopProof.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaPushPopProof.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,11 @@ +id-meta : ℕ -> ℕ -> SingleLinkedStack ℕ -> Meta +id-meta n e s = record { context = record {n = n ; element = just e} + ; nextCS = (N.cs id) ; stack = s} + +push-pop-type : ℕ -> ℕ -> ℕ -> Element ℕ -> Set₁ +push-pop-type n e x s = M.exec (M.csComp {meta} (M.cs popOnce) (M.cs pushOnce)) meta ≡ meta + where + meta = id-meta n e record {top = just (cons x (just s))} + +push-pop : (n e x : ℕ) -> (s : Element ℕ) -> push-pop-type n e x s +push-pop n e x s = refl diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaRecord.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaRecord.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +record Point : Set where + field + x : Nat + y : Nat + +makePoint : Nat -> Nat -> Point +makePoint a b = record { x = a ; y = b } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaRecordProj.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaRecordProj.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,8 @@ +getX : Point -> Nat +getX p = Point.x p + +getY : Point -> Nat +getY record { x = a ; y = b} = b + +xPlus5 : Point -> Point +xPlus5 p = record p { x = (Point.x p) + 5} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaSingleLinkedStack.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaSingleLinkedStack.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,5 @@ +pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} -> SingleLinkedStack Data -> Data -> (Code : SingleLinkedStack Data -> t) -> t +pushSingleLinkedStack stack datum next = next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaSingleLinkedStack.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaSingleLinkedStack.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,63 @@ +singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ StackMethods {n} {m} a {t} (SingleLinkedStack a) +singleLinkedStackSpec = record { +push = pushSingleLinkedStack +; pop = popSingleLinkedStack +; pop2 = pop2SingleLinkedStack +; get = getSingleLinkedStack +; get2 = get2SingleLinkedStack +; clear = clearSingleLinkedStack +} + +createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ Stack {n} {m} a {t} (SingleLinkedStack a) +createSingleLinkedStack = record { +stack = emptySingleLinkedStack ; +stackMethods = singleLinkedStackSpec +} + +-- Implementation + +pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} @$\rightarrow$@ SingleLinkedStack Data @$\rightarrow$@ Data @$\rightarrow$@ (Code : SingleLinkedStack Data @$\rightarrow$@ t) @$\rightarrow$@ t +pushSingleLinkedStack stack datum next = next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} + + +popSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ SingleLinkedStack a @$\rightarrow$@ (Code : SingleLinkedStack a @$\rightarrow$@ (Maybe a) @$\rightarrow$@ t) @$\rightarrow$@ t +popSingleLinkedStack stack cs with (top stack) +... | Nothing = cs stack Nothing +... | Just d = cs stack1 (Just data1) + where + data1 = datum d + stack1 = record { top = (next d) } + +pop2SingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ SingleLinkedStack a @$\rightarrow$@ (Code : SingleLinkedStack a @$\rightarrow$@ (Maybe a) @$\rightarrow$@ (Maybe a) @$\rightarrow$@ t) @$\rightarrow$@ t +pop2SingleLinkedStack {n} {m} {t} {a} stack cs with (top stack) +... | Nothing = cs stack Nothing Nothing +... | Just d = pop2SingleLinkedStack' {n} {m} stack cs + where + pop2SingleLinkedStack' : {n m : Level } {t : Set m } @$\rightarrow$@ SingleLinkedStack a @$\rightarrow$@ (Code : SingleLinkedStack a @$\rightarrow$@ (Maybe a) @$\rightarrow$@ (Maybe a) @$\rightarrow$@ t) @$\rightarrow$@ t + pop2SingleLinkedStack' stack cs with (next d) + ... | Nothing = cs stack Nothing Nothing + ... | Just d1 = cs (record {top = (next d1)}) (Just (datum d)) (Just (datum d1)) + + +getSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ SingleLinkedStack a @$\rightarrow$@ (Code : SingleLinkedStack a @$\rightarrow$@ (Maybe a) @$\rightarrow$@ t) @$\rightarrow$@ t +getSingleLinkedStack stack cs with (top stack) +... | Nothing = cs stack Nothing +... | Just d = cs stack (Just data1) + where + data1 = datum d + +get2SingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ SingleLinkedStack a @$\rightarrow$@ (Code : SingleLinkedStack a @$\rightarrow$@ (Maybe a) @$\rightarrow$@ (Maybe a) @$\rightarrow$@ t) @$\rightarrow$@ t +get2SingleLinkedStack {n} {m} {t} {a} stack cs with (top stack) +... | Nothing = cs stack Nothing Nothing +... | Just d = get2SingleLinkedStack' {n} {m} stack cs + where + get2SingleLinkedStack' : {n m : Level} {t : Set m } @$\rightarrow$@ SingleLinkedStack a @$\rightarrow$@ (Code : SingleLinkedStack a @$\rightarrow$@ (Maybe a) @$\rightarrow$@ (Maybe a) @$\rightarrow$@ t) @$\rightarrow$@ t + get2SingleLinkedStack' stack cs with (next d) + ... | Nothing = cs stack Nothing Nothing + ... | Just d1 = cs stack (Just (datum d)) (Just (datum d1)) + +clearSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ SingleLinkedStack a @$\rightarrow$@ (SingleLinkedStack a @$\rightarrow$@ t) @$\rightarrow$@ t +clearSingleLinkedStack stack next = next (record {top = Nothing}) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStack.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStack.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,13 @@ +data Element (a : Set) : Set where + cons : a -> Maybe (Element a) -> Element a + +datum : {a : Set} -> Element a -> a +datum (cons a _) = a + +next : {a : Set} -> Element a -> Maybe (Element a) +next (cons _ n) = n + +record SingleLinkedStack (a : Set) : Set where + field + top : Maybe (Element a) + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackDS.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStackDS.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,17 @@ +record Context : Set where + field + -- fields for stack + element : Maybe A + + +open import subtype Context as N + +record Meta : Set₁ where + field + -- context as set of data segments + context : Context + stack : SingleLinkedStack A + nextCS : N.CodeSegment Context Context + +open import subtype Meta as M + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackImpl.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStackImpl.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,28 @@ +record SingleLinkedStack {n : Level } (a : Set n) : Set n where + field + top : Maybe (Element a) +open SingleLinkedStack + +pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} -> SingleLinkedStack Data -> Data -> (Code : SingleLinkedStack Data -> t) -> t +pushSingleLinkedStack stack datum next = next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} + +-- Basic stack implementations are specifications of a Stack + +singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} -> StackMethods {n} {m} a {t} (SingleLinkedStack a) +singleLinkedStackSpec = record { + push = pushSingleLinkedStack + ; pop = popSingleLinkedStack + ; pop2 = pop2SingleLinkedStack + ; get = getSingleLinkedStack + ; get2 = get2SingleLinkedStack + ; clear = clearSingleLinkedStack + } + +createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> Stack {n} {m} a {t} (SingleLinkedStack a) +createSingleLinkedStack = record { + stack = emptySingleLinkedStack ; + stackMethods = singleLinkedStackSpec + } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackImpl.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStackImpl.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,28 @@ +record SingleLinkedStack {n : Level } (a : Set n) : Set n where + field + top : Maybe (Element a) +open SingleLinkedStack + +pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} @$\rightarrow$@ SingleLinkedStack Data @$\rightarrow$@ Data @$\rightarrow$@ (Code : SingleLinkedStack Data @$\rightarrow$@ t) @$\rightarrow$@ t +pushSingleLinkedStack stack datum next = next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} + +-- Basic stack implementations are specifications of a Stack + +singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ StackMethods {n} {m} a {t} (SingleLinkedStack a) +singleLinkedStackSpec = record { + push = pushSingleLinkedStack + ; pop = popSingleLinkedStack + ; pop2 = pop2SingleLinkedStack + ; get = getSingleLinkedStack + ; get2 = get2SingleLinkedStack + ; clear = clearSingleLinkedStack + } + +createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} @$\rightarrow$@ Stack {n} {m} a {t} (SingleLinkedStack a) +createSingleLinkedStack = record { + stack = emptySingleLinkedStack ; + stackMethods = singleLinkedStackSpec + } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackSomeState.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStackSomeState.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,2 @@ +stackInSomeState : {l m : Level } {D : Set l} {t : Set m } (s : SingleLinkedStack D ) -> Stack {l} {m} D {t} ( SingleLinkedStack D ) +stackInSomeState s = record { stack = s ; stackMethods = singleLinkedStackSpec } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackSomeState.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStackSomeState.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,6 @@ +stackInSomeState : {l m : Level } {D : Set l} {t : Set m } (s : SingleLinkedStack D ) @$\rightarrow$@ Stack {l} {m} D {t} ( SingleLinkedStack D ) +stackInSomeState s = record { stack = s ; stackMethods = singleLinkedStackSpec } + +push@$\rightarrow$@push@$\rightarrow$@pop2 : {l : Level } {D : Set l} (x y : D ) (s : SingleLinkedStack D ) @$\rightarrow$@ pushStack (stackInSomeState s) x (\s1 @$\rightarrow$@ pushStack s1 y (\s2 @$\rightarrow$@ pop2Stack s2 (\s3 y1 x1 @$\rightarrow$@ + (Just x @$\equiv$@ x1) ∧ (Just y @$\equiv$@ y1)))) +push@$\rightarrow$@push@$\rightarrow$@pop2 {l} {D} x y s = record { pi1 = refl ; pi2 = refl } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackTest.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStackTest.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,37 @@ +open import Level renaming (suc to succ ; zero to Zero ) +module AgdaStackTest where + +open import stack + +open import Relation.Binary.PropositionalEquality +open import Relation.Binary.Core +open import Data.Nat +open import Function + + +open SingleLinkedStack +open Stack + + +-- after push 1 and 2, pop2 get 1 and 2 + +testStack02 : {m : Level } -> ( Stack ℕ (SingleLinkedStack ℕ) -> Bool {m} ) -> Bool {m} +testStack02 cs = pushStack createSingleLinkedStack 1 (\s -> pushStack s 2 cs) + + +testStack031 : (d1 d2 : ℕ ) -> Bool {Zero} +testStack031 2 1 = True +testStack031 _ _ = False + +testStack032 : (d1 d2 : Maybe ℕ) -> Bool {Zero} +testStack032 (Just d1) (Just d2) = testStack031 d1 d2 +testStack032 _ _ = False + +testStack03 : {m : Level } -> Stack ℕ (SingleLinkedStack ℕ) -> ((Maybe ℕ) -> (Maybe ℕ) -> Bool {m} ) -> Bool {m} +testStack03 s cs = pop2Stack s (\s d1 d2 -> cs d1 d2 ) + +testStack04 : Bool +testStack04 = testStack02 (\s -> testStack03 s testStack032) + +testStack05 : testStack04 ≡ True +testStack05 = refl diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackTest.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaStackTest.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,22 @@ +-- after push 1 and 2, pop2 get 1 and 2 + +testStack02 : {m : Level } @$\rightarrow$@ ( Stack @$\mathbb{N}$@ (SingleLinkedStack @$\mathbb{N}$@) @$\rightarrow$@ Bool {m} ) @$\rightarrow$@ Bool {m} +testStack02 cs = pushStack createSingleLinkedStack 1 (\s @$\rightarrow$@ pushStack s 2 cs) + + +testStack031 : (d1 d2 : $\mathbb{N}$ ) @$\rightarrow$@ Bool {Zero} +testStack031 2 1 = True +testStack031 _ _ = False + +testStack032 : (d1 d2 : Maybe @$\mathbb{N}$@) @$\rightarrow$@ Bool {Zero} +testStack032 (Just d1) (Just d2) = testStack031 d1 d2 +testStack032 _ _ = False + +testStack03 : {m : Level } @$\rightarrow$@ Stack @$\mathbb{N}$@ (SingleLinkedStack @$\mathbb{N}$@) @$\rightarrow$@ ((Maybe @$\mathbb{N}$@) @$\rightarrow$@ (Maybe @$\mathbb{N}$@) @$\rightarrow$@ Bool {m} ) @$\rightarrow$@ Bool {m} +testStack03 s cs = pop2Stack s (\s d1 d2 @$\rightarrow$@ cs d1 d2 ) + +testStack04 : Bool +testStack04 = testStack02 (\s @$\rightarrow$@ testStack03 s testStack032) + +testStack05 : testStack04 @$\equiv$@ True +testStack05 = refl diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaStackTest.agdai Binary file final_pre/src/AgdaStackTest.agdai has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTree.Agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTree.Agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,17 @@ +record TreeMethods {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where + field + putImpl : treeImpl -> a -> (treeImpl -> t) -> t + getImpl : treeImpl -> (treeImpl -> Maybe a -> t) -> t +open TreeMethods + +record Tree {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where + field + tree : treeImpl + treeMethods : TreeMethods {n} {m} {a} {t} treeImpl + putTree : a -> (Tree treeImpl -> t) -> t + putTree d next = putImpl (treeMethods ) tree d (\t1 -> next (record {tree = t1 ; treeMethods = treeMethods} )) + getTree : (Tree treeImpl -> Maybe a -> t) -> t + getTree next = getImpl (treeMethods ) tree (\t1 d -> next (record {tree = t1 ; treeMethods = treeMethods} ) d ) + +open Tree + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTree.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTree.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,17 @@ +record TreeMethods {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.@$\sqcup$@ n) where + field + putImpl : treeImpl @$\rightarrow$@ a @$\rightarrow$@ (treeImpl @$\rightarrow$@ t) @$\rightarrow$@ t + getImpl : treeImpl @$\rightarrow$@ (treeImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t +open TreeMethods + +record Tree {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.@$\sqcup$@ n) where + field + tree : treeImpl + treeMethods : TreeMethods {n} {m} {a} {t} treeImpl + putTree : a @$\rightarrow$@ (Tree treeImpl @$\rightarrow$@ t) @$\rightarrow$@ t + putTree d next = putImpl (treeMethods ) tree d (\t1 @$\rightarrow$@ next (record {tree = t1 ; treeMethods = treeMethods} )) + getTree : (Tree treeImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + getTree next = getImpl (treeMethods ) tree (\t1 d @$\rightarrow$@ next (record {tree = t1 ; treeMethods = treeMethods} ) d ) + +open Tree + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeDebug.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeDebug.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,15 @@ +test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 + $ \t -> putTree1 t 2 2 + $ \t -> putTree1 t 3 3 + $ \t -> putTree1 t 4 4 + $ \t -> getRedBlackTree t 4 + $ \t x -> x + +-- Just +-- (record +-- { key = 4 +-- ; value = 4 +-- ; right = Nothing +-- ; left = Nothing +-- ; color = Red +-- }) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeDebug.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeDebug.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,15 @@ +test31 = putTree1 {_} {_} {@$\mathbb{N}$@} {@$\mathbb{N}$@} (createEmptyRedBlackTree@$\mathbb{N}$@ @$\mathbb{N}$@ ) 1 1 + $ \t @$\rightarrow$@ putTree1 t 2 2 + $ \t @$\rightarrow$@ putTree1 t 3 3 + $ \t @$\rightarrow$@ putTree1 t 4 4 + $ \t @$\rightarrow$@ getRedBlackTree t 4 + $ \t x @$\rightarrow$@ x + +-- Just +-- (record +-- { key = 4 +-- ; value = 4 +-- ; right = Nothing +-- ; left = Nothing +-- ; color = Red +-- }) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeDebugReturnNode4.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeDebugReturnNode4.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,16 @@ +test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 +$ \t -> putTree1 t 2 2 +$ \t -> putTree1 t 3 3 +$ \t -> putTree1 t 4 4 +$ \t -> getRedBlackTree t 4 +$ \t x -> x + +-- C-c C-n test31 return + -- Just + -- (record + -- { key = 4 + -- ; value = 4 + -- ; right = Nothing + -- ; left = Nothing + -- ; color = Red + -- }) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeImpl.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeImpl.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,33 @@ +record Node {n : Level } (a k : Set n) : Set n where + inductive + field + key : k + value : a + right : Maybe (Node a k) + left : Maybe (Node a k) + color : Color {n} +open Node + +leafNode : {n : Level } {a k : Set n} -> k -> a -> Node a k +leafNode k1 value = record { + key = k1 ; + value = value ; + right = Nothing ; + left = Nothing ; + color = Red + } +open leafNode + +record RedBlackTree {n m : Level } {t : Set m} (a k : Set n) : Set (m Level.⊔ n) where + field + root : Maybe (Node a k) + nodeStack : SingleLinkedStack (Node a k) + compare : k -> k -> CompareResult {n} +open RedBlackTree + +putRedBlackTree : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> k -> a -> (RedBlackTree {n} {m} {t} a k -> t) -> t +putRedBlackTree {n} {m} {a} {k} {t} tree k1 value next with (root tree) +... | Nothing = next (record tree {root = Just (leafNode k1 value) }) +... | Just n2 = clearSingleLinkedStack (nodeStack tree) (\ s -> findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 -> insertNode tree1 s n1 next)) + +-- 以下省略 diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeImpl.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeImpl.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,47 @@ +record TreeMethods {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.@$\sqcup$@ n) where + field + putImpl : treeImpl @$\rightarrow$@ a @$\rightarrow$@ (treeImpl @$\rightarrow$@ t) @$\rightarrow$@ t + getImpl : treeImpl @$\rightarrow$@ (treeImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t +open TreeMethods + +record Tree {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.@$\sqcup$@ n) where + field + tree : treeImpl + treeMethods : TreeMethods {n} {m} {a} {t} treeImpl + putTree : a @$\rightarrow$@ (Tree treeImpl @$\rightarrow$@ t) @$\rightarrow$@ t + putTree d next = putImpl (treeMethods ) tree d (\t1 @$\rightarrow$@ next (record {tree = t1 ; treeMethods = treeMethods} )) + getTree : (Tree treeImpl @$\rightarrow$@ Maybe a @$\rightarrow$@ t) @$\rightarrow$@ t + getTree next = getImpl (treeMethods ) tree (\t1 d @$\rightarrow$@ next (record {tree = t1 ; treeMethods = treeMethods} ) d ) +open Tree + +record Node {n : Level } (a k : Set n) : Set n where + inductive + field + key : k + value : a + right : Maybe (Node a k) + left : Maybe (Node a k) + color : Color {n} +open Node + +leafNode : {n : Level } {a k : Set n} @$\rightarrow$@ k @$\rightarrow$@ a @$\rightarrow$@ Node a k +leafNode k1 value = record { + key = k1 ; + value = value ; + right = Nothing ; + left = Nothing ; + color = Red + } +record RedBlackTree {n m : Level } {t : Set m} (a k : Set n) : Set (m Level.@$\sqcup$@ n) where + field + root : Maybe (Node a k) + nodeStack : SingleLinkedStack (Node a k) + compare : k @$\rightarrow$@ k @$\rightarrow$@ CompareResult {n} +open RedBlackTree + +putRedBlackTree : {n m : Level } {a k : Set n} {t : Set m} @$\rightarrow$@ RedBlackTree {n} {m} {t} a k @$\rightarrow$@ k @$\rightarrow$@ a @$\rightarrow$@ (RedBlackTree {n} {m} {t} a k @$\rightarrow$@ t) @$\rightarrow$@ t +putRedBlackTree {n} {m} {a} {k} {t} tree k1 value next with (root tree) +... | Nothing = next (record tree {root = Just (leafNode k1 value) }) +... | Just n2 = clearSingleLinkedStack (nodeStack tree) (\ s @$\rightarrow$@ findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 @$\rightarrow$@ insertNode tree1 s n1 next)) + +-- 以下省略 diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeProof.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeProof.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,34 @@ +redBlackInSomeState : { m : Level } (a : Set Level.zero) (n : Maybe (Node a ℕ)) {t : Set m} -> RedBlackTree {Level.zero} {m} {t} a ℕ +redBlackInSomeState {m} a n {t} = record { root = n ; nodeStack = emptySingleLinkedStack ; compare = compare2 } + +putTest1 :{ m : Level } (n : Maybe (Node ℕ ℕ)) + -> (k : ℕ) (x : ℕ) + -> putTree1 {_} {_} {ℕ} {ℕ} (redBlackInSomeState {_} ℕ n {Set Level.zero}) k x + (\ t -> getRedBlackTree t k (\ t x1 -> check2 x1 x ≡ True)) +putTest1 n k x with n +... | Just n1 = lemma2 ( record { top = Nothing } ) + where + lemma2 : (s : SingleLinkedStack (Node ℕ ℕ) ) -> putTree1 (record { root = Just n1 ; nodeStack = s ; compare = compare2 }) k x (λ t → + GetRedBlackTree.checkNode t k (λ t₁ x1 → check2 x1 x ≡ True) (root t)) + lemma2 s with compare2 k (key n1) + ... | EQ = lemma3 {!!} + where + lemma3 : compare2 k (key n1) ≡ EQ -> getRedBlackTree {_} {_} {ℕ} {ℕ} {Set Level.zero} ( record { root = Just ( record { + key = key n1 ; value = x ; right = right n1 ; left = left n1 ; color = Black + } ) ; nodeStack = s ; compare = λ x₁ y → compare2 x₁ y } ) k ( \ t x1 -> check2 x1 x ≡ True) + lemma3 eq with compare2 x x | putTest1Lemma2 x + ... | EQ | refl with compare2 k (key n1) | eq + ... | EQ | refl with compare2 x x | putTest1Lemma2 x + ... | EQ | refl = refl + ... | GT = {!!} + ... | LT = {!!} + +... | Nothing = lemma1 + where + lemma1 : getRedBlackTree {_} {_} {ℕ} {ℕ} {Set Level.zero} ( record { root = Just ( record { + key = k ; value = x ; right = Nothing ; left = Nothing ; color = Red + } ) ; nodeStack = record { top = Nothing } ; compare = λ x₁ y → compare2 x₁ y } ) k + ( \ t x1 -> check2 x1 x ≡ True) + lemma1 with compare2 k k | putTest1Lemma2 k + ... | EQ | refl with compare2 x x | putTest1Lemma2 x + ... | EQ | refl = refl diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeProof.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeProof.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,34 @@ +redBlackInSomeState : { m : Level } (a : Set Level.zero) (n : Maybe (Node a @$\mathbb{N}$@)) {t : Set m} @$\rightarrow$@ RedBlackTree {Level.zero} {m} {t} a @$\mathbb{N}$@ +redBlackInSomeState {m} a n {t} = record { root = n ; nodeStack = emptySingleLinkedStack ; compare = compare2 } + +putTest1 :{ m : Level } (n : Maybe (Node @$\mathbb{N}$@ @$\mathbb{N}$@)) + @$\rightarrow$@ (k : @$\mathbb{N}$@) (x : @$\mathbb{N}$@) + @$\rightarrow$@ putTree1 {_} {_} {@$\mathbb{N}$@} {@$\mathbb{N}$@} (redBlackInSomeState {_} @$\mathbb{N}$@ n {Set Level.zero}) k x + (\ t @$\rightarrow$@ getRedBlackTree t k (\ t x1 @$\rightarrow$@ check2 x1 x @$\equiv$@ True)) +putTest1 n k x with n +... | Just n1 = lemma2 ( record { top = Nothing } ) + where + lemma2 : (s : SingleLinkedStack (Node @$\mathbb{N}$@ @$\mathbb{N}$@) ) @$\rightarrow$@ putTree1 (record { root = Just n1 ; nodeStack = s ; compare = compare2 }) k x (λ t → + GetRedBlackTree.checkNode t k (λ t@$\text{1}$@ x1 → check2 x1 x @$\equiv$@ True) (root t)) + lemma2 s with compare2 k (key n1) + ... | EQ = lemma3 {!!} + where + lemma3 : compare2 k (key n1) @$\equiv$@ EQ @$\rightarrow$@ getRedBlackTree {_} {_} {@$\mathbb{N}$@} {@$\mathbb{N}$@} {Set Level.zero} ( record { root = Just ( record { + key = key n1 ; value = x ; right = right n1 ; left = left n1 ; color = Black + } ) ; nodeStack = s ; compare = λ x@$\text{1}$@ y → compare2 x@$\text{1}$@ y } ) k ( \ t x1 @$\rightarrow$@ check2 x1 x @$\equiv$@ True) + lemma3 eq with compare2 x x | putTest1Lemma2 x + ... | EQ | refl with compare2 k (key n1) | eq + ... | EQ | refl with compare2 x x | putTest1Lemma2 x + ... | EQ | refl = refl + ... | GT = {!!} + ... | LT = {!!} + +... | Nothing = lemma1 + where + lemma1 : getRedBlackTree {_} {_} {@$\mathbb{N}$@} {@$\mathbb{N}$@} {Set Level.zero} ( record { root = Just ( record { + key = k ; value = x ; right = Nothing ; left = Nothing ; color = Red + } ) ; nodeStack = record { top = Nothing } ; compare = λ x@$\text{1}$@ y → compare2 x@$\text{1}$@ y } ) k + ( \ t x1 @$\rightarrow$@ check2 x1 x @$\equiv$@ True) + lemma1 with compare2 k k | putTest1Lemma2 k + ... | EQ | refl with compare2 x x | putTest1Lemma2 x + ... | EQ | refl = refl diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTreeTest.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTreeTest.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,6 @@ +test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 +$ \t -> putTree1 t 2 2 +$ \t -> putTree1 t 3 3 +$ \t -> putTree1 t 4 4 +$ \t -> getRedBlackTree t 4 +$ \t x -> x diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaTypeClass.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaTypeClass.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +record Eq (A : Set) : Set where + field + _==_ : A -> A -> Bool diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/AgdaWhere.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/AgdaWhere.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +f : Int -> Int -> Int +f a b c = (t a) + (t b) + (t c) + where + t x = x + x + x + +f' : Int -> Int -> Int +f' a b c = (a + a + a) + (b + b + b) + (c + c + c) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/CodeSegment.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/CodeSegment.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,2 @@ +data CodeSegment {l1 l2 : Level} (I : Set l1) (O : Set l2) : Set (l ⊔ l1 ⊔ l2) where + cs : (I -> O) -> CodeSegment I O diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/CodeSegment.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/CodeSegment.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,2 @@ +data CodeSegment {l1 l2 : Level} (I : Set l1) (O : Set l2) : Set (l @$\sqcup$@ l1 @$\sqcup$@ l2) where + cs : (I @$\rightarrow$@ O) @$\rightarrow$@ CodeSegment I O diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/CodeSegments.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/CodeSegments.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,12 @@ +cs2 : CodeSegment ds1 ds1 +cs2 = cs id + +cs1 : CodeSegment ds1 ds1 +cs1 = cs (\d -> goto cs2 d) + +cs0 : CodeSegment ds0 ds1 +cs0 = cs (\d -> goto cs1 (record {c = (ds0.a d) + (ds0.b d)})) + +main : ds1 +main = goto cs0 (record {a = 100 ; b = 50}) + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/DataSegment.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/DataSegment.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,8 @@ +record ds0 : Set where + field + a : Int + b : Int + +record ds1 : Set where + field + c : Int diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/DataSegment.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/DataSegment.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,8 @@ +record ds0 : Set where + field + a : Int + b : Int + +record ds1 : Set where + field + c : Int diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Eq.Agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Eq.Agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,30 @@ +module Eq where +open import Data.Nat +open import Data.Bool +open import Data.List + +record Eq (A : Set) : Set where + field + _==_ : A -> A -> Bool + +_==Nat_ : ℕ -> ℕ -> Bool +zero ==Nat zero = true +(suc n) ==Nat zero = false +zero ==Nat (suc m) = false +(suc n) ==Nat (suc m) = n ==Nat m + + +instance + _ : Eq ℕ + _ = record { _==_ = _==Nat_} + +_||_ : Bool -> Bool -> Bool +true || _ = true +false || x = x + +elem : {A : Set} {{eqA : Eq A}} → A → List A → Bool +elem {{eqA}} x (y ∷ xs) = (Eq._==_ eqA x y) || (elem {{eqA}} x xs) +elem x [] = false + +listHas4 : Bool +listHas4 = elem 4 (3 ∷ 2 ∷ 5 ∷ 4 ∷ []) -- true diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Equiv.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Equiv.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,1 @@ +data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x \ No newline at end of file diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Exec.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Exec.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,5 @@ +exec : {l1 l2 : Level} {I : Set l1} {O : Set l2} + {{_ : DataSegment I}} {{_ : DataSegment O}} + -> CodeSegment I O -> Context -> Context +exec {l} {{i}} {{o}} (cs b) c = set o c (b (get i c)) + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Goto.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Goto.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,4 @@ +goto : {l1 l2 : Level} {I : Set l1} {O : Set l2} + -> CodeSegment I O -> I -> O +goto (cs b) i = b i + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Goto.agda.replaced --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Goto.agda.replaced Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,4 @@ +goto : {l1 l2 : Level} {I : Set l1} {O : Set l2} + @$\rightarrow$@ CodeSegment I O @$\rightarrow$@ I @$\rightarrow$@ O +goto (cs b) i = b i + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Maybe.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Maybe.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,3 @@ +data Maybe {a} (A : Set a) : Set a where + just : (x : A) -> Maybe A + nothing : Maybe A diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/MetaCodeSegment.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/MetaCodeSegment.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,4 @@ +data CodeSegment {l1 l2 : Level} (A : Set l1) (B : Set l2) : Set (l ⊔ l1 ⊔ l2) where + cs : {{_ : DataSegment A}} {{_ : DataSegment B}} + -> (A -> B) -> CodeSegment A B + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/MetaDataSegment.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/MetaDataSegment.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +module subtype {l : Level} (Context : Set l) where + +record DataSegment {ll : Level} (A : Set ll) : Set (l ⊔ ll) where + field + get : Context -> A + set : Context -> A -> Context + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/MetaMetaCodeSegment.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/MetaMetaCodeSegment.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,29 @@ +-- meta level +liftContext : {X Y : Set} {{_ : N.DataSegment X}} {{_ : N.DataSegment Y}} -> N.CodeSegment X Y -> N.CodeSegment Context Context +liftContext {{x}} {{y}} (N.cs f) = N.cs (\c -> N.DataSegment.set y c (f (N.DataSegment.get x c))) + +liftMeta : {X Y : Set} {{_ : M.DataSegment X}} {{_ : M.DataSegment Y}} -> N.CodeSegment X Y -> M.CodeSegment X Y +liftMeta (N.cs f) = M.cs f + +gotoMeta : {I O : Set} {{_ : N.DataSegment I}} {{_ : N.DataSegment O}} -> M.CodeSegment Meta Meta -> N.CodeSegment I O -> Meta -> Meta +gotoMeta mCode code m = M.exec mCode (record m {next = (liftContext code)}) + +push : M.CodeSegment Meta Meta +push = M.cs (\m -> M.exec (liftMeta (Meta.next m)) (record m {c' = Context.c (Meta.context m)})) + +-- normal level + +cs2 : N.CodeSegment ds1 ds1 +cs2 = N.cs id + +cs1 : N.CodeSegment ds1 ds1 +cs1 = N.cs (\d -> N.goto cs2 d) + +cs0 : N.CodeSegment ds0 ds1 +cs0 = N.cs (\d -> N.goto cs1 (record {c = (ds0.a d) + (ds0.b d)})) + +-- meta level (with extended normal) +main : Meta +main = gotoMeta push cs0 (record {context = (record {a = 100 ; b = 50 ; c = 70}) ; c' = 0 ; next = (N.cs id)}) +-- record {context = record {a = 100 ; b = 50 ; c = 150} ; c' = 70 ; next = (N.cs id)} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/MetaMetaDataSegment.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/MetaMetaDataSegment.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,12 @@ +-- 上で各 DataSegement の定義を行なっているとする +open import subtype Context as N -- Meta Datasegment を定義 + +-- Meta DataSegment を持つ Meta Meta DataSegment を定義できる +record Meta : Set where + field + context : Context + c' : Int + next : N.CodeSegment Context Context + +open import subtype Meta as M +-- 以下よりメタメタレベルのプログラムを記述できる diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Nat.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Nat.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,5 @@ +module nat where + +data Nat : Set where + O : Nat + S : Nat -> Nat \ No newline at end of file diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/NatAdd.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/NatAdd.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,6 @@ +open import nat +module nat_add where + +_+_ : Nat -> Nat -> Nat +O + m = m +(S n) + m = S (n + m) \ No newline at end of file diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/NatAddSym.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/NatAddSym.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,12 @@ +open import Relation.Binary.PropositionalEquality +open import nat +open import nat_add +open ≡-Reasoning + +module nat_add_sym where + +addSym : (n m : Nat) -> n + m ≡ m + n +addSym O O = refl +addSym O (S m) = cong S (addSym O m) +addSym (S n) O = cong S (addSym n O) +addSym (S n) (S m) = {!!} -- 後述 diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/PushPopType.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/PushPopType.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,9 @@ +pushOnce : Meta -> Meta +pushOnce m = M.exec pushSingleLinkedStackCS m + +popOnce : Meta -> Meta +popOnce m = M.exec popSingleLinkedStackCS m + +push-pop-type : Meta -> Set₁ +push-pop-type meta = + M.exec (M.csComp (M.cs popOnce) (M.cs pushOnce)) meta ≡ meta diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/Reasoning.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/Reasoning.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,21 @@ +open import Relation.Binary.PropositionalEquality +open import nat +open import nat_add +open ≡-Reasoning + +module nat_add_sym_reasoning where + +addToRight : (n m : Nat) -> S (n + m) ≡ n + (S m) +addToRight O m = refl +addToRight (S n) m = cong S (addToRight n m) + +addSym : (n m : Nat) -> n + m ≡ m + n +addSym O O = refl +addSym O (S m) = cong S (addSym O m) +addSym (S n) O = cong S (addSym n O) +addSym (S n) (S m) = begin + (S n) + (S m) ≡⟨ refl ⟩ + S (n + S m) ≡⟨ cong S (addSym n (S m)) ⟩ + S ((S m) + n) ≡⟨ addToRight (S m) n ⟩ + S (m + S n) ≡⟨ refl ⟩ + (S m) + (S n) ∎ diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/RedBlackTree.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/RedBlackTree.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,231 @@ +module RedBlackTree where + +open import stack +open import Level hiding (zero) +record TreeMethods {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where + field + putImpl : treeImpl -> a -> (treeImpl -> t) -> t + getImpl : treeImpl -> (treeImpl -> Maybe a -> t) -> t +open TreeMethods + +record Tree {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where + field + tree : treeImpl + treeMethods : TreeMethods {n} {m} {a} {t} treeImpl + putTree : a -> (Tree treeImpl -> t) -> t + putTree d next = putImpl (treeMethods ) tree d (\t1 -> next (record {tree = t1 ; treeMethods = treeMethods} )) + getTree : (Tree treeImpl -> Maybe a -> t) -> t + getTree next = getImpl (treeMethods ) tree (\t1 d -> next (record {tree = t1 ; treeMethods = treeMethods} ) d ) + +open Tree + +data Color {n : Level } : Set n where + Red : Color + Black : Color + +data CompareResult {n : Level } : Set n where + LT : CompareResult + GT : CompareResult + EQ : CompareResult + +record Node {n : Level } (a k : Set n) : Set n where + inductive + field + key : k + value : a + right : Maybe (Node a k) + left : Maybe (Node a k) + color : Color {n} +open Node + +record RedBlackTree {n m : Level } {t : Set m} (a k : Set n) : Set (m Level.⊔ n) where + field + root : Maybe (Node a k) + nodeStack : SingleLinkedStack (Node a k) + compare : k -> k -> CompareResult {n} + +open RedBlackTree + +open SingleLinkedStack + +-- +-- put new node at parent node, and rebuild tree to the top +-- +{-# TERMINATING #-} -- https://agda.readthedocs.io/en/v2.5.3/language/termination-checking.html +replaceNode : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Node a k -> (RedBlackTree {n} {m} {t} a k -> t) -> t +replaceNode {n} {m} {t} {a} {k} tree s n0 next = popSingleLinkedStack s ( + \s parent -> replaceNode1 s parent) + where + replaceNode1 : SingleLinkedStack (Node a k) -> Maybe ( Node a k ) -> t + replaceNode1 s Nothing = next ( record tree { root = Just (record n0 { color = Black}) } ) + replaceNode1 s (Just n1) with compare tree (key n1) (key n0) + ... | EQ = replaceNode tree s ( record n1 { value = value n0 ; left = left n0 ; right = right n0 } ) next + ... | GT = replaceNode tree s ( record n1 { left = Just n0 } ) next + ... | LT = replaceNode tree s ( record n1 { right = Just n0 } ) next + + +rotateRight : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> + (RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> t) -> t +rotateRight {n} {m} {t} {a} {k} tree s n0 parent rotateNext = getSingleLinkedStack s (\ s n0 -> rotateRight1 tree s n0 parent rotateNext) + where + rotateRight1 : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> + (RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> t) -> t + rotateRight1 {n} {m} {t} {a} {k} tree s n0 parent rotateNext with n0 + ... | Nothing = rotateNext tree s Nothing n0 + ... | Just n1 with parent + ... | Nothing = rotateNext tree s (Just n1 ) n0 + ... | Just parent1 with left parent1 + ... | Nothing = rotateNext tree s (Just n1) Nothing + ... | Just leftParent with compare tree (key n1) (key leftParent) + ... | EQ = rotateNext tree s (Just n1) parent + ... | _ = rotateNext tree s (Just n1) parent + + +rotateLeft : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> + (RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> t) -> t +rotateLeft {n} {m} {t} {a} {k} tree s n0 parent rotateNext = getSingleLinkedStack s (\ s n0 -> rotateLeft1 tree s n0 parent rotateNext) + where + rotateLeft1 : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> + (RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> t) -> t + rotateLeft1 {n} {m} {t} {a} {k} tree s n0 parent rotateNext with n0 + ... | Nothing = rotateNext tree s Nothing n0 + ... | Just n1 with parent + ... | Nothing = rotateNext tree s (Just n1) Nothing + ... | Just parent1 with right parent1 + ... | Nothing = rotateNext tree s (Just n1) Nothing + ... | Just rightParent with compare tree (key n1) (key rightParent) + ... | EQ = rotateNext tree s (Just n1) parent + ... | _ = rotateNext tree s (Just n1) parent + +{-# TERMINATING #-} +insertCase5 : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Node a k -> Node a k -> (RedBlackTree {n} {m} {t} a k -> t) -> t +insertCase5 {n} {m} {t} {a} {k} tree s n0 parent grandParent next = pop2SingleLinkedStack s (\ s parent grandParent -> insertCase51 tree s n0 parent grandParent next) + where + insertCase51 : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> (RedBlackTree {n} {m} {t} a k -> t) -> t + insertCase51 {n} {m} {t} {a} {k} tree s n0 parent grandParent next with n0 + ... | Nothing = next tree + ... | Just n1 with parent | grandParent + ... | Nothing | _ = next tree + ... | _ | Nothing = next tree + ... | Just parent1 | Just grandParent1 with left parent1 | left grandParent1 + ... | Nothing | _ = next tree + ... | _ | Nothing = next tree + ... | Just leftParent1 | Just leftGrandParent1 + with compare tree (key n1) (key leftParent1) | compare tree (key leftParent1) (key leftGrandParent1) + ... | EQ | EQ = rotateRight tree s n0 parent + (\ tree s n0 parent -> insertCase5 tree s n0 parent1 grandParent1 next) + ... | _ | _ = rotateLeft tree s n0 parent + (\ tree s n0 parent -> insertCase5 tree s n0 parent1 grandParent1 next) + +insertCase4 : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Node a k -> Node a k -> Node a k -> (RedBlackTree {n} {m} {t} a k -> t) -> t +insertCase4 {n} {m} {t} {a} {k} tree s n0 parent grandParent next + with (right parent) | (left grandParent) +... | Nothing | _ = insertCase5 tree s (Just n0) parent grandParent next +... | _ | Nothing = insertCase5 tree s (Just n0) parent grandParent next +... | Just rightParent | Just leftGrandParent with compare tree (key n0) (key rightParent) | compare tree (key parent) (key leftGrandParent) +... | EQ | EQ = popSingleLinkedStack s (\ s n1 -> rotateLeft tree s (left n0) (Just grandParent) + (\ tree s n0 parent -> insertCase5 tree s n0 rightParent grandParent next)) +... | _ | _ = insertCase41 tree s n0 parent grandParent next + where + insertCase41 : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Node a k -> Node a k -> Node a k -> (RedBlackTree {n} {m} {t} a k -> t) -> t + insertCase41 {n} {m} {t} {a} {k} tree s n0 parent grandParent next + with (left parent) | (right grandParent) + ... | Nothing | _ = insertCase5 tree s (Just n0) parent grandParent next + ... | _ | Nothing = insertCase5 tree s (Just n0) parent grandParent next + ... | Just leftParent | Just rightGrandParent with compare tree (key n0) (key leftParent) | compare tree (key parent) (key rightGrandParent) + ... | EQ | EQ = popSingleLinkedStack s (\ s n1 -> rotateRight tree s (right n0) (Just grandParent) + (\ tree s n0 parent -> insertCase5 tree s n0 leftParent grandParent next)) + ... | _ | _ = insertCase5 tree s (Just n0) parent grandParent next + +colorNode : {n : Level } {a k : Set n} -> Node a k -> Color -> Node a k +colorNode old c = record old { color = c } + +{-# TERMINATING #-} +insertNode : {n m : Level } {t : Set m } {a k : Set n} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Node a k -> (RedBlackTree {n} {m} {t} a k -> t) -> t +insertNode {n} {m} {t} {a} {k} tree s n0 next = get2SingleLinkedStack s (insertCase1 n0) + where + insertCase1 : Node a k -> SingleLinkedStack (Node a k) -> Maybe (Node a k) -> Maybe (Node a k) -> t -- placed here to allow mutual recursion + -- http://agda.readthedocs.io/en/v2.5.2/language/mutual-recursion.html + insertCase3 : SingleLinkedStack (Node a k) -> Node a k -> Node a k -> Node a k -> t + insertCase3 s n0 parent grandParent with left grandParent | right grandParent + ... | Nothing | Nothing = insertCase4 tree s n0 parent grandParent next + ... | Nothing | Just uncle = insertCase4 tree s n0 parent grandParent next + ... | Just uncle | _ with compare tree ( key uncle ) ( key parent ) + ... | EQ = insertCase4 tree s n0 parent grandParent next + ... | _ with color uncle + ... | Red = pop2SingleLinkedStack s ( \s p0 p1 -> insertCase1 ( + record grandParent { color = Red ; left = Just ( record parent { color = Black } ) ; right = Just ( record uncle { color = Black } ) }) s p0 p1 ) + ... | Black = insertCase4 tree s n0 parent grandParent next + insertCase2 : SingleLinkedStack (Node a k) -> Node a k -> Node a k -> Node a k -> t + insertCase2 s n0 parent grandParent with color parent + ... | Black = replaceNode tree s n0 next + ... | Red = insertCase3 s n0 parent grandParent + insertCase1 n0 s Nothing Nothing = next tree + insertCase1 n0 s Nothing (Just grandParent) = next tree + insertCase1 n0 s (Just parent) Nothing = replaceNode tree s (colorNode n0 Black) next + insertCase1 n0 s (Just parent) (Just grandParent) = insertCase2 s n0 parent grandParent + +---- +-- find node potition to insert or to delete, the path will be in the stack +-- +findNode : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> (Node a k) -> (Node a k) -> (RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Node a k -> t) -> t +findNode {n} {m} {a} {k} {t} tree s n0 n1 next = pushSingleLinkedStack s n1 (\ s -> findNode1 s n1) + where + findNode2 : SingleLinkedStack (Node a k) -> (Maybe (Node a k)) -> t + findNode2 s Nothing = next tree s n0 + findNode2 s (Just n) = findNode tree s n0 n next + findNode1 : SingleLinkedStack (Node a k) -> (Node a k) -> t + findNode1 s n1 with (compare tree (key n0) (key n1)) + ... | EQ = popSingleLinkedStack s ( \s _ -> next tree s (record n1 { key = key n1 ; value = value n0 } ) ) + ... | GT = findNode2 s (right n1) + ... | LT = findNode2 s (left n1) + + +leafNode : {n : Level } {a k : Set n} -> k -> a -> Node a k +leafNode k1 value = record { + key = k1 ; + value = value ; + right = Nothing ; + left = Nothing ; + color = Red + } + +putRedBlackTree : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> k -> a -> (RedBlackTree {n} {m} {t} a k -> t) -> t +putRedBlackTree {n} {m} {a} {k} {t} tree k1 value next with (root tree) +... | Nothing = next (record tree {root = Just (leafNode k1 value) }) +... | Just n2 = clearSingleLinkedStack (nodeStack tree) (\ s -> findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 -> insertNode tree1 s n1 next)) + +getRedBlackTree : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> k -> (RedBlackTree {n} {m} {t} a k -> (Maybe (Node a k)) -> t) -> t +getRedBlackTree {_} {_} {a} {k} {t} tree k1 cs = checkNode (root tree) + module GetRedBlackTree where -- http://agda.readthedocs.io/en/v2.5.2/language/let-and-where.html + search : Node a k -> t + checkNode : Maybe (Node a k) -> t + checkNode Nothing = cs tree Nothing + checkNode (Just n) = search n + search n with compare tree k1 (key n) + search n | LT = checkNode (left n) + search n | GT = checkNode (right n) + search n | EQ = cs tree (Just n) + +open import Data.Nat hiding (compare) + +compareℕ : ℕ → ℕ → CompareResult {Level.zero} +compareℕ x y with Data.Nat.compare x y +... | less _ _ = LT +... | equal _ = EQ +... | greater _ _ = GT + +compare2 : (x y : ℕ ) -> CompareResult {Level.zero} +compare2 zero zero = EQ +compare2 (suc _) zero = GT +compare2 zero (suc _) = LT +compare2 (suc x) (suc y) = compare2 x y + + +createEmptyRedBlackTreeℕ : { m : Level } (a : Set Level.zero) {t : Set m} -> RedBlackTree {Level.zero} {m} {t} a ℕ +createEmptyRedBlackTreeℕ {m} a {t} = record { + root = Nothing + ; nodeStack = emptySingleLinkedStack + ; compare = compare2 + } + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/RedBlackTree.agdai Binary file final_pre/src/RedBlackTree.agdai has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/SingleLinkedStack.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/SingleLinkedStack.cbc Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,110 @@ +#include "../context.h" +#include "../origin_cs.h" +#include + +// typedef struct SingleLinkedStack { +// struct Element* top; +// } SingleLinkedStack; + +Stack* createSingleLinkedStack(struct Context* context) { + struct Stack* stack = new Stack(); + struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); + stack->stack = (union Data*)singleLinkedStack; + singleLinkedStack->top = NULL; + stack->push = C_pushSingleLinkedStack; + stack->pop = C_popSingleLinkedStack; + stack->pop2 = C_pop2SingleLinkedStack; + stack->get = C_getSingleLinkedStack; + stack->get2 = C_get2SingleLinkedStack; + stack->isEmpty = C_isEmptySingleLinkedStack; + stack->clear = C_clearSingleLinkedStack; + return stack; +} + +void printStack1(union Data* data) { + struct Node* node = &data->Element.data->Node; + if (node == NULL) { + printf("NULL"); + } else { + printf("key = %d ,", node->key); + printStack1((union Data*)data->Element.next); + } +} + +void printStack(union Data* data) { + printStack1(data); + printf("\n"); +} + +__code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) { + stack->top = NULL; + goto next(...); +} + +__code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { + Element* element = new Element(); + element->next = stack->top; + element->data = data; + stack->top = element; + goto next(...); +} + +__code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) { + if (stack->top) { + data = stack->top->data; + stack->top = stack->top->next; + } else { + data = NULL; + } + goto next(data, ...); +} + +__code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) { + if (stack->top) { + data = stack->top->data; + stack->top = stack->top->next; + } else { + data = NULL; + } + if (stack->top) { + data1 = stack->top->data; + stack->top = stack->top->next; + } else { + data1 = NULL; + } + goto next(data, data1, ...); +} + + +__code getSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) { + if (stack->top) + data = stack->top->data; + else + data = NULL; + goto next(data, ...); +} + +__code get2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) { + if (stack->top) { + data = stack->top->data; + if (stack->top->next) { + data1 = stack->top->next->data; + } else { + data1 = NULL; + } + } else { + data = NULL; + data1 = NULL; + } + goto next(data, data1, ...); +} + +__code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { + if (stack->top) + goto next(...); + else + goto whenEmpty(...); +} + + + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/SingleLinkedStack.cbc.replace --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/SingleLinkedStack.cbc.replace Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,16 @@ +__code pushSingleLinkedStack(struct Single LinkedStack* stack,union Data* data, __code next(...)) { + Element* element = new Element(); + element->next = stack->top; + element->data = data; + stack->top = element; + goto next(...); +} +__code popSingleLinkedStack(struct Single LinkedStack* stack, __code next(union Data* data, ...)) { + if (stack->top) { + data = stack->top->data; + stack->top = stack->top->next; + } else { + data = NULL; + } + goto next(data, ...); +} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/ThreePlusOne.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/ThreePlusOne.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,8 @@ +open import Relation.Binary.PropositionalEquality +open import nat +open import nat_add + +module three_plus_one where + +3+1 : (S (S (S O))) + (S O) ≡ (S (S (S (S O)))) +3+1 = refl \ No newline at end of file diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/akashaContext.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/akashaContext.h Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,31 @@ +// Data Segment +union Data { + struct Tree { /* ... 赤黒木の定義と同様 */ } tree; + struct Node { /* ... 赤黒木の定義と同様 */ } node; + + /* for verification */ + struct IterElem { + unsigned int val; + struct IterElem* next; + } iterElem; + struct Iterator { + struct Tree* tree; + struct Iterator* previousDepth; + struct IterElem* head; + struct IterElem* last; + unsigned int iteratedValue; + unsigned long iteratedPointDataNum; + void* iteratedPointHeap; + } iterator; + struct AkashaInfo { + unsigned int minHeight; + unsigned int maxHeight; + struct AkashaNode* akashaNode; + } akashaInfo; + struct AkashaNode { + unsigned int height; + struct Node* node; + struct AkashaNode* nextAkashaNode; + } akashaNode; +}; + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/akashaMeta.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/akashaMeta.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,31 @@ +__code meta(struct Context* context, enum Code next) { + struct Iterator* iter = &context->data[Iter]->iterator; + + switch (context->prev) { + case GoToPreviousDepth: + if (iter->iteratedPointDataNum == 0) break; + if (iter->iteratedPointHeap == NULL) break; + + unsigned int diff =(unsigned long)context->heap - (unsigned long)iter->iteratedPointHeap; + memset(iter->iteratedPointHeap, 0, diff); + context->dataNum = iter->iteratedPointDataNum; + context->heap = iter->iteratedPointHeap; + break; + default: + break; + } + switch (next) { + case PutAndGoToNextDepth: // with assert check + if (context->prev == GoToPreviousDepth) break; + if (iter->previousDepth == NULL) break; + iter->previousDepth->iteratedPointDataNum = context->dataNum; + iter->previousDepth->iteratedPointHeap = context->heap; + break; + default: + break; + } + + context->prev = next; + goto (context->code[next])(context); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/assert.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/assert.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +__code verifySpecificationFinish(struct Context* context) { + if (context->data[AkashaInfo]->akashaInfo.maxHeight > 2*context->data[AkashaInfo]->akashaInfo.minHeight) { + context->next = Exit; + goto meta(context, ShowTrace); + } + goto meta(context, DuplicateIterator); +} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/atton-master-meta-sample.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/atton-master-meta-sample.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,77 @@ +module atton-master-meta-sample where + +open import Data.Nat +open import Data.Unit +open import Function +Int = ℕ + +record Context : Set where + field + a : Int + b : Int + c : Int + +open import subtype Context as N + +record Meta : Set where + field + context : Context + c' : Int + next : N.CodeSegment Context Context + +open import subtype Meta as M + +instance + _ : N.DataSegment Context + _ = record { get = id ; set = (\_ c -> c) } + _ : M.DataSegment Context + _ = record { get = (\m -> Meta.context m) ; + set = (\m c -> record m {context = c}) } + _ : M.DataSegment Meta + _ = record { get = id ; set = (\_ m -> m) } + + +liftContext : {X Y : Set} {{_ : N.DataSegment X}} {{_ : N.DataSegment Y}} -> N.CodeSegment X Y -> N.CodeSegment Context Context +liftContext {{x}} {{y}} (N.cs f) = N.cs (\c -> N.DataSegment.set y c (f (N.DataSegment.get x c))) + +liftMeta : {X Y : Set} {{_ : M.DataSegment X}} {{_ : M.DataSegment Y}} -> N.CodeSegment X Y -> M.CodeSegment X Y +liftMeta (N.cs f) = M.cs f + + +gotoMeta : {I O : Set} {{_ : N.DataSegment I}} {{_ : N.DataSegment O}} -> M.CodeSegment Meta Meta -> N.CodeSegment I O -> Meta -> Meta +gotoMeta mCode code m = M.exec mCode (record m {next = (liftContext code)}) + +push : M.CodeSegment Meta Meta +push = M.cs (\m -> M.exec (liftMeta (Meta.next m)) (record m {c' = Context.c (Meta.context m)})) + + +record ds0 : Set where + field + a : Int + b : Int + +record ds1 : Set where + field + c : Int + +instance + _ : N.DataSegment ds0 + _ = record { set = (\c d -> record c {a = (ds0.a d) ; b = (ds0.b d)}) + ; get = (\c -> record { a = (Context.a c) ; b = (Context.b c)})} + _ : N.DataSegment ds1 + _ = record { set = (\c d -> record c {c = (ds1.c d)}) + ; get = (\c -> record { c = (Context.c c)})} + +cs2 : N.CodeSegment ds1 ds1 +cs2 = N.cs id + +cs1 : N.CodeSegment ds1 ds1 +cs1 = N.cs (\d -> N.goto cs2 d) + +cs0 : N.CodeSegment ds0 ds1 +cs0 = N.cs (\d -> N.goto cs1 (record {c = (ds0.a d) + (ds0.b d)})) + + +main : Meta +main = gotoMeta push cs0 (record {context = (record {a = 100 ; b = 50 ; c = 70}) ; c' = 0 ; next = (N.cs id)}) +-- record {context = record {a = 100 ; b = 50 ; c = 150} ; c' = 70 ; next = (N.cs id)} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/atton-master-sample.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/atton-master-sample.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,46 @@ +module atton-master-sample where + +open import Data.Nat +open import Data.Unit +open import Function +Int = ℕ + +record Context : Set where + field + a : Int + b : Int + c : Int + + +open import subtype Context + + + +record ds0 : Set where + field + a : Int + b : Int + +record ds1 : Set where + field + c : Int + +instance + _ : DataSegment ds0 + _ = record { set = (\c d -> record c {a = (ds0.a d) ; b = (ds0.b d)}) + ; get = (\c -> record { a = (Context.a c) ; b = (Context.b c)})} + _ : DataSegment ds1 + _ = record { set = (\c d -> record c {c = (ds1.c d)}) + ; get = (\c -> record { c = (Context.c c)})} + +cs2 : CodeSegment ds1 ds1 +cs2 = cs id + +cs1 : CodeSegment ds1 ds1 +cs1 = cs (\d -> goto cs2 d) + +cs0 : CodeSegment ds0 ds1 +cs0 = cs (\d -> goto cs1 (record {c = (ds0.a d) + (ds0.b d)})) + +main : ds1 +main = goto cs0 (record {a = 100 ; b = 50}) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/cbmc-assert.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/cbmc-assert.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +void verifySpecification(struct Context* context, + struct Tree* tree) { + assert(!(maxHeight(tree->root, 1) > + 2*minHeight(tree->root, 1))); + return meta(context, EnumerateInputs); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/context.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/context.h Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,47 @@ +/* Context definition */ + +#define ALLOCATE_SIZE 1024 + +enum Code { + Code1, + Code2, + Allocator, +}; + +enum UniqueData { + Allocate, + Tree, +}; + +struct Context { + int codeNum; + __code (**code) (struct Context *); + void* heap_start; + void* heap; + long dataSize; + int dataNum; + union Data **data; +}; + +union Data { + struct Tree { + union Data* root; + union Data* current; + union Data* prev; + int result; + } tree; + struct Node { + int key; + int value; + enum Color { + Red, + Black, + } color; + union Data* left; + union Data* right; + } node; + struct Allocate { + long size; + enum Code next; + } allocate; +}; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/csds.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/csds.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,20 @@ +record ds0 : Set where +field +a : Int +b : Int + +record ds1 : Set where +field +c : Int + +cs2 : CodeSegment ds1 ds1 +cs2 = cs id + +cs1 : CodeSegment ds1 ds1 +cs1 = cs (\d -> goto cs2 d) + +cs0 : CodeSegment ds0 ds1 +cs0 = cs (\d -> goto cs1 (record {c = (ds0.a d) + (ds0.b d)})) + +main : ds1 +main = goto cs0 (record {a = 100 ; b = 50}) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/enumerate-inputs.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/enumerate-inputs.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,13 @@ +void enumerateInputs(struct Context* context, + struct Node* node) { + if (context->loopCount > LIMIT_OF_VERIFICATION_SIZE) { + return meta(context, Exit); + } + + node->key = nondet_int(); + node->value = node->key; + context->next = VerifySpecification; + context->loopCount++; + + return meta(context, Put); +} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/escape_agda.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/escape_agda.rb Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby +# coding: utf-8 + +Suffix = '.agda.replaced' +EscapeChar = '@' +FileName = ARGV.first + +ReplaceTable = { + '->' => 'rightarrow', + '⊔' => 'sqcup', + '∷' => 'text{::}', + '∙' => 'circ', + '≡' => 'equiv', + '×' => 'times', + '⟨' => 'langle', + '⟩' => 'rangle', + '₁' => 'text{1}', + 'ℕ' => 'mathbb{N}', + '∎' => 'blacksquare' +} + +code = File.read(FileName) +ReplaceTable.each do |k, v| + escaped_str = EscapeChar + "$\\#{v}$" + EscapeChar + code = code.gsub(k, escaped_str) +end + +File.write(FileName.sub(/.agda$/, Suffix), code) diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/expr-term.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/expr-term.txt Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,8 @@ +t ::= + true + false + if t then t else t + 0 + succ t + pred t + iszero t diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/factrial.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/factrial.cbc Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,29 @@ +__code print_factorial(int prod) +{ + printf("factorial = %d\n", prod); + exit(0); +} + +__code factorial0(int prod, int x) +{ + if (x >= 1) { + goto factorial0(prod*x, x-1); + } else { + goto print_factorial(prod); + } + +} + +__code factorial(int x) +{ + goto factorial0(1, x); +} + +int main(int argc, char **argv) +{ + int i; + i = atoi(argv[1]); + + goto factorial(i); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/getMinHeight.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/getMinHeight.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,51 @@ +__code getMinHeight_stub(struct Context* context) { + goto getMinHeight(context, &context->data[Allocate]->allocate, &context->data[AkashaInfo]->akashaInfo); +} + +__code getMinHeight(struct Context* context, struct Allocate* allocate, struct AkashaInfo* akashaInfo) { + const struct AkashaNode* akashaNode = akashaInfo->akashaNode; + + if (akashaNode == NULL) { + allocate->size = sizeof(struct AkashaNode); + allocator(context); + akashaInfo->akashaNode = (struct AkashaNode*)context->data[context->dataNum]; + + akashaInfo->akashaNode->height = 1; + akashaInfo->akashaNode->node = context->data[Tree]->tree.root; + + goto getMaxHeight_stub(context); + } + + const struct Node* node = akashaInfo->akashaNode->node; + if (node->left == NULL && node->right == NULL) { + if (akashaInfo->minHeight > akashaNode->height) { + akashaInfo->minHeight = akashaNode->height; + akashaInfo->akashaNode = akashaNode->nextAkashaNode; + goto getMinHeight_stub(context); + } + } + + akashaInfo->akashaNode = akashaInfo->akashaNode->nextAkashaNode; + + if (node->left != NULL) { + allocate->size = sizeof(struct AkashaNode); + allocator(context); + struct AkashaNode* left = (struct AkashaNode*)context->data[context->dataNum]; + left->height = akashaNode->height+1; + left->node = node->left; + left->nextAkashaNode = akashaInfo->akashaNode; + akashaInfo->akashaNode = left; + } + + if (node->right != NULL) { + allocate->size = sizeof(struct AkashaNode); + allocator(context); + struct AkashaNode* right = (struct AkashaNode*)context->data[context->dataNum]; + right->height = akashaNode->height+1; + right->node = node->right; + right->nextAkashaNode = akashaInfo->akashaNode; + akashaInfo->akashaNode = right; + } + + goto getMinHeight_stub(context); +} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/goto.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/goto.cbc Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +__code cs0(int a, int b){ + goto cs1(a+b); +} + +__code cs1(int c){ + goto cs2(c); +} diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/initLLRBContext.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/initLLRBContext.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,53 @@ +__code initLLRBContext(struct Context* context, int num) { + context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; + context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); + context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); + context->heapStart = malloc(context->heapLimit); + + context->codeNum = Exit; + + context->code[Code1] = code1_stub; + context->code[Code2] = code2_stub; + context->code[Code3] = code3_stub; + context->code[Code4] = code4; + context->code[Code5] = code5; + context->code[Find] = find; + context->code[Not_find] = not_find; + context->code[Code6] = code6; + context->code[Put] = put_stub; + context->code[Replace] = replaceNode_stub; + context->code[Insert] = insertNode_stub; + context->code[RotateL] = rotateLeft_stub; + context->code[RotateR] = rotateRight_stub; + context->code[InsertCase1] = insert1_stub; + context->code[InsertCase2] = insert2_stub; + context->code[InsertCase3] = insert3_stub; + context->code[InsertCase4] = insert4_stub; + context->code[InsertCase4_1] = insert4_1_stub; + context->code[InsertCase4_2] = insert4_2_stub; + context->code[InsertCase5] = insert5_stub; + context->code[StackClear] = stackClear_stub; + context->code[Exit] = exit_code; + + context->heap = context->heapStart; + + context->data[Allocate] = context->heap; + context->heap += sizeof(struct Allocate); + + context->data[Tree] = context->heap; + context->heap += sizeof(struct Tree); + + context->data[Node] = context->heap; + context->heap += sizeof(struct Node); + + context->dataNum = Node; + + struct Tree* tree = &context->data[Tree]->tree; + tree->root = 0; + tree->current = 0; + tree->deleted = 0; + + context->node_stack = stack_init(sizeof(struct Node*), 100); + context->code_stack = stack_init(sizeof(enum Code), 100); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/insertCase2.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/insertCase2.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,17 @@ +__code insertCase2(struct Context* context, struct Node* current) { + struct Node* parent; + stack_pop(context->node_stack, &parent); + + if (parent->color == Black) { + stack_pop(context->code_stack, &context->next); + goto meta(context, context->next); + } + + stack_push(context->node_stack, &parent); + goto meta(context, InsertCase3); +} + +__code insert2_stub(struct Context* context) { + goto insertCase2(context, context->data[Tree]->tree.current); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/interface.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/interface.cbc Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,12 @@ +typedef struct Stack{ + union Data* stack; + union Data* data; + union Data* data1; + + __code whenEmpty(...); + __code clear(Impl* stack,__code next(...)); + __code push(Impl* stack,Type* data, __code next(...)); + __code pop(Impl* stack, __code next(Type* data, ...)); + /* 途中省略 */ + __code next(...); +} Stack; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/meta.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/meta.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,4 @@ +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/push-pop.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/push-pop.cbc Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,32 @@ + __code pushSingleLinkedStack(struct Single LinkedStack* stack,union Data* data, __code next(...)) { + Element* element = new Element(); + element->next = stack->top; + element->data = data; + stack->top = element; + goto next(...); +} + __code popSingleLinkedStack(struct Single LinkedStack* stack, __code next(union Data* data, ...)) { + if (stack->top) { + data = stack->top->data; + stack->top = stack->top->next; + } else { + data = NULL; + } + goto next(data, ...); +} + +__code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) { + if (stack->top) { + data = stack->top->data; + stack->top = stack->top->next; + } else { + data = NULL; + } + if (stack->top) { + data1 = stack->top->data; + stack->top = stack->top->next; + } else { + data1 = NULL; + } + goto next(data, data1, ...); +} \ No newline at end of file diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/rbtreeContext.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/rbtreeContext.h Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,50 @@ +// DataSegments for Red-Black Tree +union Data { + struct Comparable { // interface + enum Code compare; + union Data* data; + } compare; + struct Count { + enum Code next; + long i; + } count; + struct Tree { + enum Code next; + struct Node* root; + struct Node* current; + struct Node* deleted; + int result; + } tree; + struct Node { + // need to tree + enum Code next; + int key; // comparable data segment + int value; + struct Node* left; + struct Node* right; + // need to balancing + enum Color { + Red, + Black, + } color; + } node; + struct Allocate { + enum Code next; + long size; + } allocate; +}; + + +// Meta DataSegment +struct Context { + enum Code next; + int codeNum; + __code (**code) (struct Context*); + void* heapStart; + void* heap; + long heapLimit; + int dataNum; + stack_ptr code_stack; + stack_ptr node_stack; + union Data **data; +}; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/redBlackTreeTest.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/redBlackTreeTest.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,196 @@ +module redBlackTreeTest where + +open import RedBlackTree +open import stack +open import Level hiding (zero) + +open import Data.Nat + +open Tree +open Node +open RedBlackTree.RedBlackTree +open Stack + +-- tests + +putTree1 : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> k -> a -> (RedBlackTree {n} {m} {t} a k -> t) -> t +putTree1 {n} {m} {a} {k} {t} tree k1 value next with (root tree) +... | Nothing = next (record tree {root = Just (leafNode k1 value) }) +... | Just n2 = clearSingleLinkedStack (nodeStack tree) (\ s -> findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 -> replaceNode tree1 s n1 next)) + +open import Relation.Binary.PropositionalEquality +open import Relation.Binary.Core +open import Function + + +check1 : {m : Level } (n : Maybe (Node ℕ ℕ)) -> ℕ -> Bool {m} +check1 Nothing _ = False +check1 (Just n) x with Data.Nat.compare (value n) x +... | equal _ = True +... | _ = False + +check2 : {m : Level } (n : Maybe (Node ℕ ℕ)) -> ℕ -> Bool {m} +check2 Nothing _ = False +check2 (Just n) x with compare2 (value n) x +... | EQ = True +... | _ = False + +test1 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( \t -> getRedBlackTree t 1 ( \t x -> check2 x 1 ≡ True )) +test1 = refl + +test2 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( + \t -> putTree1 t 2 2 ( + \t -> getRedBlackTree t 1 ( + \t x -> check2 x 1 ≡ True ))) +test2 = refl + +open ≡-Reasoning +test3 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero}) 1 1 + $ \t -> putTree1 t 2 2 + $ \t -> putTree1 t 3 3 + $ \t -> putTree1 t 4 4 + $ \t -> getRedBlackTree t 1 + $ \t x -> check2 x 1 ≡ True +test3 = begin + check2 (Just (record {key = 1 ; value = 1 ; color = Black ; left = Nothing ; right = Just (leafNode 2 2)})) 1 + ≡⟨ refl ⟩ + True + ∎ + +test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 + $ \t -> putTree1 t 2 2 + $ \t -> putTree1 t 3 3 + $ \t -> putTree1 t 4 4 + $ \t -> getRedBlackTree t 4 + $ \t x -> x + +-- test5 : Maybe (Node ℕ ℕ) +test5 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 4 4 + $ \t -> putTree1 t 6 6 + $ \t0 -> clearSingleLinkedStack (nodeStack t0) + $ \s -> findNode1 t0 s (leafNode 3 3) ( root t0 ) + $ \t1 s n1 -> replaceNode t1 s n1 + $ \t -> getRedBlackTree t 3 + -- $ \t x -> SingleLinkedStack.top (stack s) + -- $ \t x -> n1 + $ \t x -> root t + where + findNode1 : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> (Node a k) -> (Maybe (Node a k)) -> (RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Node a k -> t) -> t + findNode1 t s n1 Nothing next = next t s n1 + findNode1 t s n1 ( Just n2 ) next = findNode t s n1 n2 next + +-- test51 : putTree1 {_} {_} {ℕ} {ℕ} {_} {Maybe (Node ℕ ℕ)} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ \t -> +-- putTree1 t 2 2 $ \t -> putTree1 t 3 3 $ \t -> root t ≡ Just (record { key = 1; value = 1; left = Just (record { key = 2 ; value = 2 } ); right = Nothing} ) +-- test51 = refl + +test6 : Maybe (Node ℕ ℕ) +test6 = root (createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)}) + + +test7 : Maybe (Node ℕ ℕ) +test7 = clearSingleLinkedStack (nodeStack tree2) (\ s -> replaceNode tree2 s n2 (\ t -> root t)) + where + tree2 = createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)} + k1 = 1 + n2 = leafNode 0 0 + value1 = 1 + +test8 : Maybe (Node ℕ ℕ) +test8 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 + $ \t -> putTree1 t 2 2 (\ t -> root t) + + +test9 : putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( \t -> getRedBlackTree t 1 ( \t x -> check2 x 1 ≡ True )) +test9 = refl + +test10 : putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( + \t -> putRedBlackTree t 2 2 ( + \t -> getRedBlackTree t 1 ( + \t x -> check2 x 1 ≡ True ))) +test10 = refl + +test11 = putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 + $ \t -> putRedBlackTree t 2 2 + $ \t -> putRedBlackTree t 3 3 + $ \t -> getRedBlackTree t 2 + $ \t x -> root t + + +redBlackInSomeState : { m : Level } (a : Set Level.zero) (n : Maybe (Node a ℕ)) {t : Set m} -> RedBlackTree {Level.zero} {m} {t} a ℕ +redBlackInSomeState {m} a n {t} = record { root = n ; nodeStack = emptySingleLinkedStack ; compare = compare2 } + +-- compare2 : (x y : ℕ ) -> compareresult +-- compare2 zero zero = eq +-- compare2 (suc _) zero = gt +-- compare2 zero (suc _) = lt +-- compare2 (suc x) (suc y) = compare2 x y + +putTest1Lemma2 : (k : ℕ) -> compare2 k k ≡ EQ +putTest1Lemma2 zero = refl +putTest1Lemma2 (suc k) = putTest1Lemma2 k + +putTest1Lemma1 : (x y : ℕ) -> compareℕ x y ≡ compare2 x y +putTest1Lemma1 zero zero = refl +putTest1Lemma1 (suc m) zero = refl +putTest1Lemma1 zero (suc n) = refl +putTest1Lemma1 (suc m) (suc n) with Data.Nat.compare m n +putTest1Lemma1 (suc .m) (suc .(Data.Nat.suc m + k)) | less m k = lemma1 m + where + lemma1 : (m : ℕ) -> LT ≡ compare2 m (ℕ.suc (m + k)) + lemma1 zero = refl + lemma1 (suc y) = lemma1 y +putTest1Lemma1 (suc .m) (suc .m) | equal m = lemma1 m + where + lemma1 : (m : ℕ) -> EQ ≡ compare2 m m + lemma1 zero = refl + lemma1 (suc y) = lemma1 y +putTest1Lemma1 (suc .(Data.Nat.suc m + k)) (suc .m) | greater m k = lemma1 m + where + lemma1 : (m : ℕ) -> GT ≡ compare2 (ℕ.suc (m + k)) m + lemma1 zero = refl + lemma1 (suc y) = lemma1 y + +putTest1Lemma3 : (k : ℕ) -> compareℕ k k ≡ EQ +putTest1Lemma3 k = trans (putTest1Lemma1 k k) ( putTest1Lemma2 k ) + +compareLemma1 : {x y : ℕ} -> compare2 x y ≡ EQ -> x ≡ y +compareLemma1 {zero} {zero} refl = refl +compareLemma1 {zero} {suc _} () +compareLemma1 {suc _} {zero} () +compareLemma1 {suc x} {suc y} eq = cong ( \z -> ℕ.suc z ) ( compareLemma1 ( trans lemma2 eq ) ) + where + lemma2 : compare2 (ℕ.suc x) (ℕ.suc y) ≡ compare2 x y + lemma2 = refl + + +putTest1 :{ m : Level } (n : Maybe (Node ℕ ℕ)) + -> (k : ℕ) (x : ℕ) + -> putTree1 {_} {_} {ℕ} {ℕ} (redBlackInSomeState {_} ℕ n {Set Level.zero}) k x + (\ t -> getRedBlackTree t k (\ t x1 -> check2 x1 x ≡ True)) +putTest1 n k x with n +... | Just n1 = lemma2 ( record { top = Nothing } ) + where + lemma2 : (s : SingleLinkedStack (Node ℕ ℕ) ) -> putTree1 (record { root = Just n1 ; nodeStack = s ; compare = compare2 }) k x (λ t → + GetRedBlackTree.checkNode t k (λ t₁ x1 → check2 x1 x ≡ True) (root t)) + lemma2 s with compare2 k (key n1) + ... | EQ = lemma3 {!!} + where + lemma3 : compare2 k (key n1) ≡ EQ -> getRedBlackTree {_} {_} {ℕ} {ℕ} {Set Level.zero} ( record { root = Just ( record { + key = key n1 ; value = x ; right = right n1 ; left = left n1 ; color = Black + } ) ; nodeStack = s ; compare = λ x₁ y → compare2 x₁ y } ) k ( \ t x1 -> check2 x1 x ≡ True) + lemma3 eq with compare2 x x | putTest1Lemma2 x + ... | EQ | refl with compare2 k (key n1) | eq + ... | EQ | refl with compare2 x x | putTest1Lemma2 x + ... | EQ | refl = refl + ... | GT = {!!} + ... | LT = {!!} + +... | Nothing = lemma1 + where + lemma1 : getRedBlackTree {_} {_} {ℕ} {ℕ} {Set Level.zero} ( record { root = Just ( record { + key = k ; value = x ; right = Nothing ; left = Nothing ; color = Red + } ) ; nodeStack = record { top = Nothing } ; compare = λ x₁ y → compare2 x₁ y } ) k + ( \ t x1 -> check2 x1 x ≡ True) + lemma1 with compare2 k k | putTest1Lemma2 k + ... | EQ | refl with compare2 x x | putTest1Lemma2 x + ... | EQ | refl = refl diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/singleLinkedStack.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/singleLinkedStack.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,18 @@ +__code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { + Element* element = new Element(); + element->next = stack->top; + element->data = data; + stack->top = element; + goto next(...); +} + +__code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) { + if (stack->top) { + data = stack->top->data; + stack->top = stack->top->next; + } else { + data = NULL; + } + goto next(data, ...); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/singleLinkedStackInterface.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/singleLinkedStackInterface.cbc Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,10 @@ +Stack* createSingleLinkedStack(struct Context* context) { + struct Stack* stack = new Stack(); + struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); + stack->stack = (union Data*)singleLinkedStack; + singleLinkedStack->top = NULL; + stack->push = C_pushSingleLinkedStack; + stack->pop = C_popSingleLinkedStack; + /* 途中省略 */ + return stack; +} \ No newline at end of file diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack-product.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stack-product.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,158 @@ +module stack-product where + +open import product +open import Data.Product +open import Data.Nat +open import Function using (id) +open import Relation.Binary.PropositionalEquality + +-- definition based from Gears(209:5708390a9d88) src/parallel_execution +goto = executeCS + +data Bool : Set where + True : Bool + False : Bool + +data Maybe (a : Set) : Set where + Nothing : Maybe a + Just : a -> Maybe a + + +record Stack {a t : Set} (stackImpl : Set) : Set where + field + stack : stackImpl + push : CodeSegment (stackImpl × a × (CodeSegment stackImpl t)) t + pop : CodeSegment (stackImpl × (CodeSegment (stackImpl × Maybe a) t)) t + + +data Element (a : Set) : Set where + cons : a -> Maybe (Element a) -> Element a + +datum : {a : Set} -> Element a -> a +datum (cons a _) = a + +next : {a : Set} -> Element a -> Maybe (Element a) +next (cons _ n) = n + +record SingleLinkedStack (a : Set) : Set where + field + top : Maybe (Element a) +open SingleLinkedStack + +emptySingleLinkedStack : {a : Set} -> SingleLinkedStack a +emptySingleLinkedStack = record {top = Nothing} + + + + +pushSingleLinkedStack : {a t : Set} -> CodeSegment ((SingleLinkedStack a) × a × (CodeSegment (SingleLinkedStack a) t)) t +pushSingleLinkedStack = cs push + where + push : {a t : Set} -> ((SingleLinkedStack a) × a × (CodeSegment (SingleLinkedStack a) t)) -> t + push (stack , datum , next) = goto next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} + +popSingleLinkedStack : {a t : Set} -> CodeSegment (SingleLinkedStack a × (CodeSegment (SingleLinkedStack a × Maybe a) t)) t +popSingleLinkedStack = cs pop + where + pop : {a t : Set} -> (SingleLinkedStack a × (CodeSegment (SingleLinkedStack a × Maybe a) t)) -> t + pop (record { top = Nothing } , nextCS) = goto nextCS (emptySingleLinkedStack , Nothing) + pop (record { top = Just x } , nextCS) = goto nextCS (stack1 , (Just datum1)) + where + datum1 = datum x + stack1 = record { top = (next x) } + + + + + +createSingleLinkedStack : {a b : Set} -> Stack {a} {b} (SingleLinkedStack a) +createSingleLinkedStack = record { stack = emptySingleLinkedStack + ; push = pushSingleLinkedStack + ; pop = popSingleLinkedStack + } + + + + +test01 : {a : Set} -> CodeSegment (SingleLinkedStack a × Maybe a) Bool +test01 = cs test01' + where + test01' : {a : Set} -> (SingleLinkedStack a × Maybe a) -> Bool + test01' (record { top = Nothing } , _) = False + test01' (record { top = Just x } , _) = True + + +test02 : {a : Set} -> CodeSegment (SingleLinkedStack a) (SingleLinkedStack a × Maybe a) +test02 = cs test02' + where + test02' : {a : Set} -> SingleLinkedStack a -> (SingleLinkedStack a × Maybe a) + test02' stack = goto popSingleLinkedStack (stack , (cs id)) + + +test03 : {a : Set} -> CodeSegment a (SingleLinkedStack a) +test03 = cs test03' + where + test03' : {a : Set} -> a -> SingleLinkedStack a + test03' a = goto pushSingleLinkedStack (emptySingleLinkedStack , a , (cs id)) + + +lemma : {A : Set} {a : A} -> goto (test03 ◎ test02 ◎ test01) a ≡ False +lemma = refl + + +n-push : {A : Set} {a : A} -> CodeSegment (ℕ × SingleLinkedStack A) (ℕ × SingleLinkedStack A) +n-push {A} {a} = cs (push {A} {a}) + where + push : {A : Set} {a : A} -> (ℕ × SingleLinkedStack A) -> (ℕ × SingleLinkedStack A) + push {A} {a} (zero , s) = (zero , s) + push {A} {a} (suc n , s) = goto pushSingleLinkedStack (s , a , {!!} {- n-push -}) -- needs subtype + + +{- + +n-push : {A : Set} {a : A} -> Nat -> SingleLinkedStack A -> SingleLinkedStack A +n-push zero s = s +n-push {A} {a} (suc n) s = pushSingleLinkedStack (n-push {A} {a} n s) a (\s -> s) + +n-pop : {A : Set} {a : A} -> Nat -> SingleLinkedStack A -> SingleLinkedStack A +n-pop zero s = s +n-pop {A} {a} (suc n) s = popSingleLinkedStack (n-pop {A} {a} n s) (\s _ -> s) + +open ≡-Reasoning + +push-pop-equiv : {A : Set} {a : A} (s : SingleLinkedStack A) -> popSingleLinkedStack (pushSingleLinkedStack s a (\s -> s)) (\s _ -> s) ≡ s +push-pop-equiv s = refl + +push-and-n-pop : {A : Set} {a : A} (n : Nat) (s : SingleLinkedStack A) -> n-pop {A} {a} (suc n) (pushSingleLinkedStack s a id) ≡ n-pop {A} {a} n s +push-and-n-pop zero s = refl +push-and-n-pop {A} {a} (suc n) s = begin + n-pop (suc (suc n)) (pushSingleLinkedStack s a id) + ≡⟨ refl ⟩ + popSingleLinkedStack (n-pop (suc n) (pushSingleLinkedStack s a id)) (\s _ -> s) + ≡⟨ cong (\s -> popSingleLinkedStack s (\s _ -> s)) (push-and-n-pop n s) ⟩ + popSingleLinkedStack (n-pop n s) (\s _ -> s) + ≡⟨ refl ⟩ + n-pop (suc n) s + ∎ + + +n-push-pop-equiv : {A : Set} {a : A} (n : Nat) (s : SingleLinkedStack A) -> (n-pop {A} {a} n (n-push {A} {a} n s)) ≡ s +n-push-pop-equiv zero s = refl +n-push-pop-equiv {A} {a} (suc n) s = begin + n-pop (suc n) (n-push (suc n) s) + ≡⟨ refl ⟩ + n-pop (suc n) (pushSingleLinkedStack (n-push n s) a (\s -> s)) + ≡⟨ push-and-n-pop n (n-push n s) ⟩ + n-pop n (n-push n s) + ≡⟨ n-push-pop-equiv n s ⟩ + s + ∎ + + +n-push-pop-equiv-empty : {A : Set} {a : A} -> (n : Nat) -> n-pop {A} {a} n (n-push {A} {a} n emptySingleLinkedStack) ≡ emptySingleLinkedStack +n-push-pop-equiv-empty n = n-push-pop-equiv n emptySingleLinkedStack +-} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack-subtype-sample.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stack-subtype-sample.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,212 @@ +module stack-subtype-sample where + +open import Level renaming (suc to S ; zero to O) +open import Function +open import Data.Nat +open import Data.Maybe +open import Relation.Binary.PropositionalEquality + +open import stack-subtype ℕ +open import subtype Context as N +open import subtype Meta as M + + +record Num : Set where + field + num : ℕ + +instance + NumIsNormalDataSegment : N.DataSegment Num + NumIsNormalDataSegment = record { get = (\c -> record { num = Context.n c}) + ; set = (\c n -> record c {n = Num.num n})} + NumIsMetaDataSegment : M.DataSegment Num + NumIsMetaDataSegment = record { get = (\m -> record {num = Context.n (Meta.context m)}) + ; set = (\m n -> record m {context = record (Meta.context m) {n = Num.num n}})} + + +plus3 : Num -> Num +plus3 record { num = n } = record {num = n + 3} + +plus3CS : N.CodeSegment Num Num +plus3CS = N.cs plus3 + + + +plus5AndPushWithPlus3 : {mc : Meta} {{_ : N.DataSegment Num}} + -> M.CodeSegment Num (Meta) +plus5AndPushWithPlus3 {mc} {{nn}} = M.cs (\n -> record {context = con n ; nextCS = (liftContext {{nn}} {{nn}} plus3CS) ; stack = st} ) + where + co = Meta.context mc + con : Num -> Context + con record { num = num } = N.DataSegment.set nn co record {num = num + 5} + st = Meta.stack mc + + + + +push-sample : {{_ : N.DataSegment Num}} {{_ : M.DataSegment Num}} -> Meta +push-sample {{nd}} {{md}} = M.exec {{md}} (plus5AndPushWithPlus3 {mc} {{nd}}) mc + where + con = record { n = 4 ; element = just 0} + code = N.cs (\c -> c) + mc = record {context = con ; stack = emptySingleLinkedStack ; nextCS = code} + + +push-sample-equiv : push-sample ≡ record { nextCS = liftContext plus3CS + ; stack = record { top = nothing} + ; context = record { n = 9} } +push-sample-equiv = refl + + +pushed-sample : {m : Meta} {{_ : N.DataSegment Num}} {{_ : M.DataSegment Num}} -> Meta +pushed-sample {m} {{nd}} {{md}} = M.exec {{md}} (M.csComp {m} {{md}} pushSingleLinkedStackCS (plus5AndPushWithPlus3 {mc} {{nd}})) mc + where + con = record { n = 4 ; element = just 0} + code = N.cs (\c -> c) + mc = record {context = con ; stack = emptySingleLinkedStack ; nextCS = code} + + + +pushed-sample-equiv : {m : Meta} -> + pushed-sample {m} ≡ record { nextCS = liftContext plus3CS + ; stack = record { top = just (cons 0 nothing) } + ; context = record { n = 12} } +pushed-sample-equiv = refl + + + +pushNum : N.CodeSegment Context Context +pushNum = N.cs pn + where + pn : Context -> Context + pn record { n = n } = record { n = pred n ; element = just n} + + +pushOnce : Meta -> Meta +pushOnce m = M.exec pushSingleLinkedStackCS m + +n-push : {m : Meta} {{_ : M.DataSegment Meta}} (n : ℕ) -> M.CodeSegment Meta Meta +n-push {{mm}} (zero) = M.cs {{mm}} {{mm}} id +n-push {m} {{mm}} (suc n) = M.cs {{mm}} {{mm}} (\m -> M.exec {{mm}} {{mm}} (n-push {m} {{mm}} n) (pushOnce m)) + +popOnce : Meta -> Meta +popOnce m = M.exec popSingleLinkedStackCS m + +n-pop : {m : Meta} {{_ : M.DataSegment Meta}} (n : ℕ) -> M.CodeSegment Meta Meta +n-pop {{mm}} (zero) = M.cs {{mm}} {{mm}} id +n-pop {m} {{mm}} (suc n) = M.cs {{mm}} {{mm}} (\m -> M.exec {{mm}} {{mm}} (n-pop {m} {{mm}} n) (popOnce m)) + + + +initMeta : ℕ -> Maybe ℕ -> N.CodeSegment Context Context -> Meta +initMeta n mn code = record { context = record { n = n ; element = mn} + ; stack = emptySingleLinkedStack + ; nextCS = code + } + +n-push-cs-exec = M.exec (n-push {meta} 3) meta + where + meta = (initMeta 5 (just 9) pushNum) + + +n-push-cs-exec-equiv : n-push-cs-exec ≡ record { nextCS = pushNum + ; context = record {n = 2 ; element = just 3} + ; stack = record {top = just (cons 4 (just (cons 5 (just (cons 9 nothing)))))}} +n-push-cs-exec-equiv = refl + + +n-pop-cs-exec = M.exec (n-pop {meta} 4) meta + where + meta = record { nextCS = N.cs id + ; context = record { n = 0 ; element = nothing} + ; stack = record {top = just (cons 9 (just (cons 8 (just (cons 7 (just (cons 6 (just (cons 5 nothing)))))))))} + } + +n-pop-cs-exec-equiv : n-pop-cs-exec ≡ record { nextCS = N.cs id + ; context = record { n = 0 ; element = just 6} + ; stack = record { top = just (cons 5 nothing)} + } + +n-pop-cs-exec-equiv = refl + + +open ≡-Reasoning + +id-meta : ℕ -> ℕ -> SingleLinkedStack ℕ -> Meta +id-meta n e s = record { context = record {n = n ; element = just e} + ; nextCS = (N.cs id) ; stack = s} + +exec-comp : (f g : M.CodeSegment Meta Meta) (m : Meta) -> M.exec (M.csComp {m} f g) m ≡ M.exec f (M.exec g m) +exec-comp (M.cs x) (M.cs _) m = refl + + +push-pop-type : ℕ -> ℕ -> ℕ -> Element ℕ -> Set₁ +push-pop-type n e x s = M.exec (M.csComp {meta} (M.cs popOnce) (M.cs pushOnce)) meta ≡ meta + where + meta = id-meta n e record {top = just (cons x (just s))} + +push-pop : (n e x : ℕ) -> (s : Element ℕ) -> push-pop-type n e x s +push-pop n e x s = refl + + + +pop-n-push-type : ℕ -> ℕ -> ℕ -> SingleLinkedStack ℕ -> Set₁ +pop-n-push-type n cn ce s = M.exec (M.csComp {meta} (M.cs popOnce) (n-push {meta} (suc n))) meta + ≡ M.exec (n-push {meta} n) meta + where + meta = id-meta cn ce s + +pop-n-push : (n cn ce : ℕ) -> (s : SingleLinkedStack ℕ) -> pop-n-push-type n cn ce s + +pop-n-push zero cn ce s = refl +pop-n-push (suc n) cn ce s = begin + M.exec (M.csComp {id-meta cn ce s} (M.cs popOnce) (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc (suc n)))) (id-meta cn ce s) + ≡⟨ refl ⟩ + M.exec (M.csComp {id-meta cn ce s} (M.cs popOnce) (M.csComp {id-meta cn ce s} (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n)) (M.cs pushOnce))) (id-meta cn ce s) + ≡⟨ exec-comp (M.cs popOnce) (M.csComp {id-meta cn ce s} (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n)) (M.cs pushOnce)) (id-meta cn ce s) ⟩ + M.exec (M.cs popOnce) (M.exec (M.csComp {id-meta cn ce s} (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n)) (M.cs pushOnce)) (id-meta cn ce s)) + ≡⟨ cong (\x -> M.exec (M.cs popOnce) x) (exec-comp (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n)) (M.cs pushOnce) (id-meta cn ce s)) ⟩ + M.exec (M.cs popOnce) (M.exec (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n))(M.exec (M.cs pushOnce) (id-meta cn ce s))) + ≡⟨ refl ⟩ + M.exec (M.cs popOnce) (M.exec (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n)) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))}))) + ≡⟨ sym (exec-comp (M.cs popOnce) (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n)) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))}))) ⟩ + M.exec (M.csComp {id-meta cn ce s} (M.cs popOnce) (n-push {id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})} (suc n))) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})) + ≡⟨ pop-n-push n cn ce (record {top = just (cons ce (SingleLinkedStack.top s))}) ⟩ + M.exec (n-push n) (id-meta cn ce (record {top = just (cons ce (SingleLinkedStack.top s))})) + ≡⟨ refl ⟩ + M.exec (n-push n) (pushOnce (id-meta cn ce s)) + ≡⟨ refl ⟩ + M.exec (n-push n) (M.exec (M.cs pushOnce) (id-meta cn ce s)) + ≡⟨ refl ⟩ + M.exec (n-push {id-meta cn ce s} (suc n)) (id-meta cn ce s) + ∎ + + + +n-push-pop-type : ℕ -> ℕ -> ℕ -> SingleLinkedStack ℕ -> Set₁ +n-push-pop-type n cn ce st = M.exec (M.csComp {meta} (n-pop {meta} n) (n-push {meta} n)) meta ≡ meta + where + meta = id-meta cn ce st + +n-push-pop : (n cn ce : ℕ) -> (s : SingleLinkedStack ℕ) -> n-push-pop-type n cn ce s +n-push-pop zero cn ce s = refl +n-push-pop (suc n) cn ce s = begin + M.exec (M.csComp {id-meta cn ce s} (n-pop {id-meta cn ce s} (suc n)) (n-push {id-meta cn ce s} (suc n))) (id-meta cn ce s) + ≡⟨ refl ⟩ + M.exec (M.csComp {id-meta cn ce s} (M.cs (\m -> M.exec (n-pop {id-meta cn ce s} n) (popOnce m))) (n-push {id-meta cn ce s} (suc n))) (id-meta cn ce s) + ≡⟨ exec-comp (M.cs (\m -> M.exec (n-pop n) (popOnce m))) (n-push {id-meta cn ce s} (suc n)) (id-meta cn ce s) ⟩ + M.exec (M.cs (\m -> M.exec (n-pop {id-meta cn ce s} n) (popOnce m))) (M.exec (n-push {id-meta cn ce s} (suc n)) (id-meta cn ce s)) + ≡⟨ refl ⟩ + M.exec (n-pop n) (popOnce (M.exec (n-push {id-meta cn ce s} (suc n)) (id-meta cn ce s))) + ≡⟨ refl ⟩ + M.exec (n-pop n) (M.exec (M.cs popOnce) (M.exec (n-push {id-meta cn ce s} (suc n)) (id-meta cn ce s))) + ≡⟨ cong (\x -> M.exec (n-pop {id-meta cn ce s} n) x) (sym (exec-comp (M.cs popOnce) (n-push {id-meta cn ce s} (suc n)) (id-meta cn ce s))) ⟩ + M.exec (n-pop n) (M.exec (M.csComp {id-meta cn ce s} (M.cs popOnce) (n-push {id-meta cn ce s} (suc n))) (id-meta cn ce s)) + ≡⟨ cong (\x -> M.exec (n-pop {id-meta cn ce s} n) x) (pop-n-push n cn ce s) ⟩ + M.exec (n-pop n) (M.exec (n-push n) (id-meta cn ce s)) + ≡⟨ sym (exec-comp (n-pop n) (n-push n) (id-meta cn ce s)) ⟩ + M.exec (M.csComp (n-pop n) (n-push n)) (id-meta cn ce s) + ≡⟨ n-push-pop n cn ce s ⟩ + id-meta cn ce s + ∎ + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack-subtype.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stack-subtype.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,123 @@ +open import Level hiding (lift) +open import Data.Maybe +open import Data.Product +open import Data.Nat hiding (suc) +open import Function + +module stack-subtype (A : Set) where + +-- data definitions + +data Element (a : Set) : Set where + cons : a -> Maybe (Element a) -> Element a + +datum : {a : Set} -> Element a -> a +datum (cons a _) = a + +next : {a : Set} -> Element a -> Maybe (Element a) +next (cons _ n) = n + +record SingleLinkedStack (a : Set) : Set where + field + top : Maybe (Element a) +open SingleLinkedStack + +record Context : Set where + field + -- fields for concrete data segments + n : ℕ + -- fields for stack + element : Maybe A + + + + + +open import subtype Context as N + +instance + ContextIsDataSegment : N.DataSegment Context + ContextIsDataSegment = record {get = (\c -> c) ; set = (\_ c -> c)} + + +record Meta : Set₁ where + field + -- context as set of data segments + context : Context + stack : SingleLinkedStack A + nextCS : N.CodeSegment Context Context + + + + +open import subtype Meta as M + +instance + MetaIncludeContext : M.DataSegment Context + MetaIncludeContext = record { get = Meta.context + ; set = (\m c -> record m {context = c}) } + + MetaIsMetaDataSegment : M.DataSegment Meta + MetaIsMetaDataSegment = record { get = (\m -> m) ; set = (\_ m -> m) } + + +liftMeta : {X Y : Set} {{_ : M.DataSegment X}} {{_ : M.DataSegment Y}} -> N.CodeSegment X Y -> M.CodeSegment X Y +liftMeta (N.cs f) = M.cs f + +liftContext : {X Y : Set} {{_ : N.DataSegment X}} {{_ : N.DataSegment Y}} -> N.CodeSegment X Y -> N.CodeSegment Context Context +liftContext {{x}} {{y}} (N.cs f) = N.cs (\c -> N.DataSegment.set y c (f (N.DataSegment.get x c))) + +-- definition based from Gears(209:5708390a9d88) src/parallel_execution + +emptySingleLinkedStack : SingleLinkedStack A +emptySingleLinkedStack = record {top = nothing} + + +pushSingleLinkedStack : Meta -> Meta +pushSingleLinkedStack m = M.exec (liftMeta n) (record m {stack = (push s e) }) + where + n = Meta.nextCS m + s = Meta.stack m + e = Context.element (Meta.context m) + push : SingleLinkedStack A -> Maybe A -> SingleLinkedStack A + push s nothing = s + push s (just x) = record {top = just (cons x (top s))} + + + +popSingleLinkedStack : Meta -> Meta +popSingleLinkedStack m = M.exec (liftMeta n) (record m {stack = (st m) ; context = record con {element = (elem m)}}) + where + n = Meta.nextCS m + con = Meta.context m + elem : Meta -> Maybe A + elem record {stack = record { top = (just (cons x _)) }} = just x + elem record {stack = record { top = nothing }} = nothing + st : Meta -> SingleLinkedStack A + st record {stack = record { top = (just (cons _ s)) }} = record {top = s} + st record {stack = record { top = nothing }} = record {top = nothing} + + + + +pushSingleLinkedStackCS : M.CodeSegment Meta Meta +pushSingleLinkedStackCS = M.cs pushSingleLinkedStack + +popSingleLinkedStackCS : M.CodeSegment Meta Meta +popSingleLinkedStackCS = M.cs popSingleLinkedStack + + +-- for sample + +firstContext : Context +firstContext = record {element = nothing ; n = 0} + + +firstMeta : Meta +firstMeta = record { context = firstContext + ; stack = emptySingleLinkedStack + ; nextCS = (N.cs (\m -> m)) + } + + + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stack.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,149 @@ +open import Level renaming (suc to succ ; zero to Zero ) +module stack where + +open import Relation.Binary.PropositionalEquality +open import Relation.Binary.Core +open import Data.Nat + +ex : 1 + 2 ≡ 3 +ex = refl + +data Bool {n : Level } : Set n where + True : Bool + False : Bool + +record _∧_ {n : Level } (a : Set n) (b : Set n): Set n where + field + pi1 : a + pi2 : b + +data Maybe {n : Level } (a : Set n) : Set n where + Nothing : Maybe a + Just : a -> Maybe a + +record StackMethods {n m : Level } (a : Set n ) {t : Set m }(stackImpl : Set n ) : Set (m Level.⊔ n) where + field + push : stackImpl -> a -> (stackImpl -> t) -> t + pop : stackImpl -> (stackImpl -> Maybe a -> t) -> t + pop2 : stackImpl -> (stackImpl -> Maybe a -> Maybe a -> t) -> t + get : stackImpl -> (stackImpl -> Maybe a -> t) -> t + get2 : stackImpl -> (stackImpl -> Maybe a -> Maybe a -> t) -> t + clear : stackImpl -> (stackImpl -> t) -> t +open StackMethods + +record Stack {n m : Level } (a : Set n ) {t : Set m } (si : Set n ) : Set (m Level.⊔ n) where + field + stack : si + stackMethods : StackMethods {n} {m} a {t} si + pushStack : a -> (Stack a si -> t) -> t + pushStack d next = push (stackMethods ) (stack ) d (\s1 -> next (record {stack = s1 ; stackMethods = stackMethods } )) + popStack : (Stack a si -> Maybe a -> t) -> t + popStack next = pop (stackMethods ) (stack ) (\s1 d1 -> next (record {stack = s1 ; stackMethods = stackMethods }) d1 ) + pop2Stack : (Stack a si -> Maybe a -> Maybe a -> t) -> t + pop2Stack next = pop2 (stackMethods ) (stack ) (\s1 d1 d2 -> next (record {stack = s1 ; stackMethods = stackMethods }) d1 d2) + getStack : (Stack a si -> Maybe a -> t) -> t + getStack next = get (stackMethods ) (stack ) (\s1 d1 -> next (record {stack = s1 ; stackMethods = stackMethods }) d1 ) + get2Stack : (Stack a si -> Maybe a -> Maybe a -> t) -> t + get2Stack next = get2 (stackMethods ) (stack ) (\s1 d1 d2 -> next (record {stack = s1 ; stackMethods = stackMethods }) d1 d2) + clearStack : (Stack a si -> t) -> t + clearStack next = clear (stackMethods ) (stack ) (\s1 -> next (record {stack = s1 ; stackMethods = stackMethods } )) + +open Stack + +{-- +data Element {n : Level } (a : Set n) : Set n where + cons : a -> Maybe (Element a) -> Element a + + +datum : {n : Level } {a : Set n} -> Element a -> a +datum (cons a _) = a + +next : {n : Level } {a : Set n} -> Element a -> Maybe (Element a) +next (cons _ n) = n +--} + + +-- cannot define recrusive record definition. so use linked list with maybe. +record Element {l : Level} (a : Set l) : Set l where + inductive + constructor cons + field + datum : a -- `data` is reserved by Agda. + next : Maybe (Element a) + +open Element + + +record SingleLinkedStack {n : Level } (a : Set n) : Set n where + field + top : Maybe (Element a) +open SingleLinkedStack + +pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} -> SingleLinkedStack Data -> Data -> (Code : SingleLinkedStack Data -> t) -> t +pushSingleLinkedStack stack datum next = next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} + + +popSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> t) -> t +popSingleLinkedStack stack cs with (top stack) +... | Nothing = cs stack Nothing +... | Just d = cs stack1 (Just data1) + where + data1 = datum d + stack1 = record { top = (next d) } + +pop2SingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> (Maybe a) -> t) -> t +pop2SingleLinkedStack {n} {m} {t} {a} stack cs with (top stack) +... | Nothing = cs stack Nothing Nothing +... | Just d = pop2SingleLinkedStack' {n} {m} stack cs + where + pop2SingleLinkedStack' : {n m : Level } {t : Set m } -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> (Maybe a) -> t) -> t + pop2SingleLinkedStack' stack cs with (next d) + ... | Nothing = cs stack Nothing Nothing + ... | Just d1 = cs (record {top = (next d1)}) (Just (datum d)) (Just (datum d1)) + + +getSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> t) -> t +getSingleLinkedStack stack cs with (top stack) +... | Nothing = cs stack Nothing +... | Just d = cs stack (Just data1) + where + data1 = datum d + +get2SingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> (Maybe a) -> t) -> t +get2SingleLinkedStack {n} {m} {t} {a} stack cs with (top stack) +... | Nothing = cs stack Nothing Nothing +... | Just d = get2SingleLinkedStack' {n} {m} stack cs + where + get2SingleLinkedStack' : {n m : Level} {t : Set m } -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> (Maybe a) -> t) -> t + get2SingleLinkedStack' stack cs with (next d) + ... | Nothing = cs stack Nothing Nothing + ... | Just d1 = cs stack (Just (datum d)) (Just (datum d1)) + +clearSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> SingleLinkedStack a -> (SingleLinkedStack a -> t) -> t +clearSingleLinkedStack stack next = next (record {top = Nothing}) + + +emptySingleLinkedStack : {n : Level } {a : Set n} -> SingleLinkedStack a +emptySingleLinkedStack = record {top = Nothing} + +----- +-- Basic stack implementations are specifications of a Stack +-- +singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} -> StackMethods {n} {m} a {t} (SingleLinkedStack a) +singleLinkedStackSpec = record { + push = pushSingleLinkedStack + ; pop = popSingleLinkedStack + ; pop2 = pop2SingleLinkedStack + ; get = getSingleLinkedStack + ; get2 = get2SingleLinkedStack + ; clear = clearSingleLinkedStack + } + +createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> Stack {n} {m} a {t} (SingleLinkedStack a) +createSingleLinkedStack = record { + stack = emptySingleLinkedStack ; + stackMethods = singleLinkedStackSpec + } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack.agda.replace --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stack.agda.replace Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,14 @@ +pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} -> SingleLinkedStack Data -> Data -> (Code : SingleLinkedStack Data -> t) -> t +pushSingleLinkedStack stack datum next = next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} + + +popSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> t) -> t +popSingleLinkedStack stack cs with (top stack) +... | Nothing = cs stack Nothing +... | Just d = cs stack1 (Just data1) + where + data1 = datum d + stack1 = record { top = (next d) } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack.agdai Binary file final_pre/src/stack.agdai has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stack.h Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,7 @@ +struct SingleLinkedStack { + struct Element* top; +} SingleLinkedStack; +struct Element { + union Data* data; + struct Element* next; +} Element; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stackImpl.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stackImpl.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,38 @@ +record Element {l : Level} (a : Set l) : Set l where + inductive + constructor cons + field + datum : a -- `data` is reserved by Agda. + next : Maybe (Element a) +open Element + +record SingleLinkedStack {n : Level } (a : Set n) : Set n where + field + top : Maybe (Element a) +open SingleLinkedStack + +pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} -> SingleLinkedStack Data -> Data -> (Code : SingleLinkedStack Data -> t) -> t +pushSingleLinkedStack stack datum next = next stack1 + where + element = cons datum (top stack) + stack1 = record {top = Just element} + +-- push 以下は省略 + +-- Basic stack implementations are specifications of a Stack + +singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} -> StackMethods {n} {m} a {t} (SingleLinkedStack a) +singleLinkedStackSpec = record { + push = pushSingleLinkedStack + ; pop = popSingleLinkedStack + ; pop2 = pop2SingleLinkedStack + ; get = getSingleLinkedStack + ; get2 = get2SingleLinkedStack + ; clear = clearSingleLinkedStack + } + +createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> Stack {n} {m} a {t} (SingleLinkedStack a) +createSingleLinkedStack = record { + stack = emptySingleLinkedStack ; + stackMethods = singleLinkedStackSpec + } diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stackTest.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stackTest.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,144 @@ +open import Level renaming (suc to succ ; zero to Zero ) +module stackTest where + +open import stack + +open import Relation.Binary.PropositionalEquality +open import Relation.Binary.Core +open import Data.Nat +open import Function + + +open SingleLinkedStack +open Stack + +---- +-- +-- proof of properties ( concrete cases ) +-- + +test01 : {n : Level } {a : Set n} -> SingleLinkedStack a -> Maybe a -> Bool {n} +test01 stack _ with (top stack) +... | (Just _) = True +... | Nothing = False + + +test02 : {n : Level } {a : Set n} -> SingleLinkedStack a -> Bool +test02 stack = popSingleLinkedStack stack test01 + +test03 : {n : Level } {a : Set n} -> a -> Bool +test03 v = pushSingleLinkedStack emptySingleLinkedStack v test02 + +-- after a push and a pop, the stack is empty +lemma : {n : Level} {A : Set n} {a : A} -> test03 a ≡ False +lemma = refl + +testStack01 : {n m : Level } {a : Set n} -> a -> Bool {m} +testStack01 v = pushStack createSingleLinkedStack v ( + \s -> popStack s (\s1 d1 -> True)) + +-- after push 1 and 2, pop2 get 1 and 2 + +testStack02 : {m : Level } -> ( Stack ℕ (SingleLinkedStack ℕ) -> Bool {m} ) -> Bool {m} +testStack02 cs = pushStack createSingleLinkedStack 1 ( + \s -> pushStack s 2 cs) + + +testStack031 : (d1 d2 : ℕ ) -> Bool {Zero} +testStack031 2 1 = True +testStack031 _ _ = False + +testStack032 : (d1 d2 : Maybe ℕ) -> Bool {Zero} +testStack032 (Just d1) (Just d2) = testStack031 d1 d2 +testStack032 _ _ = False + +testStack03 : {m : Level } -> Stack ℕ (SingleLinkedStack ℕ) -> ((Maybe ℕ) -> (Maybe ℕ) -> Bool {m} ) -> Bool {m} +testStack03 s cs = pop2Stack s ( + \s d1 d2 -> cs d1 d2 ) + +testStack04 : Bool +testStack04 = testStack02 (\s -> testStack03 s testStack032) + +testStack05 : testStack04 ≡ True +testStack05 = refl + +testStack06 : {m : Level } -> Maybe (Element ℕ) +testStack06 = pushStack createSingleLinkedStack 1 ( + \s -> pushStack s 2 (\s -> top (stack s))) + +testStack07 : {m : Level } -> Maybe (Element ℕ) +testStack07 = pushSingleLinkedStack emptySingleLinkedStack 1 ( + \s -> pushSingleLinkedStack s 2 (\s -> top s)) + +testStack08 = pushSingleLinkedStack emptySingleLinkedStack 1 + $ \s -> pushSingleLinkedStack s 2 + $ \s -> pushSingleLinkedStack s 3 + $ \s -> pushSingleLinkedStack s 4 + $ \s -> pushSingleLinkedStack s 5 + $ \s -> top s + +------ +-- +-- proof of properties with indefinite state of stack +-- +-- this should be proved by properties of the stack inteface, not only by the implementation, +-- and the implementation have to provides the properties. +-- +-- we cannot write "s ≡ s3", since level of the Set does not fit , but use stack s ≡ stack s3 is ok. +-- anyway some implementations may result s != s3 +-- + +stackInSomeState : {l m : Level } {D : Set l} {t : Set m } (s : SingleLinkedStack D ) -> Stack {l} {m} D {t} ( SingleLinkedStack D ) +stackInSomeState s = record { stack = s ; stackMethods = singleLinkedStackSpec } + +push->push->pop2 : {l : Level } {D : Set l} (x y : D ) (s : SingleLinkedStack D ) -> + pushStack ( stackInSomeState s ) x ( \s1 -> pushStack s1 y ( \s2 -> pop2Stack s2 ( \s3 y1 x1 -> (Just x ≡ x1 ) ∧ (Just y ≡ y1 ) ) )) +push->push->pop2 {l} {D} x y s = record { pi1 = refl ; pi2 = refl } + + +-- id : {n : Level} {A : Set n} -> A -> A +-- id a = a + +-- push a, n times + +n-push : {n : Level} {A : Set n} {a : A} -> ℕ -> SingleLinkedStack A -> SingleLinkedStack A +n-push zero s = s +n-push {l} {A} {a} (suc n) s = pushSingleLinkedStack (n-push {l} {A} {a} n s) a (\s -> s ) + +n-pop : {n : Level}{A : Set n} {a : A} -> ℕ -> SingleLinkedStack A -> SingleLinkedStack A +n-pop zero s = s +n-pop {_} {A} {a} (suc n) s = popSingleLinkedStack (n-pop {_} {A} {a} n s) (\s _ -> s ) + +open ≡-Reasoning + +push-pop-equiv : {n : Level} {A : Set n} {a : A} (s : SingleLinkedStack A) -> (popSingleLinkedStack (pushSingleLinkedStack s a (\s -> s)) (\s _ -> s) ) ≡ s +push-pop-equiv s = refl + +push-and-n-pop : {n : Level} {A : Set n} {a : A} (n : ℕ) (s : SingleLinkedStack A) -> n-pop {_} {A} {a} (suc n) (pushSingleLinkedStack s a id) ≡ n-pop {_} {A} {a} n s +push-and-n-pop zero s = refl +push-and-n-pop {_} {A} {a} (suc n) s = begin + n-pop {_} {A} {a} (suc (suc n)) (pushSingleLinkedStack s a id) + ≡⟨ refl ⟩ + popSingleLinkedStack (n-pop {_} {A} {a} (suc n) (pushSingleLinkedStack s a id)) (\s _ -> s) + ≡⟨ cong (\s -> popSingleLinkedStack s (\s _ -> s )) (push-and-n-pop n s) ⟩ + popSingleLinkedStack (n-pop {_} {A} {a} n s) (\s _ -> s) + ≡⟨ refl ⟩ + n-pop {_} {A} {a} (suc n) s + ∎ + + +n-push-pop-equiv : {n : Level} {A : Set n} {a : A} (n : ℕ) (s : SingleLinkedStack A) -> (n-pop {_} {A} {a} n (n-push {_} {A} {a} n s)) ≡ s +n-push-pop-equiv zero s = refl +n-push-pop-equiv {_} {A} {a} (suc n) s = begin + n-pop {_} {A} {a} (suc n) (n-push (suc n) s) + ≡⟨ refl ⟩ + n-pop {_} {A} {a} (suc n) (pushSingleLinkedStack (n-push n s) a (\s -> s)) + ≡⟨ push-and-n-pop n (n-push n s) ⟩ + n-pop {_} {A} {a} n (n-push n s) + ≡⟨ n-push-pop-equiv n s ⟩ + s + ∎ + + +n-push-pop-equiv-empty : {n : Level} {A : Set n} {a : A} -> (n : ℕ) -> n-pop {_} {A} {a} n (n-push {_} {A} {a} n emptySingleLinkedStack) ≡ emptySingleLinkedStack +n-push-pop-equiv-empty n = n-push-pop-equiv n emptySingleLinkedStack diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stackTest.agdai Binary file final_pre/src/stackTest.agdai has changed diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stack_context.h.replace --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stack_context.h.replace Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,14 @@ +struct Stack { + union Data* stack; + union Data* data; + union Data* data1; + enum Code whenEmpty; + enum Code clear; + enum Code push; + enum Code pop; + enum Code pop2; + enum Code isEmpty; + enum Code get; + enum Code get2; + enum Code next; +} Stack; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/struct-init.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/struct-init.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,1 @@ +struct Point p = {100 , 200}; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/struct.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/struct.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,4 @@ +struct Point { + int x; + int y; +}; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/stub.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/stub.cbc Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,17 @@ +__code put(struct Context* context, + struct Tree* tree, + struct Node* root, + struct Allocate* allocate) +{ + /* 実装コードは省略 */ +} + +__code put_stub(struct Context* context) +{ + goto put(context, + &context->data[Tree]->tree, + context->data[Tree]->tree.root, + &context->data[Allocate]->allocate); +} + + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/subtype.agda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/subtype.agda Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,44 @@ +open import Level +open import Relation.Binary.PropositionalEquality + +module subtype {l : Level} (Context : Set l) where + + +record DataSegment {ll : Level} (A : Set ll) : Set (l ⊔ ll) where + field + get : Context -> A + set : Context -> A -> Context +open DataSegment + +data CodeSegment {l1 l2 : Level} (A : Set l1) (B : Set l2) : Set (l ⊔ l1 ⊔ l2) where + cs : {{_ : DataSegment A}} {{_ : DataSegment B}} -> (A -> B) -> CodeSegment A B + +goto : {l1 l2 : Level} {I : Set l1} {O : Set l2} -> CodeSegment I O -> I -> O +goto (cs b) i = b i + +exec : {l1 l2 : Level} {I : Set l1} {O : Set l2} {{_ : DataSegment I}} {{_ : DataSegment O}} + -> CodeSegment I O -> Context -> Context +exec {l} {{i}} {{o}} (cs b) c = set o c (b (get i c)) + + +comp : {con : Context} -> {l1 l2 l3 l4 : Level} + {A : Set l1} {B : Set l2} {C : Set l3} {D : Set l4} + {{_ : DataSegment A}} {{_ : DataSegment B}} {{_ : DataSegment C}} {{_ : DataSegment D}} + -> (C -> D) -> (A -> B) -> A -> D +comp {con} {{i}} {{io}} {{oi}} {{o}} g f x = g (get oi (set io con (f x))) + +csComp : {con : Context} -> {l1 l2 l3 l4 : Level} + {A : Set l1} {B : Set l2} {C : Set l3} {D : Set l4} + {{_ : DataSegment A}} {{_ : DataSegment B}} {{_ : DataSegment C}} {{_ : DataSegment D}} + -> CodeSegment C D -> CodeSegment A B -> CodeSegment A D +csComp {con} {A} {B} {C} {D} {{da}} {{db}} {{dc}} {{dd}} (cs g) (cs f) + = cs {{da}} {{dd}} (comp {con} {{da}} {{db}} {{dc}} {{dd}} g f) + + + +comp-associative : {A B C D E F : Set l} {con : Context} + {{da : DataSegment A}} {{db : DataSegment B}} {{dc : DataSegment C}} + {{dd : DataSegment D}} {{de : DataSegment E}} {{df : DataSegment F}} + -> (a : CodeSegment A B) (b : CodeSegment C D) (c : CodeSegment E F) + -> csComp {con} c (csComp {con} b a) ≡ csComp {con} (csComp {con} c b) a +comp-associative (cs _) (cs _) (cs _) = refl diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/type-cs.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/type-cs.c Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,9 @@ +__code getMinHeight_stub(struct Context* context) { + goto getMinHeight(context, &context->data[Allocate]->allocate, &context->data[AkashaInfo]->akashaInfo); +} + +__code getMinHeight(struct Context* context, struct Allocate* allocate, struct AkashaInfo* akashaInfo) { + /* ... */ + goto getMinHeight_stub(context); +} + diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/type-ds.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/type-ds.h Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,5 @@ +struct AkashaInfo { + unsigned int minHeight; + unsigned int maxHeight; + struct AkashaNode* akashaNode; +}; diff -r 8f5d263c219b -r 0e8b9646d43f final_pre/src/type-mds.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/final_pre/src/type-mds.h Sun Feb 17 05:39:59 2019 +0900 @@ -0,0 +1,15 @@ +struct Data { /* data segments as types */ + struct Tree { /* ... */ } tree; + struct Node { /* ... */ } node; + + struct IterElem { /* ... */ } iterElem; + struct Iterator { /* ... */ } iterator; + struct AkashaInfo { /* ... */} akashaInfo; + struct AkashaNode { /* ... */} akashaNode; +}; + + +struct Context { /* meta data segment as subtype */ + /* ... fields for meta computations ... */ + struct Data **data; /* data segments */ +};