GithubHelp home page GithubHelp logo

nicolas-reyland / aps Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 248 KB

Algebraic Proof System

License: GNU General Public License v3.0

Rust 100.00%
algebra algebraic-structures proof-system rust symbolic-expressions

aps's Introduction

aps

Algebraic Proof System

A system written in rust to generate proofs of algebraic statements, based on algebraic structures.

Installation

Clone and cd into the repo :

git clone https://github.com/Nicolas-Reyland/aps.git
cd aps

Install rust and cargo :

cargo build --release

Usage

To get a repl shell, run :

cargo run --release

Let's say your goal is to generate algebraic proofs in bizarre Algebraic Structures. First of all, you'll need to describe your Structure. In ASPL, you can only work with one structure at a time (yet). Let's write an algebraic structure that has a + operator and @ operator.

// comments are C-like comments

// operator properties are listed in the 'property-group'. The sign
// you put in front of the group is not relevant, but adds clarity about
// which operator is being described.
+ :: {
    // Rules are written like so : left-expression = right-expression ;

    // Let's make + a commutative operator
    A + B = B + A ;
    // Let's add an identity
    A + 0 = A ;
    // Since we have the commutative property of +, we also know that 0 + A = A
}

// Let's add another operator
@ :: {
    A @ 1 = A ;
    A @ A = 0 ;
}

// We can add properties using both operators (we'll use _ as a prefix,
// but as said previously, it doesn't matter what we put there)
_ :: {
    A @ (B + C) = (A @ B) + (A @ C) ;
}

All that should be written to a file, for example unusable.apsl. Such apsl files can be imported by adding them to the cargo run command like so : cargo run file1.apsl file2.apsl ....

Once inside the repl-shell, you can ask for a proof of X @ ((Z @ Z) + Y) @ 1 = Y @ X like so :

Algebraic Proof System Language 〉prove X @ ((Z @ Z) + Y) = X @ Y

I'll let you see what it outputs :) (there are examples of outputs in the examples section)

Please type help to get some more infos about the available commands.

Examples

Basics

Let's write a file with the following rules/axioms, defining an algebraic structure with one operation + :

+ :: {
  A + B = B + A ;
  (A + B) + C = A + (B + C) ;
}

Let's call that file plus.apsl.

Now, let's start a repl (cargo run plus.apsl). You can also just run cargo run, then use the import command as such: import plus.apsl (pay attention to the current working directory). To check that the rules are well loaded, type ctx. This should give you the following output :

 Properties :
 | A + B = B + A
 | (A + B) + C = A + (B + C)

Now that the rules defining our + operation are loaded, you can ask for a prove of A + B + C = C + B + A with the following command : prove A + B + C = C + B + A. That should give you the following result :

 Solution found for 'X + Y + Z = Z + Y + X' :
  (X + Y) + Z
 = Z + (X + Y)		|	A + B = B + A
 = Z + (Y + X)		|	A + B = B + A
 = Z + Y + X		|	(A + B) + C = A + (B + C)

A bit trickier case

Now that we've proven that A + B + C = C + B + A (wow 😲), let's prove that (X + Y)^2 = (X^2) + (2*X*Y) + (Y^2) ! (I bet you didn't know that was a thing in maths, ey ? 😏)

Note that in these expressions, we have to use parentheses, because no order has been established between the +and *operations (none will be established in this example). To prove this, we'll need our custom rules defining our + and * operations, which are in the examples/numbers.apsl.

We can start a repl with cargo run examples/numbers.apsl, and make sure we have all the rule we need :

If you don't want to start a new shell, you can do the following :

Algebraic Proof System Language 〉ctx clear
 Cleared context

Algebraic Proof System Language 〉ctx
 No Properties

Algebraic Proof System Language 〉import examples/numbers.apsl
 imported 'examples/numbers.apsl'

Let's check the current context.

Algebraic Proof System Language 〉ctx
 Properties :
 | A + B = B + A
 | (A + B) + C = A + (B + C)
 | A + 0 = A
 | A * B = B * A
 | (A * B) * C = A * (B * C)
 | A * 1 = A
 | A * 0 = 0
 | A ^ 0 = 1
 | A ^ 1 = A
 | A * (B + C) = (A * B) + (A * C)
 | A * 2 = A + A
 | A ^ 2 = A * A

 K Properties :
 | K :: R1

 Auto break : true
 
Algebraic Proof System Language 〉

Finally, let's ask it to prove the equality :

Algebraic Proof System Language 〉prove (X + Y)^2 = (X*X) + (2 * (X * Y)) + (Y*Y)

Which gives us a proof, using the rules we have defined :

 Solution found for '(X + Y) ^ 2 = (X ^ 2) + (2 * X * Y) + (Y ^ 2)' :
  (X + Y) ^ 2
 = (X + Y) * (X + Y)					|	A ^ 2 = A * A
 = ((X + Y) * X) + ((X + Y) * Y)			|	A * (B + C) = (A * B) + (A * C)
 = (X * (X + Y)) + ((X + Y) * Y)			|	A * B = B * A
 = (X * X) + (X * Y) + ((X + Y) * Y)			|	A * (B + C) = (A * B) + (A * C)
 = (X * X) + (X * Y) + (Y * (X + Y))			|	A * B = B * A
 = (X * X) + (X * Y) + ((Y * X) + (Y * Y))		|	A * (B + C) = (A * B) + (A * C)
 = (X * X) + (X * Y) + ((X * Y) + (Y * Y))		|	A * B = B * A
 = (X * X) + (X * Y) + ((X * Y) + (Y ^ 2))		|	A ^ 2 = A * A
 = (X * X) + (X * Y) + (X * Y) + (Y ^ 2)		|	(A + B) + C = A + (B + C)
 = (X ^ 2) + (X * Y) + (X * Y) + (Y ^ 2)		|	A ^ 2 = A * A
 = (X ^ 2) + ((X * Y) + (X * Y)) + (Y ^ 2)		|	(A + B) + C = A + (B + C)
 = (X ^ 2) + (X * Y * 2) + (Y ^ 2)			|	A * 2 = A + A
 = (X ^ 2) + (2 * (X * Y)) + (Y ^ 2)			|	A * B = B * A
 = (X ^ 2) + (2 * X * Y) + (Y ^ 2)			|	(A * B) * C = A * (B * C)

You may notice that some parentheses are missing for the rule on the right to be applied. This is because the expressions on the left are pretty-printed. To disable this behaviour, you should execute :

Algebraic Proof System Language 〉settings expr-pretty-print off

aps's People

Contributors

nicolas-reyland avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.