Commit graph

414 commits

Author SHA1 Message Date
Leonardo de Moura
a57ca284ec fix(tests/library/elaborator): replace eq with my_eq because eq is now a builtin symbol
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-29 17:06:32 -07:00
Leonardo de Moura
4dd6cead83 refactor(equality): make homogeneous equality the default equality
It was not a good idea to use heterogeneous equality as the default equality in Lean.
It creates the following problems.

- Heterogeneous equality does not propagate constraints in the elaborator.
For example, suppose that l has type (List Int), then the expression
     l = nil
will not propagate the type (List Int) to nil.

- It is easy to write false. For example, suppose x has type Real, and the user
writes x = 0. This is equivalent to false, since 0 has type Nat. The elaborator cannot introduce
the coercion since x = 0 is a type correct expression.

Homogeneous equality does not suffer from the problems above.
We keep heterogeneous equality because it is useful for generating proof terms.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-29 16:20:06 -07:00
Leonardo de Moura
5f11392fcc test(numerics/numeric_traits): add missing test
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-28 07:50:33 -07:00
Leonardo de Moura
1d18f60dd5 fix(numerics): add missing numeric_traits<float>::zero()
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-28 07:47:23 -07:00
Leonardo de Moura
dbefc91151 fix(kernel/metavar): add normalize assignment justification
We need that when we normalize the assignment in a metavariable environment.
That is, we replace metavariable in a substitution with other assignments.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-27 11:02:34 -07:00
Leonardo de Moura
e0ca27bfb3 fix(tests/library/rewriter): warning
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-25 08:33:53 -07:00
Leonardo de Moura
434c33f225 feat(metavar): automatically apply beta-reduction when instantiating metavariable applications (i.e., expressions of the form (?m a)), when the metavariable is a lambda
This feature is useful for problems that require higher-order matching and/or unification.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-23 16:35:50 -07:00
Leonardo de Moura
f1e0d6ec29 refactor(beta_reduction): move beta reduction functions to the kernel, delete reduce.cpp file and tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-23 15:44:26 -07:00
Leonardo de Moura
c1e451151a feat(replace_visitor): add an abstract class for applying transformations on expressions
I also removed replace_using_ctx since it is subsumed by the new class.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-23 15:01:37 -07:00
Leonardo de Moura
13531b7d3e refactor(kernel): rename trace to justification
Motivations:

- We have been writing several comments of the form "... trace/justification..." and "this trace object justify ...".
- Avoid confusion with util/trace.h

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-23 13:42:17 -07:00
Leonardo de Moura
8e1a75ce1c feat(elaborator): only process upper bound constraints when the corresponding metavariable does not have lower bound and max constraints
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-23 13:09:13 -07:00
Leonardo de Moura
172567a2fb feat(elaborator): add support for upper bounds, max constraints, and fix bugs
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-23 12:01:39 -07:00
Leonardo de Moura
c635c16637 refactor(ho_unifier): remove ho_unifier, it has been subsumed by the elaborator class
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 17:51:54 -07:00
Leonardo de Moura
019f64671b fix(elaborator): add basic support for flex-flex pairs, add more tests, fix bug when enumerating different solutions
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 17:49:37 -07:00
Leonardo de Moura
80a507cf45 refactor(tests/frontends/lean/implicit_args): remove implicit_args unit tests from frontends/lean, all tests were moved to tests/library/elaborator
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 16:42:07 -07:00
Leonardo de Moura
7ad256131e feat(elaborator): add support for constraints of the form ?m[inst, ...] == t, fix bugs, add more tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 16:39:22 -07:00
Leonardo de Moura
874f67c605 feat(normalizer): remove normalization rule t == t ==> true
This normalization rule is not really a computational rule.
It is essentially encoding the reflexivity axiom as computation.
It can also be abaused. For example, with this rule,
the following definition is valid:

Theorem Th : a = a := Refl b

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 14:02:48 -07:00
Leonardo de Moura
5e61496381 test(elaborator): add more tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 13:45:20 -07:00
Leonardo de Moura
cb2c73cf37 feat(elaborator): add higher-order matching support to elaborator
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 11:22:00 -07:00
Leonardo de Moura
f4592da87f feat(elaborator): solve more unification constraints, add more tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:37 -07:00
Leonardo de Moura
dc51d35dc0 feat(library/type_inferer): add support for metavariables at type_inferer
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:37 -07:00
Leonardo de Moura
7f96c07a01 refactor(library): rename light_checker to type_inferer
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
dc0e7a4472 feat(pos_info_provider): add position information provider for expressions
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
42edc4a72d test(set): add set of pointers test
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
b1b49e86e7 test(elaborator): add simple test
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
1548ffabb1 feat(elaborator): add new elaborator interface
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
7cf83800c0 refactor(metavar): implement metavar_env, and use unification_constraint and trace objects in the type_checker, light_checker
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
1f0eab7a14 test(type_checker): add new tests for type_checker trace objects
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
85bfa45e6a refactor(kernel_exception): delete kernel_exception_formatter, and implement kernel_exception pretty printer as a virtual method
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
d843d432d3 refactor(kernel): move printer and formatter objects to the kernel
The printer and formatter objects are not trusted code.
We moved them to the kernel to be able to provide them as an argument to the trace objects.
Another motivation is to eliminate the kernel_exception_formatter hack.
With the formatter in the kernel, we can implement the pretty printer for kernel exceptions as a virtual method.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
ddb90d3038 feat(kernel): add unification_constraint and trace objects to the kernel
Trace objects will be used to justify steps performed by engines such as the elaborator. We use them to implement non-chronological backtracking in the elaborator. They are also use to justify to the user why something did not work.

The unification constraints are in the kernel because the type checker may create them when type checking a term containing metavariables.

Remark: a minimalistic kernel does not need to include metavariables, unification constraints, nor trace objects. We include these objects in our kernel to minimize code duplication.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
e741cc29ef test(metavar): encode two of the bad examples as unit tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
59914a36f3 refactor(metavar): reorganize and simplify metavariables
- Use hierarchical names instead of unsigned integers to identify metavariables.
- Associate type with metavariable.
- Replace metavar_env with substitution.
- Rename meta_ctx --> local_ctx
- Rename meta_entry --> local_entry
- Disable old elaborator
- Rename unification_problems to unification_constraints
- Add metavar_generator
- Fix metavar unit tests
- Modify type checker to use metavar_generator
- Fix placeholder module

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00
Leonardo de Moura
93d4466d06 refactor(interval): move interval unit tests to tests/util/interval
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-21 18:17:34 -07:00
Leonardo de Moura
f18d35555e refactor(interval): organize template source code using the approach described at http://www.codeproject.com/Articles/3515/How-To-Organize-Template-Source-Code
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-21 18:15:27 -07:00
Leonardo de Moura
e208309abd refactor(numerics): rename power operator to pow, the idea is to follow the C/C++ name convention for the power operator
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-21 17:23:56 -07:00
Leonardo de Moura
1429cc9df2 feat(numerics): add finite field Z/pZ
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-18 13:27:28 -07:00
Leonardo de Moura
bdade0e638 fix(numerics): problem with gcd tests on OSX
Now, we only test gcd(a, b) for a != b && a != 0 && b != 0.
When one of these conditions do not hold, the result is implementation dependent.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-17 10:38:02 -07:00
Leonardo de Moura
cf2c0f8ebb feat(numerics): add gcd and extended gcd templates (for primitive types)
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-16 18:18:20 -07:00
Leonardo de Moura
39f68ed0d6 feat(numerics): add is_prime function
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-16 17:25:08 -07:00
Leonardo de Moura
1097bbfb22 fix(style): fix warnings produced by cpplint.py, disable sizeof(type) warning
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-16 17:04:39 -07:00
Leonardo de Moura
105f55c68b feat(numerics): add zero() method to all numeric_traits
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-16 16:55:17 -07:00
Leonardo de Moura
ff04c5a2e2 test(numerics): add test to make sure that zeros of different precision mpfp numbers are the equal.
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-16 16:54:43 -07:00
Leonardo de Moura
467eff4662 add(numerics): add prime number generator/iterator
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-16 16:05:45 -07:00
Leonardo de Moura
0783805671 feat(kernel): add weight to kernel definitions
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-15 14:50:08 -07:00
Leonardo de Moura
5bd6ba37d0 fix(light_checker): fix inconsistent cache bug in light_checker, add tests that expose the problem
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-01 19:25:58 -07:00
Leonardo de Moura
aa5be3262f fix(type_checker): fix inconsistent cache bug in type_checker, add tests that expose the problem
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-01 19:23:55 -07:00
Leonardo de Moura
2089d12bd0 fix(replace_using_ctx): fix inconsistent cache bug in replace_using_ctx, and add tests that expose the problem
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-01 18:52:18 -07:00
Soonho Kong
c50bc13be0 test(library/rewriter): add more tests 2013-10-01 00:30:38 -07:00
Leonardo de Moura
15979ab991 fix(lean): fix warnings produced by cppcheck
Fix (relevant) warnings produced by http://cppcheck.sourceforge.net.
Most warnings produced were incorrect. The tool does not seem to support some of the C++11 new features.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-30 21:38:55 -07:00
Leonardo de Moura
30089aa4f8 test(type_checker): add example showing how to use the kernel exception formatter
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-30 16:39:29 -07:00
Soonho Kong
54f4c4d9bc test(library/rewriter/fo_match): clean up enable_trace 2013-09-29 18:36:01 -07:00
Leonardo de Moura
21f9699661 test(splay_tree): add missing test
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-29 17:28:10 -07:00
Leonardo de Moura
790c2a72d5 test(safe_arith): add unit tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-29 17:20:32 -07:00
Leonardo de Moura
1179b6b52b test(hash): add missing tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-29 17:20:32 -07:00
Leonardo de Moura
57b6148bbb test(buffer): add missing tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-29 17:20:32 -07:00
Leonardo de Moura
02f621aa45 test(lazy_list): add more tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-29 14:38:35 -07:00
Leonardo de Moura
3c8dff9085 feat(lazy_list): implement ML-like lazy lists
We will use lazy lists to represent the set of solutions produced by the elaborator. The elaborator plugins will also use lazy lists.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-29 12:35:26 -07:00
Soonho Kong
4602dfd209 test(util/numerics): more tests to improve coverage 2013-09-28 23:38:17 -07:00
Soonho Kong
fb3635a9ef test(util/numerics/mpbp): add more tests for improving coverage 2013-09-28 01:01:52 -07:00
Leonardo de Moura
d2667d56c0 test(lean/parser): add more tests for improving coverage
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-27 09:59:50 -07:00
Leonardo de Moura
0ff69d28f3 test(lean/scanner): add more tests for improving coverage
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-27 09:59:50 -07:00
Leonardo de Moura
6fc177056e refactor(tests/frontends/lean): use consistent name convention for file names
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-27 09:59:50 -07:00
Soonho Kong
6a0d211d54 test(fo_match): add more unittests
[skip ci]
2013-09-27 01:53:42 -07:00
Leonardo de Moura
9d8ff0eadb test(mpz): add unit tests for mpz
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-26 20:01:39 -07:00
Leonardo de Moura
5cce74d116 test(library): add tests for improving coverage
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-26 19:43:10 -07:00
Leonardo de Moura
54e63fd4de feat(splay_tree): add fold and for_each templates for splay_tree and splay_map
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-26 18:18:20 -07:00
Leonardo de Moura
d7ed1560a9 feat(name_generator): add name_generator for unique names modulo a prefix
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-26 18:18:06 -07:00
Leonardo de Moura
19f4554145 test(exception): add tests for improving coverage
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-26 08:35:13 -07:00
Leonardo de Moura
a24dbc3527 test(buffer): add tests for improving coverage
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-26 08:35:13 -07:00
Leonardo de Moura
4bae715350 fix(memory): disable problematic test when tcmalloc is used
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 22:39:49 -07:00
Leonardo de Moura
c00534209a test(splay_map): add tests for improving code coverage
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 22:12:49 -07:00
Leonardo de Moura
23e2f72f42 test(list): add tests for improving code coverage
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 22:04:24 -07:00
Leonardo de Moura
db4e5ab0ad feat(expr_lt): improve expr_lt performance by using hash codes, and add more tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 21:59:58 -07:00
Leonardo de Moura
a7707dd669 test(bit_tricks): add tests for log2 2013-09-25 20:58:01 -07:00
Leonardo de Moura
44a16cab6a test(exception): add new tests exception and parser_exception
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 20:57:53 -07:00
Leonardo de Moura
87e749cd12 test(trace): add unit test for trace module
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 20:30:05 -07:00
Leonardo de Moura
e16f45854b refactor(deep_copy): simplify deep_copy implementation, and move unit test to separate file
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 20:25:24 -07:00
Leonardo de Moura
037ebfd1d4 refactor(util): make 'util/test.h' the first include
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-25 20:13:05 -07:00
Soonho Kong
ad62f9762b fix(tests/util): use lean_assert_eq 2013-09-25 19:22:36 -07:00
Soonho Kong
475338080f fix(tests/interval): use new lean_assert and lean_assert_eq 2013-09-25 18:40:45 -07:00
Soonho Kong
1d8b7dc193 Update 'orelse' and 'then' rewriter to take a list of rewriters 2013-09-25 16:46:39 -07:00
Soonho Kong
a50f5f92b8 Rename 'rewrite' to 'Rewriter', change type of rewriter::operator() 2013-09-25 15:38:16 -07:00
Soonho Kong
57e9e2c658 Re-implement rewrite module using rewrite_cell 2013-09-24 19:11:09 -07:00
Leonardo de Moura
ba0528c298 Implement total order on expressions
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-24 12:16:32 -07:00
Leonardo de Moura
e23813f15d Add support for creating unique internal names.
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-24 11:01:30 -07:00
Leonardo de Moura
1779b29355 Implement map using splay_trees
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-24 01:44:46 -07:00
Soonho Kong
71fb150333 Fix type of rewrite() to take an env. Add skeletons for other rewriters 2013-09-24 01:20:45 -07:00
Soonho Kong
81c9de229b Add then and orelse rewrite combinators and tests 2013-09-24 01:19:03 -07:00
Soonho Kong
9ba6068858 Update fo_match 2013-09-24 01:19:03 -07:00
Soonho Kong
f89ededddc Add rewrite and first-order pattern matching skeletal 2013-09-24 01:19:03 -07:00
Leonardo de Moura
b78b2e0585 Add remaining splay tree methods
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-24 01:04:02 -07:00
Leonardo de Moura
d31f3facac Implement splay trees
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-23 22:31:18 -07:00
Leonardo de Moura
46d6c41835 Fix bug in the type checker (when type checking terms with meta-variables).
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-22 19:12:19 -07:00
Leonardo de Moura
c847d27763 Improve higher order unification
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-21 00:41:49 -07:00
Leonardo de Moura
d29ec9ab6f Add tests for memory.cpp
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-20 22:37:13 -07:00
Leonardo de Moura
7ac94ee976 Add max_sharing tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-20 22:01:40 -07:00
Leonardo de Moura
d34cfe3f8a Add simple formatter tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-20 21:46:32 -07:00
Leonardo de Moura
42482622f6 Add imitation for lambdas and Pis
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-19 16:28:23 -07:00
Leonardo de Moura
d7cc5d2404 Fix bug in ho_unifier
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-19 16:28:23 -07:00