Skip to main content

A modular formal mathematics systems library, including Metamath

Project description

Formal mathematics package on python

Formal mathematics package on python.

Support a proof check system core equivalent to metamath

Install

pip install formalmath

Example use

Here is an example for propositional logic.

from formalmath.metamath import FormalSystem

# 1. Define constants in the system.
constants = ['wff', '->', '|-', '(', ')', '-.']

# 2. Define axioms.
axioms = {
    'wi': {
        'd': [],
        't': {
            'wph': 'wff ph',
            'wps': 'wff ps'
        },
        'h': {},
        'a': 'wff ( ph -> ps )'
    },
    'wn': {
        'd': [],
        't': {
            'wph': 'wff ph'
        },
        'h': {},
        'a': 'wff -. ph'
    },
    'ax-1': {
        'd': [],
        't': {
            'wph': 'wff ph',
            'wps': 'wff ps'
        },
        'h': {},
        'a': '|- ( ph -> ( ps -> ph ) )'
    },
    'ax-2': {
        'd': [],
        't': {
            'wph': 'wff ph',
            'wps': 'wff ps',
            'wch': 'wff ch'
        },
        'h': {},
        'a': '|- ( ( ph -> ( ps -> ch ) ) -> ( ( ph -> ps ) -> ( ph -> ch ) ) )'
    },
    'ax-3': {
        'd': [],
        't': {
            'wph': 'wff ph',
            'wps': 'wff ps'
        },
        'h': {},
        'a': '|- ( ( -. ph -> -. ps ) -> ( ps -> ph ) )'
    },
    'ax-mp': {
        'd': [],
        't': {
            'wph': 'wff ph',
            'wps': 'wff ps'
        },
        'h': {
            'min': '|- ph',
            'maj': '|- ( ph -> ps )'
        },
        'a': '|- ps'
    }
}

# 3. Instantiate FormalSystem.
fs = FormalSystem(constants=constants, axioms=axioms, theorems={})

# 4. Write a new theorem for the system.
mp2 = {
    'd': [],
    't': {
        'wph': 'wff ph',
        'wps': 'wff ps',
        'wch': 'wff ch'
    },
    'h': {
        'mp2.1': '|- ph',
        'mp2.2': '|- ps',
        'mp2.3': '|- ( ph -> ( ps -> ch ) )'
    },
    'a': '|- ch',
    'p':[
        'wps',
        'wch',
        'mp2.2',
        'wph',
        'wps',
        'wch',
        'wi',
        'mp2.1',
        'mp2.3',
        'ax-mp',
        'ax-mp'
    ]
}

# 5. Check the proof steps of the previous theorem in the formal system.
trace = fs._proof_check(mp2, detailed=True)
for tr in trace:
    print(tr)

The output will be

Step 1: push type assumption 'wps' -> 'wff ps'
Step 2: push type assumption 'wch' -> 'wff ch'
Step 3: push hypothesis 'mp2.2' -> '|- ps'
Step 4: push type assumption 'wph' -> 'wff ph'
Step 5: push type assumption 'wps' -> 'wff ps'
Step 6: push type assumption 'wch' -> 'wff ch'
Step 7: apply axiom 'wi', pop ['wff ps', 'wff ch']
  match wph: type 'wff', var 'ph' -> 'ps'
  match wps: type 'wff', var 'ps' -> 'ch'
  conclude -> 'wff ( ps -> ch )' and push to stack
Step 8: push hypothesis 'mp2.1' -> '|- ph'
Step 9: push hypothesis 'mp2.3' -> '|- ( ph -> ( ps -> ch ) )'
Step 10: apply axiom 'ax-mp', pop ['wff ph', 'wff ( ps -> ch )', '|- ph', '|- ( ph -> ( ps -> ch ) )']
  match wph: type 'wff', var 'ph' -> 'ph'
  match wps: type 'wff', var 'ps' -> '( ps -> ch )'
  hypothesis min matches '|- ph'
  hypothesis maj matches '|- ( ph -> ( ps -> ch ) )'
  conclude -> '|- ( ps -> ch )' and push to stack
Step 11: apply axiom 'ax-mp', pop ['wff ps', 'wff ch', '|- ps', '|- ( ps -> ch )']
  match wph: type 'wff', var 'ph' -> 'ps'
  match wps: type 'wff', var 'ps' -> 'ch'
  hypothesis min matches '|- ps'
  hypothesis maj matches '|- ( ps -> ch )'
  conclude -> '|- ch' and push to stack
Proof successfully concludes with assertion '|- ch'

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

formalmath-0.1.2.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

formalmath-0.1.2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file formalmath-0.1.2.tar.gz.

File metadata

  • Download URL: formalmath-0.1.2.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for formalmath-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7b82d56b14a83af9660dd4534751ae815baa84f86d2b634850fafab9be77489f
MD5 efc8f1bfb71324df50d54e18f1bbb633
BLAKE2b-256 cde534ef9fbbcabf09cc89cffc49b7d6eafbeaeeb4abc45d608316377737d593

See more details on using hashes here.

File details

Details for the file formalmath-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: formalmath-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for formalmath-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f507c0a5a0afa630ba0b6647823bc2e47dc0e453d3c47f1c1ac024798337ba91
MD5 0f34dec7dafb20e57d872b3a9e81f245
BLAKE2b-256 3df85af691ce926380f8557d60efcf96b06d83160a20eb8bb0186de7e5a7d519

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