From 6f604b19d3f5966e5c1d7c4fdf3703bd6ff0861c Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 16 Apr 2015 21:22:20 +0200 Subject: update to fp2 yay, public and licence --- LICENCE | 674 +++++++++++++++++++++++++++++++ README.md | 1 - fp1/week1/camil/1.1/Start.icl | 18 + fp1/week1/camil/1.1/antwoorden.txt | 29 ++ fp1/week1/camil/2.1/NotatieFuncties.icl | 39 ++ fp1/week1/camil/2.1/antwoorden.txt | 8 + fp1/week1/camil/2.11/BottlesOfBeer.icl | 21 + fp1/week1/camil/2.2/VindtDeRedex.icl | 17 + fp1/week1/camil/2.2/antwoorden.txt | 42 ++ fp1/week1/camil/2.3/MatchStrings.dcl | 8 + fp1/week1/camil/2.3/MatchStrings.icl | 48 +++ fp1/week1/mart/1.txt | 3 + fp1/week1/mart/MatchStrings.dcl | 8 + fp1/week1/mart/MatchStrings.icl | 54 +++ fp1/week2/camil/Makefile | 4 + fp1/week2/camil/StdT.dcl | 18 + fp1/week2/camil/StdT.icl | 37 ++ fp1/week2/camil/TupleOverloading.dcl | 25 ++ fp1/week2/camil/TupleOverloading.icl | 53 +++ fp1/week2/camil/VectorOverloading.dcl | 14 + fp1/week2/camil/VectorOverloading.icl | 37 ++ fp1/week2/mart/Makefile | 21 + fp1/week2/mart/StdT.dcl | 18 + fp1/week2/mart/StdT.icl | 35 ++ fp1/week2/mart/StdTTest.icl | 45 +++ fp1/week2/mart/TupleOverloading.dcl | 25 ++ fp1/week2/mart/TupleOverloading.icl | 49 +++ fp1/week2/mart/TupleOverloadingTest.icl | 64 +++ fp1/week2/mart/VectorOverloading.dcl | 14 + fp1/week2/mart/VectorOverloading.icl | 22 + fp1/week2/mart/VectorOverloadingTest.icl | 62 +++ fp1/week2/week2.tar.gz | Bin 0 -> 1623 bytes fp1/week3/camil/.gitignore | 2 + fp1/week3/camil/StdSortList.dcl | 18 + fp1/week3/camil/StdSortList.icl | 64 +++ fp1/week3/camil/StdSortListTest.icl | 107 +++++ fp1/week3/camil/StdStack.dcl | 13 + fp1/week3/camil/StdStack.icl | 66 +++ fp1/week3/camil/StdStackTest.icl | 60 +++ fp1/week3/mart/StdSortList.dcl | 18 + fp1/week3/mart/StdSortList.icl | 50 +++ fp1/week3/mart/StdStack.dcl | 13 + fp1/week3/mart/StdStack.icl | 57 +++ fp1/week4/camil/5.4 | 5 + fp1/week4/camil/StdSet.dcl | 25 ++ fp1/week4/camil/StdSet.icl | 64 +++ fp1/week4/mart/5.4.txt | 4 + fp1/week4/mart/StdSet.dcl | 25 ++ fp1/week4/mart/StdSet.icl | 54 +++ fp1/week4/week4.tar.gz | Bin 0 -> 890 bytes fp1/week5/camil/Origami.icl | 24 ++ fp1/week5/mart/Origami.icl | 16 + fp1/week6/camil/BewijsMapFlatten.icl | 83 ++++ fp1/week6/mart/BewijsMapFlatten.icl | 97 +++++ fp1/week7/camil/BewijsMeppenEnTippen.icl | 82 ++++ fp1/week7/camil/BinSearchTree.dcl | 7 + fp1/week7/camil/BinSearchTree.icl | 177 ++++++++ fp1/week7/camil/BinTree.dcl | 16 + fp1/week7/camil/BinTree.icl | 38 ++ fp1/week7/mart/BewijsMeppenEnTippen.icl | 29 ++ fp1/week7/mart/BinSearchTree.dcl | 7 + fp1/week7/mart/BinSearchTree.icl | 141 +++++++ week1/camil/1.1/Start.icl | 18 - week1/camil/1.1/antwoorden.txt | 29 -- week1/camil/2.1/NotatieFuncties.icl | 39 -- week1/camil/2.1/antwoorden.txt | 8 - week1/camil/2.11/BottlesOfBeer.icl | 21 - week1/camil/2.2/VindtDeRedex.icl | 17 - week1/camil/2.2/antwoorden.txt | 42 -- week1/camil/2.3/MatchStrings.dcl | 8 - week1/camil/2.3/MatchStrings.icl | 48 --- week1/mart/1.txt | 3 - week1/mart/MatchStrings.dcl | 8 - week1/mart/MatchStrings.icl | 54 --- week2/camil/Makefile | 4 - week2/camil/StdT.dcl | 18 - week2/camil/StdT.icl | 37 -- week2/camil/TupleOverloading.dcl | 25 -- week2/camil/TupleOverloading.icl | 53 --- week2/camil/VectorOverloading.dcl | 14 - week2/camil/VectorOverloading.icl | 37 -- week2/mart/Makefile | 21 - week2/mart/StdT.dcl | 18 - week2/mart/StdT.icl | 35 -- week2/mart/StdTTest.icl | 45 --- week2/mart/TupleOverloading.dcl | 25 -- week2/mart/TupleOverloading.icl | 49 --- week2/mart/TupleOverloadingTest.icl | 64 --- week2/mart/VectorOverloading.dcl | 14 - week2/mart/VectorOverloading.icl | 22 - week2/mart/VectorOverloadingTest.icl | 62 --- week2/week2.tar.gz | Bin 1623 -> 0 bytes week3/camil/.gitignore | 2 - week3/camil/StdSortList.dcl | 18 - week3/camil/StdSortList.icl | 64 --- week3/camil/StdSortListTest.icl | 107 ----- week3/camil/StdStack.dcl | 13 - week3/camil/StdStack.icl | 66 --- week3/camil/StdStackTest.icl | 60 --- week3/mart/StdSortList.dcl | 18 - week3/mart/StdSortList.icl | 50 --- week3/mart/StdStack.dcl | 13 - week3/mart/StdStack.icl | 57 --- week4/camil/5.4 | 5 - week4/camil/StdSet.dcl | 25 -- week4/camil/StdSet.icl | 64 --- week4/mart/5.4.txt | 4 - week4/mart/StdSet.dcl | 25 -- week4/mart/StdSet.icl | 54 --- week4/week4.tar.gz | Bin 890 -> 0 bytes week5/camil/Origami.icl | 24 -- week5/mart/Origami.icl | 16 - week6/camil/BewijsMapFlatten.icl | 83 ---- week6/mart/BewijsMapFlatten.icl | 97 ----- week7/camil/BewijsMeppenEnTippen.icl | 82 ---- week7/camil/BinSearchTree.dcl | 7 - week7/camil/BinSearchTree.icl | 177 -------- week7/camil/BinTree.dcl | 16 - week7/camil/BinTree.icl | 38 -- week7/mart/BewijsMeppenEnTippen.icl | 29 -- week7/mart/BinSearchTree.dcl | 7 - week7/mart/BinSearchTree.icl | 141 ------- 122 files changed, 2874 insertions(+), 2201 deletions(-) create mode 100644 LICENCE delete mode 100644 README.md create mode 100644 fp1/week1/camil/1.1/Start.icl create mode 100644 fp1/week1/camil/1.1/antwoorden.txt create mode 100644 fp1/week1/camil/2.1/NotatieFuncties.icl create mode 100644 fp1/week1/camil/2.1/antwoorden.txt create mode 100644 fp1/week1/camil/2.11/BottlesOfBeer.icl create mode 100644 fp1/week1/camil/2.2/VindtDeRedex.icl create mode 100644 fp1/week1/camil/2.2/antwoorden.txt create mode 100644 fp1/week1/camil/2.3/MatchStrings.dcl create mode 100644 fp1/week1/camil/2.3/MatchStrings.icl create mode 100644 fp1/week1/mart/1.txt create mode 100644 fp1/week1/mart/MatchStrings.dcl create mode 100644 fp1/week1/mart/MatchStrings.icl create mode 100644 fp1/week2/camil/Makefile create mode 100644 fp1/week2/camil/StdT.dcl create mode 100644 fp1/week2/camil/StdT.icl create mode 100644 fp1/week2/camil/TupleOverloading.dcl create mode 100644 fp1/week2/camil/TupleOverloading.icl create mode 100644 fp1/week2/camil/VectorOverloading.dcl create mode 100644 fp1/week2/camil/VectorOverloading.icl create mode 100644 fp1/week2/mart/Makefile create mode 100644 fp1/week2/mart/StdT.dcl create mode 100644 fp1/week2/mart/StdT.icl create mode 100644 fp1/week2/mart/StdTTest.icl create mode 100644 fp1/week2/mart/TupleOverloading.dcl create mode 100644 fp1/week2/mart/TupleOverloading.icl create mode 100644 fp1/week2/mart/TupleOverloadingTest.icl create mode 100644 fp1/week2/mart/VectorOverloading.dcl create mode 100644 fp1/week2/mart/VectorOverloading.icl create mode 100644 fp1/week2/mart/VectorOverloadingTest.icl create mode 100644 fp1/week2/week2.tar.gz create mode 100644 fp1/week3/camil/.gitignore create mode 100644 fp1/week3/camil/StdSortList.dcl create mode 100644 fp1/week3/camil/StdSortList.icl create mode 100644 fp1/week3/camil/StdSortListTest.icl create mode 100644 fp1/week3/camil/StdStack.dcl create mode 100644 fp1/week3/camil/StdStack.icl create mode 100644 fp1/week3/camil/StdStackTest.icl create mode 100644 fp1/week3/mart/StdSortList.dcl create mode 100644 fp1/week3/mart/StdSortList.icl create mode 100644 fp1/week3/mart/StdStack.dcl create mode 100644 fp1/week3/mart/StdStack.icl create mode 100644 fp1/week4/camil/5.4 create mode 100644 fp1/week4/camil/StdSet.dcl create mode 100644 fp1/week4/camil/StdSet.icl create mode 100644 fp1/week4/mart/5.4.txt create mode 100644 fp1/week4/mart/StdSet.dcl create mode 100644 fp1/week4/mart/StdSet.icl create mode 100644 fp1/week4/week4.tar.gz create mode 100644 fp1/week5/camil/Origami.icl create mode 100644 fp1/week5/mart/Origami.icl create mode 100644 fp1/week6/camil/BewijsMapFlatten.icl create mode 100644 fp1/week6/mart/BewijsMapFlatten.icl create mode 100644 fp1/week7/camil/BewijsMeppenEnTippen.icl create mode 100644 fp1/week7/camil/BinSearchTree.dcl create mode 100644 fp1/week7/camil/BinSearchTree.icl create mode 100644 fp1/week7/camil/BinTree.dcl create mode 100644 fp1/week7/camil/BinTree.icl create mode 100644 fp1/week7/mart/BewijsMeppenEnTippen.icl create mode 100644 fp1/week7/mart/BinSearchTree.dcl create mode 100644 fp1/week7/mart/BinSearchTree.icl delete mode 100644 week1/camil/1.1/Start.icl delete mode 100644 week1/camil/1.1/antwoorden.txt delete mode 100644 week1/camil/2.1/NotatieFuncties.icl delete mode 100644 week1/camil/2.1/antwoorden.txt delete mode 100644 week1/camil/2.11/BottlesOfBeer.icl delete mode 100644 week1/camil/2.2/VindtDeRedex.icl delete mode 100644 week1/camil/2.2/antwoorden.txt delete mode 100644 week1/camil/2.3/MatchStrings.dcl delete mode 100644 week1/camil/2.3/MatchStrings.icl delete mode 100644 week1/mart/1.txt delete mode 100644 week1/mart/MatchStrings.dcl delete mode 100644 week1/mart/MatchStrings.icl delete mode 100644 week2/camil/Makefile delete mode 100644 week2/camil/StdT.dcl delete mode 100644 week2/camil/StdT.icl delete mode 100644 week2/camil/TupleOverloading.dcl delete mode 100644 week2/camil/TupleOverloading.icl delete mode 100644 week2/camil/VectorOverloading.dcl delete mode 100644 week2/camil/VectorOverloading.icl delete mode 100644 week2/mart/Makefile delete mode 100644 week2/mart/StdT.dcl delete mode 100644 week2/mart/StdT.icl delete mode 100644 week2/mart/StdTTest.icl delete mode 100644 week2/mart/TupleOverloading.dcl delete mode 100644 week2/mart/TupleOverloading.icl delete mode 100644 week2/mart/TupleOverloadingTest.icl delete mode 100644 week2/mart/VectorOverloading.dcl delete mode 100644 week2/mart/VectorOverloading.icl delete mode 100644 week2/mart/VectorOverloadingTest.icl delete mode 100644 week2/week2.tar.gz delete mode 100644 week3/camil/.gitignore delete mode 100644 week3/camil/StdSortList.dcl delete mode 100644 week3/camil/StdSortList.icl delete mode 100644 week3/camil/StdSortListTest.icl delete mode 100644 week3/camil/StdStack.dcl delete mode 100644 week3/camil/StdStack.icl delete mode 100644 week3/camil/StdStackTest.icl delete mode 100644 week3/mart/StdSortList.dcl delete mode 100644 week3/mart/StdSortList.icl delete mode 100644 week3/mart/StdStack.dcl delete mode 100644 week3/mart/StdStack.icl delete mode 100644 week4/camil/5.4 delete mode 100644 week4/camil/StdSet.dcl delete mode 100644 week4/camil/StdSet.icl delete mode 100644 week4/mart/5.4.txt delete mode 100644 week4/mart/StdSet.dcl delete mode 100644 week4/mart/StdSet.icl delete mode 100644 week4/week4.tar.gz delete mode 100644 week5/camil/Origami.icl delete mode 100644 week5/mart/Origami.icl delete mode 100644 week6/camil/BewijsMapFlatten.icl delete mode 100644 week6/mart/BewijsMapFlatten.icl delete mode 100644 week7/camil/BewijsMeppenEnTippen.icl delete mode 100644 week7/camil/BinSearchTree.dcl delete mode 100644 week7/camil/BinSearchTree.icl delete mode 100644 week7/camil/BinTree.dcl delete mode 100644 week7/camil/BinTree.icl delete mode 100644 week7/mart/BewijsMeppenEnTippen.icl delete mode 100644 week7/mart/BinSearchTree.dcl delete mode 100644 week7/mart/BinSearchTree.icl diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/LICENCE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md deleted file mode 100644 index 32e9eba..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# fp1 diff --git a/fp1/week1/camil/1.1/Start.icl b/fp1/week1/camil/1.1/Start.icl new file mode 100644 index 0000000..b56a850 --- /dev/null +++ b/fp1/week1/camil/1.1/Start.icl @@ -0,0 +1,18 @@ +module Start + +import StdEnv + +Start = expr11 + +expr0 = "Hello World!" +expr1 = "Hello " +++ "World!" +expr2 = 5 +expr3 = 5.5 +//expr4 = 5 + 5.5 +expr5 = [1..10] +expr6 = (expr1,expr2,expr3,expr5) +//expr7 = [expr1,expr2,expr3,expr5] +expr8 = [1,3..10] +expr9 = ['a'..'z'] +expr10 = ['a','c'..'z'] +expr11 = ['Hello World!'] \ No newline at end of file diff --git a/fp1/week1/camil/1.1/antwoorden.txt b/fp1/week1/camil/1.1/antwoorden.txt new file mode 100644 index 0000000..3a223e2 --- /dev/null +++ b/fp1/week1/camil/1.1/antwoorden.txt @@ -0,0 +1,29 @@ +Antwoorden opgave 1.1 +Camil Staps (s4498062) + +1. Het programma wordt gecompileerd. +2. Het programma wordt uitgevoerd. +3. De data types van de variabelen worden automatisch achterhaald door de IDE (en hoeven dus niet expliciet te worden gegeven door de programmeur) + +expr1 "Hello World!" + De strings worden geconcateneerd +expr2 5 + Dit is een Int waarde +expr3 5.5 + Dit is een Real waarde +expr4 Type error; cannot unify types Real and Int + Dat is omdat + is niet gedefinieerd voor Real met Int +expr5 [1,2,3,4,5,6,7,8,9,10] + Dit is een korte schrijfwijze voor deze lijst ([min..max]) +expr6 ("Hello World!",5,5.5,[1,2,3,4,5,6,7,8,9,10]) + Een tupeltje +expr7 Type error; cannot unify types [Int] and Real + Dat is omdat elementen van een lijst hetzelfde type moeten hebben, en dat hier niet het geval is +expr8 [1,3,5,7,9] + Een andere vorm van expr5 waarmee in het begin wordt aangegeven wat de interval is +expr9 ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] + Een lijst van karakters +expr10 ['a','c','e','g','i','k','m','o','q','s','u','w','y'] + Een combinatie van expr9 en expr8 +expr11 ['H','e','l','l','o',' ','W','o','r','l','d','!'] + Blijkbaar wordt ['...'] als lijst van karakters beschouwd diff --git a/fp1/week1/camil/2.1/NotatieFuncties.icl b/fp1/week1/camil/2.1/NotatieFuncties.icl new file mode 100644 index 0000000..bab2054 --- /dev/null +++ b/fp1/week1/camil/2.1/NotatieFuncties.icl @@ -0,0 +1,39 @@ +module NotatieFuncties + +import StdEnv + +f1 :: Int +f1 = 1 + 5 + +f2 :: Int +f2 = (+) 1 5 + +f3 :: Int Int -> Int +f3 m n +| m < n = m +| otherwise = n + +f4 :: String Int -> String +f4 s n +| n <= 0 = "" +| otherwise = s +++ f4 s (n-1) + +f5 :: Int Int -> Int +f5 x 0 = x +f5 x y = f5 y (x rem y) + +f6 :: (Int,Int) -> Int +f6 x = fst x + snd x + +f7 :: (a,b) -> (b,a) +f7 (a,b) = (b,a) + +f8 :: (a,a) -> (a,a) +f8 x = f7 (f7 x) + +//Start = (f3 1 5, f3 4 3, f3 6 6) +//Start = f4 "ab" 4 +//Start = (f5 13 5, f5 8 4, f5 20 20) +//Start = f6 (2,3) +//Start = f7 (5,7) +Start = f8 (5,7) diff --git a/fp1/week1/camil/2.1/antwoorden.txt b/fp1/week1/camil/2.1/antwoorden.txt new file mode 100644 index 0000000..c0c98d6 --- /dev/null +++ b/fp1/week1/camil/2.1/antwoorden.txt @@ -0,0 +1,8 @@ +f1 5+1=6; constant +f2 Reverse polix notation voor f1; zelfde functie dus +f3 Geeft de kleinste van twee integers terug +f4 Herhaalt s n keer +f5 Geeft de ggd van x en y met Euclides' algoritme +f6 Geeft de optelling x+y voor een tupel (x,y) +f7 Flipt de twee elementen van een tupel +f8 Flipt de twee elementen van een tupel twee keer (heeft geen effect) diff --git a/fp1/week1/camil/2.11/BottlesOfBeer.icl b/fp1/week1/camil/2.11/BottlesOfBeer.icl new file mode 100644 index 0000000..70628a1 --- /dev/null +++ b/fp1/week1/camil/2.11/BottlesOfBeer.icl @@ -0,0 +1,21 @@ +module BottlesOfBeer + +import StdEnv + +Start = [(fst_line x +++ "\n" +++ snd_line x +++ "\n\n") \\ x <- [99,98..0]] + +fst_line :: Int -> String +fst_line n = btl n True +++ wall +++ ", " +++ btl n False +++ " of beer." + +snd_line :: Int -> String +snd_line 0 = "Go to the store and buy some more, " +++ btl 99 False +++ wall +++ "." +snd_line n = "Take one down and pass it around, " +++ btl (n-1) False +++ wall +++ "." + +btl :: Int Bool -> String +btl 0 True = "No more bottles" +btl 0 False = "no more bottles" +btl 1 b = "1 bottle" +btl n b = toString n +++ " bottles" + +wall :: String +wall = " of beer on the wall" \ No newline at end of file diff --git a/fp1/week1/camil/2.2/VindtDeRedex.icl b/fp1/week1/camil/2.2/VindtDeRedex.icl new file mode 100644 index 0000000..c7ec330 --- /dev/null +++ b/fp1/week1/camil/2.2/VindtDeRedex.icl @@ -0,0 +1,17 @@ +module VindtDeRedex + +import StdEnv + +e1 = 42 + +e2 = 1 + 125 * 8 / 10 - 59 + +e3 = not True || True && False + +e4 = 1 + 2 == 6 - 3 + +e5 = "1 + 2" == "6 - 3" + +e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222" + +Start = e6 diff --git a/fp1/week1/camil/2.2/antwoorden.txt b/fp1/week1/camil/2.2/antwoorden.txt new file mode 100644 index 0000000..413465c --- /dev/null +++ b/fp1/week1/camil/2.2/antwoorden.txt @@ -0,0 +1,42 @@ +e1 = 42 Is elementair + +e2 = 1 + 125 * 8 / 10 - 59 +e2 = (1 + ((125 * 8) / 10)) - 59 + ------- +e2 = (1 + (1000 / 10)) - 59 + --------- +e2 = (1 + 100) - 59 + ------- +e2 = 101 - 59 + -------- +e2 = 42 + +e3 = not True || True && False +e3 = (not True) || (True && False) + -------- +e3 = False || (True && False) + ------------- +e3 = False || False + -------------- +e3 = False + +e4 = 1 + 2 == 6 - 3 +e4 = (1 + 2) == (6 - 3) + ----- +e4 = 3 == (6 - 3) + ----- +e4 = 3 == 3 +e4 = True + +e5 = "1 + 2" == "6 - 3" + ------------------ +e5 = False + +e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222" +e6 = "1111 + 2222" == (("1111" +++ " + ") +++ "2222") + ----------------- +e6 = "1111 + 2222" == ("1111 + " +++ "2222") + -------------------- +e6 = "1111 + 2222" == "1111 + 2222" + ------------------------------ +e6 = True diff --git a/fp1/week1/camil/2.3/MatchStrings.dcl b/fp1/week1/camil/2.3/MatchStrings.dcl new file mode 100644 index 0000000..527447c --- /dev/null +++ b/fp1/week1/camil/2.3/MatchStrings.dcl @@ -0,0 +1,8 @@ +definition module MatchStrings + +head :: String -> Char +tail :: String -> String +is_gelijk :: String String -> Bool +is_deelstring :: String String -> Bool +is_deel :: String String -> Bool +is_match :: String String -> Bool diff --git a/fp1/week1/camil/2.3/MatchStrings.icl b/fp1/week1/camil/2.3/MatchStrings.icl new file mode 100644 index 0000000..17859ae --- /dev/null +++ b/fp1/week1/camil/2.3/MatchStrings.icl @@ -0,0 +1,48 @@ +implementation module MatchStrings + +import StdEnv + +head :: String -> Char +head "" = abort "head uitgevoerd op lege string" +head s = s.[0] + +tail :: String -> String +tail "" = abort "tail uitgevoerd op lege string" +tail s = s % (1, size s - 1) + +is_gelijk :: String String -> Bool +is_gelijk "" "" = True +is_gelijk a "" = False +is_gelijk "" b = False +is_gelijk a b = (head a == head b) && (is_gelijk (tail a) (tail b)) + +is_deelstring :: String String -> Bool +is_deelstring "" b = True +is_deelstring a "" = False +is_deelstring a b = is_gelijk a (b % (0, size a - 1)) || is_deelstring a (tail b) + +is_deel :: String String -> Bool +is_deel "" b = True +is_deel a "" = False +is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b) + +is_match :: String String -> Bool +is_match "" "" = True +is_match "" b = False +is_match "*" "" = True +is_match a "" = False +is_match a b = (head a == '.' || head a == head b) && is_match (tail a) (tail b) || head a == '*' && (is_match a (tail b) || is_match (tail a) b) + +//Start = (head pink_floyd, tail pink_floyd) +//Start = is_gelijk "" " " +//Start = is_deelstring "there" pink_floyd +//Start = is_deelstring "there" marillion +//Start = is_deel "there" marillion +//Start = is_deel "she and her" pink_floyd +//Start = is_deel radiohead pink_floyd +//Start = is_match "*.here*.here*." pink_floyd +//Start = is_match ".here.here." pink_floyd + +pink_floyd = "Is there anybody in there?" +marillion = "Just for the record" +radiohead = "There there" diff --git a/fp1/week1/mart/1.txt b/fp1/week1/mart/1.txt new file mode 100644 index 0000000..7ac4230 --- /dev/null +++ b/fp1/week1/mart/1.txt @@ -0,0 +1,3 @@ +1.1: +1.2: +Beide niet mogelijk zonder IDE(linux) diff --git a/fp1/week1/mart/MatchStrings.dcl b/fp1/week1/mart/MatchStrings.dcl new file mode 100644 index 0000000..527447c --- /dev/null +++ b/fp1/week1/mart/MatchStrings.dcl @@ -0,0 +1,8 @@ +definition module MatchStrings + +head :: String -> Char +tail :: String -> String +is_gelijk :: String String -> Bool +is_deelstring :: String String -> Bool +is_deel :: String String -> Bool +is_match :: String String -> Bool diff --git a/fp1/week1/mart/MatchStrings.icl b/fp1/week1/mart/MatchStrings.icl new file mode 100644 index 0000000..f10df45 --- /dev/null +++ b/fp1/week1/mart/MatchStrings.icl @@ -0,0 +1,54 @@ +implementation module MatchStrings + +import StdEnv + +head :: String -> Char +head "" = abort "Empty String" +head s = s.[0] + +tail :: String -> String +tail "" = abort "Empty String" +tail s = s % (1, size s - 1) + +is_gelijk :: String String -> Bool +is_gelijk "" "" = True +is_gelijk a b = (size a == size b) && (head a == head b) && is_gelijk (tail a) (tail b) + +is_deelstring :: String String -> Bool +is_deelstring _ "" = False +is_deelstring a b = is_begin a b || is_deelstring a (tail b) + +is_begin :: String String -> Bool +is_begin "" _ = True +is_begin _ "" = False +is_begin a b = head a == head b && is_begin (tail a) (tail b) + +is_deel :: String String -> Bool +is_deel "" _ = True +is_deel _ "" = False +is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b) + +is_match :: String String -> Bool +is_match a b = is_begin_match a b || size b > 0 && is_begin_match a (tail b) + +is_begin_match :: String String -> Bool +is_begin_match "" _ = True +is_begin_match a "" = head a == '*' && size a == 1 +is_begin_match a b +| head a == '.' || head a == head b = is_begin_match (tail a) (tail b) +| head a == '*' = is_begin_match a (tail b) || is_begin_match (tail a) b +| otherwise = False + +//Start= (head pink_floyd, tail pink_floyd) +//Start= is_gelijk "" " " +//Start= is_deelstring "there" pink_floyd +//Start= is_deelstring "there" marillion +//Start= is_deel "there" marillion +//Start= is_deel "she and her" pink_floyd +//Start= is_deel radiohead pink_floyd +//Start= is_match "*.here*.here*." pink_floyd +//Start= is_match ".here.here." pink_floyd + +pink_floyd= "Is there anybody in there?" +marillion= "Just for the record" +radiohead= "There there" diff --git a/fp1/week2/camil/Makefile b/fp1/week2/camil/Makefile new file mode 100644 index 0000000..9095df9 --- /dev/null +++ b/fp1/week2/camil/Makefile @@ -0,0 +1,4 @@ +all: + clm StdT -o StdT + clm TupleOverloading -o TupleOverloading + clm VectorOverloading -o VectorOverloading diff --git a/fp1/week2/camil/StdT.dcl b/fp1/week2/camil/StdT.dcl new file mode 100644 index 0000000..ca97fdc --- /dev/null +++ b/fp1/week2/camil/StdT.dcl @@ -0,0 +1,18 @@ +definition module StdT + +import StdOverloaded + +:: T + +instance == T +instance < T + +instance zero T +instance + T +instance - T + +instance toInt T +instance fromInt T + +instance toString T +instance fromString T diff --git a/fp1/week2/camil/StdT.icl b/fp1/week2/camil/StdT.icl new file mode 100644 index 0000000..03c8645 --- /dev/null +++ b/fp1/week2/camil/StdT.icl @@ -0,0 +1,37 @@ +/** + * Mart Lubbers, s4109503 + * Camil Staps, s4498062 + */ + +implementation module StdT + +import StdEnv + +:: T = {m :: Int, s :: Int} + +instance == T where == a b = a.m == b.m && a.s == b.s +instance < T where < a b = a.m < b.m || a.m == b.m && a.s < b.s + +instance zero T where zero = {m = zero, s = zero} +instance + T where + a b = fromInt (toInt a + toInt b) +instance - T where - a b = if (a < b) zero (fromInt (toInt a - toInt b)) + +instance toInt T where toInt a = a.m * 60 + a.s +instance fromInt T where fromInt n = if (n < 0) zero {m = n/60, s = n rem 60} + +instance toString T where + toString {m = x, s = 0} = toString x +++ ":00" + toString a = toString a.m +++ ":" +++ (if (a.s < 10) "0" "") +++ toString a.s +instance fromString T where + fromString s = if (s.[size s - 3] == ':') + {m = toInt (s % (0, size s - 4)), s = toInt (s % (size s - 2, size s - 1))} + zero + +Start :: (Bool, Bool, T, T, T, Int, String, T, T) +Start = (LOTR == Tea, Tea < LOTR, + zero + LOTR, LOTR + Tea, Tea - LOTR, + toInt LOTR, toString Tea, + fromString "5:40", fromString "foo") + +LOTR = {m=178, s=0} +Tea = {m=0,s=41} diff --git a/fp1/week2/camil/TupleOverloading.dcl b/fp1/week2/camil/TupleOverloading.dcl new file mode 100644 index 0000000..6831948 --- /dev/null +++ b/fp1/week2/camil/TupleOverloading.dcl @@ -0,0 +1,25 @@ +definition module TupleOverloading + +import StdEnv + +instance + (a,b) | + a & + b +instance + (a,b,c) | + a & + b & + c + + +instance - (a,b) | - a & - b +instance - (a,b,c) | - a & - b & - c + +instance * (a,b) | * a & * b +instance * (a,b,c) | * a & * b & * c + +instance / (a,b) | / a & / b +instance / (a,b,c) | / a & / b & / c + +instance zero (a,b) | zero a & zero b +instance zero (a,b,c) | zero a & zero b & zero c + +instance one (a,b) | one a & one b +instance one (a,b,c) | one a & one b & one c + +instance ~ (a,b) | ~ a & ~ b +instance ~ (a,b,c) | ~ a & ~ b & ~ c diff --git a/fp1/week2/camil/TupleOverloading.icl b/fp1/week2/camil/TupleOverloading.icl new file mode 100644 index 0000000..0ea437d --- /dev/null +++ b/fp1/week2/camil/TupleOverloading.icl @@ -0,0 +1,53 @@ +/** + * Mart Lubbers, s4109503 + * Camil Staps, s4498062 + */ + +implementation module TupleOverloading + +import StdEnv + +instance + (a,b) | + a & + b where + + (a,b) (c,d) = (a+c,b+d) +instance + (a,b,c) | + a & + b & + c where + + (a,b,c) (d,e,f) = (a+d,b+e,c+f) + +instance - (a,b) | - a & - b where + - (a,b) (c,d) = (a-c,b-d) +instance - (a,b,c) | - a & - b & - c where + - (a,b,c) (d,e,f) = (a-d,b-e,c-f) + +instance * (a,b) | * a & * b where + * (a,b) (c,d) = (a*c,b*d) +instance * (a,b,c) | * a & * b & * c where + * (a,b,c) (d,e,f) = (a*d,b*e,c*f) + +instance / (a,b) | / a & / b where + / (a,b) (c,d) = (a/c,b/d) +instance / (a,b,c) | / a & / b & / c where + / (a,b,c) (d,e,f) = (a/d,b/e,c/f) + +instance zero (a,b) | zero a & zero b where + zero = (zero, zero) +instance zero (a,b,c) | zero a & zero b & zero c where + zero = (zero, zero, zero) + +instance one (a,b) | one a & one b where + one = (one, one) +instance one (a,b,c) | one a & one b & one c where + one = (one, one, one) + +instance ~ (a,b) | ~ a & ~ b where + ~ (a,b) = (~ a, ~ b) +instance ~ (a,b,c) | ~ a & ~ b & ~ c where + ~ (a,b,c) = (~ a, ~ b, ~ c) + +Start = (test (1,2), test (1,2,3)) + +test a = ( zero + a == a && a == a + zero + , a - zero == a && a == ~ (zero - a) + , one * a == a && a == a * one + , zero * a == zero && zero == a * zero + , a / one == a + , ~ (~ a) == a + ) diff --git a/fp1/week2/camil/VectorOverloading.dcl b/fp1/week2/camil/VectorOverloading.dcl new file mode 100644 index 0000000..76f8520 --- /dev/null +++ b/fp1/week2/camil/VectorOverloading.dcl @@ -0,0 +1,14 @@ +definition module VectorOverloading + +import StdEnv + +:: Vector2 a = {x0 :: a, x1 :: a} + +instance == (Vector2 a) | == a +instance zero (Vector2 a) | zero a +instance one (Vector2 a) | one a +instance ~ (Vector2 a) | ~ a +instance + (Vector2 a) | + a +instance - (Vector2 a) | - a +instance * (Vector2 a) | * a +instance / (Vector2 a) | / a diff --git a/fp1/week2/camil/VectorOverloading.icl b/fp1/week2/camil/VectorOverloading.icl new file mode 100644 index 0000000..4c9c84a --- /dev/null +++ b/fp1/week2/camil/VectorOverloading.icl @@ -0,0 +1,37 @@ +/** + * Mart Lubbers, s4109503 + * Camil Staps, s4498062 + */ + +implementation module VectorOverloading + +import StdEnv + +:: Vector2 a = {x0 :: a, x1 :: a} + +instance == (Vector2 a) | == a where + == a b = a.x0 == b.x0 && a.x1 == b.x1 +instance zero (Vector2 a) | zero a where + zero = {x0 = zero, x1 = zero} +instance one (Vector2 a) | one a where + one = {x0 = one, x1 = one} +instance ~ (Vector2 a) | ~ a where + ~ a = {x0 = ~a.x0, x1 = ~a.x1} +instance + (Vector2 a) | + a where + + a b = {x0 = a.x0 + b.x0, x1 = a.x1 + b.x1} +instance - (Vector2 a) | - a where + - a b = {x0 = a.x0 - b.x0, x1 = a.x1 - b.x1} +instance * (Vector2 a) | * a where + * a b = {x0 = a.x0 * b.x0, x1 = a.x1 * b.x1} +instance / (Vector2 a) | / a where + / a b = {x0 = a.x0 / b.x0, x1 = a.x1 / b.x1} + +Start = test {x0=1,x1=2} + +test a = ( zero + a == a && a == a + zero + , a - zero == a && a == ~ (zero - a) + , one * a == a && a == a * one + , zero * a == zero && zero == a * zero + , a / one == a + , ~ (~ a) == a + ) diff --git a/fp1/week2/mart/Makefile b/fp1/week2/mart/Makefile new file mode 100644 index 0000000..a35595b --- /dev/null +++ b/fp1/week2/mart/Makefile @@ -0,0 +1,21 @@ +PATHS=-I ~/downloads/clean/lib/StdLib -I ~/downloads/clean/lib/MersenneTwister/ -I ~/downloads/usr/lib64/clean/Gast/ -I ~/downloads/clean/lib/Generics/ +FLAGS=-v + +all: tuple vector stdtime + +tuple: TupleOverloading.icl TupleOverloading.dcl + clm $(FLAGS) $(PATHS) TupleOverloadingTest -o TupleOverloadingTest + +vector: VectorOverloading.icl VectorOverloading.dcl + clm $(FLAGS) $(PATHS) VectorOverloadingTest -o VectorOverloadingTest + +stdtime: StdT.icl StdT.dcl + clm $(FLAGS) $(PATHS) StdTTest -o StdTTest + +testall: + ./StdTTest + ./TupleOverloadingTest + ./VectorOverloadingTest + +clean: + $(RM) -r Clean\ System\ Files a.out TupleOverloadingTest VectorOverloadingTest StdTTest diff --git a/fp1/week2/mart/StdT.dcl b/fp1/week2/mart/StdT.dcl new file mode 100644 index 0000000..f4f0d75 --- /dev/null +++ b/fp1/week2/mart/StdT.dcl @@ -0,0 +1,18 @@ +definition module StdT + +import StdOverloaded + +:: T + +instance == T +instance < T + +instance zero T +instance + T +instance - T + +instance toInt T +instance fromInt T + +instance toString T +instance fromString T diff --git a/fp1/week2/mart/StdT.icl b/fp1/week2/mart/StdT.icl new file mode 100644 index 0000000..01bee7d --- /dev/null +++ b/fp1/week2/mart/StdT.icl @@ -0,0 +1,35 @@ +implementation module StdT + +import StdEnv + +:: T = {m :: Int, s :: Int} + +instance == T where + == a b = a.m == b.m && a.s == b.s +instance < T where + < a b = a.m < b.m || a.s == b.s && a.s < b.s + +instance zero T where + zero = {m=zero, s=zero} +instance + T where + + a b = fromInt (toInt a + toInt b) +instance - T where + - a b = fromInt (toInt a - toInt b) + +instance toInt T where + toInt a = a.m*60 + a.s +instance fromInt T where + fromInt a + | a<0 = zero + | otherwise = {m=a/60, s=a rem 60} + +instance toString T where + toString {m=ms, s=0} = toString ms +++ ":00" + toString {m=ms, s=ss} + | ss < 10 = toString ms +++ ":0" +++ toString ss + | otherwise = toString ms +++ ":" +++ toString ss + +instance fromString T where + fromString a + | a.[size a - 3] == ':' = {m = toInt (a % (0, (size a) - 4)), s = toInt (a % ((size a) - 2, size a))} + | otherwise = zero diff --git a/fp1/week2/mart/StdTTest.icl b/fp1/week2/mart/StdTTest.icl new file mode 100644 index 0000000..6af64fc --- /dev/null +++ b/fp1/week2/mart/StdTTest.icl @@ -0,0 +1,45 @@ +module StdTTest + +/* Test module StdTTest + Voor werken met Gast: + (*) gebruik Environment 'Gast' + (*) zet Project Options op 'Basic Values Only' +*/ + +import StdT +import StdEnv +import gast + +Start + = testn 1000 + (\ i -> + gelijkheid_is_symmetrisch i /\ + ordening_is_monotoon i /\ + negatieve_tijd_bestaat_niet i /\ + omzetten_naar_Int_is_consistent i /\ + parse_print_is_consistent i /\ + True + ) + +t :: Int -> T +t x = fromInt x + +gelijkheid_is_symmetrisch :: Int -> Property +gelijkheid_is_symmetrisch i = name "gelijkheid_is_symmetrisch" + (t i == t i) + +ordening_is_monotoon :: Int -> Property +ordening_is_monotoon i = name "ordening_is_monotoon" + ((i <= i+1) ==> t i <= t (i+1)) + +negatieve_tijd_bestaat_niet :: Int -> Property +negatieve_tijd_bestaat_niet i = name "negatieve_tijd_bestaat_niet" + ((i + 1 >= i) ==> t i - t (i+1) == zero) + +omzetten_naar_Int_is_consistent :: Int -> Property +omzetten_naar_Int_is_consistent i = name "omzetten_naar_Int_is_consistent" + ((abs i >= 0) ==> toInt (t (abs i)) == abs i) + +parse_print_is_consistent :: Int -> Property +parse_print_is_consistent i = name "parse_print_is_consistent" + (fromString (toString (t i)) == t i) diff --git a/fp1/week2/mart/TupleOverloading.dcl b/fp1/week2/mart/TupleOverloading.dcl new file mode 100644 index 0000000..6831948 --- /dev/null +++ b/fp1/week2/mart/TupleOverloading.dcl @@ -0,0 +1,25 @@ +definition module TupleOverloading + +import StdEnv + +instance + (a,b) | + a & + b +instance + (a,b,c) | + a & + b & + c + + +instance - (a,b) | - a & - b +instance - (a,b,c) | - a & - b & - c + +instance * (a,b) | * a & * b +instance * (a,b,c) | * a & * b & * c + +instance / (a,b) | / a & / b +instance / (a,b,c) | / a & / b & / c + +instance zero (a,b) | zero a & zero b +instance zero (a,b,c) | zero a & zero b & zero c + +instance one (a,b) | one a & one b +instance one (a,b,c) | one a & one b & one c + +instance ~ (a,b) | ~ a & ~ b +instance ~ (a,b,c) | ~ a & ~ b & ~ c diff --git a/fp1/week2/mart/TupleOverloading.icl b/fp1/week2/mart/TupleOverloading.icl new file mode 100644 index 0000000..2995fbd --- /dev/null +++ b/fp1/week2/mart/TupleOverloading.icl @@ -0,0 +1,49 @@ +implementation module TupleOverloading + +import StdEnv + +instance + (a,b) | + a & + b where + + (a,b) (c,d) = (a+c,b+d) +instance + (a,b,c) | + a & + b & + c where + + (a,b,c) (d,e,f) = (a+d,b+e,c+f) + + +instance - (a,b) | - a & - b where + - (a,b) (c,d) = (a-c,b-d) +instance - (a,b,c) | - a & - b & - c where + - (a,b,c) (d,e,f) = (a-d,b-e,c-f) + +instance * (a,b) | * a & * b where + * (a,b) (c,d) = (a*c,b*d) +instance * (a,b,c) | * a & * b & * c where + * (a,b,c) (d,e,f) = (a*d,b*e,c*f) + +instance / (a,b) | / a & / b where + / (a,b) (c,d) = (a/c,b/d) +instance / (a,b,c) | / a & / b & / c where + / (a,b,c) (d,e,f) = (a/d,b/e,c/f) + +instance zero (a,b) | zero a & zero b where + zero = (zero,zero) +instance zero (a,b,c) | zero a & zero b & zero c where + zero = (zero,zero,zero) + +instance one (a,b) | one a & one b where + one = (one,one) +instance one (a,b,c) | one a & one b & one c where + one = (one,one,one) + +instance ~ (a,b) | ~ a & ~ b where + ~ (a,b) = (~a,~b) +instance ~ (a,b,c) | ~ a & ~ b & ~ c where + ~ (a,b,c) = (~a,~b,~c) + +Start = (test (1,2), test (1,2,3)) + +test a = ( zero + a == a && a == a + zero + , a - zero == a && a == ~ (zero - a) + , one * a == a && a == a * one + , zero * a == zero && zero == a * zero + , a / one == a + , ~ (~ a) == a + ) diff --git a/fp1/week2/mart/TupleOverloadingTest.icl b/fp1/week2/mart/TupleOverloadingTest.icl new file mode 100644 index 0000000..91417f7 --- /dev/null +++ b/fp1/week2/mart/TupleOverloadingTest.icl @@ -0,0 +1,64 @@ +module TupleOverloadingTest + +/* Test module VectorOverloading + Voor werken met Gast: + (*) gebruik Environment 'Gast' + (*) zet Project Options op 'Basic Values Only' +*/ + +import TupleOverloading +import StdEnv +import gast + +Start + = testn 1000 + (\v -> + zero_is_neutral_for_addition v /\ + zero_is_neutral_for_subtraction v /\ + one_is_neutral_for_multiplication v /\ + one_is_neutral_for_division v /\ + negation_is_idempotent v /\ + add_then_subtract_yields_identity v /\ + subtract_then_add_yields_identity v /\ + True + ) + +:: Vector2 a :== (a,a) +:: BaseType + :== Int +// :== Real + +zero_is_neutral_for_addition :: (Vector2 BaseType) -> Property +zero_is_neutral_for_addition a = name "zero_is_neutral_for_addition" + (zero + a == a && a == a + zero) + +zero_is_neutral_for_subtraction :: (Vector2 BaseType) -> Property +zero_is_neutral_for_subtraction a = name "zero_is_neutral_for_subtraction" + (a - zero == a && a == ~ (zero - a)) + +one_is_neutral_for_multiplication :: (Vector2 BaseType) -> Property +one_is_neutral_for_multiplication a = name "one_is_neutral_for_multiplication" + (one * a == a && a == a * one) + +zero_is_zero_for_multiplication :: (Vector2 BaseType) -> Property +zero_is_zero_for_multiplication a = name "zero_is_zero_for_multiplication" + (zero * a == zero && zero == a * zero) + +one_is_neutral_for_division :: (Vector2 BaseType) -> Property +one_is_neutral_for_division a = name "one_is_neutral_for_division" + (a / one == a) + +negation_is_idempotent :: (Vector2 BaseType) -> Property +negation_is_idempotent a = name "negation_is_idempotent" + (~ (~ a) == a) + + +add_then_subtract_yields_identity :: (Vector2 BaseType) -> Property +add_then_subtract_yields_identity a = name "add then subtract" ((a + a) - a == a) + +subtract_then_add_yields_identity :: (Vector2 BaseType) -> Property +subtract_then_add_yields_identity a = name "subtract then add" ((zero - a - a) + a + a == zero) + +//derive genShow (,) +//derive ggen (,) +derive bimap [] diff --git a/fp1/week2/mart/VectorOverloading.dcl b/fp1/week2/mart/VectorOverloading.dcl new file mode 100644 index 0000000..76f8520 --- /dev/null +++ b/fp1/week2/mart/VectorOverloading.dcl @@ -0,0 +1,14 @@ +definition module VectorOverloading + +import StdEnv + +:: Vector2 a = {x0 :: a, x1 :: a} + +instance == (Vector2 a) | == a +instance zero (Vector2 a) | zero a +instance one (Vector2 a) | one a +instance ~ (Vector2 a) | ~ a +instance + (Vector2 a) | + a +instance - (Vector2 a) | - a +instance * (Vector2 a) | * a +instance / (Vector2 a) | / a diff --git a/fp1/week2/mart/VectorOverloading.icl b/fp1/week2/mart/VectorOverloading.icl new file mode 100644 index 0000000..74f6f69 --- /dev/null +++ b/fp1/week2/mart/VectorOverloading.icl @@ -0,0 +1,22 @@ +implementation module VectorOverloading + +import StdEnv + +:: Vector2 a = {x0 :: a, x1 :: a} + +instance == (Vector2 a) | == a where + == a b = a.x0 == b.x0 && a.x1 == b.x1 +instance zero (Vector2 a) | zero a where + zero = {x0=zero, x1=zero} +instance one (Vector2 a) | one a where + one = {x0=one, x1=one} +instance ~ (Vector2 a) | ~ a where + ~ a = {x0= ~a.x0, x1= ~a.x1} +instance + (Vector2 a) | + a where + + a b = {x0=a.x0+b.x0, x1=a.x1+b.x1} +instance - (Vector2 a) | - a where + - a b = {x0=a.x0-b.x0, x1=a.x1-b.x1} +instance * (Vector2 a) | * a where + * a b = {x0=a.x0*b.x0, x1=a.x1*b.x1} +instance / (Vector2 a) | / a where + / a b = {x0=a.x0/b.x0, x1=a.x1/b.x1} diff --git a/fp1/week2/mart/VectorOverloadingTest.icl b/fp1/week2/mart/VectorOverloadingTest.icl new file mode 100644 index 0000000..e5571bb --- /dev/null +++ b/fp1/week2/mart/VectorOverloadingTest.icl @@ -0,0 +1,62 @@ +module VectorOverloadingTest + +/* Test module VectorOverloading + Voor werken met Gast: + (*) gebruik Environment 'Gast' + (*) zet Project Options op 'Basic Values Only' +*/ + +import VectorOverloading +import StdEnv +import gast + +Start + = testn 1000 + (\v -> + zero_is_neutral_for_addition v /\ + zero_is_neutral_for_subtraction v /\ + one_is_neutral_for_multiplication v /\ + one_is_neutral_for_division v /\ + negation_is_idempotent v /\ + add_then_subtract_yields_identity v /\ + subtract_then_add_yields_identity v /\ + True + ) + +:: BaseType + :== Int +// :== Real + +zero_is_neutral_for_addition :: (Vector2 BaseType) -> Property +zero_is_neutral_for_addition a = name "zero_is_neutral_for_addition" + (zero + a == a && a == a + zero) + +zero_is_neutral_for_subtraction :: (Vector2 BaseType) -> Property +zero_is_neutral_for_subtraction a = name "zero_is_neutral_for_subtraction" + (a - zero == a && a == ~ (zero - a)) + +one_is_neutral_for_multiplication :: (Vector2 BaseType) -> Property +one_is_neutral_for_multiplication a = name "one_is_neutral_for_multiplication" + (one * a == a && a == a * one) + +zero_is_zero_for_multiplication :: (Vector2 BaseType) -> Property +zero_is_zero_for_multiplication a = name "zero_is_zero_for_multiplication" + (zero * a == zero && zero == a * zero) + +one_is_neutral_for_division :: (Vector2 BaseType) -> Property +one_is_neutral_for_division a = name "one_is_neutral_for_division" + (a / one == a) + +negation_is_idempotent :: (Vector2 BaseType) -> Property +negation_is_idempotent a = name "negation_is_idempotent" + (~ (~ a) == a) + +add_then_subtract_yields_identity :: (Vector2 BaseType) -> Property +add_then_subtract_yields_identity a = name "add then subtract" ((a + a) - a == a) + +subtract_then_add_yields_identity :: (Vector2 BaseType) -> Property +subtract_then_add_yields_identity a = name "subtract then add" ((zero - a - a) + a + a == zero) + +derive genShow Vector2 +derive ggen Vector2 +derive bimap [] diff --git a/fp1/week2/week2.tar.gz b/fp1/week2/week2.tar.gz new file mode 100644 index 0000000..93c0467 Binary files /dev/null and b/fp1/week2/week2.tar.gz differ diff --git a/fp1/week3/camil/.gitignore b/fp1/week3/camil/.gitignore new file mode 100644 index 0000000..341d5f8 --- /dev/null +++ b/fp1/week3/camil/.gitignore @@ -0,0 +1,2 @@ +/Clean System Files/ +StdStack diff --git a/fp1/week3/camil/StdSortList.dcl b/fp1/week3/camil/StdSortList.dcl new file mode 100644 index 0000000..556dfc0 --- /dev/null +++ b/fp1/week3/camil/StdSortList.dcl @@ -0,0 +1,18 @@ +definition module StdSortList + +import StdClass + +:: SortList a + +newSortList :: SortList a | zero a // lege gesorteerde lijst +memberSort :: a (SortList a) -> Bool | Eq, Ord a // is element van +insertSort :: a (SortList a) -> SortList a | Ord a // voeg element toe +removeFirst :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder eerste voorkomen +removeAll :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder alle voorkomens +elements :: (SortList a) -> [a] // geef alle elementen +count :: (SortList a) -> Int // aantal elementen + +minimum :: (SortList a) -> a // huidige minimum waarde +maximum :: (SortList a) -> a // huidige maximum waarde + +mergeSortList :: (SortList a) (SortList a) -> SortList a | Eq, Ord, zero a // meng gesorteerde lijsten diff --git a/fp1/week3/camil/StdSortList.icl b/fp1/week3/camil/StdSortList.icl new file mode 100644 index 0000000..21778bd --- /dev/null +++ b/fp1/week3/camil/StdSortList.icl @@ -0,0 +1,64 @@ +// Ik kreeg het alleen werkend door de .dcl ook aan te passen. +// Met een record dat het maximum bijhoudt moet je er namelijk vanuit kunnen gaan dat zero gedefinieerd is voor type a. + +implementation module StdSortList + +import StdEnv + +:: SortList a = {list :: [a], max :: a} + +newSortList :: (SortList a) | zero a +newSortList = {list=[], max=zero} + +memberSort :: a (SortList a) -> Bool | Eq, Ord a // is element van +memberSort _ {list=[],max=_} = False +memberSort m l + | minimum l == m = True + | minimum l > m = False + | otherwise = memberSort m {list=(tl l.list),max=l.max} + +insertSort :: a (SortList a) -> SortList a | Ord a // voeg element toe +insertSort m l = insertSort` {list=[],max=l.max} m l +where + insertSort` :: (SortList a) a (SortList a) -> (SortList a) | Ord a + insertSort` l1 m l2 + | count l2 == 0 = {list=l1.list ++ [m], max=m} + | minimum l2 >= m = {list=l1.list ++ [m] ++ l2.list, max=l2.max} + | otherwise = insertSort` {list=l1.list ++ [hd l2.list], max=hd l2.list} m {list=(tl l2.list), max=l2.max} + +removeFirst :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder eerste voorkomen +removeFirst m l = removeFirst` newSortList m l +where + removeFirst` :: (SortList a) a (SortList a) -> (SortList a) | Eq, Ord a + removeFirst` l1 m l2 + | count l2 == 0 = l1 + | minimum l2 > m = {list=l1.list ++ l2.list, max=l2.max} + | minimum l2 == m && count l2 == 1 = {list=l1.list ++ tl l2.list, max=l1.max} + | minimum l2 == m = {list=l1.list ++ tl l2.list, max=l2.max} + | otherwise = removeFirst` {list=(l1.list ++ [hd l2.list]),max=hd l2.list} m {list=(tl l2.list), max=l2.max} + +removeAll :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder alle voorkomens +removeAll m l = removeAll` newSortList m l +where + removeAll` :: (SortList a) a (SortList a) -> (SortList a) | Eq, Ord a + removeAll` l1 m l2 + | count l2 == 0 = l1 + | minimum l2 > m = {list=l1.list ++ l2.list, max=l2.max} + | minimum l2 == m = removeAll` l1 m {list=tl l2.list, max=l2.max} + | otherwise = removeAll` {list=l1.list ++ [hd l2.list], max=hd l2.list} m {list=tl l2.list,max=l2.max} + +elements :: (SortList a) -> [a] // geef alle elementen +elements l = l.list + +count :: (SortList a) -> Int // aantal elementen +count l = length l.list + +minimum :: (SortList a) -> a // huidige minimum waarde +minimum l = hd l.list + +maximum :: (SortList a) -> a // huidige maximum waarde +maximum l = l.max + +mergeSortList :: (SortList a) (SortList a) -> SortList a | Eq, Ord, zero a // meng gesorteerde lijsten +mergeSortList l1 {list=[],max=_} = l1 +mergeSortList l1 l2 = mergeSortList (insertSort (hd l2.list) l1) {list=tl l2.list,max=l2.max} diff --git a/fp1/week3/camil/StdSortListTest.icl b/fp1/week3/camil/StdSortListTest.icl new file mode 100644 index 0000000..411f7ca --- /dev/null +++ b/fp1/week3/camil/StdSortListTest.icl @@ -0,0 +1,107 @@ +module StdSortListTest + +/* Test module StdSortList + Voor werken met Gast: + (*) gebruik Environment 'Gast' + (*) zet Project Options op 'Basic Values Only' en '16M' Maximum Heap Size. +*/ + +import gast +import GenLexOrd +import StdSortList + +Start = testn 10000 + (\n` n2` m -> let n = lst2slst (cast [A,B,C] n` ) + n2 = lst2slst (cast [A,B,C] n2`) + in + leeg_is_leeg /\ + count_matches_elems n /\ + is_sorted_elems n /\ + member_is_member n m /\ + member_na_insert n m /\ + member_na_remove n m /\ + insert_remove_invariant n m /\ + minimum_property n /\ + maximum_property n /\ + merge_additive n n2 /\ + merge_member n n2 m /\ + True + ) + +:: Enum = A | B | C + +derive bimap [] +derive ggen Enum +derive genShow Enum +derive gEq Enum +derive gLexOrd Enum +instance == Enum where (==) x y = gEq{|*|} x y +instance < Enum where (<) x y = gEq{|*|} (gLexOrd{|*|} x y) LT + +// clean should have something like this! +cast :: a a -> a +cast _ x = x + +leeg_is_leeg :: Property +leeg_is_leeg + = name "leeg_is_leeg" + (count newSortList == 0) + +count_matches_elems :: (SortList a) -> Property | Eq, Ord a +count_matches_elems n + = name "count_matches_elems" + (length (elements n) == count n) + +is_sorted_elems :: (SortList a) -> Property | Eq, Ord a +is_sorted_elems n + = name "is_sorted_elems" + (isSorted (elements n)) + where isSorted lst = and [ x<=y \\ x<-lst & y<-tl lst ] + +member_is_member :: (SortList a) a -> Property | Eq, Ord a +member_is_member lst e + = name "member_is_member" + ((isMember e (elements lst)) <==> (memberSort e lst)) + +member_na_insert :: (SortList a) a -> Property | Eq, Ord a +member_na_insert lst e + = name "member_na_insert" + (memberSort e (insertSort e lst)) + +member_na_remove :: (SortList a) a -> Property | Eq, Ord a +member_na_remove lst e + = name "member_na_remove" + (not (memberSort e (removeAll e lst))) + +insert_remove_invariant :: (SortList a) a -> Property | Eq, Ord a +insert_remove_invariant lst e + = name "insert_remove_invariant" + (memberSort e lst <==> memberSort e lst`) + where lst` = removeFirst e (insertSort e lst) + +minimum_property :: (SortList a) -> Property | Eq,Ord a +minimum_property n + = name "minimum_property" + (count n > 0 ==> (memberSort min n /\ all ((<=) min) (elements n))) + where min = minimum n + +maximum_property :: (SortList a) -> Property | Eq,Ord a +maximum_property n + = name "maximum_property" + (count n > 0 ==> (memberSort max n /\ all ((>=) max) (elements n))) + where max = maximum n + +merge_member :: (SortList a) (SortList a) a -> Property | Eq,Ord a +merge_member n m e + = name "merge_member" + (memberSort e nm <==> (memberSort e n \/ memberSort e m)) + where nm = mergeSortList n m + +merge_additive :: (SortList a) (SortList a) -> Property | Eq,Ord a +merge_additive n m + = name "merge_additive" + (count n + count m == count nm) + where nm = mergeSortList n m + +lst2slst :: [a] -> SortList a | Eq,Ord a +lst2slst xs = seq (map insertSort xs) newSortList diff --git a/fp1/week3/camil/StdStack.dcl b/fp1/week3/camil/StdStack.dcl new file mode 100644 index 0000000..8c861a1 --- /dev/null +++ b/fp1/week3/camil/StdStack.dcl @@ -0,0 +1,13 @@ +definition module StdStack + +:: Stack a + +newStack :: Stack a // lege stack +push :: a (Stack a) -> Stack a // plaats nieuw element bovenop de stack +pushes :: [a] (Stack a) -> Stack a // plaats elementen achtereenvolgens bovenop stack +pop :: (Stack a) -> Stack a // haal top element van stack +popn :: Int (Stack a) -> Stack a // haal bovenste $n$ top elementen van stack +top :: (Stack a) -> a // geef top element van stack +topn :: Int (Stack a) -> [a] // geef bovenste $n$ top elementen van stack +elements :: (Stack a) -> [a] // geef alle elementen van stack +count :: (Stack a) -> Int // tel aantal elementen in stack diff --git a/fp1/week3/camil/StdStack.icl b/fp1/week3/camil/StdStack.icl new file mode 100644 index 0000000..dd51a94 --- /dev/null +++ b/fp1/week3/camil/StdStack.icl @@ -0,0 +1,66 @@ +implementation module StdStack + +import StdEnv +import StdList + +:: Stack a :== [a] + +newStack :: (Stack a) +newStack = [] + +push :: a (Stack a) -> (Stack a) +push a s = [a] ++ s + +pop :: (Stack a) -> (Stack a) +pop [a:s] = s +pop [] = [] + +popn :: Int (Stack a) -> (Stack a) +popn 0 s = s +popn n s = popn (n-1) (pop s) + +pushes :: [a] (Stack a) -> (Stack a) +pushes [] s = s +pushes a s = pushes (tl a) (push (hd a) s) + +top :: (Stack a) -> a +top [] = abort "`top s` with s = []" +top s = hd s + +topn :: Int (Stack a) -> [a] +topn n s + | n > length s = abort "`topn n s` with n > length s" + | otherwise = take n s + +count :: (Stack a) -> Int +count s = length s + +elements :: (Stack a) -> [a] +elements s = s + +Start = ( "s0 = newStack = ", s0,'\n' + , "s1 = push 1 s0 = ", s1,'\n' + , "s2 = pushes [2..5] s1 = ",s2,'\n' + , "s3 = pop s2 = ", s3,'\n' + , "s4 = popn 3 s3 = ", s4,'\n' + , "s5 = top s4 = ", s5,'\n' + , "s6 = topn 3 s2 = ", s6,'\n' + , "s7 = elements s2 = ", s7,'\n' +// , "s8 = push 10 s1 = ", s8,'\n' +// , "s9 = popn 10 s8 = ", s9,'\n' +// , "sa = topn 5 s4 = ", sa,'\n' +// , "sb = top s0 = ", sb,'\n' + ) +where + s0 = newStack + s1 = push 1 s0 + s2 = pushes [2..5] s1 + s3 = pop s2 + s4 = popn 3 s3 + s5 = top s4 + s6 = topn 3 s2 + s7 = elements s2 +// s8 = push 10 s1 +// s9 = popn 10 s8 +// sa = topn 5 s4 +// sb = top s0 diff --git a/fp1/week3/camil/StdStackTest.icl b/fp1/week3/camil/StdStackTest.icl new file mode 100644 index 0000000..8127f53 --- /dev/null +++ b/fp1/week3/camil/StdStackTest.icl @@ -0,0 +1,60 @@ +module StdStackTest + +/* Test module StdStack + Voor werken met Gast: + (*) gebruik Environment 'Gast' + (*) zet Project Options op 'Basic Values Only' en '2M' Maximum Heap Size +*/ + +import gast +import StdStack + +Start + = testn 1000 + (\x n -> + newStack_is_empty /\ + stack_is_reverse n /\ + pop_empty_is_ok /\ + top_na_push n x /\ + pop_na_push x /\ + count_counts n x /\ + pop_maakt_stack_korter n /\ + True + ) + +newStack_is_empty :: Property +newStack_is_empty = name "newStack_is_empty" (isEmpty (elements empty)) + +stack_is_reverse :: Int -> Property +stack_is_reverse n = name "stack_is_reverse" + (elements (pushes [1..n`] newStack) == reverse [1..n`]) +where n` = min (abs n) 100 + +pop_empty_is_ok :: Property +pop_empty_is_ok = name "pop_empty_is_ok" (count (pop empty) == 0) + +top_na_push :: Int Int -> Property +top_na_push x n = name "top_na_push" + (top (push x (pushes [1..n`] newStack)) == x) +where n` = min (abs n) 100 + +pop_na_push :: Int -> Property +pop_na_push a = name "pop_na_push" + (top (pop (pop (pushes [a,b,c] newStack))) == a) +where b = a + a + one + c = b + a + one + +count_counts :: Int Int -> Property +count_counts n x = name "count_counts" + (length (elements stack) == count stack) +where stack = pushes [1..n`] newStack + n` = min (abs n) 100 + +pop_maakt_stack_korter :: Int -> Property +pop_maakt_stack_korter n = name "pop_maakt_stack_korter" + (count stack == 0 || count (pop stack) == count stack - 1) +where stack = pushes [1..n`] newStack + n` = min (abs n) 100 + +empty :: Stack Int +empty = newStack diff --git a/fp1/week3/mart/StdSortList.dcl b/fp1/week3/mart/StdSortList.dcl new file mode 100644 index 0000000..46bd238 --- /dev/null +++ b/fp1/week3/mart/StdSortList.dcl @@ -0,0 +1,18 @@ +definition module StdSortList + +import StdClass + +:: SortList a + +newSortList :: SortList a // lege gesorteerde lijst +memberSort :: a (SortList a) -> Bool | Eq, Ord a // is element van +insertSort :: a (SortList a) -> SortList a | Ord a // voeg element toe +removeFirst :: a (SortList a) -> SortList a | Eq, Ord a // verwijder eerste voorkomen +removeAll :: a (SortList a) -> SortList a | Eq, Ord a // verwijder alle voorkomens +elements :: (SortList a) -> [a] // geef alle elementen +count :: (SortList a) -> Int // aantal elementen + +minimum :: (SortList a) -> a // huidige minimum waarde +maximum :: (SortList a) -> a // huidige maximum waarde + +mergeSortList :: (SortList a) (SortList a) -> SortList a | Eq, Ord a // meng gesorteerde lijsten diff --git a/fp1/week3/mart/StdSortList.icl b/fp1/week3/mart/StdSortList.icl new file mode 100644 index 0000000..db71a36 --- /dev/null +++ b/fp1/week3/mart/StdSortList.icl @@ -0,0 +1,50 @@ +implementation module StdSortList + +import StdEnv + +:: SortList a :== ([a], a) + +newSortList :: SortList a +newSortList = ([], abort "Empty list") + +memberSort :: a (SortList a) -> Bool | Eq, Ord a +memberSort e ([], y) = y +memberSort e ([x:xs], y) +| e == x = True +| e > x = False +| otherwise = memberSort e (xs, y) + +insertSort :: a (SortList a) -> SortList a | Ord a +insertSort e ([], y) = ([e], e) +insertSort e ([x:xs], y) +| e <= x = ([e:x:xs], y) +| otherwise = ([x:fst result], snd result) + where result = insertSort e (xs, y) + +removeFirst :: a (SortList a) -> SortList a | Eq, Ord a +removeFirst e ([], y) = y +removeFirst e ([e], e) = newSortList +removeFirst e ([x:xs], y) +| e == x = ([xs], y) +removeFirst _ _ = abort "" + +removeAll :: a (SortList a) -> SortList a | Eq, Ord a +removeAll _ _ = abort "" + +elements :: (SortList a) -> [a] +elements _ = abort "" + +count :: (SortList a) -> Int +count _ = abort "" + +minimum :: (SortList a) -> a +minimum _ = abort "" + +maximum :: (SortList a) -> a +maximum _ = abort "" + +mergeSortList :: (SortList a) (SortList b) -> (SortList a) +mergeSortList _ _ = abort "" + +Start :: String +Start = newSortList diff --git a/fp1/week3/mart/StdStack.dcl b/fp1/week3/mart/StdStack.dcl new file mode 100644 index 0000000..8c861a1 --- /dev/null +++ b/fp1/week3/mart/StdStack.dcl @@ -0,0 +1,13 @@ +definition module StdStack + +:: Stack a + +newStack :: Stack a // lege stack +push :: a (Stack a) -> Stack a // plaats nieuw element bovenop de stack +pushes :: [a] (Stack a) -> Stack a // plaats elementen achtereenvolgens bovenop stack +pop :: (Stack a) -> Stack a // haal top element van stack +popn :: Int (Stack a) -> Stack a // haal bovenste $n$ top elementen van stack +top :: (Stack a) -> a // geef top element van stack +topn :: Int (Stack a) -> [a] // geef bovenste $n$ top elementen van stack +elements :: (Stack a) -> [a] // geef alle elementen van stack +count :: (Stack a) -> Int // tel aantal elementen in stack diff --git a/fp1/week3/mart/StdStack.icl b/fp1/week3/mart/StdStack.icl new file mode 100644 index 0000000..13220e1 --- /dev/null +++ b/fp1/week3/mart/StdStack.icl @@ -0,0 +1,57 @@ +implementation module StdStack + +import StdEnv + +:: Stack a = Stack [a] + +newStack :: Stack a +newStack = Stack [] + +push :: a (Stack a) -> Stack a +push x (Stack xs) = Stack [x:xs] + +pushes :: [a] (Stack a) -> Stack a +pushes [] (Stack s) = Stack s +pushes [x:xs] (Stack s) = pushes xs (push x (Stack s)) + +pop :: (Stack a) -> Stack a +pop (Stack []) = abort "Can't pop from empty stack..." +pop (Stack [x:xs]) = Stack xs + +popn :: Int (Stack a) -> Stack a +popn 0 s = s +popn n s = popn (n-1) (pop s) + +top :: (Stack a) -> a +top (Stack []) = abort "Can't give top of empty stack..." +top (Stack [x:_]) = x + +topn :: Int (Stack a) -> [a] +topn 0 _ = [] +topn n x = [top x:topn (n-1) (pop x)] + +elements :: (Stack a) -> [a] +elements (Stack s) = s + +count :: (Stack a) -> Int +count (Stack []) = 0 +count (Stack [_:xs]) = 1 + count (Stack xs) + +Start = ( "s0 = newStack = ", s0,'\n' + , "s1 = push 1 s0 = ", s1,'\n' + , "s2 = pushes [2..5] s1 = ",s2,'\n' + , "s3 = pop s2 = ", s3,'\n' + , "s4 = popn 3 s3 = ", s4,'\n' + , "s5 = top s4 = ", s5,'\n' + , "s6 = topn 3 s2 = ", s6,'\n' + , "s7 = elements s2 = ", s7,'\n' + ) +where + s0 = newStack + s1 = push 1 s0 + s2 = pushes [2..5] s1 + s3 = pop s2 + s4 = popn 3 s3 + s5 = top s4 + s6 = topn 3 s2 + s7 = elements s2 diff --git a/fp1/week4/camil/5.4 b/fp1/week4/camil/5.4 new file mode 100644 index 0000000..accd855 --- /dev/null +++ b/fp1/week4/camil/5.4 @@ -0,0 +1,5 @@ +1. Optelling in de gehele getallen is commutatief, dit maakt dus niet uit. +2. Het verschil tussen 4-2=2 en 2-4=-2. + Algemeen: het verschill tussen (-) a b = a-b en flip (-) a b = b-a, dus (-) a b = - flip (-) a b +3. Vermenigvuldiging in de gehele getallen is commutatief, dit maakt dus niet uit. +3. Het verschil tussen 4/2=2 en 2/4=0. diff --git a/fp1/week4/camil/StdSet.dcl b/fp1/week4/camil/StdSet.dcl new file mode 100644 index 0000000..6cad7f1 --- /dev/null +++ b/fp1/week4/camil/StdSet.dcl @@ -0,0 +1,25 @@ +definition module StdSet + +import StdClass + +:: Set a + +toSet :: [a] -> Set a | Eq a +fromSet :: (Set a) -> [a] + +isEmptySet :: (Set a) -> Bool +isDisjoint :: (Set a) (Set a) -> Bool | Eq a +isSubset :: (Set a) (Set a) -> Bool | Eq a +isStrictSubset :: (Set a) (Set a) -> Bool | Eq a +memberOfSet :: a (Set a) -> Bool | Eq a +union :: (Set a) (Set a) -> Set a | Eq a +intersection :: (Set a) (Set a) -> Set a | Eq a +nrOfElements :: (Set a) -> Int +without :: (Set a) (Set a) -> Set a | Eq a + +product :: (Set a) (Set b) -> Set (a,b) + +instance zero (Set a) +instance == (Set a) | Eq a + +powerSet :: (Set a) -> Set (Set a) diff --git a/fp1/week4/camil/StdSet.icl b/fp1/week4/camil/StdSet.icl new file mode 100644 index 0000000..651c869 --- /dev/null +++ b/fp1/week4/camil/StdSet.icl @@ -0,0 +1,64 @@ +implementation module StdSet + +import StdEnv +import StdClass + +:: Set a :== [a] + +toSet :: [a] -> Set a | Eq a +toSet l = toSet` l [] +where + toSet` [] s = s + toSet` [x:xs] s = toSet` xs (join x s) + where + join :: a (Set a) -> Set a | Eq a + join e s + | memberOfSet e s = s + | otherwise = s ++ [e] + +fromSet :: (Set a) -> [a] +fromSet s = s + +isEmptySet :: (Set a) -> Bool +isEmptySet [] = True +isEmptySet _ = False + +isDisjoint :: (Set a) (Set a) -> Bool | Eq a +isDisjoint s1 s2 = length (intersection s1 s2) == 0 + +isSubset :: (Set a) (Set a) -> Bool | Eq a +isSubset s1 s2 = nrOfElements (intersection s1 s2) == nrOfElements s1 + +isStrictSubset :: (Set a) (Set a) -> Bool | Eq a +isStrictSubset s1 s2 = isSubset s1 s2 && s1 <> s2 + +memberOfSet :: a (Set a) -> Bool | Eq a +memberOfSet e [] = False +memberOfSet e [x:xs] + | e == x = True + | otherwise = memberOfSet e xs + +union :: (Set a) (Set a) -> Set a | Eq a +union s1 s2 = toSet (s1 ++ s2) + +intersection :: (Set a) (Set a) -> Set a | Eq a +intersection s1 s2 = [e \\ e <- s1 | memberOfSet e s2] + +nrOfElements :: (Set a) -> Int +nrOfElements s = length (fromSet s) + +without :: (Set a) (Set a) -> Set a | Eq a +without s1 s2 = [e \\ e <- s1 | (memberOfSet e s2) == False] + +product :: (Set a) (Set b) -> Set (a,b) +product s1 s2 = [(e1,e2) \\ e1 <- s1, e2 <- s2] + +instance zero (Set a) +where zero = [] + +instance == (Set a) | Eq a +where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1 + +powerSet :: (Set a) -> Set (Set a) +powerSet [] = [zero] +powerSet [e:es] = map ((++) [e]) (powerSet es) ++ powerSet es \ No newline at end of file diff --git a/fp1/week4/mart/5.4.txt b/fp1/week4/mart/5.4.txt new file mode 100644 index 0000000..50521d3 --- /dev/null +++ b/fp1/week4/mart/5.4.txt @@ -0,0 +1,4 @@ +1. 4+2 en 2+4. Dit geeft zelfde uitkomst ivm commutativiteit van + +2. 4-2 en 2-4. Dit geeft 2 en -2. - is niet commutitatief. +3. 4*2 en 2*4. Dit geeft zelfde uitkomst ivm commutativiteit van * +4. 4/2 en 2/4. Dit geeft 2 en 0. / is niet commutitatief. diff --git a/fp1/week4/mart/StdSet.dcl b/fp1/week4/mart/StdSet.dcl new file mode 100644 index 0000000..0c702ca --- /dev/null +++ b/fp1/week4/mart/StdSet.dcl @@ -0,0 +1,25 @@ +definition module StdSet + +import StdClass + +:: Set a + +toSet :: [a] -> Set a | Eq a +fromSet :: (Set a) -> [a] + +isEmptySet :: (Set a) -> Bool +isDisjoint :: (Set a) (Set a) -> Bool | Eq a +isSubset :: (Set a) (Set a) -> Bool | Eq a +isStrictSubset :: (Set a) (Set a) -> Bool | Eq a +memberOfSet :: a (Set a) -> Bool | Eq a +union :: (Set a) (Set a) -> Set a | Eq a +intersection :: (Set a) (Set a) -> Set a | Eq a +nrOfElements :: (Set a) -> Int +without :: (Set a) (Set a) -> Set a | Eq a + +product :: (Set a) (Set b) -> Set (a,b) + +instance zero (Set a) +instance == (Set a) | Eq a + +powerSet :: (Set a) -> Set (Set a) | Eq a diff --git a/fp1/week4/mart/StdSet.icl b/fp1/week4/mart/StdSet.icl new file mode 100644 index 0000000..ecb2e60 --- /dev/null +++ b/fp1/week4/mart/StdSet.icl @@ -0,0 +1,54 @@ +implementation module StdSet + +import StdEnv +import StdClass + +:: Set a = Set [a] + +toSet :: [a] -> Set a | Eq a +toSet s = Set (removeDup s) + +fromSet :: (Set a) -> [a] +fromSet (Set s) = s + +isEmptySet :: (Set a) -> Bool +isEmptySet s = isEmpty (fromSet s) + +isDisjoint :: (Set a) (Set a) -> Bool | Eq a +isDisjoint s1 s2 = nrOfElements (intersection s1 s2) == 0 + +isSubset :: (Set a) (Set a) -> Bool | Eq a +isSubset s1 s2 = nrOfElements s1 == nrOfElements (intersection s1 s2) + +isStrictSubset :: (Set a) (Set a) -> Bool | Eq a +isStrictSubset s1 s2 = isSubset s1 s2 && nrOfElements s1 < nrOfElements s2 + +memberOfSet :: a (Set a) -> Bool | Eq a +memberOfSet a (Set []) = False +memberOfSet a (Set [x:xs]) = a == x || memberOfSet a (Set xs) + +union :: (Set a) (Set a) -> Set a | Eq a +union (Set s1) (Set s2) = toSet (s1 ++ s2) + +intersection :: (Set a) (Set a) -> Set a | Eq a +intersection (Set s1) s2 = Set [e \\ e <- s1 | memberOfSet e s2] + +nrOfElements :: (Set a) -> Int +nrOfElements s = length (fromSet s) + +without :: (Set a) (Set a) -> Set a | Eq a +without (Set s1) s2 = Set [e \\ e <- s1 | not (memberOfSet e s2)] + +product :: (Set a) (Set b) -> Set (a,b) +product (Set s1) (Set s2) = Set [(e1, e2) \\ e1 <- s1, e2 <- s2] + +instance zero (Set a) +where zero = Set [] + +instance == (Set a) | Eq a +where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1 + +powerSet :: (Set a) -> Set (Set a) | Eq a +powerSet (Set []) = Set [(Set [])] +powerSet (Set [e:xs]) = union (powerSet (Set xs)) + (Set [union (Set [e]) x \\ x <- fromSet (powerSet (Set xs))]) diff --git a/fp1/week4/week4.tar.gz b/fp1/week4/week4.tar.gz new file mode 100644 index 0000000..0258701 Binary files /dev/null and b/fp1/week4/week4.tar.gz differ diff --git a/fp1/week5/camil/Origami.icl b/fp1/week5/camil/Origami.icl new file mode 100644 index 0000000..74362a9 --- /dev/null +++ b/fp1/week5/camil/Origami.icl @@ -0,0 +1,24 @@ +module Origami + +import StdEnv + +Start = and + [ sum` [1 .. 5] == sum [1 .. 5] + , prod` [1 .. 5] == prod [1 .. 5] + , flatten` [[],[1],[1,2],[1,2,3]] == flatten [[],[1],[1,2],[1,2,3]] + , reverse` [1 .. 5] == reverse [1 .. 5] + , takeWhile` ((<>) 0) [1,2,3,0,4,5,6] == takeWhile ((<>) 0) [1,2,3,0,4,5,6] + , maxList` [1 .. 5] == maxList [1 .. 5] + ] + +sum` = foldr (+) 0 +prod` = foldr (*) 1 +flatten` = foldr (++) [] +length` = foldl (\l e = l + 1) 0 +reverse` = foldl (\xs x = [x:xs]) [] +takeWhile` _ [] = [] +takeWhile` p xs + | p (xs!!0) = take (maxList [i \\ i <- [0..length xs-1] | foldr (&&) True [p (xs!!j) \\ j <- [0..i]]] + 1) xs + | otherwise = [] +maxList` [] = undef +maxList` [x:xs] = foldr max x xs diff --git a/fp1/week5/mart/Origami.icl b/fp1/week5/mart/Origami.icl new file mode 100644 index 0000000..180a119 --- /dev/null +++ b/fp1/week5/mart/Origami.icl @@ -0,0 +1,16 @@ +/** + * Mart Lubbers, s4109503 + * Camil Staps, s4498062 + */ + +module Origami + +import StdEnv + +sum` = foldr (+) 0 +prod` = foldr (*) 1 +flatten` = foldr (++) [] +length` = foldr (\x l=l+1) 0 +reverse` = foldl (\xs x=[x:xs]) [] +takeWhile` p = foldr (\x xs=if (p x) [x:xs] []) [] +maxList` [x:xs] = foldr max x xs diff --git a/fp1/week6/camil/BewijsMapFlatten.icl b/fp1/week6/camil/BewijsMapFlatten.icl new file mode 100644 index 0000000..7f2474e --- /dev/null +++ b/fp1/week6/camil/BewijsMapFlatten.icl @@ -0,0 +1,83 @@ +// Mart Lubbers, s4109503 +// Camil Staps, s4498062 + +Zij gegeven: + +(++) :: [a] [a] -> [a] +(++) [] xs = xs (1) +(++) [y:ys] xs = [y : ys ++ xs] (2) + +map :: (a -> b) [a] -> [b] +map f [] = [] (3) +map f [x:xs] = [f x : map f xs] (4) + +flatten :: [[a]] -> [a] +flatten [] = [] (5) +flatten [x:xs] = x ++ (flatten xs) (6) + +1. +Te bewijzen: + voor iedere functie f, eindige lijst as en bs: + + map f (as ++ bs) = (map f as) ++ (map f bs) + +Bewijs: +Met inductie over as. + +Inductiebasis: +Stel as = []. Dan hebben we: + + map f (as ++ bs) // aanname as = [] + = map f ([] ++ bs) // definitie van ++, regel 1 + = map f bs // definitie van ++, regel 1 + = [] ++ (map f bs) // definitie van map, regel 3 + = (map f []) ++ (map f bs) // aanname as = [] + = (map f as) ++ (map f bs). + +Inductiestap: +Stel map f (as ++ bs) = (map f as) ++ (map f bs) voor zekere as en elke bs (inductiehypothese). Dan hebben we: + + map f ([a:as] ++ bs) // definitie van ++, regel 2 + = map f [a:as ++ bs] // definitie van map, regel 4 + = [f a : map f (as ++ bs)] // inductiehypothese: map f (as ++ bs) = (map f as) ++ (map f bs) + = [f a : (map f as) ++ (map f bs)] // lijst herschrijven + = [f a : map f as] ++ (map f bs) // definitie van map, regel 4 + = (map f [a:as]) ++ (map f bs). + +Uit het principe van volledige inductie volgt nu dat voor iedere functie f, eindige lijst as en bs: + + map f (as ++ bs) = (map f as) ++ (map f bs) (9.4.1) + +2. +Te bewijzen: + voor iedere functie f, voor iedere eindige lijst xs: + + flatten (map (map f) xs) = map f (flatten xs) + +Bewijs: +Met inductie over xs. + +Inductiebasis: +Stel xs = []. Dan hebben we: + + flatten (map (map f) xs) // aanname xs = [] + = flatten (map (map f) []) // definitie van map, regel 3 + = flatten [] // definitie van flatten, regel 5 + = [] // definitie van map, regel 3 + = map f [] // definitie van flatten, regel 5 + = map f (flatten []) // aanname xs = [] + = map f (flatten xs). + +Inductiestap: +Stel flatten (map (map f) xs) = map f (flatten xs) voor een zekere eindige lijst xs (inductiehypothese). Dan hebben we: + + flatten (map (map f) [x:xs]) // definitie van map, regel 4 + = flatten [map f x : map (map f) xs] // definitie van flatten, regel 6 + = (map f x) ++ flatten (map (map f) xs) // inductiehypothese: flatten (map (map f) xs) = map f (flatten xs) + = (map f x) ++ (map f (flatten xs)) // 9.4.1 + = map f (x ++ (flatten xs)) // definitie van flatten, regel 6 + = map f (flatten [x:xs]). + +Uit het principe van volledige inductie volgt nu dat voor iedere functie f en eindige lijst xs geldt: + + flatten (map (map f) xs) = map f (flatten xs) diff --git a/fp1/week6/mart/BewijsMapFlatten.icl b/fp1/week6/mart/BewijsMapFlatten.icl new file mode 100644 index 0000000..59fa5bc --- /dev/null +++ b/fp1/week6/mart/BewijsMapFlatten.icl @@ -0,0 +1,97 @@ +Zij gegeven: + +(++) :: [a] [a] -> [a] +(++) [] xs = xs (1) +(++) [y:ys] xs = [y : ys ++ xs] (2) + +map :: (a -> b) [a] -> [b] +map f [] = [] (3) +map f [x:xs] = [f x : map f xs] (4) + +flatten :: [[a]] -> [a] +flatten [] = [] (5) +flatten [x:xs] = x ++ (flatten xs) (6) + +1. +Te bewijzen: + voor iedere functie f, eindige lijst as en bs: + + map f (as ++ bs) = (map f as) ++ (map f bs) + +Bewijs: + met inductie naar de lengte van as. + + Basis: + aanname: as = []. + + map f ([] ++ bs) = (map f []) ++ (map f bs) basis + ******** + => map f (bs) = (map f []) ++ (map f bs) (1) + ******** + => map f (bs) = [] ++ (map f bs) (3) + **************** + => map f bs = map f bs (1) + + Inductiestap: + aanname: stelling geldt voor zekere as, ofwel: + map f (as ++ bs) = (map f as) ++ (map f bs) (IH) + + Te bewijzen: stelling geldt ook voor as, ofwel: + map f ([a:as] ++ bs) = (map f [a:as]) ++ (map f bs) + + map f ([a:as] ++ bs) = (map f [a:as]) ++ (map f bs) basis + ************ + => map f [a:as ++ bs] = (map f [a:as]) ++ (map f bs) (2) + ****************** + => [f a : map f (as ++ bs)] = (map f [a:as]) ++ (map f bs) (4) + ************ + => [f a : map f (as ++ bs)] = [f a : map f as] ++ (map f bs) (4) + **************************** + => [f a : map f (as ++ bs)] = [f a : (map f as) ++ (map f bs)] (4) + **************** ************************ + => map f (as ++ bs) = (map f as) ++ (map f bs) (IH) + + Dus: basis + inductiestap => stelling bewezen. + +2. +Te bewijzen: + voor iedere functie f, voor iedere eindige lijst xs: + + flatten (map (map f) xs) = map f (flatten xs) + +Bewijs: + met inductio van de lengte van xs + + Basis: + aanname: xs = []. + + flatten (map (map f) []) = map f (flatten []) basis + ************** + = flatten [] = map f (flatten []) (3) + ********** + = flatten [] = map f [] (5) + ********** + = [] = map f [] (5) + ***** + = [] = [] (3) + + Inductiestap: + aanname: stelling geldt voor zekere xs, ofwel: + flatten (map (map f) xs) = map f (flatten xs) + + Te bewijzen: stelling geldt ook voor xs, ofwel: + flatten (map (map f) [x:xs]) = map f (flatten [x:xs]) + + flatten (map (map f) [x:xs]) = map f (flatten [x:xs]) basis + ****************** + => flatten [map f x: map (map f) xs] = map f (flatten [x:xs]) (4) + ********************************* + => (map f x) ++ (flatten (map (map f) xs)) = map f (flatten [x:xs]) (6) + ************** + => (map f x) ++ (flatten (map (map f) xs)) = map f (x ++ (flatten xs)) (6) + ************************* + => (map f x) ++ (flatten (map (map f) xs)) = (map f x) ++ (map f (flatten xs)) (9.4.1) + ************************ **************** + => flatten (map (map f) xs) = map f (flatten xs) (IH) + + Dus: basis + inductiestap => stelling bewezen. diff --git a/fp1/week7/camil/BewijsMeppenEnTippen.icl b/fp1/week7/camil/BewijsMeppenEnTippen.icl new file mode 100644 index 0000000..ca5e396 --- /dev/null +++ b/fp1/week7/camil/BewijsMeppenEnTippen.icl @@ -0,0 +1,82 @@ +// Mart Lubbers, s4109503 +// Camil Staps, s4498062 + +Zij gegeven: + +:: BTree a = Tip a | Bin (BTree a) (BTree a) + +map :: (a -> b) [a] -> [b] +map f [] = [] (1.) +map f [x:xs] = [f x : map f xs] (2.) + +mapbtree :: (a -> b) (BTree a) -> BTree b +mapbtree f (Tip a) = Tip (f a) (3.) +mapbtree f (Bin t1 t2) = Bin (mapbtree f t1) (mapbtree f t2) (4.) + +foldbtree :: (a a -> a) (BTree a) -> a +foldbtree f (Tip x) = x (5.) +foldbtree f (Bin t1 t2) = f (foldbtree f t1) (foldbtree f t2) (6.) + +tips :: (BTree a) -> [a] +tips t = foldbtree (++) (mapbtree unit t) (7.) + +unit :: a -> [a] +unit x = [x] (8.) + + +Te bewijzen: + voor alle functies f, voor alle eindige bomen t: + + map f (tips t) = tips (mapbtree f t) + +Bewijs: + Met inductie over t. + + Inductiebasis: stel t = Tip a. + Dan hebben we: + + map f (tips t) // definitie tips (7) + = map f (foldbtree (++) (mapbtree unit t)) // aanname t = Tip a + = map f (foldbtree (++) (mapbtree unit (Tip a))) // definitie mapbtree (3) + = map f (foldbtree (++) (Tip unit a)) // definitie foldbtree (5) + = map f (unit a) // definitie unit (8) + = map f [a] // herschrijven lijst + = map f [a:[]] // definitie map (2) + = [f a : map f []] // definitie map (1) + = [f a : []] // herschrijven lijst + = [f a] // definitie unit (8) + = unit (f a) // definitie foldbtree (5) + = foldbtree (++) (Tip (unit (f a))) // definitie mapbtree (3) + = foldbtree (++) (mapbtree unit (Tip (f a))) // definitie tips (7) + = tips (Tip (f a)) // definitie mapbtree (3) + = tips (mapbtree f (Tip a)) // aanname t = Tip a + = tips (mapbtree f t) + + Dus de stelling geldt voor t = Tip a. + + Inductiestap: laten we aannemen dat + map f (tips t) = tips (mapbtree f t) + voor alle f en zekere t=t1,t=t2 (inductiehypothese). + Dan hebben we: + + map f (tips (Bin t1 t2)) // definitie tips (7) + = map f (foldbtree (++) (mapbtree unit (Bin t1 t2))) // definitie mapbtree (4) + = map f (foldbtree (++) (Bin (mapbtree unit t1) (mapbtree unit t2))) // definitie foldbtree (6) + = map f ((++) (foldbtree (++) (mapbtree unit t1)) (foldbtree (++) (mapbtree unit t2))) // definitie tips (7) + = map f ((++) (tips t1) (tips t2)) // 9.4.1 + = (map f (tips t1)) ++ (map f (tips t2)) // inductiehypothese + = (tips (mapbtree f t1)) ++ (tips (mapbtree f t2)) // definitie tips (7) + = (foldbtree (++) (mapbtree unit (f t1))) ++ (foldbtree (++) (mapbtree unit (f t2))) // herschrijven infixnotatie + = (++) (foldbtree (++) (mapbtree unit (f t1))) (foldbtree (++) (mapbtree unit (f t2))) // definitie foldbtree (6) + = foldbtree (++) (Bin (mapbtree unit (f t1)) (mapbtree unit (f t2))) // definitie mapbtree (4) + = foldbtree (++) (mapbtree unit (Bin (mapbtree f t1) (mapbtree f t2))) // definitie tips (7) + = tips (Bin (mapbtree f t1) (mapbtree f t2)) // definitie mapbtree (4) + = tips (mapbtree f (Bin t1 t2)) + + Conclusie: + We hebben laten zien dat de stelling geldt voor elke f met t = Tip a. Vervolgens hebben we laten zien dat als de stelling geldt voor elke f met t=t1 of t=t2, de stelling óók geldt voor elke f met t = Bin t1 t2. + Met het principe van inductie volgt nu + + map f (tips t) = tips (mapbtree f t) + + voor alle functies f en alle eindige bomen t. \ No newline at end of file diff --git a/fp1/week7/camil/BinSearchTree.dcl b/fp1/week7/camil/BinSearchTree.dcl new file mode 100644 index 0000000..696b065 --- /dev/null +++ b/fp1/week7/camil/BinSearchTree.dcl @@ -0,0 +1,7 @@ +definition module BinSearchTree + +import StdClass +import BinTree + +is_geordend :: (Tree a) -> Bool | Ord a // meest algemene type +is_gebalanceerd :: (Tree a) -> Bool | Ord a // meest algemene type diff --git a/fp1/week7/camil/BinSearchTree.icl b/fp1/week7/camil/BinSearchTree.icl new file mode 100644 index 0000000..559846b --- /dev/null +++ b/fp1/week7/camil/BinSearchTree.icl @@ -0,0 +1,177 @@ +// Mart Lubbers, s4109503 +// Camil Staps, s4498062 + +implementation module BinSearchTree + +import StdEnv +import BinTree + +z0 = Leaf +// Leaf + +z1 = insertTree 50 z0 +// 50 +// | +// ------------- +// | | +// Leaf Leaf + +z2 = insertTree 10 z1 +// 50 +// | +// ------------- +// | | +// 10 Leaf +// | +// --------- +// | | +// Leaf Leaf + +z3 = insertTree 75 z2 +// 50 +// | +// --------------- +// | | +// 10 75 +// | | +// --------- --------- +// | | | | +// Leaf Leaf Leaf Leaf + +z4 = insertTree 80 z3 +// 50 +// | +// --------------- +// | | +// 10 75 +// | | +// --------- --------- +// | | | | +// Leaf Leaf Leaf 80 +// | +// --------- +// | | +// Leaf Leaf + +z5 = insertTree 77 z4 +// 50 +// | +// --------------- +// | | +// 10 75 +// | | +// --------- --------- +// | | | | +// Leaf Leaf Leaf 77 +// | +// --------- +// | | +// Leaf 80 +// | +// --------- +// | | +// Leaf Leaf + +z6 = insertTree 10 z5 +// 50 +// | +// --------------- +// | | +// 10 75 +// | | +// --------- --------- +// | | | | +// 10 Leaf Leaf 77 +// | | +// --------- --------- +// | | | | +// Leaf Leaf Leaf 80 +// | +// --------- +// | | +// Leaf Leaf + +z7 = insertTree 75 z6 +// 50 +// | +// ---------------- +// | | +// 10 75 +// | | +// --------- ----------- +// | | | | +// 10 Leaf 75 77 +// | | | +// --------- ------ ------- +// | | | | | | +// Leaf Leaf Leaf Leaf Leaf 80 +// | +// --------- +// | | +// Leaf Leaf + +z8 = deleteTree 50 z7 +// 10 +// | +// ---------------- +// | | +// 10 75 +// | | +// --------- ----------- +// | | | | +// Leaf Leaf 75 77 +// | | +// ------ ------- +// | | | | +// Leaf Leaf Leaf 80 +// | +// --------- +// | | +// Leaf Leaf + +// Uit het diktaat, blz. 73: +insertTree :: a (Tree a) -> Tree a | Ord a +insertTree e Leaf = Node e Leaf Leaf +insertTree e (Node x le ri) +| e <= x = Node x (insertTree e le) ri +| e > x = Node x le (insertTree e ri) + +deleteTree :: a (Tree a) -> (Tree a) | Eq, Ord a +deleteTree e Leaf = Leaf +deleteTree e (Node x le ri) +| e < x = Node x (deleteTree e le) ri +| e == x = join le ri +| e > x = Node x le (deleteTree e ri) +where + join :: (Tree a) (Tree a) -> (Tree a) + join Leaf b2 = b2 + join b1 b2 = Node x b1` b2 + where + (x,b1`) = largest b1 + + largest :: (Tree a) -> (a,(Tree a)) + largest (Node x b1 Leaf) = (x,b1) + largest (Node x b1 b2) = (y,Node x b1 b2`) + where + (y,b2`) = largest b2 + + +is_geordend :: (Tree a) -> Bool | Ord a // meest algemene type +is_geordend Leaf = True +is_geordend (Node x le ri) = (foldr (&&) True (map ((>) x) (members le))) && (foldr (&&) True (map ((<=) x) (members ri))) && is_geordend le && is_geordend ri +where + members :: (Tree a) -> [a] + members Leaf = [] + members (Node x le ri) = [x:(members le) ++ (members ri)] + +//Start = map is_geordend [t0,t1,t2,t3,t4,t5,t6,t7] + +is_gebalanceerd :: (Tree a) -> Bool | Ord a // meest algemene type +is_gebalanceerd Leaf = True +is_gebalanceerd (Node x le ri) = abs ((depth le) - (depth ri)) <= 1 && is_gebalanceerd le && is_gebalanceerd ri +where + depth :: (Tree a) -> Int + depth Leaf = 0 + depth (Node x le ri) = max (depth le) (depth ri) + 1 + +//Start = map is_gebalanceerd [t0,t1,t2,t3,t4,t5,t6,t7] diff --git a/fp1/week7/camil/BinTree.dcl b/fp1/week7/camil/BinTree.dcl new file mode 100644 index 0000000..7774ece --- /dev/null +++ b/fp1/week7/camil/BinTree.dcl @@ -0,0 +1,16 @@ +definition module BinTree + +:: Tree a = Node a (Tree a) (Tree a) | Leaf + +t0 :: Tree Int +t1 :: Tree Int +t2 :: Tree Int +t3 :: Tree Int +t4 :: Tree Int +t5 :: Tree Int +t6 :: Tree Int +t7 :: Tree Int + +//nodes :: // meest algemene type +//leaves :: // meest algemene type +//diepte :: // meest algemene type diff --git a/fp1/week7/camil/BinTree.icl b/fp1/week7/camil/BinTree.icl new file mode 100644 index 0000000..601efcc --- /dev/null +++ b/fp1/week7/camil/BinTree.icl @@ -0,0 +1,38 @@ +implementation module BinTree + +import StdEnv + +:: Tree a = Node a (Tree a) (Tree a) | Leaf + +t0 :: Tree Int +t0 = Leaf +t1 :: Tree Int +t1 = Node 4 t0 t0 +t2 :: Tree Int +t2 = Node 2 t0 t1 +t3 :: Tree Int +t3 = Node 5 t2 t0 +t4 :: Tree Int +t4 = Node 5 t2 t2 +t5 :: Tree Int +t5 = Node 1 Leaf (Node 2 Leaf (Node 3 Leaf (Node 4 Leaf Leaf))) +t6 :: Tree Int +t6 = Node 1 (Node 2 (Node 3 (Node 4 Leaf Leaf) Leaf) Leaf) Leaf +t7 :: Tree Int +t7 = Node 4 (Node 1 Leaf Leaf) (Node 5 (Node 2 Leaf Leaf) Leaf) + +// 2. +//nodes :: // meest algemene type +//nodes ... + +//Start = map nodes [t0,t1,t2,t3,t4,t5,t6,t7] + +//leaves :: // meest algemene type +//leaves ... + +//Start = map leaves [t0,t1,t2,t3,t4,t5,t6,t7] + +//diepte :: // meest algemene type +//diepte ... + +//Start = map diepte [t0,t1,t2,t3,t4,t5,t6,t7] diff --git a/fp1/week7/mart/BewijsMeppenEnTippen.icl b/fp1/week7/mart/BewijsMeppenEnTippen.icl new file mode 100644 index 0000000..720ff4d --- /dev/null +++ b/fp1/week7/mart/BewijsMeppenEnTippen.icl @@ -0,0 +1,29 @@ +Zij gegeven: + +:: BTree a = Tip a | Bin (BTree a) (BTree a) + +map :: (a -> b) [a] -> [b] +map f [] = [] (1.) +map f [x:xs] = [f x : map f xs] (2.) + +mapbtree :: (a -> b) (BTree a) -> BTree b +mapbtree f (Tip a) = Tip (f a) (3.) +mapbtree f (Bin t1 t2) = Bin (mapbtree f t1) (mapbtree f t2) (4.) + +foldbtree :: (a a -> a) (BTree a) -> a +foldbtree f (Tip x) = x (5.) +foldbtree f (Bin t1 t2) = f (foldbtree f t1) (foldbtree f t2) (6.) + +tips :: (BTree a) -> [a] +tips t = foldbtree (++) (mapbtree unit t) (7.) + +unit :: a -> [a] +unit x = [x] (8.) + + +Te bewijzen: + voor alle functies f, voor alle eindige bomen t: + + map f (tips t) = tips (mapbtree f t) + +Bewijs: diff --git a/fp1/week7/mart/BinSearchTree.dcl b/fp1/week7/mart/BinSearchTree.dcl new file mode 100644 index 0000000..2e480bb --- /dev/null +++ b/fp1/week7/mart/BinSearchTree.dcl @@ -0,0 +1,7 @@ +definition module BinSearchTree + +import StdClass +import BinTree + +is_geordend :: // meest algemene type +is_gebalanceerd :: // meest algemene type diff --git a/fp1/week7/mart/BinSearchTree.icl b/fp1/week7/mart/BinSearchTree.icl new file mode 100644 index 0000000..8f9f05c --- /dev/null +++ b/fp1/week7/mart/BinSearchTree.icl @@ -0,0 +1,141 @@ +implementation module BinSearchTree + +import StdEnv +import BinTree + + +z0 + Leaf +z1 + 50 + | + ---------- + | | + Leaf Leaf +z2 + 50 + | + ---------- + | | + 10 Leaf + | + ------ + | | + Leaf Leaf +z3 + 50 + | + ---------- + | | + 10 75 + | | + ------ ------ + | | | | + Leaf Leaf Leaf Leaf +z4 + 50 + | + ---------- + | | + 10 75 + | | + ------ ------ + | | | | + Leaf Leaf Leaf 80 + | + ------ + | | + Leaf Leaf +z5 + 50 + | + ---------- + | | + 10 75 + | | + ------ ------ + | | | | + Leaf Leaf Leaf 77 + | + ------ + | | + Leaf 80 + | + ------ + | | + Leaf Leaf +z6 + 50 + | + ---------- + | | + 10 75 + | | + ------ ------ + | | | | + 10 Leaf Leaf 77 + | | + ------ ------ + | | | | +Leaf Leaf Leaf 80 + | + ------ + | | + Leaf Leaf +z7 + 50 + | + ---------- + | | + 10 75 + | | + ------ ----------- + | | | | + 10 Leaf 75 77 + | | | + ------ ------ ------ + | | | | | | +Leaf Leaf Leaf Leaf Leaf 80 + | + ------ + | | + Leaf Leaf +z8 + +// Uit het diktaat, blz. 73: +insertTree :: a (Tree a) -> Tree a | Ord a +insertTree e Leaf = Node e Leaf Leaf +insertTree e (Node x le ri) +| e <= x = Node x (insertTree e le) ri +| e > x = Node x le (insertTree e ri) + +deleteTree :: a (Tree a) -> (Tree a) | Eq, Ord a +deleteTree e Leaf = Leaf +deleteTree e (Node x le ri) +| e < x = Node x (deleteTree e le) ri +| e == x = join le ri +| e > x = Node x le (deleteTree e ri) +where + join :: (Tree a) (Tree a) -> (Tree a) + join Leaf b2 = b2 + join b1 b2 = Node x b1` b2 + where + (x,b1`) = largest b1 + + largest :: (Tree a) -> (a,(Tree a)) + largest (Node x b1 Leaf) = (x,b1) + largest (Node x b1 b2) = (y,Node x b1 b2`) + where + (y,b2`) = largest b2 + + +is_geordend :: // meest algemene type +is_geordend ... + +Start = map is_geordend [t0,t1,t2,t3,t4,t5,t6,t7] + + +is_gebalanceerd :: // meest algemene type +is_gebalanceerd ... + +//Start = map is_gebalanceerd [t0,t1,t2,t3,t4,t5,t6,t7] diff --git a/week1/camil/1.1/Start.icl b/week1/camil/1.1/Start.icl deleted file mode 100644 index b56a850..0000000 --- a/week1/camil/1.1/Start.icl +++ /dev/null @@ -1,18 +0,0 @@ -module Start - -import StdEnv - -Start = expr11 - -expr0 = "Hello World!" -expr1 = "Hello " +++ "World!" -expr2 = 5 -expr3 = 5.5 -//expr4 = 5 + 5.5 -expr5 = [1..10] -expr6 = (expr1,expr2,expr3,expr5) -//expr7 = [expr1,expr2,expr3,expr5] -expr8 = [1,3..10] -expr9 = ['a'..'z'] -expr10 = ['a','c'..'z'] -expr11 = ['Hello World!'] \ No newline at end of file diff --git a/week1/camil/1.1/antwoorden.txt b/week1/camil/1.1/antwoorden.txt deleted file mode 100644 index 3a223e2..0000000 --- a/week1/camil/1.1/antwoorden.txt +++ /dev/null @@ -1,29 +0,0 @@ -Antwoorden opgave 1.1 -Camil Staps (s4498062) - -1. Het programma wordt gecompileerd. -2. Het programma wordt uitgevoerd. -3. De data types van de variabelen worden automatisch achterhaald door de IDE (en hoeven dus niet expliciet te worden gegeven door de programmeur) - -expr1 "Hello World!" - De strings worden geconcateneerd -expr2 5 - Dit is een Int waarde -expr3 5.5 - Dit is een Real waarde -expr4 Type error; cannot unify types Real and Int - Dat is omdat + is niet gedefinieerd voor Real met Int -expr5 [1,2,3,4,5,6,7,8,9,10] - Dit is een korte schrijfwijze voor deze lijst ([min..max]) -expr6 ("Hello World!",5,5.5,[1,2,3,4,5,6,7,8,9,10]) - Een tupeltje -expr7 Type error; cannot unify types [Int] and Real - Dat is omdat elementen van een lijst hetzelfde type moeten hebben, en dat hier niet het geval is -expr8 [1,3,5,7,9] - Een andere vorm van expr5 waarmee in het begin wordt aangegeven wat de interval is -expr9 ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] - Een lijst van karakters -expr10 ['a','c','e','g','i','k','m','o','q','s','u','w','y'] - Een combinatie van expr9 en expr8 -expr11 ['H','e','l','l','o',' ','W','o','r','l','d','!'] - Blijkbaar wordt ['...'] als lijst van karakters beschouwd diff --git a/week1/camil/2.1/NotatieFuncties.icl b/week1/camil/2.1/NotatieFuncties.icl deleted file mode 100644 index bab2054..0000000 --- a/week1/camil/2.1/NotatieFuncties.icl +++ /dev/null @@ -1,39 +0,0 @@ -module NotatieFuncties - -import StdEnv - -f1 :: Int -f1 = 1 + 5 - -f2 :: Int -f2 = (+) 1 5 - -f3 :: Int Int -> Int -f3 m n -| m < n = m -| otherwise = n - -f4 :: String Int -> String -f4 s n -| n <= 0 = "" -| otherwise = s +++ f4 s (n-1) - -f5 :: Int Int -> Int -f5 x 0 = x -f5 x y = f5 y (x rem y) - -f6 :: (Int,Int) -> Int -f6 x = fst x + snd x - -f7 :: (a,b) -> (b,a) -f7 (a,b) = (b,a) - -f8 :: (a,a) -> (a,a) -f8 x = f7 (f7 x) - -//Start = (f3 1 5, f3 4 3, f3 6 6) -//Start = f4 "ab" 4 -//Start = (f5 13 5, f5 8 4, f5 20 20) -//Start = f6 (2,3) -//Start = f7 (5,7) -Start = f8 (5,7) diff --git a/week1/camil/2.1/antwoorden.txt b/week1/camil/2.1/antwoorden.txt deleted file mode 100644 index c0c98d6..0000000 --- a/week1/camil/2.1/antwoorden.txt +++ /dev/null @@ -1,8 +0,0 @@ -f1 5+1=6; constant -f2 Reverse polix notation voor f1; zelfde functie dus -f3 Geeft de kleinste van twee integers terug -f4 Herhaalt s n keer -f5 Geeft de ggd van x en y met Euclides' algoritme -f6 Geeft de optelling x+y voor een tupel (x,y) -f7 Flipt de twee elementen van een tupel -f8 Flipt de twee elementen van een tupel twee keer (heeft geen effect) diff --git a/week1/camil/2.11/BottlesOfBeer.icl b/week1/camil/2.11/BottlesOfBeer.icl deleted file mode 100644 index 70628a1..0000000 --- a/week1/camil/2.11/BottlesOfBeer.icl +++ /dev/null @@ -1,21 +0,0 @@ -module BottlesOfBeer - -import StdEnv - -Start = [(fst_line x +++ "\n" +++ snd_line x +++ "\n\n") \\ x <- [99,98..0]] - -fst_line :: Int -> String -fst_line n = btl n True +++ wall +++ ", " +++ btl n False +++ " of beer." - -snd_line :: Int -> String -snd_line 0 = "Go to the store and buy some more, " +++ btl 99 False +++ wall +++ "." -snd_line n = "Take one down and pass it around, " +++ btl (n-1) False +++ wall +++ "." - -btl :: Int Bool -> String -btl 0 True = "No more bottles" -btl 0 False = "no more bottles" -btl 1 b = "1 bottle" -btl n b = toString n +++ " bottles" - -wall :: String -wall = " of beer on the wall" \ No newline at end of file diff --git a/week1/camil/2.2/VindtDeRedex.icl b/week1/camil/2.2/VindtDeRedex.icl deleted file mode 100644 index c7ec330..0000000 --- a/week1/camil/2.2/VindtDeRedex.icl +++ /dev/null @@ -1,17 +0,0 @@ -module VindtDeRedex - -import StdEnv - -e1 = 42 - -e2 = 1 + 125 * 8 / 10 - 59 - -e3 = not True || True && False - -e4 = 1 + 2 == 6 - 3 - -e5 = "1 + 2" == "6 - 3" - -e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222" - -Start = e6 diff --git a/week1/camil/2.2/antwoorden.txt b/week1/camil/2.2/antwoorden.txt deleted file mode 100644 index 413465c..0000000 --- a/week1/camil/2.2/antwoorden.txt +++ /dev/null @@ -1,42 +0,0 @@ -e1 = 42 Is elementair - -e2 = 1 + 125 * 8 / 10 - 59 -e2 = (1 + ((125 * 8) / 10)) - 59 - ------- -e2 = (1 + (1000 / 10)) - 59 - --------- -e2 = (1 + 100) - 59 - ------- -e2 = 101 - 59 - -------- -e2 = 42 - -e3 = not True || True && False -e3 = (not True) || (True && False) - -------- -e3 = False || (True && False) - ------------- -e3 = False || False - -------------- -e3 = False - -e4 = 1 + 2 == 6 - 3 -e4 = (1 + 2) == (6 - 3) - ----- -e4 = 3 == (6 - 3) - ----- -e4 = 3 == 3 -e4 = True - -e5 = "1 + 2" == "6 - 3" - ------------------ -e5 = False - -e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222" -e6 = "1111 + 2222" == (("1111" +++ " + ") +++ "2222") - ----------------- -e6 = "1111 + 2222" == ("1111 + " +++ "2222") - -------------------- -e6 = "1111 + 2222" == "1111 + 2222" - ------------------------------ -e6 = True diff --git a/week1/camil/2.3/MatchStrings.dcl b/week1/camil/2.3/MatchStrings.dcl deleted file mode 100644 index 527447c..0000000 --- a/week1/camil/2.3/MatchStrings.dcl +++ /dev/null @@ -1,8 +0,0 @@ -definition module MatchStrings - -head :: String -> Char -tail :: String -> String -is_gelijk :: String String -> Bool -is_deelstring :: String String -> Bool -is_deel :: String String -> Bool -is_match :: String String -> Bool diff --git a/week1/camil/2.3/MatchStrings.icl b/week1/camil/2.3/MatchStrings.icl deleted file mode 100644 index 17859ae..0000000 --- a/week1/camil/2.3/MatchStrings.icl +++ /dev/null @@ -1,48 +0,0 @@ -implementation module MatchStrings - -import StdEnv - -head :: String -> Char -head "" = abort "head uitgevoerd op lege string" -head s = s.[0] - -tail :: String -> String -tail "" = abort "tail uitgevoerd op lege string" -tail s = s % (1, size s - 1) - -is_gelijk :: String String -> Bool -is_gelijk "" "" = True -is_gelijk a "" = False -is_gelijk "" b = False -is_gelijk a b = (head a == head b) && (is_gelijk (tail a) (tail b)) - -is_deelstring :: String String -> Bool -is_deelstring "" b = True -is_deelstring a "" = False -is_deelstring a b = is_gelijk a (b % (0, size a - 1)) || is_deelstring a (tail b) - -is_deel :: String String -> Bool -is_deel "" b = True -is_deel a "" = False -is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b) - -is_match :: String String -> Bool -is_match "" "" = True -is_match "" b = False -is_match "*" "" = True -is_match a "" = False -is_match a b = (head a == '.' || head a == head b) && is_match (tail a) (tail b) || head a == '*' && (is_match a (tail b) || is_match (tail a) b) - -//Start = (head pink_floyd, tail pink_floyd) -//Start = is_gelijk "" " " -//Start = is_deelstring "there" pink_floyd -//Start = is_deelstring "there" marillion -//Start = is_deel "there" marillion -//Start = is_deel "she and her" pink_floyd -//Start = is_deel radiohead pink_floyd -//Start = is_match "*.here*.here*." pink_floyd -//Start = is_match ".here.here." pink_floyd - -pink_floyd = "Is there anybody in there?" -marillion = "Just for the record" -radiohead = "There there" diff --git a/week1/mart/1.txt b/week1/mart/1.txt deleted file mode 100644 index 7ac4230..0000000 --- a/week1/mart/1.txt +++ /dev/null @@ -1,3 +0,0 @@ -1.1: -1.2: -Beide niet mogelijk zonder IDE(linux) diff --git a/week1/mart/MatchStrings.dcl b/week1/mart/MatchStrings.dcl deleted file mode 100644 index 527447c..0000000 --- a/week1/mart/MatchStrings.dcl +++ /dev/null @@ -1,8 +0,0 @@ -definition module MatchStrings - -head :: String -> Char -tail :: String -> String -is_gelijk :: String String -> Bool -is_deelstring :: String String -> Bool -is_deel :: String String -> Bool -is_match :: String String -> Bool diff --git a/week1/mart/MatchStrings.icl b/week1/mart/MatchStrings.icl deleted file mode 100644 index f10df45..0000000 --- a/week1/mart/MatchStrings.icl +++ /dev/null @@ -1,54 +0,0 @@ -implementation module MatchStrings - -import StdEnv - -head :: String -> Char -head "" = abort "Empty String" -head s = s.[0] - -tail :: String -> String -tail "" = abort "Empty String" -tail s = s % (1, size s - 1) - -is_gelijk :: String String -> Bool -is_gelijk "" "" = True -is_gelijk a b = (size a == size b) && (head a == head b) && is_gelijk (tail a) (tail b) - -is_deelstring :: String String -> Bool -is_deelstring _ "" = False -is_deelstring a b = is_begin a b || is_deelstring a (tail b) - -is_begin :: String String -> Bool -is_begin "" _ = True -is_begin _ "" = False -is_begin a b = head a == head b && is_begin (tail a) (tail b) - -is_deel :: String String -> Bool -is_deel "" _ = True -is_deel _ "" = False -is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b) - -is_match :: String String -> Bool -is_match a b = is_begin_match a b || size b > 0 && is_begin_match a (tail b) - -is_begin_match :: String String -> Bool -is_begin_match "" _ = True -is_begin_match a "" = head a == '*' && size a == 1 -is_begin_match a b -| head a == '.' || head a == head b = is_begin_match (tail a) (tail b) -| head a == '*' = is_begin_match a (tail b) || is_begin_match (tail a) b -| otherwise = False - -//Start= (head pink_floyd, tail pink_floyd) -//Start= is_gelijk "" " " -//Start= is_deelstring "there" pink_floyd -//Start= is_deelstring "there" marillion -//Start= is_deel "there" marillion -//Start= is_deel "she and her" pink_floyd -//Start= is_deel radiohead pink_floyd -//Start= is_match "*.here*.here*." pink_floyd -//Start= is_match ".here.here." pink_floyd - -pink_floyd= "Is there anybody in there?" -marillion= "Just for the record" -radiohead= "There there" diff --git a/week2/camil/Makefile b/week2/camil/Makefile deleted file mode 100644 index 9095df9..0000000 --- a/week2/camil/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: - clm StdT -o StdT - clm TupleOverloading -o TupleOverloading - clm VectorOverloading -o VectorOverloading diff --git a/week2/camil/StdT.dcl b/week2/camil/StdT.dcl deleted file mode 100644 index ca97fdc..0000000 --- a/week2/camil/StdT.dcl +++ /dev/null @@ -1,18 +0,0 @@ -definition module StdT - -import StdOverloaded - -:: T - -instance == T -instance < T - -instance zero T -instance + T -instance - T - -instance toInt T -instance fromInt T - -instance toString T -instance fromString T diff --git a/week2/camil/StdT.icl b/week2/camil/StdT.icl deleted file mode 100644 index 03c8645..0000000 --- a/week2/camil/StdT.icl +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Mart Lubbers, s4109503 - * Camil Staps, s4498062 - */ - -implementation module StdT - -import StdEnv - -:: T = {m :: Int, s :: Int} - -instance == T where == a b = a.m == b.m && a.s == b.s -instance < T where < a b = a.m < b.m || a.m == b.m && a.s < b.s - -instance zero T where zero = {m = zero, s = zero} -instance + T where + a b = fromInt (toInt a + toInt b) -instance - T where - a b = if (a < b) zero (fromInt (toInt a - toInt b)) - -instance toInt T where toInt a = a.m * 60 + a.s -instance fromInt T where fromInt n = if (n < 0) zero {m = n/60, s = n rem 60} - -instance toString T where - toString {m = x, s = 0} = toString x +++ ":00" - toString a = toString a.m +++ ":" +++ (if (a.s < 10) "0" "") +++ toString a.s -instance fromString T where - fromString s = if (s.[size s - 3] == ':') - {m = toInt (s % (0, size s - 4)), s = toInt (s % (size s - 2, size s - 1))} - zero - -Start :: (Bool, Bool, T, T, T, Int, String, T, T) -Start = (LOTR == Tea, Tea < LOTR, - zero + LOTR, LOTR + Tea, Tea - LOTR, - toInt LOTR, toString Tea, - fromString "5:40", fromString "foo") - -LOTR = {m=178, s=0} -Tea = {m=0,s=41} diff --git a/week2/camil/TupleOverloading.dcl b/week2/camil/TupleOverloading.dcl deleted file mode 100644 index 6831948..0000000 --- a/week2/camil/TupleOverloading.dcl +++ /dev/null @@ -1,25 +0,0 @@ -definition module TupleOverloading - -import StdEnv - -instance + (a,b) | + a & + b -instance + (a,b,c) | + a & + b & + c - - -instance - (a,b) | - a & - b -instance - (a,b,c) | - a & - b & - c - -instance * (a,b) | * a & * b -instance * (a,b,c) | * a & * b & * c - -instance / (a,b) | / a & / b -instance / (a,b,c) | / a & / b & / c - -instance zero (a,b) | zero a & zero b -instance zero (a,b,c) | zero a & zero b & zero c - -instance one (a,b) | one a & one b -instance one (a,b,c) | one a & one b & one c - -instance ~ (a,b) | ~ a & ~ b -instance ~ (a,b,c) | ~ a & ~ b & ~ c diff --git a/week2/camil/TupleOverloading.icl b/week2/camil/TupleOverloading.icl deleted file mode 100644 index 0ea437d..0000000 --- a/week2/camil/TupleOverloading.icl +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Mart Lubbers, s4109503 - * Camil Staps, s4498062 - */ - -implementation module TupleOverloading - -import StdEnv - -instance + (a,b) | + a & + b where - + (a,b) (c,d) = (a+c,b+d) -instance + (a,b,c) | + a & + b & + c where - + (a,b,c) (d,e,f) = (a+d,b+e,c+f) - -instance - (a,b) | - a & - b where - - (a,b) (c,d) = (a-c,b-d) -instance - (a,b,c) | - a & - b & - c where - - (a,b,c) (d,e,f) = (a-d,b-e,c-f) - -instance * (a,b) | * a & * b where - * (a,b) (c,d) = (a*c,b*d) -instance * (a,b,c) | * a & * b & * c where - * (a,b,c) (d,e,f) = (a*d,b*e,c*f) - -instance / (a,b) | / a & / b where - / (a,b) (c,d) = (a/c,b/d) -instance / (a,b,c) | / a & / b & / c where - / (a,b,c) (d,e,f) = (a/d,b/e,c/f) - -instance zero (a,b) | zero a & zero b where - zero = (zero, zero) -instance zero (a,b,c) | zero a & zero b & zero c where - zero = (zero, zero, zero) - -instance one (a,b) | one a & one b where - one = (one, one) -instance one (a,b,c) | one a & one b & one c where - one = (one, one, one) - -instance ~ (a,b) | ~ a & ~ b where - ~ (a,b) = (~ a, ~ b) -instance ~ (a,b,c) | ~ a & ~ b & ~ c where - ~ (a,b,c) = (~ a, ~ b, ~ c) - -Start = (test (1,2), test (1,2,3)) - -test a = ( zero + a == a && a == a + zero - , a - zero == a && a == ~ (zero - a) - , one * a == a && a == a * one - , zero * a == zero && zero == a * zero - , a / one == a - , ~ (~ a) == a - ) diff --git a/week2/camil/VectorOverloading.dcl b/week2/camil/VectorOverloading.dcl deleted file mode 100644 index 76f8520..0000000 --- a/week2/camil/VectorOverloading.dcl +++ /dev/null @@ -1,14 +0,0 @@ -definition module VectorOverloading - -import StdEnv - -:: Vector2 a = {x0 :: a, x1 :: a} - -instance == (Vector2 a) | == a -instance zero (Vector2 a) | zero a -instance one (Vector2 a) | one a -instance ~ (Vector2 a) | ~ a -instance + (Vector2 a) | + a -instance - (Vector2 a) | - a -instance * (Vector2 a) | * a -instance / (Vector2 a) | / a diff --git a/week2/camil/VectorOverloading.icl b/week2/camil/VectorOverloading.icl deleted file mode 100644 index 4c9c84a..0000000 --- a/week2/camil/VectorOverloading.icl +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Mart Lubbers, s4109503 - * Camil Staps, s4498062 - */ - -implementation module VectorOverloading - -import StdEnv - -:: Vector2 a = {x0 :: a, x1 :: a} - -instance == (Vector2 a) | == a where - == a b = a.x0 == b.x0 && a.x1 == b.x1 -instance zero (Vector2 a) | zero a where - zero = {x0 = zero, x1 = zero} -instance one (Vector2 a) | one a where - one = {x0 = one, x1 = one} -instance ~ (Vector2 a) | ~ a where - ~ a = {x0 = ~a.x0, x1 = ~a.x1} -instance + (Vector2 a) | + a where - + a b = {x0 = a.x0 + b.x0, x1 = a.x1 + b.x1} -instance - (Vector2 a) | - a where - - a b = {x0 = a.x0 - b.x0, x1 = a.x1 - b.x1} -instance * (Vector2 a) | * a where - * a b = {x0 = a.x0 * b.x0, x1 = a.x1 * b.x1} -instance / (Vector2 a) | / a where - / a b = {x0 = a.x0 / b.x0, x1 = a.x1 / b.x1} - -Start = test {x0=1,x1=2} - -test a = ( zero + a == a && a == a + zero - , a - zero == a && a == ~ (zero - a) - , one * a == a && a == a * one - , zero * a == zero && zero == a * zero - , a / one == a - , ~ (~ a) == a - ) diff --git a/week2/mart/Makefile b/week2/mart/Makefile deleted file mode 100644 index a35595b..0000000 --- a/week2/mart/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -PATHS=-I ~/downloads/clean/lib/StdLib -I ~/downloads/clean/lib/MersenneTwister/ -I ~/downloads/usr/lib64/clean/Gast/ -I ~/downloads/clean/lib/Generics/ -FLAGS=-v - -all: tuple vector stdtime - -tuple: TupleOverloading.icl TupleOverloading.dcl - clm $(FLAGS) $(PATHS) TupleOverloadingTest -o TupleOverloadingTest - -vector: VectorOverloading.icl VectorOverloading.dcl - clm $(FLAGS) $(PATHS) VectorOverloadingTest -o VectorOverloadingTest - -stdtime: StdT.icl StdT.dcl - clm $(FLAGS) $(PATHS) StdTTest -o StdTTest - -testall: - ./StdTTest - ./TupleOverloadingTest - ./VectorOverloadingTest - -clean: - $(RM) -r Clean\ System\ Files a.out TupleOverloadingTest VectorOverloadingTest StdTTest diff --git a/week2/mart/StdT.dcl b/week2/mart/StdT.dcl deleted file mode 100644 index f4f0d75..0000000 --- a/week2/mart/StdT.dcl +++ /dev/null @@ -1,18 +0,0 @@ -definition module StdT - -import StdOverloaded - -:: T - -instance == T -instance < T - -instance zero T -instance + T -instance - T - -instance toInt T -instance fromInt T - -instance toString T -instance fromString T diff --git a/week2/mart/StdT.icl b/week2/mart/StdT.icl deleted file mode 100644 index 01bee7d..0000000 --- a/week2/mart/StdT.icl +++ /dev/null @@ -1,35 +0,0 @@ -implementation module StdT - -import StdEnv - -:: T = {m :: Int, s :: Int} - -instance == T where - == a b = a.m == b.m && a.s == b.s -instance < T where - < a b = a.m < b.m || a.s == b.s && a.s < b.s - -instance zero T where - zero = {m=zero, s=zero} -instance + T where - + a b = fromInt (toInt a + toInt b) -instance - T where - - a b = fromInt (toInt a - toInt b) - -instance toInt T where - toInt a = a.m*60 + a.s -instance fromInt T where - fromInt a - | a<0 = zero - | otherwise = {m=a/60, s=a rem 60} - -instance toString T where - toString {m=ms, s=0} = toString ms +++ ":00" - toString {m=ms, s=ss} - | ss < 10 = toString ms +++ ":0" +++ toString ss - | otherwise = toString ms +++ ":" +++ toString ss - -instance fromString T where - fromString a - | a.[size a - 3] == ':' = {m = toInt (a % (0, (size a) - 4)), s = toInt (a % ((size a) - 2, size a))} - | otherwise = zero diff --git a/week2/mart/StdTTest.icl b/week2/mart/StdTTest.icl deleted file mode 100644 index 6af64fc..0000000 --- a/week2/mart/StdTTest.icl +++ /dev/null @@ -1,45 +0,0 @@ -module StdTTest - -/* Test module StdTTest - Voor werken met Gast: - (*) gebruik Environment 'Gast' - (*) zet Project Options op 'Basic Values Only' -*/ - -import StdT -import StdEnv -import gast - -Start - = testn 1000 - (\ i -> - gelijkheid_is_symmetrisch i /\ - ordening_is_monotoon i /\ - negatieve_tijd_bestaat_niet i /\ - omzetten_naar_Int_is_consistent i /\ - parse_print_is_consistent i /\ - True - ) - -t :: Int -> T -t x = fromInt x - -gelijkheid_is_symmetrisch :: Int -> Property -gelijkheid_is_symmetrisch i = name "gelijkheid_is_symmetrisch" - (t i == t i) - -ordening_is_monotoon :: Int -> Property -ordening_is_monotoon i = name "ordening_is_monotoon" - ((i <= i+1) ==> t i <= t (i+1)) - -negatieve_tijd_bestaat_niet :: Int -> Property -negatieve_tijd_bestaat_niet i = name "negatieve_tijd_bestaat_niet" - ((i + 1 >= i) ==> t i - t (i+1) == zero) - -omzetten_naar_Int_is_consistent :: Int -> Property -omzetten_naar_Int_is_consistent i = name "omzetten_naar_Int_is_consistent" - ((abs i >= 0) ==> toInt (t (abs i)) == abs i) - -parse_print_is_consistent :: Int -> Property -parse_print_is_consistent i = name "parse_print_is_consistent" - (fromString (toString (t i)) == t i) diff --git a/week2/mart/TupleOverloading.dcl b/week2/mart/TupleOverloading.dcl deleted file mode 100644 index 6831948..0000000 --- a/week2/mart/TupleOverloading.dcl +++ /dev/null @@ -1,25 +0,0 @@ -definition module TupleOverloading - -import StdEnv - -instance + (a,b) | + a & + b -instance + (a,b,c) | + a & + b & + c - - -instance - (a,b) | - a & - b -instance - (a,b,c) | - a & - b & - c - -instance * (a,b) | * a & * b -instance * (a,b,c) | * a & * b & * c - -instance / (a,b) | / a & / b -instance / (a,b,c) | / a & / b & / c - -instance zero (a,b) | zero a & zero b -instance zero (a,b,c) | zero a & zero b & zero c - -instance one (a,b) | one a & one b -instance one (a,b,c) | one a & one b & one c - -instance ~ (a,b) | ~ a & ~ b -instance ~ (a,b,c) | ~ a & ~ b & ~ c diff --git a/week2/mart/TupleOverloading.icl b/week2/mart/TupleOverloading.icl deleted file mode 100644 index 2995fbd..0000000 --- a/week2/mart/TupleOverloading.icl +++ /dev/null @@ -1,49 +0,0 @@ -implementation module TupleOverloading - -import StdEnv - -instance + (a,b) | + a & + b where - + (a,b) (c,d) = (a+c,b+d) -instance + (a,b,c) | + a & + b & + c where - + (a,b,c) (d,e,f) = (a+d,b+e,c+f) - - -instance - (a,b) | - a & - b where - - (a,b) (c,d) = (a-c,b-d) -instance - (a,b,c) | - a & - b & - c where - - (a,b,c) (d,e,f) = (a-d,b-e,c-f) - -instance * (a,b) | * a & * b where - * (a,b) (c,d) = (a*c,b*d) -instance * (a,b,c) | * a & * b & * c where - * (a,b,c) (d,e,f) = (a*d,b*e,c*f) - -instance / (a,b) | / a & / b where - / (a,b) (c,d) = (a/c,b/d) -instance / (a,b,c) | / a & / b & / c where - / (a,b,c) (d,e,f) = (a/d,b/e,c/f) - -instance zero (a,b) | zero a & zero b where - zero = (zero,zero) -instance zero (a,b,c) | zero a & zero b & zero c where - zero = (zero,zero,zero) - -instance one (a,b) | one a & one b where - one = (one,one) -instance one (a,b,c) | one a & one b & one c where - one = (one,one,one) - -instance ~ (a,b) | ~ a & ~ b where - ~ (a,b) = (~a,~b) -instance ~ (a,b,c) | ~ a & ~ b & ~ c where - ~ (a,b,c) = (~a,~b,~c) - -Start = (test (1,2), test (1,2,3)) - -test a = ( zero + a == a && a == a + zero - , a - zero == a && a == ~ (zero - a) - , one * a == a && a == a * one - , zero * a == zero && zero == a * zero - , a / one == a - , ~ (~ a) == a - ) diff --git a/week2/mart/TupleOverloadingTest.icl b/week2/mart/TupleOverloadingTest.icl deleted file mode 100644 index 91417f7..0000000 --- a/week2/mart/TupleOverloadingTest.icl +++ /dev/null @@ -1,64 +0,0 @@ -module TupleOverloadingTest - -/* Test module VectorOverloading - Voor werken met Gast: - (*) gebruik Environment 'Gast' - (*) zet Project Options op 'Basic Values Only' -*/ - -import TupleOverloading -import StdEnv -import gast - -Start - = testn 1000 - (\v -> - zero_is_neutral_for_addition v /\ - zero_is_neutral_for_subtraction v /\ - one_is_neutral_for_multiplication v /\ - one_is_neutral_for_division v /\ - negation_is_idempotent v /\ - add_then_subtract_yields_identity v /\ - subtract_then_add_yields_identity v /\ - True - ) - -:: Vector2 a :== (a,a) -:: BaseType - :== Int -// :== Real - -zero_is_neutral_for_addition :: (Vector2 BaseType) -> Property -zero_is_neutral_for_addition a = name "zero_is_neutral_for_addition" - (zero + a == a && a == a + zero) - -zero_is_neutral_for_subtraction :: (Vector2 BaseType) -> Property -zero_is_neutral_for_subtraction a = name "zero_is_neutral_for_subtraction" - (a - zero == a && a == ~ (zero - a)) - -one_is_neutral_for_multiplication :: (Vector2 BaseType) -> Property -one_is_neutral_for_multiplication a = name "one_is_neutral_for_multiplication" - (one * a == a && a == a * one) - -zero_is_zero_for_multiplication :: (Vector2 BaseType) -> Property -zero_is_zero_for_multiplication a = name "zero_is_zero_for_multiplication" - (zero * a == zero && zero == a * zero) - -one_is_neutral_for_division :: (Vector2 BaseType) -> Property -one_is_neutral_for_division a = name "one_is_neutral_for_division" - (a / one == a) - -negation_is_idempotent :: (Vector2 BaseType) -> Property -negation_is_idempotent a = name "negation_is_idempotent" - (~ (~ a) == a) - - -add_then_subtract_yields_identity :: (Vector2 BaseType) -> Property -add_then_subtract_yields_identity a = name "add then subtract" ((a + a) - a == a) - -subtract_then_add_yields_identity :: (Vector2 BaseType) -> Property -subtract_then_add_yields_identity a = name "subtract then add" ((zero - a - a) + a + a == zero) - -//derive genShow (,) -//derive ggen (,) -derive bimap [] diff --git a/week2/mart/VectorOverloading.dcl b/week2/mart/VectorOverloading.dcl deleted file mode 100644 index 76f8520..0000000 --- a/week2/mart/VectorOverloading.dcl +++ /dev/null @@ -1,14 +0,0 @@ -definition module VectorOverloading - -import StdEnv - -:: Vector2 a = {x0 :: a, x1 :: a} - -instance == (Vector2 a) | == a -instance zero (Vector2 a) | zero a -instance one (Vector2 a) | one a -instance ~ (Vector2 a) | ~ a -instance + (Vector2 a) | + a -instance - (Vector2 a) | - a -instance * (Vector2 a) | * a -instance / (Vector2 a) | / a diff --git a/week2/mart/VectorOverloading.icl b/week2/mart/VectorOverloading.icl deleted file mode 100644 index 74f6f69..0000000 --- a/week2/mart/VectorOverloading.icl +++ /dev/null @@ -1,22 +0,0 @@ -implementation module VectorOverloading - -import StdEnv - -:: Vector2 a = {x0 :: a, x1 :: a} - -instance == (Vector2 a) | == a where - == a b = a.x0 == b.x0 && a.x1 == b.x1 -instance zero (Vector2 a) | zero a where - zero = {x0=zero, x1=zero} -instance one (Vector2 a) | one a where - one = {x0=one, x1=one} -instance ~ (Vector2 a) | ~ a where - ~ a = {x0= ~a.x0, x1= ~a.x1} -instance + (Vector2 a) | + a where - + a b = {x0=a.x0+b.x0, x1=a.x1+b.x1} -instance - (Vector2 a) | - a where - - a b = {x0=a.x0-b.x0, x1=a.x1-b.x1} -instance * (Vector2 a) | * a where - * a b = {x0=a.x0*b.x0, x1=a.x1*b.x1} -instance / (Vector2 a) | / a where - / a b = {x0=a.x0/b.x0, x1=a.x1/b.x1} diff --git a/week2/mart/VectorOverloadingTest.icl b/week2/mart/VectorOverloadingTest.icl deleted file mode 100644 index e5571bb..0000000 --- a/week2/mart/VectorOverloadingTest.icl +++ /dev/null @@ -1,62 +0,0 @@ -module VectorOverloadingTest - -/* Test module VectorOverloading - Voor werken met Gast: - (*) gebruik Environment 'Gast' - (*) zet Project Options op 'Basic Values Only' -*/ - -import VectorOverloading -import StdEnv -import gast - -Start - = testn 1000 - (\v -> - zero_is_neutral_for_addition v /\ - zero_is_neutral_for_subtraction v /\ - one_is_neutral_for_multiplication v /\ - one_is_neutral_for_division v /\ - negation_is_idempotent v /\ - add_then_subtract_yields_identity v /\ - subtract_then_add_yields_identity v /\ - True - ) - -:: BaseType - :== Int -// :== Real - -zero_is_neutral_for_addition :: (Vector2 BaseType) -> Property -zero_is_neutral_for_addition a = name "zero_is_neutral_for_addition" - (zero + a == a && a == a + zero) - -zero_is_neutral_for_subtraction :: (Vector2 BaseType) -> Property -zero_is_neutral_for_subtraction a = name "zero_is_neutral_for_subtraction" - (a - zero == a && a == ~ (zero - a)) - -one_is_neutral_for_multiplication :: (Vector2 BaseType) -> Property -one_is_neutral_for_multiplication a = name "one_is_neutral_for_multiplication" - (one * a == a && a == a * one) - -zero_is_zero_for_multiplication :: (Vector2 BaseType) -> Property -zero_is_zero_for_multiplication a = name "zero_is_zero_for_multiplication" - (zero * a == zero && zero == a * zero) - -one_is_neutral_for_division :: (Vector2 BaseType) -> Property -one_is_neutral_for_division a = name "one_is_neutral_for_division" - (a / one == a) - -negation_is_idempotent :: (Vector2 BaseType) -> Property -negation_is_idempotent a = name "negation_is_idempotent" - (~ (~ a) == a) - -add_then_subtract_yields_identity :: (Vector2 BaseType) -> Property -add_then_subtract_yields_identity a = name "add then subtract" ((a + a) - a == a) - -subtract_then_add_yields_identity :: (Vector2 BaseType) -> Property -subtract_then_add_yields_identity a = name "subtract then add" ((zero - a - a) + a + a == zero) - -derive genShow Vector2 -derive ggen Vector2 -derive bimap [] diff --git a/week2/week2.tar.gz b/week2/week2.tar.gz deleted file mode 100644 index 93c0467..0000000 Binary files a/week2/week2.tar.gz and /dev/null differ diff --git a/week3/camil/.gitignore b/week3/camil/.gitignore deleted file mode 100644 index 341d5f8..0000000 --- a/week3/camil/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Clean System Files/ -StdStack diff --git a/week3/camil/StdSortList.dcl b/week3/camil/StdSortList.dcl deleted file mode 100644 index 556dfc0..0000000 --- a/week3/camil/StdSortList.dcl +++ /dev/null @@ -1,18 +0,0 @@ -definition module StdSortList - -import StdClass - -:: SortList a - -newSortList :: SortList a | zero a // lege gesorteerde lijst -memberSort :: a (SortList a) -> Bool | Eq, Ord a // is element van -insertSort :: a (SortList a) -> SortList a | Ord a // voeg element toe -removeFirst :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder eerste voorkomen -removeAll :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder alle voorkomens -elements :: (SortList a) -> [a] // geef alle elementen -count :: (SortList a) -> Int // aantal elementen - -minimum :: (SortList a) -> a // huidige minimum waarde -maximum :: (SortList a) -> a // huidige maximum waarde - -mergeSortList :: (SortList a) (SortList a) -> SortList a | Eq, Ord, zero a // meng gesorteerde lijsten diff --git a/week3/camil/StdSortList.icl b/week3/camil/StdSortList.icl deleted file mode 100644 index 21778bd..0000000 --- a/week3/camil/StdSortList.icl +++ /dev/null @@ -1,64 +0,0 @@ -// Ik kreeg het alleen werkend door de .dcl ook aan te passen. -// Met een record dat het maximum bijhoudt moet je er namelijk vanuit kunnen gaan dat zero gedefinieerd is voor type a. - -implementation module StdSortList - -import StdEnv - -:: SortList a = {list :: [a], max :: a} - -newSortList :: (SortList a) | zero a -newSortList = {list=[], max=zero} - -memberSort :: a (SortList a) -> Bool | Eq, Ord a // is element van -memberSort _ {list=[],max=_} = False -memberSort m l - | minimum l == m = True - | minimum l > m = False - | otherwise = memberSort m {list=(tl l.list),max=l.max} - -insertSort :: a (SortList a) -> SortList a | Ord a // voeg element toe -insertSort m l = insertSort` {list=[],max=l.max} m l -where - insertSort` :: (SortList a) a (SortList a) -> (SortList a) | Ord a - insertSort` l1 m l2 - | count l2 == 0 = {list=l1.list ++ [m], max=m} - | minimum l2 >= m = {list=l1.list ++ [m] ++ l2.list, max=l2.max} - | otherwise = insertSort` {list=l1.list ++ [hd l2.list], max=hd l2.list} m {list=(tl l2.list), max=l2.max} - -removeFirst :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder eerste voorkomen -removeFirst m l = removeFirst` newSortList m l -where - removeFirst` :: (SortList a) a (SortList a) -> (SortList a) | Eq, Ord a - removeFirst` l1 m l2 - | count l2 == 0 = l1 - | minimum l2 > m = {list=l1.list ++ l2.list, max=l2.max} - | minimum l2 == m && count l2 == 1 = {list=l1.list ++ tl l2.list, max=l1.max} - | minimum l2 == m = {list=l1.list ++ tl l2.list, max=l2.max} - | otherwise = removeFirst` {list=(l1.list ++ [hd l2.list]),max=hd l2.list} m {list=(tl l2.list), max=l2.max} - -removeAll :: a (SortList a) -> SortList a | Eq, Ord, zero a // verwijder alle voorkomens -removeAll m l = removeAll` newSortList m l -where - removeAll` :: (SortList a) a (SortList a) -> (SortList a) | Eq, Ord a - removeAll` l1 m l2 - | count l2 == 0 = l1 - | minimum l2 > m = {list=l1.list ++ l2.list, max=l2.max} - | minimum l2 == m = removeAll` l1 m {list=tl l2.list, max=l2.max} - | otherwise = removeAll` {list=l1.list ++ [hd l2.list], max=hd l2.list} m {list=tl l2.list,max=l2.max} - -elements :: (SortList a) -> [a] // geef alle elementen -elements l = l.list - -count :: (SortList a) -> Int // aantal elementen -count l = length l.list - -minimum :: (SortList a) -> a // huidige minimum waarde -minimum l = hd l.list - -maximum :: (SortList a) -> a // huidige maximum waarde -maximum l = l.max - -mergeSortList :: (SortList a) (SortList a) -> SortList a | Eq, Ord, zero a // meng gesorteerde lijsten -mergeSortList l1 {list=[],max=_} = l1 -mergeSortList l1 l2 = mergeSortList (insertSort (hd l2.list) l1) {list=tl l2.list,max=l2.max} diff --git a/week3/camil/StdSortListTest.icl b/week3/camil/StdSortListTest.icl deleted file mode 100644 index 411f7ca..0000000 --- a/week3/camil/StdSortListTest.icl +++ /dev/null @@ -1,107 +0,0 @@ -module StdSortListTest - -/* Test module StdSortList - Voor werken met Gast: - (*) gebruik Environment 'Gast' - (*) zet Project Options op 'Basic Values Only' en '16M' Maximum Heap Size. -*/ - -import gast -import GenLexOrd -import StdSortList - -Start = testn 10000 - (\n` n2` m -> let n = lst2slst (cast [A,B,C] n` ) - n2 = lst2slst (cast [A,B,C] n2`) - in - leeg_is_leeg /\ - count_matches_elems n /\ - is_sorted_elems n /\ - member_is_member n m /\ - member_na_insert n m /\ - member_na_remove n m /\ - insert_remove_invariant n m /\ - minimum_property n /\ - maximum_property n /\ - merge_additive n n2 /\ - merge_member n n2 m /\ - True - ) - -:: Enum = A | B | C - -derive bimap [] -derive ggen Enum -derive genShow Enum -derive gEq Enum -derive gLexOrd Enum -instance == Enum where (==) x y = gEq{|*|} x y -instance < Enum where (<) x y = gEq{|*|} (gLexOrd{|*|} x y) LT - -// clean should have something like this! -cast :: a a -> a -cast _ x = x - -leeg_is_leeg :: Property -leeg_is_leeg - = name "leeg_is_leeg" - (count newSortList == 0) - -count_matches_elems :: (SortList a) -> Property | Eq, Ord a -count_matches_elems n - = name "count_matches_elems" - (length (elements n) == count n) - -is_sorted_elems :: (SortList a) -> Property | Eq, Ord a -is_sorted_elems n - = name "is_sorted_elems" - (isSorted (elements n)) - where isSorted lst = and [ x<=y \\ x<-lst & y<-tl lst ] - -member_is_member :: (SortList a) a -> Property | Eq, Ord a -member_is_member lst e - = name "member_is_member" - ((isMember e (elements lst)) <==> (memberSort e lst)) - -member_na_insert :: (SortList a) a -> Property | Eq, Ord a -member_na_insert lst e - = name "member_na_insert" - (memberSort e (insertSort e lst)) - -member_na_remove :: (SortList a) a -> Property | Eq, Ord a -member_na_remove lst e - = name "member_na_remove" - (not (memberSort e (removeAll e lst))) - -insert_remove_invariant :: (SortList a) a -> Property | Eq, Ord a -insert_remove_invariant lst e - = name "insert_remove_invariant" - (memberSort e lst <==> memberSort e lst`) - where lst` = removeFirst e (insertSort e lst) - -minimum_property :: (SortList a) -> Property | Eq,Ord a -minimum_property n - = name "minimum_property" - (count n > 0 ==> (memberSort min n /\ all ((<=) min) (elements n))) - where min = minimum n - -maximum_property :: (SortList a) -> Property | Eq,Ord a -maximum_property n - = name "maximum_property" - (count n > 0 ==> (memberSort max n /\ all ((>=) max) (elements n))) - where max = maximum n - -merge_member :: (SortList a) (SortList a) a -> Property | Eq,Ord a -merge_member n m e - = name "merge_member" - (memberSort e nm <==> (memberSort e n \/ memberSort e m)) - where nm = mergeSortList n m - -merge_additive :: (SortList a) (SortList a) -> Property | Eq,Ord a -merge_additive n m - = name "merge_additive" - (count n + count m == count nm) - where nm = mergeSortList n m - -lst2slst :: [a] -> SortList a | Eq,Ord a -lst2slst xs = seq (map insertSort xs) newSortList diff --git a/week3/camil/StdStack.dcl b/week3/camil/StdStack.dcl deleted file mode 100644 index 8c861a1..0000000 --- a/week3/camil/StdStack.dcl +++ /dev/null @@ -1,13 +0,0 @@ -definition module StdStack - -:: Stack a - -newStack :: Stack a // lege stack -push :: a (Stack a) -> Stack a // plaats nieuw element bovenop de stack -pushes :: [a] (Stack a) -> Stack a // plaats elementen achtereenvolgens bovenop stack -pop :: (Stack a) -> Stack a // haal top element van stack -popn :: Int (Stack a) -> Stack a // haal bovenste $n$ top elementen van stack -top :: (Stack a) -> a // geef top element van stack -topn :: Int (Stack a) -> [a] // geef bovenste $n$ top elementen van stack -elements :: (Stack a) -> [a] // geef alle elementen van stack -count :: (Stack a) -> Int // tel aantal elementen in stack diff --git a/week3/camil/StdStack.icl b/week3/camil/StdStack.icl deleted file mode 100644 index dd51a94..0000000 --- a/week3/camil/StdStack.icl +++ /dev/null @@ -1,66 +0,0 @@ -implementation module StdStack - -import StdEnv -import StdList - -:: Stack a :== [a] - -newStack :: (Stack a) -newStack = [] - -push :: a (Stack a) -> (Stack a) -push a s = [a] ++ s - -pop :: (Stack a) -> (Stack a) -pop [a:s] = s -pop [] = [] - -popn :: Int (Stack a) -> (Stack a) -popn 0 s = s -popn n s = popn (n-1) (pop s) - -pushes :: [a] (Stack a) -> (Stack a) -pushes [] s = s -pushes a s = pushes (tl a) (push (hd a) s) - -top :: (Stack a) -> a -top [] = abort "`top s` with s = []" -top s = hd s - -topn :: Int (Stack a) -> [a] -topn n s - | n > length s = abort "`topn n s` with n > length s" - | otherwise = take n s - -count :: (Stack a) -> Int -count s = length s - -elements :: (Stack a) -> [a] -elements s = s - -Start = ( "s0 = newStack = ", s0,'\n' - , "s1 = push 1 s0 = ", s1,'\n' - , "s2 = pushes [2..5] s1 = ",s2,'\n' - , "s3 = pop s2 = ", s3,'\n' - , "s4 = popn 3 s3 = ", s4,'\n' - , "s5 = top s4 = ", s5,'\n' - , "s6 = topn 3 s2 = ", s6,'\n' - , "s7 = elements s2 = ", s7,'\n' -// , "s8 = push 10 s1 = ", s8,'\n' -// , "s9 = popn 10 s8 = ", s9,'\n' -// , "sa = topn 5 s4 = ", sa,'\n' -// , "sb = top s0 = ", sb,'\n' - ) -where - s0 = newStack - s1 = push 1 s0 - s2 = pushes [2..5] s1 - s3 = pop s2 - s4 = popn 3 s3 - s5 = top s4 - s6 = topn 3 s2 - s7 = elements s2 -// s8 = push 10 s1 -// s9 = popn 10 s8 -// sa = topn 5 s4 -// sb = top s0 diff --git a/week3/camil/StdStackTest.icl b/week3/camil/StdStackTest.icl deleted file mode 100644 index 8127f53..0000000 --- a/week3/camil/StdStackTest.icl +++ /dev/null @@ -1,60 +0,0 @@ -module StdStackTest - -/* Test module StdStack - Voor werken met Gast: - (*) gebruik Environment 'Gast' - (*) zet Project Options op 'Basic Values Only' en '2M' Maximum Heap Size -*/ - -import gast -import StdStack - -Start - = testn 1000 - (\x n -> - newStack_is_empty /\ - stack_is_reverse n /\ - pop_empty_is_ok /\ - top_na_push n x /\ - pop_na_push x /\ - count_counts n x /\ - pop_maakt_stack_korter n /\ - True - ) - -newStack_is_empty :: Property -newStack_is_empty = name "newStack_is_empty" (isEmpty (elements empty)) - -stack_is_reverse :: Int -> Property -stack_is_reverse n = name "stack_is_reverse" - (elements (pushes [1..n`] newStack) == reverse [1..n`]) -where n` = min (abs n) 100 - -pop_empty_is_ok :: Property -pop_empty_is_ok = name "pop_empty_is_ok" (count (pop empty) == 0) - -top_na_push :: Int Int -> Property -top_na_push x n = name "top_na_push" - (top (push x (pushes [1..n`] newStack)) == x) -where n` = min (abs n) 100 - -pop_na_push :: Int -> Property -pop_na_push a = name "pop_na_push" - (top (pop (pop (pushes [a,b,c] newStack))) == a) -where b = a + a + one - c = b + a + one - -count_counts :: Int Int -> Property -count_counts n x = name "count_counts" - (length (elements stack) == count stack) -where stack = pushes [1..n`] newStack - n` = min (abs n) 100 - -pop_maakt_stack_korter :: Int -> Property -pop_maakt_stack_korter n = name "pop_maakt_stack_korter" - (count stack == 0 || count (pop stack) == count stack - 1) -where stack = pushes [1..n`] newStack - n` = min (abs n) 100 - -empty :: Stack Int -empty = newStack diff --git a/week3/mart/StdSortList.dcl b/week3/mart/StdSortList.dcl deleted file mode 100644 index 46bd238..0000000 --- a/week3/mart/StdSortList.dcl +++ /dev/null @@ -1,18 +0,0 @@ -definition module StdSortList - -import StdClass - -:: SortList a - -newSortList :: SortList a // lege gesorteerde lijst -memberSort :: a (SortList a) -> Bool | Eq, Ord a // is element van -insertSort :: a (SortList a) -> SortList a | Ord a // voeg element toe -removeFirst :: a (SortList a) -> SortList a | Eq, Ord a // verwijder eerste voorkomen -removeAll :: a (SortList a) -> SortList a | Eq, Ord a // verwijder alle voorkomens -elements :: (SortList a) -> [a] // geef alle elementen -count :: (SortList a) -> Int // aantal elementen - -minimum :: (SortList a) -> a // huidige minimum waarde -maximum :: (SortList a) -> a // huidige maximum waarde - -mergeSortList :: (SortList a) (SortList a) -> SortList a | Eq, Ord a // meng gesorteerde lijsten diff --git a/week3/mart/StdSortList.icl b/week3/mart/StdSortList.icl deleted file mode 100644 index db71a36..0000000 --- a/week3/mart/StdSortList.icl +++ /dev/null @@ -1,50 +0,0 @@ -implementation module StdSortList - -import StdEnv - -:: SortList a :== ([a], a) - -newSortList :: SortList a -newSortList = ([], abort "Empty list") - -memberSort :: a (SortList a) -> Bool | Eq, Ord a -memberSort e ([], y) = y -memberSort e ([x:xs], y) -| e == x = True -| e > x = False -| otherwise = memberSort e (xs, y) - -insertSort :: a (SortList a) -> SortList a | Ord a -insertSort e ([], y) = ([e], e) -insertSort e ([x:xs], y) -| e <= x = ([e:x:xs], y) -| otherwise = ([x:fst result], snd result) - where result = insertSort e (xs, y) - -removeFirst :: a (SortList a) -> SortList a | Eq, Ord a -removeFirst e ([], y) = y -removeFirst e ([e], e) = newSortList -removeFirst e ([x:xs], y) -| e == x = ([xs], y) -removeFirst _ _ = abort "" - -removeAll :: a (SortList a) -> SortList a | Eq, Ord a -removeAll _ _ = abort "" - -elements :: (SortList a) -> [a] -elements _ = abort "" - -count :: (SortList a) -> Int -count _ = abort "" - -minimum :: (SortList a) -> a -minimum _ = abort "" - -maximum :: (SortList a) -> a -maximum _ = abort "" - -mergeSortList :: (SortList a) (SortList b) -> (SortList a) -mergeSortList _ _ = abort "" - -Start :: String -Start = newSortList diff --git a/week3/mart/StdStack.dcl b/week3/mart/StdStack.dcl deleted file mode 100644 index 8c861a1..0000000 --- a/week3/mart/StdStack.dcl +++ /dev/null @@ -1,13 +0,0 @@ -definition module StdStack - -:: Stack a - -newStack :: Stack a // lege stack -push :: a (Stack a) -> Stack a // plaats nieuw element bovenop de stack -pushes :: [a] (Stack a) -> Stack a // plaats elementen achtereenvolgens bovenop stack -pop :: (Stack a) -> Stack a // haal top element van stack -popn :: Int (Stack a) -> Stack a // haal bovenste $n$ top elementen van stack -top :: (Stack a) -> a // geef top element van stack -topn :: Int (Stack a) -> [a] // geef bovenste $n$ top elementen van stack -elements :: (Stack a) -> [a] // geef alle elementen van stack -count :: (Stack a) -> Int // tel aantal elementen in stack diff --git a/week3/mart/StdStack.icl b/week3/mart/StdStack.icl deleted file mode 100644 index 13220e1..0000000 --- a/week3/mart/StdStack.icl +++ /dev/null @@ -1,57 +0,0 @@ -implementation module StdStack - -import StdEnv - -:: Stack a = Stack [a] - -newStack :: Stack a -newStack = Stack [] - -push :: a (Stack a) -> Stack a -push x (Stack xs) = Stack [x:xs] - -pushes :: [a] (Stack a) -> Stack a -pushes [] (Stack s) = Stack s -pushes [x:xs] (Stack s) = pushes xs (push x (Stack s)) - -pop :: (Stack a) -> Stack a -pop (Stack []) = abort "Can't pop from empty stack..." -pop (Stack [x:xs]) = Stack xs - -popn :: Int (Stack a) -> Stack a -popn 0 s = s -popn n s = popn (n-1) (pop s) - -top :: (Stack a) -> a -top (Stack []) = abort "Can't give top of empty stack..." -top (Stack [x:_]) = x - -topn :: Int (Stack a) -> [a] -topn 0 _ = [] -topn n x = [top x:topn (n-1) (pop x)] - -elements :: (Stack a) -> [a] -elements (Stack s) = s - -count :: (Stack a) -> Int -count (Stack []) = 0 -count (Stack [_:xs]) = 1 + count (Stack xs) - -Start = ( "s0 = newStack = ", s0,'\n' - , "s1 = push 1 s0 = ", s1,'\n' - , "s2 = pushes [2..5] s1 = ",s2,'\n' - , "s3 = pop s2 = ", s3,'\n' - , "s4 = popn 3 s3 = ", s4,'\n' - , "s5 = top s4 = ", s5,'\n' - , "s6 = topn 3 s2 = ", s6,'\n' - , "s7 = elements s2 = ", s7,'\n' - ) -where - s0 = newStack - s1 = push 1 s0 - s2 = pushes [2..5] s1 - s3 = pop s2 - s4 = popn 3 s3 - s5 = top s4 - s6 = topn 3 s2 - s7 = elements s2 diff --git a/week4/camil/5.4 b/week4/camil/5.4 deleted file mode 100644 index accd855..0000000 --- a/week4/camil/5.4 +++ /dev/null @@ -1,5 +0,0 @@ -1. Optelling in de gehele getallen is commutatief, dit maakt dus niet uit. -2. Het verschil tussen 4-2=2 en 2-4=-2. - Algemeen: het verschill tussen (-) a b = a-b en flip (-) a b = b-a, dus (-) a b = - flip (-) a b -3. Vermenigvuldiging in de gehele getallen is commutatief, dit maakt dus niet uit. -3. Het verschil tussen 4/2=2 en 2/4=0. diff --git a/week4/camil/StdSet.dcl b/week4/camil/StdSet.dcl deleted file mode 100644 index 6cad7f1..0000000 --- a/week4/camil/StdSet.dcl +++ /dev/null @@ -1,25 +0,0 @@ -definition module StdSet - -import StdClass - -:: Set a - -toSet :: [a] -> Set a | Eq a -fromSet :: (Set a) -> [a] - -isEmptySet :: (Set a) -> Bool -isDisjoint :: (Set a) (Set a) -> Bool | Eq a -isSubset :: (Set a) (Set a) -> Bool | Eq a -isStrictSubset :: (Set a) (Set a) -> Bool | Eq a -memberOfSet :: a (Set a) -> Bool | Eq a -union :: (Set a) (Set a) -> Set a | Eq a -intersection :: (Set a) (Set a) -> Set a | Eq a -nrOfElements :: (Set a) -> Int -without :: (Set a) (Set a) -> Set a | Eq a - -product :: (Set a) (Set b) -> Set (a,b) - -instance zero (Set a) -instance == (Set a) | Eq a - -powerSet :: (Set a) -> Set (Set a) diff --git a/week4/camil/StdSet.icl b/week4/camil/StdSet.icl deleted file mode 100644 index 651c869..0000000 --- a/week4/camil/StdSet.icl +++ /dev/null @@ -1,64 +0,0 @@ -implementation module StdSet - -import StdEnv -import StdClass - -:: Set a :== [a] - -toSet :: [a] -> Set a | Eq a -toSet l = toSet` l [] -where - toSet` [] s = s - toSet` [x:xs] s = toSet` xs (join x s) - where - join :: a (Set a) -> Set a | Eq a - join e s - | memberOfSet e s = s - | otherwise = s ++ [e] - -fromSet :: (Set a) -> [a] -fromSet s = s - -isEmptySet :: (Set a) -> Bool -isEmptySet [] = True -isEmptySet _ = False - -isDisjoint :: (Set a) (Set a) -> Bool | Eq a -isDisjoint s1 s2 = length (intersection s1 s2) == 0 - -isSubset :: (Set a) (Set a) -> Bool | Eq a -isSubset s1 s2 = nrOfElements (intersection s1 s2) == nrOfElements s1 - -isStrictSubset :: (Set a) (Set a) -> Bool | Eq a -isStrictSubset s1 s2 = isSubset s1 s2 && s1 <> s2 - -memberOfSet :: a (Set a) -> Bool | Eq a -memberOfSet e [] = False -memberOfSet e [x:xs] - | e == x = True - | otherwise = memberOfSet e xs - -union :: (Set a) (Set a) -> Set a | Eq a -union s1 s2 = toSet (s1 ++ s2) - -intersection :: (Set a) (Set a) -> Set a | Eq a -intersection s1 s2 = [e \\ e <- s1 | memberOfSet e s2] - -nrOfElements :: (Set a) -> Int -nrOfElements s = length (fromSet s) - -without :: (Set a) (Set a) -> Set a | Eq a -without s1 s2 = [e \\ e <- s1 | (memberOfSet e s2) == False] - -product :: (Set a) (Set b) -> Set (a,b) -product s1 s2 = [(e1,e2) \\ e1 <- s1, e2 <- s2] - -instance zero (Set a) -where zero = [] - -instance == (Set a) | Eq a -where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1 - -powerSet :: (Set a) -> Set (Set a) -powerSet [] = [zero] -powerSet [e:es] = map ((++) [e]) (powerSet es) ++ powerSet es \ No newline at end of file diff --git a/week4/mart/5.4.txt b/week4/mart/5.4.txt deleted file mode 100644 index 50521d3..0000000 --- a/week4/mart/5.4.txt +++ /dev/null @@ -1,4 +0,0 @@ -1. 4+2 en 2+4. Dit geeft zelfde uitkomst ivm commutativiteit van + -2. 4-2 en 2-4. Dit geeft 2 en -2. - is niet commutitatief. -3. 4*2 en 2*4. Dit geeft zelfde uitkomst ivm commutativiteit van * -4. 4/2 en 2/4. Dit geeft 2 en 0. / is niet commutitatief. diff --git a/week4/mart/StdSet.dcl b/week4/mart/StdSet.dcl deleted file mode 100644 index 0c702ca..0000000 --- a/week4/mart/StdSet.dcl +++ /dev/null @@ -1,25 +0,0 @@ -definition module StdSet - -import StdClass - -:: Set a - -toSet :: [a] -> Set a | Eq a -fromSet :: (Set a) -> [a] - -isEmptySet :: (Set a) -> Bool -isDisjoint :: (Set a) (Set a) -> Bool | Eq a -isSubset :: (Set a) (Set a) -> Bool | Eq a -isStrictSubset :: (Set a) (Set a) -> Bool | Eq a -memberOfSet :: a (Set a) -> Bool | Eq a -union :: (Set a) (Set a) -> Set a | Eq a -intersection :: (Set a) (Set a) -> Set a | Eq a -nrOfElements :: (Set a) -> Int -without :: (Set a) (Set a) -> Set a | Eq a - -product :: (Set a) (Set b) -> Set (a,b) - -instance zero (Set a) -instance == (Set a) | Eq a - -powerSet :: (Set a) -> Set (Set a) | Eq a diff --git a/week4/mart/StdSet.icl b/week4/mart/StdSet.icl deleted file mode 100644 index ecb2e60..0000000 --- a/week4/mart/StdSet.icl +++ /dev/null @@ -1,54 +0,0 @@ -implementation module StdSet - -import StdEnv -import StdClass - -:: Set a = Set [a] - -toSet :: [a] -> Set a | Eq a -toSet s = Set (removeDup s) - -fromSet :: (Set a) -> [a] -fromSet (Set s) = s - -isEmptySet :: (Set a) -> Bool -isEmptySet s = isEmpty (fromSet s) - -isDisjoint :: (Set a) (Set a) -> Bool | Eq a -isDisjoint s1 s2 = nrOfElements (intersection s1 s2) == 0 - -isSubset :: (Set a) (Set a) -> Bool | Eq a -isSubset s1 s2 = nrOfElements s1 == nrOfElements (intersection s1 s2) - -isStrictSubset :: (Set a) (Set a) -> Bool | Eq a -isStrictSubset s1 s2 = isSubset s1 s2 && nrOfElements s1 < nrOfElements s2 - -memberOfSet :: a (Set a) -> Bool | Eq a -memberOfSet a (Set []) = False -memberOfSet a (Set [x:xs]) = a == x || memberOfSet a (Set xs) - -union :: (Set a) (Set a) -> Set a | Eq a -union (Set s1) (Set s2) = toSet (s1 ++ s2) - -intersection :: (Set a) (Set a) -> Set a | Eq a -intersection (Set s1) s2 = Set [e \\ e <- s1 | memberOfSet e s2] - -nrOfElements :: (Set a) -> Int -nrOfElements s = length (fromSet s) - -without :: (Set a) (Set a) -> Set a | Eq a -without (Set s1) s2 = Set [e \\ e <- s1 | not (memberOfSet e s2)] - -product :: (Set a) (Set b) -> Set (a,b) -product (Set s1) (Set s2) = Set [(e1, e2) \\ e1 <- s1, e2 <- s2] - -instance zero (Set a) -where zero = Set [] - -instance == (Set a) | Eq a -where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1 - -powerSet :: (Set a) -> Set (Set a) | Eq a -powerSet (Set []) = Set [(Set [])] -powerSet (Set [e:xs]) = union (powerSet (Set xs)) - (Set [union (Set [e]) x \\ x <- fromSet (powerSet (Set xs))]) diff --git a/week4/week4.tar.gz b/week4/week4.tar.gz deleted file mode 100644 index 0258701..0000000 Binary files a/week4/week4.tar.gz and /dev/null differ diff --git a/week5/camil/Origami.icl b/week5/camil/Origami.icl deleted file mode 100644 index 74362a9..0000000 --- a/week5/camil/Origami.icl +++ /dev/null @@ -1,24 +0,0 @@ -module Origami - -import StdEnv - -Start = and - [ sum` [1 .. 5] == sum [1 .. 5] - , prod` [1 .. 5] == prod [1 .. 5] - , flatten` [[],[1],[1,2],[1,2,3]] == flatten [[],[1],[1,2],[1,2,3]] - , reverse` [1 .. 5] == reverse [1 .. 5] - , takeWhile` ((<>) 0) [1,2,3,0,4,5,6] == takeWhile ((<>) 0) [1,2,3,0,4,5,6] - , maxList` [1 .. 5] == maxList [1 .. 5] - ] - -sum` = foldr (+) 0 -prod` = foldr (*) 1 -flatten` = foldr (++) [] -length` = foldl (\l e = l + 1) 0 -reverse` = foldl (\xs x = [x:xs]) [] -takeWhile` _ [] = [] -takeWhile` p xs - | p (xs!!0) = take (maxList [i \\ i <- [0..length xs-1] | foldr (&&) True [p (xs!!j) \\ j <- [0..i]]] + 1) xs - | otherwise = [] -maxList` [] = undef -maxList` [x:xs] = foldr max x xs diff --git a/week5/mart/Origami.icl b/week5/mart/Origami.icl deleted file mode 100644 index 180a119..0000000 --- a/week5/mart/Origami.icl +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Mart Lubbers, s4109503 - * Camil Staps, s4498062 - */ - -module Origami - -import StdEnv - -sum` = foldr (+) 0 -prod` = foldr (*) 1 -flatten` = foldr (++) [] -length` = foldr (\x l=l+1) 0 -reverse` = foldl (\xs x=[x:xs]) [] -takeWhile` p = foldr (\x xs=if (p x) [x:xs] []) [] -maxList` [x:xs] = foldr max x xs diff --git a/week6/camil/BewijsMapFlatten.icl b/week6/camil/BewijsMapFlatten.icl deleted file mode 100644 index 7f2474e..0000000 --- a/week6/camil/BewijsMapFlatten.icl +++ /dev/null @@ -1,83 +0,0 @@ -// Mart Lubbers, s4109503 -// Camil Staps, s4498062 - -Zij gegeven: - -(++) :: [a] [a] -> [a] -(++) [] xs = xs (1) -(++) [y:ys] xs = [y : ys ++ xs] (2) - -map :: (a -> b) [a] -> [b] -map f [] = [] (3) -map f [x:xs] = [f x : map f xs] (4) - -flatten :: [[a]] -> [a] -flatten [] = [] (5) -flatten [x:xs] = x ++ (flatten xs) (6) - -1. -Te bewijzen: - voor iedere functie f, eindige lijst as en bs: - - map f (as ++ bs) = (map f as) ++ (map f bs) - -Bewijs: -Met inductie over as. - -Inductiebasis: -Stel as = []. Dan hebben we: - - map f (as ++ bs) // aanname as = [] - = map f ([] ++ bs) // definitie van ++, regel 1 - = map f bs // definitie van ++, regel 1 - = [] ++ (map f bs) // definitie van map, regel 3 - = (map f []) ++ (map f bs) // aanname as = [] - = (map f as) ++ (map f bs). - -Inductiestap: -Stel map f (as ++ bs) = (map f as) ++ (map f bs) voor zekere as en elke bs (inductiehypothese). Dan hebben we: - - map f ([a:as] ++ bs) // definitie van ++, regel 2 - = map f [a:as ++ bs] // definitie van map, regel 4 - = [f a : map f (as ++ bs)] // inductiehypothese: map f (as ++ bs) = (map f as) ++ (map f bs) - = [f a : (map f as) ++ (map f bs)] // lijst herschrijven - = [f a : map f as] ++ (map f bs) // definitie van map, regel 4 - = (map f [a:as]) ++ (map f bs). - -Uit het principe van volledige inductie volgt nu dat voor iedere functie f, eindige lijst as en bs: - - map f (as ++ bs) = (map f as) ++ (map f bs) (9.4.1) - -2. -Te bewijzen: - voor iedere functie f, voor iedere eindige lijst xs: - - flatten (map (map f) xs) = map f (flatten xs) - -Bewijs: -Met inductie over xs. - -Inductiebasis: -Stel xs = []. Dan hebben we: - - flatten (map (map f) xs) // aanname xs = [] - = flatten (map (map f) []) // definitie van map, regel 3 - = flatten [] // definitie van flatten, regel 5 - = [] // definitie van map, regel 3 - = map f [] // definitie van flatten, regel 5 - = map f (flatten []) // aanname xs = [] - = map f (flatten xs). - -Inductiestap: -Stel flatten (map (map f) xs) = map f (flatten xs) voor een zekere eindige lijst xs (inductiehypothese). Dan hebben we: - - flatten (map (map f) [x:xs]) // definitie van map, regel 4 - = flatten [map f x : map (map f) xs] // definitie van flatten, regel 6 - = (map f x) ++ flatten (map (map f) xs) // inductiehypothese: flatten (map (map f) xs) = map f (flatten xs) - = (map f x) ++ (map f (flatten xs)) // 9.4.1 - = map f (x ++ (flatten xs)) // definitie van flatten, regel 6 - = map f (flatten [x:xs]). - -Uit het principe van volledige inductie volgt nu dat voor iedere functie f en eindige lijst xs geldt: - - flatten (map (map f) xs) = map f (flatten xs) diff --git a/week6/mart/BewijsMapFlatten.icl b/week6/mart/BewijsMapFlatten.icl deleted file mode 100644 index 59fa5bc..0000000 --- a/week6/mart/BewijsMapFlatten.icl +++ /dev/null @@ -1,97 +0,0 @@ -Zij gegeven: - -(++) :: [a] [a] -> [a] -(++) [] xs = xs (1) -(++) [y:ys] xs = [y : ys ++ xs] (2) - -map :: (a -> b) [a] -> [b] -map f [] = [] (3) -map f [x:xs] = [f x : map f xs] (4) - -flatten :: [[a]] -> [a] -flatten [] = [] (5) -flatten [x:xs] = x ++ (flatten xs) (6) - -1. -Te bewijzen: - voor iedere functie f, eindige lijst as en bs: - - map f (as ++ bs) = (map f as) ++ (map f bs) - -Bewijs: - met inductie naar de lengte van as. - - Basis: - aanname: as = []. - - map f ([] ++ bs) = (map f []) ++ (map f bs) basis - ******** - => map f (bs) = (map f []) ++ (map f bs) (1) - ******** - => map f (bs) = [] ++ (map f bs) (3) - **************** - => map f bs = map f bs (1) - - Inductiestap: - aanname: stelling geldt voor zekere as, ofwel: - map f (as ++ bs) = (map f as) ++ (map f bs) (IH) - - Te bewijzen: stelling geldt ook voor as, ofwel: - map f ([a:as] ++ bs) = (map f [a:as]) ++ (map f bs) - - map f ([a:as] ++ bs) = (map f [a:as]) ++ (map f bs) basis - ************ - => map f [a:as ++ bs] = (map f [a:as]) ++ (map f bs) (2) - ****************** - => [f a : map f (as ++ bs)] = (map f [a:as]) ++ (map f bs) (4) - ************ - => [f a : map f (as ++ bs)] = [f a : map f as] ++ (map f bs) (4) - **************************** - => [f a : map f (as ++ bs)] = [f a : (map f as) ++ (map f bs)] (4) - **************** ************************ - => map f (as ++ bs) = (map f as) ++ (map f bs) (IH) - - Dus: basis + inductiestap => stelling bewezen. - -2. -Te bewijzen: - voor iedere functie f, voor iedere eindige lijst xs: - - flatten (map (map f) xs) = map f (flatten xs) - -Bewijs: - met inductio van de lengte van xs - - Basis: - aanname: xs = []. - - flatten (map (map f) []) = map f (flatten []) basis - ************** - = flatten [] = map f (flatten []) (3) - ********** - = flatten [] = map f [] (5) - ********** - = [] = map f [] (5) - ***** - = [] = [] (3) - - Inductiestap: - aanname: stelling geldt voor zekere xs, ofwel: - flatten (map (map f) xs) = map f (flatten xs) - - Te bewijzen: stelling geldt ook voor xs, ofwel: - flatten (map (map f) [x:xs]) = map f (flatten [x:xs]) - - flatten (map (map f) [x:xs]) = map f (flatten [x:xs]) basis - ****************** - => flatten [map f x: map (map f) xs] = map f (flatten [x:xs]) (4) - ********************************* - => (map f x) ++ (flatten (map (map f) xs)) = map f (flatten [x:xs]) (6) - ************** - => (map f x) ++ (flatten (map (map f) xs)) = map f (x ++ (flatten xs)) (6) - ************************* - => (map f x) ++ (flatten (map (map f) xs)) = (map f x) ++ (map f (flatten xs)) (9.4.1) - ************************ **************** - => flatten (map (map f) xs) = map f (flatten xs) (IH) - - Dus: basis + inductiestap => stelling bewezen. diff --git a/week7/camil/BewijsMeppenEnTippen.icl b/week7/camil/BewijsMeppenEnTippen.icl deleted file mode 100644 index ca5e396..0000000 --- a/week7/camil/BewijsMeppenEnTippen.icl +++ /dev/null @@ -1,82 +0,0 @@ -// Mart Lubbers, s4109503 -// Camil Staps, s4498062 - -Zij gegeven: - -:: BTree a = Tip a | Bin (BTree a) (BTree a) - -map :: (a -> b) [a] -> [b] -map f [] = [] (1.) -map f [x:xs] = [f x : map f xs] (2.) - -mapbtree :: (a -> b) (BTree a) -> BTree b -mapbtree f (Tip a) = Tip (f a) (3.) -mapbtree f (Bin t1 t2) = Bin (mapbtree f t1) (mapbtree f t2) (4.) - -foldbtree :: (a a -> a) (BTree a) -> a -foldbtree f (Tip x) = x (5.) -foldbtree f (Bin t1 t2) = f (foldbtree f t1) (foldbtree f t2) (6.) - -tips :: (BTree a) -> [a] -tips t = foldbtree (++) (mapbtree unit t) (7.) - -unit :: a -> [a] -unit x = [x] (8.) - - -Te bewijzen: - voor alle functies f, voor alle eindige bomen t: - - map f (tips t) = tips (mapbtree f t) - -Bewijs: - Met inductie over t. - - Inductiebasis: stel t = Tip a. - Dan hebben we: - - map f (tips t) // definitie tips (7) - = map f (foldbtree (++) (mapbtree unit t)) // aanname t = Tip a - = map f (foldbtree (++) (mapbtree unit (Tip a))) // definitie mapbtree (3) - = map f (foldbtree (++) (Tip unit a)) // definitie foldbtree (5) - = map f (unit a) // definitie unit (8) - = map f [a] // herschrijven lijst - = map f [a:[]] // definitie map (2) - = [f a : map f []] // definitie map (1) - = [f a : []] // herschrijven lijst - = [f a] // definitie unit (8) - = unit (f a) // definitie foldbtree (5) - = foldbtree (++) (Tip (unit (f a))) // definitie mapbtree (3) - = foldbtree (++) (mapbtree unit (Tip (f a))) // definitie tips (7) - = tips (Tip (f a)) // definitie mapbtree (3) - = tips (mapbtree f (Tip a)) // aanname t = Tip a - = tips (mapbtree f t) - - Dus de stelling geldt voor t = Tip a. - - Inductiestap: laten we aannemen dat - map f (tips t) = tips (mapbtree f t) - voor alle f en zekere t=t1,t=t2 (inductiehypothese). - Dan hebben we: - - map f (tips (Bin t1 t2)) // definitie tips (7) - = map f (foldbtree (++) (mapbtree unit (Bin t1 t2))) // definitie mapbtree (4) - = map f (foldbtree (++) (Bin (mapbtree unit t1) (mapbtree unit t2))) // definitie foldbtree (6) - = map f ((++) (foldbtree (++) (mapbtree unit t1)) (foldbtree (++) (mapbtree unit t2))) // definitie tips (7) - = map f ((++) (tips t1) (tips t2)) // 9.4.1 - = (map f (tips t1)) ++ (map f (tips t2)) // inductiehypothese - = (tips (mapbtree f t1)) ++ (tips (mapbtree f t2)) // definitie tips (7) - = (foldbtree (++) (mapbtree unit (f t1))) ++ (foldbtree (++) (mapbtree unit (f t2))) // herschrijven infixnotatie - = (++) (foldbtree (++) (mapbtree unit (f t1))) (foldbtree (++) (mapbtree unit (f t2))) // definitie foldbtree (6) - = foldbtree (++) (Bin (mapbtree unit (f t1)) (mapbtree unit (f t2))) // definitie mapbtree (4) - = foldbtree (++) (mapbtree unit (Bin (mapbtree f t1) (mapbtree f t2))) // definitie tips (7) - = tips (Bin (mapbtree f t1) (mapbtree f t2)) // definitie mapbtree (4) - = tips (mapbtree f (Bin t1 t2)) - - Conclusie: - We hebben laten zien dat de stelling geldt voor elke f met t = Tip a. Vervolgens hebben we laten zien dat als de stelling geldt voor elke f met t=t1 of t=t2, de stelling óók geldt voor elke f met t = Bin t1 t2. - Met het principe van inductie volgt nu - - map f (tips t) = tips (mapbtree f t) - - voor alle functies f en alle eindige bomen t. \ No newline at end of file diff --git a/week7/camil/BinSearchTree.dcl b/week7/camil/BinSearchTree.dcl deleted file mode 100644 index 696b065..0000000 --- a/week7/camil/BinSearchTree.dcl +++ /dev/null @@ -1,7 +0,0 @@ -definition module BinSearchTree - -import StdClass -import BinTree - -is_geordend :: (Tree a) -> Bool | Ord a // meest algemene type -is_gebalanceerd :: (Tree a) -> Bool | Ord a // meest algemene type diff --git a/week7/camil/BinSearchTree.icl b/week7/camil/BinSearchTree.icl deleted file mode 100644 index 559846b..0000000 --- a/week7/camil/BinSearchTree.icl +++ /dev/null @@ -1,177 +0,0 @@ -// Mart Lubbers, s4109503 -// Camil Staps, s4498062 - -implementation module BinSearchTree - -import StdEnv -import BinTree - -z0 = Leaf -// Leaf - -z1 = insertTree 50 z0 -// 50 -// | -// ------------- -// | | -// Leaf Leaf - -z2 = insertTree 10 z1 -// 50 -// | -// ------------- -// | | -// 10 Leaf -// | -// --------- -// | | -// Leaf Leaf - -z3 = insertTree 75 z2 -// 50 -// | -// --------------- -// | | -// 10 75 -// | | -// --------- --------- -// | | | | -// Leaf Leaf Leaf Leaf - -z4 = insertTree 80 z3 -// 50 -// | -// --------------- -// | | -// 10 75 -// | | -// --------- --------- -// | | | | -// Leaf Leaf Leaf 80 -// | -// --------- -// | | -// Leaf Leaf - -z5 = insertTree 77 z4 -// 50 -// | -// --------------- -// | | -// 10 75 -// | | -// --------- --------- -// | | | | -// Leaf Leaf Leaf 77 -// | -// --------- -// | | -// Leaf 80 -// | -// --------- -// | | -// Leaf Leaf - -z6 = insertTree 10 z5 -// 50 -// | -// --------------- -// | | -// 10 75 -// | | -// --------- --------- -// | | | | -// 10 Leaf Leaf 77 -// | | -// --------- --------- -// | | | | -// Leaf Leaf Leaf 80 -// | -// --------- -// | | -// Leaf Leaf - -z7 = insertTree 75 z6 -// 50 -// | -// ---------------- -// | | -// 10 75 -// | | -// --------- ----------- -// | | | | -// 10 Leaf 75 77 -// | | | -// --------- ------ ------- -// | | | | | | -// Leaf Leaf Leaf Leaf Leaf 80 -// | -// --------- -// | | -// Leaf Leaf - -z8 = deleteTree 50 z7 -// 10 -// | -// ---------------- -// | | -// 10 75 -// | | -// --------- ----------- -// | | | | -// Leaf Leaf 75 77 -// | | -// ------ ------- -// | | | | -// Leaf Leaf Leaf 80 -// | -// --------- -// | | -// Leaf Leaf - -// Uit het diktaat, blz. 73: -insertTree :: a (Tree a) -> Tree a | Ord a -insertTree e Leaf = Node e Leaf Leaf -insertTree e (Node x le ri) -| e <= x = Node x (insertTree e le) ri -| e > x = Node x le (insertTree e ri) - -deleteTree :: a (Tree a) -> (Tree a) | Eq, Ord a -deleteTree e Leaf = Leaf -deleteTree e (Node x le ri) -| e < x = Node x (deleteTree e le) ri -| e == x = join le ri -| e > x = Node x le (deleteTree e ri) -where - join :: (Tree a) (Tree a) -> (Tree a) - join Leaf b2 = b2 - join b1 b2 = Node x b1` b2 - where - (x,b1`) = largest b1 - - largest :: (Tree a) -> (a,(Tree a)) - largest (Node x b1 Leaf) = (x,b1) - largest (Node x b1 b2) = (y,Node x b1 b2`) - where - (y,b2`) = largest b2 - - -is_geordend :: (Tree a) -> Bool | Ord a // meest algemene type -is_geordend Leaf = True -is_geordend (Node x le ri) = (foldr (&&) True (map ((>) x) (members le))) && (foldr (&&) True (map ((<=) x) (members ri))) && is_geordend le && is_geordend ri -where - members :: (Tree a) -> [a] - members Leaf = [] - members (Node x le ri) = [x:(members le) ++ (members ri)] - -//Start = map is_geordend [t0,t1,t2,t3,t4,t5,t6,t7] - -is_gebalanceerd :: (Tree a) -> Bool | Ord a // meest algemene type -is_gebalanceerd Leaf = True -is_gebalanceerd (Node x le ri) = abs ((depth le) - (depth ri)) <= 1 && is_gebalanceerd le && is_gebalanceerd ri -where - depth :: (Tree a) -> Int - depth Leaf = 0 - depth (Node x le ri) = max (depth le) (depth ri) + 1 - -//Start = map is_gebalanceerd [t0,t1,t2,t3,t4,t5,t6,t7] diff --git a/week7/camil/BinTree.dcl b/week7/camil/BinTree.dcl deleted file mode 100644 index 7774ece..0000000 --- a/week7/camil/BinTree.dcl +++ /dev/null @@ -1,16 +0,0 @@ -definition module BinTree - -:: Tree a = Node a (Tree a) (Tree a) | Leaf - -t0 :: Tree Int -t1 :: Tree Int -t2 :: Tree Int -t3 :: Tree Int -t4 :: Tree Int -t5 :: Tree Int -t6 :: Tree Int -t7 :: Tree Int - -//nodes :: // meest algemene type -//leaves :: // meest algemene type -//diepte :: // meest algemene type diff --git a/week7/camil/BinTree.icl b/week7/camil/BinTree.icl deleted file mode 100644 index 601efcc..0000000 --- a/week7/camil/BinTree.icl +++ /dev/null @@ -1,38 +0,0 @@ -implementation module BinTree - -import StdEnv - -:: Tree a = Node a (Tree a) (Tree a) | Leaf - -t0 :: Tree Int -t0 = Leaf -t1 :: Tree Int -t1 = Node 4 t0 t0 -t2 :: Tree Int -t2 = Node 2 t0 t1 -t3 :: Tree Int -t3 = Node 5 t2 t0 -t4 :: Tree Int -t4 = Node 5 t2 t2 -t5 :: Tree Int -t5 = Node 1 Leaf (Node 2 Leaf (Node 3 Leaf (Node 4 Leaf Leaf))) -t6 :: Tree Int -t6 = Node 1 (Node 2 (Node 3 (Node 4 Leaf Leaf) Leaf) Leaf) Leaf -t7 :: Tree Int -t7 = Node 4 (Node 1 Leaf Leaf) (Node 5 (Node 2 Leaf Leaf) Leaf) - -// 2. -//nodes :: // meest algemene type -//nodes ... - -//Start = map nodes [t0,t1,t2,t3,t4,t5,t6,t7] - -//leaves :: // meest algemene type -//leaves ... - -//Start = map leaves [t0,t1,t2,t3,t4,t5,t6,t7] - -//diepte :: // meest algemene type -//diepte ... - -//Start = map diepte [t0,t1,t2,t3,t4,t5,t6,t7] diff --git a/week7/mart/BewijsMeppenEnTippen.icl b/week7/mart/BewijsMeppenEnTippen.icl deleted file mode 100644 index 720ff4d..0000000 --- a/week7/mart/BewijsMeppenEnTippen.icl +++ /dev/null @@ -1,29 +0,0 @@ -Zij gegeven: - -:: BTree a = Tip a | Bin (BTree a) (BTree a) - -map :: (a -> b) [a] -> [b] -map f [] = [] (1.) -map f [x:xs] = [f x : map f xs] (2.) - -mapbtree :: (a -> b) (BTree a) -> BTree b -mapbtree f (Tip a) = Tip (f a) (3.) -mapbtree f (Bin t1 t2) = Bin (mapbtree f t1) (mapbtree f t2) (4.) - -foldbtree :: (a a -> a) (BTree a) -> a -foldbtree f (Tip x) = x (5.) -foldbtree f (Bin t1 t2) = f (foldbtree f t1) (foldbtree f t2) (6.) - -tips :: (BTree a) -> [a] -tips t = foldbtree (++) (mapbtree unit t) (7.) - -unit :: a -> [a] -unit x = [x] (8.) - - -Te bewijzen: - voor alle functies f, voor alle eindige bomen t: - - map f (tips t) = tips (mapbtree f t) - -Bewijs: diff --git a/week7/mart/BinSearchTree.dcl b/week7/mart/BinSearchTree.dcl deleted file mode 100644 index 2e480bb..0000000 --- a/week7/mart/BinSearchTree.dcl +++ /dev/null @@ -1,7 +0,0 @@ -definition module BinSearchTree - -import StdClass -import BinTree - -is_geordend :: // meest algemene type -is_gebalanceerd :: // meest algemene type diff --git a/week7/mart/BinSearchTree.icl b/week7/mart/BinSearchTree.icl deleted file mode 100644 index 8f9f05c..0000000 --- a/week7/mart/BinSearchTree.icl +++ /dev/null @@ -1,141 +0,0 @@ -implementation module BinSearchTree - -import StdEnv -import BinTree - - -z0 - Leaf -z1 - 50 - | - ---------- - | | - Leaf Leaf -z2 - 50 - | - ---------- - | | - 10 Leaf - | - ------ - | | - Leaf Leaf -z3 - 50 - | - ---------- - | | - 10 75 - | | - ------ ------ - | | | | - Leaf Leaf Leaf Leaf -z4 - 50 - | - ---------- - | | - 10 75 - | | - ------ ------ - | | | | - Leaf Leaf Leaf 80 - | - ------ - | | - Leaf Leaf -z5 - 50 - | - ---------- - | | - 10 75 - | | - ------ ------ - | | | | - Leaf Leaf Leaf 77 - | - ------ - | | - Leaf 80 - | - ------ - | | - Leaf Leaf -z6 - 50 - | - ---------- - | | - 10 75 - | | - ------ ------ - | | | | - 10 Leaf Leaf 77 - | | - ------ ------ - | | | | -Leaf Leaf Leaf 80 - | - ------ - | | - Leaf Leaf -z7 - 50 - | - ---------- - | | - 10 75 - | | - ------ ----------- - | | | | - 10 Leaf 75 77 - | | | - ------ ------ ------ - | | | | | | -Leaf Leaf Leaf Leaf Leaf 80 - | - ------ - | | - Leaf Leaf -z8 - -// Uit het diktaat, blz. 73: -insertTree :: a (Tree a) -> Tree a | Ord a -insertTree e Leaf = Node e Leaf Leaf -insertTree e (Node x le ri) -| e <= x = Node x (insertTree e le) ri -| e > x = Node x le (insertTree e ri) - -deleteTree :: a (Tree a) -> (Tree a) | Eq, Ord a -deleteTree e Leaf = Leaf -deleteTree e (Node x le ri) -| e < x = Node x (deleteTree e le) ri -| e == x = join le ri -| e > x = Node x le (deleteTree e ri) -where - join :: (Tree a) (Tree a) -> (Tree a) - join Leaf b2 = b2 - join b1 b2 = Node x b1` b2 - where - (x,b1`) = largest b1 - - largest :: (Tree a) -> (a,(Tree a)) - largest (Node x b1 Leaf) = (x,b1) - largest (Node x b1 b2) = (y,Node x b1 b2`) - where - (y,b2`) = largest b2 - - -is_geordend :: // meest algemene type -is_geordend ... - -Start = map is_geordend [t0,t1,t2,t3,t4,t5,t6,t7] - - -is_gebalanceerd :: // meest algemene type -is_gebalanceerd ... - -//Start = map is_gebalanceerd [t0,t1,t2,t3,t4,t5,t6,t7] -- cgit v1.2.3