Libraries, etc. | ||||||||||||||||||||||||||||
Logical types has the following libraries, systems, and sample code. All provided with the usual caveats (they are not guaranteed to work, and Logical Types is not liable for you downloading and using this code):
| ||||||||||||||||||||||||||||
| Libraries | ||||||||||||||||||||||||||||
utils |
a set of utilities useful for building production systems
contains modules: | |||||||||||||||||||||||||||
qcheck2 |
A testing/verification framework for Mercury programs
see
| |||||||||||||||||||||||||||
| Systems | ||||||||||||||||||||||||||||
ltq |
Extends Mercury with
op/3 declarations, allowing syntax modificationsee installation instructions | |||||||||||||||||||||||||||
| Fixes/Patches | ||||||||||||||||||||||||||||
anys |
A set of fixes to the utilities provided in the Mercury
extras distribution supporting operations with the any mode
see
| |||||||||||||||||||||||||||
| Alpha: You Have Been Warned! | ||||||||||||||||||||||||||||
matrix |
Work in progress to add a viable matrix protocol; will be rolled into the
utils library. | |||||||||||||||||||||||||||
tiffany |
A very small, thread-un-safe, foreign interface to libtiff; also requires
matrix (which it already bundles). | |||||||||||||||||||||||||||
Incorporates strong typing over predicate logic programming, and, conversely, incorporates predicate logic programming into strongly typed functional languages. The style of predicate logic is from Prolog; the strongly typed functional language is Haskell.
Tuesday, December 18, 2012
Logical Types Libraries
Installation Instructions for QuickSilver
| Installation Instructions for Quicksilver | ||||
| PowerPC/Apple architecture | ||||
| ||||
Creating syntax with op/3 can become complicated when several operators interact to create a term. I've provided a module that prints the canonical representation of a parsed term (write_canonical.m) and a testing module (test_op.m) that allows prototyping of operator declarations and allows submitting terms under that syntax. The whole test system may be built in the usual way:$ mmake test_op.depend $ mmake test_op |
Logical Types Company Mission Statement
| Rule-based Systems |
Rule-based systems process data according to sets of constraints established by the user. The results of these systems is a collection of rule findings that can be used to construct the final product or to assist the user in rendering an informed decision.
The above description may seem all-too-general, as that describes the what most programs do. This is indeed correct: rule-based programming is sufficiently powerful enough to describe any computable system. In fact, the rule-based approach is now being viewed by the mainstream as the preferred method for workflow analysis, process, resource scheduling, service-based systems, etc. Nearly every software system has a set of rules, explicit or implied, to which it adheres. The rule-based programming style model these rule constructs directly and facilitate their manipulation as the system grows and changes.
| ||
| Deductive Logic |
The traditional approach to building logic systems is to construct a set of clauses where the head of the clause matches a condition and the rest of the clause verifies the match through a set of goals for that match. These clauses are known as rules and a set of rules is a predicate, and this predicate can be used, in turn, as a goal in a new rule. Deductive logic matches problem specifications very closely and is a very effective way to convert a set of requirements into a production system. Some examples of types of problems that are easily modelled in deductive logic are expert systems, planning systems and scheduling systems.
Deductive systems are used when the rules are clear, when the user requires certain outcomes, and are very good at "explaining" what the rule findings are and how they were arrived at.
| ||
| Inductive Logic |
The opposite approach to a deductive system is an inductive one. Whereas in an deductive system, the user has very exacting control over the process and outcome, in an inductive system, the rules are obtained by deriving the relations between input data and their outcomes, with very little guidance, if any, from the builder of the system. Traditional inductive systems required very clean data and had little tolerance for deviation -- a slight perturbation in the data set could cause the system to fall into an undefined state. Modern inductive systems have taken a different approach: reaping the benefits of recent advances in probability and statistics, these systems (such as Bayesian systems and neural networks) are highly redundant and adaptive. These new systems consistently perform well: they have excellent success narrowing to a classification from apparently unrelated attributes, and they have a high rate of stability, being very fault-tolerant, even in the presence of very noisy data. It is also trivial to convert a statically trained inductive system to one that learns continuously from new inputs and outcomes.
Inductive systems are used when users cannot explain how they arrive at decisions (attributing the outcomes to a "feel" for the situation), and where gradual trends result in eventual changes to outcomes. These systems excel at making the correct decision with a very high degree of confidence, but are poor at explaining what prompted the decision.
| ||
| Our Approach |
Logical Types, LLC uses both deductive and inductive logic to build systems as the needs of the customer demand:
| ||
PADL Symposium 2006 Post-Mortem
After Action Report: PADL 2006
Practical Aspects of Declarative Languages
Introduction
This is an highly-opinionated report on the presentations at the PADL 2006. The sessions are presented chronologically, but are tabled in the contents by topic, and cross-referenced by their practicality (i.e. in what I found useful in the presentation).
Presentations
| Cross References | |
|---|---|
| Topic | Practicality |
| Invited Speakers | Practical Results |
| Phil Walder | Dominators |
| Erik Meijer | Probabilistic Prolog |
| No show: David Roundy | Distribution type |
| Theorem Provers (no, really!) | |
| "Practical" "Applications"1 | Declarative debugging |
| CHRs for testing | Improving the search from failed branches |
| Probabilistic music | Cliques as power sets |
| Genomes with distribution type | Complexity measures |
| Constraints | "Theoretical" 2 (including compiler |
| Optimal paths with dominators | implementations and optimizations)3 |
| Constraints in Mercury | Tabling and tabling 4 |
| Informing constraints with failure | Constraints 5 |
| Model checking | |
| Analysis and Verification | Reimplementing cut |
| Typing Prolog with cliques | Description logics 6 |
| Model Checking model checkers | |
| Logic Programming | |
| Generic (foreign) Cuts | |
| Tabling in Mercury | |
| Correct Tabling in XSB | |
| Declarative debugging | |
| Browsing and Querying | |
| Logical Eclipse plugin | |
| description logic queries | |
| Queries with sets with regex | |
Retrospective
As you can see below, my critisms are very harsh. This begs two questions: harsh against whom? and would I go again to a PADL? The answer to the latter is resoundingly in the affirmative (as William Byrd would pipe up: 't'): the density of useful concepts I took away from this conference was much greater than most other conferences I've attended, including, not surprisingly, the POPL.
So, why so harsh in my reviews? Was I critizing the speakers? In some cases, I was indeed critizing the speakers, particularly when they sacrifice rigor for herd thinking (particularly when they do not acknowledge such lapses), but in the main, my criticisms, such as 'this topic does not interest me', was not a criticism of the speaker, nor even the choice of topic (with the caveat that of the 17 of the 33 papers accepted, the papers accepted should be more practical and less esoteric, if the reviewers chose academic curiosities over less polished papers on the topic of applications then I do fault the selection process), but a severe criticism of me. What I mean here is that the PADL's mission is to gather reports from the front-lines, as it were. That's where companies, like mine, operate. So, companies, like mine, including mine, should be submitting these papers. We do not, and the PADL has suffered for it.
In short, the PADL was what it set out to be -- a free exchange of ideas of the application of research and an open channel between researchers and industry. AND the PADL, as good as it was, could be even better with more practical, real, applications developed in the declarative style showcased for all to see. It motivates the researchers ('my work has revelance! an audience! a fan club!'), and it improves the tools industry uses to deliver these applications ('you can do that?'). Win/win. QED.
The Challenge
So you companies that use declarative programming ... you know who you are (*cough* galois *cough* ... um, Doug, what about you? Yeah, me, too), belly up to the bar, 'cause drinks are on the house! (trans: submit papers; you are not divulging company secrets, and you're gonna get lots of neato ideas that will help you on your current projects).
Day 1: Monday, January 9, 2006
| 9:00 am | Links: Linking Theory to Practice for the Web |
| Phil Walder | |
| |
| 10:30 am | Using CHRs to generate functional test cases for the Java Card Virtual Machine |
| Sandrine-Dominique Gourand (presenter), Arnaud Gotlieb | |
| |
| 11:00 am | Probabilistic-logical Modeling of Music |
| Jon Sneyers, et al. | |
| |
| 11:30 am | Modeling Genome Evolution with a DSEL for Probabilistic Programming |
| Martin Erwig and Steve Kollmansberger (presenter) | |
| |
| 2:00 pm | Using Dominators for Solving Constrained Path Problems |
| Luis Quesada, et al. | |
| |
| 2:30 pm | Adding constraint solving to Mercury |
| Ralph Becket, et al. presented by Zoltan Somogyi (co-author) | |
| |
| 3:00 pm | A Hybrid BDD and SAT Finite Domain Constraint Solver |
| Peter Hawkins (presenter) and Peter Stuckey | |
| |
| 4:00 pm | Efficient top-down set-sharing analysis using cliques |
| Jorge Navas, Francisco Bueno and Manuel Hermenegildo (presenter) | |
| |
| 4:30 pm | Automatic Verification of a Model Checker by Reflection |
| Bow-Yaw Wang | |
|
Day 2: Tuesday, January 10, 2006
| 9:10 am8 | Generic Cut Actions for External Prolog Predicates |
| Tiago Soares, Ricardo Rocha and Michel Ferreira (presenter) | |
| |
| 9:40 am | Tabling in Mercury: Design and Implementation |
| Zoltan Somogyi (presenter) and Konstantinos Sagonas | |
| |
| 10:10 am | Incremental Evaluation of Tabled Prolog: Beyond Pure Logic Programs |
| Diptikalyan Saha and C. R. Ramakrishnan | |
| |
| 10:40 am | Controlling search space materialization in a practical declarative debugger |
| Ian MacLarty and Zoltan Somogyi (presenter) | |
| |
| 2:00 pm | LINQ: Reconciling objects, relations and XML in the .NET framework: a Personal Perspective |
| Erik Meijer | |
| |
| 3:30 pm | A Generic Code Browser with a Declarative Configuration Language |
| Kris De Volder | |
| |
| 4:00 pm | Translating Description Logic Queries to Prolog |
| Zsolt Nagy, Gergely Lukácsy (presenter) and Péter Szeredi | |
| |
| 4:30 pm | Querying Complex Graphs |
| Yanhong A. Liu (presenter) and Scott D. Stoller | |
|
Endnotes
| 1 | As all of the talks in the "Practical" "Applications" were neither practical (they were all used to further research or as dissertations) nor applications (several speakers thoughout the conference, when I queried them about aspects of their presentation stated that the works they discussed where under development still), I query the accuracy of the topic heading for these talks. A saving grace is that all of the talks on this topic did have results that were practical and immediately usable for real-world applications, unlike what some of the other presentations had to offer. |
| 2 | |
| 3 | |
| 4 | Yes, there were two presentations on tabling. Both of them I found to be very "useful" in a "theoretical" sense of the word. |
| 5 | Okay, okay, so I am looking into constraints. This does point out an issue with the symposium: it may point out things that I don't know I don't know, but it wasn't very helpful in educating me about the practical applications in these areas. |
| 6 | I think a more approapriate term for 'description logics' or 'ontologies' is 'hooey'. Bluntly, descriptions logics are as innovative and as useful as Java is ('the most distressing thing to hit computing since MS-DOS' Alan Kay). With the set of claims proponents are making grandiosely about knowledge representation, which I must remind everyone is a similar set of claims the AI community was making for symbolic representation of knowledge (what, again, is description logic? Oh, the 'symbolic representation of knowledge'? Ah, yes, we have a winner here!), in the same self-satisfied tone, just before AI went dark for twenty years, AND with the bedfellows it has (whispered: 'eggs'-'em'-'ill'), I am shocked that more gullible consumers of this hogwash haven't made the obvious connections and avoided this dead end... |
| 7 | The 'random' in "'random' testing" means 'comprehensive with random generation of parameters', not 'a random selection [e.g. not comprehensive] of possible tests'. |
| 8 | This is a departure from the published schedule; the invited speaker for the morning was a no-show. |
(originally published January 16, 2006)
Testing with qcheck, version 2.0
qcheck, version 2.0
Introduction
QuickCheck is a system developed by John Hughes and Koen Claessen. Its premise is that comprehesive testing can be obtained by combining a testing specification language and test data automation ("random testing"). It has been ported to several languages from its native Haskell: the Mercury programming language provides a QuickCheck facility in their "extras" distribution, called
qcheck.
As it stands, the original
qcheck (herein after referred to as Q1) is an excellent piece of work, fully capable of testing entire systems. It can decipher how to generate example data from user-defined types. It also provides examples for various general and specific situations where the user may wish to exercise control over the ranges or frequencies of the data generated. What, then, would need to be changed?
Not much, it turns out. The fundamental aspects of the system -- comprehesive unit testing fed by randomly-generated values and directed by a test specification remain intact, but there are several features to comprehensive testing that can be added to improve this system.
Q1 is good at verifying that one particular predicate behaves as it should, but it gives no indication that all the (interface) predicates of a system have been tested. Further, the user has some control over the detail reported for each test, but, for a user wishing a summary report, even the smallest report allowed is too much detail: adding a facility that give the user complete control over reportage becomes necessary for larger systems. Finally, Q1 has an excellent facility to generate random values for user-defined types, but for primitive types (such as char, int, and float), the approach is a bit arcane (only mentioned in one of the last examples) and lossy -- giving the user control over the random number generator itself, and integrating that part of the system with the goal of ease of use will carry forward the automation of user-defined typed values as well as simplify controlling ranges of generated primitive values.
These improvements were the aim of this new version: keep the essence of previous version while adding these new layers to help the tester verify much larger systems. The first two aims outlined above, that of comprehension and detail, are addressed by the new reporting facility that exists both outside
qcheck2 proper and is also integrated into its state. The third aim, more and simpler control over randomly-generated values, incorporate changes that now allow the user to define their own random number generator (or to use the very excellent one supplied) and also to change the generator's behavior in the midst of testing. We will address each aim, and their implementations, in the following sections.Aims
Aim 1: Comprehension
One question that testing frameworks, such as QuickCheck, must eventually address, particularly for larger systems, is the one of completeness. Or, "has the entire functionality of the system been tested?" Under the first implementation this is a difficult question to answer, and the root of this problem is a rather trivial one to fix: the second input argument to
qcheck/[4,7,8] is a string that has the purpose of describing the test to be performed. Typing this argument as a string is rather limitting: although the (human) user can seen the purpose from the description, the problem is that encoding the test description as a string does not facilitate reasoning about test results mechanically, which makes it difficult for the system to report on what was and, importantly, was not, covered in the testing.A new accumulated state variable
The fix to this problem is therefore simple: generalize the test description argument to any (univeral) type. This way other systems may, for example, generate a model of the system being tested and then, after the tests are completed, a method of tabulating and reporting the results. The internals of
Q1 change in two ways: first, the description type signature is relaxed, and second, as reportage is spread across several calls to qcheck/[4,7,8], we will defer the commitment of outputting results until the user so determines. In this case, we convert the state variable from io.state (which commits the output) to a specific accumulator (that simply collects it)::- pred qcheck(T, Desc, int, list(list(frequency)), general_frequencies, list(user_gen_type(RNG)), qstate(RNG, Desc), qstate(RNG, Desc)) <= (testable(T), random_number_generator(RNG)). :- mode qcheck(in, in, in, in, in, list_skel_in(user_gen_inst(RNG)), in, out) is det.where:
T the type (pred/func) to test Desc a generic type describing the test intnumber of tests list(list(frequency))list of specific frequencies (as per Q1)general_frequencieslist of general frequencies for testing (described later) list(user_gen_type(RNG))user-defined types for value generation, as per Q1, specialized on the random number generatorqstate(RNG, Desc)The state variable collecting test results and keeping the random number generator au courant The typeclasstestable(T)is as perQ1; and the random number generator typeclass (random_number_generator(RNG)) will be discussed under the value generator aim.For the new types forqcheck2::- type general_frequencies == assoc_list(type_desc, list(frequency)). :- type qstate(RNG, Description) ---> qstate(generator(RNG), map(Description, test_results)). :- type test_results ---> test_results(int, int, int, bag(univ)) ; falsifiable(univ).
The above
qstate type shows that the test description is mapped to the test_results type, as qcheck/[4,7,8] is called for each test, it accumulates the test results indexed by the (generic) description.The Program Modelling Tool
As Description can be of any type, we can now allow the user to pass in a simple description
string, as in Q1, or, alternatively, we can enhance the description with something that we can use as a declarative index. In Prolog, we could use the index of the module-qualified name of the predicate. Mercury is not as dynamic a system to allow any number of module/predicate/function values for Description,1 so we will employ a preprocessing system to identify and alias all interface predicate/function types to a uniform (enumerated) type. One such system is qcpt available from logicaltypes.com packaged into the ltq system. From an input set of files, qcpt generates the following types:
:- program_module
---> .
:- func all_program_modules = list(program_module).
:- func all_public_predicates = list(full_predicate_signature).
:- type public_predicate_signature
---> public_predicate / int.
:- type full_predicate_signature
---> public(program_module, public_predicate_signature).
:- type test_desc == pair(full_predicate_signature, string).
:- type public_predicate
---> .
Example
Say we wish to test a single module, for example the
peano module. By running ...$ qcpt peano.m
... the file
qcheck2.tests_digests_types.m is generated with the above type declarations and the following specific realizations:
% ...
:- type program_module
---> peano.
% ...
:- type public_predicate
---> increment
; peano
; to_peano.
:- implementation.
all_program_modules = [
peano
].
all_public_predicates = [
public(peano, increment/2),
public(peano, peano/2),
public(peano, to_peano/2)
].
A new reporting facility
Given that we now have collected all the public (or interface) predicates and functions of a system, it is now also possible to determine the completeness of the testing, in that all of those predicates were tested. It simply now falls to a system to collect the results of testing and report the results. The user may attack this task any number of ways, but we also provide one implementation in module
qcheck2.tests_digest_reports. The predicate
show_module_tests_summary(Results, !IO)
does all this work by comparing the accumulated test Results (typed as an
assoc_list(test_desc, test_results), where test_desc is provided by moduleqcheck2.tests_digest_types (generated from the tested module using qcpt), and the assoc_list is the accumulated result of calling a set of qcheck/[4,7,8] goals).
The
show_module_tests_summary/3 predicate reports the total number of tests (and those that passed) within each module and reports the number of predicates that succeeded all unit testing. This predicate also reports, by name and arity, the predicates not tested by the framework.Example
The following report ...
$ ./peano_unit_tests_missing_to_peano
Qcheck2 tested the following modules:
*** 6/6 tests passed on 2/3 predicates in peano
(did not test to_peano/2)
... shows that my modifications to module
peano_unit_tests (I commented out the to_peano/2 tests) resulted in all tests passing, but the test suite did not provide full coverage of the peano module's functionality.Traditional Reportage
Module
qcheck2.reports provides two ways to report results as Q1 did:show_test_results_sets(Results, !IO) show_test_results(Description, test_results, !IO)
The predicate
show_test_results_sets/3 simply iterates over Results, calling show_test_results/4 at each iteration. The predicate show_test_results/4 reports the results from qcheck/[4,7,8] in the style of Q1.Example
Here are some of the results reported from running
peano_unit_tests_with_failing_test with a call to show_test_results_sets/3:
...1) Test description : public(peano, increment / 2) - "Makes sure we get a successor" Number of test cases that succeeded : 100 Number of trivial tests : 0 Number of tests cases which failed the pre-condition : 02) Test description : public(peano, increment / 2) - "Checks increment/2\'s compare" Number of test cases that succeeded : 19 Number of trivial tests : 0 Number of tests cases which failed the pre-condition : 81 Distributions of selected arguments : 13 {0, 1} 5 {1, 2} 1 {2, 3}3) Test description : public(peano, to_peano / 2) - "Tests string creation" Falsifiable : i(-68) ...
The above examples demonstrate 1) a sample test report where all the tests succeeded (with no reportage on the test values used), 2) a sample where some test values were unusable (with reportage), and 3) a sample where the predicate and test values (by intention) failed the test. These tests are of the same form as those of
Q1. The major difference is that test tests are reported separately from the qcheck/[4,7,8] call. This separation allows delayed (even permanently delayed) reporting of results.Aim 2: Generation
Q1 offers a dizzying array of options when giving the user control over what test values are generated and how they are generated, that is, if these values are to be generated from user-defined, or complex (not builtin), types. It also offers a generator of such power that it is dubbed: "The Mother of all Random Number Generators" by its creator. Impressive as the above offerings are (and they are, in fact, impressive) there are two glaring wants: first, one is required to use the supplied generator -- users are not permitted alternate generators for their own testing, and this becomes an issue when, for example, "pure" randomness (such as the values provided by random.org), or cryptological-strength randomness is a requirement of the tested system, and, second, restricting the ranges of primitive builtins (or other "unbound" enumerated types (such as integer)) is not directly feasible (albeit possibly with some esoteric indirection). We address each of these wants in the new system in this document by turns.Want 1: User-supplied random number generators
Q1 was built to hide its inner workings. This software principle is considered to be good practice, but, since one of the inner workings is random number generation to generate test values, this good practice obstructs the ability to replace the random number generator when so required. The new architecture in qcheck2 exposes the random number generator in the state variable, allowing its replacement by alternate equivalent types. The change also comes with a supplied state initialization predicate that provides the default random number generator.
The design of the system requires the user to wrap their random number generator (hereinafter referred to as the RNG) in type described in the next section, and it must conform to the following typeclass:
:- typeclass random_number_generator(RNG) where [ % gives a random float on the range [0, 1) pred rnd(float::out, RNG::in, RNG::out) is det, pred reseed(int::in, RNG::unused, RNG::out) is det ].where:
rnd/3supplies a float between 0.0 and 1.0 and updates the state of the RNG; and reseed/3reinitializes the RNG with the seed supplied as the first argument.
Want 2: User-controllable numeric ranges
It is very easy for the user of
Q1 to specify a discriminated-union type and have the system generate test examples. The problem is for builtin types: Q1 does not consider bounds when generating floats, ints and, surprisingly, chars.2 One could argue that by choosing unbound types, the user must be prepared to accept any value those types describe, and indeed this is true. Where this argument falls apart is when the user wishes to test predicates within their nominal ranges. Certainly the test framework should generate test data that tests beyond the ranges, but when every test case offered is extrinsic, nothing is gained by submitting that predicate to random testing. In short, the user must be allowed direct control over ranges of test values of builtin types when the situation warrants.:- type generator(RNG) ---> generator(int_range, float_range, character_type, RNG).where:
int_rangeis either range(int, int)orunbound
Endnotes
| 1 |
Well, this statement is not true in all cases -- if all the tested predicates had the same type and modality then one may simply use the name of the predicate as the Description. See, for example, modules
foo and foo_unit_tests included in the distribution. The material point here is that although it is possible to use the name of a predicate as the Description it is not realistic given that most systems use predicates with different types, arities, and modalities. |
| 2 | Q1 treats strings as list(int), where each element is a char-equivalent int, which can be positive, negative or, as is most often the case, of very large magnitude. |
(article posted circa 2006)
Subscribe to:
Posts (Atom)