Module: Polymath
- Defined in:
- lib/polymath.rb,
lib/polymath/math/math.rb,
lib/polymath/nomial/parser.rb,
lib/polymath/nomial/monomial.rb,
lib/polymath/nomial/polynomial.rb
Defined Under Namespace
Class Method Summary collapse
-
.command_line(options) ⇒ Object
Nil.
-
.parse_options(args) ⇒ Object
A hash of parsed options.
- .polynomial(exp) ⇒ Object
Class Method Details
.command_line(options) ⇒ Object
Returns nil.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/polymath.rb', line 76 def self.command_line() raise "No polynomial given" unless [:polynomial] polynomial = Polymath.polynomial([:polynomial]) math = Polymath::Math.new polynomial.cleanup! if [:factor] zeroes = math.factor_rational_zeroes(polynomial: polynomial) end #output puts .map { |opt, value| next unless value case opt when :verbose polynomial.to_s when :factor "zeroes: #{zeroes}" if [:factor] when :analyze { deg: polynomial.deg, class: polynomial.classification.map { |t, c| c }.compact.join(" ") }.map { |a,b| "#{a}: #{b}" }.join("\n") end }.compact.join("\n") end |
.parse_options(args) ⇒ Object
Returns a hash of parsed options.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/polymath.rb', line 17 def self.(args) = { :polynomial => nil, :verbose => true, :analyze => false, :factor => false } parser = OptionParser.new { |opts| opts. = "Usage: polymath [options] <polynomial>" opts.on("-f", "--factor", "factor the polynomial expression") { |f| [:factor] = f } opts.on("-a", "--analyze", "analyze the polynomial expression") { |a| [:analyze] = a } opts.on("-q", "--quiet", "only output what is specified") { |q| [:verbose] = ! q } opts.on("-r", "--random [N]", "generate a random polynomial") { |n| [:polynomial] = if n Nomial::random_polynomial(Integer(n)) else Nomial::random_polynomial end } opts.on_tail("-h", "--help", "Show this message") { puts opts exit } opts.on_tail("--version", "Show version") { puts self::Version.join('.') exit } } parser.parse!(args) [:polynomial] = args.pop unless [:polynomial] end |
.polynomial(exp) ⇒ Object
65 66 67 |
# File 'lib/polymath.rb', line 65 def self.polynomial(exp) Polymath::Nomial::Polynomial.new(exp) end |