Commit Graph

67 Commits

Author SHA1 Message Date
Patrick Lühne 8e32b58c99
Remove unneeded indirection from vector types
The type aliases for vectors of formulas and terms were defined as
vectors of boxed formulas and terms, respectively. This is an
unnecessary indirection, so store the formulas and terms directly.
2020-04-13 22:16:01 +02:00
Patrick Lühne 2fa592576b
Take reference-counted arguments by value
These reference-counted arguments were taken by reference, which made it
necessary to clone them. If a reference-counted object is created for the
sole purpose of being passed to one of these methods, it would be cloned
unnecessarily. This changes the signatures to take these arguments by
value, shifting the responsibility of cloning the reference-counted
objects to the users of these methods.
2020-04-13 22:09:43 +02:00
Patrick Lühne 7d22e47ba1
Represent quantified formulas consistently
Existential and universal quantification used redundant data
representations, while they actually share the same structure. This
unifies both into a single QuantifiedFormula type.
2020-04-13 22:05:09 +02:00
Patrick Lühne 7566fdaa29
Support n-ary biconditionals
For convenience, support biconditionals with more than one argument.
An n-ary “if and only if” statement

    F_1 <-> F_2 <-> ... <-> F_n

is to be interpreted as

    F_1 <-> F_2 and F2 <-> F3 and ... and F_(n - 1) <-> F_n
2020-04-13 21:59:25 +02:00
Patrick Lühne 855fd9abcf
Support right-to-left implications
As right-to-left implications are common in answer set programming, this
adds support for using implications in both directions.
2020-04-13 21:44:02 +02:00
Patrick Lühne 5bbb09eef8
Split formatting utils into separate files
For clarity, this moves the formatting functionality related to formulas
and terms into two separate files.
2020-04-09 22:09:15 +02:00
Patrick Lühne fd6ba4a005
Test crate with GitHub Actions
This adds a GitHub Actions workflow to test this crate with the Rust
stable, beta, and nightly toolchains.
2020-04-09 15:34:49 +02:00
Patrick Lühne 153f77621e
Fix precedence of absolute value operation
As the absolute value operation has its own type of parentheses, it
never needs to take precedence over other terms in order to be displayed
correctly. To avoid extraneous parentheses around absolute value
operations, set its precedence level to 0.
2020-03-30 06:42:54 +02:00
Patrick Lühne 551c35ed75
Fix formatting of binary operations
The precedence rules of binary operations are a bit trickier than
expected. The fact that a parent and a child term have the same
precedence level doesn’t automatically mean that parentheses can be
omitted. This is the case, for example, with

    a - (b + c)

While addition and subtraction have the same precedence level, the
parenthesis cannot be omitted. In general, this happens on the right-
hand side of the subtraction, division, and modulo operators if the
right-hand side has the same precedence level.

This patch fixes the output of binary operations accordingly.
2020-03-30 06:37:21 +02:00
Patrick Lühne 549f127729
Derive simple enums from basic traits
This adds derive statements from Copy, Clone, PartialEq, and Eq to the
operator enums as well as SpecialInteger.
2020-03-30 06:37:21 +02:00
Patrick Lühne a304ec9a75
Fix output of Booleans in formulas
Booleans are supposed to be formatted without a leading hash sign in
both terms and formulas. By mistake, the formula formatter added leading
hash signs though.
2020-03-30 06:37:21 +02:00
Patrick Lühne a82b4080c8
Fix function formatting
By mistake, a function’s name was printed two consecutive times if the
function had more than one argument.
2020-03-30 06:37:21 +02:00
Patrick Lühne 90f7be2f33
Minor refactoring for clarity 2020-03-30 06:37:21 +02:00
Patrick Lühne a127a053b2
Support formatting special integers separately
This adds Debug and Display trait implementations for the SpecialInteger
enum to make it possible to format its values without having to wrap it
in a Term variant.
2020-03-30 06:37:21 +02:00
Patrick Lühne 14abd73110
Remove unneeded lifetime specifiers 2020-03-30 05:19:01 +02:00
Patrick Lühne 3a5788bd24
Remove redundant release badge
Provided that the latest version of this crate is always published on
crates.io and tagged as a release on GitHub.com, the crates.io and the
GitHub.com release badges will always show the same version.
Consequently, remove the GitHub.com release badge to avoid redundancy.
2020-02-25 15:27:24 +01:00
Patrick Lühne a446aed011
Initial commit
This provides an abstract syntax tree for first-order logic with integer
arithmetics. Initially, the following types of formulas are supported:

- Booleans values (true and false)
- predicates
- negated formulas
- comparisons of terms (<, ≤, >, ≥, =, ≠)
- implications and biconditionals
- conjunctions and disjunctions of formulas
- existentially and universally quantified formulas

In addition, these types of terms are provided:

- Boolean values (true and false)
- integers
- strings
- special integers (infimum and supremum)
- symbolic functions
- variables
- binary operations (addition, subtraction, multiplication, division,
  modulo, exponentiation)
- unary operations (absolute value, numeric negation)
2020-02-05 03:23:11 +01:00