satre 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9284e24b8881153af1c176da6c00ad1d941e9865
4
+ data.tar.gz: c7b867612d502482258b27a8c3394ed4a3108021
5
+ SHA512:
6
+ metadata.gz: 52e4914ee2c6494410df25eb227410a1c6937721b9294968c7fe9ef61f55ba7c1fd8922c4e6b96414357b26033d7a70be0e74046ad003b3018ac5d8fece54c0a
7
+ data.tar.gz: baa4ae312af5b6eb16d81887d02f823111097388236f0c566583aa57a4a15b7738294852b7cefae4b6241a45cfb4500442dfb7db3ffcbf52d149dd488f75cdb8
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,110 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ satre (0.1.0)
5
+ terminal-table
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.1.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
13
+ coderay (1.1.0)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.5)
16
+ ffi (1.9.10)
17
+ formatador (0.2.5)
18
+ guard (2.13.0)
19
+ formatador (>= 0.2.4)
20
+ listen (>= 2.7, <= 4.0)
21
+ lumberjack (~> 1.0)
22
+ nenv (~> 0.1)
23
+ notiffany (~> 0.0)
24
+ pry (>= 0.9.12)
25
+ shellany (~> 0.0)
26
+ thor (>= 0.18.1)
27
+ guard-bundler (2.1.0)
28
+ bundler (~> 1.0)
29
+ guard (~> 2.2)
30
+ guard-compat (~> 1.1)
31
+ guard-compat (1.2.1)
32
+ guard-minitest (2.4.4)
33
+ guard-compat (~> 1.2)
34
+ minitest (>= 3.0)
35
+ guard-rubocop (1.2.0)
36
+ guard (~> 2.0)
37
+ rubocop (~> 0.20)
38
+ json (1.8.3)
39
+ listen (3.0.5)
40
+ rb-fsevent (>= 0.9.3)
41
+ rb-inotify (>= 0.9)
42
+ lumberjack (1.0.9)
43
+ method_source (0.8.2)
44
+ minitest (5.8.3)
45
+ nenv (0.2.0)
46
+ notiffany (0.0.8)
47
+ nenv (~> 0.1)
48
+ shellany (~> 0.0)
49
+ parser (2.2.3.0)
50
+ ast (>= 1.1, < 3.0)
51
+ powerpack (0.1.1)
52
+ pry (0.10.3)
53
+ coderay (~> 1.1.0)
54
+ method_source (~> 0.8.1)
55
+ slop (~> 3.4)
56
+ rainbow (2.0.0)
57
+ rake (10.4.2)
58
+ rb-fsevent (0.9.6)
59
+ rb-inotify (0.9.5)
60
+ ffi (>= 0.5.0)
61
+ rspec (3.4.0)
62
+ rspec-core (~> 3.4.0)
63
+ rspec-expectations (~> 3.4.0)
64
+ rspec-mocks (~> 3.4.0)
65
+ rspec-core (3.4.0)
66
+ rspec-support (~> 3.4.0)
67
+ rspec-expectations (3.4.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.4.0)
70
+ rspec-mocks (3.4.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.4.0)
73
+ rspec-support (3.4.0)
74
+ rubocop (0.35.1)
75
+ astrolabe (~> 1.3)
76
+ parser (>= 2.2.3.0, < 3.0)
77
+ powerpack (~> 0.1)
78
+ rainbow (>= 1.99.1, < 3.0)
79
+ ruby-progressbar (~> 1.7)
80
+ tins (<= 1.6.0)
81
+ ruby-progressbar (1.7.5)
82
+ shellany (0.0.1)
83
+ simplecov (0.11.1)
84
+ docile (~> 1.1.0)
85
+ json (~> 1.8)
86
+ simplecov-html (~> 0.10.0)
87
+ simplecov-html (0.10.0)
88
+ slop (3.6.0)
89
+ terminal-table (1.5.2)
90
+ thor (0.19.1)
91
+ tins (1.6.0)
92
+
93
+ PLATFORMS
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ bundler (~> 1.10)
98
+ guard-bundler
99
+ guard-minitest
100
+ guard-rubocop
101
+ minitest
102
+ pry
103
+ rake (~> 10.0)
104
+ rspec
105
+ rubocop
106
+ satre!
107
+ simplecov
108
+
109
+ BUNDLED WITH
110
+ 1.10.6
@@ -0,0 +1,42 @@
1
+ guard :rubocop do
2
+ watch(%r{.+\.rb$})
3
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
4
+ end
5
+
6
+ guard :bundler do
7
+ require 'guard/bundler'
8
+ require 'guard/bundler/verify'
9
+ helper = Guard::Bundler::Verify.new
10
+
11
+ files = ['Gemfile']
12
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
13
+
14
+ # Assume files are symlinked from somewhere
15
+ files.each { |file| watch(helper.real_path(file)) }
16
+ end
17
+
18
+ guard :minitest do
19
+ # with Minitest::Unit
20
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
21
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
22
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
23
+
24
+ # with Minitest::Spec
25
+ # watch(%r{^spec/(.*)_spec\.rb$})
26
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
27
+ # watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
28
+
29
+ # Rails 4
30
+ # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
31
+ # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
32
+ # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
33
+ # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
34
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
35
+ # watch(%r{^test/.+_test\.rb$})
36
+ # watch(%r{^test/test_helper\.rb$}) { 'test' }
37
+
38
+ # Rails < 4
39
+ # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
40
+ # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
41
+ # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
42
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Roman C. Podolski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,82 @@
1
+ # Satre
2
+
3
+ Congito ergo sum - I think therefore I am.
4
+
5
+ [![Build Status](https://travis-ci.org/RomanCPodolski/satre.svg)](https://travis-ci.org/RomanCPodolski/satre)
6
+ [![Code Climate](https://codeclimate.com/github/RomanCPodolski/satre/badges/gpa.svg)](https://codeclimate.com/github/RomanCPodolski/satre)
7
+ [![Test Coverage](https://codeclimate.com/github/RomanCPodolski/satre/badges/coverage.svg)](https://codeclimate.com/github/RomanCPodolski/satre/coverage)
8
+ [![Issue Count](https://codeclimate.com/github/RomanCPodolski/satre/badges/issue_count.svg)](https://codeclimate.com/github/RomanCPodolski/satre)
9
+
10
+ Satre is a library for proportional and first order logic problem solving in ruby.
11
+ It was inspired by the book ['Handbook of practical logic and automated reasoning' by Harrison, J (2009)](http://www.cambridge.org/us/academic/subjects/computer-science/programming-languages-and-applied-logic/handbook-practical-logic-and-automated-reasoning).
12
+
13
+ This project originated at the [Technical University Munich](http://www.tum.de) as a students project in the lecture ['Basics of Artificial Intelligence'](http://www6.in.tum.de/Main/TeachingWs2014KuenstlicheIntelligenz).
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'satre'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install satre
30
+
31
+ ## Usage
32
+
33
+ For examples look at the file `bin/exercise`.
34
+ The see the results of the exercise run `./bin/exercise` from the root directory of this project.
35
+
36
+ To embed proportional logic solving in your project one can use `String#to_formula`, on a well formed proportional logic string.
37
+ Possible operations are
38
+
39
+ * True value `"True"`
40
+ * False value `"False"`
41
+ * Atomic logical variable `"A"` (or any other alphanumeric combination)
42
+ * logical negation `"~A"`
43
+ * logical and `"A /\\ B"`
44
+ * logical or `"A \\/ B"`
45
+ * Implies `"A <=> B"`
46
+ * If and only if `"A => B"`
47
+ * Entails `"A |= B"`
48
+
49
+ An example
50
+
51
+ ```ruby
52
+ formula = '(Fire => Smoke) /\\ Fire /\\ ~Smoke'.to_formula
53
+ ```
54
+
55
+ To evaluate a formula use `Satre::Formula#eval`
56
+
57
+ ```ruby
58
+ formula = '(Fire => Smoke) /\\ Fire /\\ ~Smoke'.to_formula
59
+ formula.eval 'Fire' => true, 'Smoke' => true
60
+ ```
61
+
62
+ Further are provided `Satre::Formula#tauntolgy?`,`Satre::Formula#satisfiable?`,`Satre::Formula#unsatisfiable?`
63
+
64
+ For further information see the doc.
65
+
66
+ ## Development
67
+
68
+ After checking out the repo, run `bin/setup` to install dependencies.
69
+ Then, run `rake` to run the tests.
70
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ To install this gem onto your local machine, run `bundle exec rake install`.
73
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/RomanCPodolski/satre.
78
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ Rake::RDocTask.new do |rd|
12
+ rd.main = 'README.md'
13
+ rd.rdoc_files.include("README.md", "lib/**/*.rb")
14
+ rd.options << "--all"
15
+ end
16
+
17
+ task default: [ :test, :rdoc ]
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'satre'
5
+
6
+ include Satre
7
+
8
+ require 'pry'
9
+ Pry.start
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'satre'
5
+ require 'terminal-table'
6
+
7
+ include Satre
8
+
9
+ problem_4_1_1 = 'False |= True'.to_formula
10
+ problem_4_1_2 = 'True |= False'.to_formula
11
+ problem_4_1_3 = '(A /\\ B) |= (A <=> B)'.to_formula
12
+ problem_4_1_4 = '(A <=> B) |= A \\/ B'.to_formula
13
+ problem_4_1_5 = '(A <=> B) |= ~A \\/ B'.to_formula
14
+
15
+ problem_4_2_1 = 'Smoke => Smoke'.to_formula
16
+ problem_4_2_2 = '(Smoke => Fire) => (~Smoke => ~Fire)'.to_formula
17
+ problem_4_2_3 = 'Smoke \\/ Fire \\/ ~Fire'.to_formula
18
+ problem_4_2_4 = '(Fire => Smoke) /\\ Fire /\\ ~Smoke'.to_formula
19
+
20
+ bsays = 'b <=> (a <=> ~a)'.to_formula
21
+ csays = 'c <=> ~b'.to_formula
22
+
23
+ kb = And.new(bsays, csays)
24
+
25
+ a_is_knight = Entails.new(kb,'a'.to_formula)
26
+ a_is_knave = Entails.new(kb,'~a'.to_formula)
27
+ b_is_knight = Entails.new(kb,'b'.to_formula)
28
+ b_is_knave = Entails.new(kb,'~b'.to_formula)
29
+ c_is_knight = Entails.new(kb,'c'.to_formula)
30
+ c_is_knave = Entails.new(kb,'~c'.to_formula)
31
+
32
+ problem_4_1 = Terminal::Table.new do |t|
33
+ t.title = 'Problem 4.1'
34
+ t.headings = ['', 'Formula', 'Result' ]
35
+ t << ['1.', problem_4_1_1, problem_4_1_1.eval ]
36
+ t << ['2.', problem_4_1_2, problem_4_1_2.eval ]
37
+ t << ['3.', problem_4_1_3, problem_4_1_3.eval ]
38
+ t << ['4.', problem_4_1_4, problem_4_1_4.eval ]
39
+ t << ['5.', problem_4_1_5, problem_4_1_5.eval ]
40
+ end
41
+
42
+
43
+ problem_4_2 = Terminal::Table.new do |t|
44
+ t.title = 'Problem 4.2'
45
+ t.headings = ['', 'Formula', 'tauntolgy?', 'satifiable?', 'unsatifiable?']
46
+ t << ['1.', problem_4_2_1, problem_4_2_1.tautology?, problem_4_2_1.satifiable?, problem_4_2_1.unsatifiable? ]
47
+ t << ['2.', problem_4_2_2, problem_4_2_2.tautology?, problem_4_2_2.satifiable?, problem_4_2_2.unsatifiable? ]
48
+ t << ['3.', problem_4_2_3, problem_4_2_3.tautology?, problem_4_2_3.satifiable?, problem_4_2_3.unsatifiable? ]
49
+ t << ['4.', problem_4_2_4, problem_4_2_4.tautology?, problem_4_2_4.satifiable?, problem_4_2_4.unsatifiable? ]
50
+ end
51
+
52
+ problem_4_3 = Terminal::Table.new do |t|
53
+ t.title = 'Problem 4.2'
54
+ t.headings = ['', 'a', 'b', 'c']
55
+ t << ['is knight?', a_is_knight.eval , b_is_knight.eval , c_is_knight.eval ]
56
+ t << ['is knave?', a_is_knave.eval , b_is_knave.eval , c_is_knave.eval ]
57
+ end
58
+
59
+
60
+ puts problem_4_1
61
+ puts """I used a similar approach in my pencil-and-paper derivations
62
+ first subtitude the entails a |= b with a /\\ ~b and then check this statement
63
+ on unsatisfiability.
64
+ """
65
+
66
+ puts problem_4_2
67
+ puts problem_4_3
68
+
69
+ puts """This approach uses the entails functions to solve the puzzle,
70
+ while in the exercise we substituded with the rules until clear statements were made."""
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'satre/version'
2
+ require 'satre/expression'
3
+ require 'satre/lexer'
4
+ require 'satre/formula'
5
+ require 'satre/parser'
6
+ require 'satre/formula_parser'