Class: HenselCode::GAdicBase

Inherits:
Object
  • Object
show all
Includes:
GAdicVerifier, Tools
Defined in:
lib/hensel_code/gadic_base.rb

Overview

base hensel code class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GAdicVerifier

#different_primes_and_different_exponent?, #different_primes_and_same_exponent?, #incompatible_operand_type?, #same_primes_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(primes, exponent, number) ⇒ GAdicBase

Returns a new instance of GAdicBase.



12
13
14
15
16
17
18
19
20
21
# File 'lib/hensel_code/gadic_base.rb', line 12

def initialize(primes, exponent, number)
  can_initilize?
  @primes = primes
  @exponent = exponent
  @g = primes.inject(:*)
  @n = Integer.sqrt(((g**exponent) - 1) / 2)
  valid_number?(number)
  encode
  decode
end

Instance Attribute Details

#exponentObject

Returns the value of attribute exponent.



9
10
11
# File 'lib/hensel_code/gadic_base.rb', line 9

def exponent
  @exponent
end

#gObject

Returns the value of attribute g.



9
10
11
# File 'lib/hensel_code/gadic_base.rb', line 9

def g
  @g
end

#hensel_codeObject

Returns the value of attribute hensel_code.



9
10
11
# File 'lib/hensel_code/gadic_base.rb', line 9

def hensel_code
  @hensel_code
end

#nObject

Returns the value of attribute n.



9
10
11
# File 'lib/hensel_code/gadic_base.rb', line 9

def n
  @n
end

#primesObject

Returns the value of attribute primes.



9
10
11
# File 'lib/hensel_code/gadic_base.rb', line 9

def primes
  @primes
end

#rationalObject

Returns the value of attribute rational.



9
10
11
# File 'lib/hensel_code/gadic_base.rb', line 9

def rational
  @rational
end

Instance Method Details

#*(other) ⇒ Object



46
47
48
49
# File 'lib/hensel_code/gadic_base.rb', line 46

def *(other)
  valid?(other)
  evaluate("*", other)
end

#+(other) ⇒ Object



36
37
38
39
# File 'lib/hensel_code/gadic_base.rb', line 36

def +(other)
  valid?(other)
  evaluate("+", other)
end

#-(other) ⇒ Object



41
42
43
44
# File 'lib/hensel_code/gadic_base.rb', line 41

def -(other)
  valid?(other)
  evaluate("-", other)
end

#/(other) ⇒ Object



51
52
53
54
# File 'lib/hensel_code/gadic_base.rb', line 51

def /(other)
  valid?(other)
  evaluate("/", other)
end

#denominatorObject



27
28
29
# File 'lib/hensel_code/gadic_base.rb', line 27

def denominator
  rational.denominator
end

#numeratorObject



23
24
25
# File 'lib/hensel_code/gadic_base.rb', line 23

def numerator
  rational.numerator
end

#replace_exponent(new_exponent) ⇒ Object



60
61
62
# File 'lib/hensel_code/gadic_base.rb', line 60

def replace_exponent(new_exponent)
  replace_attribute("exponent=", new_exponent, 0)
end

#replace_hensel_code(new_hensel_code) ⇒ Object



68
69
70
71
# File 'lib/hensel_code/gadic_base.rb', line 68

def replace_hensel_code(new_hensel_code)
  valid_hensel_code?(new_hensel_code)
  replace_attribute("hensel_code=", new_hensel_code, 1)
end

#replace_primes(new_primes) ⇒ Object



56
57
58
# File 'lib/hensel_code/gadic_base.rb', line 56

def replace_primes(new_primes)
  replace_attribute("primes=", new_primes, 0)
end

#replace_rational(new_rational) ⇒ Object



64
65
66
# File 'lib/hensel_code/gadic_base.rb', line 64

def replace_rational(new_rational)
  replace_attribute("rational=", new_rational, 0)
end

#to_rObject



31
32
33
34
# File 'lib/hensel_code/gadic_base.rb', line 31

def to_r
  decode
  rational
end