Skip to main content

Unification algorithm

Project description

[![](https://travis-ci.org/logpy/unification.png)](https://travis-ci.org/logpy/unification)

Straightforward Unification, extensible via dispatch.

Examples

>>> from unification import *
>>> unify(1, 1)
{}
>>> unify(1, 2)
False
>>> x = var('x')

>>> unify((1, x), (1, 2))
{~x: 2}

>>> unify((x, x), (1, 2))
False

@unifiable
class Account(object):
    def __init__(self, id, name, balance):
        self.id = id
        self.name = name
        self.balance = balance

data = [Account(1, 'Alice', 100),
        Account(2, 'Bob', 0),
        Account(2, 'Charlie', 0),
        Account(2, 'Denis', 400),
        Account(2, 'Edith', 500)]

id, name, balance = var('id'), var('name'), var('balance')

>>> [unify(Account(id, name, balance), acct) for acct in data]
[{~name: 'Alice', ~balance: 100, ~id: 1},
 {~name: 'Bob', ~balance: 0, ~id: 2},
 {~name: 'Charlie', ~balance: 0, ~id: 2},
 {~name: 'Denis', ~balance: 400, ~id: 2},
 {~name: 'Edith', ~balance: 500, ~id: 2}]

>>> [unify(Account(id, name, 0), acct) for acct in data]
[False,
 {~name: 'Bob', ~id: 2},
 {~name: 'Charlie', ~id: 2},
 False,
 False]

History

This was carved out from the LogPy project.

Author

Matthew Rocklin

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

unification-0.3.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unification-0.3.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file unification-0.3.1.tar.gz.

File metadata

  • Download URL: unification-0.3.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for unification-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e59bb12cf3252c57436e9b65cb4eeb516fd6e07427ffad073d2d304a6da73c87
MD5 8aae886eff9034dbb02eb83c00f556e9
BLAKE2b-256 a2e266aa8756f2a5c3f9f8c857c9f7b9ec036ea4e53eca52ffb2a372c1ec3d56

See more details on using hashes here.

File details

Details for the file unification-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: unification-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for unification-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf92f5d3338bc108c1fb742cb792321cc58458b70ca271e32486e2c0bcbec915
MD5 195d68e1a529900cfca3226028c84533
BLAKE2b-256 89414adbaafba55513ceda4e178eb9f9f77b967c783d1ecce4e07c0c4d04b90c

See more details on using hashes here.

Supported by

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