diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -1,674 +1,26 @@
-                    GNU GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- 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.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    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 <http://www.gnu.org/licenses/>.
-
-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:
-
-    <program>  Copyright (C) <year>  <name of author>
-    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".
+Copyright (c) 2013 Henning Thielemann, Dylan Thurston, Mikael Johansson
+All rights reserved.
 
-  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
-<http://www.gnu.org/licenses/>.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
 
-  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
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,81 +1,32 @@
-
-OBJECT_DIR    := build/$(shell uname -s)-$(shell uname -m)
-INTERFACE_DIR := build/Interface
-
-MODULES = $(wildcard src/*.hs) \
-          $(wildcard src/NumericPrelude/*.hs) \
-          $(wildcard src/Algebra/*.hs) \
-          $(wildcard src/Algebra/NormedSpace/*.hs) \
-          $(wildcard src/Number/*.hs) \
-          $(wildcard src/Number/Physical/*.hs) \
-          $(wildcard src/Number/DimensionTerm/*.hs) \
-          $(wildcard src/Number/SI/*.hs) \
-          $(wildcard src/Number/ResidueClass/*.hs) \
-          $(wildcard src/Number/FixedPoint/*.hs) \
-          $(wildcard src/Number/Positional/*.hs) \
-          $(wildcard src/MathObj/*hs) \
-          $(wildcard src/MathObj/Permutation/*.hs) \
-          $(wildcard src/MathObj/Permutation/CycleList/*.hs) \
-          $(wildcard src/MathObj/PowerSeries/*.hs)
-
-GHC_OPTIONS = -Wall -odir$(OBJECT_DIR) -hidir$(INTERFACE_DIR)
-
-
-# names of literate modules after removing literary information
-UNLIT_MODULES = $(patsubst %.lhs, %.hs, $(patsubst %.hs, , $(MODULES)))
-
-# names of all modules without literary information
-HS_MODULES = $(patsubst %.lhs, %.hs, $(MODULES))
-
-STDINTERFACES = base/base.haddock parsec/parsec.haddock
-
-HADDOCK_INCL = $(patsubst %, -i /usr/local/share/ghc-6.2/html/libraries/%, \
-                    $(STDINTERFACES))
-
-HC = ghc
-
-HCI = ghci
-
-
-
-.INTERMEDIATE:	$(UNLIT_MODULES)
-
-.PHONY:	all doc clean build test ghci publish
+HCI6 = ghci
+HCI7 = ghci -XCPP -DNoImplicitPrelude=RebindableSyntax
 
-all:	build
+.PHONY: ghci ghci6 ghci7 ghci-gauss ghci-compile
 
-clean:
-	-rm `find $(OBJECT_DIR) -name "*.o"`
-	-rm `find $(INTERFACE_DIR) -name "*.hi"`
+ghci:	ghci7
 
-test:	build
-#	$(HC) -Wall -i:$(INTERFACE_DIR) -hide-package NumericPrelude -c test/Test.hs
-	$(HC) $(GHC_OPTIONS) -i:src:test --make -hide-package numeric-prelude -o testsuite test/Test/Run.hs
-	./testsuite
+ghci6:
+	$(HCI6) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Demo.hs
 
-ghci:
-	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Test.hs
+ghci7:
+	$(HCI7) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Demo.hs
 
 ghci-gauss:
-	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Test/MathObj/Gaussian/Variance.hs
+	$(HCI7) -Wall -i:src:test:gaussian +RTS -M256m -c30 -RTS test/Test/MathObj/Gaussian/Variance.hs
 
 ghci-compile:
-	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS -fobject-code -O -hidir=dist/build -odir=dist/build test/Test.hs
+	$(HCI7) -Wall -i:src:test +RTS -M256m -c30 -RTS -fobject-code -O -hidir=dist/build -odir=dist/build test/Demo.hs
 
-build:
-	-mkdir $(OBJECT_DIR)
-	$(HC) $(GHC_OPTIONS) -hide-package numeric-prelude --make -O $(MODULES)
 
-doc:	$(HS_MODULES)
-	haddock -o docs/html --dump-interface=docs/numericprelude.haddock $(HADDOCK_INCL) -h $(HS_MODULES)
+run-test:	update-test
+	runhaskell Setup configure --user -fbuildExamples --enable-tests
+	runhaskell Setup build
+	runhaskell Setup haddock
+	./dist/build/numeric-prelude-test/numeric-prelude-test
 
-%.hs:	%.lhs
-	unlit $< $@
+update-test:
+	doctest-extract-0.1 -i src/ -i gaussian/ -i playground/ -o test/ --executable-main=Test/Run.hs $$(cat test-module.list)
 
-HASKELLORG_HTMLDIR = /home/darcs/numericprelude/docs/html
 
-publish:
-	scp -r dist/doc/html/* cvs.haskell.org:$(HASKELLORG_HTMLDIR)/
-	#scp -r docs/html/* cvs.haskell.org:$(HASKELLORG_HTMLDIR)/
-	ssh cvs.haskell.org chmod -R o+r $(HASKELLORG_HTMLDIR)
-	#ssh cvs.haskell.org chmod o+x `find $(HASKELLORG_HTMLDIR) -type d`
+%.html:	%.md
+	pandoc $< --output=$@
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,139 @@
+# Revisiting the Numeric Classes
+
+## Introduction
+
+The Prelude for Haskell 98 offers a well-considered set of numeric classes
+which covers the standard numeric types
+(`Integer`, `Int`, `Rational`, `Float`, `Double`, `Complex`) quite well.
+But they offer limited extensibility and have a few other flaws.
+In this proposal we will revisit these classes, addressing the following concerns:
+
+1.  The current Prelude defines no semantics for the fundamental operations.
+    For instance, presumably addition should be associative
+    (or come as close as feasible),
+    but this is not mentioned anywhere.
+
+2.  There are some superfluous superclasses.
+    For instance, `Eq` and `Show` are superclasses of `Num`.
+    Consider the data type
+    `   data IntegerFunction a = IF (a -> Integer) `.
+    One can reasonably define all the methods of `Algebra.Ring.C` for
+    `IntegerFunction a` (satisfying good semantics),
+    but it is impossible to define non-bottom instances of `Eq` and `Show`.
+    In general, superclass relationship should indicate
+    some semantic connection between the two classes.
+
+3.  In a few cases, there is a mix of semantic operations and
+    representation-specific operations.
+    `toInteger`, `toRational`,
+    and the various operations in `RealFloating` (`decodeFloat`, ...)
+    are the main examples.
+
+4.  In some cases, the hierarchy is not finely-grained enough:
+    Operations that are often defined independently are lumped together.
+    For instance, in a financial application one might want a type "Dollar",
+    or in a graphics application one might want a type "Vector".
+    It is reasonable to add two Vectors or Dollars,
+    but not, in general, reasonable to multiply them.
+    But the programmer is currently forced to define a method for `(*)`
+    when she defines a method for `(+)`.
+
+In specifying the semantics of type classes,
+I will state laws as follows:
+
+~~~~
+    (a + b) + c === a + (b + c)
+~~~~
+
+The intended meaning is extensional equality:
+The rest of the program should behave in the same way
+if one side is replaced with the other.
+Unfortunately, the laws are frequently violated by standard instances;
+the law above, for instance, fails for `Float`:
+
+~~~~
+    (1e20 + (-1e20)) + 1.0  = 1.0
+     1e20 + ((-1e20) + 1.0) = 0.0
+~~~~
+
+For inexact number types like floating point types,
+thus these laws should be interpreted as guidelines rather than absolute rules.
+In particular, the compiler is not allowed to use them for optimization.
+Unless stated otherwise, default definitions should also be taken as laws.
+
+Thanks to Brian Boutel, Joe English, William Lee Irwin II, Marcin
+Kowalczyk, Ketil Malde, Tom Schrijvers, Ken Shan, and Henning
+Thielemann for helpful comments.
+
+
+## Usage
+
+Write modules in the following style:
+
+~~~~
+    {-# LANGUAGE RebindableSyntax #-}
+    module MyModule where
+
+    ... various specific imports ...
+
+    import NumericPrelude
+~~~~
+
+Importing `NumericPrelude` is almost the same as
+
+~~~~
+    import NumericPrelude.Numeric
+    import NumericPrelude.Base   .
+~~~~
+
+Instead of the `NoImplicitPrelude` pragma
+you could also write `import Prelude ()`
+but this will yield problems with numeric literals.
+
+There are two wrapper types that allow types
+to be used with both Haskell98 and NumericPrelude type classes
+that are initially implemented for only one of them.
+
+
+## Scope & Limitations/TODO
+
+* It might be desireable to split `Ord` up into `Poset` and `Ord`
+  (a total ordering).
+  This is not addressed here.
+
+* In some cases, this hierarchy may not yet be fine-grained enough.
+  For instance, time spans ("5 minutes") can be added to times ("12:34"),
+  but two times are not addable. ("12:34 + 8:23")
+  As it stands,
+  users have to use a different operator for adding time spans to times
+  than for adding two time spans.
+  Similar issues arise for vector space et al.
+  This is a consciously-made tradeoff, but might be changed.
+  This becomes most serious when dealing with quantities with units
+  like `length/distance^2`, for which `(*)` as defined here is useless.
+  (One way to see the issue: should
+  `  f x y = iterate (x *) y  `
+  have principal type
+  `  (Ring.C a) => a -> a -> [a]  `
+  or something like
+  `  (Ring.C a, Module a b) => a -> b -> [b]  `
+  ?)
+
+* I stuck with the Haskell 98 names.
+  In some cases I find them lacking.
+  Neglecting backwards compatibility, we have renamed classes as follows:
+
+    ~~~~
+    Num           --> Additive, Ring, Absolute
+    Integral      --> ToInteger, IntegralDomain, RealIntegral
+    Fractional    --> Field
+    Floating      --> Algebraic, Transcendental
+    Real          --> ToRational
+    RealFrac      --> RealRing, RealField
+    RealFloat     --> RealTranscendental
+    ~~~~
+
+
+Additional standard libraries might include `Enum`, `IEEEFloat`
+(including the bulk of the functions in Haskell 98's `RealFloat` class),
+`VectorSpace`, `Ratio`, and `Lattice`.
diff --git a/docs/NOTES b/docs/NOTES
--- a/docs/NOTES
+++ b/docs/NOTES
@@ -1,3 +1,36 @@
+* Positional: test suite
+
+Test against 'compensated' package.
+
+* Positional and zero
+
+Represent zero with empty mantissa?
+Or better have NonZero type with non-empty mantissa
+and a full number type with optional zero?
+Or something where we can have negative numbers and zero as option?
+Problem is, that we allow negative digits
+and thus even a Positive number type can represent zero and negative numbers.
+
+We might at least define a NonEmptyMantissa type for interim computations,
+like in 'divide'.
+
+* Positional.Fixed
+
+We could derive the base from digit type, e.g.
+   Int32 -> 1000
+   Int64 -> 1000000
+   newtype Integer -> anything
+
+* Algebra.Module
+
+I think it should be a type family rather than a multi-parameter type class.
+My main motivation for multi-paramter type class
+was to allow complex numbers to be a vector space over both real and complex numbers.
+This does not worked well and even more type inference often fails.
+We should just have two different types of complex numbers:
+One complex number type being a vector space over reals
+and another complex type being a vector space over complex numbers.
+
 * zipWithChecked
 
 We could make the second operand lazy,
diff --git a/gaussian/Gaussian.hs b/gaussian/Gaussian.hs
new file mode 100644
--- /dev/null
+++ b/gaussian/Gaussian.hs
@@ -0,0 +1,6 @@
+module Main where
+
+import qualified MathObj.Gaussian.Example as Example
+
+main :: IO ()
+main = Example.polyApprox
diff --git a/gaussian/MathObj/Gaussian/Bell.hs b/gaussian/MathObj/Gaussian/Bell.hs
new file mode 100644
--- /dev/null
+++ b/gaussian/MathObj/Gaussian/Bell.hs
@@ -0,0 +1,398 @@
+{-# LANGUAGE RebindableSyntax #-}
+{-
+Complex translated and modulated Gaussian bell curve.
+
+It could be extended to chirps
+using a complex valued quadratic term with (real c >= 0).
+This allows for a new test:
+Express the Fourier transform in terms of a convolution with a chirp.
+-}
+module MathObj.Gaussian.Bell where
+
+import qualified MathObj.Polynomial as Poly
+import qualified Number.Complex as Complex
+
+import qualified Algebra.Transcendental as Trans
+import qualified Algebra.Field          as Field
+import qualified Algebra.Absolute       as Absolute
+import qualified Algebra.Ring           as Ring
+import qualified Algebra.Additive       as Additive
+
+import Number.Complex ((+:), )
+
+import Test.QuickCheck (Arbitrary, arbitrary, )
+import Control.Monad (liftM4, )
+
+import NumericPrelude.Numeric
+import NumericPrelude.Base hiding (reverse, )
+
+
+{- $setup
+>>> import qualified MathObj.Gaussian.Bell as G
+>>> import qualified Algebra.ZeroTestable as ZeroTestable
+>>> import qualified Algebra.Laws as Laws
+>>> import qualified Number.Complex as Complex
+>>> import Number.Complex ((+:))
+>>> import NumericPrelude.Base as P
+>>> import NumericPrelude.Numeric as NP
+>>> import Prelude ()
+>>> import qualified Test.QuickCheck as QC
+>>> import Data.Function.HT (Id, nest)
+>>>
+>>> asRational :: Id (G.T Rational)
+>>> asRational = id
+>>>
+>>> withRational :: Id (G.T Rational -> a)
+>>> withRational = id
+>>>
+>>> isConstant :: ZeroTestable.C a => G.T a -> Bool
+>>> isConstant (G.Cons _amp _a b c) = isZero b && isZero c
+-}
+
+
+data T a = Cons {amp :: a, c0, c1 :: Complex.T a, c2 :: a}
+   deriving (Eq, Show)
+
+instance (Absolute.C a, Arbitrary a) => Arbitrary (T a) where
+   arbitrary =
+      liftM4
+         (\k a b c -> Cons (abs k) a b (1 + abs c))
+         arbitrary arbitrary arbitrary arbitrary
+
+
+constant :: Ring.C a => T a
+constant = Cons one zero zero zero
+
+{- |
+eigenfunction of 'fourier'
+-}
+unit :: Ring.C a => T a
+unit = Cons one zero zero one
+
+{-# INLINE evaluate #-}
+evaluate :: (Trans.C a) =>
+   T a -> a -> Complex.T a
+evaluate f x =
+   Complex.scale
+     (sqrt (amp f))
+     (Complex.exp $ Complex.scale (-pi) $
+      c0 f + Complex.scale x (c1 f) + Complex.fromReal (c2 f * x^2))
+
+evaluateSqRt :: (Trans.C a) =>
+   T a -> a -> Complex.T a
+evaluateSqRt f x0 =
+   Complex.scale
+     (sqrt (amp f))
+     (let x = sqrt pi * x0
+      in  Complex.exp $ negate $
+          c0 f + Complex.scale x (c1 f) + Complex.fromReal (c2 f * x^2))
+
+exponentPolynomial :: (Additive.C a) =>
+   T a -> Poly.T (Complex.T a)
+exponentPolynomial f =
+   Poly.fromCoeffs [c0 f, c1 f, Complex.fromReal (c2 f)]
+
+
+{-
+norm functions depend on interpretation
+and would have to return both a rational and transcendental part
+expressed as @exp a@.
+-}
+
+variance :: (Trans.C a) =>
+   T a -> a
+variance f =
+   recip $ c2 f * 2*pi
+
+{- |
+prop> Laws.identity G.multiply G.constant . asRational
+prop> Laws.commutative G.multiply . asRational
+prop> Laws.associative G.multiply . asRational
+-}
+multiply :: (Ring.C a) =>
+   T a -> T a -> T a
+multiply f g =
+   Cons
+      (amp f * amp g)
+      (c0 f + c0 g) (c1 f + c1 g) (c2 f + c2 g)
+
+powerRing :: (Trans.C a) =>
+   Integer -> T a -> T a
+powerRing p f =
+   let pa = fromInteger p
+   in  Cons
+          (amp f ^ p)
+          (pa * c0 f) (pa * c1 f) (fromInteger p * c2 f)
+
+{-
+powerField does not makes sense,
+since the reciprocal of a Gaussian diverges.
+-}
+
+powerAlgebraic :: (Trans.C a) =>
+   Rational -> T a -> T a
+powerAlgebraic p f =
+   let pa = fromRational' p
+   in  Cons
+          (amp f ^/ p)
+          (pa * c0 f) (pa * c1 f) (fromRational' p * c2 f)
+
+powerTranscendental :: (Trans.C a) =>
+   a -> T a -> T a
+powerTranscendental p f =
+   Cons
+      (amp f ^? p)
+      (Complex.scale p $ c0 f) (Complex.scale p $ c1 f) (p * c2 f)
+
+
+{- |
+>>> let x=G.Cons 2 (1+:3) (4+:5) (7::Rational); y=G.Cons 7 (1+:4) (3+:2) (5::Rational) in G.convolve x y
+Cons {amp = 7 % 6, c0 = 13 % 6 +: 55 % 8, c1 = 41 % 12 +: 13 % 4, c2 = 35 % 12}
+
+prop> Laws.commutative G.convolve . asRational
+prop> Laws.associative G.convolve . asRational
+
+Would be nice to have something like:
+
+> Laws.identity G.convolve G.dirac
+
+but we cannot represent @G.dirac@.
+
+prop> isConstant . G.convolve G.constant . asRational
+
+Using a @G.norm1@ we could exactly compute the amplitude
+of the resulting constant function.
+But that would require transcendent operations.
+-}
+convolve :: (Field.C a) =>
+   T a -> T a -> T a
+convolve f g =
+   let s = c2 f + c2 g
+       {-
+       fd = f1/(2*f2)
+       gd = g1/(2*g2)
+       c = f2*g2/(f2+g2)
+
+       c*(fd+gd) = (f1*g2+f2*g1)/(2*(f2+g2)) = b/2
+
+       c*(fd+gd)^2 - fd^2*f2 - gd^2*g2
+         = f2*g2*(fd+gd)^2/(f2 + g2) - (fd^2*f2 + gd^2*g2)
+         = (f2*g2*(fd+gd)^2 - (f2+g2)*(fd^2*f2+gd^2*g2)) / (f2 + g2)
+         = (2*f2*g2*fd*gd - (fd^2*f2^2+gd^2*g2^2)) / (f2 + g2)
+         = (2*f1*g1 - (f1^2+g1^2)) / (4*(f2 + g2))
+         = -(f1 - g1)^2/(4*(f2 + g2))
+       -}
+   in  Cons
+          (amp f * amp g / s)
+          (c0 f + c0 g
+              - Complex.scale (recip (4*s)) ((c1 f - c1 g)^2))
+          (Complex.scale (c2 g / s) (c1 f) +
+           Complex.scale (c2 f / s) (c1 g))
+          (c2 f * c2 g / s)
+            -- recip $ recip (c2 f) + recip (c2 g)
+{-
+   Cons
+      (c0 f + c0 g) (c1 f + c1 g)
+      (recip $ recip (c2 f) + recip (c2 g))
+-}
+
+{- |
+prop> withRational $ \x y -> G.convolve x y == G.convolveByTranslation x y
+-}
+convolveByTranslation :: (Field.C a) =>
+   T a -> T a -> T a
+convolveByTranslation f0 g0 =
+   let fd = Complex.scale (recip (2 * c2 f0)) $ c1 f0
+       gd = Complex.scale (recip (2 * c2 g0)) $ c1 g0
+       f1 = translateComplex fd f0
+       g1 = translateComplex gd g0
+       s = c2 f1 + c2 g1
+   in  translateComplex (negate $ fd + gd) $
+       Cons
+          (amp f1 * amp g1 / s)
+          (c0 f1 + c0 g1) zero
+          (c2 f1 * c2 g1 / s)
+
+{- |
+prop> withRational $ \x y -> G.convolve x y == G.convolveByFourier x y
+-}
+convolveByFourier :: (Field.C a) =>
+   T a -> T a -> T a
+convolveByFourier f g =
+   reverse $ fourier $ multiply (fourier f) (fourier g)
+
+{- |
+prop> withRational $ \x y -> G.fourier (G.convolve x y) == G.multiply (G.fourier x) (G.fourier y)
+prop> withRational $ \x -> nest 2 G.fourier x == G.reverse x
+prop> G.fourier G.unit == (asRational G.unit)
+prop> withRational $ \x a -> G.fourier (G.translate a x) == G.modulate a (G.fourier x)
+prop> withRational $ \x (QC.Positive a) -> G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x))
+-}
+fourier :: (Field.C a) =>
+   T a -> T a
+fourier f =
+   let a = c0 f
+       b = c1 f
+       rc = recip $ c2 f
+   in  Cons
+          (amp f * rc)
+          (Complex.scale (rc/4) (-b^2) + a)
+          (Complex.scale rc $ Complex.quarterRight b)
+          rc
+
+{- |
+prop> withRational $ \x -> G.fourier x == G.fourierByTranslation x
+-}
+fourierByTranslation :: (Field.C a) =>
+   T a -> T a
+fourierByTranslation f =
+   translateComplex (Complex.scale (1/2) $ Complex.quarterLeft $ c1 f) $
+   Cons (amp f / c2 f) (c0 f) zero (recip $ c2 f)
+
+{-
+a + b*x + c*x^2
+ = c*(a/c + b/c*x + x^2)
+ = c*((x-b/(2*c))^2 + (4*a*c+b^2)/(4*c^2))
+ = c*(x-b/(2*c))^2 + (4*a*c+b^2)/(4*c)
+
+fourier ->
+   x^2/c - i*b/c*x + (4*a*c+b^2)/(4*c)
+
+fourier (x -> exp(-pi*c*(x-t)^2))
+ = fourier $ translate t $ shrink (sqrt c) $ x -> exp(-pi*x^2)
+ = modulate t $ dilate (sqrt c) $ fourier $ x -> exp(-pi*x^2)
+ = modulate t $ dilate (sqrt c) $ x -> exp(-pi*x^2)
+ = modulate t $ x -> exp(-pi*x^2/c)
+ = x -> exp(-pi*x^2/c) * exp(-2*pi*i*x*t)
+ = x -> exp(-pi*(x^2/c - 2*i*x*t))
+-}
+
+{-
+b*x + c*x^2
+ = c*(b/c*x + x^2)
+ = c*((x-br/(2*c))^2 + i*x*bi/c - br^2/(4*c^2))
+ = c*(x-br/(2*c))^2 + i*x*bi - br^2/(4*c)
+
+fourier ->
+   (x+bi/2)^2/c - i*br/c*(x+bi/2) - br^2/(4*c)
+ = (1/c) * ((x+bi/2)^2 - i*br*(x+bi/2) + (br/2)^2)
+ = (1/c) * (x^2 - i*b*x + -(br/2)^2 + (bi/2)^2 - i*br*bi/2)
+ = (1/c) * (x^2 - i*b*x - (br^2-bi^2+2*br*bi*i)^2 /4)
+ = (1/c) * (x^2 - i*b*x - b^2 / 4)
+ = (1/c) * (x^2 - i*b*x + (i*b/2)^2)
+ = (1/c) * (x - i*b/2)^2
+
+Example:
+  (x-b)^2 = b^2 - 2*b*x + x^2
+    ->  (- i*2*b*x + x^2)
+
+
+fourier (x -> exp(-pi*(c*(x-t)^2 + 2*i*m*x)))
+ = fourier $ modulate m $ translate t $ shrink (sqrt c) $ x -> exp(-pi*x^2)
+ = translate (-m) $ modulate t $ dilate (sqrt c) $ fourier $ x -> exp(-pi*x^2)
+ = translate (-m) $ modulate t $ dilate (sqrt c) $ x -> exp(-pi*x^2)
+ = translate (-m) $ modulate t $ x -> exp(-pi*x^2/c)
+ = translate (-m) $ x -> exp(-pi*x^2/c) * exp(-2*pi*i*x*t)
+ = x -> exp(-pi*(x+m)^2/c) * exp(-2*pi*i*(x+m)*t)
+ = x -> exp(-pi*((x+m)^2/c - 2*i*(x+m)*t))
+-}
+
+{-
+fourier (Cons a 0 0) =
+  Cons a 0 infinity
+
+fourier (Cons 0 0 c) =
+  Cons 0 0 (recip c)
+
+fourier (Cons 0 b 1) =
+  Cons 0 (i*b) 1
+-}
+
+{- |
+prop> withRational $ \x a b -> G.translate a (G.translate b x) == G.translate (a+b) x
+-}
+translate :: Ring.C a => a -> T a -> T a
+translate d f =
+   let a = c0 f
+       b = c1 f
+       c = c2 f
+   in  Cons
+          (amp f)
+          (Complex.fromReal (c*d^2) - Complex.scale d b + a)
+          (Complex.fromReal (-2*c*d) + b)
+          c
+
+{- |
+prop> withRational $ \x a b -> G.translateComplex a (G.translateComplex b x) == G.translateComplex (a+b) x
+prop> withRational $ \x a -> G.translateComplex (Complex.fromReal a) x == G.translate a x
+-}
+translateComplex :: Ring.C a => Complex.T a -> T a -> T a
+translateComplex d f =
+   let a = c0 f
+       b = c1 f
+       c = c2 f
+   in  Cons
+          (amp f)
+          (Complex.scale c (d^2) - b*d + a)
+          (Complex.scale (-2*c) d + b)
+          c
+
+{- |
+prop> withRational $ \x a b -> G.modulate a (G.modulate b x) == G.modulate (a+b) x
+prop> withRational $ \x a b -> G.modulate b (G.translate a x) == G.turn (a*b) (G.translate a (G.modulate b x))
+-}
+modulate :: Ring.C a => a -> T a -> T a
+modulate d f =
+   Cons
+      (amp f)
+      (c0 f)
+      (c1 f + (zero +: 2*d))
+      (c2 f)
+
+turn :: Ring.C a => a -> T a -> T a
+turn d f =
+   Cons
+      (amp f)
+      (c0 f + (zero +: 2*d))
+      (c1 f)
+      (c2 f)
+
+{- |
+prop> withRational $ \x -> nest 2 G.reverse x == x
+-}
+reverse :: Additive.C a => T a -> T a
+reverse f =
+   f{c1 = negate $ c1 f}
+
+
+{- |
+prop> withRational $ \x (QC.Positive a) (QC.Positive b) -> G.dilate a (G.dilate b x) == G.dilate (a*b) x
+prop> withRational $ \x (QC.Positive a) -> G.shrink a x == G.dilate (recip a) x
+-}
+dilate :: Field.C a => a -> T a -> T a
+dilate k f =
+   Cons
+      (amp f)
+      (c0 f)
+      (Complex.scale (recip k) $ c1 f)
+      (c2 f / k^2)
+
+{- |
+prop> withRational $ \x (QC.Positive a) -> G.dilate a (G.shrink a x) == x
+prop> withRational $ \x (QC.Positive a) -> G.shrink a (G.dilate a x) == x
+-}
+shrink :: Ring.C a => a -> T a -> T a
+shrink k f =
+   Cons
+      (amp f)
+      (c0 f)
+      (Complex.scale k $ c1 f)
+      (c2 f * k^2)
+
+amplify :: (Ring.C a) => a -> T a -> T a
+amplify k f =
+   Cons
+      (k^2 * amp f)
+      (c0 f)
+      (c1 f)
+      (c2 f)
diff --git a/gaussian/MathObj/Gaussian/Example.hs b/gaussian/MathObj/Gaussian/Example.hs
new file mode 100644
--- /dev/null
+++ b/gaussian/MathObj/Gaussian/Example.hs
@@ -0,0 +1,226 @@
+{-# LANGUAGE RebindableSyntax #-}
+{-
+Reciprocal of variance of a Gaussian bell curve.
+We describe the curve only in terms of its variance
+thus we represent a bell curve at the coordinate origin
+neglecting its amplitude.
+
+We could also define the amplitude as @root 4 c@,
+thus preserving L2 norm being one,
+but then @dilate@ and @shrink@ also include an amplification.
+
+We could do some projective geometry in the exponent
+in order to also have zero variance,
+which corresponds to the dirac impulse.
+-}
+module MathObj.Gaussian.Example where
+
+import qualified MathObj.Gaussian.Polynomial as PolyBell
+import qualified MathObj.Gaussian.Bell as Bell
+import qualified MathObj.Gaussian.Variance as Var
+
+import qualified MathObj.Polynomial as Poly
+
+import qualified Algebra.Transcendental as Trans
+import qualified Algebra.Algebraic      as Algebraic
+import qualified Algebra.Field          as Field
+import qualified Algebra.Ring           as Ring
+
+import qualified Number.Complex as Complex
+import qualified Number.Root as Root
+
+import Algebra.Transcendental (pi, )
+import Algebra.Algebraic (root, )
+import Algebra.Ring ((*), (^), )
+
+import Number.Complex ((+:), )
+
+import qualified Numerics.Function as Func
+import qualified Numerics.Fourier as Fourier
+import qualified Numerics.Integration as Integ
+import qualified Numerics.Differentiation as Diff
+
+import qualified Graphics.Gnuplot.Simple as GP
+
+import Control.Applicative (liftA2, )
+
+import NumericPrelude.Numeric
+import NumericPrelude.Base
+import qualified Prelude as P
+
+
+curve0 :: Var.T Double
+curve0 = curve0a
+
+curve0a :: Var.T Double
+curve0a = Var.Cons 1.4 3.3
+
+curve0b :: Var.T Double
+curve0b = Var.Cons 2.2 1.7
+
+variance0 :: (Double, Double)
+variance0 =
+   (Var.variance curve0,
+    (Integ.rectangular 1000 (-2,2) $ liftA2 (*) (^2) (Var.evaluate curve0)) /
+    (Integ.rectangular 1000 (-2,2) $ Var.evaluate curve0))
+
+norm10 :: (Double, Double, Double)
+norm10 =
+   (Integ.rectangular 1000 (-2,2) $ Var.evaluate curve0,
+    Var.norm1 curve0,
+    Root.toNumber (Var.norm1Root curve0))
+
+norm20 :: (Double, Double, Double)
+norm20 =
+   (sqrt $ Integ.rectangular 1000 (-2,2) $ (^2) . Var.evaluate curve0,
+    Var.norm2 curve0,
+    Root.toNumber (Var.norm2Root curve0))
+
+norm30 :: (Double, Double, Double)
+norm30 =
+   (root 3 $ Integ.rectangular 1000 (-2,2) $ (^3) . Var.evaluate curve0,
+    Var.normP 3 curve0,
+    Root.toNumber (Var.normPRoot 3 curve0))
+
+fourier0 :: IO ()
+fourier0 =
+   GP.plotFuncs []
+      (GP.linearScale 100 (-2,2))
+      [Var.evaluate $ Var.fourier curve0,
+       Fourier.analysisTransformOneReal 100 (-2,2) $ Var.evaluate curve0]
+
+multiply0 :: IO ()
+multiply0 =
+   GP.plotFuncs []
+      (GP.linearScale 100 (-1,1))
+      [Var.evaluate $ Var.multiply curve0a curve0b,
+       liftA2 (*) (Var.evaluate curve0a) (Var.evaluate curve0b)]
+
+convolve0 :: IO ()
+convolve0 =
+   GP.plotFuncs []
+      (GP.linearScale 100 (-2,2))
+      [Var.evaluate $ Var.convolve curve0a curve0b,
+       Integ.convolve 1000 (-3,3) (Var.evaluate curve0a) (Var.evaluate curve0b)]
+
+
+curve1 :: Bell.T Double
+curve1 = curve1a
+
+curve1a :: Bell.T Double
+curve1a = Bell.Cons 1.4 (0.1+:0.3) ((-0.2)+:1.4) 2.3
+
+curve1b :: Bell.T Double
+curve1b = Bell.Cons 2.2 ((-0.3)+:2.1) (0.2+:(-0.4)) 1.7
+
+variance1 :: (Double, Double)
+variance1 =
+   (Bell.variance curve1,
+    (Integ.rectangular 1000 (-2,2) $
+        liftA2 (*) (^2)
+           (Complex.magnitudeSqr .
+            Func.translateRight
+               (Complex.real (Bell.c1 curve1) / (2 * Bell.c2 curve1))
+               (Bell.evaluate curve1))) /
+    (Integ.rectangular 1000 (-2,2) $ Complex.magnitude . Bell.evaluate curve1))
+
+{- the norm depends on too much things
+norm0vs1 :: (Double, Double)
+norm0vs1 =
+   ((Integ.rectangular 1000 (-5,5) $ Var.evaluate curve0)
+         * exp (- Complex.real (Bell.c0 curve1)),
+    Integ.rectangular 1000 (-5,5) $ Complex.magnitude . Bell.evaluate curve1)
+-}
+
+fourier1 :: IO ()
+fourier1 =
+   GP.plotFuncs []
+      (GP.linearScale 100 (-5,5))
+      [Complex.real . (Bell.evaluate $ Bell.fourier curve1),
+       fourierAnalysisReal 100 (-2,2) $ Bell.evaluate curve1]
+
+
+curve2 :: PolyBell.T Double
+curve2 =
+   PolyBell.Cons
+--      Bell.unit
+--      (Bell.Cons 1.4 (0.1+:0.3) 0 1.2)
+--      (Bell.Cons 1.4 (0.1+:0.3) ((-0.2)+:1.4) 1)
+      curve1
+--      (Poly.fromCoeffs [one])
+--      (Poly.fromCoeffs [zero,one])
+--      (Poly.fromCoeffs [zero,zero,one])
+--      (Poly.fromCoeffs [0,Complex.imaginaryUnit])
+      (Poly.fromCoeffs [1.4+:(-0.1),0.8+:(0.1),(-1.1)+:0.3])
+
+differentiate2 :: IO ()
+differentiate2 =
+   GP.plotFuncs []
+      (GP.linearScale 100 (-2,2))
+      [Complex.real . (PolyBell.evaluateSqRt $ PolyBell.differentiate curve2),
+       ((/ sqrt pi) . ) $ Diff.diff (1e-5) $ Complex.real . PolyBell.evaluateSqRt curve2]
+
+fourier2 :: IO ()
+fourier2 =
+   GP.plotFuncs []
+      (GP.linearScale 100 (-5,5))
+      [Complex.real . (PolyBell.evaluateSqRt $ PolyBell.fourier curve2),
+       fourierAnalysisReal 100 (-2,2) $ PolyBell.evaluateSqRt curve2]
+
+
+
+fourierAnalysisReal ::
+   (P.Floating a) =>
+   Integer -> (a, a) -> (a -> Complex.T a) -> a -> a
+fourierAnalysisReal n rng f =
+   liftA2 (P.-)
+      (Fourier.analysisTransformOneReal n rng (Complex.real . f))
+      (Fourier.analysisTransformOneImag n rng (Complex.imag . f))
+
+
+{- |
+Try to approximate @\x -> exp (-x^2) * x@
+by a difference of translated Gaussian bells.
+
+exp(-x^2) * x
+  ==  exp(-(a+b*x+c*x^2)) - exp(-(a-b*x+c*x^2))
+  ==  exp(-(a+c*x^2)) * (exp(-b*x) - exp(b*x))
+  ==  exp(-(a+c*x^2)) * 2*sinh (b*x)
+
+It holds
+  lim (\b x -> sinh (b*x) / b)  =  id
+-}
+diffApprox :: IO ()
+diffApprox =
+   let amp = (2*b)^- (-2)
+       a = 0
+       {-
+       amp = 1
+       a = log (2 * abs b)
+       -}
+       b = -0.1
+       c = 1
+       ac = Complex.fromReal a
+       bc = Complex.fromReal b
+   in  GP.plotFuncs []
+          (GP.linearScale 100 (-2,2::Double))
+          [Complex.real .
+           (PolyBell.evaluateSqRt $
+              PolyBell.Cons Bell.unit (Poly.fromCoeffs [zero,one])),
+           Complex.real .
+           liftA2 (-)
+             (PolyBell.evaluateSqRt $
+                PolyBell.Cons (Bell.Cons amp ac bc c) (Poly.fromCoeffs [one]))
+             (PolyBell.evaluateSqRt $
+                PolyBell.Cons (Bell.Cons amp ac (-bc) c) (Poly.fromCoeffs [one]))]
+
+
+polyApprox :: IO ()
+polyApprox =
+   GP.plotFuncs []
+      (GP.linearScale 100 (-2,2::Double))
+      [Complex.real .
+         PolyBell.evaluateSqRt curve2,
+       Complex.real . sum .
+         mapM (\(amp,b) -> \x -> amp * Bell.evaluateSqRt b x)
+         (PolyBell.approximateByBells 0.1 curve2)]
diff --git a/gaussian/MathObj/Gaussian/ExponentTuple.hs b/gaussian/MathObj/Gaussian/ExponentTuple.hs
new file mode 100644
--- /dev/null
+++ b/gaussian/MathObj/Gaussian/ExponentTuple.hs
@@ -0,0 +1,114 @@
+{-# LANGUAGE RebindableSyntax #-}
+module MathObj.Gaussian.ExponentTuple where
+
+import qualified Test.QuickCheck as QC
+
+import Control.Applicative (liftA2, liftA3)
+
+import Data.Function.HT (compose2)
+
+import NumericPrelude.Base as P
+import NumericPrelude.Numeric as NP
+
+
+{- $setup
+>>> import MathObj.Gaussian.ExponentTuple (HoelderConjugates(HoelderConjugates))
+>>> import MathObj.Gaussian.ExponentTuple (YoungConjugates(YoungConjugates))
+>>> import NumericPrelude.Base as P
+>>> import NumericPrelude.Numeric as NP
+>>> import Prelude ()
+-}
+
+
+{- |
+For @(HoelderConjugates p q)@ it holds
+
+prop> \(HoelderConjugates p q)  ->  p>=1 && q>=1 && 1/p + 1/q == 1
+-}
+data HoelderConjugates = HoelderConjugates Rational Rational
+   deriving Show
+
+instance QC.Arbitrary HoelderConjugates where
+   arbitrary = genHoelderConjugates0
+
+genHoelderConjugates0 :: QC.Gen HoelderConjugates
+genHoelderConjugates0 =
+   liftA2
+      (\(QC.Positive p) (QC.Positive q) ->
+         let s = p + q in HoelderConjugates (s % p) (s % q))
+      QC.arbitrary QC.arbitrary
+
+genHoelderConjugates1 :: QC.Gen HoelderConjugates
+genHoelderConjugates1 =
+   liftA2
+      (\(QC.Positive p) (QC.Positive q) ->
+         let s = 1%p + 1%q
+         in HoelderConjugates (fromInteger p * s) (fromInteger q * s))
+      QC.arbitrary QC.arbitrary
+
+
+{- |
+For @(YoungConjugates p q r)@ it holds
+
+prop> \(YoungConjugates p q r)  ->  p>=1 && q>=1 && r>=1 && 1/p + 1/q == 1/r + 1
+-}
+data YoungConjugates = YoungConjugates Rational Rational Rational
+   deriving Show
+
+instance QC.Arbitrary YoungConjugates where
+   arbitrary = genYoungConjugates0
+
+{-
+Find positive natural numbers @a, b, c, d@ with
+
+> a + b = c + d
+
+and
+
+> d >= a, d >= b, d >= c
+
+then set
+
+> p=d/a, q=d/b, r=d/c
+
+
+a+b<=c
+b+c<=a
+->  2b <= 0
+-}
+genYoungConjugates0 :: QC.Gen YoungConjugates
+genYoungConjugates0 =
+   liftA3
+      (\(QC.Positive a0) (QC.Positive b0) (QC.Positive c0) ->
+         let guardSwap cond (x,y) =
+                if cond x y then (x,y) else (y,x)
+             {-
+             If a+b<=c, then from b>0 it follows a<c and thus c+b>a.
+             Swapping a and c is enough and we have not to consider more cases.
+             -}
+             (a1,c1) = guardSwap (\a c -> a+b0>c) (a0,c0)
+             b1 = b0
+             d1 = a1+b1-c1
+             ((a2,b2),(c2,d2)) =
+                guardSwap (compose2 (<=) snd)
+                   (guardSwap (<=) (a1,b1),
+                    guardSwap (<=) (c1,d1))
+         in  YoungConjugates (d2%a2) (d2%b2) (d2%c2))
+      QC.arbitrary QC.arbitrary QC.arbitrary
+
+{- |
+This one is simpler, but may yield exponents smaller than 1.
+-}
+genYoungConjugates1 :: QC.Gen YoungConjugates
+genYoungConjugates1 =
+   liftA3
+      (\(QC.Positive a0) (QC.Positive b0) (QC.Positive c0) ->
+         let {-
+             If a+b<=c, then from b>0 it follows a<c and thus c+b>a.
+             Swapping a and c is enough and we have not to consider more cases.
+             -}
+             (a1,c1) = if a0+b0<=c0 then (c0,a0) else (a0,c0)
+             b1 = b0
+             d1 = a1+b1-c1
+         in  YoungConjugates (d1%a1) (d1%b1) (d1%c1))
+      QC.arbitrary QC.arbitrary QC.arbitrary
diff --git a/gaussian/MathObj/Gaussian/Polynomial.hs b/gaussian/MathObj/Gaussian/Polynomial.hs
new file mode 100644
--- /dev/null
+++ b/gaussian/MathObj/Gaussian/Polynomial.hs
@@ -0,0 +1,584 @@
+{-# LANGUAGE RebindableSyntax #-}
+{-
+Complex Gaussian bell multiplied with a polynomial.
+
+In order to make this free of @pi@ factors,
+we have to choose @recip (sqrt pi)@
+as unit for translations and modulations,
+for linear factors and in the differentiation.
+-}
+{-
+ToDo:
+
+* In order to avoid the weird @sqrt pi@ factor,
+  use a polynomial expression in @pi@.
+
+* sum of multiple bells using Data.Map from exponent polynomial to coefficient polynomial
+  use of Algebra object.
+
+* Discrete Fourier Transform and its eigenvectors
+
+* Use projective geometry in order to support Dirac impulse.
+  There are many open questions:
+  1. What shall be the product of two Dirac impulses -
+     whether they are at the same location or not.
+  2. How to organize coefficients
+     such that the constant function can be modulated
+     and the Dirac impulse can be translated.
+-}
+module MathObj.Gaussian.Polynomial where
+
+import qualified MathObj.Gaussian.Bell as Bell
+
+import qualified MathObj.LaurentPolynomial as LPoly
+import qualified MathObj.Polynomial.Core   as PolyCore
+import qualified MathObj.Polynomial        as Poly
+import qualified Number.Complex     as Complex
+
+import qualified Algebra.ZeroTestable   as ZeroTestable
+import qualified Algebra.Differential   as Differential
+import qualified Algebra.Transcendental as Trans
+import qualified Algebra.Field          as Field
+import qualified Algebra.Absolute       as Absolute
+import qualified Algebra.Ring           as Ring
+import qualified Algebra.Additive       as Additive
+
+import qualified Data.Record.HT as Rec
+import qualified Data.List as List
+import Data.Function.HT (nest, )
+import Data.Eq.HT (equating, )
+import Data.List.HT (mapAdjacent, )
+import Data.Tuple.HT (forcePair, )
+
+import Test.QuickCheck (Arbitrary, arbitrary, )
+import Control.Monad (liftM2, )
+
+import NumericPrelude.Numeric
+import NumericPrelude.Base hiding (reverse, )
+
+
+{- $setup
+>>> :set -XRebindableSyntax
+>>>
+>>> import qualified MathObj.Gaussian.Polynomial as G
+>>> import qualified MathObj.Gaussian.Bell as Bell
+>>> import qualified MathObj.Polynomial as Poly
+>>> import qualified Algebra.Laws as Laws
+>>> import qualified Number.Complex as Complex
+>>> import Number.Complex ((+:))
+>>> import NumericPrelude.Base as P
+>>> import NumericPrelude.Numeric as NP
+>>> import qualified Test.QuickCheck as QC
+>>> import Data.Function.HT (Id, nest)
+>>> import Data.Tuple.HT (mapSnd)
+>>>
+>>> asRational :: Id (G.T Rational)
+>>> asRational = id
+>>>
+>>> withRational :: Id (G.T Rational -> a)
+>>> withRational = id
+>>>
+>>> mulLinear2i :: Id (G.T Rational)
+>>> mulLinear2i x =
+>>>    x{G.polynomial = Poly.fromCoeffs [0, 0+:2] * G.polynomial x}
+>>>
+>>> rotateQuarter :: Int -> Id (G.T Rational)
+>>> rotateQuarter n =
+>>>    G.scaleComplex (negate Complex.imaginaryUnit ^ fromIntegral n)
+-}
+
+
+data T a = Cons {bell :: Bell.T a, polynomial :: Poly.T (Complex.T a)}
+   deriving (Show)
+
+instance (Absolute.C a, ZeroTestable.C a, Eq a) => Eq (T a) where
+   (==) = equal
+
+
+{-
+Helper data type for 'equal',
+that allows to call the (not quite trivial) polynomial equality check.
+@RootProduct r a@ represents @sqrt r * a@.
+The test using 'signum' works for real numbers,
+and I do not know, whether it is correct for other mathematical objects.
+However I cannot imagine other mathematical objects,
+that make sense at all, here.
+Maybe elements of a finite field.
+-}
+data RootProduct a = RootProduct a a
+
+instance (Absolute.C a, ZeroTestable.C a, Eq a) => Eq (RootProduct a) where
+   (RootProduct xr xa) == (RootProduct yr ya)  =
+      let xp = xr*xa^2
+          yp = yr*ya^2
+      in  xp==yp &&
+          (isZero xp || signum xa == signum ya)
+
+instance (ZeroTestable.C a) => ZeroTestable.C (RootProduct a) where
+   isZero (RootProduct r a) = isZero r || isZero a
+
+
+{-
+The derived Eq is not correct.
+We have to combine the amplitude of the bell with the polynomial,
+respecting signs and the square root of the bell amplitude.
+-}
+equal :: (Absolute.C a, ZeroTestable.C a, Eq a) => T a -> T a -> Bool
+equal x y =
+   let bx = bell x
+       by = bell y
+       scaleSqr b =
+          (\p ->
+              (fmap (RootProduct (Bell.amp b) . Complex.real) p,
+               fmap (RootProduct (Bell.amp b) . Complex.imag) p))
+           . polynomial
+   in  Rec.equal
+          (equating Bell.c0 :
+           equating Bell.c1 :
+           equating Bell.c2 :
+           [])
+          bx by
+       &&
+       scaleSqr bx x == scaleSqr by y
+
+
+instance (Absolute.C a, ZeroTestable.C a, Arbitrary a) => Arbitrary (T a) where
+   arbitrary =
+--      liftM2 Cons arbitrary arbitrary
+      liftM2 Cons
+         arbitrary
+         -- we have to restrict the number of polynomial coefficients,
+         -- since with the quadratic time algorithms like fourier and convolve,
+         -- in connection with Rational slow down tests too much.
+         (fmap (Poly.fromCoeffs . take 5 . Poly.coeffs) arbitrary)
+
+
+
+{-# INLINE evaluateSqRt #-}
+evaluateSqRt :: (Trans.C a) =>
+   T a -> a -> Complex.T a
+evaluateSqRt f x =
+   Bell.evaluateSqRt (bell f) x *
+   Poly.evaluate (polynomial f) (Complex.fromReal $ sqrt pi * x)
+{- ToDo: evaluating a complex polynomial for a real argument can be optimized -}
+
+
+constant :: (Ring.C a) => T a
+constant =
+   Cons Bell.constant (Poly.const one)
+
+scale :: (Ring.C a) => a -> T a -> T a
+scale x f =
+   f{polynomial = fmap (Complex.scale x) $ polynomial f}
+
+scaleComplex :: (Ring.C a) => Complex.T a -> T a -> T a
+scaleComplex x f =
+   f{polynomial = fmap (x*) $ polynomial f}
+
+
+unit :: (Ring.C a) => T a
+unit = eigenfunction0
+
+{- |
+This one does not hold for larger degrees, although it would be nice:
+
+prop> QC.forAll (QC.choose (0,3)) $ \n -> G.eigenfunctionDifferential n == asRational (G.eigenfunctionIterative n)
+
+Unfortunately, both implementations compute different eigenbases.
+-}
+eigenfunction :: (Field.C a) => Int -> T a
+eigenfunction =
+   eigenfunctionDifferential
+
+-- | prop> G.eigenfunction0  ==  asRational (G.eigenfunctionDifferential 0)
+eigenfunction0 :: (Ring.C a) => T a
+eigenfunction0 =
+   Cons Bell.unit (Poly.fromCoeffs [one])
+
+-- | prop> G.eigenfunction1  ==  asRational (G.eigenfunctionDifferential 1)
+eigenfunction1 :: (Ring.C a) => T a
+eigenfunction1 =
+   Cons Bell.unit (Poly.fromCoeffs [zero, one])
+
+-- | prop> G.eigenfunction2  ==  asRational (G.eigenfunctionDifferential 2)
+eigenfunction2 :: (Field.C a) => T a
+eigenfunction2 =
+   Cons Bell.unit (Poly.fromCoeffs [-(1/4), zero, one])
+
+-- | prop> G.eigenfunction3  ==  asRational (G.eigenfunctionDifferential 3)
+eigenfunction3 :: (Field.C a) => T a
+eigenfunction3 =
+   Cons Bell.unit (Poly.fromCoeffs [zero, -(3/4), zero, one])
+
+
+{- |
+prop> QC.forAll (QC.choose (0,15)) $ \n -> let x = G.eigenfunctionDifferential n in G.fourier x  ==  rotateQuarter n x
+-}
+eigenfunctionDifferential :: (Field.C a) => Int -> T a
+eigenfunctionDifferential n =
+   (\f -> f{bell = Bell.unit}) $
+   nest n (scale (-1/4) . differentiate) $
+   Cons (Bell.Cons one zero zero 2) one
+
+{- |
+prop> QC.forAll (QC.choose (0,15)) $ \n -> let x = G.eigenfunctionIterative n in G.fourier x  ==  rotateQuarter n x
+-}
+eigenfunctionIterative ::
+   (Field.C a, Absolute.C a, ZeroTestable.C a, Eq a) => Int -> T a
+eigenfunctionIterative n =
+   fst . head . dropWhile (uncurry (/=)) . mapAdjacent (,) $
+   eigenfunctionIteration $
+   Cons
+      Bell.unit
+      (Poly.fromCoeffs $ replicate n zero ++ [one])
+
+eigenfunctionIteration :: (Field.C a) => T a -> [T a]
+eigenfunctionIteration =
+   iterate (\x ->
+      let y = fourier x
+          px = polynomial x
+          py = polynomial y
+          c = last (Poly.coeffs px) / last (Poly.coeffs py)
+      in  y{polynomial = fmap (0.5*) (px + fmap (c*) py)})
+
+
+{- |
+prop> withRational $ Laws.identity G.multiply G.constant
+prop> withRational $ Laws.commutative G.multiply
+prop> withRational $ Laws.associative G.multiply
+-}
+multiply :: (Ring.C a) =>
+   T a -> T a -> T a
+multiply f g =
+   Cons
+      (Bell.multiply (bell f) (bell g))
+      (polynomial f * polynomial g)
+
+{- |
+prop> withRational $ Laws.commutative G.convolve
+prop> withRational $ Laws.associative G.convolve
+-}
+convolve, {- convolveByDifferentiation, -} convolveByFourier :: (Field.C a) =>
+   T a -> T a -> T a
+convolve = convolveByFourier
+
+{-
+f <*> g =
+   let (foff,fint) = integrate f
+   in  fint <*> differentiate g + makeGaussPoly foff * g
+
+In principle this would work,
+but (makeGaussPoly foff * g) contains a lot of
+convolutions of Gaussian with Gaussian-polynomial-product,
+where the Gaussians have different parameters.
+
+convolveByDifferentiation f g =
+   case polynomial f of
+      fpoly ->
+         if null $ Poly.coeffs fpoly
+           then ...
+           else ...
+-}
+
+convolveByFourier f g =
+   reverse $ fourier $ multiply (fourier f) (fourier g)
+
+{-
+We use a Horner like scheme
+in order to translate multiplications with @id@
+to differentations on the Fourier side.
+Quadratic runtime.
+
+fourier (Cons bell (Poly.const a + Poly.shift f))
+  = fourier (Cons bell (Poly.const a)) + fourier (Cons bell (Poly.shift f))
+  = fourier (Cons bell (Poly.const a)) + differentiate (fourier (Cons bell f))
+
+We can certainly speed this up considerably
+by decomposing the polynomial into four polynomials,
+one for each of the four eigenvalues 1, i, -1, -i.
+-}
+{- |
+prop> withRational $ \x y -> G.fourier (G.convolve x y) == G.multiply (G.fourier x) (G.fourier y)
+prop> withRational $ \x -> nest 2 G.fourier x == G.reverse x
+prop> withRational $ \x a -> G.fourier (G.translate a x) == G.modulate a (G.fourier x)
+prop> withRational $ \x (QC.Positive a) -> G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x))
+prop> withRational $ \x -> G.fourier (G.differentiate x) == mulLinear2i (G.fourier x)
+-}
+fourier :: (Field.C a) =>
+   T a -> T a
+fourier f =
+   foldr
+      (\c p ->
+          let q = differentiate p
+          in  q{polynomial =
+                   Poly.const c +
+                   fmap (Complex.scale (1/2) . Complex.quarterLeft) (polynomial q)})
+      (Cons (Bell.fourier $ bell f) zero) $
+   Poly.coeffs $ polynomial f
+
+{- |
+Differentiate and divide by @sqrt pi@ in order to stay in a ring.
+This way, we do not need to fiddle with pi factors.
+
+prop> withRational $ \x y -> G.convolve (G.differentiate x) y == G.convolve x (G.differentiate y)
+-}
+differentiate :: (Ring.C a) => T a -> T a
+differentiate f =
+   f{polynomial =
+        Differential.differentiate (polynomial f)
+        - Differential.differentiate (Bell.exponentPolynomial (bell f))
+           * polynomial f}
+
+{-
+g = (bell f * poly f)'
+  = bell f * ((poly f)' - (exppoly (bell f))' * poly f)
+poly g = (poly f)' - (exppoly (bell f))' * poly f
+
+Integration means we have g and ask for f.
+
+poly f = ((poly f)' - poly g) / (exppoly (bell f))'
+
+However must start with the highest term of 'poly f',
+and thus we need to perform the division on reversed polynomials.
+-}
+{- |
+>>> snd $ G.integrate $ G.differentiate $ G.Cons Bell.unit (Poly.fromCoeffs [7,7,7,7 :: Complex.T Rational])
+Cons {bell = Cons {amp = 1 % 1, c0 = 0 % 1 +: 0 % 1, c1 = 0 % 1 +: 0 % 1, c2 = 1 % 1}, polynomial = Polynomial.fromCoeffs [7 % 1 +: 0 % 1,7 % 1 +: 0 % 1,7 % 1 +: 0 % 1,7 % 1 +: 0 % 1]}
+
+prop> withRational $ \x -> G.integrate (G.differentiate x) == (zero, x)
+prop> withRational $ \x@(G.Cons b p) -> let (xoff,xint) = G.integrate x in G.differentiate xint == G.Cons b (p + Poly.const xoff)
+-}
+integrate ::
+   (Field.C a, ZeroTestable.C a) =>
+   T a -> (Complex.T a, T a)
+integrate f =
+   let fs = Poly.coeffs $ polynomial f
+       (ys,~[r]) =
+          PolyCore.divModRev
+             {-
+             We need the shortening convention of 'zipWith'
+             in order to limit the result list,
+             we cannot use list instance for (-).
+             -}
+             (zipWith (-)
+                (0 : 0 : diffRev ys)
+                (List.reverse fs))
+             (List.reverse $ Poly.coeffs $
+              Differential.differentiate $
+              Bell.exponentPolynomial $ bell f)
+   in  forcePair $
+       if null fs
+         then (zero, f)
+         else (r, f{polynomial = Poly.fromCoeffs $ List.reverse ys})
+
+diffRev :: Ring.C a => [a] -> [a]
+diffRev xs =
+   zipWith (*) xs
+      (drop 1 (iterate (subtract 1) (fromIntegral $ length xs)))
+
+{-
+integrateDefinite
+   (maybe rename integrate to antiderivative and call this one integrate)
+
+int(x^(2*n)*exp(-x^2),x=-infinity..infinity)
+ = 2 * int(x^(2*n)*exp(-x^2),x=0..infinity)
+     substitute t=x^2, dt = dx * 2 * sqrt t
+ = int(t^(n-1/2)*exp(-t),x=0..infinity)
+ = Gamma(n+1/2)
+ = (2n-1)!!/2^n * sqrt pi
+
+int(pi^n*x^(2*n)*exp(-pi*x^2),x=-infinity..infinity)
+ = (2n-1)!!/2^n
+
+
+The remainder value of 'integrate'
+is the coefficient of the error function
+and this is the only part that does not vanish when approaching the limit.
+
+
+In order to stay in a field,
+we have to return a rational number
+and a transcendental part written es @exp a@.
+
+It would be interesting to see how integral inequalities
+translate to scalar inequalities containing exponential functions.
+-}
+
+
+{- |
+prop> withRational $ \x a b -> G.translate a (G.translate b x) == G.translate (a+b) x
+-}
+translate :: Ring.C a => a -> T a -> T a
+translate d =
+   translateComplex (Complex.fromReal d)
+
+{- |
+prop> withRational $ \x a b -> G.translateComplex a (G.translateComplex b x) == G.translateComplex (a+b) x
+prop> withRational $ \x a -> G.translateComplex (Complex.fromReal a) x == G.translate a x
+-}
+translateComplex :: Ring.C a => Complex.T a -> T a -> T a
+translateComplex d f =
+   Cons
+      (Bell.translateComplex d $ bell f)
+      (Poly.translate d $ polynomial f)
+
+{- |
+prop> withRational $ \x a b -> G.modulate a (G.modulate b x) == G.modulate (a+b) x
+prop> withRational $ \x a b -> G.modulate b (G.translate a x) == G.turn (a*b) (G.translate a (G.modulate b x))
+-}
+modulate :: Ring.C a => a -> T a -> T a
+modulate d f =
+   Cons
+      (Bell.modulate d $ bell f)
+      (polynomial f)
+
+turn :: Ring.C a => a -> T a -> T a
+turn d f =
+   Cons
+      (Bell.turn d $ bell f)
+      (polynomial f)
+
+{- |
+prop> withRational $ \x -> nest 2 G.reverse x == x
+-}
+reverse :: Additive.C a => T a -> T a
+reverse f =
+   Cons
+      (Bell.reverse $ bell f)
+      (Poly.reverse $ polynomial f)
+
+{- |
+prop> withRational $ \x (QC.Positive a) (QC.Positive b) -> G.dilate a (G.dilate b x) == G.dilate (a*b) x
+prop> withRational $ \x (QC.Positive a) -> G.shrink a x == G.dilate (recip a) x
+-}
+dilate :: Field.C a => a -> T a -> T a
+dilate k f =
+   Cons
+      (Bell.dilate k $ bell f)
+      (Poly.dilate (Complex.fromReal k) $ polynomial f)
+
+{- |
+prop> withRational $ \x (QC.Positive a) -> G.dilate a (G.shrink a x) == x
+prop> withRational $ \x (QC.Positive a) -> G.shrink a (G.dilate a x) == x
+-}
+shrink :: Ring.C a => a -> T a -> T a
+shrink k f =
+   Cons
+      (Bell.shrink k $ bell f)
+      (Poly.shrink (Complex.fromReal k) $ polynomial f)
+
+{-
+We could also amplify the polynomial coefficients.
+-}
+amplify :: Ring.C a => a -> T a -> T a
+amplify k f =
+   Cons
+      (Bell.amplify k $ bell f)
+      (polynomial f)
+
+
+{- |
+Approximate a @T a@ using a linear combination of translated @Bell.T a@.
+The smaller the unit (e.g. 0.1, 0.01, 0.001)
+the better the approximation but the worse the numeric properties.
+
+We cannot put all information into @amp@ of @Bell@,
+since @amp@ must be real, but is complex here by construction.
+We really need at least signed amplitudes at this place,
+since we want to represent differences of Gaussians.
+
+prop> withRational $ \x (QC.NonZero unit) d -> G.approximateByBells unit (G.translateComplex d x) == map (mapSnd (Bell.translateComplex d)) (G.approximateByBells unit x)
+prop> withRational $ \x (QC.NonZero unit) (QC.NonZero d) -> G.approximateByBells unit (G.dilate d x) == map (mapSnd (Bell.dilate d)) (G.approximateByBells (unit/d) x)
+prop> withRational $ \x (QC.NonZero unit) (QC.NonZero d) -> G.approximateByBells unit (G.shrink d x) == map (mapSnd (Bell.shrink d)) (G.approximateByBells (unit*d) x)
+-}
+approximateByBells ::
+   Field.C a =>
+   a -> T a -> [(Complex.T a, Bell.T a)]
+approximateByBells unit_ f =
+   let b = bell f
+       amps =
+          -- approximateByBellsByTranslation
+          approximateByBellsAtOnce
+             unit_
+             (Complex.scale (recip (2 * Bell.c2 b)) (Bell.c1 b))
+             (recip (2*unit_*Bell.c2 b))
+             (polynomial f)
+   in  zip (LPoly.coeffs amps) $
+       map
+          (\d -> Bell.translate d b)
+          (laurentAbscissas (unit_/2) amps)
+
+{- |
+prop> \(QC.NonZero unit) d s p0 -> let p = Poly.fromCoeffs $ take 10 p0 in G.approximateByBellsAtOnce unit d s p == G.approximateByBellsByTranslation unit d (s::Rational) p
+-}
+approximateByBellsAtOnce ::
+   Field.C a =>
+   a -> Complex.T a -> a -> Poly.T (Complex.T a) -> LPoly.T (Complex.T a)
+approximateByBellsAtOnce unit_ d s p =
+   foldr
+      (\x amps0 ->
+         {-
+         Decompose (bell t * (t-d)) = bell t * t - bell t * d
+         -}
+         let y = fmap (Complex.scale s) amps0
+         in  -- \t -> bell t * t
+             --    ~   (translate unit_ bell - translate (-unit_) bell) / unit_
+             LPoly.shift 1 y -
+             LPoly.shift (-1) y +
+             -- bell t * d
+             zipWithAbscissas
+                (\t z -> (Complex.fromReal t - d) * z)
+                (unit_/2) amps0 +
+             LPoly.const x)
+      (LPoly.fromCoeffs [])
+      (Poly.coeffs p)
+
+approximateByBellsByTranslation ::
+   Field.C a =>
+   a -> Complex.T a -> a -> Poly.T (Complex.T a) -> LPoly.T (Complex.T a)
+approximateByBellsByTranslation unit_ d s p =
+   foldr
+      (\x amps0 ->
+         {-
+         Decompose (bell t * (t-d)) = bell t * t - bell t * d
+         -}
+         let y = fmap (Complex.scale s) amps0
+         in  -- \t -> bell t * t
+             --    ~   (translate unit_ bell - translate (-unit_) bell) / unit_
+             LPoly.shift 1 y -
+             LPoly.shift (-1) y +
+             -- bell t * d
+             zipWithAbscissas Complex.scale (unit_/2) amps0 +
+             LPoly.const x)
+      (LPoly.fromCoeffs [])
+      (Poly.coeffs $ Poly.translate d p)
+
+zipWithAbscissas ::
+   (Ring.C a) =>
+   (a -> b -> c) -> a -> LPoly.T b -> LPoly.T c
+zipWithAbscissas h unit_ y =
+   LPoly.fromShiftCoeffs (LPoly.expon y) $
+   zipWith h
+      (laurentAbscissas unit_ y)
+      (LPoly.coeffs y)
+
+laurentAbscissas :: Ring.C a => a -> LPoly.T c -> [a]
+laurentAbscissas unit_ =
+   map (\d -> fromIntegral d * unit_) .
+   iterate (1+) . LPoly.expon
+
+
+{- No Ring instance for Gaussians
+instance (Ring.C a) => Differential.C (T a) where
+   differentiate = differentiate
+-}
+
+{- laws
+differentiate (f*g) =
+   (differentiate f) * g + f * (differentiate g)
+
+inequalities:
+
+Heisenberg's uncertainty relation
+   needs integrals and thus needs product of exponential numbers and roots
+-}
diff --git a/gaussian/MathObj/Gaussian/Variance.hs b/gaussian/MathObj/Gaussian/Variance.hs
new file mode 100644
--- /dev/null
+++ b/gaussian/MathObj/Gaussian/Variance.hs
@@ -0,0 +1,285 @@
+{-# LANGUAGE RebindableSyntax #-}
+{-
+We represent a Gaussian bell curve in terms of the reciprocal of its variance
+and its value at the origin.
+
+We could do some projective geometry in the exponent
+in order to also have zero variance,
+which corresponds to the dirac impulse.
+
+The Gaussians form a nice multiplicative commutative monoid.
+Maybe we should have such a structure.
+It would also be useful for the Root data type
+and a new Exponential data type.
+-}
+module MathObj.Gaussian.Variance where
+
+import qualified MathObj.Polynomial as Poly
+import qualified Number.Root as Root
+
+import qualified Algebra.Transcendental as Trans
+import qualified Algebra.Algebraic      as Algebraic
+import qualified Algebra.Field          as Field
+import qualified Algebra.Absolute       as Absolute
+import qualified Algebra.Ring           as Ring
+import qualified Algebra.Additive       as Additive
+
+import Test.QuickCheck (Arbitrary, arbitrary, )
+import Control.Monad (liftM2, )
+
+import NumericPrelude.Numeric
+import NumericPrelude.Base
+
+
+{- $setup
+>>> import qualified MathObj.Gaussian.Variance as G
+>>> import MathObj.Gaussian.ExponentTuple (HoelderConjugates(HoelderConjugates))
+>>> import MathObj.Gaussian.ExponentTuple (YoungConjugates(YoungConjugates))
+>>> import qualified Algebra.Laws as Laws
+>>> import qualified Number.Root as Root
+>>> import NumericPrelude.Base as P
+>>> import NumericPrelude.Numeric as NP
+>>> import Prelude ()
+>>> import qualified Test.QuickCheck as QC
+>>> import Data.Function.HT (Id, nest)
+>>>
+>>> asRational :: Id (G.T Rational)
+>>> asRational = id
+>>>
+>>> withRational :: Id (G.T Rational -> a)
+>>> withRational = id
+-}
+
+
+{- |
+Since @amp@ is the square of the actual amplitude it must be non-negative.
+-}
+data T a = Cons {amp, c :: a}
+   deriving (Eq, Show)
+
+instance (Absolute.C a, Arbitrary a) => Arbitrary (T a) where
+   arbitrary =
+      liftM2 Cons
+         (fmap abs arbitrary)
+         (fmap ((1+) . abs) arbitrary)
+
+
+constant :: Ring.C a => T a
+constant = Cons one zero
+
+{- |
+eigenfunction of 'fourier'
+-}
+unit :: Ring.C a => T a
+unit = Cons one one
+
+{-# INLINE evaluate #-}
+evaluate :: (Trans.C a) =>
+   T a -> a -> a
+evaluate f x =
+   sqrt (amp f) * exp (-pi * c f * x^2)
+
+exponentPolynomial :: (Additive.C a) =>
+   T a -> Poly.T a
+exponentPolynomial f =
+   Poly.fromCoeffs [zero, zero, c f]
+
+
+integrateRoot :: (Field.C a) => T a -> Root.T a
+integrateRoot f =
+   Root.sqrt $ Root.fromNumber $ amp f / c f
+
+{- |
+Cauchy-Schwarz inequality:
+
+prop> withRational $ \x y -> G.scalarProductRoot x y <= G.norm2Root x `Root.mul` G.norm2Root y
+
+Hoelder inequality:
+
+prop> withRational $ \x y -> G.scalarProductRoot x y <= G.norm1Root x `Root.mul` G.normInfRoot y
+prop> withRational $ \x y (HoelderConjugates p q) -> G.scalarProductRoot x y <= G.normPRoot p x `Root.mul` G.normPRoot q y
+-}
+scalarProductRoot :: (Field.C a) => T a -> T a -> Root.T a
+scalarProductRoot f g =
+   integrateRoot (multiply f g)
+
+
+{- |
+prop> withRational $ \x -> G.norm1Root x == G.normPRoot 1 x
+-}
+norm1Root :: (Field.C a) => T a -> Root.T a
+norm1Root = integrateRoot
+
+{- |
+prop> withRational $ \x -> G.norm2Root x == G.normPRoot 2 x
+-}
+norm2Root :: (Field.C a) => T a -> Root.T a
+norm2Root f =
+   Root.sqrt $
+      Root.fromNumber (amp f)
+      `Root.div`
+      Root.sqrt (Root.fromNumber $ 2 * c f)
+
+normInfRoot :: (Field.C a) => T a -> Root.T a
+normInfRoot f =
+   Root.sqrt $ Root.fromNumber $ amp f
+
+{-
+I would have liked to test for a monotony of norms.
+Unfortunately, it does not hold.
+
+Means contain a division by the size of the domain.
+Norms do not have this division.
+Means are monotonic with respect to the degree.
+Norms are not.
+We cannot turn the norms into means since the size of the domain
+(the complete real axis) is infinitely large.
+
+prop> :{ withRational $ \x p0 q0 ->
+   let p = 1 + abs p0
+       q = 1 + abs q0
+   in  case compare p q of
+          EQ -> G.normPRoot p x == G.normPRoot q x
+          LT -> G.normPRoot p x <= G.normPRoot q x
+          GT -> G.normPRoot p x >= G.normPRoot q x
+:}
+
+This should also fail,
+but QuickCheck does not seem to try counterexamples.
+
+prop> :{ withRational $ \x p0 ->
+   let p = 1 + abs p0
+   in  G.normPRoot p x <= G.normInfRoot x
+:}
+-}
+normPRoot :: (Field.C a) => Rational -> T a -> Root.T a
+normPRoot p f =
+   Root.sqrt (Root.fromNumber (amp f))
+   `Root.div`
+   Root.rationalPower (recip (2*p)) (Root.fromNumber (fromRational' p * c f))
+
+
+-- ToDo: implement NormedSpace.Sum et.al.
+norm1 :: (Algebraic.C a) => T a -> a
+norm1 f =
+   sqrt $ amp f / c f
+
+norm2 :: (Algebraic.C a) => T a -> a
+norm2 f =
+   sqrt $ amp f / (sqrt $ 2 * c f)
+
+normInf :: (Algebraic.C a) => T a -> a
+normInf f =
+   sqrt (amp f)
+
+normP :: (Trans.C a) => a -> T a -> a
+normP p f =
+   sqrt (amp f) * (p * c f) ^? (- recip (2*p))
+
+
+variance :: (Trans.C a) =>
+   T a -> a
+variance f =
+   recip $ c f * 2*pi
+
+{- |
+prop> withRational $ \x (QC.Positive a) -> G.varianceRational (G.dilate a x) == a^2 * G.varianceRational x
+prop> withRational $ \x y -> G.varianceRational (G.convolve x y) == G.varianceRational x + G.varianceRational y
+-}
+varianceRational :: (Field.C a) => T a -> a
+varianceRational f = recip $ c f
+
+{- |
+prop> Laws.identity G.multiply G.constant . asRational
+prop> Laws.commutative G.multiply . asRational
+prop> Laws.associative G.multiply . asRational
+-}
+multiply :: (Ring.C a) =>
+   T a -> T a -> T a
+multiply f g =
+   Cons (amp f * amp g) (c f + c g)
+
+powerRing :: (Trans.C a) =>
+   Integer -> T a -> T a
+powerRing p f =
+   Cons (amp f ^ p) (fromInteger p * c f)
+
+{-
+powerField does not makes sense,
+since the reciprocal of a Gaussian diverges.
+-}
+
+powerAlgebraic :: (Trans.C a) =>
+   Rational -> T a -> T a
+powerAlgebraic p f =
+   Cons (amp f ^/ p) (fromRational' p * c f)
+
+powerTranscendental :: (Trans.C a) =>
+   a -> T a -> T a
+powerTranscendental p f =
+   Cons (amp f ^? p) (p * c f)
+
+{- |
+> convolve x y t =
+>    integrate $ \s -> x s * y(t-s)
+
+Convergence only for @c f + c g > 0@.
+
+prop> Laws.commutative G.convolve . asRational
+prop> Laws.associative G.convolve . asRational
+
+Young inequality:
+
+prop> withRational $ \x y -> G.normInfRoot (G.convolve x y) <= G.norm1Root x `Root.mul` G.normInfRoot y
+prop> withRational $ \x y (HoelderConjugates p q) -> G.normInfRoot (G.convolve x y) <= G.normPRoot p x `Root.mul` G.normPRoot q y
+prop> withRational $ \x y (YoungConjugates p q r) -> G.normPRoot r (G.convolve x y) <= G.normPRoot p x `Root.mul` G.normPRoot q y
+-}
+convolve :: (Field.C a) =>
+   T a -> T a -> T a
+convolve f g =
+   let s = c f + c g
+   in  Cons
+          (amp f * amp g / s)
+          (c f * c g / s)
+
+{- |
+> fourier x f =
+>    integrate $ \t -> x t * cis (-2*pi*t*f)
+
+Convergence only for @c f > 0@.
+
+prop> withRational $ \x y -> G.fourier (G.convolve x y) == G.multiply (G.fourier x) (G.fourier y)
+prop> withRational $ \x -> nest 4 G.fourier x == x
+prop> withRational $ \x (QC.Positive a) -> G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x))
+prop> withRational $ \x y -> G.scalarProductRoot x y == G.scalarProductRoot (G.fourier x) (G.fourier y)
+-}
+fourier :: (Field.C a) =>
+   T a -> T a
+fourier f =
+   Cons (amp f / c f) (recip $ c f)
+{-
+fourier (t -> exp(-(a*t)^2))
+-}
+
+{- |
+prop> withRational $ \x (QC.Positive a) (QC.Positive b) -> G.dilate a (G.dilate b x) == G.dilate (a*b) x
+prop> withRational $ \x (QC.Positive a) -> G.shrink a x == G.dilate (recip a) x
+-}
+dilate :: (Field.C a) => a -> T a -> T a
+dilate k f =
+   Cons (amp f) $ c f / k^2
+
+{- |
+prop> withRational $ \x (QC.Positive a) -> G.dilate a (G.shrink a x) == x
+prop> withRational $ \x (QC.Positive a) -> G.shrink a (G.dilate a x) == x
+-}
+shrink :: (Ring.C a) => a -> T a -> T a
+shrink k f =
+   Cons (amp f) $ c f * k^2
+
+{- |
+@amplify k@ scales by @abs k@!
+-}
+amplify :: (Ring.C a) => a -> T a -> T a
+amplify k f =
+   Cons (k^2 * amp f) $ c f
diff --git a/numeric-prelude.cabal b/numeric-prelude.cabal
--- a/numeric-prelude.cabal
+++ b/numeric-prelude.cabal
@@ -1,188 +1,60 @@
+Cabal-Version:  2.2
 Name:           numeric-prelude
-Version:        0.3.0.2
-License:        GPL
+Version:        0.4.4
+License:        BSD-3-Clause
 License-File:   LICENSE
 Author:         Dylan Thurston <dpt@math.harvard.edu>, Henning Thielemann <numericprelude@henning-thielemann.de>, Mikael Johansson
 Maintainer:     Henning Thielemann <numericprelude@henning-thielemann.de>
 Homepage:       http://www.haskell.org/haskellwiki/Numeric_Prelude
 Category:       Math
 Stability:      Experimental
-Tested-With:    GHC==6.4.1, GHC==6.8.2, GHC==6.10.4, GHC==6.12.3
-Tested-With:    GHC==7.2.2, GHC==7.4.1
-Cabal-Version:  >=1.6
+Tested-With:    GHC==7.4.2, GHC==7.6.3, GHC==7.8.4, GHC==7.10.3
+Tested-With:    GHC==8.4.4, GHC==8.6.5, GHC==9.0.1
 Build-Type:     Simple
 Synopsis:       An experimental alternative hierarchy of numeric type classes
 Description:
-  Revisiting the Numeric Classes
-  .
-  The Prelude for Haskell 98 offers a well-considered set of numeric classes
-  which covers the standard numeric types
-  ('Integer', 'Int', 'Rational', 'Float', 'Double', 'Complex') quite well.
-  But they offer limited extensibility and have a few other flaws.
-  In this proposal we will revisit these classes, addressing the following concerns:
-  .
-  [1] The current Prelude defines no semantics for the fundamental operations.
-      For instance, presumably addition should be associative
-      (or come as close as feasible),
-      but this is not mentioned anywhere.
-  .
-  [2] There are some superfluous superclasses.
-      For instance, 'Eq' and 'Show' are superclasses of 'Num'.
-      Consider the data type
-      @   data IntegerFunction a = IF (a -> Integer) @
-      One can reasonably define all the methods of 'Algebra.Ring.C' for
-      @IntegerFunction a@ (satisfying good semantics),
-      but it is impossible to define non-bottom instances of 'Eq' and 'Show'.
-      In general, superclass relationship should indicate
-      some semantic connection between the two classes.
-  .
-  [3] In a few cases, there is a mix of semantic operations and
-      representation-specific operations.
-      'toInteger', 'toRational',
-      and the various operations in 'RealFloating' ('decodeFloat', ...)
-      are the main examples.
-  .
-  [4] In some cases, the hierarchy is not finely-grained enough:
-      Operations that are often defined independently are lumped together.
-      For instance, in a financial application one might want a type \"Dollar\",
-      or in a graphics application one might want a type \"Vector\".
-      It is reasonable to add two Vectors or Dollars,
-      but not, in general, reasonable to multiply them.
-      But the programmer is currently forced to define a method for '(*)'
-      when she defines a method for '(+)'.
-  .
-  In specifying the semantics of type classes,
-  I will state laws as follows:
-  .
-  >    (a + b) + c === a + (b + c)
-  .
-  The intended meaning is extensional equality:
-  The rest of the program should behave in the same way
-  if one side is replaced with the other.
-  Unfortunately, the laws are frequently violated by standard instances;
-  the law above, for instance, fails for 'Float':
-  .
-  >    (1e20 + (-1e20)) + 1.0  = 1.0
-  >     1e20 + ((-1e20) + 1.0) = 0.0
-  .
-  For inexact number types like floating point types,
-  thus these laws should be interpreted as guidelines rather than absolute rules.
-  In particular, the compiler is not allowed to use them for optimization.
-  Unless stated otherwise, default definitions should also be taken as laws.
-  .
-  Thanks to Brian Boutel, Joe English, William Lee Irwin II, Marcin
-  Kowalczyk, Ketil Malde, Tom Schrijvers, Ken Shan, and Henning
-  Thielemann for helpful comments.
-  .
-  .
-  Usage:
-  .
-  Write modules in the following style:
-  .
-  > [-# NoImplicitPrelude #-]
-  > module MyModule where
-  >
-  > ... various specific imports ...
-  >
-  > import NumericPrelude
-  .
-  Importing @NumericPrelude@ is almost the same as
-  .
-  > import NumericPrelude.Numeric
-  > import NumericPrelude.Base   .
-  .
-  Instead of the @NoImplicitPrelude@ pragma
-  you could also write @import Prelude ()@
-  but this will yield problems with numeric literals.
-  .
-  There are two wrapper types that allow types
-  to be used with both Haskell98 and NumericPrelude type classes
-  that are initially implemented for only one of them.
-  .
-  .
-  Scope & Limitations\/TODO:
-  .
-  * It might be desireable to split Ord up into Poset and Ord
-    (a total ordering).
-    This is not addressed here.
-  .
-  * In some cases, this hierarchy may not yet be fine-grained enough.
-    For instance, time spans (\"5 minutes\") can be added to times (\"12:34\"),
-    but two times are not addable. (\"12:34 + 8:23\")
-    As it stands,
-    users have to use a different operator for adding time spans to times
-    than for adding two time spans.
-    Similar issues arise for vector space et al.
-    This is a consciously-made tradeoff, but might be changed.
-    This becomes most serious when dealing with quantities with units
-    like @length\/distance^2@, for which @(*)@ as defined here is useless.
-    (One way to see the issue: should
-    @  f x y = iterate (x *) y  @
-    have principal type
-    @  (Ring.C a) => a -> a -> [a]  @
-    or something like
-    @  (Ring.C a, Module a b) => a -> b -> [b]  @
-    ?)
-  .
-  * I stuck with the Haskell 98 names.
-    In some cases I find them lacking.
-    Neglecting backwards compatibility, we have renamed classes as follows:
-      Num           --> Additive, Ring, Absolute
-      Integral      --> ToInteger, IntegralDomain, RealIntegral
-      Fractional    --> Field
-      Floating      --> Algebraic, Transcendental
-      Real          --> ToRational
-      RealFrac      --> RealRing, RealField
-      RealFloat     --> RealTranscendental
-  .
-  .
-  Additional standard libraries might include Enum, IEEEFloat (including
-  the bulk of the functions in Haskell 98's RealFloat class),
-  VectorSpace, Ratio, and Lattice.
+  The package provides an experimental alternative hierarchy
+  of numeric type classes.
+  The type classes are more oriented at mathematical structures
+  and their methods come with laws that the instances must fulfill.
 
 Extra-Source-Files:
   Makefile
+  README.md
   docs/NOTES
   docs/README
   src/Algebra/GenerateRules.hs
 
-Flag splitBase
-  description: Choose the new smaller, split-up base package.
-
-Flag buildTests
-  description: Build test executables
+Flag buildExamples
+  description: Build example executables
   default:     False
 
 Source-Repository this
-  Tag:         0.3.0.2
+  Tag:         0.4.4
   Type:        darcs
-  Location:    http://code.haskell.org/numeric-prelude/
+  Location:    https://hub.darcs.net/thielema/numeric-prelude/
 
 Source-Repository head
   Type:        darcs
-  Location:    http://code.haskell.org/numeric-prelude/
+  Location:    https://hub.darcs.net/thielema/numeric-prelude/
 
 Library
   Build-Depends:
     parsec >=1 && <4,
-    QuickCheck >=1 && <3,
+    QuickCheck >=2.10 && <3,
     storable-record >=0.0.1 && <0.1,
     non-negative >=0.0.5 && <0.2,
-    utility-ht >=0.0.6 && <0.1,
-    deepseq >=1.1 && <1.4
-  If flag(splitBase)
-    Build-Depends:
-      base >= 2 && <5,
-      array >=0.1 && <0.5,
-      containers >=0.1 && <0.6,
-      random >=1.0 && <1.1
-  Else
-    Build-Depends: base >= 1.0 && < 2
+    semigroups >=0.1 && <1.0,
+    utility-ht >=0.0.13 && <0.1,
+    deepseq >=1.1 && <1.5
 
-  If impl(ghc>=7.0)
-    CPP-Options: -DNoImplicitPrelude=RebindableSyntax
-    Extensions: CPP
+  Build-Depends:
+    array >=0.1 && <0.6,
+    containers >=0.1 && <0.7,
+    random >=1.0 && <1.3,
+    base >=4.5 && <5
 
+  Default-Language: Haskell98
   GHC-Options:    -Wall
   Hs-source-dirs: src
   Exposed-modules:
@@ -193,6 +65,7 @@
     Algebra.DimensionTerm
     Algebra.DivisibleSpace
     Algebra.Field
+    Algebra.FloatingPoint
     Algebra.Indexable
     Algebra.IntegralDomain
     Algebra.NonNegative
@@ -281,68 +154,86 @@
     NumericPrelude.List
     Algebra.AffineSpace
     Algebra.RealRing98
-    MathObj.Gaussian.Variance
-    MathObj.Gaussian.Bell
-    MathObj.Gaussian.Polynomial
-    Number.ComplexSquareRoot
     -- I think I won't add them this way.
     -- It is certainly better to split the class into comparison and selection.
     Algebra.EqualityDecision
     Algebra.OrderDecision
 
-Executable test
-  Hs-Source-Dirs: src, test
+Executable numeric-prelude-demo
+  Hs-Source-Dirs: test
   GHC-Options:    -Wall
-  Main-Is: Test.hs
-
-  If !flag(buildTests)
-    Buildable:         False
+  Default-Language: Haskell98
+  Main-Is: Demo.hs
 
-  If impl(ghc>=7.0)
-    CPP-Options: -DNoImplicitPrelude=RebindableSyntax
-    Extensions: CPP
+  If flag(buildExamples)
+    Build-Depends:
+      numeric-prelude,
+      base
+  Else
+    Buildable: False
 
-Executable testsuite
-  Hs-Source-Dirs: src, test
+Test-Suite numeric-prelude-test
+  Type: exitcode-stdio-1.0
   GHC-Options:    -Wall
+  Default-Language: Haskell98
+  Hs-Source-Dirs: test
   Other-modules:
     Test.NumericPrelude.Utility
     Test.Number.GaloisField2p32m5
     Test.Number.ComplexSquareRoot
     Test.Algebra.IntegralDomain
+    Test.Algebra.PrincipalIdealDomain
     Test.Algebra.RealRing
     Test.Algebra.Additive
     Test.MathObj.RefinementMask2
     Test.MathObj.PartialFraction
     Test.MathObj.Matrix
     Test.MathObj.Polynomial
+    Test.MathObj.Polynomial.Core
     Test.MathObj.PowerSeries
+    Test.MathObj.PowerSeries.Core
+    Test.MathObj.PowerSeries.Example
+    Test.MathObj.Gaussian.ExponentTuple
     Test.MathObj.Gaussian.Variance
     Test.MathObj.Gaussian.Bell
     Test.MathObj.Gaussian.Polynomial
+  Hs-Source-Dirs: playground
+  Other-modules:
+    Number.ComplexSquareRoot
+  Hs-Source-Dirs: gaussian
+  Other-Modules:
+    MathObj.Gaussian.Bell
+    MathObj.Gaussian.Polynomial
+    MathObj.Gaussian.Variance
+    MathObj.Gaussian.ExponentTuple
   Main-Is: Test/Run.hs
 
-  If flag(buildTests)
-    Build-Depends: HUnit >=1 && <2
-  Else
-    Buildable: False
-
-  If impl(ghc>=7.0)
-    CPP-Options: -DNoImplicitPrelude=RebindableSyntax
-    Extensions: CPP
+  Build-Depends:
+    doctest-exitcode-stdio >=0.0 && <0.1,
+    doctest-lib >=0.1 && <0.1.1,
+    numeric-prelude,
+    QuickCheck,
+    utility-ht,
+    random,
+    base
 
-Executable test-gaussian
-  Hs-Source-Dirs: src, test
+Executable numeric-prelude-gaussian
+  Hs-Source-Dirs: gaussian
   Main-Is: Gaussian.hs
+  Default-Language: Haskell98
   Other-Modules:
     MathObj.Gaussian.Example
-  If flag(buildTests)
+    MathObj.Gaussian.Variance
+    MathObj.Gaussian.Bell
+    MathObj.Gaussian.Polynomial
+
+  If flag(buildExamples)
     Build-Depends:
-      gnuplot >=0.3 && <0.5,
-      HTam >=0.0.2 && <0.1
+      gnuplot >=0.5 && <0.6,
+      HTam >=0.0.2 && <0.2,
+      numeric-prelude,
+      QuickCheck,
+      utility-ht,
+      base
   Else
     Buildable: False
-
-  If impl(ghc>=7.0)
-    CPP-Options: -DNoImplicitPrelude=RebindableSyntax
-    Extensions: CPP
diff --git a/playground/Number/ComplexSquareRoot.hs b/playground/Number/ComplexSquareRoot.hs
new file mode 100644
--- /dev/null
+++ b/playground/Number/ComplexSquareRoot.hs
@@ -0,0 +1,137 @@
+module Number.ComplexSquareRoot where
+
+import qualified Algebra.RealField as RealField
+import qualified Algebra.RealRing as RealRing
+import qualified Algebra.Ring as Ring
+import qualified Algebra.Additive as Additive
+import qualified Algebra.ZeroTestable as ZeroTestable
+
+import qualified Number.Complex as Complex
+
+import Test.QuickCheck (Arbitrary, arbitrary, )
+
+import Control.Monad (liftM2, )
+
+import qualified NumericPrelude.Numeric as NP
+import NumericPrelude.Numeric hiding (recip, )
+import NumericPrelude.Base
+import Prelude ()
+
+
+{- $setup
+>>> import qualified Number.ComplexSquareRoot as SR
+>>> import qualified Number.Complex as Complex
+>>> import qualified Algebra.Laws as Laws
+>>> import Test.QuickCheck ((==>))
+>>> import NumericPrelude.Numeric
+>>> import NumericPrelude.Base
+>>> import Prelude ()
+>>>
+>>> sr :: SR.T Rational -> SR.T Rational
+>>> sr = id
+-}
+
+{- |
+Represent the square root of a complex number
+without actually having to compute a square root.
+If the Bool is False,
+then the square root is represented with positive real part
+or zero real part and positive imaginary part.
+If the Bool is True the square root is negated.
+
+prop> Laws.identity SR.mul SR.one . sr
+prop> Laws.commutative SR.mul . sr
+prop> Laws.associative SR.mul . sr
+prop> Laws.homomorphism SR.fromNumber (\x y -> x * (y :: Complex.T Rational)) SR.mul
+prop> Laws.rightIdentity SR.div SR.one . sr
+prop> \x -> not (isZero x) ==> SR.recip (SR.recip x) == sr x
+prop> \x -> not (isZero x) ==> Laws.inverse SR.mul SR.recip SR.one (sr x)
+-}
+data T a = Cons Bool (Complex.T a)
+   deriving (Show)
+
+{- |
+You must use @fmap@ only for number type conversion.
+-}
+instance Functor T where
+   fmap f (Cons n x) = Cons n (fmap f x)
+
+instance (ZeroTestable.C a) => ZeroTestable.C (T a) where
+   isZero (Cons _b s) = isZero s
+
+instance (ZeroTestable.C a, Eq a) => Eq (T a) where
+   (Cons xb xs) == (Cons yb ys) =
+      isZero xs && isZero ys  ||
+      xb==yb && xs==ys
+
+instance (Arbitrary a) => Arbitrary (T a) where
+   arbitrary = liftM2 Cons arbitrary arbitrary
+
+
+fromNumber :: (RealRing.C a) => Complex.T a -> T a
+fromNumber x =
+   Cons
+      (case compare zero (Complex.real x) of
+         LT -> False
+         GT -> True
+         EQ -> Complex.imag x < zero)
+      (x^2)
+
+-- htam:Wavelet.DyadicResultant.parityFlip
+toNumber :: (RealRing.C a, Complex.Power a) => T a -> Complex.T a
+toNumber (Cons n x) =
+   case sqrt x of y -> if n then NP.negate y else y
+
+
+one :: (Ring.C a) => T a
+one = Cons False NP.one
+
+inUpperHalfplane :: (Additive.C a, Ord a) => Complex.T a -> Bool
+inUpperHalfplane x =
+   case compare (Complex.imag x) zero of
+      GT -> True
+      LT -> False
+      EQ -> Complex.real x < zero
+
+mul, mulAlt, mulAlt2 :: (RealRing.C a) => T a -> T a -> T a
+mul (Cons xb xs) (Cons yb ys) =
+   let zs = xs*ys
+   in  Cons
+          ((xb /= yb) /=
+             case (inUpperHalfplane xs,
+                   inUpperHalfplane ys,
+                   inUpperHalfplane zs) of
+                (True,True,False) -> True
+                (False,False,True) -> True
+                _ -> False)
+          zs
+
+mulAlt (Cons xb xs) (Cons yb ys) =
+   let zs = xs*ys
+   in  Cons
+          ((xb /= yb) /=
+             let xi = Complex.imag xs
+                 yi = Complex.imag ys
+                 zi = Complex.imag zs
+             in  (xi>=zero) /= (yi>=zero) &&
+                 (xi>=zero) /= (zi>=zero))
+          zs
+
+mulAlt2 (Cons xb xs) (Cons yb ys) =
+   let zs = xs*ys
+   in  Cons
+          ((xb /= yb) /=
+             let xi = Complex.imag xs
+                 yi = Complex.imag ys
+                 zi = Complex.imag zs
+             in  xi*yi<zero && xi*zi<zero)
+          zs
+
+div :: (RealField.C a) => T a -> T a -> T a
+div x y = mul x (recip y)
+
+recip :: (RealField.C a) => T a -> T a
+recip (Cons b s) =
+   Cons
+      (b /= (Complex.imag s == zero && Complex.real s < zero))
+      (NP.recip s)
diff --git a/src/Algebra/Absolute.hs b/src/Algebra/Absolute.hs
--- a/src/Algebra/Absolute.hs
+++ b/src/Algebra/Absolute.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Absolute (
    C(abs, signum),
    absOrd, signumOrd,
@@ -7,7 +7,7 @@
 import qualified Algebra.Ring         as Ring
 import qualified Algebra.Additive     as Additive
 
-import Algebra.Ring (one, ) -- fromInteger
+import Algebra.Ring (one, )
 import Algebra.Additive (zero, negate,)
 
 import Data.Int  (Int,  Int8,  Int16,  Int32,  Int64,  )
diff --git a/src/Algebra/Additive.hs b/src/Algebra/Additive.hs
--- a/src/Algebra/Additive.hs
+++ b/src/Algebra/Additive.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Additive (
     -- * Class
     C,
@@ -32,12 +32,19 @@
 import Data.Tuple.HT (fst3, snd3, thd3, )
 import qualified Data.List.Match as Match
 
+import qualified Data.Complex as Complex98
 import qualified Data.Ratio as Ratio98
 import qualified Prelude as P
 import Prelude (Integer, Float, Double, fromInteger, )
 import NumericPrelude.Base
 
 
+{- $setup
+>>> import qualified Algebra.Additive as A
+>>> import qualified Test.QuickCheck as QC
+-}
+
+
 infixl 6  +, -
 
 {- |
@@ -57,6 +64,7 @@
 -}
 
 class C a where
+    {-# MINIMAL zero, (+), ((-) | negate) #-}
     -- | zero element of the vector space
     zero     :: a
     -- | add and subtract elements
@@ -95,6 +103,9 @@
 Sum up all elements of a non-empty list.
 This avoids including a zero which is useful for types
 where no universal zero is available.
+ToDo: Should have NonEmpty type.
+
+prop> \(QC.NonEmpty ns) -> A.sum ns == (A.sum1 ns :: Integer)
 -}
 sum1 :: (C a) => [a] -> a
 sum1 = foldl1 (+)
@@ -106,19 +117,23 @@
 Does this have a measurably effect on speed?
 
 Requires associativity.
+
+prop> \ns -> A.sum ns == (A.sumNestedAssociative ns :: Integer)
 -}
 sumNestedAssociative :: (C a) => [a] -> a
 sumNestedAssociative [] = zero
 sumNestedAssociative [x] = x
 sumNestedAssociative xs = sumNestedAssociative (sum2 xs)
 
-{-
+{- |
 Make sure that the last entries in the list
 are equally often part of an addition.
 Maybe this can reduce rounding errors.
 The list that sum2 computes is a breadth-first-flattened binary tree.
 
 Requires associativity and commutativity.
+
+prop> \ns -> A.sum ns == (A.sumNestedCommutative ns :: Integer)
 -}
 sumNestedCommutative :: (C a) => [a] -> a
 sumNestedCommutative [] = zero
@@ -363,6 +378,13 @@
    negate = Elem.run  $ pure (,,) <*>.-$ fst3 <*>.-$ snd3 <*>.-$ thd3
 
 
+{- |
+The 'Additive' instantiations treat lists
+as prefixes of infinite lists with zero filled tail.
+This interpretation is not always appropriate.
+The end of a list may just mean: End of available data.
+In this case the shortening 'zip' semantics would be more appropriate.
+-}
 instance (C v) => C [v] where
    zero   = []
    negate = map negate
@@ -405,7 +427,17 @@
    {-# INLINE negate #-}
    {-# INLINE (+) #-}
    {-# INLINE (-) #-}
-   zero                =  0
+   zero                =  P.fromInteger 0
+   (+)                 =  (P.+)
+   (-)                 =  (P.-)
+   negate              =  P.negate
+
+instance (P.RealFloat a) => C (Complex98.Complex a) where
+   {-# INLINE zero #-}
+   {-# INLINE negate #-}
+   {-# INLINE (+) #-}
+   {-# INLINE (-) #-}
+   zero                =  P.fromInteger 0
    (+)                 =  (P.+)
    (-)                 =  (P.-)
    negate              =  P.negate
diff --git a/src/Algebra/Algebraic.hs b/src/Algebra/Algebraic.hs
--- a/src/Algebra/Algebraic.hs
+++ b/src/Algebra/Algebraic.hs
@@ -1,8 +1,7 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Algebraic where
 
 import qualified Algebra.Field as Field
--- import qualified Algebra.Units as Units
 import qualified Algebra.Laws as Laws
 import qualified Algebra.ToRational as ToRational
 import qualified Algebra.ToInteger  as ToInteger
@@ -21,6 +20,7 @@
 {- | Minimal implementation: 'root' or '(^\/)'. -}
 
 class (Field.C a) => C a where
+    {-# MINIMAL root | (^/) #-}
     sqrt :: a -> a
     sqrt = root 2
     -- sqrt x  =  x ** (1/2)
diff --git a/src/Algebra/Differential.hs b/src/Algebra/Differential.hs
--- a/src/Algebra/Differential.hs
+++ b/src/Algebra/Differential.hs
@@ -1,10 +1,8 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Differential where
 
 import qualified Algebra.Ring as Ring
 
--- import NumericPrelude.Numeric
--- import qualified Prelude
 
 {- |
 'differentiate' is a general differentation operation
diff --git a/src/Algebra/DimensionTerm.hs b/src/Algebra/DimensionTerm.hs
--- a/src/Algebra/DimensionTerm.hs
+++ b/src/Algebra/DimensionTerm.hs
@@ -1,12 +1,4 @@
 {- |
-Copyright   :  (c) Henning Thielemann 2008
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  portable
-
-
 We already have the dynamically checked physical units
 provided by "Number.Physical"
 and the statically checked ones of the @dimensional@ package of Buckwalter,
diff --git a/src/Algebra/DivisibleSpace.hs b/src/Algebra/DivisibleSpace.hs
--- a/src/Algebra/DivisibleSpace.hs
+++ b/src/Algebra/DivisibleSpace.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 module Algebra.DivisibleSpace where
diff --git a/src/Algebra/Field.hs b/src/Algebra/Field.hs
--- a/src/Algebra/Field.hs
+++ b/src/Algebra/Field.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Field (
     {- * Class -}
     C,
@@ -16,12 +16,11 @@
 
 import Number.Ratio (T((:%)), Rational, (%), numerator, denominator, )
 import qualified Number.Ratio as Ratio
+import qualified Data.Complex as Complex98
 import qualified Data.Ratio as Ratio98
 import qualified Algebra.PrincipalIdealDomain as PID
-import qualified Algebra.Units as Unit
 
 import qualified Algebra.Ring         as Ring
--- import qualified Algebra.Additive     as Additive
 import qualified Algebra.ZeroTestable as ZeroTestable
 
 import Algebra.Ring ((*), (^), one, fromInteger)
@@ -69,6 +68,7 @@
 -}
 
 class (Ring.C a) => C a where
+    {-# MINIMAL recip | (/) #-}
     (/)           :: a -> a -> a
     recip         :: a -> a
     fromRational' :: Rational -> a
@@ -136,10 +136,7 @@
 
     recip (x:%y)         =  (y:%x)
 -}
-    recip (x:%y)         =
-       if isZero y
-         then error "Ratio./: division by zero"
-         else (y * Unit.stdUnitInv x) :% Unit.stdAssociate x
+    recip = Ratio.recip
     fromRational' (x:%y) =  fromInteger x % fromInteger y
 
 
@@ -155,6 +152,12 @@
 -- legacy
 
 instance (P.Integral a) => C (Ratio98.Ratio a) where
+    {-# INLINE (/) #-}
+    {-# INLINE recip #-}
+    (/)    = (P./)
+    recip  = (P.recip)
+
+instance (P.RealFloat a) => C (Complex98.Complex a) where
     {-# INLINE (/) #-}
     {-# INLINE recip #-}
     (/)    = (P./)
diff --git a/src/Algebra/FloatingPoint.hs b/src/Algebra/FloatingPoint.hs
new file mode 100644
--- /dev/null
+++ b/src/Algebra/FloatingPoint.hs
@@ -0,0 +1,57 @@
+{-# LANGUAGE RebindableSyntax #-}
+module Algebra.FloatingPoint where
+
+import qualified Algebra.RealRing as RealRing
+import NumericPrelude.Base
+
+import qualified Prelude as P
+import Prelude (Int, Integer, Float, Double, )
+
+
+{- |
+Counterpart of 'Prelude.RealFloat' but with NumericPrelude superclass.
+-}
+class RealRing.C a => C a where
+   radix :: a -> Integer
+   digits :: a -> Int
+   range :: a -> (Int, Int)
+   decode :: a -> (Integer, Int)
+   encode :: Integer -> Int -> a
+   exponent :: a -> Int
+   significand :: a -> a
+   scale :: Int -> a -> a
+   isNaN :: a -> Bool
+   isInfinite :: a -> Bool
+   isDenormalized :: a -> Bool
+   isNegativeZero :: a -> Bool
+   isIEEE :: a -> Bool
+
+instance C Float where
+   radix = P.floatRadix
+   digits = P.floatDigits
+   range = P.floatRange
+   decode = P.decodeFloat
+   encode = P.encodeFloat
+   exponent = P.exponent
+   significand = P.significand
+   scale = P.scaleFloat
+   isNaN = P.isNaN
+   isInfinite = P.isInfinite
+   isDenormalized = P.isDenormalized
+   isNegativeZero = P.isNegativeZero
+   isIEEE = P.isIEEE
+
+instance C Double where
+   radix = P.floatRadix
+   digits = P.floatDigits
+   range = P.floatRange
+   decode = P.decodeFloat
+   encode = P.encodeFloat
+   exponent = P.exponent
+   significand = P.significand
+   scale = P.scaleFloat
+   isNaN = P.isNaN
+   isInfinite = P.isInfinite
+   isDenormalized = P.isDenormalized
+   isNegativeZero = P.isNegativeZero
+   isIEEE = P.isIEEE
diff --git a/src/Algebra/IntegralDomain.hs b/src/Algebra/IntegralDomain.hs
--- a/src/Algebra/IntegralDomain.hs
+++ b/src/Algebra/IntegralDomain.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.IntegralDomain (
     {- * Class -}
     C,
@@ -32,7 +32,6 @@
   ) where
 
 import qualified Algebra.Ring         as Ring
--- import qualified Algebra.Additive     as Additive
 import qualified Algebra.ZeroTestable as ZeroTestable
 
 import Algebra.Ring     ((*), fromInteger, )
@@ -52,7 +51,15 @@
 import qualified Prelude as P
 
 
+{- $setup
+>>> import Algebra.IntegralDomain (roundDown, roundUp, divUp)
+>>> import qualified Test.QuickCheck as QC
+>>> import NumericPrelude.Base as P
+>>> import NumericPrelude.Numeric as NP
+>>> import Prelude ()
+-}
 
+
 infixl 7 `div`, `mod`
 
 
@@ -95,7 +102,11 @@
 Minimal definition: 'divMod' or ('div' and 'mod')
 -}
 class (Ring.C a) => C a where
+    {-# MINIMAL divMod | (div, mod) #-}
     div, mod :: a -> a -> a
+    {- |
+    prop> \n (QC.NonZero m) -> let (q,r) = divMod n m in n == (q*m+r :: Integer)
+    -}
     divMod :: a -> a -> (a,a)
 
     {-# INLINE div #-}
@@ -183,6 +194,8 @@
 that is at most @n@.
 The parameter order is consistent with @div@ and friends,
 but maybe not useful for partial application.
+
+prop> \n (QC.NonZero m) -> div n m * m == (roundDown n m :: Integer)
 -}
 roundDown :: C a => a -> a -> a
 roundDown n m = n - mod n m
@@ -191,6 +204,10 @@
 @roundUp n m@ rounds @n@ up to the next multiple of @m@.
 That is, @roundUp n m@ is the greatest multiple of @m@
 that is at most @n@.
+
+prop> \n (QC.NonZero m) -> divUp n m * m == (roundUp n m :: Integer)
+prop> \n (QC.Positive m) -> let x = roundDown n m in  n-m < x && x <= (n :: Integer)
+prop> \n (QC.NonZero m) -> - roundDown n m == (roundUp (-n) m :: Integer)
 -}
 roundUp :: C a => a -> a -> a
 roundUp n m = n + mod (-n) m
diff --git a/src/Algebra/Lattice.hs b/src/Algebra/Lattice.hs
--- a/src/Algebra/Lattice.hs
+++ b/src/Algebra/Lattice.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Lattice (
       C(up, dn)
     , max, min, abs
diff --git a/src/Algebra/Module.hs b/src/Algebra/Module.hs
--- a/src/Algebra/Module.hs
+++ b/src/Algebra/Module.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
@@ -28,13 +28,16 @@
 import qualified NumericPrelude.Elementwise as Elem
 import Control.Applicative (Applicative(pure, (<*>)), )
 
+import qualified Data.Complex as Complex98
+import Data.Int (Int, Int8, Int16, Int32, Int64, )
+
 import Data.Function.HT (powerAssociative, )
 import Data.List (map, zipWith, )
 import Data.Tuple.HT (fst3, snd3, thd3, )
 import Data.Tuple (fst, snd, )
 
-import Prelude((.), Eq, Bool, Int, Integer, Float, Double, ($), )
--- import qualified Prelude as P
+import qualified Prelude as P
+import Prelude((.), Eq, Bool, Integer, Float, Double, ($), )
 
 
 -- Is this right?
@@ -83,6 +86,22 @@
    {-# INLINE (*>) #-}
    (*>) = (*)
 
+instance C Int8 Int8 where
+   {-# INLINE (*>) #-}
+   (*>) = (*)
+
+instance C Int16 Int16 where
+   {-# INLINE (*>) #-}
+   (*>) = (*)
+
+instance C Int32 Int32 where
+   {-# INLINE (*>) #-}
+   (*>) = (*)
+
+instance C Int64 Int64 where
+   {-# INLINE (*>) #-}
+   (*>) = (*)
+
 instance C Integer Integer where
    {-# INLINE (*>) #-}
    (*>) = (*)
@@ -116,6 +135,11 @@
 instance (C a v) => C a (c -> v) where
    {-# INLINE (*>) #-}
    (*>) s f = (*>) s . f
+
+
+instance (C a b, P.RealFloat b) => C a (Complex98.Complex b) where
+   {-# INLINE (*>) #-}
+   s *> (x Complex98.:+ y)  =  (s *> x) Complex98.:+ (s *> y)
 
 
 {-* Related functions -}
diff --git a/src/Algebra/ModuleBasis.hs b/src/Algebra/ModuleBasis.hs
--- a/src/Algebra/ModuleBasis.hs
+++ b/src/Algebra/ModuleBasis.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
@@ -15,14 +15,12 @@
 
 import qualified Algebra.PrincipalIdealDomain as PID
 import qualified Algebra.Module   as Module
--- import qualified Algebra.Additive as Additive
 import Algebra.Ring     (one, fromInteger)
 import Algebra.Additive ((+), zero)
 
 import Data.List (map, length, (++))
 
 import Prelude(Eq, (==), Bool, Int, Integer, Float, Double, asTypeOf, )
--- import qualified Prelude as P
 
 {- |
 It must hold:
diff --git a/src/Algebra/Monoid.hs b/src/Algebra/Monoid.hs
--- a/src/Algebra/Monoid.hs
+++ b/src/Algebra/Monoid.hs
@@ -18,6 +18,11 @@
 
 import Data.Monoid as Mn
 
+import Data.Function ((.))
+import Data.List (foldr, reverse, map)
+import Prelude ()
+
+
 {- |
 We expect a monoid to adher to associativity and
 the identity behaving decently.
diff --git a/src/Algebra/NonNegative.hs b/src/Algebra/NonNegative.hs
--- a/src/Algebra/NonNegative.hs
+++ b/src/Algebra/NonNegative.hs
@@ -25,11 +25,9 @@
    ) where
 
 import qualified Algebra.Additive as Additive
--- import qualified Algebra.RealRing as RealRing
 
 import qualified Algebra.Monoid as Monoid
 
--- import Algebra.Absolute (abs, )
 import Algebra.Additive ((-), )
 
 import Prelude hiding (sum, (-), abs, )
diff --git a/src/Algebra/NormedSpace/Euclidean.hs b/src/Algebra/NormedSpace/Euclidean.hs
--- a/src/Algebra/NormedSpace/Euclidean.hs
+++ b/src/Algebra/NormedSpace/Euclidean.hs
@@ -1,15 +1,8 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
 {- |
-Copyright   :  (c) Henning Thielemann 2005-2010
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  requires multi-parameter type classes
-
 Abstraction of normed vector spaces
 -}
 
@@ -17,6 +10,7 @@
 
 import NumericPrelude.Base
 import NumericPrelude.Numeric (sqr, abs, zero, (+), sum, Float, Double, Int, Integer, )
+import qualified Prelude as P
 
 import qualified Number.Ratio as Ratio
 
@@ -25,6 +19,7 @@
 import qualified Algebra.Absolute      as Absolute
 import qualified Algebra.Module    as Module
 
+import qualified Data.Complex as Complex98
 import qualified Data.Foldable as Fold
 
 
@@ -123,4 +118,13 @@
   normSqr = sum . map normSqr
 
 instance (Algebraic.C a, Sqr a v) => C a [v] where
+  norm    = defltNorm
+
+
+instance (Sqr a v, P.RealFloat v) => Sqr a (Complex98.Complex v) where
+  normSqr (x0 Complex98.:+ x1) = normSqr x0 + normSqr x1
+
+instance
+  (Algebraic.C a, Sqr a v, P.RealFloat v) =>
+    C a (Complex98.Complex v) where
   norm    = defltNorm
diff --git a/src/Algebra/NormedSpace/Maximum.hs b/src/Algebra/NormedSpace/Maximum.hs
--- a/src/Algebra/NormedSpace/Maximum.hs
+++ b/src/Algebra/NormedSpace/Maximum.hs
@@ -1,15 +1,8 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
 {- |
-Copyright   :  (c) Henning Thielemann 2005-2010
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  requires multi-parameter type classes
-
 Abstraction of normed vector spaces
 -}
 
@@ -17,6 +10,7 @@
 
 import NumericPrelude.Base
 import NumericPrelude.Numeric
+import qualified Prelude as P
 
 import qualified Number.Ratio as Ratio
 
@@ -25,6 +19,7 @@
 import qualified Algebra.RealRing as RealRing
 import qualified Algebra.Module   as Module
 
+import qualified Data.Complex as Complex98
 import qualified Data.Foldable as Fold
 
 
@@ -83,3 +78,7 @@
 we can use zero as identity element.
   norm = maximum . map norm
 -}
+
+
+instance (C a v, P.RealFloat v) => C a (Complex98.Complex v) where
+  norm (x0 Complex98.:+ x1) = max (norm x0) (norm x1)
diff --git a/src/Algebra/NormedSpace/Sum.hs b/src/Algebra/NormedSpace/Sum.hs
--- a/src/Algebra/NormedSpace/Sum.hs
+++ b/src/Algebra/NormedSpace/Sum.hs
@@ -1,15 +1,8 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
 {- |
-Copyright   :  (c) Henning Thielemann 2005-2010
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  requires multi-parameter type classes
-
 Abstraction of normed vector spaces
 -}
 
@@ -17,6 +10,7 @@
 
 import NumericPrelude.Base
 import NumericPrelude.Numeric
+import qualified Prelude as P
 
 import qualified Number.Ratio as Ratio
 
@@ -25,6 +19,7 @@
 import qualified Algebra.Additive as Additive
 import qualified Algebra.Module   as Module
 
+import qualified Data.Complex as Complex98
 import qualified Data.Foldable as Fold
 
 
@@ -88,3 +83,7 @@
 
 instance (Additive.C a, C a v) => C a [v] where
   norm = sum . map norm
+
+
+instance (C a v, P.RealFloat v) => C a (Complex98.Complex v) where
+  norm (x0 Complex98.:+ x1) = norm x0 + norm x1
diff --git a/src/Algebra/OccasionallyScalar.hs b/src/Algebra/OccasionallyScalar.hs
--- a/src/Algebra/OccasionallyScalar.hs
+++ b/src/Algebra/OccasionallyScalar.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
@@ -27,15 +27,8 @@
 
 module Algebra.OccasionallyScalar where
 
--- import qualified Algebra.RealRing    as RealRing
-import qualified Algebra.ZeroTestable as ZeroTestable
-import qualified Algebra.Additive     as Additive
-import qualified Number.Complex       as Complex
-
 import Data.Maybe (fromMaybe, )
 
-import Number.Complex((+:))
-
 import NumericPrelude.Base
 import NumericPrelude.Numeric
 
@@ -66,14 +59,6 @@
    toScalar      = id
    toMaybeScalar = Just
    fromScalar    = id
-
--- this instance should be defined in Number.Complex
-instance (Show v, ZeroTestable.C v, Additive.C v, C a v) => C a (Complex.T v) where
-   toScalar        = toScalarShow
-   toMaybeScalar x = if isZero (Complex.imag x)
-                       then toMaybeScalar (Complex.real x)
-                       else Nothing
-   fromScalar x    = fromScalar x +: zero
 
 {- converting values automatically to integers is a bad idea
 instance (Integral b, RealRing.C a)
diff --git a/src/Algebra/PrincipalIdealDomain.hs b/src/Algebra/PrincipalIdealDomain.hs
--- a/src/Algebra/PrincipalIdealDomain.hs
+++ b/src/Algebra/PrincipalIdealDomain.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.PrincipalIdealDomain (
     {- * Class -}
     C,
@@ -39,8 +39,6 @@
 
 import qualified Algebra.Units          as Units
 import qualified Algebra.IntegralDomain as Integral
--- import qualified Algebra.Ring           as Ring
--- import qualified Algebra.Additive       as Additive
 import qualified Algebra.ZeroTestable   as ZeroTestable
 
 import qualified Algebra.Laws as Laws
@@ -63,7 +61,19 @@
 import Test.QuickCheck ((==>), Property)
 
 
+{- $setup
+>>> import qualified Algebra.PrincipalIdealDomain as PID
+>>> import Test.NumericPrelude.Utility ((/\))
+>>> import qualified Test.QuickCheck as QC
+>>>
+>>> genResidueClass :: QC.Gen (Integer,Integer)
+>>> genResidueClass = do
+>>>    m <- fmap QC.getNonZero $ QC.arbitrary
+>>>    a <- QC.choose (min 0 $ 1+m, max 0 $ m-1)
+>>>    return (m,a)
+-}
 
+
 {- |
 A principal ideal domain is a ring in which every ideal
 (the set of multiples of some generating set of elements)
@@ -235,9 +245,9 @@
 
 {- |
 Not efficient because it requires duplicate computations of GCDs.
-However GCDs of neighbouring list elements were not computed before.
+However GCDs of adjacent list elements were not computed before.
 It is also quite arbitrary,
-because only neighbouring elements are used for balancing.
+because only adjacent elements are used for balancing.
 There are certainly more sophisticated solutions.
 -}
 diophantineMultiMin :: C a => a -> [a] -> Maybe [a]
@@ -279,10 +289,21 @@
 -}
 
 {- |
-For @Just (b,n) = chineseRemainder [(a0,m0), (a1,m1), ..., (an,mn)]@
-and all @x@ with @x = b mod n@ the congruences
-@x=a0 mod m0, x=a1 mod m1, ..., x=an mod mn@
+For @Just (n,b) = chineseRemainderMulti [(m0,a0), (m1,a1), ..., (mk,ak)]@
+and all @x@ with @x = b mod n@, the congruences
+@x=a0 mod m0, x=a1 mod m1, ..., x=ak mod mk@
 are fulfilled.
+Also, @n@ is the least common multiplier of all @mi@.
+
+>>> PID.chineseRemainderMulti [(100,21), (10000,2021::Integer)]
+Just (10000,2021)
+>>> PID.chineseRemainderMulti [(97,90),(99,10),(100,0::Integer)]
+Just (960300,100000)
+>>> PID.chineseRemainderMulti [(95,30),(97,27),(98,8),(99,1::Integer)]
+Just (89403930,1000000)
+
+prop> QC.listOf genResidueClass /\ \xs -> case PID.chineseRemainderMulti xs of Nothing -> True; Just (n,b) -> abs n == abs (foldl lcm 1 (map fst xs)) && map snd xs == map (mod b . fst) xs
+prop> \(QC.NonEmpty ms) b -> let xs = map (\(QC.NonZero m) -> (m, mod b m)) ms in case PID.chineseRemainderMulti xs of Nothing -> False; Just (n,c) -> abs n == abs (foldl lcm 1 (map QC.getNonZero ms)) && mod b n == (c::Integer)
 -}
 chineseRemainderMulti :: C a => [(a,a)] -> Maybe (a,a)
 chineseRemainderMulti congs =
diff --git a/src/Algebra/RealField.hs b/src/Algebra/RealField.hs
--- a/src/Algebra/RealField.hs
+++ b/src/Algebra/RealField.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.RealField (
    C,
    ) where
@@ -10,8 +10,6 @@
 
 import qualified Number.Ratio as Ratio
 
--- import NumericPrelude.Base
--- import qualified Prelude as P
 import Prelude (Float, Double, )
 
 {- |
diff --git a/src/Algebra/RealIntegral.hs b/src/Algebra/RealIntegral.hs
--- a/src/Algebra/RealIntegral.hs
+++ b/src/Algebra/RealIntegral.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Generally before using 'quot' and 'rem', think twice.
 In most cases 'divMod' and friends are the right choice,
@@ -19,8 +19,6 @@
 import qualified Algebra.ZeroTestable   as ZeroTestable
 import qualified Algebra.IntegralDomain as Integral
 import qualified Algebra.Absolute       as Absolute
--- import qualified Algebra.Ring           as Ring
--- import qualified Algebra.Additive       as Additive
 
 import Algebra.Absolute (signum, )
 import Algebra.IntegralDomain (divMod, )
diff --git a/src/Algebra/RealRing.hs b/src/Algebra/RealRing.hs
--- a/src/Algebra/RealRing.hs
+++ b/src/Algebra/RealRing.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.RealRing where
 
 import qualified Algebra.RealRing98 as RealRing98
@@ -35,6 +35,20 @@
 import NumericPrelude.Base
 
 
+{- $setup
+>>> import qualified Algebra.RealRing as RealRing
+>>> import Data.Tuple.HT (mapFst)
+>>> import NumericPrelude.Numeric as NP
+>>> import NumericPrelude.Base
+>>> import Prelude ()
+>>>
+>>> infix 4 =~=
+>>>
+>>> (=~=) :: (Eq b) => (a -> b) -> (a -> b) -> a -> Bool
+>>> (f =~= g) x = f x == g x
+-}
+
+
 {- |
 Minimal complete definition:
      'splitFraction' or 'floor'
@@ -115,8 +129,24 @@
 -}
 
 class (Absolute.C a, Ord a) => C a where
+    {-# MINIMAL splitFraction | floor #-}
+    {- |
+    prop> \x -> (x::Rational) == (uncurry (+) $ mapFst fromInteger $ splitFraction x)
+    prop> \x -> uncurry (==) $ mapFst (((x::Double)-) . fromInteger) $ splitFraction x
+    prop> \x -> uncurry (==) $ mapFst (((x::Rational)-) . fromInteger) $ splitFraction x
+    prop> \x -> splitFraction x == (floor (x::Double) :: Integer, fraction x)
+    prop> \x -> splitFraction x == (floor (x::Rational) :: Integer, fraction x)
+    -}
     splitFraction    :: (Ring.C b) => a -> (b,a)
-    fraction         ::               a -> a
+    {- |
+    prop> \x -> let y = fraction (x::Double) in 0<=y && y<1
+    prop> \x -> let y = fraction (x::Rational) in 0<=y && y<1
+    -}
+    fraction :: a -> a
+    {- |
+    prop> \x -> ceiling (-x) == negate (floor (x::Double) :: Integer)
+    prop> \x -> ceiling (-x) == negate (floor (x::Rational) :: Integer)
+    -}
     ceiling, floor   :: (Ring.C b) => a -> b
     truncate         :: (Ring.C b) => a -> b
     round            :: (ToInteger.C b) => a -> b
@@ -156,6 +186,7 @@
 but is simply a kind of rounding that is the fastest
 on IEEE floating point architectures.
 -}
+{-# NOINLINE [2] roundSimple #-}
 roundSimple :: (C a, Ring.C b) => a -> b
 roundSimple x =
    let (n,r) = splitFraction x
@@ -169,6 +200,20 @@
     splitFraction (x:%y) = (fromIntegral q, r:%y)
                                where (q,r) = divMod x y
 
+instance C Integer where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromInteger x, zero)
+    fraction      _ = zero
+    floor         x = fromInteger x
+    ceiling       x = fromInteger x
+    round         x = fromInteger x
+    truncate      x = fromInteger x
+
 instance C Int where
     {-# INLINE splitFraction #-}
     {-# INLINE fraction #-}
@@ -183,20 +228,118 @@
     round         x = fromIntegral x
     truncate      x = fromIntegral x
 
-instance C Integer where
+instance C Int8 where
     {-# INLINE splitFraction #-}
     {-# INLINE fraction #-}
     {-# INLINE floor #-}
     {-# INLINE ceiling #-}
     {-# INLINE round #-}
     {-# INLINE truncate #-}
-    splitFraction x = (fromInteger x, zero)
+    splitFraction x = (fromIntegral x, zero)
     fraction      _ = zero
-    floor         x = fromInteger x
-    ceiling       x = fromInteger x
-    round         x = fromInteger x
-    truncate      x = fromInteger x
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
 
+instance C Int16 where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromIntegral x, zero)
+    fraction      _ = zero
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
+
+instance C Int32 where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromIntegral x, zero)
+    fraction      _ = zero
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
+
+instance C Int64 where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromIntegral x, zero)
+    fraction      _ = zero
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
+
+instance C Word8 where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromIntegral x, zero)
+    fraction      _ = zero
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
+
+instance C Word16 where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromIntegral x, zero)
+    fraction      _ = zero
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
+
+instance C Word32 where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromIntegral x, zero)
+    fraction      _ = zero
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
+
+instance C Word64 where
+    {-# INLINE splitFraction #-}
+    {-# INLINE fraction #-}
+    {-# INLINE floor #-}
+    {-# INLINE ceiling #-}
+    {-# INLINE round #-}
+    {-# INLINE truncate #-}
+    splitFraction x = (fromIntegral x, zero)
+    fraction      _ = zero
+    floor         x = fromIntegral x
+    ceiling       x = fromIntegral x
+    round         x = fromIntegral x
+    truncate      x = fromIntegral x
+
 instance C Float where
     {-# INLINE splitFraction #-}
     {-# INLINE fraction #-}
@@ -417,6 +560,9 @@
 If operations like multiplication with two and comparison
 need time proportional to the number of binary digits,
 then the overall rounding requires quadratic time.
+
+prop> RealRing.genericFloor =~= (NP.floor :: Double -> Integer)
+prop> RealRing.genericFloor =~= (NP.floor :: Rational -> Integer)
 -}
 genericFloor :: (Ord a, Ring.C a, Ring.C b) => a -> b
 genericFloor a =
@@ -424,30 +570,50 @@
      then genericPosFloor a
      else negate $ genericPosCeiling $ negate a
 
+{- |
+prop> RealRing.genericCeiling =~= (NP.ceiling :: Double -> Integer)
+prop> RealRing.genericCeiling =~= (NP.ceiling :: Rational -> Integer)
+-}
 genericCeiling :: (Ord a, Ring.C a, Ring.C b) => a -> b
 genericCeiling a =
    if a>=zero
      then genericPosCeiling a
      else negate $ genericPosFloor $ negate a
 
+{- |
+prop> RealRing.genericTruncate =~= (NP.truncate :: Double -> Integer)
+prop> RealRing.genericTruncate =~= (NP.truncate :: Rational -> Integer)
+-}
 genericTruncate :: (Ord a, Ring.C a, Ring.C b) => a -> b
 genericTruncate a =
    if a>=zero
      then genericPosFloor a
      else negate $ genericPosFloor $ negate a
 
+{- |
+prop> RealRing.genericRound =~= (NP.round :: Double -> Integer)
+prop> RealRing.genericRound =~= (NP.round :: Rational -> Integer)
+-}
 genericRound :: (Ord a, Ring.C a, Ring.C b) => a -> b
 genericRound a =
    if a>=zero
      then genericPosRound a
      else negate $ genericPosRound $ negate a
 
+{- |
+prop> RealRing.genericFraction =~= (NP.fraction :: Double -> Double)
+prop> RealRing.genericFraction =~= (NP.fraction :: Rational -> Rational)
+-}
 genericFraction :: (Ord a, Ring.C a) => a -> a
 genericFraction a =
    if a>=zero
      then genericPosFraction a
      else fixFraction $ negate $ genericPosFraction $ negate a
 
+{- |
+prop> RealRing.genericSplitFraction =~= (NP.splitFraction :: Double -> (Integer,Double))
+prop> RealRing.genericSplitFraction =~= (NP.splitFraction :: Rational -> (Integer,Rational))
+-}
 genericSplitFraction :: (Ord a, Ring.C a, Ring.C b) => a -> (b,a)
 genericSplitFraction a =
    if a>=zero
diff --git a/src/Algebra/RealTranscendental.hs b/src/Algebra/RealTranscendental.hs
--- a/src/Algebra/RealTranscendental.hs
+++ b/src/Algebra/RealTranscendental.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.RealTranscendental where
 
 import qualified Algebra.Transcendental      as Trans
diff --git a/src/Algebra/RightModule.hs b/src/Algebra/RightModule.hs
--- a/src/Algebra/RightModule.hs
+++ b/src/Algebra/RightModule.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 module Algebra.RightModule where
@@ -6,8 +6,6 @@
 import qualified Algebra.Ring     as Ring
 import qualified Algebra.Additive as Additive
 
--- import NumericPrelude.Numeric
--- import qualified Prelude
 
 
 -- Is this right?
diff --git a/src/Algebra/Ring.hs b/src/Algebra/Ring.hs
--- a/src/Algebra/Ring.hs
+++ b/src/Algebra/Ring.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Ring (
     {- * Class -}
     C,
@@ -38,9 +38,9 @@
 
 import NumericPrelude.Base
 import Prelude (Integer, Float, Double, )
+import qualified Data.Complex as Complex98
 import qualified Data.Ratio as Ratio98
 import qualified Prelude as P
--- import Test.QuickCheck
 
 
 infixl 7 *
@@ -64,6 +64,7 @@
 -}
 
 class (Additive.C a) => C a where
+    {-# MINIMAL (*), (one | fromInteger) #-}
     (*)         :: a -> a -> a
     one         :: a
     fromInteger :: Integer -> a
@@ -252,6 +253,14 @@
    {-# INLINE one #-}
    {-# INLINE fromInteger #-}
    {-# INLINE (*) #-}
-   one                 =  1
+   one                 =  P.fromInteger 1
+   fromInteger         =  P.fromInteger
+   (*)                 =  (P.*)
+
+instance (P.RealFloat a) => C (Complex98.Complex a) where
+   {-# INLINE one #-}
+   {-# INLINE fromInteger #-}
+   {-# INLINE (*) #-}
+   one                 =  P.fromInteger 1
    fromInteger         =  P.fromInteger
    (*)                 =  (P.*)
diff --git a/src/Algebra/ToInteger.hs b/src/Algebra/ToInteger.hs
--- a/src/Algebra/ToInteger.hs
+++ b/src/Algebra/ToInteger.hs
@@ -49,6 +49,7 @@
    toInteger :: a -> Integer
 
 
+{-# NOINLINE [2] fromIntegral #-}
 fromIntegral :: (C a, Ring.C b) => a -> b
 fromIntegral = fromInteger . toInteger
 
diff --git a/src/Algebra/ToRational.hs b/src/Algebra/ToRational.hs
--- a/src/Algebra/ToRational.hs
+++ b/src/Algebra/ToRational.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.ToRational where
 
 import qualified Algebra.ZeroTestable as ZeroTestable
@@ -68,6 +68,7 @@
 such as converting 'Float' to 'Double'.
 This achieved by optimizer rules.
 -}
+{-# NOINLINE [2] realToField #-}
 realToField :: (C a, Field.C b) => a -> b
 realToField = Field.fromRational' . toRational
 
diff --git a/src/Algebra/Transcendental.hs b/src/Algebra/Transcendental.hs
--- a/src/Algebra/Transcendental.hs
+++ b/src/Algebra/Transcendental.hs
@@ -1,9 +1,7 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Transcendental where
 
 import qualified Algebra.Algebraic as Algebraic
--- import qualified Algebra.Ring      as Ring
--- import qualified Algebra.Additive  as Additive
 
 import qualified Algebra.Laws as Laws
 
@@ -31,9 +29,10 @@
 branch cuts, etc.
 
 Minimal complete definition:
-     pi, exp, log, sin, cos, asin, acos, atan
+     pi, exp, (log or logBase), sin, cos, atan
 -}
 class (Algebraic.C a) => C a where
+    {-# MINIMAL pi, exp, (log | logBase), sin, cos, atan #-}
     pi                  :: a
     exp, log            :: a -> a
     logBase, (**)       :: a -> a -> a
@@ -56,6 +55,7 @@
 
     x ** y           =  exp (log x * y)
     logBase x y      =  log y / log x
+    log              =  logBase (exp 1)
 
     tan  x           =  sin x / cos x
 
diff --git a/src/Algebra/Units.hs b/src/Algebra/Units.hs
--- a/src/Algebra/Units.hs
+++ b/src/Algebra/Units.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.Units (
     {- * Class -}
     C,
@@ -22,7 +22,6 @@
 
 import qualified Algebra.IntegralDomain as Integral
 import qualified Algebra.Ring           as Ring
--- import qualified Algebra.Additive       as Additive
 import qualified Algebra.ZeroTestable   as ZeroTestable
 
 import qualified Algebra.Laws           as Laws
@@ -70,6 +69,7 @@
 -}
 
 class (Integral.C a) => C a where
+  {-# MINIMAL isUnit, (stdUnit | stdUnitInv) #-}
   isUnit :: a -> Bool
   stdAssociate, stdUnit, stdUnitInv :: a -> a
 
diff --git a/src/Algebra/Vector.hs b/src/Algebra/Vector.hs
--- a/src/Algebra/Vector.hs
+++ b/src/Algebra/Vector.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright   :  (c) Henning Thielemann 2004-2005
 
@@ -18,7 +18,6 @@
 import Algebra.Additive ((+))
 
 import Data.List (zipWith, foldl)
--- import Data.Functor (Functor, fmap)
 
 import Prelude((.), (==), Bool, Functor, fmap)
 import qualified Prelude as P
diff --git a/src/Algebra/VectorSpace.hs b/src/Algebra/VectorSpace.hs
--- a/src/Algebra/VectorSpace.hs
+++ b/src/Algebra/VectorSpace.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 module Algebra.VectorSpace where
@@ -8,7 +8,8 @@
 import qualified Algebra.PrincipalIdealDomain as PID
 import qualified Number.Ratio   as Ratio
 
--- import NumericPrelude.Numeric
+import qualified Data.Complex as Complex98
+
 import qualified Prelude as P
 
 
@@ -32,3 +33,5 @@
 instance (C a b) => C a [b]
 
 instance (C a b) => C a (c -> b)
+
+instance (C a b, P.RealFloat b) => C a (Complex98.Complex b)
diff --git a/src/Algebra/ZeroTestable.hs b/src/Algebra/ZeroTestable.hs
--- a/src/Algebra/ZeroTestable.hs
+++ b/src/Algebra/ZeroTestable.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Algebra.ZeroTestable where
 
 import qualified Algebra.Additive as Additive
@@ -6,7 +6,6 @@
 import Data.Int  (Int,  Int8,  Int16,  Int32,  Int64,  )
 import Data.Word (Word, Word8, Word16, Word32, Word64, )
 
--- import qualified Prelude as P
 import Prelude (Integer, Float, Double, )
 import NumericPrelude.Base
 
diff --git a/src/MathObj/Algebra.hs b/src/MathObj/Algebra.hs
--- a/src/MathObj/Algebra.hs
+++ b/src/MathObj/Algebra.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright    :   (c) Mikael Johansson 2006
 Maintainer   :   mik@math.uni-jena.de
diff --git a/src/MathObj/DiscreteMap.hs b/src/MathObj/DiscreteMap.hs
--- a/src/MathObj/DiscreteMap.hs
+++ b/src/MathObj/DiscreteMap.hs
@@ -1,5 +1,5 @@
 {-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
@@ -41,7 +41,6 @@
 import qualified Data.Map as Map
 import Data.Map (Map)
 
--- import qualified Prelude as P
 import NumericPrelude.Base
 
 -- FIXME: Should this be implemented by isZero?
diff --git a/src/MathObj/Gaussian/Bell.hs b/src/MathObj/Gaussian/Bell.hs
deleted file mode 100644
--- a/src/MathObj/Gaussian/Bell.hs
+++ /dev/null
@@ -1,324 +0,0 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-
-Complex translated and modulated Gaussian bell curve.
-
-It could be extended to chirps
-using a complex valued quadratic term with (real c >= 0).
-This allows for a new test:
-Express the Fourier transform in terms of a convolution with a chirp.
--}
-module MathObj.Gaussian.Bell where
-
-import qualified MathObj.Polynomial as Poly
-import qualified Number.Complex as Complex
-
-import qualified Algebra.Transcendental as Trans
-import qualified Algebra.Field          as Field
-import qualified Algebra.Absolute       as Absolute
-import qualified Algebra.Ring           as Ring
-import qualified Algebra.Additive       as Additive
-
-import Number.Complex ((+:), )
-
-import Test.QuickCheck (Arbitrary, arbitrary, )
-import Control.Monad (liftM4, )
-
--- import Prelude (($))
-import NumericPrelude.Numeric
-import NumericPrelude.Base hiding (reverse, )
-
-
-data T a = Cons {amp :: a, c0, c1 :: Complex.T a, c2 :: a}
-   deriving (Eq, Show)
-
-instance (Absolute.C a, Arbitrary a) => Arbitrary (T a) where
-   arbitrary =
-      liftM4
-         (\k a b c -> Cons (abs k) a b (1 + abs c))
-         arbitrary arbitrary arbitrary arbitrary
-
-
-constant :: Ring.C a => T a
-constant = Cons one zero zero zero
-
-{- |
-eigenfunction of 'fourier'
--}
-unit :: Ring.C a => T a
-unit = Cons one zero zero one
-
-{-# INLINE evaluate #-}
-evaluate :: (Trans.C a) =>
-   T a -> a -> Complex.T a
-evaluate f x =
-   Complex.scale
-     (sqrt (amp f))
-     (Complex.exp $ Complex.scale (-pi) $
-      c0 f + Complex.scale x (c1 f) + Complex.fromReal (c2 f * x^2))
-
-evaluateSqRt :: (Trans.C a) =>
-   T a -> a -> Complex.T a
-evaluateSqRt f x0 =
-   Complex.scale
-     (sqrt (amp f))
-     (let x = sqrt pi * x0
-      in  Complex.exp $ negate $
-          c0 f + Complex.scale x (c1 f) + Complex.fromReal (c2 f * x^2))
-
-exponentPolynomial :: (Additive.C a) =>
-   T a -> Poly.T (Complex.T a)
-exponentPolynomial f =
-   Poly.fromCoeffs [c0 f, c1 f, Complex.fromReal (c2 f)]
-
-
-{-
-norm functions depend on interpretation
-and would have to return both a rational and transcendental part
-expressed as @exp a@.
--}
-
-variance :: (Trans.C a) =>
-   T a -> a
-variance f =
-   recip $ c2 f * 2*pi
-
-multiply :: (Ring.C a) =>
-   T a -> T a -> T a
-multiply f g =
-   Cons
-      (amp f * amp g)
-      (c0 f + c0 g) (c1 f + c1 g) (c2 f + c2 g)
-
-powerRing :: (Trans.C a) =>
-   Integer -> T a -> T a
-powerRing p f =
-   let pa = fromInteger p
-   in  Cons
-          (amp f ^ p)
-          (pa * c0 f) (pa * c1 f) (fromInteger p * c2 f)
-
-{-
-powerField does not makes sense,
-since the reciprocal of a Gaussian diverges.
--}
-
-powerAlgebraic :: (Trans.C a) =>
-   Rational -> T a -> T a
-powerAlgebraic p f =
-   let pa = fromRational' p
-   in  Cons
-          (amp f ^/ p)
-          (pa * c0 f) (pa * c1 f) (fromRational' p * c2 f)
-
-powerTranscendental :: (Trans.C a) =>
-   a -> T a -> T a
-powerTranscendental p f =
-   Cons
-      (amp f ^? p)
-      (Complex.scale p $ c0 f) (Complex.scale p $ c1 f) (p * c2 f)
-
-
-{-
-let x=Cons 2 (1+:3) (4+:5) (7::Rational); y=Cons 7 (1+:4) (3+:2) (5::Rational)
--}
-convolve :: (Field.C a) =>
-   T a -> T a -> T a
-convolve f g =
-   let s = c2 f + c2 g
-       {-
-       fd = f1/(2*f2)
-       gd = g1/(2*g2)
-       c = f2*g2/(f2+g2)
-
-       c*(fd+gd) = (f1*g2+f2*g1)/(2*(f2+g2)) = b/2
-
-       c*(fd+gd)^2 - fd^2*f2 - gd^2*g2
-         = f2*g2*(fd+gd)^2/(f2 + g2) - (fd^2*f2 + gd^2*g2)
-         = (f2*g2*(fd+gd)^2 - (f2+g2)*(fd^2*f2+gd^2*g2)) / (f2 + g2)
-         = (2*f2*g2*fd*gd - (fd^2*f2^2+gd^2*g2^2)) / (f2 + g2)
-         = (2*f1*g1 - (f1^2+g1^2)) / (4*(f2 + g2))
-         = -(f1 - g1)^2/(4*(f2 + g2))
-       -}
-   in  Cons
-          (amp f * amp g / s)
-          (c0 f + c0 g
-              - Complex.scale (recip (4*s)) ((c1 f - c1 g)^2))
-          (Complex.scale (c2 g / s) (c1 f) +
-           Complex.scale (c2 f / s) (c1 g))
-          (c2 f * c2 g / s)
-            -- recip $ recip (c2 f) + recip (c2 g)
-{-
-   Cons
-      (c0 f + c0 g) (c1 f + c1 g)
-      (recip $ recip (c2 f) + recip (c2 g))
--}
-
-convolveByTranslation :: (Field.C a) =>
-   T a -> T a -> T a
-convolveByTranslation f0 g0 =
-   let fd = Complex.scale (recip (2 * c2 f0)) $ c1 f0
-       gd = Complex.scale (recip (2 * c2 g0)) $ c1 g0
-       f1 = translateComplex fd f0
-       g1 = translateComplex gd g0
-       s = c2 f1 + c2 g1
-   in  translateComplex (negate $ fd + gd) $
-       Cons
-          (amp f1 * amp g1 / s)
-          (c0 f1 + c0 g1) zero
-          (c2 f1 * c2 g1 / s)
-
-convolveByFourier :: (Field.C a) =>
-   T a -> T a -> T a
-convolveByFourier f g =
-   reverse $ fourier $ multiply (fourier f) (fourier g)
-
-fourier :: (Field.C a) =>
-   T a -> T a
-fourier f =
-   let a = c0 f
-       b = c1 f
-       rc = recip $ c2 f
-   in  Cons
-          (amp f * rc)
-          (Complex.scale (rc/4) (-b^2) + a)
-          (Complex.scale rc $ Complex.quarterRight b)
-          rc
-
-fourierByTranslation :: (Field.C a) =>
-   T a -> T a
-fourierByTranslation f =
-   translateComplex (Complex.scale (1/2) $ Complex.quarterLeft $ c1 f) $
-   Cons (amp f / c2 f) (c0 f) zero (recip $ c2 f)
-
-{-
-a + b*x + c*x^2
- = c*(a/c + b/c*x + x^2)
- = c*((x-b/(2*c))^2 + (4*a*c+b^2)/(4*c^2))
- = c*(x-b/(2*c))^2 + (4*a*c+b^2)/(4*c)
-
-fourier ->
-   x^2/c - i*b/c*x + (4*a*c+b^2)/(4*c)
-
-fourier (x -> exp(-pi*c*(x-t)^2))
- = fourier $ translate t $ shrink (sqrt c) $ x -> exp(-pi*x^2)
- = modulate t $ dilate (sqrt c) $ fourier $ x -> exp(-pi*x^2)
- = modulate t $ dilate (sqrt c) $ x -> exp(-pi*x^2)
- = modulate t $ x -> exp(-pi*x^2/c)
- = x -> exp(-pi*x^2/c) * exp(-2*pi*i*x*t)
- = x -> exp(-pi*(x^2/c - 2*i*x*t))
--}
-
-{-
-b*x + c*x^2
- = c*(b/c*x + x^2)
- = c*((x-br/(2*c))^2 + i*x*bi/c - br^2/(4*c^2))
- = c*(x-br/(2*c))^2 + i*x*bi - br^2/(4*c)
-
-fourier ->
-   (x+bi/2)^2/c - i*br/c*(x+bi/2) - br^2/(4*c)
- = (1/c) * ((x+bi/2)^2 - i*br*(x+bi/2) + (br/2)^2)
- = (1/c) * (x^2 - i*b*x + -(br/2)^2 + (bi/2)^2 - i*br*bi/2)
- = (1/c) * (x^2 - i*b*x - (br^2-bi^2+2*br*bi*i)^2 /4)
- = (1/c) * (x^2 - i*b*x - b^2 / 4)
- = (1/c) * (x^2 - i*b*x + (i*b/2)^2)
- = (1/c) * (x - i*b/2)^2
-
-Example:
-  (x-b)^2 = b^2 - 2*b*x + x^2
-    ->  (- i*2*b*x + x^2)
-
-
-fourier (x -> exp(-pi*(c*(x-t)^2 + 2*i*m*x)))
- = fourier $ modulate m $ translate t $ shrink (sqrt c) $ x -> exp(-pi*x^2)
- = translate (-m) $ modulate t $ dilate (sqrt c) $ fourier $ x -> exp(-pi*x^2)
- = translate (-m) $ modulate t $ dilate (sqrt c) $ x -> exp(-pi*x^2)
- = translate (-m) $ modulate t $ x -> exp(-pi*x^2/c)
- = translate (-m) $ x -> exp(-pi*x^2/c) * exp(-2*pi*i*x*t)
- = x -> exp(-pi*(x+m)^2/c) * exp(-2*pi*i*(x+m)*t)
- = x -> exp(-pi*((x+m)^2/c - 2*i*(x+m)*t))
--}
-
-{-
-fourier (Cons a 0 0) =
-  Cons a 0 infinity
-
-fourier (Cons 0 0 c) =
-  Cons 0 0 (recip c)
-
-fourier (Cons 0 b 1) =
-  Cons 0 (i*b) 1
--}
-
-translate :: Ring.C a => a -> T a -> T a
-translate d f =
-   let a = c0 f
-       b = c1 f
-       c = c2 f
-   in  Cons
-          (amp f)
-          (Complex.fromReal (c*d^2) - Complex.scale d b + a)
-          (Complex.fromReal (-2*c*d) + b)
-          c
-
-translateComplex :: Ring.C a => Complex.T a -> T a -> T a
-translateComplex d f =
-   let a = c0 f
-       b = c1 f
-       c = c2 f
-   in  Cons
-          (amp f)
-          (Complex.scale c (d^2) - b*d + a)
-          (Complex.scale (-2*c) d + b)
-          c
-
-modulate :: Ring.C a => a -> T a -> T a
-modulate d f =
-   Cons
-      (amp f)
-      (c0 f)
-      (c1 f + (zero +: 2*d))
-      (c2 f)
-
-turn :: Ring.C a => a -> T a -> T a
-turn d f =
-   Cons
-      (amp f)
-      (c0 f + (zero +: 2*d))
-      (c1 f)
-      (c2 f)
-
-reverse :: Additive.C a => T a -> T a
-reverse f =
-   f{c1 = negate $ c1 f}
-
-
-dilate :: Field.C a => a -> T a -> T a
-dilate k f =
-   Cons
-      (amp f)
-      (c0 f)
-      (Complex.scale (recip k) $ c1 f)
-      (c2 f / k^2)
-
-shrink :: Ring.C a => a -> T a -> T a
-shrink k f =
-   Cons
-      (amp f)
-      (c0 f)
-      (Complex.scale k $ c1 f)
-      (c2 f * k^2)
-
-amplify :: (Ring.C a) => a -> T a -> T a
-amplify k f =
-   Cons
-      (k^2 * amp f)
-      (c0 f)
-      (c1 f)
-      (c2 f)
-
-
-{- laws
-fourier (convolve f g) = fourier f * fourier g
-
-fourier (fourier f) = reverse f
--}
diff --git a/src/MathObj/Gaussian/Example.hs b/src/MathObj/Gaussian/Example.hs
deleted file mode 100644
--- a/src/MathObj/Gaussian/Example.hs
+++ /dev/null
@@ -1,231 +0,0 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-
-Reciprocal of variance of a Gaussian bell curve.
-We describe the curve only in terms of its variance
-thus we represent a bell curve at the coordinate origin
-neglecting its amplitude.
-
-We could also define the amplitude as @root 4 c@,
-thus preserving L2 norm being one,
-but then @dilate@ and @shrink@ also include an amplification.
-
-We could do some projective geometry in the exponent
-in order to also have zero variance,
-which corresponds to the dirac impulse.
--}
-module MathObj.Gaussian.Example where
-
-import qualified MathObj.Gaussian.Polynomial as PolyBell
-import qualified MathObj.Gaussian.Bell as Bell
-import qualified MathObj.Gaussian.Variance as Var
-
-import qualified MathObj.Polynomial as Poly
-
-import qualified Algebra.Transcendental as Trans
-import qualified Algebra.Algebraic      as Algebraic
-import qualified Algebra.Field          as Field
--- import qualified Algebra.Absolute           as Absolute
-import qualified Algebra.Ring           as Ring
--- import qualified Algebra.Additive       as Additive
-
-import qualified Number.Complex as Complex
-import qualified Number.Root as Root
-
-import Algebra.Transcendental (pi, )
-import Algebra.Algebraic (root, )
-import Algebra.Ring ((*), (^), )
-
-import Number.Complex ((+:), )
-
-import qualified Numerics.Function as Func
-import qualified Numerics.Fourier as Fourier
-import qualified Numerics.Integration as Integ
-import qualified Numerics.Differentiation as Diff
-
-import qualified Graphics.Gnuplot.Simple as GP
-
-import Control.Applicative (liftA2, )
-
--- import System.Exit (ExitCode, )
-
--- import Prelude (($))
-import NumericPrelude.Numeric
-import NumericPrelude.Base
-import qualified Prelude as P
-
-
-curve0 :: Var.T Double
-curve0 = curve0a
-
-curve0a :: Var.T Double
-curve0a = Var.Cons 1.4 3.3
-
-curve0b :: Var.T Double
-curve0b = Var.Cons 2.2 1.7
-
-variance0 :: (Double, Double)
-variance0 =
-   (Var.variance curve0,
-    (Integ.rectangular 1000 (-2,2) $ liftA2 (*) (^2) (Var.evaluate curve0)) /
-    (Integ.rectangular 1000 (-2,2) $ Var.evaluate curve0))
-
-norm10 :: (Double, Double, Double)
-norm10 =
-   (Integ.rectangular 1000 (-2,2) $ Var.evaluate curve0,
-    Var.norm1 curve0,
-    Root.toNumber (Var.norm1Root curve0))
-
-norm20 :: (Double, Double, Double)
-norm20 =
-   (sqrt $ Integ.rectangular 1000 (-2,2) $ (^2) . Var.evaluate curve0,
-    Var.norm2 curve0,
-    Root.toNumber (Var.norm2Root curve0))
-
-norm30 :: (Double, Double, Double)
-norm30 =
-   (root 3 $ Integ.rectangular 1000 (-2,2) $ (^3) . Var.evaluate curve0,
-    Var.normP 3 curve0,
-    Root.toNumber (Var.normPRoot 3 curve0))
-
-fourier0 :: IO ()
-fourier0 =
-   GP.plotFuncs []
-      (GP.linearScale 100 (-2,2))
-      [Var.evaluate $ Var.fourier curve0,
-       Fourier.analysisTransformOneReal 100 (-2,2) $ Var.evaluate curve0]
-
-multiply0 :: IO ()
-multiply0 =
-   GP.plotFuncs []
-      (GP.linearScale 100 (-1,1))
-      [Var.evaluate $ Var.multiply curve0a curve0b,
-       liftA2 (*) (Var.evaluate curve0a) (Var.evaluate curve0b)]
-
-convolve0 :: IO ()
-convolve0 =
-   GP.plotFuncs []
-      (GP.linearScale 100 (-2,2))
-      [Var.evaluate $ Var.convolve curve0a curve0b,
-       Integ.convolve 1000 (-3,3) (Var.evaluate curve0a) (Var.evaluate curve0b)]
-
-
-curve1 :: Bell.T Double
-curve1 = curve1a
-
-curve1a :: Bell.T Double
-curve1a = Bell.Cons 1.4 (0.1+:0.3) ((-0.2)+:1.4) 2.3
-
-curve1b :: Bell.T Double
-curve1b = Bell.Cons 2.2 ((-0.3)+:2.1) (0.2+:(-0.4)) 1.7
-
-variance1 :: (Double, Double)
-variance1 =
-   (Bell.variance curve1,
-    (Integ.rectangular 1000 (-2,2) $
-        liftA2 (*) (^2)
-           (Complex.magnitudeSqr .
-            Func.translateRight
-               (Complex.real (Bell.c1 curve1) / (2 * Bell.c2 curve1))
-               (Bell.evaluate curve1))) /
-    (Integ.rectangular 1000 (-2,2) $ Complex.magnitude . Bell.evaluate curve1))
-
-{- the norm depends on too much things
-norm0vs1 :: (Double, Double)
-norm0vs1 =
-   ((Integ.rectangular 1000 (-5,5) $ Var.evaluate curve0)
-         * exp (- Complex.real (Bell.c0 curve1)),
-    Integ.rectangular 1000 (-5,5) $ Complex.magnitude . Bell.evaluate curve1)
--}
-
-fourier1 :: IO ()
-fourier1 =
-   GP.plotFuncs []
-      (GP.linearScale 100 (-5,5))
-      [Complex.real . (Bell.evaluate $ Bell.fourier curve1),
-       fourierAnalysisReal 100 (-2,2) $ Bell.evaluate curve1]
-
-
-curve2 :: PolyBell.T Double
-curve2 =
-   PolyBell.Cons
---      Bell.unit
---      (Bell.Cons 1.4 (0.1+:0.3) 0 1.2)
---      (Bell.Cons 1.4 (0.1+:0.3) ((-0.2)+:1.4) 1)
-      curve1
---      (Poly.fromCoeffs [one])
---      (Poly.fromCoeffs [zero,one])
---      (Poly.fromCoeffs [zero,zero,one])
---      (Poly.fromCoeffs [0,Complex.imaginaryUnit])
-      (Poly.fromCoeffs [1.4+:(-0.1),0.8+:(0.1),(-1.1)+:0.3])
-
-differentiate2 :: IO ()
-differentiate2 =
-   GP.plotFuncs []
-      (GP.linearScale 100 (-2,2))
-      [Complex.real . (PolyBell.evaluateSqRt $ PolyBell.differentiate curve2),
-       ((/ sqrt pi) . ) $ Diff.diff (1e-5) $ Complex.real . PolyBell.evaluateSqRt curve2]
-
-fourier2 :: IO ()
-fourier2 =
-   GP.plotFuncs []
-      (GP.linearScale 100 (-5,5))
-      [Complex.real . (PolyBell.evaluateSqRt $ PolyBell.fourier curve2),
-       fourierAnalysisReal 100 (-2,2) $ PolyBell.evaluateSqRt curve2]
-
-
-
-fourierAnalysisReal ::
-   (P.Floating a) =>
-   Integer -> (a, a) -> (a -> Complex.T a) -> a -> a
-fourierAnalysisReal n rng f =
-   liftA2 (P.-)
-      (Fourier.analysisTransformOneReal n rng (Complex.real . f))
-      (Fourier.analysisTransformOneImag n rng (Complex.imag . f))
-
-
-{- |
-Try to approximate @\x -> exp (-x^2) * x@
-by a difference of translated Gaussian bells.
-
-exp(-x^2) * x
-  ==  exp(-(a+b*x+c*x^2)) - exp(-(a-b*x+c*x^2))
-  ==  exp(-(a+c*x^2)) * (exp(-b*x) - exp(b*x))
-  ==  exp(-(a+c*x^2)) * 2*sinh (b*x)
-
-It holds
-  lim (\b x -> sinh (b*x) / b)  =  id
--}
-diffApprox :: IO ()
-diffApprox =
-   let amp = (2*b)^- (-2)
-       a = 0
-       {-
-       amp = 1
-       a = log (2 * abs b)
-       -}
-       b = -0.1
-       c = 1
-       ac = Complex.fromReal a
-       bc = Complex.fromReal b
-   in  GP.plotFuncs []
-          (GP.linearScale 100 (-2,2::Double))
-          [Complex.real .
-           (PolyBell.evaluateSqRt $
-              PolyBell.Cons Bell.unit (Poly.fromCoeffs [zero,one])),
-           Complex.real .
-           liftA2 (-)
-             (PolyBell.evaluateSqRt $
-                PolyBell.Cons (Bell.Cons amp ac bc c) (Poly.fromCoeffs [one]))
-             (PolyBell.evaluateSqRt $
-                PolyBell.Cons (Bell.Cons amp ac (-bc) c) (Poly.fromCoeffs [one]))]
-
-
-polyApprox :: IO ()
-polyApprox =
-   GP.plotFuncs []
-      (GP.linearScale 100 (-2,2::Double))
-      [Complex.real .
-         PolyBell.evaluateSqRt curve2,
-       Complex.real . sum .
-         mapM (\(amp,b) -> \x -> amp * Bell.evaluateSqRt b x)
-         (PolyBell.approximateByBells 0.1 curve2)]
diff --git a/src/MathObj/Gaussian/Polynomial.hs b/src/MathObj/Gaussian/Polynomial.hs
deleted file mode 100644
--- a/src/MathObj/Gaussian/Polynomial.hs
+++ /dev/null
@@ -1,480 +0,0 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-
-Complex Gaussian bell multiplied with a polynomial.
-
-In order to make this free of @pi@ factors,
-we have to choose @recip (sqrt pi)@
-as unit for translations and modulations,
-for linear factors and in the differentiation.
--}
-{-
-ToDo:
-
-* In order to avoid the weird @sqrt pi@ factor,
-  use a polynomial expression in @pi@.
-
-* sum of multiple bells using Data.Map from exponent polynomial to coefficient polynomial
-  use of Algebra object.
-
-* Discrete Fourier Transform and its eigenvectors
-
-* Use projective geometry in order to support Dirac impulse.
-  There are many open questions:
-  1. What shall be the product of two Dirac impulses -
-     whether they are at the same location or not.
-  2. How to organize coefficients
-     such that the constant function can be modulated
-     and the Dirac impulse can be translated.
--}
-module MathObj.Gaussian.Polynomial where
-
-import qualified MathObj.Gaussian.Bell as Bell
-
-import qualified MathObj.LaurentPolynomial as LPoly
-import qualified MathObj.Polynomial.Core   as PolyCore
-import qualified MathObj.Polynomial        as Poly
-import qualified Number.Complex     as Complex
-
-import qualified Algebra.ZeroTestable   as ZeroTestable
-import qualified Algebra.Differential   as Differential
-import qualified Algebra.Transcendental as Trans
-import qualified Algebra.Field          as Field
-import qualified Algebra.Absolute       as Absolute
-import qualified Algebra.Ring           as Ring
-import qualified Algebra.Additive       as Additive
-
-import qualified Data.Record.HT as Rec
-import qualified Data.List as List
-import Data.Function.HT (nest, )
-import Data.Eq.HT (equating, )
-import Data.List.HT (mapAdjacent, )
-import Data.Tuple.HT (forcePair, )
-
-import Test.QuickCheck (Arbitrary, arbitrary, )
-import Control.Monad (liftM2, )
-
-import NumericPrelude.Numeric
-import NumericPrelude.Base hiding (reverse, )
--- import Prelude ()
-
-
-data T a = Cons {bell :: Bell.T a, polynomial :: Poly.T (Complex.T a)}
-   deriving (Show)
-
-instance (Absolute.C a, ZeroTestable.C a, Eq a) => Eq (T a) where
-   (==) = equal
-
-
-{-
-Helper data type for 'equal',
-that allows to call the (not quite trivial) polynomial equality check.
-@RootProduct r a@ represents @sqrt r * a@.
-The test using 'signum' works for real numbers,
-and I do not know, whether it is correct for other mathematical objects.
-However I cannot imagine other mathematical objects,
-that make sense at all, here.
-Maybe elements of a finite field.
--}
-data RootProduct a = RootProduct a a
-
-instance (Absolute.C a, ZeroTestable.C a, Eq a) => Eq (RootProduct a) where
-   (RootProduct xr xa) == (RootProduct yr ya)  =
-      let xp = xr*xa^2
-          yp = yr*ya^2
-      in  xp==yp &&
-          (isZero xp || signum xa == signum ya)
-
-instance (ZeroTestable.C a) => ZeroTestable.C (RootProduct a) where
-   isZero (RootProduct r a) = isZero r || isZero a
-
-
-{-
-The derived Eq is not correct.
-We have to combine the amplitude of the bell with the polynomial,
-respecting signs and the square root of the bell amplitude.
--}
-equal :: (Absolute.C a, ZeroTestable.C a, Eq a) => T a -> T a -> Bool
-equal x y =
-   let bx = bell x
-       by = bell y
-       scaleSqr b =
-          (\p ->
-              (fmap (RootProduct (Bell.amp b) . Complex.real) p,
-               fmap (RootProduct (Bell.amp b) . Complex.imag) p))
-           . polynomial
-   in  Rec.equal
-          (equating Bell.c0 :
-           equating Bell.c1 :
-           equating Bell.c2 :
-           [])
-          bx by
-       &&
-       scaleSqr bx x == scaleSqr by y
-
-
-instance (Absolute.C a, ZeroTestable.C a, Arbitrary a) => Arbitrary (T a) where
-   arbitrary =
---      liftM2 Cons arbitrary arbitrary
-      liftM2 Cons
-         arbitrary
-         -- we have to restrict the number of polynomial coefficients,
-         -- since with the quadratic time algorithms like fourier and convolve,
-         -- in connection with Rational slow down tests too much.
-         (fmap (Poly.fromCoeffs . take 5 . Poly.coeffs) arbitrary)
-
-
-
-{-# INLINE evaluateSqRt #-}
-evaluateSqRt :: (Trans.C a) =>
-   T a -> a -> Complex.T a
-evaluateSqRt f x =
-   Bell.evaluateSqRt (bell f) x *
-   Poly.evaluate (polynomial f) (Complex.fromReal $ sqrt pi * x)
-{- ToDo: evaluating a complex polynomial for a real argument can be optimized -}
-
-
-constant :: (Ring.C a) => T a
-constant =
-   Cons Bell.constant (Poly.const one)
-
-scale :: (Ring.C a) => a -> T a -> T a
-scale x f =
-   f{polynomial = fmap (Complex.scale x) $ polynomial f}
-
-scaleComplex :: (Ring.C a) => Complex.T a -> T a -> T a
-scaleComplex x f =
-   f{polynomial = fmap (x*) $ polynomial f}
-
-
-unit :: (Ring.C a) => T a
-unit = eigenfunction0
-
-eigenfunction :: (Field.C a) => Int -> T a
-eigenfunction =
-   eigenfunctionDifferential
-
-eigenfunction0 :: (Ring.C a) => T a
-eigenfunction0 =
-   Cons Bell.unit (Poly.fromCoeffs [one])
-
-eigenfunction1 :: (Ring.C a) => T a
-eigenfunction1 =
-   Cons Bell.unit (Poly.fromCoeffs [zero, one])
-
-eigenfunction2 :: (Field.C a) => T a
-eigenfunction2 =
-   Cons Bell.unit (Poly.fromCoeffs [-(1/4), zero, one])
-
-eigenfunction3 :: (Field.C a) => T a
-eigenfunction3 =
-   Cons Bell.unit (Poly.fromCoeffs [zero, -(3/4), zero, one])
-
-
-eigenfunctionDifferential :: (Field.C a) => Int -> T a
-eigenfunctionDifferential n =
-   (\f -> f{bell = Bell.unit}) $
-   nest n (scale (-1/4) . differentiate) $
-   Cons (Bell.Cons one zero zero 2) one
-
-eigenfunctionIterative ::
-   (Field.C a, Absolute.C a, ZeroTestable.C a, Eq a) => Int -> T a
-eigenfunctionIterative n =
-   fst . head . dropWhile (uncurry (/=)) . mapAdjacent (,) $
-   eigenfunctionIteration $
-   Cons
-      Bell.unit
-      (Poly.fromCoeffs $ replicate n zero ++ [one])
-
-eigenfunctionIteration :: (Field.C a) => T a -> [T a]
-eigenfunctionIteration =
-   iterate (\x ->
-      let y = fourier x
-          px = polynomial x
-          py = polynomial y
-          c = last (Poly.coeffs px) / last (Poly.coeffs py)
-      in  y{polynomial = fmap (0.5*) (px + fmap (c*) py)})
-
-
-multiply :: (Ring.C a) =>
-   T a -> T a -> T a
-multiply f g =
-   Cons
-      (Bell.multiply (bell f) (bell g))
-      (polynomial f * polynomial g)
-
-convolve, {- convolveByDifferentiation, -} convolveByFourier :: (Field.C a) =>
-   T a -> T a -> T a
-convolve = convolveByFourier
-
-{-
-f <*> g =
-   let (foff,fint) = integrate f
-   in  fint <*> differentiate g + makeGaussPoly foff * g
-
-In principle this would work,
-but (makeGaussPoly foff * g) contains a lot of
-convolutions of Gaussian with Gaussian-polynomial-product,
-where the Gaussians have different parameters.
-
-convolveByDifferentiation f g =
-   case polynomial f of
-      fpoly ->
-         if null $ Poly.coeffs fpoly
-           then ...
-           else ...
--}
-
-convolveByFourier f g =
-   reverse $ fourier $ multiply (fourier f) (fourier g)
-
-{-
-We use a Horner like scheme
-in order to translate multiplications with @id@
-to differentations on the Fourier side.
-Quadratic runtime.
-
-fourier (Cons bell (Poly.const a + Poly.shift f))
-  = fourier (Cons bell (Poly.const a)) + fourier (Cons bell (Poly.shift f))
-  = fourier (Cons bell (Poly.const a)) + differentiate (fourier (Cons bell f))
-
-We can certainly speed this up considerably
-by decomposing the polynomial into four polynomials,
-one for each of the four eigenvalues 1, i, -1, -i.
--}
-fourier :: (Field.C a) =>
-   T a -> T a
-fourier f =
-   foldr
-      (\c p ->
-          let q = differentiate p
-          in  q{polynomial =
-                   Poly.const c +
-                   fmap (Complex.scale (1/2) . Complex.quarterLeft) (polynomial q)})
-      (Cons (Bell.fourier $ bell f) zero) $
-   Poly.coeffs $ polynomial f
-
-{- |
-Differentiate and divide by @sqrt pi@ in order to stay in a ring.
-This way, we do not need to fiddle with pi factors.
--}
-differentiate :: (Ring.C a) => T a -> T a
-differentiate f =
-   f{polynomial =
-        Differential.differentiate (polynomial f)
-        - Differential.differentiate (Bell.exponentPolynomial (bell f))
-           * polynomial f}
-
-{-
-snd $ integrate $ differentiate (Cons Bell.unit (Poly.fromCoeffs [7,7,7,7]) :: T Double)
-
-g = (bell f * poly f)'
-  = bell f * ((poly f)' - (exppoly (bell f))' * poly f)
-poly g = (poly f)' - (exppoly (bell f))' * poly f
-
-Integration means we have g and ask for f.
-
-poly f = ((poly f)' - poly g) / (exppoly (bell f))'
-
-However must start with the highest term of 'poly f',
-and thus we need to perform the division on reversed polynomials.
--}
-integrate ::
-   (Field.C a, ZeroTestable.C a) =>
-   T a -> (Complex.T a, T a)
-integrate f =
-   let fs = Poly.coeffs $ polynomial f
-       (ys,~[r]) =
-          PolyCore.divModRev
-             {-
-             We need the shortening convention of 'zipWith'
-             in order to limit the result list,
-             we cannot use list instance for (-).
-             -}
-             (zipWith (-)
-                (0 : 0 : diffRev ys)
-                (List.reverse fs))
-             (List.reverse $ Poly.coeffs $
-              Differential.differentiate $
-              Bell.exponentPolynomial $ bell f)
-   in  forcePair $
-       if null fs
-         then (zero, f)
-         else (r, f{polynomial = Poly.fromCoeffs $ List.reverse ys})
-
-diffRev :: Ring.C a => [a] -> [a]
-diffRev xs =
-   zipWith (*) xs
-      (drop 1 (iterate (subtract 1) (fromIntegral $ length xs)))
-
-{-
-integrateDefinite
-   (maybe rename integrate to antiderivative and call this one integrate)
-
-int(x^(2*n)*exp(-x^2),x=-infinity..infinity)
- = 2 * int(x^(2*n)*exp(-x^2),x=0..infinity)
-     substitute t=x^2, dt = dx * 2 * sqrt t
- = int(t^(n-1/2)*exp(-t),x=0..infinity)
- = Gamma(n+1/2)
- = (2n-1)!!/2^n * sqrt pi
-
-int(pi^n*x^(2*n)*exp(-pi*x^2),x=-infinity..infinity)
- = (2n-1)!!/2^n
-
-
-The remainder value of 'integrate'
-is the coefficient of the error function
-and this is the only part that does not vanish when approaching the limit.
-
-
-In order to stay in a field,
-we have to return a rational number
-and a transcendental part written es @exp a@.
-
-It would be interesting to see how integral inequalities
-translate to scalar inequalities containing exponential functions.
--}
-
-
-translate :: Ring.C a => a -> T a -> T a
-translate d =
-   translateComplex (Complex.fromReal d)
-
-translateComplex :: Ring.C a => Complex.T a -> T a -> T a
-translateComplex d f =
-   Cons
-      (Bell.translateComplex d $ bell f)
-      (Poly.translate d $ polynomial f)
-
-modulate :: Ring.C a => a -> T a -> T a
-modulate d f =
-   Cons
-      (Bell.modulate d $ bell f)
-      (polynomial f)
-
-turn :: Ring.C a => a -> T a -> T a
-turn d f =
-   Cons
-      (Bell.turn d $ bell f)
-      (polynomial f)
-
-reverse :: Additive.C a => T a -> T a
-reverse f =
-   Cons
-      (Bell.reverse $ bell f)
-      (Poly.reverse $ polynomial f)
-
-dilate :: Field.C a => a -> T a -> T a
-dilate k f =
-   Cons
-      (Bell.dilate k $ bell f)
-      (Poly.dilate (Complex.fromReal k) $ polynomial f)
-
-shrink :: Ring.C a => a -> T a -> T a
-shrink k f =
-   Cons
-      (Bell.shrink k $ bell f)
-      (Poly.shrink (Complex.fromReal k) $ polynomial f)
-
-{-
-We could also amplify the polynomial coefficients.
--}
-amplify :: Ring.C a => a -> T a -> T a
-amplify k f =
-   Cons
-      (Bell.amplify k $ bell f)
-      (polynomial f)
-
-
-{- |
-Approximate a @T a@ using a linear combination of translated @Bell.T a@.
-The smaller the unit (e.g. 0.1, 0.01, 0.001)
-the better the approximation but the worse the numeric properties.
-
-We cannot put all information into @amp@ of @Bell@,
-since @amp@ must be real, but is complex here by construction.
-We really need at least signed amplitudes at this place,
-since we want to represent differences of Gaussians.
--}
-approximateByBells ::
-   Field.C a =>
-   a -> T a -> [(Complex.T a, Bell.T a)]
-approximateByBells unit_ f =
-   let b = bell f
-       amps =
-          -- approximateByBellsByTranslation
-          approximateByBellsAtOnce
-             unit_
-             (Complex.scale (recip (2 * Bell.c2 b)) (Bell.c1 b))
-             (recip (2*unit_*Bell.c2 b))
-             (polynomial f)
-   in  zip (LPoly.coeffs amps) $
-       map
-          (\d -> Bell.translate d b)
-          (laurentAbscissas (unit_/2) amps)
-
-approximateByBellsAtOnce ::
-   Field.C a =>
-   a -> Complex.T a -> a -> Poly.T (Complex.T a) -> LPoly.T (Complex.T a)
-approximateByBellsAtOnce unit_ d s p =
-   foldr
-      (\x amps0 ->
-         {-
-         Decompose (bell t * (t-d)) = bell t * t - bell t * d
-         -}
-         let y = fmap (Complex.scale s) amps0
-         in  -- \t -> bell t * t
-             --    ~   (translate unit_ bell - translate (-unit_) bell) / unit_
-             LPoly.shift 1 y -
-             LPoly.shift (-1) y +
-             -- bell t * d
-             zipWithAbscissas
-                (\t z -> (Complex.fromReal t - d) * z)
-                (unit_/2) amps0 +
-             LPoly.const x)
-      (LPoly.fromCoeffs [])
-      (Poly.coeffs p)
-
-approximateByBellsByTranslation ::
-   Field.C a =>
-   a -> Complex.T a -> a -> Poly.T (Complex.T a) -> LPoly.T (Complex.T a)
-approximateByBellsByTranslation unit_ d s p =
-   foldr
-      (\x amps0 ->
-         {-
-         Decompose (bell t * (t-d)) = bell t * t - bell t * d
-         -}
-         let y = fmap (Complex.scale s) amps0
-         in  -- \t -> bell t * t
-             --    ~   (translate unit_ bell - translate (-unit_) bell) / unit_
-             LPoly.shift 1 y -
-             LPoly.shift (-1) y +
-             -- bell t * d
-             zipWithAbscissas Complex.scale (unit_/2) amps0 +
-             LPoly.const x)
-      (LPoly.fromCoeffs [])
-      (Poly.coeffs $ Poly.translate d p)
-
-zipWithAbscissas ::
-   (Ring.C a) =>
-   (a -> b -> c) -> a -> LPoly.T b -> LPoly.T c
-zipWithAbscissas h unit_ y =
-   LPoly.fromShiftCoeffs (LPoly.expon y) $
-   zipWith h
-      (laurentAbscissas unit_ y)
-      (LPoly.coeffs y)
-
-laurentAbscissas :: Ring.C a => a -> LPoly.T c -> [a]
-laurentAbscissas unit_ =
-   map (\d -> fromIntegral d * unit_) .
-   iterate (1+) . LPoly.expon
-
-
-{- No Ring instance for Gaussians
-instance (Ring.C a) => Differential.C (T a) where
-   differentiate = differentiate
--}
-
-{- laws
-differentiate (f*g) =
-   (differentiate f) * g + f * (differentiate g)
--}
diff --git a/src/MathObj/Gaussian/Variance.hs b/src/MathObj/Gaussian/Variance.hs
deleted file mode 100644
--- a/src/MathObj/Gaussian/Variance.hs
+++ /dev/null
@@ -1,206 +0,0 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-
-We represent a Gaussian bell curve in terms of the reciprocal of its variance
-and its value at the origin.
-
-We could do some projective geometry in the exponent
-in order to also have zero variance,
-which corresponds to the dirac impulse.
-
-The Gaussians form a nice multiplicative commutative monoid.
-Maybe we should have such a structure.
-It would also be useful for the Root data type
-and a new Exponential data type.
--}
-module MathObj.Gaussian.Variance where
-
-import qualified MathObj.Polynomial as Poly
-import qualified Number.Root as Root
-
-import qualified Algebra.Transcendental as Trans
-import qualified Algebra.Algebraic      as Algebraic
-import qualified Algebra.Field          as Field
-import qualified Algebra.Absolute       as Absolute
-import qualified Algebra.Ring           as Ring
-import qualified Algebra.Additive       as Additive
-
-{-
-import Algebra.Transcendental (pi, )
-import Algebra.Ring ((*), (^), )
-import Algebra.Additive ((+))
--}
-import Test.QuickCheck (Arbitrary, arbitrary, )
-import Control.Monad (liftM2, )
-
--- import Prelude (($))
-import NumericPrelude.Numeric
-import NumericPrelude.Base
-
-
-{- |
-Since @amp@ is the square of the actual amplitude it must be non-negative.
--}
-data T a = Cons {amp, c :: a}
-   deriving (Eq, Show)
-
-instance (Absolute.C a, Arbitrary a) => Arbitrary (T a) where
-   arbitrary =
-      liftM2 Cons
-         (fmap abs arbitrary)
-         (fmap ((1+) . abs) arbitrary)
-
-
-constant :: Ring.C a => T a
-constant = Cons one zero
-
-{- |
-eigenfunction of 'fourier'
--}
-unit :: Ring.C a => T a
-unit = Cons one one
-
-{-# INLINE evaluate #-}
-evaluate :: (Trans.C a) =>
-   T a -> a -> a
-evaluate f x =
-   sqrt (amp f) * exp (-pi * c f * x^2)
-
-exponentPolynomial :: (Additive.C a) =>
-   T a -> Poly.T a
-exponentPolynomial f =
-   Poly.fromCoeffs [zero, zero, c f]
-
-
-integrateRoot :: (Field.C a) => T a -> Root.T a
-integrateRoot f =
-   Root.sqrt $ Root.fromNumber $ amp f / c f
-
-scalarProductRoot :: (Field.C a) => T a -> T a -> Root.T a
-scalarProductRoot f g =
-   integrateRoot (multiply f g)
-
-
-norm1Root :: (Field.C a) => T a -> Root.T a
-norm1Root = integrateRoot
-
-norm2Root :: (Field.C a) => T a -> Root.T a
-norm2Root f =
-   Root.sqrt $
-      Root.fromNumber (amp f)
-      `Root.div`
-      Root.sqrt (Root.fromNumber $ 2 * c f)
-
-normInfRoot :: (Field.C a) => T a -> Root.T a
-normInfRoot f =
-   Root.sqrt $ Root.fromNumber $ amp f
-
-normPRoot :: (Field.C a) => Rational -> T a -> Root.T a
-normPRoot p f =
-   Root.sqrt (Root.fromNumber (amp f))
-   `Root.div`
-   Root.rationalPower (recip (2*p)) (Root.fromNumber (fromRational' p * c f))
-
-
--- ToDo: implement NormedSpace.Sum et.al.
-norm1 :: (Algebraic.C a) => T a -> a
-norm1 f =
-   sqrt $ amp f / c f
-
-norm2 :: (Algebraic.C a) => T a -> a
-norm2 f =
-   sqrt $ amp f / (sqrt $ 2 * c f)
-
-normInf :: (Algebraic.C a) => T a -> a
-normInf f =
-   sqrt (amp f)
-
-normP :: (Trans.C a) => a -> T a -> a
-normP p f =
-   sqrt (amp f) * (p * c f) ^? (- recip (2*p))
-
-
-variance :: (Trans.C a) =>
-   T a -> a
-variance f =
-   recip $ c f * 2*pi
-
-multiply :: (Ring.C a) =>
-   T a -> T a -> T a
-multiply f g =
-   Cons (amp f * amp g) (c f + c g)
-
-powerRing :: (Trans.C a) =>
-   Integer -> T a -> T a
-powerRing p f =
-   Cons (amp f ^ p) (fromInteger p * c f)
-
-{-
-powerField does not makes sense,
-since the reciprocal of a Gaussian diverges.
--}
-
-powerAlgebraic :: (Trans.C a) =>
-   Rational -> T a -> T a
-powerAlgebraic p f =
-   Cons (amp f ^/ p) (fromRational' p * c f)
-
-powerTranscendental :: (Trans.C a) =>
-   a -> T a -> T a
-powerTranscendental p f =
-   Cons (amp f ^? p) (p * c f)
-
-{- |
-> convolve x y t =
->    integrate $ \s -> x s * y(t-s)
-
-Convergence only for @c f + c g > 0@.
--}
-convolve :: (Field.C a) =>
-   T a -> T a -> T a
-convolve f g =
-   let s = c f + c g
-   in  Cons
-          (amp f * amp g / s)
-          (c f * c g / s)
-
-{- |
-> fourier x f =
->    integrate $ \t -> x t * cis (-2*pi*t*f)
-
-Convergence only for @c f > 0@.
--}
-fourier :: (Field.C a) =>
-   T a -> T a
-fourier f =
-   Cons (amp f / c f) (recip $ c f)
-{-
-fourier (t -> exp(-(a*t)^2))
--}
-
-dilate :: (Field.C a) => a -> T a -> T a
-dilate k f =
-   Cons (amp f) $ c f / k^2
-
-shrink :: (Ring.C a) => a -> T a -> T a
-shrink k f =
-   Cons (amp f) $ c f * k^2
-
-{- |
-@amplify k@ scales by @abs k@!
--}
-amplify :: (Ring.C a) => a -> T a -> T a
-amplify k f =
-   Cons (k^2 * amp f) $ c f
-
-
-{- laws
-fourier (convolve f g) = multiply (fourier f) (fourier g)
-
-dilate k (dilate m f) = dilate (k*m) f
-
-dilate k (shrink k f) = f
-
-variance (dilate k f) = k^2 * variance f
-
-variance (convolve f g) = variance f + variance g
--}
diff --git a/src/MathObj/LaurentPolynomial.hs b/src/MathObj/LaurentPolynomial.hs
--- a/src/MathObj/LaurentPolynomial.hs
+++ b/src/MathObj/LaurentPolynomial.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
@@ -26,7 +26,6 @@
 
 import qualified Number.Complex as Complex
 
--- import qualified NumericPrelude.Base as P
 import qualified NumericPrelude.Numeric as NP
 
 import NumericPrelude.Base    hiding (const, reverse, )
diff --git a/src/MathObj/Matrix.hs b/src/MathObj/Matrix.hs
--- a/src/MathObj/Matrix.hs
+++ b/src/MathObj/Matrix.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
@@ -18,7 +18,7 @@
 but no additional parameters.
 
 ToDo:
- - Matrix inverse, determinant
+ - Matrix inverse, determinant (see htam:Matrix)
 -}
 
 module MathObj.Matrix (
@@ -68,17 +68,56 @@
 import NumericPrelude.Base hiding (zipWith, )
 
 
+{- $setup
+>>> import qualified MathObj.Matrix as Matrix
+>>> import qualified Algebra.Ring as Ring
+>>> import qualified Algebra.Laws as Laws
+>>> import Test.NumericPrelude.Utility ((/\))
+>>> import qualified Test.QuickCheck as QC
+>>> import NumericPrelude.Numeric as NP
+>>> import NumericPrelude.Base as P
+>>> import Prelude ()
+>>>
+>>> import Control.Monad (replicateM, join)
+>>> import Control.Applicative (liftA2)
+>>> import Data.Function.HT (nest)
+>>>
+>>> genDimension :: QC.Gen Int
+>>> genDimension = QC.choose (0,20)
+>>>
+>>> genMatrixFor :: (QC.Arbitrary a) => Int -> Int -> QC.Gen (Matrix.T a)
+>>> genMatrixFor m n =
+>>>    fmap (Matrix.fromList m n) $ replicateM (m*n) QC.arbitrary
+>>>
+>>> genMatrix :: (QC.Arbitrary a) => QC.Gen (Matrix.T a)
+>>> genMatrix = join $ liftA2 genMatrixFor genDimension genDimension
+>>>
+>>> genIntMatrix :: QC.Gen (Matrix.T Integer)
+>>> genIntMatrix = genMatrix
+>>>
+>>> genFactorMatrix :: (QC.Arbitrary a) => Matrix.T a -> QC.Gen (Matrix.T a)
+>>> genFactorMatrix a = genMatrixFor (Matrix.numColumns a) =<< genDimension
+>>>
+>>> genSameMatrix :: (QC.Arbitrary a) => Matrix.T a -> QC.Gen (Matrix.T a)
+>>> genSameMatrix = uncurry genMatrixFor . Matrix.dimension
+-}
+
+
 {- |
 A matrix is a twodimensional array, indexed by integers.
 -}
-data T a =
+newtype T a =
    Cons (Array (Dimension, Dimension) a)
-      deriving (Eq,Ord,Read)
+      deriving (Eq, Ord, Read)
 
 type Dimension = Int
 
 {- |
 Transposition of matrices is just transposition in the sense of Data.List.
+
+prop> genIntMatrix /\ \a -> Matrix.rows a == Matrix.columns (Matrix.transpose a)
+prop> genIntMatrix /\ \a -> Matrix.columns a == Matrix.rows (Matrix.transpose a)
+prop> genIntMatrix /\ \a -> genSameMatrix a /\ \b -> Laws.homomorphism Matrix.transpose (+) (+) a b
 -}
 transpose :: T a -> T a
 transpose (Cons m) =
@@ -98,6 +137,9 @@
 index :: T a -> Dimension -> Dimension -> a
 index (Cons m) i j = m ! (i,j)
 
+{- |
+prop> genIntMatrix /\ \a -> a == uncurry Matrix.fromRows (Matrix.dimension a) (Matrix.rows a)
+-}
 fromRows :: Dimension -> Dimension -> [[a]] -> T a
 fromRows m n =
    Cons .
@@ -106,6 +148,9 @@
    List.zipWith (\r -> map (\(c,x) -> ((r,c),x))) allIndices .
    map (zip allIndices)
 
+{- |
+prop> genIntMatrix /\ \a -> a == uncurry Matrix.fromColumns (Matrix.dimension a) (Matrix.columns a)
+-}
 fromColumns :: Dimension -> Dimension -> [[a]] -> T a
 fromColumns m n =
    Cons .
@@ -146,6 +191,10 @@
 
 -- These implementations may benefit from a better exception than
 -- just assertions to validate dimensionalities
+{- |
+prop> genIntMatrix /\ \a -> genSameMatrix a /\ \b -> Laws.commutative (+) a b
+prop> genIntMatrix /\ \a -> genSameMatrix a /\ \b -> genSameMatrix b /\ \c -> Laws.associative (+) a b c
+-}
 instance (Additive.C a) => Additive.C (T a) where
    (+) = zipWith (+)
    (-) = zipWith (-)
@@ -159,6 +208,9 @@
    in  assert (d == dimension nM) $
          uncurry fromList d (List.zipWith op em en)
 
+{- |
+prop> genIntMatrix /\ \a -> Laws.identity (+) (uncurry Matrix.zero $ Matrix.dimension a) a
+-}
 zero :: (Additive.C a) => Dimension -> Dimension -> T a
 zero m n =
    fromList m n $
@@ -172,6 +224,9 @@
       (indexBounds n n)
       (map (\i -> ((i,i), Ring.one)) (indexRange n))
 
+{- |
+prop> genDimension /\ \n -> Matrix.one n == Matrix.diagonal (replicate n Ring.one :: [Integer])
+-}
 diagonal :: (Additive.C a) => [a] -> T a
 diagonal xs =
    let n = List.length xs
@@ -183,6 +238,15 @@
 scale :: (Ring.C a) => a -> T a -> T a
 scale s = Vector.functorScale s
 
+{- |
+prop> genIntMatrix /\ \a -> Laws.leftIdentity  (*) (Matrix.one (Matrix.numRows a)) a
+prop> genIntMatrix /\ \a -> Laws.rightIdentity (*) (Matrix.one (Matrix.numColumns a)) a
+prop> genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> Laws.homomorphism Matrix.transpose (*) (flip (*)) a b
+prop> genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> genFactorMatrix b /\ \c -> Laws.associative (*) a b c
+prop> genIntMatrix /\ \b -> genSameMatrix b /\ \c -> genFactorMatrix b /\ \a -> Laws.leftDistributive (*) (+) a b c
+prop> genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> genSameMatrix b /\ \c -> Laws.rightDistributive (*) (+) a b c
+prop> QC.choose (0,10) /\ \k -> genDimension /\ \n -> genMatrixFor n n /\ \a -> a^k == nest (fromInteger k) ((a::Matrix.T Integer)*) (Matrix.one n)
+-}
 instance (Ring.C a) => Ring.C (T a) where
    mM * nM =
       assert (numColumns mM == numRows nM) $
diff --git a/src/MathObj/Monoid.hs b/src/MathObj/Monoid.hs
--- a/src/MathObj/Monoid.hs
+++ b/src/MathObj/Monoid.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module MathObj.Monoid where
 
 import qualified Algebra.PrincipalIdealDomain as PID
diff --git a/src/MathObj/PartialFraction.hs b/src/MathObj/PartialFraction.hs
--- a/src/MathObj/PartialFraction.hs
+++ b/src/MathObj/PartialFraction.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright    :   (c) Henning Thielemann 2007
 Maintainer   :   numericprelude@henning-thielemann.de
@@ -29,21 +29,89 @@
 import Algebra.Additive((+), zero, negate)
 import Algebra.ZeroTestable (isZero)
 
+import qualified Data.List.Reverse.StrictSpine as Rev
+import qualified Data.List.Match as Match
 import qualified Data.List as List
-
-import Data.Map(Map)
 import qualified Data.Map as Map
-import Data.Maybe(fromMaybe, )
-import qualified Data.List.Match as Match
-import Data.List.HT (dropWhileRev, )
-import Data.List (group, sortBy, mapAccumR, )
+import Data.Map (Map)
+import Data.List (group, sortBy, mapAccumR)
+import Data.Maybe (fromMaybe)
 
 import NumericPrelude.Base hiding (zipWith)
 
 import NumericPrelude.Numeric(Int, fromInteger)
 
 
+{- $setup
+>>> import qualified MathObj.PartialFraction as PartialFraction
+>>> import qualified MathObj.Polynomial.Core as PolyCore
+>>> import qualified MathObj.Polynomial as Poly
+>>> import qualified Algebra.PrincipalIdealDomain as PID
+>>> import qualified Algebra.Indexable as Indexable
+>>> import qualified Algebra.Laws as Laws
+>>> import qualified Number.Ratio as Ratio
+>>> import Test.NumericPrelude.Utility ((/\))
+>>> import qualified Test.QuickCheck as QC
+>>> import NumericPrelude.Numeric as NP
+>>> import NumericPrelude.Base as P
+>>> import Prelude ()
+>>>
+>>> import Control.Applicative (liftA2)
+>>>
+>>> {- |
+>>> Generator of irreducible elements for tests.
+>>> Choosing from a list of examples is a simple yet effective design.
+>>> If we would construct irreducible elements by a clever algorithm
+>>> we might obtain multiple primes only rarely.
+>>> -} --
+>>> genSmallPrime :: QC.Gen Integer
+>>> genSmallPrime =
+>>>    let primes = [2,3,5,7,11,13]
+>>>    in  QC.elements (primes ++ map negate primes)
+>>>
+>>> genPartialFractionInt :: QC.Gen (PartialFraction.T Integer)
+>>> genPartialFractionInt =
+>>>    liftA2 PartialFraction.fromFactoredFraction
+>>>       (QC.listOf genSmallPrime) QC.arbitrary
+>>>
+>>>
+>>> genIrreduciblePolynomial :: QC.Gen (Poly.T Rational)
+>>> genIrreduciblePolynomial = do
+>>>    QC.NonZero unit <- QC.arbitrary
+>>>    fmap (Poly.fromCoeffs . map (unit*)) $
+>>>       QC.elements [[2,3],[2,0,1],[3,0,1],[1,-3,0,1]]
+>>>
+>>> genPartialFractionPoly :: QC.Gen (PartialFraction.T (Poly.T Rational))
+>>> genPartialFractionPoly =
+>>>    liftA2 PartialFraction.fromFactoredFraction
+>>>       (fmap (take 3) $ QC.listOf genIrreduciblePolynomial)
+>>>       (fmap (Poly.fromCoeffs . PolyCore.normalize . take 5) QC.arbitrary)
+>>>
+>>>
+>>> fractionConv :: (PID.C a, Indexable.C a) => [a] -> a -> Bool
+>>> fractionConv xs y =
+>>>    PartialFraction.toFraction (PartialFraction.fromFactoredFraction xs y) ==
+>>>    y % product xs
+>>>
+>>> fractionConvAlt :: (PID.C a, Indexable.C a) => [a] -> a -> Bool
+>>> fractionConvAlt xs y =
+>>>    PartialFraction.fromFactoredFraction xs y ==
+>>>    PartialFraction.fromFactoredFractionAlt xs y
+>>>
+>>> scaleInt :: (PID.C a, Indexable.C a) => a -> PartialFraction.T a -> Bool
+>>> scaleInt k a =
+>>>    PartialFraction.toFraction (PartialFraction.scaleInt k a) ==
+>>>    Ratio.scale k (PartialFraction.toFraction a)
+>>>
+>>> add, sub, mul ::
+>>>    (PID.C a, Indexable.C a) =>
+>>>    PartialFraction.T a -> PartialFraction.T a -> Bool
+>>> add = Laws.homomorphism PartialFraction.toFraction (+) (+)
+>>> sub = Laws.homomorphism PartialFraction.toFraction (-) (-)
+>>> mul = Laws.homomorphism PartialFraction.toFraction (*) (*)
+-}
 
+
 {- |
 @Cons z (indexMapFromList [(x0,[y00,y01]), (x1,[y10]), (x2,[y20,y21,y22])])@
 represents the partial fraction
@@ -123,6 +191,9 @@
 There are more direct methods for special cases
 like polynomials over rational numbers
 where the denominators are linear factors.
+
+prop> QC.listOf genSmallPrime /\ fractionConv
+prop> fmap (take 3) (QC.listOf genIrreduciblePolynomial) /\ fractionConv
 -}
 fromFactoredFraction :: (PID.C a, Indexable.C a) => [a] -> a -> T a
 fromFactoredFraction denoms0 numer0 =
@@ -145,6 +216,10 @@
        -- Is reduceHeads also necessary for polynomial partial fractions?
    in  removeZeros $ reduceHeads $ Cons intPart (indexMapFromList pairs)
 
+{- |
+prop> QC.listOf genSmallPrime /\ fractionConvAlt
+prop> fmap (take 3) (QC.listOf genIrreduciblePolynomial) /\ fractionConvAlt
+-}
 fromFactoredFractionAlt :: (PID.C a, Indexable.C a) => [a] -> a -> T a
 fromFactoredFractionAlt denoms numer =
    foldl (\p d -> scaleFrac (one%d) p) (fromValue numer) denoms
@@ -205,9 +280,7 @@
 -}
 removeZeros :: (Indexable.C a, ZeroTestable.C a) => T a -> T a
 removeZeros (Cons z m) =
-   Cons z $
-   Map.filter (not . null) $
-   Map.map (dropWhileRev isZero) m
+   Cons z $ Map.filter (not . null) $ Map.map (Rev.dropWhile isZero) m
 
 
 {-
@@ -220,7 +293,16 @@
 zipWith opS opV (Cons za ma) (Cons zb mb) =
    Cons (opS za zb) (Map.unionWith opV ma mb)
 
-instance (Indexable.C a, Integral.C a, ZeroTestable.C a) => Additive.C (T a) where
+{- |
+prop> genPartialFractionInt /\ \x -> genPartialFractionInt /\ \y -> add x y
+prop> genPartialFractionInt /\ \x -> genPartialFractionInt /\ \y -> sub x y
+
+prop> genPartialFractionPoly /\ \x -> genPartialFractionPoly /\ \y -> add x y
+prop> genPartialFractionPoly /\ \x -> genPartialFractionPoly /\ \y -> sub x y
+-}
+instance
+   (Indexable.C a, Integral.C a, ZeroTestable.C a) =>
+      Additive.C (T a) where
    a + b = removeZeros $ normalizeModulo $ zipWith (+) (+) a b
    {- This implementation is attracting but wrong.
      It fails if terms are present in b that are missing in a.
@@ -343,6 +425,10 @@
              (uncurry (:) . carryRipple ds . map (ns*))
              scaleFracs m)
 
+{- |
+prop> genPartialFractionInt /\ \x k -> scaleInt k x
+prop> genPartialFractionPoly /\ \x k -> scaleInt k x
+-}
 scaleInt :: (PID.C a, Indexable.C a) => a -> T a -> T a
 scaleInt x (Cons z m) =
    removeZeros $ normalizeModulo $
@@ -359,6 +445,10 @@
                  scaleFrac (one%d) (scaleInt numer a + acc)) zero l)
            (indexMapToList m))
 
+{- |
+prop> genPartialFractionInt /\ \x -> genPartialFractionInt /\ \y -> mul x y
+prop> genPartialFractionPoly /\ \x -> genPartialFractionPoly /\ \y -> mul x y
+-}
 mulFast :: (PID.C a, Indexable.C a) => T a -> T a -> T a
 mulFast pa pb =
    let ra = toFactoredFraction pa
diff --git a/src/MathObj/Permutation.hs b/src/MathObj/Permutation.hs
--- a/src/MathObj/Permutation.hs
+++ b/src/MathObj/Permutation.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright    :   (c) Henning Thielemann 2006
 Maintainer   :   numericprelude@henning-thielemann.de
@@ -16,8 +16,6 @@
 
 import Data.Array(Ix)
 
--- import NumericPrelude.Numeric (Integer)
--- import NumericPrelude.Base
 
 
 {- |
diff --git a/src/MathObj/Permutation/CycleList.hs b/src/MathObj/Permutation/CycleList.hs
--- a/src/MathObj/Permutation/CycleList.hs
+++ b/src/MathObj/Permutation/CycleList.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright    :   (c) Mikael Johansson 2006
 Maintainer   :   mik@math.uni-jena.de
diff --git a/src/MathObj/Permutation/CycleList/Check.hs b/src/MathObj/Permutation/CycleList/Check.hs
--- a/src/MathObj/Permutation/CycleList/Check.hs
+++ b/src/MathObj/Permutation/CycleList/Check.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright    :   (c) Henning Thielemann 2006
 Maintainer   :   numericprelude@henning-thielemann.de
@@ -12,19 +12,12 @@
 import qualified MathObj.Permutation.Table     as PermTable
 import qualified MathObj.Permutation           as Perm
 
-{-
-import qualified Algebra.Ring as Ring
-import qualified Algebra.Additive as Additive
-import Algebra.Ring((*),one,fromInteger)
-import Algebra.Additive((+))
--}
-import Algebra.Monoid((<*>))
 import qualified Algebra.Monoid as Monoid
+import Algebra.Monoid((<*>))
 
-import Data.Array((!), Ix)
 import qualified Data.Array as Array
+import Data.Array((!), Ix)
 
--- import NumericPrelude.Numeric (Integer)
 import NumericPrelude.Base hiding (cycle)
 
 {- |
diff --git a/src/MathObj/Permutation/Table.hs b/src/MathObj/Permutation/Table.hs
--- a/src/MathObj/Permutation/Table.hs
+++ b/src/MathObj/Permutation/Table.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright    :   (c) Henning Thielemann 2006
 Maintainer   :   numericprelude@henning-thielemann.de
@@ -23,7 +23,6 @@
 import Data.Tuple.HT (swap, )
 import Data.Maybe.HT (toMaybe, )
 
--- import NumericPrelude.Numeric (Integer)
 import NumericPrelude.Base hiding (cycle)
 
 
diff --git a/src/MathObj/Polynomial.hs b/src/MathObj/Polynomial.hs
--- a/src/MathObj/Polynomial.hs
+++ b/src/MathObj/Polynomial.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
@@ -73,15 +73,46 @@
 
 import Test.QuickCheck (Arbitrary(arbitrary))
 
+import qualified MathObj.Wrapper.Haskell98 as W98
+
 import NumericPrelude.Base    hiding (const, reverse, )
 import NumericPrelude.Numeric
 
 import qualified Prelude as P98
 
 
+{- $setup
+>>> import qualified MathObj.Polynomial as Poly
+>>> import qualified Algebra.IntegralDomain as Integral
+>>> import qualified Algebra.Laws as Laws
+>>> import NumericPrelude.Numeric
+>>> import NumericPrelude.Base
+>>> import Prelude ()
+>>>
+>>> intPoly :: Poly.T Integer -> Poly.T Integer
+>>> intPoly = id
+>>>
+>>> ratioPoly :: Poly.T Rational -> Poly.T Rational
+>>> ratioPoly = id
+-}
+
+{- |
+prop> Laws.identity (+) zero . intPoly
+prop> Laws.commutative (+) . intPoly
+prop> Laws.associative (+) . intPoly
+prop> Laws.identity (*) one . intPoly
+prop> Laws.commutative (*) . intPoly
+prop> Laws.associative (*) . intPoly
+prop> Laws.leftDistributive (*) (+) . intPoly
+prop> Integral.propInverse . ratioPoly
+-}
 newtype T a = Cons {coeffs :: [a]}
 
+{-
+>>> import Test.QuickCheck ((==>))
+-}
 
+
 {-# INLINE fromCoeffs #-}
 fromCoeffs :: [a] -> T a
 fromCoeffs = lift0
@@ -268,18 +299,17 @@
    lift1 $ foldr (\c p -> [c] + Core.mulLinearFactor d p) []
 
 shrink :: Ring.C a => a -> T a -> T a
-shrink k =
-   lift1 $ zipWith (*) (iterate (k*) one)
+shrink = lift1 . Core.shrink
 
 dilate :: Field.C a => a -> T a -> T a
-dilate = shrink . Field.recip
+dilate = lift1 . Core.dilate
 
 
 instance (Arbitrary a, ZeroTestable.C a) => Arbitrary (T a) where
    arbitrary = liftM (fromCoeffs . Core.normalize) arbitrary
 
 
-{- * legacy instances -}
+-- * Haskell 98 legacy instances
 
 {- |
 It is disputable whether polynomials shall be represented by number literals or not.
@@ -288,19 +318,20 @@
 in  (x^2+x+1)*(x-1)
 However the output looks much different.
 -}
-{-# INLINE legacyInstance #-}
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
+{-# INLINE notImplemented #-}
+notImplemented :: String -> a
+notImplemented name =
+   error $ "MathObj.Polynomial: method " ++ name ++ " cannot be implemented"
 
-instance (Ring.C a, Eq a, Show a, ZeroTestable.C a) => P98.Num (T a) where
-   fromInteger = const . fromInteger
-   negate = Additive.negate -- for unary minus
-   (+)    = legacyInstance
-   (*)    = legacyInstance
-   abs    = legacyInstance
-   signum = legacyInstance
+-- legacy instances for use of numeric literals in GHCi
+instance (P98.Num a) => P98.Num (T a) where
+   fromInteger = const . P98.fromInteger
+   negate = W98.unliftF1 Additive.negate
+   (+)    = W98.unliftF2 (Additive.+)
+   (*)    = W98.unliftF2 (Ring.*)
+   abs    = notImplemented "abs"
+   signum = notImplemented "signum"
 
-instance (Field.C a, Eq a, Show a, ZeroTestable.C a) => P98.Fractional (T a) where
-   fromRational = const . fromRational
-   (/) = legacyInstance
+instance (P98.Fractional a) => P98.Fractional (T a) where
+   fromRational = const . P98.fromRational
+   (/) = notImplemented "(/)"
diff --git a/src/MathObj/Polynomial/Core.hs b/src/MathObj/Polynomial/Core.hs
--- a/src/MathObj/Polynomial/Core.hs
+++ b/src/MathObj/Polynomial/Core.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 This module implements polynomial functions on plain lists.
 We use such functions in order to implement methods of other datatypes.
@@ -21,7 +21,7 @@
    stdUnit,
    progression, differentiate, integrate, integrateInt,
    mulLinearFactor,
-   alternate,
+   alternate, dilate, shrink,
    ) where
 
 import qualified Algebra.Module               as Module
@@ -31,11 +31,11 @@
 import qualified Algebra.Additive             as Additive
 import qualified Algebra.ZeroTestable         as ZeroTestable
 
+import qualified Data.List.Reverse.StrictSpine as Rev
 import qualified Data.List as List
 import NumericPrelude.List (zipWithOverlap, )
 import Data.Tuple.HT (mapPair, mapFst, forcePair, )
-import Data.List.HT
-          (dropWhileRev, switchL, shear, shearTranspose, outerProduct, )
+import Data.List.HT (switchL, shear, shearTranspose, outerProduct)
 
 import qualified NumericPrelude.Base as P
 import qualified NumericPrelude.Numeric as NP
@@ -44,6 +44,25 @@
 import NumericPrelude.Numeric hiding (divMod, negate, stdUnit, )
 
 
+{- $setup
+>>> import qualified MathObj.Polynomial.Core as PolyCore
+>>> import qualified MathObj.Polynomial as Poly
+>>> import qualified Data.List as List
+>>> import qualified Test.QuickCheck as QC
+>>> import Test.QuickCheck ((==>))
+>>> import Data.Tuple.HT (mapPair, mapSnd)
+>>> import NumericPrelude.Numeric
+>>> import NumericPrelude.Base
+>>> import Prelude ()
+>>>
+>>> intPoly :: [Integer] -> [Integer]
+>>> intPoly = id
+>>>
+>>> ratioPoly :: [Rational] -> [Rational]
+>>> ratioPoly = id
+-}
+
+
 {- |
 Horner's scheme for evaluating a polynomial in a ring.
 -}
@@ -69,7 +88,7 @@
 -}
 {-# INLINE normalize #-}
 normalize :: (ZeroTestable.C a) => [a] -> [a]
-normalize = dropWhileRev isZero
+normalize = Rev.dropWhile isZero
 
 {- |
 Multiply by the variable, used internally.
@@ -113,6 +132,9 @@
    all (==zero) xs && all (==zero) ys
 
 
+{- |
+prop> \(QC.NonEmpty xs) (QC.NonEmpty ys) -> PolyCore.tensorProduct xs ys == List.transpose (PolyCore.tensorProduct ys (intPoly xs))
+-}
 {-# INLINE tensorProduct #-}
 tensorProduct :: Ring.C a => [a] -> [a] -> [[a]]
 tensorProduct = outerProduct (*)
@@ -135,6 +157,9 @@
 -- this one fails on infinite lists
 --    mul xs = foldr (\y zs -> add (scale y xs) (shift zs)) []
 
+{- |
+prop> \xs ys  ->  PolyCore.equal (intPoly $ PolyCore.mul xs ys) (PolyCore.mulShear xs ys)
+-}
 {-# INLINE mulShear #-}
 mulShear :: Ring.C a => [a] -> [a] -> [a]
 mulShear xs ys = map sum (shear (tensorProduct xs ys))
@@ -144,6 +169,11 @@
 mulShearTranspose xs ys = map sum (shearTranspose (tensorProduct xs ys))
 
 
+{- |
+prop> \x y -> case (PolyCore.normalize x, PolyCore.normalize y) of (nx, ny) -> not (null (ratioPoly ny)) ==> mapSnd PolyCore.normalize (PolyCore.divMod nx ny) == mapPair (PolyCore.normalize, PolyCore.normalize) (PolyCore.divMod x y)
+prop> \x y -> not (isZero (ratioPoly y)) ==> let z = fst $ PolyCore.divMod (Poly.coeffs x) y in  PolyCore.normalize z == z
+prop> \x y -> case PolyCore.normalize $ ratioPoly y of ny -> not (null ny) ==> List.length (snd $ PolyCore.divMod x y) < List.length ny
+-}
 divMod :: (ZeroTestable.C a, Field.C a) => [a] -> [a] -> ([a], [a])
 divMod x y =
    mapPair (List.reverse, List.reverse) $
@@ -152,21 +182,26 @@
 {-
 snd $ Poly.divMod (repeat (1::Double)) [1,1]
 -}
+{- |
+The modulus will always have one element less than the divisor.
+This means that the modulus will be denormalized in some cases,
+e.g. @mod [2,1,1] [1,1,1] == [1,0]@ instead of @[1]@.
+-}
 divModRev :: (ZeroTestable.C a, Field.C a) => [a] -> [a] -> ([a], [a])
 divModRev x y =
-   let (y0:ys) = dropWhile isZero y
-       -- the second parameter represents lazily (length x - length y)
-       aux xs' =
-         forcePair .
-         switchL
-           ([], xs')
-           (P.const $
-              let (x0:xs) = xs'
-                  q0      = x0/y0
-              in  mapFst (q0:) . aux (sub xs (scale q0 ys)))
-   in  if isZero y
-         then error "MathObj.Polynomial: division by zero"
-         else aux x (drop (length y - 1) x)
+   case dropWhile isZero y of
+      [] -> error "MathObj.Polynomial: division by zero"
+      y0:ys ->
+         let -- the second parameter represents lazily (length x - length (normalize y))
+             aux xs' =
+               forcePair .
+               switchL
+                 ([], xs')
+                 (P.const $
+                    let (x0:xs) = xs'
+                        q0      = x0/y0
+                    in  mapFst (q0:) . aux (sub xs (scale q0 ys)))
+         in  aux x (drop (length ys) x)
 
 {-# INLINE stdUnit #-}
 stdUnit :: (ZeroTestable.C a, Ring.C a) => [a] -> a
@@ -206,6 +241,14 @@
 {-# INLINE alternate #-}
 alternate :: Additive.C a => [a] -> [a]
 alternate = zipWith ($) (cycle [id, Additive.negate])
+
+{-# INLINE shrink #-}
+shrink :: Ring.C a => a -> [a] -> [a]
+shrink k = zipWith (*) (iterate (k*) one)
+
+{-# INLINE dilate #-}
+dilate :: Field.C a => a -> [a] -> [a]
+dilate = shrink . Field.recip
 
 
 {-
diff --git a/src/MathObj/PowerSeries.hs b/src/MathObj/PowerSeries.hs
--- a/src/MathObj/PowerSeries.hs
+++ b/src/MathObj/PowerSeries.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
@@ -27,6 +27,17 @@
 import NumericPrelude.Numeric
 
 
+{- $setup
+>>> import qualified MathObj.PowerSeries.Core as PS
+>>> import qualified MathObj.PowerSeries as PST
+>>> import qualified Test.QuickCheck as QC
+>>> import Test.NumericPrelude.Utility (equalTrunc, (/\))
+>>> import NumericPrelude.Numeric as NP
+>>> import NumericPrelude.Base as P
+>>> import Prelude ()
+-}
+
+
 newtype T a = Cons {coeffs :: [a]} deriving (Ord)
 
 {-# INLINE fromCoeffs #-}
@@ -126,6 +137,9 @@
    (-)    = lift2 Poly.sub
    zero   = lift0 []
 
+{- |
+prop> QC.choose (1,10) /\ \expon (QC.Positive x) xs -> let xt = x:xs in  equalTrunc 15 (PS.pow (const x) (1 % expon) (PST.coeffs (PST.fromCoeffs xt ^ expon)) ++ repeat zero) (xt ++ repeat zero)
+-}
 instance (Ring.C a) => Ring.C (T a) where
    one           = const one
    fromInteger n = const (fromInteger n)
@@ -189,3 +203,9 @@
    if isZero y
      then Cons (Core.compose x ys)
      else error "PowerSeries.compose: inner series must not have an absolute term."
+
+shrink :: Ring.C a => a -> T a -> T a
+shrink = lift1 . Poly.shrink
+
+dilate :: Field.C a => a -> T a -> T a
+dilate = lift1 . Poly.dilate
diff --git a/src/MathObj/PowerSeries/Core.hs b/src/MathObj/PowerSeries/Core.hs
--- a/src/MathObj/PowerSeries/Core.hs
+++ b/src/MathObj/PowerSeries/Core.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module MathObj.PowerSeries.Core where
 
 import qualified MathObj.Polynomial.Core as Poly
@@ -20,6 +20,32 @@
                               sin, cos, tan, asin, acos, atan)
 
 
+{- $setup
+>>> import qualified MathObj.PowerSeries.Core as PS
+>>> import qualified MathObj.PowerSeries.Example as PSE
+>>> import Test.NumericPrelude.Utility (equalTrunc, (/\))
+>>> import qualified Test.QuickCheck as QC
+>>> import NumericPrelude.Numeric as NP
+>>> import NumericPrelude.Base as P
+>>> import Prelude ()
+>>> import Control.Applicative (liftA3)
+>>>
+>>> checkHoles ::
+>>>    Int -> ([Rational] -> [Rational]) ->
+>>>    Rational -> [Rational] -> QC.Property
+>>> checkHoles trunc f x xs =
+>>>    QC.choose (1,10) /\ \expon ->
+>>>    equalTrunc trunc
+>>>       (f (PS.insertHoles expon (x:xs)) ++ repeat zero)
+>>>       (PS.insertHoles expon (f (x:xs)) ++ repeat zero)
+>>>
+>>> genInvertible :: QC.Gen [Rational]
+>>> genInvertible =
+>>>    liftA3 (\x0 x1 xs -> x0:x1:xs)
+>>>       QC.arbitrary (fmap QC.getNonZero QC.arbitrary) QC.arbitrary
+-}
+
+
 {-# INLINE evaluate #-}
 evaluate :: Ring.C a => [a] -> a -> a
 evaluate = flip Poly.horner
@@ -76,6 +102,18 @@
    zipWith id (cycle [id, P.const zero, NP.negate, P.const zero])
 
 
+{- |
+For power series of @f x@, compute the power series of @f(x^n)@.
+
+prop> QC.choose (1,10) /\ \m -> QC.choose (1,10) /\ \n xs -> equalTrunc 100 (PS.insertHoles m $ PS.insertHoles n xs) (PS.insertHoles (m*n) xs)
+-}
+insertHoles :: Additive.C a => Int -> [a] -> [a]
+insertHoles n =
+   if n<=0
+     then error $ "insertHoles requires positive exponent, but got " ++ show n
+     else concatMap (\x -> x : replicate (n-1) zero)
+
+
 {- * Series arithmetic -}
 
 add, sub :: (Additive.C a) => [a] -> [a] -> [a]
@@ -148,6 +186,10 @@
 We need to compute the square root only of the first term.
 That is, if the first term is rational,
 then all terms of the series are rational.
+
+prop> equalTrunc 50 PSE.sqrtExpl (PS.sqrt (\1 -> 1) [1,1])
+prop> equalTrunc 500 (1:1:repeat 0) (PS.sqrt (\1 -> 1) (PS.mul [1,1] [1,1]))
+prop> checkHoles 50 (PS.sqrt (\1 -> 1)) 1
 -}
 sqrt :: Field.C a => (a -> a) -> [a] -> [a]
 sqrt _ [] = []
@@ -159,18 +201,28 @@
 {-
 pow alpha t = t^alpha
 (pow alpha . x)' = alpha * (pow (alpha-1) . x) * x'
-alpha * (pow alpha . x) = x * x' * (pow alpha . x)'
+(pow alpha . x)' * x = alpha * (pow alpha . x) * x'
+
 y = pow alpha . x
-alpha * y = x * x' * y'
+y' * x = alpha * y * x'
+
+This yields an implementation that is a fused
+exp (alpha * log x)
 -}
 
 {- |
-Input series must start with non-zero term.
+Input series must start with a non-zero term,
+even better with a positive one.
+
+prop> equalTrunc 100 (PSE.powExpl (-1/3)) (PS.pow (\1 -> 1) (-1/3) [1,1])
+prop> equalTrunc 50 (PSE.powExpl (-1/3)) (PS.exp (\0 -> 1) (PS.scale (-1/3) PSE.log))
+prop> checkHoles 30 (PS.pow (\1 -> 1) (1/3)) 1
+prop> checkHoles 30 (PS.pow (\1 -> 1) (2/5)) 1
 -}
 pow :: (Field.C a) => (a -> a) -> a -> [a] -> [a]
 pow f0 expon x =
    let y  = integrate (f0 (head x)) y'
-       y' = scale expon (divide y (mul x (differentiate x)))
+       y' = scale expon (mul y (derivedLog x))
    in  y
 
 
@@ -181,6 +233,10 @@
 > (exp . x)' =   (exp . x) * x'
 > (sin . x)' =   (cos . x) * x'
 > (cos . x)' = - (sin . x) * x'
+
+prop> equalTrunc 500 PSE.expExpl (PS.exp (\0 -> 1) [0,1])
+prop> equalTrunc 100 (1:1:repeat 0) (PS.exp (\0 -> 1) PSE.log)
+prop> checkHoles 30 (PS.exp (\0 -> 1)) 0
 -}
 exp :: Field.C a => (a -> a) -> [a] -> [a]
 exp f0 x =
@@ -199,10 +255,25 @@
 sinCosScalar :: Transcendental.C a => a -> (a,a)
 sinCosScalar x = (Transcendental.sin x, Transcendental.cos x)
 
-sin, cos :: Field.C a => (a -> (a,a)) -> [a] -> [a]
+{- |
+prop> equalTrunc 500 PSE.sinExpl (PS.sin (\0 -> (0,1)) [0,1])
+prop> equalTrunc 50 (0:1:repeat 0) (PS.sin (\0 -> (0,1)) PSE.asin)
+prop> checkHoles 20 (PS.sin (\0 -> (0,1))) 0
+-}
+sin :: Field.C a => (a -> (a,a)) -> [a] -> [a]
 sin f0 = fst . sinCos f0
+{- |
+prop> equalTrunc 500 PSE.cosExpl (PS.cos (\0 -> (0,1)) [0,1])
+prop> checkHoles 20 (PS.cos (\0 -> (0,1))) 0
+-}
+cos :: Field.C a => (a -> (a,a)) -> [a] -> [a]
 cos f0 = snd . sinCos f0
 
+{- |
+prop> equalTrunc 50 PSE.tanExpl (PS.tan (\0 -> (0,1)) [0,1])
+prop> equalTrunc 50 (0:1:repeat 0) (PS.tan (\0 -> (0,1)) PSE.atan)
+prop> checkHoles 20 (PS.tan (\0 -> (0,1))) 0
+-}
 tan :: (Field.C a) => (a -> (a,a)) -> [a] -> [a]
 tan f0 = uncurry divide . sinCos f0
 
@@ -214,6 +285,10 @@
 
 {- |
 Input series must start with non-zero term.
+
+prop> equalTrunc 500 PSE.logExpl (PS.log (\1 -> 0) [1,1])
+prop> equalTrunc 100 (0:1:repeat 0) (PS.log (\1 -> 0) PSE.exp)
+prop> checkHoles 30 (PS.log (\1 -> 0)) 1
 -}
 log :: (Field.C a) => (a -> a) -> [a] -> [a]
 log f0 x = integrate (f0 (head x)) (derivedLog x)
@@ -224,17 +299,33 @@
 derivedLog :: (Field.C a) => [a] -> [a]
 derivedLog x = divide (differentiate x) x
 
+{- |
+prop> equalTrunc 500 PSE.atan (PS.atan (\0 -> 0) [0,1])
+prop> equalTrunc 50 (0:1:repeat 0) (PS.atan (\0 -> 0) PSE.tan)
+prop> checkHoles 20 (PS.atan (\0 -> 0)) 0
+-}
 atan :: (Field.C a) => (a -> a) -> [a] -> [a]
 atan f0 x =
    let x' = differentiate x
    in  integrate (f0 (head x)) (divide x' ([1] + mul x x))
 
-asin, acos :: (Field.C a) =>
-   (a -> a) -> (a -> a) -> [a] -> [a]
+{- |
+prop> equalTrunc 100 (0:1:repeat 0) (PS.asin (\1 -> 1) (\0 -> 0) PSE.sin)
+prop> equalTrunc 50 PSE.asin (PS.asin (\1 -> 1) (\0 -> 0) [0,1])
+prop> checkHoles 30 (PS.asin (\1 -> 1) (\0 -> 0)) 0
+-}
+asin :: (Field.C a) => (a -> a) -> (a -> a) -> [a] -> [a]
 asin sqrt0 f0 x =
    let x' = differentiate x
    in  integrate (f0 (head x))
                  (divide x' (sqrt sqrt0 ([1] - mul x x)))
+
+{- |
+Would be a nice test, but we cannot compute exactly with 'pi':
+
+> equalTrunc 50 PSE.acos (PS.acos (\1 -> 1) (\0 -> pi/2) [0,1])
+-}
+acos :: (Field.C a) => (a -> a) -> (a -> a) -> [a] -> [a]
 acos = asin
 
 {- |
@@ -257,22 +348,58 @@
 composeTaylor x []     = x 0
 
 
+{-
+X(t) = t*x(t)
+R(t) = t*r(t)
 
+r(t) = 1 / (x(r(t)*t))
+R(t)/t
+   = 1 / (x(R(t)))
+   = 1 / (X(R(t)) / R(t))
+   = 1 / (t / R(t))
+-}
+
+{- |
+This function returns the series of the inverse function in the form:
+(point of the expansion, power series).
+
+That is, say we have the equation:
+
+> y = a + f(x)
+
+where function f is given by a power series with f(0) = 0.
+We want to solve for x:
+
+> x = f^-1(y-a)
+
+If you pass the power series of @a+f(x)@ to 'inv',
+you get @(a, f^-1)@ as answer, where @f^-1@ is a power series.
+
+The linear term of @f@ (the coefficient of @x@) must be non-zero.
+
+This needs cubic run-time and thus is exceptionally slow.
+Computing inverse series for special power series might be faster.
+
+prop> genInvertible /\ \xs -> let (y,ys) = PS.inv xs; (z,zs) = PS.invDiff xs in y==z && equalTrunc 15 ys zs
+-}
+-- how about NonEmpty.T here?
+inv :: (Eq a, Field.C a) => [a] -> (a, [a])
+inv [] = error "inv: power series must be non-zero"
+inv (x:xs) =
+   (x, let r = divide [1] (compose xs r) in 0 : r)
+
+
 {-
 (x . y) = id
 (x' . y) * y' = 1
 y' = 1 / (x' . y)
 -}
 
-{- |
-This function returns the series of the function in the form:
-(point of the expansion, power series)
-
-This is exceptionally slow and needs cubic run-time.
+{-
+Like 'inv' but with a slightly cumbersome implementation.
 -}
-
-inv :: (Field.C a) => [a] -> (a, [a])
-inv x =
+invDiff :: (Field.C a) => [a] -> (a, [a])
+invDiff x =
    let y' = divide [1] (compose (differentiate x) (tail y))
        y  = integrate 0 y'
             -- the first term is zero, which is required for composition
diff --git a/src/MathObj/PowerSeries/DifferentialEquation.hs b/src/MathObj/PowerSeries/DifferentialEquation.hs
--- a/src/MathObj/PowerSeries/DifferentialEquation.hs
+++ b/src/MathObj/PowerSeries/DifferentialEquation.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Lazy evaluation allows for the solution
  of differential equations in terms of power series.
diff --git a/src/MathObj/PowerSeries/Example.hs b/src/MathObj/PowerSeries/Example.hs
--- a/src/MathObj/PowerSeries/Example.hs
+++ b/src/MathObj/PowerSeries/Example.hs
@@ -1,11 +1,10 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module MathObj.PowerSeries.Example where
 
 import qualified MathObj.PowerSeries.Core as PS
 
 import qualified Algebra.Field          as Field
 import qualified Algebra.Ring           as Ring
--- import qualified Algebra.Additive       as Additive
 import qualified Algebra.ZeroTestable   as ZeroTestable
 import qualified Algebra.Transcendental as Transcendental
 
@@ -19,6 +18,16 @@
 import NumericPrelude.Base -- (Bool, const, map, zipWith, id, (&&), (==))
 
 
+{- $setup
+>>> import qualified MathObj.PowerSeries.Core as PS
+>>> import qualified MathObj.PowerSeries.Example as PSE
+>>> import Test.NumericPrelude.Utility (equalTrunc)
+>>> import NumericPrelude.Numeric as NP
+>>> import NumericPrelude.Base as P
+>>> import Prelude ()
+-}
+
+
 {- * Default implementations. -}
 
 recip :: (Ring.C a) => [a]
@@ -42,6 +51,8 @@
 cosh  = coshODE
 atanh = atanhODE
 
+
+-- | prop> \m n -> equalTrunc 30 (PS.mul (PSE.pow m) (PSE.pow n)) (PSE.pow (m+n))
 pow :: (Field.C a) => a -> [a]
 pow = powExpl
 sqrt = sqrtExpl
@@ -52,34 +63,54 @@
 recipExpl :: (Ring.C a) => [a]
 recipExpl = cycle [1,-1]
 
-expExpl, sinExpl, cosExpl :: (Field.C a) => [a]
+-- | prop> equalTrunc 500 PSE.expExpl PSE.expODE
+expExpl :: (Field.C a) => [a]
 expExpl = scanl (*) one PS.recipProgression
+-- | prop> equalTrunc 500 PSE.sinExpl PSE.sinODE
+sinExpl :: (Field.C a) => [a]
 sinExpl = zero : PS.holes2alternate (tail expExpl)
-cosExpl =        PS.holes2alternate       expExpl
+-- | prop> equalTrunc 500 PSE.cosExpl PSE.cosODE
+cosExpl :: (Field.C a) => [a]
+cosExpl = PS.holes2alternate expExpl
 
-tanExpl, tanExplSieve :: (ZeroTestable.C a, Field.C a) => [a]
+-- | prop> equalTrunc 50 PSE.tanExpl PSE.tanODE
+tanExpl :: (ZeroTestable.C a, Field.C a) => [a]
 tanExpl = PS.divide sinExpl cosExpl
 -- ignore zero values
+-- | prop> equalTrunc 50 PSE.tanExpl PSE.tanExplSieve
+tanExplSieve :: (ZeroTestable.C a, Field.C a) => [a]
 tanExplSieve =
    concatMap
       (\x -> [zero,x])
       (PS.divide (sieve 2 (tail sin)) (sieve 2 cos))
 
-logExpl, atanExpl, sqrtExpl :: (Field.C a) => [a]
+-- | prop> equalTrunc 500 PSE.logExpl PSE.logODE
+logExpl :: (Field.C a) => [a]
 logExpl  = zero : PS.alternate       PS.recipProgression
+-- | prop> equalTrunc 500 PSE.atanExpl PSE.atanODE
+atanExpl :: (Field.C a) => [a]
 atanExpl = zero : PS.holes2alternate PS.recipProgression
 
-sinhExpl, coshExpl, atanhExpl :: (Field.C a) => [a]
+-- | prop> equalTrunc 500 PSE.sinhExpl PSE.sinhODE
+sinhExpl :: (Field.C a) => [a]
 sinhExpl  = zero : PS.holes2 (tail expExpl)
+-- | prop> equalTrunc 500 PSE.coshExpl PSE.coshODE
+coshExpl :: (Field.C a) => [a]
 coshExpl  =        PS.holes2       expExpl
+-- | prop> equalTrunc 500 PSE.atanhExpl PSE.atanhODE
+atanhExpl :: (Field.C a) => [a]
 atanhExpl = zero : PS.holes2 PS.recipProgression
 
 {- * Power series of (1+x)^expon using the binomial series. -}
 
+-- | prop> \expon -> equalTrunc 50 (PSE.powODE expon) (PSE.powExpl expon)
 powExpl :: (Field.C a) => a -> [a]
 powExpl expon =
    scanl (*) 1 (zipWith (/)
       (iterate (subtract 1) expon) PS.progression)
+
+-- | prop> equalTrunc 100 PSE.sqrtExpl PSE.sqrtODE
+sqrtExpl :: (Field.C a) => [a]
 sqrtExpl = powExpl (1/2)
 
 {- |
@@ -110,11 +141,13 @@
        == cos x ^ (-2)
 -}
 
-expODE, sinODE, cosODE, tanODE, tanODESieve :: (Field.C a) => [a]
+expODE, sinODE, cosODE, tanODE :: (Field.C a) => [a]
 expODE = PS.integrate 1 expODE
 sinODE = PS.integrate 0 cosODE
 cosODE = PS.integrate 1 (PS.negate sinODE)
 tanODE = PS.integrate 0 (PS.add [1] (PS.mul tanODE tanODE))
+-- | prop> equalTrunc 50 PSE.tanODE PSE.tanODESieve
+tanODESieve :: (Field.C a) => [a]
 tanODESieve =
    -- sieve is too strict here because it wants to detect end of lists
    let tan2 = map head (iterate (drop 2) (tail tanODESieve))
@@ -126,9 +159,11 @@
 atan' x == 1/(1+x^2)
 -}
 
-logODE, recipCircle, asinODE, atanODE, sqrtODE :: (Field.C a) => [a]
+logODE, recipCircle, atanODE, sqrtODE :: (Field.C a) => [a]
 logODE  = PS.integrate zero recip
 recipCircle = intersperse zero (PS.alternate (powODE (-1/2)))
+-- | prop> equalTrunc 50 PSE.asinODE (snd $ PS.inv PSE.sinODE)
+asinODE :: (Field.C a) => [a]
 asinODE = PS.integrate 0 recipCircle
 atanODE = PS.integrate zero (cycle [1,0,-1,0])
 sqrtODE = powODE (1/2)
diff --git a/src/MathObj/PowerSeries/Mean.hs b/src/MathObj/PowerSeries/Mean.hs
--- a/src/MathObj/PowerSeries/Mean.hs
+++ b/src/MathObj/PowerSeries/Mean.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 This module computes power series for
 representing some means as generalized $f$-means.
diff --git a/src/MathObj/PowerSeries2.hs b/src/MathObj/PowerSeries2.hs
--- a/src/MathObj/PowerSeries2.hs
+++ b/src/MathObj/PowerSeries2.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 
@@ -19,11 +19,6 @@
 import qualified Algebra.Additive       as Additive
 import qualified Algebra.ZeroTestable   as ZeroTestable
 
-{-
-import qualified NumericPrelude.Numeric as NP
-import qualified NumericPrelude.Base as P
--}
-
 import Data.List (isPrefixOf, )
 import qualified Data.List.Match as Match
 
@@ -86,6 +81,11 @@
 const x = lift0 [[x]]
 
 
+{-# INLINE truncate #-}
+truncate :: Int -> T a -> T a
+truncate n = lift1 (take n)
+
+
 instance Functor T where
    fmap f (Cons xs) = Cons (map (map f) xs)
 
@@ -124,5 +124,4 @@
 
 instance (Algebraic.C a) => Algebraic.C (T a) where
    sqrt   = lift1 (Core.sqrt Algebraic.sqrt)
---   x ^/ y = lift1 (Core.pow (Algebraic.^/ y)
---                       (fromRational' y)) x
+   x ^/ y = lift1 (Core.pow (Algebraic.^/ y) (fromRational' y)) x
diff --git a/src/MathObj/PowerSeries2/Core.hs b/src/MathObj/PowerSeries2/Core.hs
--- a/src/MathObj/PowerSeries2/Core.hs
+++ b/src/MathObj/PowerSeries2/Core.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module MathObj.PowerSeries2.Core where
 
 import qualified MathObj.PowerSeries as PS
@@ -11,7 +11,6 @@
 import qualified Algebra.Additive       as Additive
 
 import NumericPrelude.Base
--- import NumericPrelude.Numeric hiding (negate, sqrt, )
 
 
 type T a = [[a]]
@@ -59,6 +58,11 @@
    lift1fromPowerSeries $
    PSCore.sqrt (PS.const . (\[x] -> fSqRt x) . PS.coeffs)
 
+pow :: (Field.C a) =>
+   (a -> a) -> a -> T a -> T a
+pow fPow expon =
+   lift1fromPowerSeries $
+   PSCore.pow (PS.const . (\[x] -> fPow x) . PS.coeffs) (PS.const expon)
 
 
 swapVariables :: T a -> T a
diff --git a/src/MathObj/PowerSum.hs b/src/MathObj/PowerSum.hs
--- a/src/MathObj/PowerSum.hs
+++ b/src/MathObj/PowerSum.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
diff --git a/src/MathObj/RefinementMask2.hs b/src/MathObj/RefinementMask2.hs
--- a/src/MathObj/RefinementMask2.hs
+++ b/src/MathObj/RefinementMask2.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module MathObj.RefinementMask2 (
    T, coeffs, fromCoeffs,
    fromPolynomial,
@@ -29,6 +29,43 @@
 import NumericPrelude.Numeric
 
 
+{- $setup
+>>> import qualified MathObj.RefinementMask2 as Mask
+>>> import qualified MathObj.Polynomial      as Poly
+>>> import qualified MathObj.Polynomial.Core as PolyCore
+>>>
+>>> import qualified Algebra.Differential as D
+>>> import qualified Algebra.Ring as Ring
+>>> import Test.NumericPrelude.Utility ((/\))
+>>> import qualified Test.QuickCheck as QC
+>>> import NumericPrelude.Numeric as NP
+>>> import NumericPrelude.Base as P
+>>> import Prelude ()
+>>>
+>>> import Data.Function.HT (nest)
+>>> import Data.Maybe (fromMaybe)
+>>>
+>>>
+>>> hasMultipleZero :: (Ring.C a, Eq a) => Int -> a -> Poly.T a -> Bool
+>>> hasMultipleZero n x poly =
+>>>    all (zero==) $ take n $
+>>>    map (flip Poly.evaluate x) $
+>>>    iterate D.differentiate poly
+>>>
+>>> genAdmissibleMask :: QC.Gen (Mask.T Rational, Poly.T Rational)
+>>> genAdmissibleMask =
+>>>    QC.suchThatMap QC.arbitrary $
+>>>       \mask -> fmap ((,) mask) $ Mask.toPolynomial mask
+>>>
+>>> polyFromMask :: Mask.T a -> Poly.T a
+>>> polyFromMask = Poly.fromCoeffs . Mask.coeffs
+>>>
+>>> genShortPolynomial :: Int -> QC.Gen (Poly.T Rational)
+>>> genShortPolynomial n =
+>>>    fmap (Poly.fromCoeffs . PolyCore.normalize . take n) $ QC.arbitrary
+-}
+
+
 newtype T a = Cons {coeffs :: [a]}
 
 
@@ -85,6 +122,11 @@
 p2 = L * R^(-1) * m
 
 R * L^(-1) * p2 = m
+
+
+prop> genAdmissibleMask /\ \(mask,poly) -> hasMultipleZero (fromMaybe 0 $ Poly.degree poly) 1 (polyFromMask (Mask.fromPolynomial poly) - polyFromMask mask)
+
+prop> genShortPolynomial 5 /\ \poly -> maybe False (Poly.collinear poly) $ Mask.toPolynomial $ Mask.fromPolynomial poly
 -}
 fromPolynomial ::
    (Field.C a) => Poly.T a -> T a
@@ -115,6 +157,9 @@
 {- |
 If the mask does not sum up to a power of @1/2@
 then the function returns 'Nothing'.
+
+>>> fmap ((6::Rational) *>) $ Mask.toPolynomial (Mask.fromCoeffs [0.1, 0.02, 0.005::Rational])
+Just (Polynomial.fromCoeffs [-12732 % 109375,272 % 625,-18 % 25,1 % 1])
 -}
 toPolynomial ::
    (RealField.C a) => T a -> Maybe (Poly.T a)
@@ -131,10 +176,6 @@
                    in  ip + Poly.const (correctConstant (fmap (k/s*) mask) ip))
                 (Poly.const 1) ks0
           _ -> Nothing
-{-
-> fmap (6 Vector.*>) $ toPolynomial (Cons [0.1, 0.02, 0.005::Rational])
-Just (Polynomial.fromCoeffs [-12732 % 109375, 272 % 625, -18 % 25, 1 % 1])
--}
 
 {-
 The constant term must be zero,
@@ -162,17 +203,18 @@
                 (Poly.const 1) ks0
           _ -> Nothing
 
+{- |
+prop> genShortPolynomial 5 /\ \poly -> poly == Mask.refinePolynomial (Mask.fromPolynomial poly) poly
+
+>>> fmap (round :: Double -> Integer) $ fmap (1000000*) $ nest 50 (Mask.refinePolynomial (Mask.fromCoeffs [0.1, 0.02, 0.005])) (Poly.fromCoeffs [0,0,0,1])
+Polynomial.fromCoeffs [-116407,435200,-720000,1000000]
+-}
 refinePolynomial ::
    (Ring.C a) => T a -> Poly.T a -> Poly.T a
 refinePolynomial mask =
    Poly.shrink 2 .
    Vector.linearComb (coeffs mask) .
    iterate (Poly.translate 1)
-{-
-> mapM_ print $ take 50 $ iterate (refinePolynomial (Cons [0.1, 0.02, 0.005])) (Poly.fromCoeffs [0,0,0,1::Double])
-...
-Polynomial.fromCoeffs [-0.11640685714285712,0.4351999999999999,-0.7199999999999999,1.0]
--}
 
 convolve ::
    (Ring.C a) => T a -> T a -> T a
diff --git a/src/MathObj/RootSet.hs b/src/MathObj/RootSet.hs
--- a/src/MathObj/RootSet.hs
+++ b/src/MathObj/RootSet.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright   :  (c) Henning Thielemann 2004-2005
 
diff --git a/src/MathObj/Wrapper/Haskell98.hs b/src/MathObj/Wrapper/Haskell98.hs
--- a/src/MathObj/Wrapper/Haskell98.hs
+++ b/src/MathObj/Wrapper/Haskell98.hs
@@ -10,6 +10,7 @@
 import qualified Algebra.Additive as Additive
 import qualified Algebra.Algebraic as Algebraic
 import qualified Algebra.Field as Field
+import qualified Algebra.FloatingPoint as Float
 import qualified Algebra.IntegralDomain as Integral
 import qualified Algebra.PrincipalIdealDomain as PID
 import qualified Algebra.RealField as RealField
@@ -43,7 +44,7 @@
 then @T (Polynomial (MathObj.Wrapper.NumericPrelude.T a))@
 is in 'Ring.C' for all types @a@ that are in 'Ring.C'.
 -}
-newtype T a = Cons a
+newtype T a = Cons {decons :: a}
    deriving
       (Show, Eq, Ord, Ix, Bounded, Enum,
        Num, Integral, Fractional, Floating,
@@ -59,6 +60,15 @@
 lift2 f (Cons a) (Cons b) = Cons (f a b)
 
 
+{-# INLINE unliftF1 #-}
+unliftF1 :: Functor f => (f (T a) -> f (T b)) -> f a -> f b
+unliftF1 f a = fmap decons $ f (fmap Cons a)
+
+{-# INLINE unliftF2 #-}
+unliftF2 :: Functor f => (f (T a) -> f (T b) -> f (T c)) -> f a -> f b -> f c
+unliftF2 f a b = fmap decons $ f (fmap Cons a) (fmap Cons b)
+
+
 instance Functor T where
    {-# INLINE fmap #-}
    fmap f (Cons a) = Cons (f a)
@@ -155,6 +165,21 @@
 
 instance (Real a) => ToRational.C (T a) where
    toRational (Cons a) = Field.fromRational (toRational a)
+
+instance (RealFloat a) => Float.C (T a) where
+   radix = floatRadix . decons
+   digits = floatDigits . decons
+   range = floatRange . decons
+   decode = decodeFloat . decons
+   encode m = Cons . encodeFloat m
+   exponent = exponent . decons
+   significand = lift1 significand
+   scale = lift1 . scaleFloat
+   isNaN = isNaN . decons
+   isInfinite = isInfinite . decons
+   isDenormalized = isDenormalized . decons
+   isNegativeZero = isNegativeZero . decons
+   isIEEE = isIEEE . decons
 
 
 
diff --git a/src/MathObj/Wrapper/NumericPrelude.hs b/src/MathObj/Wrapper/NumericPrelude.hs
--- a/src/MathObj/Wrapper/NumericPrelude.hs
+++ b/src/MathObj/Wrapper/NumericPrelude.hs
@@ -11,6 +11,7 @@
 import qualified Algebra.Additive as Additive
 import qualified Algebra.Algebraic as Algebraic
 import qualified Algebra.Field as Field
+import qualified Algebra.FloatingPoint as Float
 import qualified Algebra.IntegralDomain as Integral
 import qualified Algebra.PrincipalIdealDomain as PID
 import qualified Algebra.RealField as RealField
@@ -51,14 +52,14 @@
 then @T (Polynomial (MathObj.Wrapper.Haskell98.T a))@
 is in 'Num' for all types @a@ that are in 'Num'.
 -}
-newtype T a = Cons a
+newtype T a = Cons {decons :: a}
    deriving
       (Show, Eq, Ord, Ix, Bounded, Enum,
        Ring.C, Additive.C, Field.C, Algebraic.C, Trans.C,
        Integral.C, PID.C, Units.C,
        Absolute.C, ZeroTestable.C,
        RealField.C, RealIntegral.C, RealRing.C, RealTrans.C,
-       ToInteger.C, ToRational.C,
+       ToInteger.C, ToRational.C, Float.C,
        Differential.C)
 
 {-# INLINE lift1 #-}
@@ -151,21 +152,21 @@
    truncate (Cons a) = fromInteger (RealRing.truncate a)
    round (Cons a) = fromInteger (RealRing.round a)
 
-instance (Trans.C a, RealRing.C a, ToRational.C a, Absolute.C a, Ord a, Show a) => RealFloat (T a) where
-   atan2 = atan2
-   floatRadix = unimplemented "floatRadix"
-   floatDigits = unimplemented "floatDigits"
-   floatRange = unimplemented "floatRange"
-   decodeFloat = unimplemented "decodeFloat"
-   encodeFloat = unimplemented "encodeFloat"
-   exponent = unimplemented "exponent"
-   significand = unimplemented "significand"
-   scaleFloat = unimplemented "scaleFloat"
-   isNaN = unimplemented "isNaN"
-   isInfinite = unimplemented "isInfinite"
-   isDenormalized = unimplemented "isDenormalized"
-   isNegativeZero = unimplemented "isNegativeZero"
-   isIEEE = unimplemented "isIEEE"
+instance (RealTrans.C a, Float.C a, ToRational.C a, Absolute.C a, Ord a, Show a) => RealFloat (T a) where
+   atan2 = RealTrans.atan2
+   floatRadix = Float.radix . decons
+   floatDigits = Float.digits . decons
+   floatRange = Float.range . decons
+   decodeFloat = Float.decode . decons
+   encodeFloat m = Cons . Float.encode m
+   exponent = Float.exponent . decons
+   significand = lift1 Float.significand
+   scaleFloat = lift1 . Float.scale
+   isNaN = Float.isNaN . decons
+   isInfinite = Float.isInfinite . decons
+   isDenormalized = Float.isDenormalized . decons
+   isNegativeZero = Float.isNegativeZero . decons
+   isIEEE = Float.isIEEE . decons
 
 {-
 instance Additive.C (T a) where
diff --git a/src/Number/Complex.hs b/src/Number/Complex.hs
--- a/src/Number/Complex.hs
+++ b/src/Number/Complex.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- Rules should be processed -}
@@ -48,12 +48,12 @@
         defltPow,
         )  where
 
--- import qualified Number.Ratio as Ratio
 
 import qualified Algebra.NormedSpace.Euclidean as NormedEuc
 import qualified Algebra.NormedSpace.Sum       as NormedSum
 import qualified Algebra.NormedSpace.Maximum   as NormedMax
 
+import qualified Algebra.OccasionallyScalar as OccScalar
 import qualified Algebra.VectorSpace        as VectorSpace
 import qualified Algebra.Module             as Module
 import qualified Algebra.Vector             as Vector
@@ -81,8 +81,10 @@
 import Control.Applicative (liftA2, )
 
 import Test.QuickCheck (Arbitrary, arbitrary, )
-import Control.Monad (liftM2, )
+import Control.Monad (liftM2, guard, )
 
+import qualified MathObj.Wrapper.Haskell98 as W98
+
 import qualified Prelude as P
 import NumericPrelude.Base
 import NumericPrelude.Numeric hiding (signum, exp, )
@@ -90,7 +92,6 @@
 import Text.Read.HT (readsInfixPrec, )
 
 
--- import qualified Data.Typeable as Ty
 
 infix  6  +:, `Cons`
 
@@ -359,7 +360,14 @@
    {-# INLINE norm #-}
    norm x = max (NormedMax.norm (real x)) (NormedMax.norm (imag x))
 
+instance (Show v, ZeroTestable.C v, Additive.C v, OccScalar.C a v) => OccScalar.C a (T v) where
+   toScalar        = OccScalar.toScalarShow
+   toMaybeScalar x =
+      guard (isZero (imag x)) >>
+      OccScalar.toMaybeScalar (real x)
+   fromScalar      = fromReal . OccScalar.fromScalar
 
+
 {-
   In this implementation the complex plane is structured
   as an orthogonal grid induced by the divisor z'.
@@ -545,29 +553,25 @@
 -}
 
 
-{- * legacy instances -}
-
-{-# INLINE legacyInstance #-}
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
+-- * Haskell 98 legacy instances
 
-instance (Ring.C a, Eq a, Show a) => P.Num (T a) where
+-- legacy instances for use of numeric literals in GHCi
+instance (P.Floating a, Eq a) => P.Num (T a) where
    {-# INLINE fromInteger #-}
-   fromInteger = fromReal . fromInteger
+   fromInteger n = Cons (P.fromInteger n) (P.fromInteger 0)
    {-# INLINE negate #-}
-   negate = negate -- for unary minus
+   negate = W98.unliftF1 Additive.negate
    {-# INLINE (+) #-}
-   (+)    = legacyInstance
+   (+)    = W98.unliftF2 (Additive.+)
    {-# INLINE (*) #-}
-   (*)    = legacyInstance
+   (*)    = W98.unliftF2 (Ring.*)
    {-# INLINE abs #-}
-   abs    = legacyInstance
+   abs    = W98.unliftF1 Absolute.abs
    {-# INLINE signum #-}
-   signum = legacyInstance
+   signum = W98.unliftF1 Absolute.signum
 
-instance (Field.C a, Eq a, Show a) => P.Fractional (T a) where
+instance (P.Floating a, Eq a) => P.Fractional (T a) where
    {-# INLINE fromRational #-}
-   fromRational = fromRational
+   fromRational x = Cons (P.fromRational x) (P.fromInteger 0)
    {-# INLINE (/) #-}
-   (/) = legacyInstance
+   (/) = W98.unliftF2 (Field./)
diff --git a/src/Number/ComplexSquareRoot.hs b/src/Number/ComplexSquareRoot.hs
deleted file mode 100644
--- a/src/Number/ComplexSquareRoot.hs
+++ /dev/null
@@ -1,117 +0,0 @@
-module Number.ComplexSquareRoot where
-
--- import qualified Algebra.Algebraic as Algebraic
-import qualified Algebra.RealField as RealField
-import qualified Algebra.RealRing as RealRing
--- import qualified Algebra.Field as Field
-import qualified Algebra.Ring as Ring
-import qualified Algebra.Additive as Additive
-import qualified Algebra.ZeroTestable as ZeroTestable
-
-import qualified Number.Complex as Complex
-
-import Test.QuickCheck (Arbitrary, arbitrary, )
-
-import Control.Monad (liftM2, )
-
-import qualified NumericPrelude.Numeric as NP
-import NumericPrelude.Numeric hiding (recip, )
-import NumericPrelude.Base
-import Prelude ()
-
-{- |
-Represent the square root of a complex number
-without actually having to compute a square root.
-If the Bool is False,
-then the square root is represented with positive real part
-or zero real part and positive imaginary part.
-If the Bool is True the square root is negated.
--}
-data T a = Cons Bool (Complex.T a)
-   deriving (Show)
-
-{- |
-You must use @fmap@ only for number type conversion.
--}
-instance Functor T where
-   fmap f (Cons n x) = Cons n (fmap f x)
-
-instance (ZeroTestable.C a) => ZeroTestable.C (T a) where
-   isZero (Cons _b s) = isZero s
-
-instance (ZeroTestable.C a, Eq a) => Eq (T a) where
-   (Cons xb xs) == (Cons yb ys) =
-      isZero xs && isZero ys  ||
-      xb==yb && xs==ys
-
-instance (Arbitrary a) => Arbitrary (T a) where
-   arbitrary = liftM2 Cons arbitrary arbitrary
-
-
-fromNumber :: (RealRing.C a) => Complex.T a -> T a
-fromNumber x =
-   Cons
-      (case compare zero (Complex.real x) of
-         LT -> False
-         GT -> True
-         EQ -> Complex.imag x < zero)
-      (x^2)
-
--- htam:Wavelet.DyadicResultant.parityFlip
-toNumber :: (RealRing.C a, Complex.Power a) => T a -> Complex.T a
-toNumber (Cons n x) =
-   case sqrt x of y -> if n then NP.negate y else y
-
-
-one :: (Ring.C a) => T a
-one = Cons False NP.one
-
-inUpperHalfplane :: (Additive.C a, Ord a) => Complex.T a -> Bool
-inUpperHalfplane x =
-   case compare (Complex.imag x) zero of
-      GT -> True
-      LT -> False
-      EQ -> Complex.real x < zero
-
-mul, mulAlt, mulAlt2 :: (RealRing.C a) => T a -> T a -> T a
-mul (Cons xb xs) (Cons yb ys) =
-   let zs = xs*ys
-   in  Cons
-          ((xb /= yb) /=
-             case (inUpperHalfplane xs,
-                   inUpperHalfplane ys,
-                   inUpperHalfplane zs) of
-                (True,True,False) -> True
-                (False,False,True) -> True
-                _ -> False)
-          zs
-
-mulAlt (Cons xb xs) (Cons yb ys) =
-   let zs = xs*ys
-   in  Cons
-          ((xb /= yb) /=
-             let xi = Complex.imag xs
-                 yi = Complex.imag ys
-                 zi = Complex.imag zs
-             in  (xi>=zero) /= (yi>=zero) &&
-                 (xi>=zero) /= (zi>=zero))
-          zs
-
-mulAlt2 (Cons xb xs) (Cons yb ys) =
-   let zs = xs*ys
-   in  Cons
-          ((xb /= yb) /=
-             let xi = Complex.imag xs
-                 yi = Complex.imag ys
-                 zi = Complex.imag zs
-             in  xi*yi<zero && xi*zi<zero)
-          zs
-
-div :: (RealField.C a) => T a -> T a -> T a
-div x y = mul x (recip y)
-
-recip :: (RealField.C a) => T a -> T a
-recip (Cons b s) =
-   Cons
-      (b /= (Complex.imag s == zero && Complex.real s < zero))
-      (NP.recip s)
diff --git a/src/Number/DimensionTerm.hs b/src/Number/DimensionTerm.hs
--- a/src/Number/DimensionTerm.hs
+++ b/src/Number/DimensionTerm.hs
@@ -1,14 +1,6 @@
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2008
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  portable
-
-
 See "Algebra.DimensionTerm".
 -}
 
diff --git a/src/Number/DimensionTerm/SI.hs b/src/Number/DimensionTerm/SI.hs
--- a/src/Number/DimensionTerm/SI.hs
+++ b/src/Number/DimensionTerm/SI.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2003
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  portable
-
 Special physical units: SI unit system
 -}
 
@@ -38,10 +31,8 @@
     SI.exa,   SI.zetta, SI.yotta,
     ) where
 
--- import qualified Algebra.Transcendental      as Trans
 import qualified Algebra.Field               as Field
 
--- import qualified Algebra.DimensionTerm as Dim
 import qualified Number.DimensionTerm  as DN
 import qualified Number.SI.Unit as SI
 
diff --git a/src/Number/FixedPoint.hs b/src/Number/FixedPoint.hs
--- a/src/Number/FixedPoint.hs
+++ b/src/Number/FixedPoint.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Copyright   :  (c) Henning Thielemann 2006
 
@@ -17,14 +17,13 @@
 module Number.FixedPoint where
 
 import qualified Algebra.RealRing    as RealRing
--- import qualified Algebra.Additive       as Additive
--- import qualified Algebra.ZeroTestable   as ZeroTestable
 import qualified Algebra.Transcendental as Trans
 import qualified MathObj.PowerSeries.Example as PSE
 
+import qualified Data.List.Reverse.StrictElement as Rev
 import NumericPrelude.List (mapLast, )
 import Data.Function.HT (powerAssociative, )
-import Data.List.HT (dropWhileRev, padLeft, )
+import Data.List.HT (padLeft)
 import Data.Maybe.HT (toMaybe, )
 import Data.List (transpose, unfoldr, )
 import Data.Char (intToDigit, )
@@ -60,7 +59,7 @@
        basis = ringPower packetSize 10
        (int,frac) = toPositional basis den x
    in  show int ++ "." ++
-          concat (mapLast (dropWhileRev ('0'==))
+          concat (mapLast (Rev.dropWhile ('0'==))
              (map (padLeft '0' packetSize . show) frac))
 
 showPositionalHex :: Integer -> Integer -> String
diff --git a/src/Number/FixedPoint/Check.hs b/src/Number/FixedPoint/Check.hs
--- a/src/Number/FixedPoint/Check.hs
+++ b/src/Number/FixedPoint/Check.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Number.FixedPoint.Check where
 
 import qualified Number.FixedPoint as FP
@@ -176,19 +176,15 @@
 
 
 
--- legacy instances for work with GHCi
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
-
+-- legacy instances for use of numeric literals in GHCi
 instance P98.Num T where
    fromInteger = fromInteger' defltDenominator
-   negate = negate --for unary minus
-   (+)    = legacyInstance
-   (*)    = legacyInstance
-   abs    = legacyInstance
-   signum = legacyInstance
+   negate = negate -- for unary minus
+   (+)    = (+)
+   (*)    = (*)
+   abs    = abs
+   signum = signum
 
 instance P98.Fractional T where
    fromRational = fromRational' defltDenominator . fromRational
-   (/) = legacyInstance
+   (/) = (/)
diff --git a/src/Number/GaloisField2p32m5.hs b/src/Number/GaloisField2p32m5.hs
--- a/src/Number/GaloisField2p32m5.hs
+++ b/src/Number/GaloisField2p32m5.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {- |
 This number type is intended for tests of functions over fields,
@@ -7,11 +7,12 @@
 For 'Rational' this would not be possible.
 
 However, be aware that sums of non-zero elements may yield zero.
-Thus division is not always safe, where it is for rational numbers.
+Thus division is not always defined, where it is for rational numbers.
 -}
 module Number.GaloisField2p32m5 where
 
 import qualified Number.ResidueClass as RC
+import qualified Algebra.ZeroTestable as ZeroTestable
 import qualified Algebra.Module   as Module
 import qualified Algebra.Field    as Field
 import qualified Algebra.Ring     as Ring
@@ -29,6 +30,30 @@
 import NumericPrelude.Numeric
 
 
+{- $setup
+>>> import qualified Number.GaloisField2p32m5 as GF
+>>> import qualified Algebra.Laws as Laws
+>>> import Test.QuickCheck ((==>))
+>>> import NumericPrelude.Numeric
+>>> import NumericPrelude.Base
+>>> import Prelude ()
+>>>
+>>> gf :: GF.T -> GF.T
+>>> gf = id
+-}
+
+{- |
+prop> Laws.identity (+) zero . gf
+prop> Laws.commutative (+) . gf
+prop> Laws.associative (+) . gf
+prop> Laws.inverse (+) negate zero . gf
+prop> \x -> Laws.inverse (+) (x-) (gf x)
+prop> Laws.identity (*) one . gf
+prop> Laws.commutative (*) . gf
+prop> Laws.associative (*) . gf
+prop> \y -> gf y /= zero ==> Laws.inverse (*) recip one y
+prop> \y x -> gf y /= zero ==> Laws.inverse (*) (x/) x y
+-}
 newtype T = Cons {decons :: Word32}
    deriving Eq
 
@@ -90,3 +115,6 @@
 
 instance Module.C T T where
    (*>) = (*)
+
+instance ZeroTestable.C T where
+   isZero x  =  zero == x
diff --git a/src/Number/NonNegative.hs b/src/Number/NonNegative.hs
--- a/src/Number/NonNegative.hs
+++ b/src/Number/NonNegative.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 
 {-
@@ -46,7 +46,6 @@
 
 import qualified Algebra.ToInteger          as ToInteger
 import qualified Algebra.ToRational         as ToRational
--- import Test.QuickCheck (Arbitrary(arbitrary))
 
 import qualified Number.Ratio as R
 
diff --git a/src/Number/NonNegativeChunky.hs b/src/Number/NonNegativeChunky.hs
--- a/src/Number/NonNegativeChunky.hs
+++ b/src/Number/NonNegativeChunky.hs
@@ -24,8 +24,7 @@
 import qualified Numeric.NonNegative.Class as NonNeg98
 
 import qualified Algebra.NonNegative  as NonNeg
-import qualified Algebra.Field        as Field
-import qualified Algebra.Absolute         as Absolute
+import qualified Algebra.Absolute     as Absolute
 import qualified Algebra.Ring         as Ring
 import qualified Algebra.Additive     as Additive
 import qualified Algebra.ToInteger    as ToInteger
@@ -36,6 +35,7 @@
 
 import qualified Algebra.Monoid as Monoid
 import qualified Data.Monoid as Mn98
+import qualified Data.Semigroup as Sg98
 
 import Control.Monad (liftM, liftM2, )
 import Data.Tuple.HT (mapFst, mapSnd, mapPair, )
@@ -44,9 +44,10 @@
 
 import NumericPrelude.Numeric
 import NumericPrelude.Base
-import qualified Prelude as P98 (Num(..), Fractional(..), )
 
+import qualified Prelude as P98
 
+
 {- |
 A chunky non-negative number is a list of non-negative numbers.
 It represents the sum of the list elements.
@@ -283,27 +284,53 @@
 
 
 
-{- * legacy instances -}
+-- * Haskell 98 legacy instances
 
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
+fromChunky98_ :: (NonNeg98.C a) => Chunky98.T a -> T a
+fromChunky98_ = Cons . Chunky98.toChunks
 
-instance (Ring.C a, Eq a, Show a, NonNeg.C a) => P98.Num (T a) where
-   fromInteger = fromNumber . fromInteger
-   negate = Additive.negate -- for unary minus
-   (+)    = legacyInstance
-   (*)    = legacyInstance
-   abs    = legacyInstance
-   signum = legacyInstance
+toChunky98_ :: (NonNeg98.C a) => T a -> Chunky98.T a
+toChunky98_ = Chunky98.fromChunks . decons
 
-instance (Field.C a, Eq a, Show a, NonNeg.C a) => P98.Fractional (T a) where
-   fromRational = fromNumber . fromRational
-   (/) = legacyInstance
+fromNumber_ :: a -> T a
+fromNumber_ = Cons . (:[])
 
+{-# INLINE lift98_1 #-}
+lift98_1 ::
+   (NonNeg98.C a, NonNeg98.C b) =>
+   (Chunky98.T a -> Chunky98.T b) -> T a -> T b
+lift98_1 f a = fromChunky98_ (f (toChunky98_ a))
+
+{-# INLINE lift98_2 #-}
+lift98_2 ::
+   (NonNeg98.C a, NonNeg98.C b, NonNeg98.C c) =>
+   (Chunky98.T a -> Chunky98.T b -> Chunky98.T c) -> T a -> T b -> T c
+lift98_2 f a b = fromChunky98_ (f (toChunky98_ a) (toChunky98_ b))
+
+
+{-# INLINE notImplemented #-}
+notImplemented :: String -> a
+notImplemented name =
+   error $ "Number.NonNegativeChunky: method " ++ name ++ " cannot be implemented"
+
+instance (NonNeg98.C a, P98.Num a) => P98.Num (T a) where
+   fromInteger = fromNumber_ . P98.fromInteger
+   negate = lift98_1 P98.negate
+   (+)    = lift98_2 (P98.+)
+   (*)    = lift98_2 (P98.*)
+   abs    = lift98_1 P98.abs
+   signum = lift98_1 P98.signum
+
+instance (NonNeg98.C a, P98.Fractional a) => P98.Fractional (T a) where
+   fromRational = fromNumber_ . P98.fromRational
+   (/) = notImplemented "(/)"
+
+instance (NonNeg.C a) => Sg98.Semigroup (T a) where
+   (<>) = (Monoid.<*>)
+
 instance (NonNeg.C a) => Mn98.Monoid (T a) where
    mempty  = Monoid.idt
-   mappend = (Monoid.<*>)
+   mappend = (Sg98.<>)
 
 instance (NonNeg.C a) => Monoid.C (T a) where
    idt   = Cons []
diff --git a/src/Number/OccasionallyScalarExpression.hs b/src/Number/OccasionallyScalarExpression.hs
--- a/src/Number/OccasionallyScalarExpression.hs
+++ b/src/Number/OccasionallyScalarExpression.hs
@@ -1,14 +1,7 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2004
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  multi-type parameter classes (vector space)
-
 Physical expressions track the operations made on physical values
 so we are able to give detailed information on how to resolve
 unit violations.
diff --git a/src/Number/PartiallyTranscendental.hs b/src/Number/PartiallyTranscendental.hs
--- a/src/Number/PartiallyTranscendental.hs
+++ b/src/Number/PartiallyTranscendental.hs
@@ -1,10 +1,10 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Define Transcendental functions on arbitrary fields.
 These functions are defined for only a few (in most cases only one) arguments,
-that's why discourage making these types instances of 'Algebra.Transcendental.C'.
+that's why we discourage making these types instances of 'Algebra.Transcendental.C'.
 But instances of 'Algebra.Transcendental.C' can be useful when working with power series.
-If you intent to work with power series with 'Rational' coefficients,
+If you intend to work with power series with 'Rational' coefficients,
 you might consider using @MathObj.PowerSeries.T (Number.PartiallyTranscendental.T Rational)@
 instead of @MathObj.PowerSeries.T Rational@.
 -}
@@ -15,7 +15,6 @@
 import qualified Algebra.Field          as Field
 import qualified Algebra.Ring           as Ring
 import qualified Algebra.Additive       as Additive
--- import qualified Algebra.ZeroTestable   as ZeroTestable
 
 import NumericPrelude.Numeric
 import NumericPrelude.Base
@@ -74,18 +73,15 @@
 
 
 
-legacyInstance :: a
-legacyInstance = error "legacy Ring instance for simple input of numeric literals"
-
-
 instance (P.Num a) => P.Num (T a) where
-   fromInteger n = lift0 $ P.fromInteger n
-   negate = P.negate -- for unary minus
-   (+)    = legacyInstance
-   (*)    = legacyInstance
-   abs    = legacyInstance
-   signum = legacyInstance
+   fromInteger = lift0 . P.fromInteger
+   negate = lift1 P.negate
+   (+)    = lift2 (P.+)
+   (-)    = lift2 (P.-)
+   (*)    = lift2 (P.*)
+   abs    = lift1 P.abs
+   signum = lift1 P.signum
 
-instance (P.Num a) => P.Fractional (T a) where
+instance (P.Fractional a) => P.Fractional (T a) where
    fromRational = P.fromRational
-   (/) = legacyInstance
+   (/) = lift2 (P./)
diff --git a/src/Number/Peano.hs b/src/Number/Peano.hs
--- a/src/Number/Peano.hs
+++ b/src/Number/Peano.hs
@@ -1,6 +1,6 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright    :   (c) Henning Thielemann 2007
+Copyright    :   (c) Henning Thielemann 2007-2012
 Maintainer   :   numericprelude@henning-thielemann.de
 Stability    :   provisional
 Portability  :   portable
@@ -32,14 +32,10 @@
 import Data.Maybe (catMaybes, )
 import Data.Array(Ix(..))
 
-import qualified Prelude     as P98
-{-
-import qualified NumericPrelude.Base as P
-import qualified NumericPrelude.Numeric as NP
--}
 import Data.List.HT (mapAdjacent, shearTranspose, )
 import Data.Tuple.HT (mapFst, )
 
+import qualified Prelude as P98
 import NumericPrelude.Base
 import NumericPrelude.Numeric
 
@@ -403,9 +399,10 @@
 
 
 
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
+{-# INLINE notImplemented #-}
+notImplemented :: String -> a
+notImplemented name =
+   error $ "Number.Peano: method " ++ name ++ " cannot be implemented"
 
 instance P98.Num T where
    fromInteger = Ring.fromInteger
@@ -413,8 +410,8 @@
    (+) = add
    (-) = sub
    (*) = mul
-   signum = legacyInstance
-   abs = legacyInstance
+   abs    = notImplemented "abs"
+   signum = notImplemented "signum"
 
 -- for use with genericLength et.al.
 instance P98.Real T where
diff --git a/src/Number/Physical.hs b/src/Number/Physical.hs
--- a/src/Number/Physical.hs
+++ b/src/Number/Physical.hs
@@ -1,14 +1,7 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2003-2006
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  generic instances
-
 Numeric values combined with abstract Physical Units
 -}
 
@@ -23,7 +16,7 @@
 import qualified Algebra.Transcendental      as Trans
 import qualified Algebra.Algebraic           as Algebraic
 import qualified Algebra.Field               as Field
-import qualified Algebra.Absolute                as Absolute
+import qualified Algebra.Absolute            as Absolute
 import qualified Algebra.Ring                as Ring
 import qualified Algebra.Additive            as Additive
 import qualified Algebra.ZeroTestable        as ZeroTestable
@@ -32,7 +25,8 @@
 
 import qualified Number.Ratio as Ratio
 
-import Control.Monad(guard,liftM,liftM2)
+import Control.Monad (guard, liftM, liftM2, ap)
+import Control.Applicative (Applicative(pure, (<*>)))
 
 import Data.Maybe.HT(toMaybe)
 import Data.Maybe(fromMaybe)
@@ -226,9 +220,13 @@
     then fromScalarSingle (f x)
     else error "Physics.Quantity.Value.fmap: function for scalars, only"
 
+instance Applicative (T a) where
+   (<*>) = ap
+   pure = fromScalarSingle
+
 instance Monad (T i) where
-  (>>=) (Cons xu x) f =
+   (>>=) (Cons xu x) f =
     if Unit.isScalar xu
     then f x
     else error "Physics.Quantity.Value.(>>=): function for scalars, only"
-  return = fromScalarSingle
+   return = pure
diff --git a/src/Number/Physical/Read.hs b/src/Number/Physical/Read.hs
--- a/src/Number/Physical/Read.hs
+++ b/src/Number/Physical/Read.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2004
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  multi-parameter type classes (VectorSpace.hs)
-
 Convert a human readable string to a physical value.
 -}
 
@@ -15,7 +8,6 @@
 import qualified Number.Physical        as Value
 import qualified Number.Physical.UnitDatabase as Db
 import qualified Algebra.VectorSpace as VectorSpace
--- import Algebra.Module((*>))
 import qualified Algebra.Field       as Field
 import qualified Data.Map as Map
 import Data.Map (Map)
diff --git a/src/Number/Physical/Show.hs b/src/Number/Physical/Show.hs
--- a/src/Number/Physical/Show.hs
+++ b/src/Number/Physical/Show.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2004
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  multi-parameter type classes (VectorSpace.hs, Normalization.hs)
-
 Convert a physical value to a human readable string.
 -}
 
diff --git a/src/Number/Physical/Unit.hs b/src/Number/Physical/Unit.hs
--- a/src/Number/Physical/Unit.hs
+++ b/src/Number/Physical/Unit.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2003-2006
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  portable
-
 Abstract Physical Units
 -}
 
@@ -30,8 +23,8 @@
 
    Example: Let the quantity of length (meter, m) be the zeroth dimension
    and let the quantity of time (second, s) be the first dimension,
-   then the composed unit "m_s²" corresponds to the Map
-   [(0,1),(1,-2)]
+   then the composed unit @m/s^2@ corresponds to the Map
+   @[(0,1),(1,-2)]@.
 
    In future I want to have more abstraction here,
    e.g. a type class from the Edison project
@@ -78,7 +71,7 @@
                in  toMaybe (denominator y == 1) (numerator y))
 
 
-{- impossible because Unit.T is a type synonyme but not a data type
+{- impossible because Unit.T is a type synonym but not a data type
 instance Show (Unit.T i) where
   show = show.toVector
 -}
diff --git a/src/Number/Physical/UnitDatabase.hs b/src/Number/Physical/UnitDatabase.hs
--- a/src/Number/Physical/UnitDatabase.hs
+++ b/src/Number/Physical/UnitDatabase.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2003
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  portable
-
 Tools for creating a data base of physical units
 and for extracting data from it
 -}
@@ -16,7 +9,6 @@
 import qualified Number.Physical.Unit as Unit
 import qualified Algebra.Field as Field
 
--- import Algebra.Module((*>))
 import Algebra.NormedSpace.Sum(norm)
 
 import Data.Maybe.HT (toMaybe)
diff --git a/src/Number/Positional.hs b/src/Number/Positional.hs
--- a/src/Number/Positional.hs
+++ b/src/Number/Positional.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2006
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-
-
 Exact Real Arithmetic - Computable reals.
 Inspired by ''The most unreliable technique for computing pi.''
 See also <http://www.haskell.org/haskellwiki/Exact_real_arithmetic> .
@@ -18,7 +11,6 @@
 
 import qualified Algebra.IntegralDomain as Integral
 import qualified Algebra.Ring           as Ring
--- import qualified Algebra.Additive       as Additive
 import qualified Algebra.ToInteger      as ToInteger
 
 import qualified Prelude as P98
@@ -428,7 +420,7 @@
        This would create finite representations
        in some cases (input is finite, and the result is finite)
        but will cause infinite loop otherwise.
-       dropWhileRev (0==) . compressMant bDst
+       Rev.dropWhile (0==) . compressMant bDst
        -}
        cmpr (mag,xs) = (mag - unit, compressMant bSrc xs)
 
@@ -596,20 +588,20 @@
 
 {- * arithmetic -}
 
-fromLaurent :: LPoly.T Int -> T
+fromLaurent :: LPoly.T Digit -> T
 fromLaurent (LPoly.Cons nxe xm) = (NP.negate nxe, xm)
 
-toLaurent :: T -> LPoly.T Int
+toLaurent :: T -> LPoly.T Digit
 toLaurent (xe, xm) = LPoly.Cons (NP.negate xe) xm
 
 liftLaurent2 ::
-   (LPoly.T Int -> LPoly.T Int -> LPoly.T Int) ->
+   (LPoly.T Digit -> LPoly.T Digit -> LPoly.T Digit) ->
       (T -> T -> T)
 liftLaurent2 f x y =
    fromLaurent (f (toLaurent x) (toLaurent y))
 
 liftLaurentMany ::
-   ([LPoly.T Int] -> LPoly.T Int) ->
+   ([LPoly.T Digit] -> LPoly.T Digit) ->
       ([T] -> T)
 liftLaurentMany f =
    fromLaurent . f . map toLaurent
@@ -780,7 +772,9 @@
    let (ye,ym) = until ((>=b) . abs . head . snd)
                        (decreaseExp b)
                        (ye',ym')
-   in  nest 3 trimOnce (compress b (xe-ye, divMant b ym xm))
+   in  if null xm
+         then (xe,xm)
+         else nest 3 trimOnce (compress b (xe-ye, divMant b ym xm))
 
 divMant :: Basis -> Mantissa -> Mantissa -> Mantissa
 divMant _ [] _   = error "Number.Positional: division by zero"
@@ -818,7 +812,7 @@
 Fast division for small integral divisors,
 which occur for instance in summands of power series.
 -}
-divIntMant :: Basis -> Int -> Mantissa -> Mantissa
+divIntMant :: Basis -> Digit -> Mantissa -> Mantissa
 divIntMant b y xInit =
    List.unfoldr (\(r,rxs) ->
              let rb = r*b
@@ -831,7 +825,7 @@
            (0,xInit)
 
 -- this version is simple but ignores the possibility of a terminating result
-divIntMantInf :: Basis -> Int -> Mantissa -> Mantissa
+divIntMantInf :: Basis -> Digit -> Mantissa -> Mantissa
 divIntMantInf b y =
    map fst . tail .
       scanl (\(_,r) x -> divMod (r*b+x) y) (undefined,0) .
@@ -1315,7 +1309,7 @@
 {- |
 Efficient computation of Arcus tangens of an argument of the form @1\/n@.
 -}
-arctanStem :: Basis -> Int -> T
+arctanStem :: Basis -> Digit -> T
 arctanStem b n =
    let x = (0, divIntMant b n [1])
        divN2 = divInt b n . divInt b (-n)
diff --git a/src/Number/Positional/Check.hs b/src/Number/Positional/Check.hs
--- a/src/Number/Positional/Check.hs
+++ b/src/Number/Positional/Check.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2006
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-
-
 Interface to "Number.Positional" which dynamically checks for equal bases.
 -}
 module Number.Positional.Check where
@@ -15,7 +8,6 @@
 
 import qualified Number.Complex as Complex
 
--- import qualified Algebra.Module             as Module
 import qualified Algebra.RealTranscendental as RealTrans
 import qualified Algebra.Transcendental     as Trans
 import qualified Algebra.Algebraic          as Algebraic
@@ -30,7 +22,6 @@
 import qualified Algebra.EqualityDecision as EqDec
 import qualified Algebra.OrderDecision    as OrdDec
 
--- import qualified NumericPrelude.Base as P
 import qualified Prelude     as P98
 
 import NumericPrelude.Base as P
@@ -55,7 +46,7 @@
 and cannot be made unique in finite time.
 This way we avoid infinite carry ripples.
 -}
-data T = Cons {base :: Int, exponent :: Int, mantissa :: Pos.Mantissa}
+data T = Cons {base :: Pos.Basis, exponent :: Int, mantissa :: Pos.Mantissa}
    deriving (Show)
 
 
@@ -81,7 +72,7 @@
    in  prependDigit (fst (head ys)) (Cons b ex digits)
 
 
-prependDigit :: Int -> T -> T
+prependDigit :: Pos.Digit -> T -> T
 prependDigit 0 x = x
 prependDigit x (Cons b ex xs) =
    Cons b (ex+1) (x:xs)
@@ -90,15 +81,15 @@
 
 {- * conversions -}
 
-lift0 :: (Int -> Pos.T) -> T
+lift0 :: (Pos.Basis -> Pos.T) -> T
 lift0 op =
    uncurry (Cons defltBase) (op defltBase)
 
-lift1 :: (Int -> Pos.T -> Pos.T) -> T -> T
+lift1 :: (Pos.Basis -> Pos.T -> Pos.T) -> T -> T
 lift1 op (Cons xb xe xm) =
    uncurry (Cons xb) (op xb (xe, xm))
 
-lift2 :: (Int -> Pos.T -> Pos.T -> Pos.T) -> T -> T -> T
+lift2 :: (Pos.Basis -> Pos.T -> Pos.T -> Pos.T) -> T -> T -> T
 lift2 op (Cons xb xe xm) (Cons yb ye ym) =
    let b = commonBasis xb yb
    in  uncurry (Cons b) (op b (xe, xm) (ye, ym))
@@ -116,11 +107,11 @@
      then xb
      else error "Number.Positional: bases differ"
 
-fromBaseInteger :: Int -> Integer -> T
+fromBaseInteger :: Pos.Basis -> Integer -> T
 fromBaseInteger b n =
    uncurry (Cons b) (Pos.fromBaseInteger b n)
 
-fromBaseRational :: Int -> Rational -> T
+fromBaseRational :: Pos.Basis -> Rational -> T
 fromBaseRational b r =
    uncurry (Cons b) (Pos.fromBaseRational b r)
 
@@ -237,22 +228,18 @@
 
 
 
--- legacy instances for work with GHCi
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
-
+-- legacy instances for use of numeric literals in GHCi
 instance P98.Num T where
    fromInteger = fromBaseInteger defltBase
-   negate = negate --for unary minus
-   (+)    = legacyInstance
-   (*)    = legacyInstance
-   abs    = legacyInstance
-   signum = legacyInstance
+   negate = negate -- for unary minus
+   (+)    = (+)
+   (*)    = (*)
+   abs    = abs
+   signum = signum
 
 instance P98.Fractional T where
    fromRational = fromBaseRational defltBase . fromRational
-   (/) = legacyInstance
+   (/) = (/)
 
 
 {-
diff --git a/src/Number/Quaternion.hs b/src/Number/Quaternion.hs
--- a/src/Number/Quaternion.hs
+++ b/src/Number/Quaternion.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
 {- |
@@ -55,11 +55,9 @@
 import qualified NumericPrelude.Elementwise as Elem
 import Algebra.Additive ((<*>.+), (<*>.-), (<*>.-$), )
 
--- import qualified Data.Typeable as Ty
 import Data.Array (Array, (!))
 import qualified Data.Array as Array
 
--- import qualified Prelude as P
 import NumericPrelude.Base
 import NumericPrelude.Numeric hiding (signum)
 import Text.Show.HT (showsInfixPrec, )
@@ -103,34 +101,34 @@
 
 -- | The conjugate of a quaternion.
 {-# SPECIALISE conjugate :: T Double -> T Double #-}
-conjugate	 :: (Additive.C a) => T a -> T a
+conjugate        :: (Additive.C a) => T a -> T a
 conjugate (Cons r i) =  Cons r (negate i)
 
 -- | Scale a quaternion by a real number.
 {-# SPECIALISE scale :: Double -> T Double -> T Double #-}
-scale		 :: (Ring.C a) => a -> T a -> T a
+scale            :: (Ring.C a) => a -> T a -> T a
 scale r (Cons xr xi) =  Cons (r * xr) (scaleImag r xi)
 
 -- | like Module.*> but without additional class dependency
-scaleImag	 :: (Ring.C a) => a -> (a,a,a) -> (a,a,a)
+scaleImag        :: (Ring.C a) => a -> (a,a,a) -> (a,a,a)
 scaleImag r (xi,xj,xk) =  (r * xi, r * xj, r * xk)
 
 -- | the same as NormedEuc.normSqr but with a simpler type class constraint
-normSqr		 :: (Ring.C a) => T a -> a
+normSqr          :: (Ring.C a) => T a -> a
 normSqr (Cons xr xi) = xr*xr + scalarProduct xi xi
 
-norm		 :: (Algebraic.C a) => T a -> a
+norm             :: (Algebraic.C a) => T a -> a
 norm x = sqrt (normSqr x)
 
 -- | scale a quaternion into a unit quaternion
-normalize	 :: (Algebraic.C a) => T a -> T a
+normalize        :: (Algebraic.C a) => T a -> T a
 normalize x = scale (recip (norm x)) x
 
-scalarProduct	 :: (Ring.C a) => (a,a,a) -> (a,a,a) -> a
+scalarProduct    :: (Ring.C a) => (a,a,a) -> (a,a,a) -> a
 scalarProduct (xi,xj,xk) (yi,yj,yk) =
    xi*yi + xj*yj + xk*yk
 
-crossProduct	 :: (Ring.C a) => (a,a,a) -> (a,a,a) -> (a,a,a)
+crossProduct     :: (Ring.C a) => (a,a,a) -> (a,a,a) -> (a,a,a)
 crossProduct (xi,xj,xk) (yi,yj,yk) =
    (xj*yk - xk*yj, xk*yi - xi*yk, xi*yj - xj*yi)
 
@@ -140,11 +138,11 @@
 @similarity (cos(a\/2) +:: scaleImag (sin(a\/2)) v) (0 +:: x) == (0 +:: y)@
 where @y@ results from rotating @x@ around the axis @v@ by the angle @a@.
 -}
-similarity	 :: (Field.C a) => T a -> T a -> T a
+similarity       :: (Field.C a) => T a -> T a -> T a
 similarity c x = c*x/c
 
 {-
-rotate	 :: (Field.C a) =>
+rotate   :: (Field.C a) =>
       (a,a,a)  {- ^ rotation axis, must be normalized -}
    -> T a
    -> T a
@@ -265,9 +263,9 @@
 instance (Ring.C a) => Ring.C (T a)  where
    {-# SPECIALISE instance Ring.C (T Float) #-}
    {-# SPECIALISE instance Ring.C (T Double) #-}
-   one				=  Cons one zero
-   fromInteger			=  fromReal . fromInteger
-   (Cons xr xi) * (Cons yr yi)	=
+   one                          =  Cons one zero
+   fromInteger                  =  fromReal . fromInteger
+   (Cons xr xi) * (Cons yr yi)  =
        Cons (xr*yr - scalarProduct xi yi)
             (scaleImag xr yi + scaleImag yr xi +
              crossProduct xi yi)
diff --git a/src/Number/Ratio.hs b/src/Number/Ratio.hs
--- a/src/Number/Ratio.hs
+++ b/src/Number/Ratio.hs
@@ -1,7 +1,8 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Module      :  Number.Ratio
-Copyright   :  (c) Henning Thielemann, Dylan Thurston 2006
+Copyright   :  (c) Henning Thielemann 2011-2012
+               (c) Dylan Thurston 2006
 
 Maintainer  :  numericprelude@henning-thielemann.de
 Stability   :  provisional
@@ -11,10 +12,11 @@
 -}
 
 module Number.Ratio
-	(
-	  T((:%), numerator, denominator), (%),
+        (
+          T((:%), numerator, denominator), (%),
           Rational,
           fromValue,
+          recip,
 
           scale,
           split,
@@ -24,6 +26,7 @@
         )  where
 
 import qualified Algebra.PrincipalIdealDomain as PID
+import qualified Algebra.Units                as Unit
 import qualified Algebra.Absolute             as Absolute
 import qualified Algebra.Ring                 as Ring
 import qualified Algebra.Additive             as Additive
@@ -117,7 +120,13 @@
     abs (x:%y)          =  Absolute.abs x :% y
     signum (x:%_)       =  Absolute.signum x :% one
 
+recip :: (ZeroTestable.C a, Unit.C a) => T a -> T a
+recip (x:%y) =
+   if isZero y
+     then error "Ratio.recip: division by zero"
+     else (y * stdUnitInv x) :% stdAssociate x
 
+
 liftOrd :: Ring.C a => (a -> a -> b) -> (T a -> T a -> b)
 liftOrd f (x:%y) (x':%y') = f (x * y') (x' * y)
 
@@ -222,28 +231,54 @@
 
 -- | Necessary when mixing NumericPrelude.Numeric Rationals with Prelude98 Rationals
 
-toRational98 :: (P.Integral a, PID.C a) => T a -> Ratio98.Ratio a
+toRational98 :: (P.Integral a) => T a -> Ratio98.Ratio a
 toRational98 x = numerator x Ratio98.% denominator x
 
+fromRational98 :: (P.Integral a) => Ratio98.Ratio a -> T a
+fromRational98 x = Ratio98.numerator x :% Ratio98.denominator x
 
-legacyInstance :: String -> a
-legacyInstance op =
-   error ("Ratio." ++ op ++ ": legacy Ring instance for simple input of numeric literals")
 
+{-# INLINE lift1 #-}
+lift1 ::
+   (P.Integral a, P.Integral b) =>
+   (Ratio98.Ratio a -> Ratio98.Ratio b) -> T a -> T b
+lift1 f a = fromRational98 (f (toRational98 a))
 
--- instance (P.Num a, PID.C a) => P.Num (T a) where
-instance (P.Num a, PID.C a, Absolute.C a) => P.Num (T a) where
+{-# INLINE lift2 #-}
+lift2 ::
+   (P.Integral a, P.Integral b, P.Integral c) =>
+   (Ratio98.Ratio a -> Ratio98.Ratio b -> Ratio98.Ratio c) -> T a -> T b -> T c
+lift2 f a b = fromRational98 (f (toRational98 a) (toRational98 b))
+
+
+instance (P.Integral a) => P.Num (T a) where
+   fromInteger n = P.fromInteger n :% P.fromInteger 1
+   negate = lift1 P.negate
+   (+)    = lift2 (P.+)
+   (*)    = lift2 (P.*)
+   abs    = lift1 P.abs
+   signum = lift1 P.signum
+
+instance (P.Integral a) => P.Fractional (T a) where
+   fromRational x =
+      P.fromInteger (Ratio98.numerator x) :%
+      P.fromInteger (Ratio98.denominator x)
+   (/) = lift2 (P./)
+   recip = lift1 P.recip
+
+{- causes an import cycle
+instance (P.Integral a) => P.Num (T a) where
    fromInteger n = P.fromInteger n % 1
-   negate = negate -- for unary minus
-   (+)    = legacyInstance "(+)"
-   (*)    = legacyInstance "(*)"
-   abs    = Absolute.abs -- needed for Arbitrary instance of NonNegative.Ratio
-   signum = legacyInstance "signum"
+   negate = W98.unliftF1 P.negate
+   (+)    = W98.unliftF2 (+)
+   (*)    = W98.unliftF2 (*)
+   abs    = W98.unliftF1 abs
+   signum = W98.unliftF1 P.signum
 
--- instance (P.Num a, PID.C a) => P.Fractional (T a) where
-instance (P.Num a, PID.C a, Absolute.C a) => P.Fractional (T a) where
+instance (P.Integral a) => P.Fractional (T a) where
 --   fromRational = Field.fromRational
    fromRational x =
       fromInteger (Ratio98.numerator x) :%
       fromInteger (Ratio98.denominator x)
-   (/) = legacyInstance "(/)"
+   recip = recip
+-}
diff --git a/src/Number/ResidueClass.hs b/src/Number/ResidueClass.hs
--- a/src/Number/ResidueClass.hs
+++ b/src/Number/ResidueClass.hs
@@ -1,10 +1,8 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Number.ResidueClass where
 
 import qualified Algebra.PrincipalIdealDomain as PID
 import qualified Algebra.IntegralDomain as Integral
--- import qualified Algebra.Additive       as Additive
--- import qualified Algebra.ZeroTestable   as ZeroTestable
 
 import NumericPrelude.Base
 import NumericPrelude.Numeric hiding (recip)
diff --git a/src/Number/ResidueClass/Check.hs b/src/Number/ResidueClass/Check.hs
--- a/src/Number/ResidueClass/Check.hs
+++ b/src/Number/ResidueClass/Check.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Number.ResidueClass.Check where
 
 import qualified Number.ResidueClass as Res
@@ -101,18 +101,18 @@
     isZero (Cons _ r)   =  isZero r
 
 instance  (Eq a, Integral.C a) => Additive.C (T a)  where
-    zero		=  error "no generic zero in a residue class, use ResidueClass.zero"
-    (+)			=  lift2 Res.add
-    (-)			=  lift2 Res.sub
-    negate		=  lift1 Res.neg
+    zero                =  error "no generic zero in a residue class, use ResidueClass.zero"
+    (+)                 =  lift2 Res.add
+    (-)                 =  lift2 Res.sub
+    negate              =  lift1 Res.neg
 
 instance  (Eq a, Integral.C a) => Ring.C (T a)  where
-    one			=  error "no generic one in a residue class, use ResidueClass.one"
-    (*)			=  lift2 Res.mul
-    fromInteger		=  error "no generic integer in a residue class, use ResidueClass.fromInteger"
+    one                 =  error "no generic one in a residue class, use ResidueClass.one"
+    (*)                 =  lift2 Res.mul
+    fromInteger         =  error "no generic integer in a residue class, use ResidueClass.fromInteger"
     x^n                 =  Func.powerAssociative (*) (one (modulus x)) x n
 
 instance  (Eq a, PID.C a) => Field.C (T a)  where
-    (/)			=  lift2 Res.divide
+    (/)                 =  lift2 Res.divide
     recip               =  lift1 (flip Res.divide Ring.one)
-    fromRational'	=  error "no conversion from rational to residue class"
+    fromRational'       =  error "no conversion from rational to residue class"
diff --git a/src/Number/ResidueClass/Func.hs b/src/Number/ResidueClass/Func.hs
--- a/src/Number/ResidueClass/Func.hs
+++ b/src/Number/ResidueClass/Func.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Number.ResidueClass.Func where
 
 import qualified Number.ResidueClass as Res
@@ -11,6 +11,9 @@
 import qualified Algebra.EqualityDecision as EqDec
 
 import Algebra.EqualityDecision ((==?), )
+
+import qualified MathObj.Wrapper.Haskell98 as W98
+
 import NumericPrelude.Base
 import NumericPrelude.Numeric hiding (zero, one, )
 
@@ -61,20 +64,20 @@
        Cons (\m -> (x m ==? y m) (eq m) (noteq m))
 
 instance  (Integral.C a) => Additive.C (T a)  where
-    zero		=  zero
-    (+)			=  lift2 Res.add
-    (-)			=  lift2 Res.sub
-    negate		=  lift1 Res.neg
+    zero                =  zero
+    (+)                 =  lift2 Res.add
+    (-)                 =  lift2 Res.sub
+    negate              =  lift1 Res.neg
 
 instance  (Integral.C a) => Ring.C (T a)  where
-    one			=  one
-    (*)			=  lift2 Res.mul
-    fromInteger		=  Number.ResidueClass.Func.fromInteger
+    one                 =  one
+    (*)                 =  lift2 Res.mul
+    fromInteger         =  Number.ResidueClass.Func.fromInteger
 
 instance  (PID.C a) => Field.C (T a)  where
-    (/)			=  lift2 Res.divide
+    (/)                 =  lift2 Res.divide
     recip               =  (NP.one /)
-    fromRational'	=  error "no conversion from rational to residue class"
+    fromRational'       =  error "no conversion from rational to residue class"
 
 
 {-
@@ -82,21 +85,32 @@
 But Prelude.fromInteger requires Prelude.Num instance.
 -}
 
--- legacy instances for work with GHCi
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
+{-# INLINE notImplemented #-}
+notImplemented :: String -> a
+notImplemented name =
+   error $ "ResidueClass.Func: method " ++ name ++ " cannot be implemented"
 
-instance (P.Num a, Integral.C a) => P.Num (T a) where
-   fromInteger = Number.ResidueClass.Func.fromInteger
-   negate = negate --for unary minus
-   (+)    = legacyInstance
-   (*)    = legacyInstance
-   abs    = legacyInstance
-   signum = legacyInstance
 
+lift98_1 :: (W98.T a -> W98.T a -> W98.T a) -> T a -> T a
+lift98_1 f (Cons x) =
+   Cons $ \m -> W98.decons $ f (W98.Cons m) (W98.Cons $ x m)
+
+lift98_2 :: (W98.T a -> W98.T a -> W98.T a -> W98.T a) -> T a -> T a -> T a
+lift98_2 f (Cons x) (Cons y) =
+   Cons $ \m -> W98.decons $ f (W98.Cons m) (W98.Cons $ x m) (W98.Cons $ y m)
+
+
+-- legacy instances for use of numeric literals in GHCi
+instance (P.Integral a) => P.Num (T a) where
+   fromInteger = Cons . P.mod . P.fromInteger
+   negate = lift98_1 Res.neg
+   (+)    = lift98_2 Res.add
+   (*)    = lift98_2 Res.mul
+   abs    = notImplemented "abs"
+   signum = notImplemented "signum"
+
 instance Eq (T a) where
-   (==) = error "ResidueClass.Func: (==) not implemented"
+   (==) = notImplemented "(==)"
 
 instance Show (T a) where
-   show = error "ResidueClass.Func: 'show' not implemented"
+   show = notImplemented "show"
diff --git a/src/Number/ResidueClass/Maybe.hs b/src/Number/ResidueClass/Maybe.hs
--- a/src/Number/ResidueClass/Maybe.hs
+++ b/src/Number/ResidueClass/Maybe.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Number.ResidueClass.Maybe where
 
 import qualified Number.ResidueClass as Res
@@ -69,12 +69,12 @@
         else error "ResidueClass.(==): Incompatible operands"
 
 instance  (Eq a, Integral.C a) => Additive.C (T a)  where
-    zero		=  Cons Nothing zero
-    (+)			=  lift2 Res.add (+)
-    (-)			=  lift2 Res.sub (-)
-    negate (Cons m r)	=  Cons m (negate r)
+    zero                =  Cons Nothing zero
+    (+)                 =  lift2 Res.add (+)
+    (-)                 =  lift2 Res.sub (-)
+    negate (Cons m r)   =  Cons m (negate r)
 
 instance  (Eq a, Integral.C a) => Ring.C (T a)  where
-    one			=  Cons Nothing one
-    (*)			=  lift2 Res.mul (*)
-    fromInteger		=  Cons Nothing . fromInteger
+    one                 =  Cons Nothing one
+    (*)                 =  lift2 Res.mul (*)
+    fromInteger         =  Cons Nothing . fromInteger
diff --git a/src/Number/ResidueClass/Reader.hs b/src/Number/ResidueClass/Reader.hs
--- a/src/Number/ResidueClass/Reader.hs
+++ b/src/Number/ResidueClass/Reader.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module Number.ResidueClass.Reader where
 
 import qualified Number.ResidueClass as Res
@@ -11,10 +11,9 @@
 import NumericPrelude.Base
 import NumericPrelude.Numeric
 
-import Control.Monad (liftM2, liftM4)
--- import Control.Monad.Reader (MonadReader)
+import Control.Monad (liftM, liftM2, liftM4, ap)
+import Control.Applicative (Applicative(pure, (<*>)))
 
--- import qualified Prelude        as P
 import qualified NumericPrelude.Numeric as NP
 
 
@@ -41,9 +40,16 @@
 fromInteger = fromRepresentative . NP.fromInteger
 
 
+instance Functor (T a) where
+   fmap = liftM
+
+instance Applicative (T a) where
+   (<*>) = ap
+   pure = Cons . const
+
 instance Monad (T a) where
    (Cons x) >>= y  =  Cons (\r -> toFunc (y (x r)) r)
-   return = Cons . const
+   return = pure
 
 
 
diff --git a/src/Number/SI.hs b/src/Number/SI.hs
--- a/src/Number/SI.hs
+++ b/src/Number/SI.hs
@@ -1,14 +1,8 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2003-2006
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  portable
-
 Numerical values equipped with SI units.
 This is considered as the user front-end.
 -}
@@ -40,6 +34,8 @@
 
 import Data.Tuple.HT (mapFst, )
 
+import qualified MathObj.Wrapper.Haskell98 as W98
+
 import qualified Prelude as P
 
 import NumericPrelude.Numeric
@@ -47,9 +43,7 @@
 
 
 newtype T a v = Cons (PValue v)
-{- LANGUAGE GeneralizedNewtypeDeriving allows even this
-   deriving (Monad, Functor)
--}
+   deriving (Functor)
 
 type PValue v = Value.T Dimension v
 
@@ -249,21 +243,14 @@
 
 
 
--- legacy instances for work with GHCi
-legacyInstance :: a
-legacyInstance =
-   error "legacy Ring.C instance for simple input of numeric literals"
-
-instance (Ord a, Trans.C a, NormedMax.C a v, P.Num v, Ring.C v) =>
-      P.Num (T a v) where
-   fromInteger = fromInteger
-   negate = negate -- for unary minus
-   (+)    = legacyInstance
-   (*)    = legacyInstance
-   abs    = legacyInstance
-   signum = legacyInstance
+instance (P.Num v) => P.Num (T a v) where
+   fromInteger = fromScalarSingle . P.fromInteger
+   negate = W98.unliftF1 Additive.negate
+   (+)    = W98.unliftF2 (Additive.+)
+   (*)    = W98.unliftF2 (Ring.*)
+   abs    = W98.unliftF1 Absolute.abs
+   signum = W98.unliftF1 Absolute.signum
 
-instance (Ord a, Trans.C a, NormedMax.C a v, P.Num v, Field.C v) =>
-      P.Fractional (T a v) where
-   fromRational = fromRational
-   (/) = legacyInstance
+instance (P.Fractional v) => P.Fractional (T a v) where
+   fromRational = fromScalarSingle . P.fromRational
+   (/) = W98.unliftF2 (Field./)
diff --git a/src/Number/SI/Unit.hs b/src/Number/SI/Unit.hs
--- a/src/Number/SI/Unit.hs
+++ b/src/Number/SI/Unit.hs
@@ -1,12 +1,5 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
-Copyright   :  (c) Henning Thielemann 2003
-License     :  GPL
-
-Maintainer  :  numericprelude@henning-thielemann.de
-Stability   :  provisional
-Portability :  portable
-
 Special physical units: SI unit system
 -}
 
diff --git a/src/NumericPrelude/Base.hs b/src/NumericPrelude/Base.hs
--- a/src/NumericPrelude/Base.hs
+++ b/src/NumericPrelude/Base.hs
@@ -3,11 +3,136 @@
 to reexport items that we want from the standard Prelude.
 -}
 
-module NumericPrelude.Base (module Prelude, ifThenElse, ) where
-import Prelude hiding (
-       Int, Integer, Float, Double, Rational, Num(..), Real(..),
-       Integral(..), Fractional(..), Floating(..), RealFrac(..),
-       RealFloat(..), subtract, even, odd,
-       gcd, lcm, (^), (^^), sum, product,
-       fromIntegral, fromRational, )
+module NumericPrelude.Base (
+   (P.!!),
+   (P.$),
+   (P.$!),
+   (P.&&),
+   (P.++),
+   (P..),
+   (P.=<<),
+   P.Bool(..),
+   P.Bounded(..),
+   P.Char,
+   P.Either(..),
+   P.Enum(..),
+   P.Eq(..),
+   P.FilePath,
+   P.Functor(..),
+   P.IO,
+   P.IOError,
+   P.Maybe(..),
+   P.Monad(..), P.fail,
+   P.Ord(..),
+   P.Ordering(..),
+   P.Read(..),
+   P.ReadS,
+   P.Show(..),
+   P.ShowS,
+   P.String,
+   P.all,
+   P.and,
+   P.any,
+   P.appendFile,
+   P.asTypeOf,
+   P.break,
+   P.concat,
+   P.concatMap,
+   P.const,
+   P.curry,
+   P.cycle,
+   P.drop,
+   P.dropWhile,
+   P.either,
+   P.elem,
+   P.error,
+   P.filter,
+   P.flip,
+   P.foldl,
+   P.foldl1,
+   P.foldr,
+   P.foldr1,
+   P.fst,
+   P.getChar,
+   P.getContents,
+   P.getLine,
+   P.head,
+   P.id,
+   P.init,
+   P.interact,
+   P.ioError,
+   P.iterate,
+   P.last,
+   P.length,
+   P.lex,
+   P.lines,
+   P.lookup,
+   P.map,
+   P.mapM,
+   P.mapM_,
+   P.maximum,
+   P.maybe,
+   P.minimum,
+   P.not,
+   P.notElem,
+   P.null,
+   P.or,
+   P.otherwise,
+   P.print,
+   P.putChar,
+   P.putStr,
+   P.putStrLn,
+   P.read,
+   P.readFile,
+   P.readIO,
+   P.readLn,
+   P.readParen,
+   P.reads,
+   P.realToFrac,
+   P.repeat,
+   P.replicate,
+   P.reverse,
+   P.scanl,
+   P.scanl1,
+   P.scanr,
+   P.scanr1,
+   P.seq,
+   P.sequence,
+   P.sequence_,
+   P.showChar,
+   P.showParen,
+   P.showString,
+   P.shows,
+   P.snd,
+   P.span,
+   P.splitAt,
+   P.tail,
+   P.take,
+   P.takeWhile,
+   P.uncurry,
+   P.undefined,
+   P.unlines,
+   P.until,
+   P.unwords,
+   P.unzip,
+   P.unzip3,
+   P.userError,
+   P.words,
+   P.writeFile,
+   P.zip,
+   P.zip3,
+   P.zipWith,
+   P.zipWith3,
+   (P.||),
+
+   catch,
+   ifThenElse,
+   ) where
+
+import qualified System.IO.Error as IOError
+import qualified Prelude as P
+import Prelude (IO)
 import Data.Bool.HT (ifThenElse, )
+
+catch :: IO a -> (P.IOError -> IO a) -> IO a
+catch = IOError.catchIOError
diff --git a/src/NumericPrelude/List.hs b/src/NumericPrelude/List.hs
--- a/src/NumericPrelude/List.hs
+++ b/src/NumericPrelude/List.hs
@@ -27,7 +27,7 @@
    in  aux
 
 {-
-This is exported Checked.zipWith.
+This is exported as Checked.zipWith.
 We need to define it here in order to prevent an import cycle.
 -}
 zipWithChecked
diff --git a/src/NumericPrelude/List/Checked.hs b/src/NumericPrelude/List/Checked.hs
--- a/src/NumericPrelude/List/Checked.hs
+++ b/src/NumericPrelude/List/Checked.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Some functions that are counterparts of functions from "Data.List"
 using NumericPrelude.Numeric type classes.
@@ -13,7 +13,6 @@
    ) where
 
 import qualified Algebra.ToInteger  as ToInteger
--- import qualified Algebra.Ring       as Ring
 import Algebra.Ring (one, )
 import Algebra.Additive (zero, (-), )
 
diff --git a/src/NumericPrelude/List/Generic.hs b/src/NumericPrelude/List/Generic.hs
--- a/src/NumericPrelude/List/Generic.hs
+++ b/src/NumericPrelude/List/Generic.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 {- |
 Functions that are counterparts of the @generic@ functions in "Data.List"
 using NumericPrelude.Numeric type classes.
diff --git a/src/NumericPrelude/Numeric.hs b/src/NumericPrelude/Numeric.hs
--- a/src/NumericPrelude/Numeric.hs
+++ b/src/NumericPrelude/Numeric.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE RebindableSyntax #-}
 module NumericPrelude.Numeric (
     {- Additive -} (+), (-), negate, zero, subtract, sum, sum1,
     {- ZeroTestable -} isZero,
diff --git a/test/Demo.hs b/test/Demo.hs
new file mode 100644
--- /dev/null
+++ b/test/Demo.hs
@@ -0,0 +1,178 @@
+{-# LANGUAGE RebindableSyntax #-}
+module Main where
+
+import Number.Complex((+:), (-:), )
+import qualified Number.Complex as Complex
+import Number.Physical      as Value
+import Number.SI            as SIValue -- units
+import Number.SI.Unit       as SIUnit  -- unit prefixes
+          (pico, nano, micro, milli, centi, deci,
+           deca, hecto, kilo, mega, giga, tera, peta)
+import Number.OccasionallyScalarExpression as Expr
+
+import qualified Number.NonNegativeChunky as Chunky
+import qualified Number.NonNegative       as NonNegW
+import qualified Number.Positional.Check  as Real
+import qualified Number.FixedPoint.Check  as FixedPoint
+import qualified Number.ResidueClass.Func as ResidueClass
+import qualified Number.Peano             as Peano
+
+import qualified MathObj.Polynomial          as Polynomial
+import qualified MathObj.LaurentPolynomial   as LaurentPolynomial
+import qualified MathObj.PowerSeries         as PowerSeries
+import qualified MathObj.PowerSeries.Example as PowerSeriesExample
+import qualified MathObj.PartialFraction     as PartialFraction
+
+import qualified Algebra.PrincipalIdealDomain as PID
+import qualified Algebra.Field                as Field
+import qualified Algebra.ZeroTestable         as ZeroTestable
+import qualified Algebra.Indexable            as Indexable
+
+import Data.List (genericTake, genericLength)
+
+import NumericPrelude.Base
+import NumericPrelude.Numeric
+
+
+{- * Physical units -}
+
+-- some shorthands for common usage
+type SIDouble  = SIValue.T Double Double
+type SIComplex = SIValue.T Double (Complex.T Double)
+
+{- this advice seems not to be targeted to ghc's interactive mode
+default (SIDouble)
+-}
+
+
+
+
+test :: [SIDouble]
+test =
+   let lengthScales = map (\n->10^-n*meter) [-10..6]
+       areaScales = map (\n->10^-n*meter^2) [-10..6]
+   in  lengthScales ++ map recip lengthScales ++
+       areaScales   ++ map recip areaScales ++
+       map ((meter*gramm/second)^-) [-5..5] ++
+       take 16 (iterate (10*) (10e-10*meter/gramm)) ++
+       [1/meter^2, 1/meter, meter, meter^2,
+        second, hertz,
+        meter*second, second/meter, meter/second, 1/meter/second,
+        volt/meter,newton/meter,
+        gramm]
+
+testComplex :: SIComplex
+testComplex = (2 :: Double) *> (SIValue.fromScalarSingle (3+:4)*milli*second)
+
+testMagnitude :: SIDouble
+testMagnitude = SIValue.lift (Value.lift Complex.magnitude) testComplex
+
+testExpr :: Expr.T Double SIDouble
+testExpr = sin (5 / (3+1) * fromValue meter)
+
+testPrefixes :: [SIDouble]
+testPrefixes =
+   [pico, nano, micro, milli, centi, deci,
+    deca, hecto, kilo, mega, giga, tera, peta]
+
+
+{- * Reals -}
+
+testReal :: String
+testReal = Real.defltShow (sqrt 2 + log 2 * pi)
+
+testComplexReal :: Complex.T Real.T
+testComplexReal = exp (0 +: pi) + exp (0 -: pi)
+
+showReal :: Real.T -> String
+showReal = Real.defltShow
+
+
+{- * Fixed point numbers -}
+
+testFixedPoint :: String
+testFixedPoint = FixedPoint.defltShow (sqrt 2 + log 2 * pi)
+
+showFixedPoint :: FixedPoint.T -> String
+showFixedPoint = FixedPoint.defltShow
+
+
+{- * Residue classes -}
+
+testResidueClass :: Integer
+testResidueClass = ResidueClass.concrete 7 (5*3/2)
+
+polyResidueClass :: (ZeroTestable.C a, Field.C a) =>
+   [a] -> ResidueClass.T (Polynomial.T a)
+polyResidueClass = ResidueClass.fromRepresentative . polynomial
+
+{- That's strange:
+The residue class implementation should constantly compute mod
+and thus should be much faster.
+I assume that this is an effect of missing sharing.
+The functions which represent a residue class are shared,
+but not their values.
+
+*Main> mod (3^3000000) 2 :: Integer
+1
+(2.47 secs, 24541080 bytes)
+*Main> ResidueClass.concrete 2 (3^3000000) :: Integer
+1
+(7.33 secs, 515047072 bytes)
+-}
+
+
+{- * Polynomials and power series -}
+
+polynomial :: [a] -> Polynomial.T a
+polynomial = Polynomial.fromCoeffs
+
+powerSeries :: [a] -> PowerSeries.T a
+powerSeries = PowerSeries.fromCoeffs
+
+laurentPolynomial :: Int -> [a] -> LaurentPolynomial.T a
+laurentPolynomial = LaurentPolynomial.fromShiftCoeffs
+
+tanSeries :: PowerSeries.T Rational
+tanSeries = powerSeries PowerSeriesExample.tan
+
+
+{- * Partial fractions -}
+
+partialFraction :: (PID.C a, Indexable.C a) =>
+   [a] -> a -> PartialFraction.T a
+partialFraction = PartialFraction.fromFactoredFraction
+
+{- |
+An example from wavelet theory: lifting coefficients of the CDF wavelet family.
+-}
+cdfFraction :: PartialFraction.T (Polynomial.T Rational)
+cdfFraction =
+   partialFraction
+      (map polynomial [[-4,1],[0,1],[4,1]])
+      (product (map polynomial [[-2,1],[2,1]]))
+
+{- |
+The same example with different notation,
+that relies on numerical literals being used for polynomials.
+-}
+cdfFractionNum :: PartialFraction.T (Polynomial.T Rational)
+cdfFractionNum =
+   let x = polynomial [0,1]
+   in  partialFraction [x-4,x,x+4] ((x-2)*(x+2))
+
+
+{- * Peano numbers -}
+testPeano :: Peano.T
+testPeano = minimum [Peano.infinity, 2, Peano.infinity, 4]
+
+testPeanoList :: [Char]
+testPeanoList =
+   genericTake (genericLength (repeat 'a') :: Peano.T) ['a'..'z']
+
+testChunky :: Chunky.T NonNegW.Int
+testChunky = (2+3)*(1+5)
+
+
+main :: IO ()
+main = print test
diff --git a/test/Gaussian.hs b/test/Gaussian.hs
deleted file mode 100644
--- a/test/Gaussian.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Main where
-
-import qualified MathObj.Gaussian.Example as Example
-
-main :: IO ()
-main = Example.polyApprox
diff --git a/test/Test.hs b/test/Test.hs
deleted file mode 100644
--- a/test/Test.hs
+++ /dev/null
@@ -1,173 +0,0 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-module Main where
-
-import Number.Complex((+:), (-:), )
-import qualified Number.Complex as Complex
-import Number.Physical      as Value
-import Number.SI            as SIValue -- units
-import Number.SI.Unit       as SIUnit  -- unit prefixes
-          (pico, nano, micro, milli, centi, deci,
-           deca, hecto, kilo, mega, giga, tera, peta)
-import Number.OccasionallyScalarExpression as Expr
-
-import qualified Number.Positional.Check  as Absolute
-import qualified Number.FixedPoint.Check  as FixedPoint
-import qualified Number.ResidueClass.Func as ResidueClass
-import qualified Number.Peano             as Peano
-
-import qualified MathObj.Polynomial          as Polynomial
-import qualified MathObj.LaurentPolynomial   as LaurentPolynomial
-import qualified MathObj.PowerSeries         as PowerSeries
-import qualified MathObj.PowerSeries.Example as PowerSeriesExample
-import qualified MathObj.PartialFraction     as PartialFraction
-
-import qualified Algebra.PrincipalIdealDomain as PID
-import qualified Algebra.Field                as Field
-import qualified Algebra.ZeroTestable         as ZeroTestable
-import qualified Algebra.Indexable            as Indexable
-
-import Data.List (genericTake, genericLength)
-
-import NumericPrelude.Base
-import NumericPrelude.Numeric
-
-
-{- * Physical units -}
-
--- some shorthands for common usage
-type SIDouble  = SIValue.T Double Double
-type SIComplex = SIValue.T Double (Complex.T Double)
-
-{- this advice seems not to be targeted to ghc's interactive mode
-default (SIDouble)
--}
-
-
-
-
-test :: [SIDouble]
-test =
-   let lengthScales = map (\n->10^-n*meter) [-10..6]
-       areaScales = map (\n->10^-n*meter^2) [-10..6]
-   in  lengthScales ++ map recip lengthScales ++
-       areaScales   ++ map recip areaScales ++
-       map ((meter*gramm/second)^-) [-5..5] ++
-       take 16 (iterate (10*) (10e-10*meter/gramm)) ++
-       [1/meter^2, 1/meter, meter, meter^2,
-        second, hertz,
-        meter*second, second/meter, meter/second, 1/meter/second,
-        volt/meter,newton/meter,
-        gramm]
-
-testComplex :: SIComplex
-testComplex = (2 :: Double) *> (SIValue.fromScalarSingle (3+:4)*milli*second)
-
-testMagnitude :: SIDouble
-testMagnitude = SIValue.lift (Value.lift Complex.magnitude) testComplex
-
-testExpr :: Expr.T Double SIDouble
-testExpr = sin (5 / (3+1) * fromValue meter)
-
-testPrefixes :: [SIDouble]
-testPrefixes =
-   [pico, nano, micro, milli, centi, deci,
-    deca, hecto, kilo, mega, giga, tera, peta]
-
-
-{- * Reals -}
-
-testReal :: String
-testReal = Absolute.defltShow (sqrt 2 + log 2 * pi)
-
-testComplexReal :: Complex.T Absolute.T
-testComplexReal = exp (0 +: pi) + exp (0 -: pi)
-
-showReal :: Absolute.T -> String
-showReal = Absolute.defltShow
-
-
-{- * Fixed point numbers -}
-
-testFixedPoint :: String
-testFixedPoint = FixedPoint.defltShow (sqrt 2 + log 2 * pi)
-
-showFixedPoint :: FixedPoint.T -> String
-showFixedPoint = FixedPoint.defltShow
-
-
-{- * Residue classes -}
-
-testResidueClass :: Integer
-testResidueClass = ResidueClass.concrete 7 (5*3/2)
-
-polyResidueClass :: (ZeroTestable.C a, Field.C a) =>
-   [a] -> ResidueClass.T (Polynomial.T a)
-polyResidueClass = ResidueClass.fromRepresentative . polynomial
-
-{- That's strange:
-The residue class implementation should constantly compute mod
-and thus should be much faster.
-I assume that this is an effect of missing sharing.
-The functions which represent a residue class are shared,
-but not their values.
-
-*Main> mod (3^3000000) 2 :: Integer
-1
-(2.47 secs, 24541080 bytes)
-*Main> ResidueClass.concrete 2 (3^3000000) :: Integer
-1
-(7.33 secs, 515047072 bytes)
--}
-
-
-{- * Polynomials and power series -}
-
-polynomial :: [a] -> Polynomial.T a
-polynomial = Polynomial.fromCoeffs
-
-powerSeries :: [a] -> PowerSeries.T a
-powerSeries = PowerSeries.fromCoeffs
-
-laurentPolynomial :: Int -> [a] -> LaurentPolynomial.T a
-laurentPolynomial = LaurentPolynomial.fromShiftCoeffs
-
-tanSeries :: PowerSeries.T Rational
-tanSeries = powerSeries PowerSeriesExample.tan
-
-
-{- * Partial fractions -}
-
-partialFraction :: (PID.C a, Indexable.C a) =>
-   [a] -> a -> PartialFraction.T a
-partialFraction = PartialFraction.fromFactoredFraction
-
-{- |
-An example from wavelet theory: lifting coefficients of the CDF wavelet family.
--}
-cdfFraction :: PartialFraction.T (Polynomial.T Rational)
-cdfFraction =
-   partialFraction
-      (map polynomial [[-4,1],[0,1],[4,1]])
-      (product (map polynomial [[-2,1],[2,1]]))
-
-{- |
-The same example with different notation,
-that relies on numerical literals being used for polynomials.
--}
-cdfFractionNum :: PartialFraction.T (Polynomial.T Rational)
-cdfFractionNum =
-   let x = polynomial [0,1]
-   in  partialFraction [x-4,x,x+4] ((x-2)*(x+2))
-
-
-{- * Peano numbers -}
-testPeano :: Peano.T
-testPeano = minimum [Peano.infinity, 2, Peano.infinity, 4]
-
-testPeanoList :: [Char]
-testPeanoList =
-   genericTake (genericLength (repeat 'a') :: Peano.T) ['a'..'z']
-
-
-main :: IO ()
-main = print test
diff --git a/test/Test/Algebra/Additive.hs b/test/Test/Algebra/Additive.hs
--- a/test/Test/Algebra/Additive.hs
+++ b/test/Test/Algebra/Additive.hs
@@ -1,35 +1,28 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-module Test.Algebra.Additive where
-
-import qualified Algebra.Additive as A
-
-import Test.NumericPrelude.Utility (testUnit, )
-import Test.QuickCheck (Testable, quickCheck, )
-import qualified Test.HUnit as HUnit
-
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
-
+-- Do not edit! Automatically created with doctest-extract from src/Algebra/Additive.hs
+{-# LINE 42 "src/Algebra/Additive.hs" #-}
 
-test ::
-   (Testable t) =>
-   ([Integer] -> t) -> IO ()
-test = quickCheck
+module Test.Algebra.Additive where
 
+import qualified Test.DocTest.Driver as DocTest
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "additive group" $
-   HUnit.TestList $
-   map testUnit $
-   testList
+{-# LINE 43 "src/Algebra/Additive.hs" #-}
+import     qualified Algebra.Additive as A
+import     qualified Test.QuickCheck as QC
 
-testList :: [(String, IO ())]
-testList =
-   ("sum1", test $ \ns n ->
-      A.sum (n:ns) == A.sum1 (n:ns)) :
-   ("sumNestedAssociative", test $ \ns ->
-      A.sum ns == A.sumNestedAssociative ns) :
-   ("sumNestedCommutative", test $ \ns ->
-      A.sum ns == A.sumNestedCommutative ns) :
-   []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "Algebra.Additive:108: "
+{-# LINE 108 "src/Algebra/Additive.hs" #-}
+ DocTest.property
+{-# LINE 108 "src/Algebra/Additive.hs" #-}
+     (\(QC.NonEmpty ns) -> A.sum ns == (A.sum1 ns :: Integer))
+ DocTest.printPrefix "Algebra.Additive:121: "
+{-# LINE 121 "src/Algebra/Additive.hs" #-}
+ DocTest.property
+{-# LINE 121 "src/Algebra/Additive.hs" #-}
+     (\ns -> A.sum ns == (A.sumNestedAssociative ns :: Integer))
+ DocTest.printPrefix "Algebra.Additive:136: "
+{-# LINE 136 "src/Algebra/Additive.hs" #-}
+ DocTest.property
+{-# LINE 136 "src/Algebra/Additive.hs" #-}
+     (\ns -> A.sum ns == (A.sumNestedCommutative ns :: Integer))
diff --git a/test/Test/Algebra/IntegralDomain.hs b/test/Test/Algebra/IntegralDomain.hs
--- a/test/Test/Algebra/IntegralDomain.hs
+++ b/test/Test/Algebra/IntegralDomain.hs
@@ -1,41 +1,41 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-module Test.Algebra.IntegralDomain where
-
-import Algebra.IntegralDomain (roundDown, roundUp, divUp, )
-
-import Test.NumericPrelude.Utility (testUnit, )
-import Test.QuickCheck (Testable, quickCheck, (==>), )
-import qualified Test.HUnit as HUnit
-
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
-
+-- Do not edit! Automatically created with doctest-extract from src/Algebra/IntegralDomain.hs
+{-# LINE 54 "src/Algebra/IntegralDomain.hs" #-}
 
-test ::
-   (Testable t) =>
-   (Integer -> t) -> IO ()
-test = quickCheck
+module Test.Algebra.IntegralDomain where
 
+import qualified Test.DocTest.Driver as DocTest
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "integral domain functions" $
-   HUnit.TestList $
-   map testUnit $
-   testList
+{-# LINE 55 "src/Algebra/IntegralDomain.hs" #-}
+import     Algebra.IntegralDomain (roundDown, roundUp, divUp)
+import     qualified Test.QuickCheck as QC
+import     NumericPrelude.Base as P
+import     NumericPrelude.Numeric as NP
+import     Prelude ()
 
-testList :: [(String, IO ())]
-testList =
-   ("divMod", test $ \n m ->
-      m/=0 ==> let (q,r) = divMod n m in n == q*m+r) :
-   ("divRound", test $ \n m ->
-      m/=0 ==> div n m * m == roundDown n m) :
-   ("divUpRound", test $ \n m ->
-      m/=0 ==> divUp n m * m == roundUp n m) :
-   ("floorLimit", test $ \n m0 ->
-      let m = 1 + abs m0
-          x = roundDown n m
-      in  n-m < x && x <=n) :
-   ("floorCeiling", test $ \n m ->
-      m/=0 ==> - roundDown n m == roundUp (-n) m) :
-   []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "Algebra.IntegralDomain:108: "
+{-# LINE 108 "src/Algebra/IntegralDomain.hs" #-}
+ DocTest.property
+{-# LINE 108 "src/Algebra/IntegralDomain.hs" #-}
+         (\n (QC.NonZero m) -> let (q,r) = divMod n m in n == (q*m+r :: Integer))
+ DocTest.printPrefix "Algebra.IntegralDomain:198: "
+{-# LINE 198 "src/Algebra/IntegralDomain.hs" #-}
+ DocTest.property
+{-# LINE 198 "src/Algebra/IntegralDomain.hs" #-}
+     (\n (QC.NonZero m) -> div n m * m == (roundDown n m :: Integer))
+ DocTest.printPrefix "Algebra.IntegralDomain:208: "
+{-# LINE 208 "src/Algebra/IntegralDomain.hs" #-}
+ DocTest.property
+{-# LINE 208 "src/Algebra/IntegralDomain.hs" #-}
+     (\n (QC.NonZero m) -> divUp n m * m == (roundUp n m :: Integer))
+ DocTest.printPrefix "Algebra.IntegralDomain:209: "
+{-# LINE 209 "src/Algebra/IntegralDomain.hs" #-}
+ DocTest.property
+{-# LINE 209 "src/Algebra/IntegralDomain.hs" #-}
+     (\n (QC.Positive m) -> let x = roundDown n m in  n-m < x && x <= (n :: Integer))
+ DocTest.printPrefix "Algebra.IntegralDomain:210: "
+{-# LINE 210 "src/Algebra/IntegralDomain.hs" #-}
+ DocTest.property
+{-# LINE 210 "src/Algebra/IntegralDomain.hs" #-}
+     (\n (QC.NonZero m) -> - roundDown n m == (roundUp (-n) m :: Integer))
diff --git a/test/Test/Algebra/PrincipalIdealDomain.hs b/test/Test/Algebra/PrincipalIdealDomain.hs
new file mode 100644
--- /dev/null
+++ b/test/Test/Algebra/PrincipalIdealDomain.hs
@@ -0,0 +1,49 @@
+-- Do not edit! Automatically created with doctest-extract from src/Algebra/PrincipalIdealDomain.hs
+{-# LINE 64 "src/Algebra/PrincipalIdealDomain.hs" #-}
+
+module Test.Algebra.PrincipalIdealDomain where
+
+import Test.DocTest.Base
+import qualified Test.DocTest.Driver as DocTest
+
+{-# LINE 65 "src/Algebra/PrincipalIdealDomain.hs" #-}
+import     qualified Algebra.PrincipalIdealDomain as PID
+import     Test.NumericPrelude.Utility ((/\))
+import     qualified Test.QuickCheck as QC
+
+genResidueClass     :: QC.Gen (Integer,Integer)
+genResidueClass     = do
+       m <- fmap QC.getNonZero $ QC.arbitrary
+       a <- QC.choose (min 0 $ 1+m, max 0 $ m-1)
+       return (m,a)
+
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "Algebra.PrincipalIdealDomain:305: "
+{-# LINE 305 "src/Algebra/PrincipalIdealDomain.hs" #-}
+ DocTest.property
+{-# LINE 305 "src/Algebra/PrincipalIdealDomain.hs" #-}
+     (QC.listOf genResidueClass /\ \xs -> case PID.chineseRemainderMulti xs of Nothing -> True; Just (n,b) -> abs n == abs (foldl lcm 1 (map fst xs)) && map snd xs == map (mod b . fst) xs)
+ DocTest.printPrefix "Algebra.PrincipalIdealDomain:306: "
+{-# LINE 306 "src/Algebra/PrincipalIdealDomain.hs" #-}
+ DocTest.property
+{-# LINE 306 "src/Algebra/PrincipalIdealDomain.hs" #-}
+     (\(QC.NonEmpty ms) b -> let xs = map (\(QC.NonZero m) -> (m, mod b m)) ms in case PID.chineseRemainderMulti xs of Nothing -> False; Just (n,c) -> abs n == abs (foldl lcm 1 (map QC.getNonZero ms)) && mod b n == (c::Integer))
+ DocTest.printPrefix "Algebra.PrincipalIdealDomain:298: "
+{-# LINE 298 "src/Algebra/PrincipalIdealDomain.hs" #-}
+ DocTest.example
+{-# LINE 298 "src/Algebra/PrincipalIdealDomain.hs" #-}
+   (PID.chineseRemainderMulti [(100,21), (10000,2021::Integer)])
+  [ExpectedLine [LineChunk "Just (10000,2021)"]]
+ DocTest.printPrefix "Algebra.PrincipalIdealDomain:300: "
+{-# LINE 300 "src/Algebra/PrincipalIdealDomain.hs" #-}
+ DocTest.example
+{-# LINE 300 "src/Algebra/PrincipalIdealDomain.hs" #-}
+   (PID.chineseRemainderMulti [(97,90),(99,10),(100,0::Integer)])
+  [ExpectedLine [LineChunk "Just (960300,100000)"]]
+ DocTest.printPrefix "Algebra.PrincipalIdealDomain:302: "
+{-# LINE 302 "src/Algebra/PrincipalIdealDomain.hs" #-}
+ DocTest.example
+{-# LINE 302 "src/Algebra/PrincipalIdealDomain.hs" #-}
+   (PID.chineseRemainderMulti [(95,30),(97,27),(98,8),(99,1::Integer)])
+  [ExpectedLine [LineChunk "Just (89403930,1000000)"]]
diff --git a/test/Test/Algebra/RealRing.hs b/test/Test/Algebra/RealRing.hs
--- a/test/Test/Algebra/RealRing.hs
+++ b/test/Test/Algebra/RealRing.hs
@@ -1,40 +1,126 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-module Test.Algebra.RealRing where
-
-import qualified Algebra.RealRing as RealRing
-
-import Test.NumericPrelude.Utility (testUnit, )
-import Test.QuickCheck (quickCheck, )
-import qualified Test.HUnit as HUnit
-
-import Data.Tuple.HT (mapFst, )
+-- Do not edit! Automatically created with doctest-extract from src/Algebra/RealRing.hs
+{-# LINE 38 "src/Algebra/RealRing.hs" #-}
 
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
+module Test.Algebra.RealRing where
 
+import qualified Test.DocTest.Driver as DocTest
 
-test :: (Eq a) => (Double -> a) -> (Double -> a) -> IO ()
-test f g =
-   quickCheck (\x -> f x == g x)
+{-# LINE 39 "src/Algebra/RealRing.hs" #-}
+import     qualified Algebra.RealRing as RealRing
+import     Data.Tuple.HT (mapFst)
+import     NumericPrelude.Numeric as NP
+import     NumericPrelude.Base
+import     Prelude ()
 
+infix     4 =~=
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "rounding functions" $
-   HUnit.TestList $
-   map testUnit $
-      ("round",         test RealRing.genericRound    (NP.round :: Double -> Integer)) :
-      ("truncate",      test RealRing.genericTruncate (NP.truncate :: Double -> Integer)) :
-      ("ceiling",       test RealRing.genericCeiling  (NP.ceiling :: Double -> Integer)) :
-      ("floor",         test RealRing.genericFloor    (NP.floor :: Double -> Integer)) :
-      ("fraction",      test RealRing.genericFraction (NP.fraction :: Double -> Double)) :
-      ("splitFraction", test RealRing.genericSplitFraction (NP.splitFraction :: Double -> (Integer, Double))) :
+(=~=)     :: (Eq b) => (a -> b) -> (a -> b) -> a -> Bool
+(f     =~= g) x = f x == g x
 
-{-
-      ("splitFractionId", quickCheck (\x -> (x::Double) == (uncurry (+) $ mapFst fromInteger $ splitFraction x))) :
--}
-      ("splitFractionId", quickCheck (\x ->  uncurry (==) $ mapFst (((x::Double)-) . fromInteger) $ splitFraction x)) :
-      ("splitFractionFloorFraction", quickCheck (\x -> (floor (x::Double) :: Integer, fraction x) == splitFraction x)) :
-      ("fractionBound", quickCheck (\x -> let y = fraction (x::Double) in 0<=y && y<1)) :
-      ("floorCeiling", quickCheck (\x -> negate (floor (x::Double) :: Integer) == ceiling (-x))) :
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "Algebra.RealRing:134: "
+{-# LINE 134 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 134 "src/Algebra/RealRing.hs" #-}
+         (\x -> (x::Rational) == (uncurry (+) $ mapFst fromInteger $ splitFraction x))
+ DocTest.printPrefix "Algebra.RealRing:135: "
+{-# LINE 135 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 135 "src/Algebra/RealRing.hs" #-}
+         (\x -> uncurry (==) $ mapFst (((x::Double)-) . fromInteger) $ splitFraction x)
+ DocTest.printPrefix "Algebra.RealRing:136: "
+{-# LINE 136 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 136 "src/Algebra/RealRing.hs" #-}
+         (\x -> uncurry (==) $ mapFst (((x::Rational)-) . fromInteger) $ splitFraction x)
+ DocTest.printPrefix "Algebra.RealRing:137: "
+{-# LINE 137 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 137 "src/Algebra/RealRing.hs" #-}
+         (\x -> splitFraction x == (floor (x::Double) :: Integer, fraction x))
+ DocTest.printPrefix "Algebra.RealRing:138: "
+{-# LINE 138 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 138 "src/Algebra/RealRing.hs" #-}
+         (\x -> splitFraction x == (floor (x::Rational) :: Integer, fraction x))
+ DocTest.printPrefix "Algebra.RealRing:142: "
+{-# LINE 142 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 142 "src/Algebra/RealRing.hs" #-}
+         (\x -> let y = fraction (x::Double) in 0<=y && y<1)
+ DocTest.printPrefix "Algebra.RealRing:143: "
+{-# LINE 143 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 143 "src/Algebra/RealRing.hs" #-}
+         (\x -> let y = fraction (x::Rational) in 0<=y && y<1)
+ DocTest.printPrefix "Algebra.RealRing:147: "
+{-# LINE 147 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 147 "src/Algebra/RealRing.hs" #-}
+         (\x -> ceiling (-x) == negate (floor (x::Double) :: Integer))
+ DocTest.printPrefix "Algebra.RealRing:148: "
+{-# LINE 148 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 148 "src/Algebra/RealRing.hs" #-}
+         (\x -> ceiling (-x) == negate (floor (x::Rational) :: Integer))
+ DocTest.printPrefix "Algebra.RealRing:564: "
+{-# LINE 564 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 564 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericFloor =~= (NP.floor :: Double -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:565: "
+{-# LINE 565 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 565 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericFloor =~= (NP.floor :: Rational -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:574: "
+{-# LINE 574 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 574 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericCeiling =~= (NP.ceiling :: Double -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:575: "
+{-# LINE 575 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 575 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericCeiling =~= (NP.ceiling :: Rational -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:584: "
+{-# LINE 584 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 584 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericTruncate =~= (NP.truncate :: Double -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:585: "
+{-# LINE 585 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 585 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericTruncate =~= (NP.truncate :: Rational -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:594: "
+{-# LINE 594 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 594 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericRound =~= (NP.round :: Double -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:595: "
+{-# LINE 595 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 595 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericRound =~= (NP.round :: Rational -> Integer))
+ DocTest.printPrefix "Algebra.RealRing:604: "
+{-# LINE 604 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 604 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericFraction =~= (NP.fraction :: Double -> Double))
+ DocTest.printPrefix "Algebra.RealRing:605: "
+{-# LINE 605 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 605 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericFraction =~= (NP.fraction :: Rational -> Rational))
+ DocTest.printPrefix "Algebra.RealRing:614: "
+{-# LINE 614 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 614 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericSplitFraction =~= (NP.splitFraction :: Double -> (Integer,Double)))
+ DocTest.printPrefix "Algebra.RealRing:615: "
+{-# LINE 615 "src/Algebra/RealRing.hs" #-}
+ DocTest.property
+{-# LINE 615 "src/Algebra/RealRing.hs" #-}
+     (RealRing.genericSplitFraction =~= (NP.splitFraction :: Rational -> (Integer,Rational)))
diff --git a/test/Test/MathObj/Gaussian/Bell.hs b/test/Test/MathObj/Gaussian/Bell.hs
--- a/test/Test/MathObj/Gaussian/Bell.hs
+++ b/test/Test/MathObj/Gaussian/Bell.hs
@@ -1,103 +1,157 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE FlexibleInstances #-}
-module Test.MathObj.Gaussian.Bell where
-
-import qualified MathObj.Gaussian.Bell as G
-
-import qualified Algebra.Laws as Laws
+-- Do not edit! Automatically created with doctest-extract from gaussian/MathObj/Gaussian/Bell.hs
+{-# LINE 30 "gaussian/MathObj/Gaussian/Bell.hs" #-}
 
-import qualified Number.Complex as Complex
+module Test.MathObj.Gaussian.Bell where
 
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (Testable, quickCheck, (==>))
-import qualified Test.HUnit as HUnit
+import Test.DocTest.Base
+import qualified Test.DocTest.Driver as DocTest
 
-import Data.Function.HT (nest, )
+{-# LINE 31 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+import     qualified MathObj.Gaussian.Bell as G
+import     qualified Algebra.ZeroTestable as ZeroTestable
+import     qualified Algebra.Laws as Laws
+import     qualified Number.Complex as Complex
+import     Number.Complex ((+:))
+import     NumericPrelude.Base as P
+import     NumericPrelude.Numeric as NP
+import     Prelude ()
+import     qualified Test.QuickCheck as QC
+import     Data.Function.HT (Id, nest)
 
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
+asRational     :: Id (G.T Rational)
+asRational     = id
 
+withRational     :: Id (G.T Rational -> a)
+withRational     = id
 
-simple ::
-   (Testable t) =>
-   (G.T Rational -> t) -> IO ()
-simple = quickCheck
+isConstant     :: ZeroTestable.C a => G.T a -> Bool
+isConstant     (G.Cons _amp _a b c) = isZero b && isZero c
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "polynomial" $
-   HUnit.TestList $
-   map testUnit $
-{-
-      ("convolution, dirac",
-          simple $ Laws.identity (+) zero) :
--}
-      ("convolution, commutative",
-          simple $ Laws.commutative G.convolve) :
-      ("convolution, associative",
-          simple $ Laws.associative G.convolve) :
-      ("convolution by constant function",
-          {-
-          using a G.norm1 we could exactly compute the amplitude
-          of the resulting constant function.
-          -}
-          simple $ \x ->
-             case G.convolve x (G.constant) of
-                G.Cons _amp _a b c -> isZero b && isZero c) :
-      ("multiplication, one",
-          simple $ Laws.identity G.multiply G.constant) :
-      ("multiplication, commutative",
-          simple $ Laws.commutative G.multiply) :
-      ("multiplication, associative",
-          simple $ Laws.associative G.multiply) :
-      ("convolution, multplication, fourier",
-          simple $ \x y ->
-             G.fourier (G.convolve x y)
-              == G.multiply (G.fourier x) (G.fourier y)) :
-      ("convolution via translation",
-          simple $ \x y ->
-             G.convolve x y
-              == G.convolveByTranslation x y) :
-      ("convolution via fourier",
-          simple $ \x y ->
-             G.convolve x y
-              == G.convolveByFourier x y) :
-      ("fourier by translation",
-          simple $ \x -> G.fourier x == G.fourierByTranslation x) :
-      ("fourier reverse",
-          simple $ \x -> nest 2 G.fourier x == G.reverse x) :
-      ("reverse identity",
-          simple $ \x -> nest 2 G.reverse x == x) :
-      ("fourier unit",
-          quickCheck $ G.fourier G.unit == (G.unit :: G.T Rational)) :
-      ("translate additive",
-          simple $ \x a b ->
-             G.translate a (G.translate b x) == G.translate (a+b) x) :
-      ("translateComplex additive",
-          simple $ \x a b ->
-             G.translateComplex a (G.translateComplex b x) == G.translateComplex (a+b) x) :
-      ("translateComplex real",
-          simple $ \x a ->
-             G.translateComplex (Complex.fromReal a) x == G.translate a x) :
-      ("modulate additive",
-          simple $ \x a b ->
-             G.modulate a (G.modulate b x) == G.modulate (a+b) x) :
-      ("commute translate modulate",
-          simple $ \x a b ->
-             G.modulate b (G.translate a x)
-              == G.turn (a*b) (G.translate a (G.modulate b x))) :
-      ("fourier translate",
-          simple $ \x a ->
-             G.fourier (G.translate a x)
-              == G.modulate a (G.fourier x)) :
-      ("dilate multiplicative",
-          simple $ \x a b -> a>0 && b>0 ==>
-             G.dilate a (G.dilate b x) == G.dilate (a*b) x) :
-      ("dilate by shrink",
-          simple $ \x a -> a>0 ==>
-             G.shrink a x == G.dilate (recip a) x) :
-      ("fourier dilate",
-          simple $ \x a -> a>0 ==>
-             G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x))) :
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.Gaussian.Bell:108: "
+{-# LINE 108 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 108 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (Laws.identity G.multiply G.constant . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:109: "
+{-# LINE 109 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 109 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (Laws.commutative G.multiply . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:110: "
+{-# LINE 110 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 110 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (Laws.associative G.multiply . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:152: "
+{-# LINE 152 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 152 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (Laws.commutative G.convolve . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:153: "
+{-# LINE 153 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 153 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (Laws.associative G.convolve . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:161: "
+{-# LINE 161 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 161 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (isConstant . G.convolve G.constant . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:149: "
+{-# LINE 149 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.example
+{-# LINE 149 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+   (let x=G.Cons 2 (1+:3) (4+:5) (7::Rational); y=G.Cons 7 (1+:4) (3+:2) (5::Rational) in G.convolve x y)
+  [ExpectedLine [LineChunk "Cons {amp = 7 % 6, c0 = 13 % 6 +: 55 % 8, c1 = 41 % 12 +: 13 % 4, c2 = 35 % 12}"]]
+ DocTest.printPrefix "MathObj.Gaussian.Bell:200: "
+{-# LINE 200 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 200 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x y -> G.convolve x y == G.convolveByTranslation x y)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:217: "
+{-# LINE 217 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 217 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x y -> G.convolve x y == G.convolveByFourier x y)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:225: "
+{-# LINE 225 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 225 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x y -> G.fourier (G.convolve x y) == G.multiply (G.fourier x) (G.fourier y))
+ DocTest.printPrefix "MathObj.Gaussian.Bell:226: "
+{-# LINE 226 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 226 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x -> nest 2 G.fourier x == G.reverse x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:227: "
+{-# LINE 227 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 227 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (G.fourier G.unit == (asRational G.unit))
+ DocTest.printPrefix "MathObj.Gaussian.Bell:228: "
+{-# LINE 228 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 228 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x a -> G.fourier (G.translate a x) == G.modulate a (G.fourier x))
+ DocTest.printPrefix "MathObj.Gaussian.Bell:229: "
+{-# LINE 229 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 229 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x)))
+ DocTest.printPrefix "MathObj.Gaussian.Bell:244: "
+{-# LINE 244 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 244 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x -> G.fourier x == G.fourierByTranslation x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:312: "
+{-# LINE 312 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 312 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x a b -> G.translate a (G.translate b x) == G.translate (a+b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:326: "
+{-# LINE 326 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 326 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x a b -> G.translateComplex a (G.translateComplex b x) == G.translateComplex (a+b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:327: "
+{-# LINE 327 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 327 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x a -> G.translateComplex (Complex.fromReal a) x == G.translate a x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:341: "
+{-# LINE 341 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 341 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x a b -> G.modulate a (G.modulate b x) == G.modulate (a+b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:342: "
+{-# LINE 342 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 342 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x a b -> G.modulate b (G.translate a x) == G.turn (a*b) (G.translate a (G.modulate b x)))
+ DocTest.printPrefix "MathObj.Gaussian.Bell:361: "
+{-# LINE 361 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 361 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x -> nest 2 G.reverse x == x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:369: "
+{-# LINE 369 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 369 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x (QC.Positive a) (QC.Positive b) -> G.dilate a (G.dilate b x) == G.dilate (a*b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:370: "
+{-# LINE 370 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 370 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.shrink a x == G.dilate (recip a) x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:381: "
+{-# LINE 381 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 381 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.dilate a (G.shrink a x) == x)
+ DocTest.printPrefix "MathObj.Gaussian.Bell:382: "
+{-# LINE 382 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+ DocTest.property
+{-# LINE 382 "gaussian/MathObj/Gaussian/Bell.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.shrink a (G.dilate a x) == x)
diff --git a/test/Test/MathObj/Gaussian/ExponentTuple.hs b/test/Test/MathObj/Gaussian/ExponentTuple.hs
new file mode 100644
--- /dev/null
+++ b/test/Test/MathObj/Gaussian/ExponentTuple.hs
@@ -0,0 +1,26 @@
+-- Do not edit! Automatically created with doctest-extract from gaussian/MathObj/Gaussian/ExponentTuple.hs
+{-# LINE 14 "gaussian/MathObj/Gaussian/ExponentTuple.hs" #-}
+
+module Test.MathObj.Gaussian.ExponentTuple where
+
+import qualified Test.DocTest.Driver as DocTest
+
+{-# LINE 15 "gaussian/MathObj/Gaussian/ExponentTuple.hs" #-}
+import     MathObj.Gaussian.ExponentTuple (HoelderConjugates(HoelderConjugates))
+import     MathObj.Gaussian.ExponentTuple (YoungConjugates(YoungConjugates))
+import     NumericPrelude.Base as P
+import     NumericPrelude.Numeric as NP
+import     Prelude ()
+
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.Gaussian.ExponentTuple:26: "
+{-# LINE 26 "gaussian/MathObj/Gaussian/ExponentTuple.hs" #-}
+ DocTest.property
+{-# LINE 26 "gaussian/MathObj/Gaussian/ExponentTuple.hs" #-}
+     (\(HoelderConjugates p q)  ->  p>=1 && q>=1 && 1/p + 1/q == 1)
+ DocTest.printPrefix "MathObj.Gaussian.ExponentTuple:53: "
+{-# LINE 53 "gaussian/MathObj/Gaussian/ExponentTuple.hs" #-}
+ DocTest.property
+{-# LINE 53 "gaussian/MathObj/Gaussian/ExponentTuple.hs" #-}
+     (\(YoungConjugates p q r)  ->  p>=1 && q>=1 && r>=1 && 1/p + 1/q == 1/r + 1)
diff --git a/test/Test/MathObj/Gaussian/Polynomial.hs b/test/Test/MathObj/Gaussian/Polynomial.hs
--- a/test/Test/MathObj/Gaussian/Polynomial.hs
+++ b/test/Test/MathObj/Gaussian/Polynomial.hs
@@ -1,165 +1,215 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE FlexibleInstances #-}
-module Test.MathObj.Gaussian.Polynomial where
-
-import qualified MathObj.Gaussian.Polynomial as G
-import qualified MathObj.Gaussian.Bell as B
-
-import qualified MathObj.Polynomial as Poly
-
--- import qualified Algebra.Ring           as Ring
-
-import qualified Algebra.Laws as Laws
-
-import qualified Number.Complex as Complex
-
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (Testable, quickCheck, (==>))
-import qualified Test.HUnit as HUnit
+-- Do not edit! Automatically created with doctest-extract from gaussian/MathObj/Gaussian/Polynomial.hs
+{-# LINE 60 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
 
-import qualified Number.NonNegative as NonNeg
-import Data.Function.HT (nest, )
-import Data.Tuple.HT (mapSnd, )
+{-# OPTIONS_GHC -XRebindableSyntax #-}
 
--- import Debug.Trace (trace, )
+module Test.MathObj.Gaussian.Polynomial where
 
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
+import Test.DocTest.Base
+import qualified Test.DocTest.Driver as DocTest
 
+{-# LINE 63 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+import     qualified MathObj.Gaussian.Polynomial as G
+import     qualified MathObj.Gaussian.Bell as Bell
+import     qualified MathObj.Polynomial as Poly
+import     qualified Algebra.Laws as Laws
+import     qualified Number.Complex as Complex
+import     Number.Complex ((+:))
+import     NumericPrelude.Base as P
+import     NumericPrelude.Numeric as NP
+import     qualified Test.QuickCheck as QC
+import     Data.Function.HT (Id, nest)
+import     Data.Tuple.HT (mapSnd)
 
-simple ::
-   (Testable t) =>
-   (G.T Rational -> t) -> IO ()
-simple f =
-   quickCheck (\x -> f (x :: G.T Rational))
+asRational     :: Id (G.T Rational)
+asRational     = id
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "polynomial" $
-   HUnit.TestList $
-   map testUnit $
-   testList
+withRational     :: Id (G.T Rational -> a)
+withRational     = id
 
-testList :: [(String, IO ())]
-testList =
-{-
-      ("convolution, dirac",
-          simple $ Laws.identity (+) zero) :
--}
-      ("convolution, commutative",
-          simple $ Laws.commutative G.convolve) :
---          simple $ \x -> Laws.commutative G.convolve (trace (show x) x)) :
-      ("convolution, associative",
-          simple $ Laws.associative G.convolve) :
-{-
-      ("convolution by differentiation vs. fourier",
-          simple $ \x y ->
-             G.convolveByDifferentiation x y
-              == G.convolveByFourier x y) :
--}
-      ("multiplication, one",
-          simple $ Laws.identity G.multiply G.constant) :
-      ("multiplication, commutative",
-          simple $ Laws.commutative G.multiply) :
-      ("multiplication, associative",
-          simple $ Laws.associative G.multiply) :
-      ("convolution, multplication, fourier",
-          simple $ \x y ->
-             G.fourier (G.convolve x y)
-              == G.multiply (G.fourier x) (G.fourier y)) :
-      ("fourier reverse",
-          simple $ \x -> nest 2 G.fourier x == G.reverse x) :
-      ("reverse identity",
-          simple $ \x -> nest 2 G.reverse x == x) :
-      ("fourier eigenfunction differential",
-          quickCheck $ \m ->
-             m <= 15 ==>
-                let n = NonNeg.toNumber m
-                    x = G.eigenfunctionDifferential n :: G.T Rational
-                    k = Complex.conjugate Complex.imaginaryUnit ^ fromIntegral n
-                in  G.fourier x  ==  G.scaleComplex k x) :
-      ("fourier eigenfunction iterative",
-          quickCheck $ \m ->
-             m <= 15 ==>
-                let n = NonNeg.toNumber m
-                    x = G.eigenfunctionIterative n :: G.T Rational
-                    k = Complex.conjugate Complex.imaginaryUnit ^ fromIntegral n
-                in  G.fourier x  ==  G.scaleComplex k x) :
-{- this does not hold, both functions compute different eigenbases
-      ("fourier eigenfunction diff vs. iterative",
-          quickCheck $ \n ->
-             n <= 15 ==>
-                G.eigenfunctionDifferential n ==
-                (G.eigenfunctionIterative n :: G.T Rational)) :
--}
-      ("translate additive",
-          simple $ \x a b ->
-             G.translate a (G.translate b x) == G.translate (a+b) x) :
-      ("translateComplex additive",
-          simple $ \x a b ->
-             G.translateComplex a (G.translateComplex b x) == G.translateComplex (a+b) x) :
-      ("translateComplex real",
-          simple $ \x a ->
-             G.translateComplex (Complex.fromReal a) x == G.translate a x) :
-      ("modulate additive",
-          simple $ \x a b ->
-             G.modulate a (G.modulate b x) == G.modulate (a+b) x) :
-      ("commute translate modulate",
-          simple $ \x a b ->
-             G.modulate b (G.translate a x)
-              == G.turn (a*b) (G.translate a (G.modulate b x))) :
-      ("fourier translate",
-          simple $ \x a ->
-             G.fourier (G.translate a x)
-              == G.modulate a (G.fourier x)) :
-      ("dilate multiplicative",
-          simple $ \x a b -> a>0 && b>0 ==>
-             G.dilate a (G.dilate b x) == G.dilate (a*b) x) :
-      ("dilate by shrink",
-          simple $ \x a -> a>0 ==>
-             G.shrink a x == G.dilate (recip a) x) :
-      ("fourier dilate",
-          simple $ \x a -> a>0 ==>
-             G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x))) :
-      ("integrate differentiate",
-          simple $ \x ->
-             G.integrate (G.differentiate x) == (zero, x)) :
-      ("differentiate integrate",
-          simple $ \x@(G.Cons b p) ->
-             let (xoff,xint) = G.integrate x
-             in  G.differentiate xint == G.Cons b (p + Poly.const xoff)) :
-      ("fourier differentiate",
-          simple $ \x ->
-             G.fourier (G.differentiate x) ==
-              let y = G.fourier x
-              in  y{G.polynomial =
-                      Poly.fromCoeffs [0, 0 Complex.+: 2] * G.polynomial y}) :
-      ("differentiate convolve",
-          simple $ \x y ->
-             G.convolve (G.differentiate x) y ==
-             G.convolve x (G.differentiate y)) :
-      ("approximate by bells, translate",
-          simple $ \x unit d -> unit/=0 ==>
-             G.approximateByBells unit (G.translateComplex d x) ==
-             map (mapSnd (B.translateComplex d)) (G.approximateByBells unit x)) :
-      ("approximate by bells, dilate",
-          simple $ \x unit d -> unit/=0 && d/=0 ==>
-             G.approximateByBells unit (G.dilate d x) ==
-             map (mapSnd (B.dilate d)) (G.approximateByBells (unit/d) x)) :
-      ("approximate by bells, shrink",
-          simple $ \x unit d -> unit/=0 && d/=0 ==>
-             G.approximateByBells unit (G.shrink d x) ==
-             map (mapSnd (B.shrink d)) (G.approximateByBells (unit*d) x)) :
-      ("approximate by bells, different implementations",
-          quickCheck $ \unit d s p -> unit/=0 ==>
-             G.approximateByBellsAtOnce unit d s (p::Poly.T (Complex.T Rational)) ==
-             G.approximateByBellsByTranslation unit d s p) :
-      []
+mulLinear2i     :: Id (G.T Rational)
+mulLinear2i     x =
+       x{G.polynomial = Poly.fromCoeffs [0, 0+:2] * G.polynomial x}
 
-{-
-inequalities:
+rotateQuarter     :: Int -> Id (G.T Rational)
+rotateQuarter     n =
+       G.scaleComplex (negate Complex.imaginaryUnit ^ fromIntegral n)
 
-Heisenberg's uncertainty relation
-   needs integrals and thus needs product of exponential numbers and roots
--}
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:185: "
+{-# LINE 185 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 185 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (QC.forAll (QC.choose (0,3)) $ \n -> G.eigenfunctionDifferential n == asRational (G.eigenfunctionIterative n))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:193: "
+{-# LINE 193 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 193 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+          (G.eigenfunction0  ==  asRational (G.eigenfunctionDifferential 0))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:198: "
+{-# LINE 198 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 198 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+          (G.eigenfunction1  ==  asRational (G.eigenfunctionDifferential 1))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:203: "
+{-# LINE 203 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 203 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+          (G.eigenfunction2  ==  asRational (G.eigenfunctionDifferential 2))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:208: "
+{-# LINE 208 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 208 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+          (G.eigenfunction3  ==  asRational (G.eigenfunctionDifferential 3))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:215: "
+{-# LINE 215 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 215 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (QC.forAll (QC.choose (0,15)) $ \n -> let x = G.eigenfunctionDifferential n in G.fourier x  ==  rotateQuarter n x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:224: "
+{-# LINE 224 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 224 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (QC.forAll (QC.choose (0,15)) $ \n -> let x = G.eigenfunctionIterative n in G.fourier x  ==  rotateQuarter n x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:246: "
+{-# LINE 246 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 246 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ Laws.identity G.multiply G.constant)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:247: "
+{-# LINE 247 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 247 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ Laws.commutative G.multiply)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:248: "
+{-# LINE 248 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 248 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ Laws.associative G.multiply)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:258: "
+{-# LINE 258 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 258 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ Laws.commutative G.convolve)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:259: "
+{-# LINE 259 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 259 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ Laws.associative G.convolve)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:301: "
+{-# LINE 301 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 301 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x y -> G.fourier (G.convolve x y) == G.multiply (G.fourier x) (G.fourier y))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:302: "
+{-# LINE 302 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 302 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x -> nest 2 G.fourier x == G.reverse x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:303: "
+{-# LINE 303 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 303 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x a -> G.fourier (G.translate a x) == G.modulate a (G.fourier x))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:304: "
+{-# LINE 304 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 304 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x)))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:305: "
+{-# LINE 305 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 305 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x -> G.fourier (G.differentiate x) == mulLinear2i (G.fourier x))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:323: "
+{-# LINE 323 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 323 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x y -> G.convolve (G.differentiate x) y == G.convolve x (G.differentiate y))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:348: "
+{-# LINE 348 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 348 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x -> G.integrate (G.differentiate x) == (zero, x))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:349: "
+{-# LINE 349 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 349 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x@(G.Cons b p) -> let (xoff,xint) = G.integrate x in G.differentiate xint == G.Cons b (p + Poly.const xoff))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:345: "
+{-# LINE 345 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.example
+{-# LINE 345 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+   (snd $ G.integrate $ G.differentiate $ G.Cons Bell.unit (Poly.fromCoeffs [7,7,7,7 :: Complex.T Rational]))
+  [ExpectedLine [LineChunk "Cons {bell = Cons {amp = 1 % 1, c0 = 0 % 1 +: 0 % 1, c1 = 0 % 1 +: 0 % 1, c2 = 1 % 1}, polynomial = Polynomial.fromCoeffs [7 % 1 +: 0 % 1,7 % 1 +: 0 % 1,7 % 1 +: 0 % 1,7 % 1 +: 0 % 1]}"]]
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:409: "
+{-# LINE 409 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 409 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x a b -> G.translate a (G.translate b x) == G.translate (a+b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:416: "
+{-# LINE 416 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 416 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x a b -> G.translateComplex a (G.translateComplex b x) == G.translateComplex (a+b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:417: "
+{-# LINE 417 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 417 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x a -> G.translateComplex (Complex.fromReal a) x == G.translate a x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:426: "
+{-# LINE 426 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 426 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x a b -> G.modulate a (G.modulate b x) == G.modulate (a+b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:427: "
+{-# LINE 427 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 427 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x a b -> G.modulate b (G.translate a x) == G.turn (a*b) (G.translate a (G.modulate b x)))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:442: "
+{-# LINE 442 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 442 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x -> nest 2 G.reverse x == x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:451: "
+{-# LINE 451 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 451 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.Positive a) (QC.Positive b) -> G.dilate a (G.dilate b x) == G.dilate (a*b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:452: "
+{-# LINE 452 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 452 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.shrink a x == G.dilate (recip a) x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:461: "
+{-# LINE 461 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 461 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.dilate a (G.shrink a x) == x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:462: "
+{-# LINE 462 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 462 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.shrink a (G.dilate a x) == x)
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:490: "
+{-# LINE 490 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 490 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.NonZero unit) d -> G.approximateByBells unit (G.translateComplex d x) == map (mapSnd (Bell.translateComplex d)) (G.approximateByBells unit x))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:491: "
+{-# LINE 491 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 491 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.NonZero unit) (QC.NonZero d) -> G.approximateByBells unit (G.dilate d x) == map (mapSnd (Bell.dilate d)) (G.approximateByBells (unit/d) x))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:492: "
+{-# LINE 492 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 492 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (withRational $ \x (QC.NonZero unit) (QC.NonZero d) -> G.approximateByBells unit (G.shrink d x) == map (mapSnd (Bell.shrink d)) (G.approximateByBells (unit*d) x))
+ DocTest.printPrefix "MathObj.Gaussian.Polynomial:512: "
+{-# LINE 512 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 512 "gaussian/MathObj/Gaussian/Polynomial.hs" #-}
+     (\(QC.NonZero unit) d s p0 -> let p = Poly.fromCoeffs $ take 10 p0 in G.approximateByBellsAtOnce unit d s p == G.approximateByBellsByTranslation unit d (s::Rational) p)
diff --git a/test/Test/MathObj/Gaussian/Variance.hs b/test/Test/MathObj/Gaussian/Variance.hs
--- a/test/Test/MathObj/Gaussian/Variance.hs
+++ b/test/Test/MathObj/Gaussian/Variance.hs
@@ -1,227 +1,142 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE FlexibleInstances #-}
-module Test.MathObj.Gaussian.Variance where
-
-import qualified MathObj.Gaussian.Variance as G
-import qualified Number.Root as Root
-
--- import qualified Algebra.Ring           as Ring
-
-import qualified Algebra.Laws as Laws
-
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (Testable, quickCheck, (==>), Arbitrary, arbitrary, )
-import qualified Test.HUnit as HUnit
-
-import Control.Monad (liftM2, liftM3, )
-
-import Data.Function.HT (nest, compose2, )
-
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
-
-
-newtype PositiveInteger = PositiveInteger Integer
-   deriving Show
-
-instance Arbitrary PositiveInteger where
-   arbitrary =
-      fmap (\p -> PositiveInteger $ 1 + abs p) arbitrary
-
-
-{- |
-For @(HoelderConjugates p q)@ it holds
-
-> 1/p + 1/q = 1
--}
-data HoelderConjugates = HoelderConjugates Rational Rational
-   deriving Show
-
-{-
-instance Arbitrary HoelderConjugates where
-   arbitrary = liftM2
-      (\(PositiveInteger p) (PositiveInteger q) ->
-         let s  = 1%p + 1%q
-         in  HoelderConjugates (fromInteger p * s) (fromInteger q * s))
-      arbitrary arbitrary
--}
-instance Arbitrary HoelderConjugates where
-   arbitrary = liftM2
-      (\(PositiveInteger p) (PositiveInteger q) ->
-         let s = p + q
-         in  HoelderConjugates (s % p) (s % q))
-      arbitrary arbitrary
-
-{- |
-For @(YoungConjugates p q r)@ it holds
-
-> 1/p + 1/q = 1/r + 1
--}
-data YoungConjugates = YoungConjugates Rational Rational Rational
-   deriving Show
-
-{-
-Find positive natural numbers @a, b, c, d@ with
-
-> a + b = c + d
-
-and
-
-> d >= a, d >= b, d >= c
-
-then set
-
-> p=d/a, q=d/b, r=d/c
-
-
-a+b<=c
-b+c<=a
-->  2b <= 0
--}
-instance Arbitrary YoungConjugates where
-   arbitrary = liftM3
-      (\(PositiveInteger a0) (PositiveInteger b0) (PositiveInteger c0) ->
-         let guardSwap cond (x,y) =
-                if cond x y then (x,y) else (y,x)
-             {-
-             If a+b<=c, then from b>0 it follows a<c and thus c+b>a.
-             Swapping a and c is enough and we have not to consider more cases.
-             -}
-             (a1,c1) = guardSwap (\a c -> a+b0>c) (a0,c0)
-             b1 = b0
-             d1 = a1+b1-c1
-             ((a2,b2),(c2,d2)) =
-                guardSwap (compose2 (<=) snd)
-                   (guardSwap (<=) (a1,b1),
-                    guardSwap (<=) (c1,d1))
-         in  YoungConjugates (d2%a2) (d2%b2) (d2%c2))
-      arbitrary arbitrary arbitrary
-
-{-
-This is simpler, but may yield exponents smaller than 1.
-
-instance Arbitrary YoungConjugates where
-   arbitrary = liftM3
-      (\(PositiveInteger a0) (PositiveInteger b0) (PositiveInteger c0) ->
-         let {-
-             If a+b<=c, then from b>0 it follows a<c and thus c+b>a.
-             Swapping a and c is enough and we have not to consider more cases.
-             -}
-             (a1,c1) = if a0+b0<=c0 then (c0,a0) else (a0,c0)
-             b1 = b0
-             d1 = a1+b1-c1
-         in  YoungConjugates (d1%a1) (d1%b1) (d1%c1))
-      arbitrary arbitrary arbitrary
--}
+-- Do not edit! Automatically created with doctest-extract from gaussian/MathObj/Gaussian/Variance.hs
+{-# LINE 34 "gaussian/MathObj/Gaussian/Variance.hs" #-}
 
+module Test.MathObj.Gaussian.Variance where
 
-simple ::
-   (Testable t) =>
-   (G.T Rational -> t) -> IO ()
-simple f =
-   quickCheck (\x -> f (x :: G.T Rational))
+import qualified Test.DocTest.Driver as DocTest
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "variance" $
-   HUnit.TestList $
-   map testUnit $
-   testList
+{-# LINE 35 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+import     qualified MathObj.Gaussian.Variance as G
+import     MathObj.Gaussian.ExponentTuple (HoelderConjugates(HoelderConjugates))
+import     MathObj.Gaussian.ExponentTuple (YoungConjugates(YoungConjugates))
+import     qualified Algebra.Laws as Laws
+import     qualified Number.Root as Root
+import     NumericPrelude.Base as P
+import     NumericPrelude.Numeric as NP
+import     Prelude ()
+import     qualified Test.QuickCheck as QC
+import     Data.Function.HT (Id, nest)
 
-testList :: [(String, IO ())]
-testList =
-{-
-      ("convolution, dirac",
-          simple $ Laws.identity (+) zero) :
--}
-      ("convolution, commutative",
-          simple $ Laws.commutative G.convolve) :
-      ("convolution, associative",
-          simple $ Laws.associative G.convolve) :
-      ("multiplication, one",
-          simple $ Laws.identity G.multiply G.constant) :
-      ("multiplication, commutative",
-          simple $ Laws.commutative G.multiply) :
-      ("multiplication, associative",
-          simple $ Laws.associative G.multiply) :
-      ("convolution via fourier",
-          simple $ \x y ->
-             G.fourier (G.convolve x y)
-              == G.multiply (G.fourier x) (G.fourier y)) :
-      ("fourier identity",
-          simple $ \x -> nest 4 G.fourier x == x) :
-      ("dilate multiplicative",
-          simple $ \x a b -> a>0 && b>0 ==>
-             G.dilate a (G.dilate b x) == G.dilate (a*b) x) :
-      ("dilate by shrink",
-          simple $ \x a -> a>0 ==>
-             G.shrink a x == G.dilate (recip a) x) :
-      ("fourier dilate",
-          simple $ \x a -> a>0 ==>
-             G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x))) :
-      ("fourier, unitary",
-          simple $ \x y ->
-             G.scalarProductRoot x y
-              == G.scalarProductRoot (G.fourier x) (G.fourier y)) :
-      ("norm1 vs. normP 1",
-          simple $ \x -> G.norm1Root x == G.normPRoot 1 x) :
-      ("norm2 vs. normP 2",
-          simple $ \x -> G.norm2Root x == G.normPRoot 2 x) :
-{-
-I would have liked to test for a monotony of norms.
-Unfortunately, it does not hold.
+asRational     :: Id (G.T Rational)
+asRational     = id
 
-Means contain a division by the size of the domain.
-Norms do not have this division.
-Means are monotonic with respect to the degree.
-Norms are not.
-We cannot turn the norms into means since the size of the domain
-(the complete real axis) is infinitely large.
-      ("norm monotony",
-          simple $ \x p0 q0 ->
-             let p = 1 + abs p0
-                 q = 1 + abs q0
-             in  case compare p q of
-                    EQ -> G.normPRoot p x == G.normPRoot q x
-                    LT -> G.normPRoot p x <= G.normPRoot q x
-                    GT -> G.normPRoot p x >= G.normPRoot q x) :
+withRational     :: Id (G.T Rational -> a)
+withRational     = id
 
-This should also fail,
-but QuickCheck does not seem to try counterexamples.
-      ("infinity norm upper bound",
-          simple $ \x p0 ->
-             let p = 1 + abs p0
-             in  G.normPRoot p x <= G.normInfRoot x) :
--}
-      ("Cauchy-Schwarz inequality",
-          simple $ \x y ->
-             G.scalarProductRoot x y
-                <= G.norm2Root x `Root.mul` G.norm2Root y) :
-      ("Hoelder conjugates",
-          quickCheck $ \(HoelderConjugates p q) ->
-             p>=1 && q>=1 && 1/p + 1/q == 1) :
-      ("Hoelder inequality with infinity norm",
-          simple $ \x y ->
-             G.scalarProductRoot x y
-                <= G.norm1Root x `Root.mul` G.normInfRoot y) :
-      ("Hoelder inequality",
-          simple $ \x y (HoelderConjugates p q) ->
-             G.scalarProductRoot x y
-                <= G.normPRoot p x `Root.mul` G.normPRoot q y) :
-      ("Young inequality with two infinity norms",
-          simple $ \x y ->
-             G.normInfRoot (G.convolve x y)
-                <= G.norm1Root x `Root.mul` G.normInfRoot y) :
-      ("Young inequality with infinity norm",
-          simple $ \x y (HoelderConjugates p q) ->
-             G.normInfRoot (G.convolve x y)
-                <= G.normPRoot p x `Root.mul` G.normPRoot q y) :
-      ("Young conjugates",
-          quickCheck $ \(YoungConjugates p q r) ->
-             p>=1 && q>=1 && r>=1 && 1/p + 1/q == 1/r + 1) :
-      ("Young inequality",
-          simple $ \x y (YoungConjugates p q r) ->
-             G.normPRoot r (G.convolve x y)
-                <= G.normPRoot p x `Root.mul` G.normPRoot q y) :
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.Gaussian.Variance:95: "
+{-# LINE 95 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 95 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y -> G.scalarProductRoot x y <= G.norm2Root x `Root.mul` G.norm2Root y)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:99: "
+{-# LINE 99 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 99 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y -> G.scalarProductRoot x y <= G.norm1Root x `Root.mul` G.normInfRoot y)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:100: "
+{-# LINE 100 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 100 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y (HoelderConjugates p q) -> G.scalarProductRoot x y <= G.normPRoot p x `Root.mul` G.normPRoot q y)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:108: "
+{-# LINE 108 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 108 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x -> G.norm1Root x == G.normPRoot 1 x)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:114: "
+{-# LINE 114 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 114 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x -> G.norm2Root x == G.normPRoot 2 x)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:186: "
+{-# LINE 186 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 186 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.varianceRational (G.dilate a x) == a^2 * G.varianceRational x)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:187: "
+{-# LINE 187 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 187 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y -> G.varianceRational (G.convolve x y) == G.varianceRational x + G.varianceRational y)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:193: "
+{-# LINE 193 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 193 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (Laws.identity G.multiply G.constant . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:194: "
+{-# LINE 194 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 194 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (Laws.commutative G.multiply . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:195: "
+{-# LINE 195 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 195 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (Laws.associative G.multiply . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:228: "
+{-# LINE 228 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 228 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (Laws.commutative G.convolve . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:229: "
+{-# LINE 229 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 229 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (Laws.associative G.convolve . asRational)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:233: "
+{-# LINE 233 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 233 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y -> G.normInfRoot (G.convolve x y) <= G.norm1Root x `Root.mul` G.normInfRoot y)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:234: "
+{-# LINE 234 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 234 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y (HoelderConjugates p q) -> G.normInfRoot (G.convolve x y) <= G.normPRoot p x `Root.mul` G.normPRoot q y)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:235: "
+{-# LINE 235 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 235 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y (YoungConjugates p q r) -> G.normPRoot r (G.convolve x y) <= G.normPRoot p x `Root.mul` G.normPRoot q y)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:251: "
+{-# LINE 251 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 251 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y -> G.fourier (G.convolve x y) == G.multiply (G.fourier x) (G.fourier y))
+ DocTest.printPrefix "MathObj.Gaussian.Variance:252: "
+{-# LINE 252 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 252 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x -> nest 4 G.fourier x == x)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:253: "
+{-# LINE 253 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 253 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.fourier (G.dilate a x) == G.amplify a (G.shrink a (G.fourier x)))
+ DocTest.printPrefix "MathObj.Gaussian.Variance:254: "
+{-# LINE 254 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 254 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x y -> G.scalarProductRoot x y == G.scalarProductRoot (G.fourier x) (G.fourier y))
+ DocTest.printPrefix "MathObj.Gaussian.Variance:265: "
+{-# LINE 265 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 265 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x (QC.Positive a) (QC.Positive b) -> G.dilate a (G.dilate b x) == G.dilate (a*b) x)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:266: "
+{-# LINE 266 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 266 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.shrink a x == G.dilate (recip a) x)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:273: "
+{-# LINE 273 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 273 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.dilate a (G.shrink a x) == x)
+ DocTest.printPrefix "MathObj.Gaussian.Variance:274: "
+{-# LINE 274 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+ DocTest.property
+{-# LINE 274 "gaussian/MathObj/Gaussian/Variance.hs" #-}
+     (withRational $ \x (QC.Positive a) -> G.shrink a (G.dilate a x) == x)
diff --git a/test/Test/MathObj/Matrix.hs b/test/Test/MathObj/Matrix.hs
--- a/test/Test/MathObj/Matrix.hs
+++ b/test/Test/MathObj/Matrix.hs
@@ -1,103 +1,122 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE FlexibleInstances #-}
-module Test.MathObj.Matrix where
-
-import qualified MathObj.Matrix as Matrix
-
-import qualified Algebra.Ring           as Ring
-
-import qualified Algebra.Laws as Laws
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/Matrix.hs
+{-# LINE 71 "src/MathObj/Matrix.hs" #-}
 
-import qualified Number.NonNegative as NonNeg
+module Test.MathObj.Matrix where
 
-import qualified System.Random as Random
+import qualified Test.DocTest.Driver as DocTest
 
-import Data.Function.HT (nest, )
+{-# LINE 72 "src/MathObj/Matrix.hs" #-}
+import     qualified MathObj.Matrix as Matrix
+import     qualified Algebra.Ring as Ring
+import     qualified Algebra.Laws as Laws
+import     Test.NumericPrelude.Utility ((/\))
+import     qualified Test.QuickCheck as QC
+import     NumericPrelude.Numeric as NP
+import     NumericPrelude.Base as P
+import     Prelude ()
 
-import Test.NumericPrelude.Utility (testUnit, )
-import Test.QuickCheck (quickCheck, )
-import qualified Test.HUnit as HUnit
+import     Control.Monad (replicateM, join)
+import     Control.Applicative (liftA2)
+import     Data.Function.HT (nest)
 
+genDimension     :: QC.Gen Int
+genDimension     = QC.choose (0,20)
 
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
+genMatrixFor     :: (QC.Arbitrary a) => Int -> Int -> QC.Gen (Matrix.T a)
+genMatrixFor     m n =
+       fmap (Matrix.fromList m n) $ replicateM (m*n) QC.arbitrary
 
+genMatrix     :: (QC.Arbitrary a) => QC.Gen (Matrix.T a)
+genMatrix     = join $ liftA2 genMatrixFor genDimension genDimension
 
-type Seed = Int
-type Dimension = NonNeg.Int
+genIntMatrix     :: QC.Gen (Matrix.T Integer)
+genIntMatrix     = genMatrix
 
-random :: Dimension -> Dimension -> Seed -> Matrix.T Integer
-random mn nn seed =
-   fst $
-   Matrix.random (NonNeg.toNumber mn) (NonNeg.toNumber nn) $
-   Random.mkStdGen seed
+genFactorMatrix     :: (QC.Arbitrary a) => Matrix.T a -> QC.Gen (Matrix.T a)
+genFactorMatrix     a = genMatrixFor (Matrix.numColumns a) =<< genDimension
 
+genSameMatrix     :: (QC.Arbitrary a) => Matrix.T a -> QC.Gen (Matrix.T a)
+genSameMatrix     = uncurry genMatrixFor . Matrix.dimension
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "matrix" $
-   HUnit.TestList $
-   map testUnit $
-      ("dimension",
-          quickCheck (\m n a ->
-             (NonNeg.toNumber m, NonNeg.toNumber n) == Matrix.dimension (random m n a))) :
-      ("to and from rows",
-          quickCheck (\m n a' ->
-             let a = random m n a'
-             in  a == Matrix.fromRows (NonNeg.toNumber m) (NonNeg.toNumber n) (Matrix.rows a))) :
-      ("to and from columns",
-          quickCheck (\m n a' ->
-             let a = random m n a'
-             in  a == Matrix.fromColumns (NonNeg.toNumber m) (NonNeg.toNumber n) (Matrix.columns a))) :
-      ("transpose, rows, columns",
-          quickCheck (\m n a' ->
-             let a = random m n a'
-             in  Matrix.rows a == Matrix.columns (Matrix.transpose a))) :
-      ("transpose, columns, rows",
-          quickCheck (\m n a' ->
-             let a = random m n a'
-             in  Matrix.columns a == Matrix.rows (Matrix.transpose a))) :
-      ("addition, zero",
-          quickCheck (\m n a ->
-             Laws.identity (+) (Matrix.zero (NonNeg.toNumber m) (NonNeg.toNumber n)) (random m n a))) :
-      ("addition, commutative",
-          quickCheck (\m n a b ->
-             Laws.commutative (+) (random m n a) (random m n b))) :
-      ("addition, associative",
-          quickCheck (\m n a b c ->
-             Laws.associative (+) (random m n a) (random m n b) (random m n c))) :
-      ("addition, transpose",
-          quickCheck (\m n a b ->
-             Laws.homomorphism Matrix.transpose (+) (+) (random m n a) (random m n b))) :
-      ("one, diagonal",
-          quickCheck (\n' ->
-             let n = NonNeg.toNumber n'
-             in Matrix.one n == (Matrix.diagonal $ replicate n Ring.one :: Matrix.T Integer))) :
-      ("multiplication, one left",
-          quickCheck (\m n a ->
-             Laws.leftIdentity  (*) (Matrix.one (NonNeg.toNumber m)) (random m n a))) :
-      ("multiplication, one right",
-          quickCheck (\m n a ->
-             Laws.rightIdentity (*) (Matrix.one (NonNeg.toNumber n)) (random m n a))) :
-      ("multiplication, associative",
-          quickCheck (\k l m n a b c ->
-             Laws.associative (*) (random k l a) (random l m b) (random m n c))) :
-      ("multiplication and addition, distributive left",
-          quickCheck (\l m n a b c ->
-             Laws.leftDistributive (*) (+) (random n l a) (random m n b) (random m n c))) :
-      ("multiplication and addition, distributive right",
-          quickCheck (\l m n a b c ->
-             Laws.rightDistributive (*) (+) (random l m a) (random m n b) (random m n c))) :
-      ("multiplication, transpose",
-          quickCheck (\l m n a b ->
-             Laws.homomorphism Matrix.transpose (*) (flip (*)) (random l m a) (random m n b))) :
-      ("multiplication vs. power",
-          quickCheck (\m a n0 ->
-             let x = random m m a
-                 n = mod n0 10
-             in  x^n == nest (fromInteger n) (x*) (Matrix.one (NonNeg.toNumber m)))) :
-{-
-      ("division",       quickCheck (\x -> Integral.propInverse (x :: Poly.T Rational))) :
--}
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.Matrix:118: "
+{-# LINE 118 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 118 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> Matrix.rows a == Matrix.columns (Matrix.transpose a))
+ DocTest.printPrefix "MathObj.Matrix:119: "
+{-# LINE 119 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 119 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> Matrix.columns a == Matrix.rows (Matrix.transpose a))
+ DocTest.printPrefix "MathObj.Matrix:120: "
+{-# LINE 120 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 120 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> genSameMatrix a /\ \b -> Laws.homomorphism Matrix.transpose (+) (+) a b)
+ DocTest.printPrefix "MathObj.Matrix:141: "
+{-# LINE 141 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 141 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> a == uncurry Matrix.fromRows (Matrix.dimension a) (Matrix.rows a))
+ DocTest.printPrefix "MathObj.Matrix:152: "
+{-# LINE 152 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 152 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> a == uncurry Matrix.fromColumns (Matrix.dimension a) (Matrix.columns a))
+ DocTest.printPrefix "MathObj.Matrix:195: "
+{-# LINE 195 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 195 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> genSameMatrix a /\ \b -> Laws.commutative (+) a b)
+ DocTest.printPrefix "MathObj.Matrix:196: "
+{-# LINE 196 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 196 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> genSameMatrix a /\ \b -> genSameMatrix b /\ \c -> Laws.associative (+) a b c)
+ DocTest.printPrefix "MathObj.Matrix:212: "
+{-# LINE 212 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 212 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> Laws.identity (+) (uncurry Matrix.zero $ Matrix.dimension a) a)
+ DocTest.printPrefix "MathObj.Matrix:228: "
+{-# LINE 228 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 228 "src/MathObj/Matrix.hs" #-}
+     (genDimension /\ \n -> Matrix.one n == Matrix.diagonal (replicate n Ring.one :: [Integer]))
+ DocTest.printPrefix "MathObj.Matrix:242: "
+{-# LINE 242 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 242 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> Laws.leftIdentity  (*) (Matrix.one (Matrix.numRows a)) a)
+ DocTest.printPrefix "MathObj.Matrix:243: "
+{-# LINE 243 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 243 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> Laws.rightIdentity (*) (Matrix.one (Matrix.numColumns a)) a)
+ DocTest.printPrefix "MathObj.Matrix:244: "
+{-# LINE 244 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 244 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> Laws.homomorphism Matrix.transpose (*) (flip (*)) a b)
+ DocTest.printPrefix "MathObj.Matrix:245: "
+{-# LINE 245 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 245 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> genFactorMatrix b /\ \c -> Laws.associative (*) a b c)
+ DocTest.printPrefix "MathObj.Matrix:246: "
+{-# LINE 246 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 246 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \b -> genSameMatrix b /\ \c -> genFactorMatrix b /\ \a -> Laws.leftDistributive (*) (+) a b c)
+ DocTest.printPrefix "MathObj.Matrix:247: "
+{-# LINE 247 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 247 "src/MathObj/Matrix.hs" #-}
+     (genIntMatrix /\ \a -> genFactorMatrix a /\ \b -> genSameMatrix b /\ \c -> Laws.rightDistributive (*) (+) a b c)
+ DocTest.printPrefix "MathObj.Matrix:248: "
+{-# LINE 248 "src/MathObj/Matrix.hs" #-}
+ DocTest.property
+{-# LINE 248 "src/MathObj/Matrix.hs" #-}
+     (QC.choose (0,10) /\ \k -> genDimension /\ \n -> genMatrixFor n n /\ \a -> a^k == nest (fromInteger k) ((a::Matrix.T Integer)*) (Matrix.one n))
diff --git a/test/Test/MathObj/PartialFraction.hs b/test/Test/MathObj/PartialFraction.hs
--- a/test/Test/MathObj/PartialFraction.hs
+++ b/test/Test/MathObj/PartialFraction.hs
@@ -1,205 +1,137 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE FlexibleInstances #-}
-module Test.MathObj.PartialFraction where
-
-import qualified MathObj.PartialFraction      as PartialFraction
-import qualified MathObj.Polynomial           as Poly
-import qualified Number.Ratio                 as Ratio
-
-import qualified Algebra.PrincipalIdealDomain as PID
--- import qualified Algebra.Ring                 as Ring
-import qualified Algebra.Indexable            as Indexable
-import qualified Algebra.Vector               as Vector
--- import Algebra.Vector((*>))
-
-import qualified Algebra.Laws as Laws
-import qualified Test.QuickCheck as QC
-
-import Control.Monad.HT as M
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (quickCheck)
-import qualified Test.HUnit as HUnit
-
-
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
-
-
-{- * Properties for generic types -}
-
-fractionConv :: (PID.C a, Indexable.C a) => [a] -> a -> Bool
-fractionConv xs y =
-   PartialFraction.toFraction (PartialFraction.fromFactoredFraction xs y) ==
-   y % product xs
-
-fractionConvAlt :: (PID.C a, Indexable.C a) => [a] -> a -> Bool
-fractionConvAlt xs y =
-   PartialFraction.fromFactoredFraction xs y ==
-   PartialFraction.fromFactoredFractionAlt xs y
-
-scaleInt :: (PID.C a, Indexable.C a) => a -> PartialFraction.T a -> Bool
-scaleInt k a =
-   PartialFraction.toFraction (PartialFraction.scaleInt k a) ==
-   Ratio.scale k (PartialFraction.toFraction a)
-
-add :: (PID.C a, Indexable.C a) => PartialFraction.T a -> PartialFraction.T a -> Bool
-add = Laws.homomorphism PartialFraction.toFraction (+) (+)
-
-sub :: (PID.C a, Indexable.C a) => PartialFraction.T a -> PartialFraction.T a -> Bool
-sub = Laws.homomorphism PartialFraction.toFraction (-) (-)
-
-mul :: (PID.C a, Indexable.C a) => PartialFraction.T a -> PartialFraction.T a -> Bool
-mul = Laws.homomorphism PartialFraction.toFraction (*) (*)
-
-
-
-{- * Properties for Integers -}
-
-{- |
-Arbitrary instance of that type generates irreducible elements for tests.
-Choosing from a list of examples is a simple yet effective design.
-If we would construct irreducible elements by a clever algorithm
-we might obtain multiple primes only rarely.
--}
-newtype SmallPrime = SmallPrime {intFromSmallPrime :: Integer}
-
-type IntFraction = ([SmallPrime],Integer)
-
-instance QC.Arbitrary SmallPrime where
-   arbitrary =
-      let primes = [2,3,5,7,11,13]
-      in  fmap SmallPrime $ QC.elements (primes ++ map negate primes)
-
-instance Show SmallPrime where
-   show = show . intFromSmallPrime
-
-
-fractionConvInt :: [SmallPrime] -> Integer -> Bool
-fractionConvInt =
-   fractionConv . map intFromSmallPrime
-
-fractionConvAltInt :: [SmallPrime] -> Integer -> Bool
-fractionConvAltInt =
-   fractionConvAlt . map intFromSmallPrime
-
-fromSmallPrimes :: IntFraction -> PartialFraction.T Integer
-fromSmallPrimes (xs,y) =
-   PartialFraction.fromFactoredFraction (map intFromSmallPrime xs) y
-
-
-scaleIntInt :: Integer -> IntFraction -> Bool
-scaleIntInt k a =
-   scaleInt k (fromSmallPrimes a)
-
-addInt :: IntFraction -> IntFraction -> Bool
-addInt q0 q1 =
-   add
-      (fromSmallPrimes q0)
-      (fromSmallPrimes q1)
-
-subInt :: IntFraction -> IntFraction -> Bool
-subInt q0 q1 =
-   sub
-      (fromSmallPrimes q0)
-      (fromSmallPrimes q1)
-
-mulInt :: IntFraction -> IntFraction -> Bool
-mulInt q0 q1 =
-   mul
-      (fromSmallPrimes q0)
-      (fromSmallPrimes q1)
-
-
-intTests :: HUnit.Test
-intTests =
-   HUnit.TestLabel "integer" $
-   HUnit.TestList $
-   map testUnit $
-      ("conversion between partial and ordinary fraction", quickCheck fractionConvInt) :
-      ("two conversion routines from factored fractions", quickCheck fractionConvAltInt) :
-      ("integer scaling", quickCheck scaleIntInt) :
-      ("addition", quickCheck addInt) :
-      ("subtraction", quickCheck subInt) :
-      ("multiplication", quickCheck mulInt) :
-      []
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/PartialFraction.hs
+{-# LINE 45 "src/MathObj/PartialFraction.hs" #-}
 
+module Test.MathObj.PartialFraction where
 
-{- * Properties for Polynomials -}
+import qualified Test.DocTest.Driver as DocTest
 
-newtype IrredPoly = IrredPoly {polyFromIrredPoly :: Poly.T Rational}
+{-# LINE 46 "src/MathObj/PartialFraction.hs" #-}
+import     qualified MathObj.PartialFraction as PartialFraction
+import     qualified MathObj.Polynomial.Core as PolyCore
+import     qualified MathObj.Polynomial as Poly
+import     qualified Algebra.PrincipalIdealDomain as PID
+import     qualified Algebra.Indexable as Indexable
+import     qualified Algebra.Laws as Laws
+import     qualified Number.Ratio as Ratio
+import     Test.NumericPrelude.Utility ((/\))
+import     qualified Test.QuickCheck as QC
+import     NumericPrelude.Numeric as NP
+import     NumericPrelude.Base as P
+import     Prelude ()
 
-type RatPolynomial = Poly.T Rational
-type PolyFraction = ([IrredPoly],RatPolynomial)
+import     Control.Applicative (liftA2)
 
-instance QC.Arbitrary IrredPoly where
-   arbitrary =
-      do poly <- QC.elements (map Poly.fromCoeffs [[2,3],[2,0,1],[3,0,1],[1,-3,0,1]])
-         unit <- M.until (not. isZero) QC.arbitrary
-         return (IrredPoly (unit Vector.*> poly))
+{-     |
+Generator     of irreducible elements for tests.
+Choosing     from a list of examples is a simple yet effective design.
+If     we would construct irreducible elements by a clever algorithm
+we     might obtain multiple primes only rarely.
+-}     --
+genSmallPrime     :: QC.Gen Integer
+genSmallPrime     =
+       let primes = [2,3,5,7,11,13]
+       in  QC.elements (primes ++ map negate primes)
 
-instance Show IrredPoly where
-   show = show . polyFromIrredPoly
+genPartialFractionInt     :: QC.Gen (PartialFraction.T Integer)
+genPartialFractionInt     =
+       liftA2 PartialFraction.fromFactoredFraction
+          (QC.listOf genSmallPrime) QC.arbitrary
 
 
-fractionConvPoly :: [IrredPoly] -> RatPolynomial -> Bool
-fractionConvPoly =
-   fractionConv . map polyFromIrredPoly
-
-fractionConvAltPoly :: [IrredPoly] -> RatPolynomial -> Bool
-fractionConvAltPoly =
-   fractionConvAlt . map polyFromIrredPoly
+genIrreduciblePolynomial     :: QC.Gen (Poly.T Rational)
+genIrreduciblePolynomial     = do
+       QC.NonZero unit <- QC.arbitrary
+       fmap (Poly.fromCoeffs . map (unit*)) $
+          QC.elements [[2,3],[2,0,1],[3,0,1],[1,-3,0,1]]
 
-fromIrredPolys :: PolyFraction -> PartialFraction.T RatPolynomial
-fromIrredPolys (xs,y) =
-   PartialFraction.fromFactoredFraction (map polyFromIrredPoly xs) y
+genPartialFractionPoly     :: QC.Gen (PartialFraction.T (Poly.T Rational))
+genPartialFractionPoly     =
+       liftA2 PartialFraction.fromFactoredFraction
+          (fmap (take 3) $ QC.listOf genIrreduciblePolynomial)
+          (fmap (Poly.fromCoeffs . PolyCore.normalize . take 5) QC.arbitrary)
 
 
-scaleIntPoly :: RatPolynomial -> PolyFraction -> Bool
-scaleIntPoly k a =
-   scaleInt k (fromIrredPolys a)
-
-addPoly :: PolyFraction -> PolyFraction -> Bool
-addPoly q0 q1 =
-   add
-      (fromIrredPolys q0)
-      (fromIrredPolys q1)
-
-subPoly :: PolyFraction -> PolyFraction -> Bool
-subPoly q0 q1 =
-   sub
-      (fromIrredPolys q0)
-      (fromIrredPolys q1)
-
-mulPoly :: PolyFraction -> PolyFraction -> Bool
-mulPoly q0 q1 =
-   mul
-      (fromIrredPolys q0)
-      (fromIrredPolys q1)
-
+fractionConv     :: (PID.C a, Indexable.C a) => [a] -> a -> Bool
+fractionConv     xs y =
+       PartialFraction.toFraction (PartialFraction.fromFactoredFraction xs y) ==
+       y % product xs
 
+fractionConvAlt     :: (PID.C a, Indexable.C a) => [a] -> a -> Bool
+fractionConvAlt     xs y =
+       PartialFraction.fromFactoredFraction xs y ==
+       PartialFraction.fromFactoredFractionAlt xs y
 
-polyTests :: HUnit.Test
-polyTests =
-   HUnit.TestLabel "polynomial" $
-   HUnit.TestList $
-   map testUnit $
-{- this test fails, because addition may result in leading zero coefficients,
-      that is, polynomial addition does not contain a normalization
-      if it would contain one, we would exclude computable reals -}
--- wrong     ("conversion between partial and ordinary fraction", quickCheck fractionConvPoly) :
--- wrong     ("two conversion routines from factored fractions", quickCheck fractionConvAltPoly) :
--- too slow      ("integer scaling", quickCheck scaleIntPoly) :
--- too slow      ("addition", quickCheck addPoly) :
--- too slow      ("subtraction", quickCheck subPoly) :
--- too slow      ("multiplication", quickCheck mulPoly) :
-      []
+scaleInt     :: (PID.C a, Indexable.C a) => a -> PartialFraction.T a -> Bool
+scaleInt     k a =
+       PartialFraction.toFraction (PartialFraction.scaleInt k a) ==
+       Ratio.scale k (PartialFraction.toFraction a)
 
+add,     sub, mul ::
+       (PID.C a, Indexable.C a) =>
+       PartialFraction.T a -> PartialFraction.T a -> Bool
+add     = Laws.homomorphism PartialFraction.toFraction (+) (+)
+sub     = Laws.homomorphism PartialFraction.toFraction (-) (-)
+mul     = Laws.homomorphism PartialFraction.toFraction (*) (*)
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "partial fraction" $
-   HUnit.TestList $
-      intTests :
---      polyTests :
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.PartialFraction:195: "
+{-# LINE 195 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 195 "src/MathObj/PartialFraction.hs" #-}
+     (QC.listOf genSmallPrime /\ fractionConv)
+ DocTest.printPrefix "MathObj.PartialFraction:196: "
+{-# LINE 196 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 196 "src/MathObj/PartialFraction.hs" #-}
+     (fmap (take 3) (QC.listOf genIrreduciblePolynomial) /\ fractionConv)
+ DocTest.printPrefix "MathObj.PartialFraction:220: "
+{-# LINE 220 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 220 "src/MathObj/PartialFraction.hs" #-}
+     (QC.listOf genSmallPrime /\ fractionConvAlt)
+ DocTest.printPrefix "MathObj.PartialFraction:221: "
+{-# LINE 221 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 221 "src/MathObj/PartialFraction.hs" #-}
+     (fmap (take 3) (QC.listOf genIrreduciblePolynomial) /\ fractionConvAlt)
+ DocTest.printPrefix "MathObj.PartialFraction:297: "
+{-# LINE 297 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 297 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionInt /\ \x -> genPartialFractionInt /\ \y -> add x y)
+ DocTest.printPrefix "MathObj.PartialFraction:298: "
+{-# LINE 298 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 298 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionInt /\ \x -> genPartialFractionInt /\ \y -> sub x y)
+ DocTest.printPrefix "MathObj.PartialFraction:300: "
+{-# LINE 300 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 300 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionPoly /\ \x -> genPartialFractionPoly /\ \y -> add x y)
+ DocTest.printPrefix "MathObj.PartialFraction:301: "
+{-# LINE 301 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 301 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionPoly /\ \x -> genPartialFractionPoly /\ \y -> sub x y)
+ DocTest.printPrefix "MathObj.PartialFraction:429: "
+{-# LINE 429 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 429 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionInt /\ \x k -> scaleInt k x)
+ DocTest.printPrefix "MathObj.PartialFraction:430: "
+{-# LINE 430 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 430 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionPoly /\ \x k -> scaleInt k x)
+ DocTest.printPrefix "MathObj.PartialFraction:449: "
+{-# LINE 449 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 449 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionInt /\ \x -> genPartialFractionInt /\ \y -> mul x y)
+ DocTest.printPrefix "MathObj.PartialFraction:450: "
+{-# LINE 450 "src/MathObj/PartialFraction.hs" #-}
+ DocTest.property
+{-# LINE 450 "src/MathObj/PartialFraction.hs" #-}
+     (genPartialFractionPoly /\ \x -> genPartialFractionPoly /\ \y -> mul x y)
diff --git a/test/Test/MathObj/Polynomial.hs b/test/Test/MathObj/Polynomial.hs
--- a/test/Test/MathObj/Polynomial.hs
+++ b/test/Test/MathObj/Polynomial.hs
@@ -1,56 +1,63 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-module Test.MathObj.Polynomial where
-
-import qualified MathObj.Polynomial      as Poly
-import qualified MathObj.Polynomial.Core as PolyCore
-
-import qualified Algebra.IntegralDomain as Integral
-import qualified Algebra.Ring           as Ring
-
-import qualified Algebra.ZeroTestable   as ZeroTestable
-import qualified Algebra.Laws as Laws
-
-import qualified Data.List as List
-
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (Property, quickCheck, (==>), Testable, )
-import qualified Test.HUnit as HUnit
-
-
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
-
-
-tensorProductTranspose :: (Ring.C a, Eq a) => [a] -> [a] -> Property
-tensorProductTranspose xs ys =
-   not (null xs) && not (null ys) ==>
-      PolyCore.tensorProduct xs ys == List.transpose (PolyCore.tensorProduct ys xs)
-
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/Polynomial.hs
+{-# LINE 84 "src/MathObj/Polynomial.hs" #-}
 
-mul :: (Ring.C a, Eq a, ZeroTestable.C a) => [a] -> [a] -> Bool
-mul xs ys  =  PolyCore.equal (PolyCore.mul xs ys) (PolyCore.mulShear xs ys)
+module Test.MathObj.Polynomial where
 
+import qualified Test.DocTest.Driver as DocTest
 
-test :: Testable a => (Poly.T Integer -> a) -> IO ()
-test = quickCheck
+{-# LINE 85 "src/MathObj/Polynomial.hs" #-}
+import     qualified MathObj.Polynomial as Poly
+import     qualified Algebra.IntegralDomain as Integral
+import     qualified Algebra.Laws as Laws
+import     NumericPrelude.Numeric
+import     NumericPrelude.Base
+import     Prelude ()
 
-testRat :: Testable a => (Poly.T Rational -> a) -> IO ()
-testRat = quickCheck
+intPoly     :: Poly.T Integer -> Poly.T Integer
+intPoly     = id
 
+ratioPoly     :: Poly.T Rational -> Poly.T Rational
+ratioPoly     = id
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "polynomial" $
-   HUnit.TestList $
-   map testUnit $
-      ("tensor product", quickCheck (tensorProductTranspose :: [Integer] -> [Integer] -> Property)) :
-      ("mul speed",      quickCheck (mul                    :: [Integer] -> [Integer] -> Bool)) :
-      ("addition, zero",         test (Laws.identity (+) zero)) :
-      ("addition, commutative",  test (Laws.commutative (+))) :
-      ("addition, associative",  test (Laws.associative (+))) :
-      ("multiplication, one",          test (Laws.identity (*) one)) :
-      ("multiplication, commutative",  test (Laws.commutative (*))) :
-      ("multiplication, associative",  test (Laws.associative (*))) :
-      ("multiplication and addition, distributive",   test (Laws.leftDistributive (*) (+))) :
-      ("division",       testRat (Integral.propInverse)) :
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.Polynomial:100: "
+{-# LINE 100 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 100 "src/MathObj/Polynomial.hs" #-}
+     (Laws.identity (+) zero . intPoly)
+ DocTest.printPrefix "MathObj.Polynomial:101: "
+{-# LINE 101 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 101 "src/MathObj/Polynomial.hs" #-}
+     (Laws.commutative (+) . intPoly)
+ DocTest.printPrefix "MathObj.Polynomial:102: "
+{-# LINE 102 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 102 "src/MathObj/Polynomial.hs" #-}
+     (Laws.associative (+) . intPoly)
+ DocTest.printPrefix "MathObj.Polynomial:103: "
+{-# LINE 103 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 103 "src/MathObj/Polynomial.hs" #-}
+     (Laws.identity (*) one . intPoly)
+ DocTest.printPrefix "MathObj.Polynomial:104: "
+{-# LINE 104 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 104 "src/MathObj/Polynomial.hs" #-}
+     (Laws.commutative (*) . intPoly)
+ DocTest.printPrefix "MathObj.Polynomial:105: "
+{-# LINE 105 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 105 "src/MathObj/Polynomial.hs" #-}
+     (Laws.associative (*) . intPoly)
+ DocTest.printPrefix "MathObj.Polynomial:106: "
+{-# LINE 106 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 106 "src/MathObj/Polynomial.hs" #-}
+     (Laws.leftDistributive (*) (+) . intPoly)
+ DocTest.printPrefix "MathObj.Polynomial:107: "
+{-# LINE 107 "src/MathObj/Polynomial.hs" #-}
+ DocTest.property
+{-# LINE 107 "src/MathObj/Polynomial.hs" #-}
+     (Integral.propInverse . ratioPoly)
diff --git a/test/Test/MathObj/Polynomial/Core.hs b/test/Test/MathObj/Polynomial/Core.hs
new file mode 100644
--- /dev/null
+++ b/test/Test/MathObj/Polynomial/Core.hs
@@ -0,0 +1,51 @@
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/Polynomial/Core.hs
+{-# LINE 47 "src/MathObj/Polynomial/Core.hs" #-}
+
+module Test.MathObj.Polynomial.Core where
+
+import qualified Test.DocTest.Driver as DocTest
+
+{-# LINE 48 "src/MathObj/Polynomial/Core.hs" #-}
+import     qualified MathObj.Polynomial.Core as PolyCore
+import     qualified MathObj.Polynomial as Poly
+import     qualified Data.List as List
+import     qualified Test.QuickCheck as QC
+import     Test.QuickCheck ((==>))
+import     Data.Tuple.HT (mapPair, mapSnd)
+import     NumericPrelude.Numeric
+import     NumericPrelude.Base
+import     Prelude ()
+
+intPoly     :: [Integer] -> [Integer]
+intPoly     = id
+
+ratioPoly     :: [Rational] -> [Rational]
+ratioPoly     = id
+
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.Polynomial.Core:136: "
+{-# LINE 136 "src/MathObj/Polynomial/Core.hs" #-}
+ DocTest.property
+{-# LINE 136 "src/MathObj/Polynomial/Core.hs" #-}
+     (\(QC.NonEmpty xs) (QC.NonEmpty ys) -> PolyCore.tensorProduct xs ys == List.transpose (PolyCore.tensorProduct ys (intPoly xs)))
+ DocTest.printPrefix "MathObj.Polynomial.Core:161: "
+{-# LINE 161 "src/MathObj/Polynomial/Core.hs" #-}
+ DocTest.property
+{-# LINE 161 "src/MathObj/Polynomial/Core.hs" #-}
+     (\xs ys  ->  PolyCore.equal (intPoly $ PolyCore.mul xs ys) (PolyCore.mulShear xs ys))
+ DocTest.printPrefix "MathObj.Polynomial.Core:173: "
+{-# LINE 173 "src/MathObj/Polynomial/Core.hs" #-}
+ DocTest.property
+{-# LINE 173 "src/MathObj/Polynomial/Core.hs" #-}
+     (\x y -> case (PolyCore.normalize x, PolyCore.normalize y) of (nx, ny) -> not (null (ratioPoly ny)) ==> mapSnd PolyCore.normalize (PolyCore.divMod nx ny) == mapPair (PolyCore.normalize, PolyCore.normalize) (PolyCore.divMod x y))
+ DocTest.printPrefix "MathObj.Polynomial.Core:174: "
+{-# LINE 174 "src/MathObj/Polynomial/Core.hs" #-}
+ DocTest.property
+{-# LINE 174 "src/MathObj/Polynomial/Core.hs" #-}
+     (\x y -> not (isZero (ratioPoly y)) ==> let z = fst $ PolyCore.divMod (Poly.coeffs x) y in  PolyCore.normalize z == z)
+ DocTest.printPrefix "MathObj.Polynomial.Core:175: "
+{-# LINE 175 "src/MathObj/Polynomial/Core.hs" #-}
+ DocTest.property
+{-# LINE 175 "src/MathObj/Polynomial/Core.hs" #-}
+     (\x y -> case PolyCore.normalize $ ratioPoly y of ny -> not (null ny) ==> List.length (snd $ PolyCore.divMod x y) < List.length ny)
diff --git a/test/Test/MathObj/PowerSeries.hs b/test/Test/MathObj/PowerSeries.hs
--- a/test/Test/MathObj/PowerSeries.hs
+++ b/test/Test/MathObj/PowerSeries.hs
@@ -1,103 +1,23 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE FlexibleInstances #-}
-module Test.MathObj.PowerSeries where
-
-import qualified MathObj.PowerSeries.Core    as PS
-import qualified MathObj.PowerSeries.Example as PSE
-
-import Test.NumericPrelude.Utility (equalInfLists {- , testUnit -} )
--- import Test.QuickCheck (Property, quickCheck, (==>))
-import qualified Test.HUnit as HUnit
-
-
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
-
-
-identitiesExplODE, identitiesSeriesFunction, identitiesInverses ::
-   [(String, Int, [Rational],[Rational])]
-
-identitiesExplODE =
-   ("exp",   500, PSE.expExpl,   PSE.expODE) :
-   ("sin",   500, PSE.sinExpl,   PSE.sinODE) :
-   ("cos",   500, PSE.cosExpl,   PSE.cosODE) :
-   ("tan",    50, PSE.tanExpl,   PSE.tanODE) :
-   ("tan",    50, PSE.tanExpl,   PSE.tanExplSieve) :
-   ("tan",    50, PSE.tanODE,    PSE.tanODESieve) :
-   ("log",   500, PSE.logExpl,   PSE.logODE) :
-   ("asin",   50, PSE.asinODE,   snd (PS.inv PSE.sinODE)) :
-   ("atan",  500, PSE.atanExpl,  PSE.atanODE) :
-   ("sinh",  500, PSE.sinhExpl,  PSE.sinhODE) :
-   ("cosh",  500, PSE.coshExpl,  PSE.coshODE) :
-   ("atanh", 500, PSE.atanhExpl, PSE.atanhODE) :
-   ("sqrt",  100, PSE.sqrtExpl,  PSE.sqrtODE) :
-   []
-
-identitiesSeriesFunction =
-   ("exp",   500, PSE.expExpl,  PS.exp (\0 -> 1) [0,1]) :
-   ("sin",   500, PSE.sinExpl,  PS.sin (\0 -> (0,1)) [0,1]) :
-   ("cos",   500, PSE.cosExpl,  PS.cos (\0 -> (0,1)) [0,1]) :
-   ("tan",    50, PSE.tanExpl,  PS.tan (\0 -> (0,1)) [0,1]) :
-   ("sqrt",   50, PSE.sqrtExpl, PS.sqrt (\1 -> 1) [1,1]) :
-   ("power", 500, PSE.powExpl (-1/3), PS.pow (\1 -> 1) (-1/3) [1,1]) :
-   ("power",  50, PSE.powExpl (-1/3), PS.exp (\0 -> 1) (PS.scale (-1/3) PSE.log)) :
-   ("log",   500, PSE.logExpl, PS.log (\1 -> 0) [1,1]) :
-   ("asin",   50, PSE.asin, PS.asin (\1 -> 1) (\0 -> 0) [0,1]) :
- --  ("acos",  50, PSE.acos, PS.acos (\1 -> 1) (\0 -> pi/2) [0,1]) :
-   ("atan",  500, PSE.atan, PS.atan (\0 -> 0) [0,1]) :
-   []
-
-identitiesInverses =
-   ("exp",   100, 1:1:repeat 0, PS.exp  (\0 -> 1) PSE.log) :
-   ("log",   100, 0:1:repeat 0, PS.log  (\1 -> 0) PSE.exp) :
-   ("tan",    50, 0:1:repeat 0, PS.tan  (\0 -> (0,1)) PSE.atan) :
-   ("atan",   50, 0:1:repeat 0, PS.atan (\0 -> 0) PSE.tan) :
-   ("sin",    50, 0:1:repeat 0, PS.sin  (\0 -> (0,1)) PSE.asin) :
-   ("asin",  100, 0:1:repeat 0, PS.asin (\1 -> 1) (\0 -> 0) PSE.sin) :
-   ("sqrt",  500, 1:1:repeat 0, PS.sqrt (\1 -> 1) (PS.mul [1,1] [1,1])) :
-   []
-
-testSeriesIdentity :: (String, Int, [Rational], [Rational]) -> HUnit.Test
-testSeriesIdentity (label, len, x, y) =
-   HUnit.test (HUnit.assertBool label (equalInfLists len [x,y]))
-
-testSeriesIdentities ::
-   String -> [(String, Int, [Rational], [Rational])] -> HUnit.Test
-testSeriesIdentities label ids =
-   HUnit.TestLabel label $
-     HUnit.TestList $ map testSeriesIdentity ids
-
-checkSeriesIdentities ::
-   [(String, Int, [Rational], [Rational])] -> [(String,Bool)]
-checkSeriesIdentities =
-   map (\(label, len, x, y) -> (label, equalInfLists len [x,y]))
-
-
-
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/PowerSeries.hs
+{-# LINE 30 "src/MathObj/PowerSeries.hs" #-}
 
-powerMult :: Rational -> Rational -> Bool
-powerMult exp0 exp1 =
-   PS.mul (PSE.pow exp0) (PSE.pow exp1)  ==  PSE.pow (exp0+exp1)
+module Test.MathObj.PowerSeries where
 
-powerExplODE :: Rational -> Bool
-powerExplODE expon =
-   PSE.powODE expon == PSE.powExpl expon
+import qualified Test.DocTest.Driver as DocTest
 
+{-# LINE 31 "src/MathObj/PowerSeries.hs" #-}
+import     qualified MathObj.PowerSeries.Core as PS
+import     qualified MathObj.PowerSeries as PST
+import     qualified Test.QuickCheck as QC
+import     Test.NumericPrelude.Utility (equalTrunc, (/\))
+import     NumericPrelude.Numeric as NP
+import     NumericPrelude.Base as P
+import     Prelude ()
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "power series" $
-   HUnit.TestList [
-      testSeriesIdentities "explicit vs. ODE solution" identitiesExplODE,
-      testSeriesIdentities "transcendent functions of series" identitiesSeriesFunction,
-      testSeriesIdentities "inverses of some series" identitiesInverses
-{-
-      HUnit.TestLabel "laws" $
-      HUnit.TestList $
-         map testUnit $
-            ("products of powers",     quickCheck (powerMult)) :
-            ("power explicit vs. ODE", quickCheck (powerExplODE)) :
-            []
--}
-    ]
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.PowerSeries:141: "
+{-# LINE 141 "src/MathObj/PowerSeries.hs" #-}
+ DocTest.property
+{-# LINE 141 "src/MathObj/PowerSeries.hs" #-}
+     (QC.choose (1,10) /\ \expon (QC.Positive x) xs -> let xt = x:xs in  equalTrunc 15 (PS.pow (const x) (1 % expon) (PST.coeffs (PST.fromCoeffs xt ^ expon)) ++ repeat zero) (xt ++ repeat zero))
diff --git a/test/Test/MathObj/PowerSeries/Core.hs b/test/Test/MathObj/PowerSeries/Core.hs
new file mode 100644
--- /dev/null
+++ b/test/Test/MathObj/PowerSeries/Core.hs
@@ -0,0 +1,178 @@
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/PowerSeries/Core.hs
+{-# LINE 23 "src/MathObj/PowerSeries/Core.hs" #-}
+
+module Test.MathObj.PowerSeries.Core where
+
+import qualified Test.DocTest.Driver as DocTest
+
+{-# LINE 24 "src/MathObj/PowerSeries/Core.hs" #-}
+import     qualified MathObj.PowerSeries.Core as PS
+import     qualified MathObj.PowerSeries.Example as PSE
+import     Test.NumericPrelude.Utility (equalTrunc, (/\))
+import     qualified Test.QuickCheck as QC
+import     NumericPrelude.Numeric as NP
+import     NumericPrelude.Base as P
+import     Prelude ()
+import     Control.Applicative (liftA3)
+
+checkHoles     ::
+       Int -> ([Rational] -> [Rational]) ->
+       Rational -> [Rational] -> QC.Property
+checkHoles     trunc f x xs =
+       QC.choose (1,10) /\ \expon ->
+       equalTrunc trunc
+          (f (PS.insertHoles expon (x:xs)) ++ repeat zero)
+          (PS.insertHoles expon (f (x:xs)) ++ repeat zero)
+
+genInvertible     :: QC.Gen [Rational]
+genInvertible     =
+       liftA3 (\x0 x1 xs -> x0:x1:xs)
+          QC.arbitrary (fmap QC.getNonZero QC.arbitrary) QC.arbitrary
+
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.PowerSeries.Core:108: "
+{-# LINE 108 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 108 "src/MathObj/PowerSeries/Core.hs" #-}
+     (QC.choose (1,10) /\ \m -> QC.choose (1,10) /\ \n xs -> equalTrunc 100 (PS.insertHoles m $ PS.insertHoles n xs) (PS.insertHoles (m*n) xs))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:190: "
+{-# LINE 190 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 190 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 50 PSE.sqrtExpl (PS.sqrt (\1 -> 1) [1,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:191: "
+{-# LINE 191 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 191 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 500 (1:1:repeat 0) (PS.sqrt (\1 -> 1) (PS.mul [1,1] [1,1])))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:192: "
+{-# LINE 192 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 192 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 50 (PS.sqrt (\1 -> 1)) 1)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:217: "
+{-# LINE 217 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 217 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 100 (PSE.powExpl (-1/3)) (PS.pow (\1 -> 1) (-1/3) [1,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:218: "
+{-# LINE 218 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 218 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 50 (PSE.powExpl (-1/3)) (PS.exp (\0 -> 1) (PS.scale (-1/3) PSE.log)))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:219: "
+{-# LINE 219 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 219 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 30 (PS.pow (\1 -> 1) (1/3)) 1)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:220: "
+{-# LINE 220 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 220 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 30 (PS.pow (\1 -> 1) (2/5)) 1)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:237: "
+{-# LINE 237 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 237 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 500 PSE.expExpl (PS.exp (\0 -> 1) [0,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:238: "
+{-# LINE 238 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 238 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 100 (1:1:repeat 0) (PS.exp (\0 -> 1) PSE.log))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:239: "
+{-# LINE 239 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 239 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 30 (PS.exp (\0 -> 1)) 0)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:259: "
+{-# LINE 259 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 259 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 500 PSE.sinExpl (PS.sin (\0 -> (0,1)) [0,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:260: "
+{-# LINE 260 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 260 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 50 (0:1:repeat 0) (PS.sin (\0 -> (0,1)) PSE.asin))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:261: "
+{-# LINE 261 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 261 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 20 (PS.sin (\0 -> (0,1))) 0)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:266: "
+{-# LINE 266 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 266 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 500 PSE.cosExpl (PS.cos (\0 -> (0,1)) [0,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:267: "
+{-# LINE 267 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 267 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 20 (PS.cos (\0 -> (0,1))) 0)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:273: "
+{-# LINE 273 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 273 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 50 PSE.tanExpl (PS.tan (\0 -> (0,1)) [0,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:274: "
+{-# LINE 274 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 274 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 50 (0:1:repeat 0) (PS.tan (\0 -> (0,1)) PSE.atan))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:275: "
+{-# LINE 275 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 275 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 20 (PS.tan (\0 -> (0,1))) 0)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:289: "
+{-# LINE 289 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 289 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 500 PSE.logExpl (PS.log (\1 -> 0) [1,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:290: "
+{-# LINE 290 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 290 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 100 (0:1:repeat 0) (PS.log (\1 -> 0) PSE.exp))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:291: "
+{-# LINE 291 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 291 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 30 (PS.log (\1 -> 0)) 1)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:303: "
+{-# LINE 303 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 303 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 500 PSE.atan (PS.atan (\0 -> 0) [0,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:304: "
+{-# LINE 304 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 304 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 50 (0:1:repeat 0) (PS.atan (\0 -> 0) PSE.tan))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:305: "
+{-# LINE 305 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 305 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 20 (PS.atan (\0 -> 0)) 0)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:313: "
+{-# LINE 313 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 313 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 100 (0:1:repeat 0) (PS.asin (\1 -> 1) (\0 -> 0) PSE.sin))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:314: "
+{-# LINE 314 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 314 "src/MathObj/PowerSeries/Core.hs" #-}
+     (equalTrunc 50 PSE.asin (PS.asin (\1 -> 1) (\0 -> 0) [0,1]))
+ DocTest.printPrefix "MathObj.PowerSeries.Core:315: "
+{-# LINE 315 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 315 "src/MathObj/PowerSeries/Core.hs" #-}
+     (checkHoles 30 (PS.asin (\1 -> 1) (\0 -> 0)) 0)
+ DocTest.printPrefix "MathObj.PowerSeries.Core:383: "
+{-# LINE 383 "src/MathObj/PowerSeries/Core.hs" #-}
+ DocTest.property
+{-# LINE 383 "src/MathObj/PowerSeries/Core.hs" #-}
+     (genInvertible /\ \xs -> let (y,ys) = PS.inv xs; (z,zs) = PS.invDiff xs in y==z && equalTrunc 15 ys zs)
diff --git a/test/Test/MathObj/PowerSeries/Example.hs b/test/Test/MathObj/PowerSeries/Example.hs
new file mode 100644
--- /dev/null
+++ b/test/Test/MathObj/PowerSeries/Example.hs
@@ -0,0 +1,92 @@
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/PowerSeries/Example.hs
+{-# LINE 21 "src/MathObj/PowerSeries/Example.hs" #-}
+
+module Test.MathObj.PowerSeries.Example where
+
+import qualified Test.DocTest.Driver as DocTest
+
+{-# LINE 22 "src/MathObj/PowerSeries/Example.hs" #-}
+import     qualified MathObj.PowerSeries.Core as PS
+import     qualified MathObj.PowerSeries.Example as PSE
+import     Test.NumericPrelude.Utility (equalTrunc)
+import     NumericPrelude.Numeric as NP
+import     NumericPrelude.Base as P
+import     Prelude ()
+
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.PowerSeries.Example:55: "
+{-# LINE 55 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 55 "src/MathObj/PowerSeries/Example.hs" #-}
+          (\m n -> equalTrunc 30 (PS.mul (PSE.pow m) (PSE.pow n)) (PSE.pow (m+n)))
+ DocTest.printPrefix "MathObj.PowerSeries.Example:66: "
+{-# LINE 66 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 66 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.expExpl PSE.expODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:69: "
+{-# LINE 69 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 69 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.sinExpl PSE.sinODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:72: "
+{-# LINE 72 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 72 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.cosExpl PSE.cosODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:76: "
+{-# LINE 76 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 76 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 50 PSE.tanExpl PSE.tanODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:80: "
+{-# LINE 80 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 80 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 50 PSE.tanExpl PSE.tanExplSieve)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:87: "
+{-# LINE 87 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 87 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.logExpl PSE.logODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:90: "
+{-# LINE 90 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 90 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.atanExpl PSE.atanODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:94: "
+{-# LINE 94 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 94 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.sinhExpl PSE.sinhODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:97: "
+{-# LINE 97 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 97 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.coshExpl PSE.coshODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:100: "
+{-# LINE 100 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 100 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 500 PSE.atanhExpl PSE.atanhODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:106: "
+{-# LINE 106 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 106 "src/MathObj/PowerSeries/Example.hs" #-}
+          (\expon -> equalTrunc 50 (PSE.powODE expon) (PSE.powExpl expon))
+ DocTest.printPrefix "MathObj.PowerSeries.Example:112: "
+{-# LINE 112 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 112 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 100 PSE.sqrtExpl PSE.sqrtODE)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:149: "
+{-# LINE 149 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 149 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 50 PSE.tanODE PSE.tanODESieve)
+ DocTest.printPrefix "MathObj.PowerSeries.Example:165: "
+{-# LINE 165 "src/MathObj/PowerSeries/Example.hs" #-}
+ DocTest.property
+{-# LINE 165 "src/MathObj/PowerSeries/Example.hs" #-}
+          (equalTrunc 50 PSE.asinODE (snd $ PS.inv PSE.sinODE))
diff --git a/test/Test/MathObj/RefinementMask2.hs b/test/Test/MathObj/RefinementMask2.hs
--- a/test/Test/MathObj/RefinementMask2.hs
+++ b/test/Test/MathObj/RefinementMask2.hs
@@ -1,78 +1,72 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-module Test.MathObj.RefinementMask2 where
-
-import qualified MathObj.RefinementMask2 as Mask
-import qualified Algebra.Differential    as D
-
-import qualified MathObj.Polynomial      as Poly
-import qualified MathObj.Polynomial.Core as PolyCore
-
-import qualified Algebra.RealField      as RealField
-import qualified Algebra.Ring           as Ring
-
-import qualified Algebra.ZeroTestable   as ZeroTestable
-
-import Data.Maybe (fromMaybe, )
-
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (Property, quickCheck, (==>), Testable, )
-import qualified Test.HUnit as HUnit
-
-
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
-
-
+-- Do not edit! Automatically created with doctest-extract from src/MathObj/RefinementMask2.hs
+{-# LINE 32 "src/MathObj/RefinementMask2.hs" #-}
 
-hasMultipleZero :: (Ring.C a, Eq a) => Int -> a -> Poly.T a -> Bool
-hasMultipleZero n x poly =
-   all (zero==) $ take n $
-   map (flip Poly.evaluate x) $
-   iterate D.differentiate poly
+module Test.MathObj.RefinementMask2 where
 
-inverse0 :: (RealField.C a, ZeroTestable.C a) => Mask.T a -> Property
-inverse0 mask0 =
-   let (b,poly) =
-          case Mask.toPolynomial mask0 of
-             Just p -> (True, p)
-             Nothing -> (False, error "RefinementMask2.inverse0: no admissible mask")
-       mask1 = Mask.fromPolynomial poly
-       maskD =
-          Poly.fromCoeffs (Mask.coeffs mask1) -
-          Poly.fromCoeffs (Mask.coeffs mask0)
-   in  b ==>
-          hasMultipleZero (fromMaybe 0 $ Poly.degree poly)
-             1 maskD
+import Test.DocTest.Base
+import qualified Test.DocTest.Driver as DocTest
 
-truncatePolynomial :: (ZeroTestable.C a) => Int -> Poly.T a -> Poly.T a
-truncatePolynomial n =
-   Poly.fromCoeffs . PolyCore.normalize . take n . Poly.coeffs
+{-# LINE 33 "src/MathObj/RefinementMask2.hs" #-}
+import     qualified MathObj.RefinementMask2 as Mask
+import     qualified MathObj.Polynomial      as Poly
+import     qualified MathObj.Polynomial.Core as PolyCore
 
-inverse1 :: (RealField.C a) => Poly.T a -> Bool
-inverse1 poly0 =
-   case Mask.toPolynomial (Mask.fromPolynomial poly0) of
-      Just poly1 -> Poly.collinear poly0 poly1
-      Nothing -> False
+import     qualified Algebra.Differential as D
+import     qualified Algebra.Ring as Ring
+import     Test.NumericPrelude.Utility ((/\))
+import     qualified Test.QuickCheck as QC
+import     NumericPrelude.Numeric as NP
+import     NumericPrelude.Base as P
+import     Prelude ()
 
-refining :: (RealField.C a, ZeroTestable.C a) => Poly.T a -> Bool
-refining poly =
-   poly == Mask.refinePolynomial (Mask.fromPolynomial poly) poly
+import     Data.Function.HT (nest)
+import     Data.Maybe (fromMaybe)
 
 
+hasMultipleZero     :: (Ring.C a, Eq a) => Int -> a -> Poly.T a -> Bool
+hasMultipleZero     n x poly =
+       all (zero==) $ take n $
+       map (flip Poly.evaluate x) $
+       iterate D.differentiate poly
 
-test :: Testable a => (Poly.T Integer -> a) -> IO ()
-test = quickCheck
+genAdmissibleMask     :: QC.Gen (Mask.T Rational, Poly.T Rational)
+genAdmissibleMask     =
+       QC.suchThatMap QC.arbitrary $
+          \mask -> fmap ((,) mask) $ Mask.toPolynomial mask
 
-testRat :: Testable a => (Poly.T Rational -> a) -> IO ()
-testRat = quickCheck
+polyFromMask     :: Mask.T a -> Poly.T a
+polyFromMask     = Poly.fromCoeffs . Mask.coeffs
 
+genShortPolynomial     :: Int -> QC.Gen (Poly.T Rational)
+genShortPolynomial     n =
+       fmap (Poly.fromCoeffs . PolyCore.normalize . take n) $ QC.arbitrary
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "refinement mask" $
-   HUnit.TestList $
-   map testUnit $
-      ("inverse0", quickCheck (inverse0 :: Mask.T Rational -> Property)) :
-      ("inverse1", quickCheck (inverse1 . truncatePolynomial 5 :: Poly.T Rational -> Bool)) :
-      ("refining", quickCheck (refining . truncatePolynomial 5 :: Poly.T Rational -> Bool)) :
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "MathObj.RefinementMask2:127: "
+{-# LINE 127 "src/MathObj/RefinementMask2.hs" #-}
+ DocTest.property
+{-# LINE 127 "src/MathObj/RefinementMask2.hs" #-}
+     (genAdmissibleMask /\ \(mask,poly) -> hasMultipleZero (fromMaybe 0 $ Poly.degree poly) 1 (polyFromMask (Mask.fromPolynomial poly) - polyFromMask mask))
+ DocTest.printPrefix "MathObj.RefinementMask2:129: "
+{-# LINE 129 "src/MathObj/RefinementMask2.hs" #-}
+ DocTest.property
+{-# LINE 129 "src/MathObj/RefinementMask2.hs" #-}
+     (genShortPolynomial 5 /\ \poly -> maybe False (Poly.collinear poly) $ Mask.toPolynomial $ Mask.fromPolynomial poly)
+ DocTest.printPrefix "MathObj.RefinementMask2:161: "
+{-# LINE 161 "src/MathObj/RefinementMask2.hs" #-}
+ DocTest.example
+{-# LINE 161 "src/MathObj/RefinementMask2.hs" #-}
+   (fmap ((6::Rational) *>) $ Mask.toPolynomial (Mask.fromCoeffs [0.1, 0.02, 0.005::Rational]))
+  [ExpectedLine [LineChunk "Just (Polynomial.fromCoeffs [-12732 % 109375,272 % 625,-18 % 25,1 % 1])"]]
+ DocTest.printPrefix "MathObj.RefinementMask2:207: "
+{-# LINE 207 "src/MathObj/RefinementMask2.hs" #-}
+ DocTest.property
+{-# LINE 207 "src/MathObj/RefinementMask2.hs" #-}
+     (genShortPolynomial 5 /\ \poly -> poly == Mask.refinePolynomial (Mask.fromPolynomial poly) poly)
+ DocTest.printPrefix "MathObj.RefinementMask2:209: "
+{-# LINE 209 "src/MathObj/RefinementMask2.hs" #-}
+ DocTest.example
+{-# LINE 209 "src/MathObj/RefinementMask2.hs" #-}
+   (fmap (round :: Double -> Integer) $ fmap (1000000*) $ nest 50 (Mask.refinePolynomial (Mask.fromCoeffs [0.1, 0.02, 0.005])) (Poly.fromCoeffs [0,0,0,1]))
+  [ExpectedLine [LineChunk "Polynomial.fromCoeffs [-116407,435200,-720000,1000000]"]]
diff --git a/test/Test/Number/ComplexSquareRoot.hs b/test/Test/Number/ComplexSquareRoot.hs
--- a/test/Test/Number/ComplexSquareRoot.hs
+++ b/test/Test/Number/ComplexSquareRoot.hs
@@ -1,50 +1,56 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE FlexibleInstances #-}
-module Test.Number.ComplexSquareRoot where
-
-import qualified Number.ComplexSquareRoot as S
-import qualified Number.Complex as Complex
-
--- import qualified Algebra.Ring           as Ring
-
-import qualified Algebra.Laws as Laws
-
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (Testable, quickCheck, (==>), )
-import qualified Test.HUnit as HUnit
+-- Do not edit! Automatically created with doctest-extract from playground/Number/ComplexSquareRoot.hs
+{-# LINE 21 "playground/Number/ComplexSquareRoot.hs" #-}
 
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
+module Test.Number.ComplexSquareRoot where
 
+import qualified Test.DocTest.Driver as DocTest
 
-simple ::
-   (Testable t) =>
-   (S.T Rational -> t) -> IO ()
-simple = quickCheck
+{-# LINE 22 "playground/Number/ComplexSquareRoot.hs" #-}
+import     qualified Number.ComplexSquareRoot as SR
+import     qualified Number.Complex as Complex
+import     qualified Algebra.Laws as Laws
+import     Test.QuickCheck ((==>))
+import     NumericPrelude.Numeric
+import     NumericPrelude.Base
+import     Prelude ()
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "complex square root" $
-   HUnit.TestList $
-   map testUnit $
-   testList
+sr     :: SR.T Rational -> SR.T Rational
+sr     = id
 
-testList :: [(String, IO ())]
-testList =
-   ("multiplication, one",
-      simple $ Laws.identity S.mul S.one) :
-   ("multiplication, commutative",
-      simple $ Laws.commutative S.mul) :
-   ("multiplication, associative",
-      simple $ Laws.associative S.mul) :
-   ("multiplication, homomorphism",
-      quickCheck $ Laws.homomorphism S.fromNumber
-         (\x y -> (x :: Complex.T Rational) * y) S.mul) :
-   ("division, one",
-      simple $ Laws.rightIdentity S.div S.one) :
-   ("recip recip",
-      simple $ \x -> not (isZero x) ==> S.recip (S.recip x) == x) :
-   ("recip inverts multiplication",
-      simple $ \x -> not (isZero x) ==> Laws.inverse S.mul S.recip S.one x) :
-   []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "Number.ComplexSquareRoot:42: "
+{-# LINE 42 "playground/Number/ComplexSquareRoot.hs" #-}
+ DocTest.property
+{-# LINE 42 "playground/Number/ComplexSquareRoot.hs" #-}
+     (Laws.identity SR.mul SR.one . sr)
+ DocTest.printPrefix "Number.ComplexSquareRoot:43: "
+{-# LINE 43 "playground/Number/ComplexSquareRoot.hs" #-}
+ DocTest.property
+{-# LINE 43 "playground/Number/ComplexSquareRoot.hs" #-}
+     (Laws.commutative SR.mul . sr)
+ DocTest.printPrefix "Number.ComplexSquareRoot:44: "
+{-# LINE 44 "playground/Number/ComplexSquareRoot.hs" #-}
+ DocTest.property
+{-# LINE 44 "playground/Number/ComplexSquareRoot.hs" #-}
+     (Laws.associative SR.mul . sr)
+ DocTest.printPrefix "Number.ComplexSquareRoot:45: "
+{-# LINE 45 "playground/Number/ComplexSquareRoot.hs" #-}
+ DocTest.property
+{-# LINE 45 "playground/Number/ComplexSquareRoot.hs" #-}
+     (Laws.homomorphism SR.fromNumber (\x y -> x * (y :: Complex.T Rational)) SR.mul)
+ DocTest.printPrefix "Number.ComplexSquareRoot:46: "
+{-# LINE 46 "playground/Number/ComplexSquareRoot.hs" #-}
+ DocTest.property
+{-# LINE 46 "playground/Number/ComplexSquareRoot.hs" #-}
+     (Laws.rightIdentity SR.div SR.one . sr)
+ DocTest.printPrefix "Number.ComplexSquareRoot:47: "
+{-# LINE 47 "playground/Number/ComplexSquareRoot.hs" #-}
+ DocTest.property
+{-# LINE 47 "playground/Number/ComplexSquareRoot.hs" #-}
+     (\x -> not (isZero x) ==> SR.recip (SR.recip x) == sr x)
+ DocTest.printPrefix "Number.ComplexSquareRoot:48: "
+{-# LINE 48 "playground/Number/ComplexSquareRoot.hs" #-}
+ DocTest.property
+{-# LINE 48 "playground/Number/ComplexSquareRoot.hs" #-}
+     (\x -> not (isZero x) ==> Laws.inverse SR.mul SR.recip SR.one (sr x))
diff --git a/test/Test/Number/GaloisField2p32m5.hs b/test/Test/Number/GaloisField2p32m5.hs
--- a/test/Test/Number/GaloisField2p32m5.hs
+++ b/test/Test/Number/GaloisField2p32m5.hs
@@ -1,37 +1,70 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-module Test.Number.GaloisField2p32m5 where
-
-import qualified Number.GaloisField2p32m5 as GF
-
-import qualified Algebra.Laws as Laws
-
-import Test.NumericPrelude.Utility (testUnit)
-import Test.QuickCheck (Testable, quickCheck, (==>))
-import qualified Test.HUnit as HUnit
-
+-- Do not edit! Automatically created with doctest-extract from src/Number/GaloisField2p32m5.hs
+{-# LINE 33 "src/Number/GaloisField2p32m5.hs" #-}
 
-import NumericPrelude.Base as P
-import NumericPrelude.Numeric as NP
+module Test.Number.GaloisField2p32m5 where
 
+import qualified Test.DocTest.Driver as DocTest
 
-test :: Testable a => (GF.T -> a) -> IO ()
-test = quickCheck
+{-# LINE 34 "src/Number/GaloisField2p32m5.hs" #-}
+import     qualified Number.GaloisField2p32m5 as GF
+import     qualified Algebra.Laws as Laws
+import     Test.QuickCheck ((==>))
+import     NumericPrelude.Numeric
+import     NumericPrelude.Base
+import     Prelude ()
 
+gf     :: GF.T -> GF.T
+gf     = id
 
-tests :: HUnit.Test
-tests =
-   HUnit.TestLabel "galois field 2^32-5" $
-   HUnit.TestList $
-   map testUnit $
-      ("addition, zero",         test (Laws.identity (+) zero)) :
-      ("addition, commutative",  test (Laws.commutative (+))) :
-      ("addition, associative",  test (Laws.associative (+))) :
-      ("addition, negate",       test (Laws.inverse (+) negate zero)) :
-      ("addition, subtract",     test (\x -> Laws.inverse (+) (x-) x)) :
-      ("multiplication, one",          test (Laws.identity (*) one)) :
-      ("multiplication, commutative",  test (Laws.commutative (*))) :
-      ("multiplication, associative",  test (Laws.associative (*))) :
-      ("multiplication, recip",        test (\y -> y /= 0 ==> Laws.inverse (*) recip one y)) :
-      ("multiplication, division",     test (\y x -> y /= 0 ==> Laws.inverse (*) (x/) x y)) :
-      ("multiplication and addition, distributive",   test (Laws.leftDistributive (*) (+))) :
-      []
+test :: DocTest.T ()
+test = do
+ DocTest.printPrefix "Number.GaloisField2p32m5:46: "
+{-# LINE 46 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 46 "src/Number/GaloisField2p32m5.hs" #-}
+     (Laws.identity (+) zero . gf)
+ DocTest.printPrefix "Number.GaloisField2p32m5:47: "
+{-# LINE 47 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 47 "src/Number/GaloisField2p32m5.hs" #-}
+     (Laws.commutative (+) . gf)
+ DocTest.printPrefix "Number.GaloisField2p32m5:48: "
+{-# LINE 48 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 48 "src/Number/GaloisField2p32m5.hs" #-}
+     (Laws.associative (+) . gf)
+ DocTest.printPrefix "Number.GaloisField2p32m5:49: "
+{-# LINE 49 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 49 "src/Number/GaloisField2p32m5.hs" #-}
+     (Laws.inverse (+) negate zero . gf)
+ DocTest.printPrefix "Number.GaloisField2p32m5:50: "
+{-# LINE 50 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 50 "src/Number/GaloisField2p32m5.hs" #-}
+     (\x -> Laws.inverse (+) (x-) (gf x))
+ DocTest.printPrefix "Number.GaloisField2p32m5:51: "
+{-# LINE 51 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 51 "src/Number/GaloisField2p32m5.hs" #-}
+     (Laws.identity (*) one . gf)
+ DocTest.printPrefix "Number.GaloisField2p32m5:52: "
+{-# LINE 52 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 52 "src/Number/GaloisField2p32m5.hs" #-}
+     (Laws.commutative (*) . gf)
+ DocTest.printPrefix "Number.GaloisField2p32m5:53: "
+{-# LINE 53 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 53 "src/Number/GaloisField2p32m5.hs" #-}
+     (Laws.associative (*) . gf)
+ DocTest.printPrefix "Number.GaloisField2p32m5:54: "
+{-# LINE 54 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 54 "src/Number/GaloisField2p32m5.hs" #-}
+     (\y -> gf y /= zero ==> Laws.inverse (*) recip one y)
+ DocTest.printPrefix "Number.GaloisField2p32m5:55: "
+{-# LINE 55 "src/Number/GaloisField2p32m5.hs" #-}
+ DocTest.property
+{-# LINE 55 "src/Number/GaloisField2p32m5.hs" #-}
+     (\y x -> gf y /= zero ==> Laws.inverse (*) (x/) x y)
diff --git a/test/Test/NumericPrelude/Utility.hs b/test/Test/NumericPrelude/Utility.hs
--- a/test/Test/NumericPrelude/Utility.hs
+++ b/test/Test/NumericPrelude/Utility.hs
@@ -1,21 +1,17 @@
--- cf. utility-ht Test.Utility
 module Test.NumericPrelude.Utility where
 
-import Data.List.HT (mapAdjacent, )
-import qualified Data.List as List
-import qualified Test.HUnit as HUnit
+import qualified Test.QuickCheck as QC
 
+import qualified NumericPrelude.Numeric as NP
 
-testUnit :: (String, IO ()) -> HUnit.Test
-testUnit (label, check) =
-   HUnit.TestLabel label (HUnit.TestCase check)
+import Data.Eq.HT (equating)
 
--- compare the lists simultaneously
-equalLists :: Eq a => [[a]] -> Bool
-equalLists xs =
-   let equalElems ys =
-          and (mapAdjacent (==) ys)  &&  length xs == length ys
-   in  all equalElems (List.transpose xs)
 
-equalInfLists :: Eq a => Int -> [[a]] -> Bool
-equalInfLists n xs = equalLists (map (take n) xs)
+equalTrunc :: Int -> [NP.Rational] -> [NP.Rational] -> Bool
+equalTrunc n = equating (take n)
+
+
+infixr 0 /\
+
+(/\) :: (Show a, QC.Testable test) => QC.Gen a -> (a -> test) -> QC.Property
+(/\) = QC.forAll
diff --git a/test/Test/Run.hs b/test/Test/Run.hs
--- a/test/Test/Run.hs
+++ b/test/Test/Run.hs
@@ -1,36 +1,44 @@
+-- Do not edit! Automatically created with doctest-extract.
 module Main where
 
-import qualified Test.MathObj.RefinementMask2 as RefinementMask2
-import qualified Test.Algebra.RealRing as RealRing
-import qualified Test.Algebra.IntegralDomain as Integral
-import qualified Test.Algebra.Additive as Additive
-import qualified Test.MathObj.Gaussian.Polynomial as GaussPoly
-import qualified Test.MathObj.Gaussian.Variance as GaussVariance
-import qualified Test.MathObj.Gaussian.Bell as GaussBell
-import qualified Test.MathObj.PartialFraction as PartialFraction
-import qualified Test.MathObj.Matrix  as Matrix
-import qualified Test.MathObj.Polynomial  as Polynomial
-import qualified Test.MathObj.PowerSeries as PowerSeries
-import qualified Test.Number.ComplexSquareRoot as CSqRt
-import qualified Test.Number.GaloisField2p32m5 as GF
-import qualified Test.HUnit.Text as HUnitText
-import qualified Test.HUnit as HUnit
+import qualified Test.Algebra.Additive
+import qualified Test.Algebra.IntegralDomain
+import qualified Test.Algebra.PrincipalIdealDomain
+import qualified Test.Algebra.RealRing
+import qualified Test.MathObj.Gaussian.Bell
+import qualified Test.MathObj.Gaussian.Polynomial
+import qualified Test.MathObj.Gaussian.ExponentTuple
+import qualified Test.MathObj.Gaussian.Variance
+import qualified Test.MathObj.Matrix
+import qualified Test.MathObj.PartialFraction
+import qualified Test.MathObj.Polynomial
+import qualified Test.MathObj.Polynomial.Core
+import qualified Test.MathObj.PowerSeries
+import qualified Test.MathObj.PowerSeries.Core
+import qualified Test.MathObj.PowerSeries.Example
+import qualified Test.MathObj.RefinementMask2
+import qualified Test.Number.ComplexSquareRoot
+import qualified Test.Number.GaloisField2p32m5
 
+import qualified Test.DocTest.Driver as DocTest
+
 main :: IO ()
-main =
-   print =<<
-      HUnitText.runTestTT (HUnit.TestList $
-         RefinementMask2.tests :
-         RealRing.tests :
-         Integral.tests :
-         Additive.tests :
-         GaussVariance.tests :
-         GaussBell.tests :
-         GaussPoly.tests :
-         PartialFraction.tests :
-         Matrix.tests :
-         Polynomial.tests :
-         PowerSeries.tests :
-         CSqRt.tests :
-         GF.tests :
-         [])
+main = DocTest.run $ do
+    Test.Algebra.Additive.test
+    Test.Algebra.IntegralDomain.test
+    Test.Algebra.PrincipalIdealDomain.test
+    Test.Algebra.RealRing.test
+    Test.MathObj.Gaussian.Bell.test
+    Test.MathObj.Gaussian.Polynomial.test
+    Test.MathObj.Gaussian.ExponentTuple.test
+    Test.MathObj.Gaussian.Variance.test
+    Test.MathObj.Matrix.test
+    Test.MathObj.PartialFraction.test
+    Test.MathObj.Polynomial.test
+    Test.MathObj.Polynomial.Core.test
+    Test.MathObj.PowerSeries.test
+    Test.MathObj.PowerSeries.Core.test
+    Test.MathObj.PowerSeries.Example.test
+    Test.MathObj.RefinementMask2.test
+    Test.Number.ComplexSquareRoot.test
+    Test.Number.GaloisField2p32m5.test
