This example is actually three examples in one (sorry, crunched for time!):
- A basic CRUD REST API with backing database and minimum viable User Interface built in Angular.
- A suite of Machine Learning models built to teach a computer how to use (Classical, Zero Order) logic (Statistically, through Linear Regression rather than to stipulate Boolean Algebra as such through Imperative programming languages) whilst adding XOR, NAND, and Biconditional. Philosophically this aligns with Putnam's approach.
- Unit Tests are supplied in the Python scripts.
- To expose those Machine Learning models through an API accessible only through Postman since examples about how to do this easily seem lacking.
- Integration Tests are defined in the Postman Collection.
Run the following from the root dir:
docker-compose up
# If using Docker Compose Engine V2:
docker compose upThat should spin up each subservice. Otherwise, you can launch each service individually by:
-
Commenting out everything in
docker-compose.ymlexcept for:services: mysql: image: 'bitnami/mysql:8.0' ports: - '3306:3306' environment: - ALLOW_EMPTY_PASSWORD=yes - MYSQL_USER=example - MYSQL_PASSWORD=example - MYSQL_DATABASE=example - MYSQL_AUTHENTICATION_PLUGIN=mysql_native_password
Then launching the MySQL subservice via
docker-compose up. -
From within
/angularrunnpm i && npm i angular/cli -g, thenng serve -oto spin up the Angular frontend. -
From within
/backendrun:cd ml python3 -m pip install --upgrade pip python3 -m pip install -r requirements.txt python3 ml-conjunction.py python3 ml-disjunction.py python3 ml-implication.py python3 ml-negation.py python3 ml-nand.py python3 ml-xor.py python3 ml-biconditional.py python3 ml-triviality-f.py python3 ml-triviality-t.py python3 ml-nor.pyTo generate the Machine Learning models.
-
Lastly, to start the backend service - from within
/backendrun:cd backend python3 -m pip install --upgrade pip python3 -m pip install -r requirements.txt python3 main.py
Generally speaking, the necessary config, settings, and commands are available within docker-compose.yml, backend dockerfile, frontend dockerfile, angular.json, and main.py, respectively. So, please make recourse to those if you encounter problems.
NOTE:
MYSQL_AUTHENTICATION_PLUGIN=mysql_native_passwordis deprecated in8.4- for now I've pinned the version to8.0which is likely the closest to what I was using in early Spring 2024 - you may need to clean your local images and volumes via something likedocker system prune --volumessince the Bitnami container may throw the following error message otherwise:The designated data directory /bitnami/mysql/data/ is unusable.)
Will be exposed on:
- Docker:
http://localhost:4201 - Standalone:
http://localhost:4200
API endpoints are exposed through Docker or by running each subservice individually.
A test endpoint to verify that requests are getting through and the app is exposed correctly through Docker:
- Docker
http://localhost:5001/api/hello - Standalone
http://localhost:5000/api/hello
Generates Boolean, bivalent, classical, logic results from Deep Learning Linear Regression models (it doesn't use in-built programmatic, native, Boolean clauses or Automated Theorem Proving techniques).
Also, inferences are included that exceed the standard Boolean operations (Material Conditional/Implication, Conjunction, Disjunction, Negation - for example: NAND).
This mirrors research into how one might try to teach a computer logic rather than just stipulate how logic works like we do within programming languages. Read more here.
-
Negation
- "NOT" - Reverses the truth value of the supplied expression.
- Supply sequences of
0,0(False) or1,1(True) - Will reject any invalid pair (e.g. -
1,0,0,1) - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,1at indexiwill map tofalseat indexi.
- Docker:
POST http://localhost:5001/api/logic/negation?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone:
POST http://localhost:5000/api/logic/negation?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 1 ], [ 0, 0 ] ], [ [ false, true, false, true ] ] ] -
Conjunction
- "AND" - Evaluates
Trueonly if both conjuncts areTrue. - Supply sequences of
0,1(left conjunctFalse, right conjunctTrue),1,1(left conjunctTrue, right conjunctTrue),1,0(left conjunctTrue, right conjunctFalse),0,0(left conjunctFalse, right conjunctFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,1at indexiwill map totrueat indexi.
- Docker
POST http://localhost:5001/api/logic/conjunction?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone
POST http://localhost:5000/api/logic/conjunction?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ true, false, false, false, true, false, false, false ] ] ] - "AND" - Evaluates
-
Implication
- "Material Implication" - Evaluates
Falseonly if the antecedant isTrueand the consequentFalse. (Not to be confused with the imperative conditional - e.g.if { ... }in most programming languages.) - Supply sequences of
0,1(antecedantFalse, consequentTrue),1,1(antecedantTrue, consequentTrue),1,0(antecedantTrue, consequentFalse),0,0(antecedantFalse, consequentFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map tofalseat indexi.
- Docker
POST http://localhost:5001/api/logic/implication?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone
POST http://localhost:5000/api/logic/implication?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ true, true, false, true, true, true, false, true ] ] ] - "Material Implication" - Evaluates
-
Disjunction
- "OR" - Evaluates
Trueif either disjunct isTrue(or both). - Supply sequences of
0,1(left disjunctFalse, right disjunctTrue),1,1(left disjunctTrue, right disjunctTrue),1,0(left disjunctTrue, right disjunctFalse),0,0(left disjunctFalse, right disjunctFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map totrueat indexi.
- Docker
POST http://localhost:5001/api/logic/disjunction?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone
POST http://localhost:5000/api/logic/disjunction?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ true, false, true, true, true, false, true, true ] ] ] - "OR" - Evaluates
-
NAND
- "NOT-AND" - Evaluates
Trueonly if the expression isn't aTrueConjunction. - Supply sequences of
0,1(left conjunctFalse, right conjunctTrue),1,1(left conjunctTrue, right conjunctTrue),1,0(left conjunctTrue, right conjunctFalse),0,0(left conjunctFalse, right conjunctFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map totrueat indexi.
- Docker
POST http://localhost:5001/api/logic/nand?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone
POST http://localhost:5000/api/logic/nand?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ false, true, true, true, false, true, true, true ] ] ] - "NOT-AND" - Evaluates
-
XOR
- "Exclusive OR" - Evaluates
Trueonly if neither disjunct is the same. (EvaluatesTrueif either disjunct isTruebut not both.) - Supply sequences of
0,1(left disjunctFalse, right disjunctTrue),1,1(left disjunctTrue, right disjunctTrue),1,0(left disjunctTrue, right disjunctFalse),0,0(left disjunctFalse, right disjunctFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map totrueat indexi.
- Docker
POST http://localhost:5001/api/logic/xor?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1|0,0|1,0|1,0|0,1 - Standalone
POST http://localhost:5000/api/logic/xor?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1|0,0|1,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 0, 0 ], [ 1, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ false, false, true, true, false, false, true, true, false, true, true, true ] ] ] - "Exclusive OR" - Evaluates
-
Biconditional
- "Two Directional Material Conditionals" ("Necessary and Sufficient") - Evaluates
Trueif both sides are the same. - Supply sequences of
0,1(left sideFalse, right sideTrue),1,1(left sideTrue, right sideTrue),1,0(left sideTrue, right sideFalse),0,0(left sideFalse, right sideFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map tofalseat indexi.
- Docker
POST http://localhost:5001/api/logic/biconditional?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1|0,0|1,0|1,0|0,1|0,0|1,1 - Standalone
POST http://localhost:5000/api/logic/biconditional?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1|0,0|1,0|1,0|0,1|0,0|1,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 0, 0 ], [ 1, 0 ], [ 1, 0 ], [ 0, 1 ], [ 0, 0 ], [ 1, 1 ] ], [ [ true, true, false, false, true, true, false, false, true, false, false, false, true, true ] ] ] - "Two Directional Material Conditionals" ("Necessary and Sufficient") - Evaluates
-
Triviality-T
- "Triviality-T" - Evaluates
Trueregardless. (Consequence of the Principle of Explosion or ex contradictione sequitur quodlibet or Triviality - a logic that collapses into Triviality is insufficient for reasoning. Also, here to better fill out the Hasse Diagram and Lattice.) - Supply sequences of
0,1(left argumentFalse, right argumentTrue),1,1(left argumentTrue, right argumentTrue),1,0(left argumentTrue, right argumentFalse),0,0(left argumentFalse, right argumentFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map totrueat indexi.
- Docker
POST http://localhost:5001/api/logic/trivialityt?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone
POST http://localhost:5001/api/logic/trivialityt?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ true, true, true, true, true, true, true, true ] ] ] - "Triviality-T" - Evaluates
-
Triviality-F
- "Triviality-F" - Evaluates
Falseregardless. (Consequence of the Principle of Explosion or ex contradictione sequitur quodlibet or Triviality - a logic that collapses into Triviality is insufficient for reasoning. Also, here to better fill out the Hasse Diagram and Lattice.) - Supply sequences of
0,1(left argumentFalse, right argumentTrue),1,1(left argumentTrue, right argumentTrue),1,0(left argumentTrue, right argumentFalse),0,0(left argumentFalse, right argumentFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map tofalseat indexi.
- Docker
POST http://localhost:5001/api/logic/trivialityt?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone
POST http://localhost:5001/api/logic/trivialityt?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ false, false, false, false, false, false, false, false ] ] ] - "Triviality-F" - Evaluates
-
NOR
- "Neither Nor" - Evaluates
Trueonly if neither disjunct isTrue. - Supply sequences of
0,1(left disjunctFalse, right disjunctTrue),1,1(left disjunctTrue, right disjunctTrue),1,0(left disjunctTrue, right disjunctFalse),0,0(left disjunctFalse, right disjunctFalse). - Each result will contain two parts with each entry in the first mapped to the result in the second by same index:
1,0at indexiwill map tofalseat indexi.
- Docker
POST http://localhost:5001/api/logic/nor?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1 - Standalone
POST http://localhost:5001/api/logic/nor?test=1,1|0,0|1,0|0,1|1,1|0,0|1,0|0,1
Response:
[ [ [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ], [ [ false, true, false, false, false, true, false, false ] ] ] - "Neither Nor" - Evaluates
Supports RESTful CRUD (CREATE, READ, UPDATE, DELETE) operations against a backing MySQL DB.
Check out the Example SQL Domain entry.
-
Scan
- Retrieve all prepopulated entries from the MySQL DB.
- Docker
GET http://localhost:5001/api/db/examples - Standalone
GET http://localhost:5000/api/db/examples
Response:
["{ id: 1, name: 'example_a' }","{ id: 2, name: 'example_b' }","{ id: 3, name: 'example_c' }","{ id: 4, name: 'example_d' }"]
-
Get One
- Retrieve one Example by ID.
- Docker
GET http://localhost:5001/api/db/example/1 - Standalone
GET http://localhost:5000/api/db/example/1
Response:
["{ id: 1, name: 'example_a' }"] -
Create Example
- Create an Example with
form-data. - Docker
POST http://localhost:5001/api/db/example - Standalone
POST http://localhost:5000/api/db/example
Request Body
form-data:name createdResponse:
[ "{ id: 5, name: 'created' }" ] - Create an Example with
-
Update Example
- Update an Example by ID
- Docker
PUT http://localhost:5001/api/db/example/1 - Standalone
PUT http://localhost:5000/api/db/example/1
- Docker
Request Body
form-data:name updatedResponse:
[ "{ id: 1, name: 'updated' }" ] - Update an Example by ID
-
Delete Example
- Delete an Example by ID
- Docker
DELETE http://localhost:5001/api/db/example/1 - Standalone
DELETE http://localhost:5000/api/db/example/1
- Docker
Request Body
form-data:name updatedResponse:
[ "{ id: 1, name: 'updated' }" ] - Delete an Example by ID