ruby_maxima 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/ruby_maxima.rb +6 -0
- data/lib/ruby_maxima/session.rb +36 -0
- data/lib/ruby_maxima/version.rb +3 -0
- data/phil.todo +3 -0
- data/ruby_maxima.gemspec +23 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 816c09bfd6e5aa5086aaa09229bff7ab85aec2be
|
4
|
+
data.tar.gz: 511c85fc52c8a59a015c3b432680dbbb4747d1b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10d7bc797912a076fa8731214426cca624683601fd8b263b85916d9651f0870e0806a7b8b7b2ccadb37065fe9aa308605827bd6b1d967b42b199d21d2eafe98a
|
7
|
+
data.tar.gz: ad2c0703aeb2cff2478e78fa41487198d1ef2f407d396813502540708b1dd26f4bae399bd6e4d538d8eda21f7872b8f5660040ce199ec9c72a98143de4bbddb0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# RubyMaxima
|
2
|
+
|
3
|
+
Use Maxima (a computer algebra system) from Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruby_maxima'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruby_maxima
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
RubyMaxima has a single class to work with: the `Session`. It practically translates all methods into Maxima calls, except for:
|
24
|
+
|
25
|
+
* `execute` - This executes all the commands in the session.
|
26
|
+
* `commands` - Here you can have a look at the current commands in the session.
|
27
|
+
* `debug=` - Here you can set the debug mode. When it is set to true, RubyMaxima will print the output from maxima.
|
28
|
+
|
29
|
+
RubyMaxima will automatically translate hashes: `constraints: 'x+y<=100'` becomes `constraints = x+y<=100`.
|
30
|
+
Here is an example:
|
31
|
+
```
|
32
|
+
s = RubyMaxima::Session.new
|
33
|
+
s.load 'fmin_cobyla'
|
34
|
+
s.fmin_cobyla '-(x*y)',['x', 'y'], [1,1], constraints: ['x*y<=49']
|
35
|
+
eval s.execute # handle this line with absolute care!
|
36
|
+
```
|
37
|
+
|
38
|
+
## Todos
|
39
|
+
|
40
|
+
Feel free to open issues for missing features.
|
41
|
+
|
42
|
+
* I did not implement the basic arithmetic operations, since I don't need them.
|
43
|
+
* Implement an `assigns` method on session which takes a variable name and a block and assigns the result of the block to the variable in maxima.
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. 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).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/phikes/ruby_maxima.
|
54
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby_maxima"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/ruby_maxima.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module RubyMaxima
|
2
|
+
class Session
|
3
|
+
attr_reader :commands
|
4
|
+
attr_accessor :debug
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@commands = []
|
8
|
+
@debug = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
result = `maxima -r '#{commands.join ' '}'`
|
13
|
+
puts result if @debug
|
14
|
+
result.scan(
|
15
|
+
/(?<=\(%o#{@commands.count}\)).*(?=\(%i\d*\))/m
|
16
|
+
).first.strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method, *args, &block)
|
20
|
+
translated_args = args.map {|arg| translate_argument arg }
|
21
|
+
|
22
|
+
@commands << "#{method}(#{translated_args.join ','});"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def translate_argument(arg)
|
27
|
+
if arg.kind_of? Hash
|
28
|
+
arg.map {|(key, value)| "#{translate_argument key} = #{translate_argument value}"}.join ','
|
29
|
+
elsif arg.kind_of? Array
|
30
|
+
'[' + arg.map {|element| translate_argument element}.join(',') + ']'
|
31
|
+
else
|
32
|
+
arg
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/phil.todo
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
☐ hashes need to be handled correctly (just replace any argument that is a hash with a RubyMaxima::Hash, that has its inspect method overriden)
|
2
|
+
☐ there need to be "atomic strings", that are translated into a command without quotation marks (use smth like "abc".atomic) to get a RubyMaxima::AtomicString
|
3
|
+
☐ upload this to RubyGems w/ some docs @later
|
data/ruby_maxima.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruby_maxima/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby_maxima"
|
8
|
+
spec.version = RubyMaxima::VERSION
|
9
|
+
spec.authors = ["Phillip Kessels"]
|
10
|
+
spec.email = ["info@phikes.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Use Maxima from Ruby.}
|
13
|
+
spec.homepage = "https://github.com/phikes/ruby_maxima"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_maxima
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phillip Kessels
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- info@phikes.de
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/ruby_maxima.rb
|
71
|
+
- lib/ruby_maxima/session.rb
|
72
|
+
- lib/ruby_maxima/version.rb
|
73
|
+
- phil.todo
|
74
|
+
- ruby_maxima.gemspec
|
75
|
+
homepage: https://github.com/phikes/ruby_maxima
|
76
|
+
licenses: []
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Use Maxima from Ruby.
|
98
|
+
test_files: []
|
99
|
+
has_rdoc:
|