Skip to main content

A solver for combinatorics math word problems.

Project description

# About This repository contains the code associated to the paper [Lifted Reasoning for Combinatorical Counting](https://jair.org/index.php/jair/article/view/14062).

## Installation

install.sh installs the python environment with all the requirements listed in requirements.txt.

install-tools.sh installs optional third-party tools used in the experiments of the paper, but they are not a necessary requirement to run CoSo.

## Run

Activate the python environment pyenv and run python coso.py [filename], where filename is a file containing a CoLa problem (see below).

Add the option -v to generate a visual representation of the reasoning in CoSo. You can specify a filename (.html) if you want to save the output in a custom location.

# CoSo CoSo is a lifted solver for combinatorics problems expressed in CoLa. Lifted reasoning is a form of automated reasoning which is based on the manipulation of groups of objects and their sizes to answer counting-related queries. CoSo can thus answer efficiently to problems expressed in CoLa such as:

> A kit of toy shapes contains five triangles and two squares. One triangle and one square are red. Another triangle and the other square are blue, and the remaining triangles are green. In how many different rows of four objects can the shapes be arranged if the two squares are included and the second object is green?

> Given the same set of shapes, in how many ways can the objects be divided into three(non-empty) groups such that the green objects all belong to the same group?

# CoLa The input language for the solver is CoLa: a CoLa program is defined by a multiset of objects, a configuration, and optional constraints.

The multiset of objects, the universe, can be expressed by enumeration, for example: shapes ={square_red, square_blue, triangle_red, triangle_blue, triangle_green, triangle_green, triangle_green};. Indistinguishable elements are denoted by the repetition of the same label as for triangle_green. Objects can have properties, which make them distinguishable: property red ={triangle_red, square_red};

property blue ={triangle_blue, square_blue};

property green ={triangle_green};

property triangle ={triangle_red, triangle_blue, triangle_green};

property square ={square_blue square_red};

Alternatively, the universe can be declared by listing the different properties and the corresponding number of objects with that property:

property red; property blue; property green;

#red=2; #blue=2; #green=3;

property triangle; property square;#triangle=7; #square=2;

#square&red=1; #square&blue=1; #triangle&red=1;

#triangle&blue=1; #triangle&green=3;

Set formulas allow us to refer to combinations of property according to the usual set-operations: ¬prop is the complement of a property or a set formula prop with respect to the universe. prop1 & prop2 expresses the intersection, prop1 + prop2 expresses the union of set formulas/properties.

The keyword labelled can be prepended to the property declaration as a shortcut for expressingthat all objects having the property can be distinguished from one another, for instance: labelled property people; #people=4;

### Configuration. A configuration is declared by using the following notation: - [universe] denotes the set of all permutations of the universe. - [repeated universe] denotes the set of all sequences of the universe. - {universe} denotes the set of all subsets of the universe. - {repeated universe} denotes the set of all multisubsets of the universe. - [{universe}] denotes the set of all compositions of the universe. - {{universe}} denotes the set of all partitions of the universe.

The set universe can be replaced with any name of a declared property. To refer to a valid configuration, a label is associated with the keyword in, for instance:

row in [shapes];

groups in {{shapes}};

## Constraints

Constraints restrict the set of valid configurations according to some additional requirement. In CoLa there are currently three types of constraints: size constraints, positional constraints, and counting constraints.

### Size Constraints Size constraints define either the size of a configuration or a part (a subset in a partition/composition):

#row = 4

defines that only the rows of length 4 are valid. Any arithmetic comparison can be used: =,!=,<,<=,>,>=.

### Positional Constraints. Positional constraints are expressed with name[i] in prop where name is the name of the configuration, i is the position, prop is a property for example:

row[2] in green;

### Counting Constraints. Counting constraints count either entities or parts that satisfy some property in the configuration. For example:

#row & squares = 2

states that the number of squares in a row is 2. Here we can also use any of =,!=,<,<=,>,>=. Counting constraints can be nested in partitions and compositions:

`` #(#part & green = 3) = 1;``

the keyword part denotes a generic subset of a partition/configuration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coso-1.0.0.tar.gz (76.6 kB view details)

Uploaded Source

Built Distributions

coso-1.0.0-py3-none-any.whl (82.1 kB view details)

Uploaded Python 3

coso-1.0.0-py2.py3-none-any.whl (82.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file coso-1.0.0.tar.gz.

File metadata

  • Download URL: coso-1.0.0.tar.gz
  • Upload date:
  • Size: 76.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for coso-1.0.0.tar.gz
Algorithm Hash digest
SHA256 99a9308e1293a6b2ce1ea9de787a920b59a846beb23dc012ed35a162a13a809e
MD5 67da5340e7c5f9463e32c8ca2b7e80fe
BLAKE2b-256 4a83cf7330ad88c20f2587ccf9b04a56ebdb2b53749fc570a26c82844384b120

See more details on using hashes here.

Provenance

File details

Details for the file coso-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: coso-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 82.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for coso-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4efa8312549f22e9ae1fd98c3b28ee75681a1543050f0169b1df546525ce35c
MD5 4e5c98945f86bf37d52f72229e5a3605
BLAKE2b-256 13d44540358d8426dea13c1ae8e2295b1318cba2ac3b02ce5147b5a66495ea3d

See more details on using hashes here.

Provenance

File details

Details for the file coso-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: coso-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 82.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for coso-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 162f40f5e05219a4919c0b2d454596ae111dd9115743538ad5b9320a25635160
MD5 2db1d2483bece5471d9164fc5fd9c96e
BLAKE2b-256 0950e8bf481bca8c15d4207d4988a115e25a618b7a84371344f1ed1d2177702c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page