Class: HenselCode::PAdicBase
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
#different_prime_and_different_exponent?, #different_prime_and_same_exponent?, #incompatible_operand_type?, #same_prime_and_different_exponent?, #valid?
Methods included from Tools
#crt, #eea_core, #extended_gcd, #mod_inverse, #random_distinct_numbers, #random_integer, #random_prime, #random_rational
Constructor Details
#initialize(prime, exponent, number) ⇒ PAdicBase
Returns a new instance of PAdicBase.
12
13
14
15
16
17
18
19
20
|
# File 'lib/hensel_code/padic_base.rb', line 12
def initialize(prime, exponent, number)
can_initilize?
@prime = prime
@exponent = exponent
@n = Integer.sqrt(((prime**exponent) - 1) / 2)
valid_number?(number)
encode
decode
end
|
Instance Attribute Details
#exponent ⇒ Object
Returns the value of attribute exponent.
9
10
11
|
# File 'lib/hensel_code/padic_base.rb', line 9
def exponent
@exponent
end
|
#hensel_code ⇒ Object
Returns the value of attribute hensel_code.
9
10
11
|
# File 'lib/hensel_code/padic_base.rb', line 9
def hensel_code
@hensel_code
end
|
#n ⇒ Object
Returns the value of attribute n.
9
10
11
|
# File 'lib/hensel_code/padic_base.rb', line 9
def n
@n
end
|
#prime ⇒ Object
Returns the value of attribute prime.
9
10
11
|
# File 'lib/hensel_code/padic_base.rb', line 9
def prime
@prime
end
|
#rational ⇒ Object
Returns the value of attribute rational.
9
10
11
|
# File 'lib/hensel_code/padic_base.rb', line 9
def rational
@rational
end
|
Instance Method Details
#*(other) ⇒ Object
45
46
47
48
|
# File 'lib/hensel_code/padic_base.rb', line 45
def *(other)
valid?(other)
evaluate("*", other)
end
|
#+(other) ⇒ Object
35
36
37
38
|
# File 'lib/hensel_code/padic_base.rb', line 35
def +(other)
valid?(other)
evaluate("+", other)
end
|
#-(other) ⇒ Object
40
41
42
43
|
# File 'lib/hensel_code/padic_base.rb', line 40
def -(other)
valid?(other)
evaluate("-", other)
end
|
#/(other) ⇒ Object
50
51
52
53
|
# File 'lib/hensel_code/padic_base.rb', line 50
def /(other)
valid?(other)
evaluate("/", other)
end
|
#denominator ⇒ Object
26
27
28
|
# File 'lib/hensel_code/padic_base.rb', line 26
def denominator
rational.denominator
end
|
#numerator ⇒ Object
22
23
24
|
# File 'lib/hensel_code/padic_base.rb', line 22
def numerator
rational.numerator
end
|
#replace_exponent(new_exponent) ⇒ Object
59
60
61
|
# File 'lib/hensel_code/padic_base.rb', line 59
def replace_exponent(new_exponent)
replace_attribute("exponent=", new_exponent, 0)
end
|
#replace_hensel_code(new_hensel_code) ⇒ Object
67
68
69
70
|
# File 'lib/hensel_code/padic_base.rb', line 67
def replace_hensel_code(new_hensel_code)
valid_hensel_code?(new_hensel_code)
replace_attribute("hensel_code=", new_hensel_code, 1)
end
|
#replace_prime(new_prime) ⇒ Object
55
56
57
|
# File 'lib/hensel_code/padic_base.rb', line 55
def replace_prime(new_prime)
replace_attribute("prime=", new_prime, 0)
end
|
#replace_rational(new_rational) ⇒ Object
63
64
65
|
# File 'lib/hensel_code/padic_base.rb', line 63
def replace_rational(new_rational)
replace_attribute("rational=", new_rational, 0)
end
|
#to_r ⇒ Object
30
31
32
33
|
# File 'lib/hensel_code/padic_base.rb', line 30
def to_r
decode
rational
end
|