Class: Algebra::JordanForm

Inherits:
Object show all
Defined in:
lib/algebra/jordan-form.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ JordanForm

Returns a new instance of JordanForm.



20
21
22
# File 'lib/algebra/jordan-form.rb', line 20

def initialize(body)
  @body = body
end

Class Method Details

.construct(elem_divs, facts, field, pfield) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/algebra/jordan-form.rb', line 59

def self.construct(elem_divs, facts, field, pfield)
  a = []
  elem_divs.each do |e|
    facts.each do |f, n|
      next if f.deg.zero? || n.zero?
      f = f.convert_to(pfield)
      g = e.convert_to(pfield)

      raise 'insufficient decomposition' unless f.deg <= 1
      k = 0
      loop do
        q, r = g.divmod f
        break unless r.zero?
        g = q
        k += 1
      end
      a.push [-f[0], k] if k > 0
    end
  end
  Algebra::JordanForm.new(a).to_matrix(field)
end

.decompose(m) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/algebra/jordan-form.rb', line 81

def self.decompose(m)
  base_ring = m.ground
  base_pring = Algebra.Polynomial(base_ring, 'x')
  base_alg = Algebra.SquareMatrix(base_pring, m.size)

  me = m._char_matrix(base_alg).to_quint.e_diagonalize
  elem_divs = me.body.diag

  facts = Algebra::ElementaryDivisor.factorize(elem_divs)
  dl = facts.last
  field, modulus, facts, roots, elms = dl.pi.decompose(dl)

  pfield = Algebra.Polynomial(field, 'x')
  pfm_alg = Algebra.SquareMatrix(pfield, m.size)

  jm = Algebra::JordanForm.construct(elem_divs, facts, field, pfield)
  jme = jm._char_matrix(pfm_alg).to_quint.e_diagonalize

  mebody = pfm_alg.convert_from(me.body)
  meright = pfm_alg.convert_from(me.right)
  meleft = pfm_alg.convert_from(me.left)

  sR = (meright * jme.righti).i2o.evaluateR(jm)
  tL = (jme.lefti * meleft).i2o.evaluateL(jm)

  [jm, tL, sR, field, modulus]
end

Instance Method Details

#jordan_block_l(ring, x, n) ⇒ Object



55
56
57
# File 'lib/algebra/jordan-form.rb', line 55

def jordan_block_l(ring, x, n)
  jordan_block_u(ring, x, n).transpose
end

#jordan_block_u(ring, x, n) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/algebra/jordan-form.rb', line 42

def jordan_block_u(ring, x, n)
  a = Algebra.SquareMatrix(ring, n)
  a.matrix do |i, j|
    if i == j
      x
    elsif i == j - 1
      ring.unity
    else
      ring.zero
    end
  end
end

#to_matrix(ring = Integer) ⇒ Object Also known as: to_matrix_u



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/algebra/jordan-form.rb', line 24

def to_matrix(ring = Integer)
  mat = nil
  @body.each do |x, n|
    mat = if mat
            mat.dsum(jordan_block_u(ring, x, n))
          else
            jordan_block_u(ring, x, n)
          end
  end
  mat
end

#to_matrix_lObject



38
39
40
# File 'lib/algebra/jordan-form.rb', line 38

def to_matrix_l
  to_matrix_u.transpose
end