rmathemata 0.1
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.
- data/README.rdoc +0 -0
- data/lib/arithmetic.rb +75 -0
- data/lib/rmathemata.rb +1 -0
- metadata +68 -0
data/README.rdoc
ADDED
File without changes
|
data/lib/arithmetic.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/local/bin/ruby -Kuw
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
|
5
|
+
def ∑(values)
|
6
|
+
values.inject(&:+)
|
7
|
+
end
|
8
|
+
|
9
|
+
def √(root)
|
10
|
+
Math.sqrt(root)
|
11
|
+
end
|
12
|
+
|
13
|
+
def ∏(values)
|
14
|
+
values.inject(:*)
|
15
|
+
end
|
16
|
+
|
17
|
+
def ∏x(expression, variable, values)
|
18
|
+
∏ (values.map {|value| eval(expression.gsub(variable, value.to_s))})
|
19
|
+
end
|
20
|
+
|
21
|
+
def ∑x(expression, variable, values)
|
22
|
+
∑ (values.map {|value| eval(expression.gsub(variable, value.to_s))})
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
module PowerfulInteger
|
28
|
+
require 'mathn'
|
29
|
+
|
30
|
+
def gcdn integers
|
31
|
+
return self unless integers.any?
|
32
|
+
self.gcd integers.shift.gcdn(integers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def prime_powers
|
36
|
+
prime_division.map(&:pop)
|
37
|
+
end
|
38
|
+
|
39
|
+
def is_powerful?
|
40
|
+
return true if self == 1
|
41
|
+
prime_powers.min >= 2
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_perfect_power?
|
45
|
+
n = 1
|
46
|
+
loop do
|
47
|
+
n += 1
|
48
|
+
root = self**(1/n)
|
49
|
+
return true if root.is_a?(Integer)
|
50
|
+
return false if root < 2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def is_achilles_number?
|
55
|
+
is_powerful? and not is_perfect_power?
|
56
|
+
end
|
57
|
+
|
58
|
+
def euler_totient
|
59
|
+
return 1 if self == 1
|
60
|
+
self * ∏x("1 - 1/p", "p", prime_division.map(&:first))
|
61
|
+
end
|
62
|
+
|
63
|
+
def is_strong_achilles_number?
|
64
|
+
is_achilles_number? and euler_totient.is_achilles_number?
|
65
|
+
end
|
66
|
+
|
67
|
+
def numbers_of_strong_achilles_numbers_below
|
68
|
+
1.upto(self).inject(0) {|total, number| total += 1 if number.is_strong_achilles_number? ; total}
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class Integer
|
74
|
+
include PowerfulInteger
|
75
|
+
end
|
data/lib/rmathemata.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'arithmetic')
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rmathemata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Philippe Cantin
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-11 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Provide mathematics functions and utilities for Theory of Number. Analysis. Geometry ...
|
22
|
+
email:
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
files:
|
30
|
+
- lib/arithmetic.rb
|
31
|
+
- lib/rmathemata.rb
|
32
|
+
- README.rdoc
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/anoiaque/RMathemata
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.7
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Mathematic Library written in ruby
|
67
|
+
test_files: []
|
68
|
+
|