M500 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/m500.rb +761 -102
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac4623172c8c3593148e5d41021c7e6af22b5cde
|
4
|
+
data.tar.gz: 81508c65134aac2effd6d6c26c7d16254dc53cf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0903c099d74d1148920d289fc9710e061f05200546e74b1b680bbff5c477f978e2f2dea898848b14a1c6add45469bf747f838edfa7960615ef2483a75ef69c73'
|
7
|
+
data.tar.gz: 7e3912857a7f424725749fe6bcb1ad14df71334e53f537e6e65a58321dba1f3488d4794a7dde99ecf8d155a3235350cfab6bfd2ee65caf6c28c0327e17bb3684
|
data/lib/m500.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# M500.rb -
|
3
3
|
# $Release Version: 0.9 $
|
4
|
-
# $Revision: 1.
|
4
|
+
# $Revision: 1.47 $
|
5
5
|
# by mark ingram
|
6
6
|
#
|
7
7
|
# --
|
@@ -36,6 +36,20 @@ class Array
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
class String
|
39
|
+
def is_Q?
|
40
|
+
t = true
|
41
|
+
re = /(\d+)\/(\d+)/
|
42
|
+
md = re.match(self)
|
43
|
+
if md.nil? then
|
44
|
+
t = is_Z?
|
45
|
+
else
|
46
|
+
t = false if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil?
|
47
|
+
end
|
48
|
+
t
|
49
|
+
end
|
50
|
+
def is_r?
|
51
|
+
Rational(self).kind_of?(Rational)
|
52
|
+
end
|
39
53
|
def is_f?
|
40
54
|
t = true
|
41
55
|
re = /(\-*\d+).(\d+)e([-|+])(\d+)/
|
@@ -43,25 +57,56 @@ class String
|
|
43
57
|
t = false if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil?
|
44
58
|
t
|
45
59
|
end
|
46
|
-
def
|
60
|
+
def is_N?
|
61
|
+
re = /(^[0-9]+)$/
|
62
|
+
md = re.match(self.to_s)
|
63
|
+
t = emptySet
|
64
|
+
t = md[1].to_i.to_N unless md.nil?
|
65
|
+
end
|
66
|
+
def is_N0?
|
67
|
+
re = /(^[0-9]+)$/
|
68
|
+
md = re.match(self.to_s)
|
69
|
+
t = emptySet
|
70
|
+
t = md[1].to_i.to_N unless md.nil?
|
71
|
+
end
|
72
|
+
def is_Z?
|
73
|
+
re = /(^-?[0-9]+)$/
|
74
|
+
md = re.match(self.to_s)
|
75
|
+
t = emptySet
|
76
|
+
t = Zahlen(md[1].to_i) unless md.nil?
|
77
|
+
end
|
78
|
+
def is_Q?
|
47
79
|
t = true
|
48
|
-
re = /(
|
80
|
+
re = /(^-?[0-9]+)\/([0-9]+)/
|
49
81
|
md = re.match(self)
|
50
|
-
|
82
|
+
if md.nil?
|
83
|
+
t = false
|
84
|
+
else
|
85
|
+
t = false if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil?
|
86
|
+
end
|
51
87
|
t
|
52
88
|
end
|
53
|
-
|
89
|
+
def is_Frac?
|
54
90
|
t = true
|
55
|
-
re = /(
|
91
|
+
re = /(^-?[0-9]+) ([0-9]+)\/([0-9]+)/
|
56
92
|
md = re.match(self)
|
57
|
-
|
93
|
+
if md.nil?
|
94
|
+
t = false
|
95
|
+
else
|
96
|
+
t = false if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil?
|
97
|
+
end
|
58
98
|
t
|
59
99
|
end
|
60
100
|
def is_Dec?
|
61
101
|
t = true
|
62
|
-
re = /(
|
63
|
-
|
64
|
-
|
102
|
+
re = /(^-?[0-9]+)\\#{Decimal::decimalSeparator}([0-9]+)/
|
103
|
+
re = /(^-?[0-9]+)\.([0-9]+)/
|
104
|
+
md = re.match(self.to_s)
|
105
|
+
if md.nil?
|
106
|
+
t = false
|
107
|
+
else
|
108
|
+
t = false if md[1].nil? && md[2].nil? && md[3].nil?
|
109
|
+
end
|
65
110
|
t
|
66
111
|
end
|
67
112
|
def is_Sig?
|
@@ -69,55 +114,26 @@ class String
|
|
69
114
|
def is_R?
|
70
115
|
false
|
71
116
|
end
|
72
|
-
|
73
|
-
re = /(
|
117
|
+
def to_N
|
118
|
+
re = /(^[0-9]+)/
|
74
119
|
md = re.match(self.to_s)
|
75
120
|
t = emptySet
|
76
121
|
t = md[1].to_i.to_N unless md.nil?
|
77
122
|
end
|
78
|
-
def to_Z
|
79
|
-
re = /(^\d+)/
|
80
|
-
md = re.match(self.to_s)
|
81
|
-
t = emptySet
|
82
|
-
if not md.nil? then
|
83
|
-
t = Zahlen(md[1].to_i)
|
84
|
-
else
|
85
|
-
re = /(^-\d+)/
|
86
|
-
md = re.match(self.to_s)
|
87
|
-
t = Zahlen((md[1].to_i)) unless md.nil?
|
88
|
-
end
|
89
|
-
t
|
90
|
-
end
|
91
123
|
def to_N0
|
92
|
-
re = /(
|
124
|
+
re = /(^[0-9]+)/
|
93
125
|
md = re.match(self.to_s)
|
94
126
|
t = emptySet
|
95
|
-
t =
|
127
|
+
t = md[1].to_i.to_N0 unless md.nil?
|
96
128
|
end
|
97
|
-
def
|
98
|
-
re = /(
|
129
|
+
def to_Z
|
130
|
+
re = /(^-?[0-9]+)/
|
99
131
|
md = re.match(self.to_s)
|
100
|
-
t =
|
101
|
-
|
102
|
-
t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i))
|
103
|
-
else
|
104
|
-
re = /^-1\((\d+) (\d+)\/(\d+)\)/
|
105
|
-
md = re.match(self.to_s)
|
106
|
-
if not md.nil? then
|
107
|
-
t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i),-1) unless md.nil?
|
108
|
-
else
|
109
|
-
re = /(\-*\d+)\/(\d+)/
|
110
|
-
md = re.match(self.to_s)
|
111
|
-
if not md.nil? then
|
112
|
-
t = Fraction(Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i)))
|
113
|
-
else
|
114
|
-
t=Fraction(Quotient(self.to_i,1))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
132
|
+
t = emptySet
|
133
|
+
t = Zahlen(md[1].to_i) unless md.nil?
|
118
134
|
end
|
119
135
|
def to_Q
|
120
|
-
re = /(
|
136
|
+
re = /(-?[0-9]+)\/([0-9]+)/
|
121
137
|
md = re.match(self.to_s)
|
122
138
|
ret = naught
|
123
139
|
if md then
|
@@ -128,9 +144,6 @@ class String
|
|
128
144
|
end
|
129
145
|
ret
|
130
146
|
end
|
131
|
-
def to_ST
|
132
|
-
ST.new(self)
|
133
|
-
end
|
134
147
|
def to_Dec
|
135
148
|
re = /^-/
|
136
149
|
md = re.match(self.to_s)
|
@@ -141,16 +154,19 @@ class String
|
|
141
154
|
t1 = '0'
|
142
155
|
t2 = nil
|
143
156
|
t3 = nil
|
144
|
-
re = /(
|
157
|
+
re = /([0-9]+)#{Decimal::decimalSeparator}([0-9]+)\[([0-9]+)\]/
|
158
|
+
re = /([0-9]+)\.([0-9]+)\[([0-9]+)\]/
|
145
159
|
md = re.match(self.to_s)
|
146
160
|
if md.to_a.empty? then
|
147
|
-
re = /(
|
161
|
+
re = /([0-9]+)#{Decimal::decimalSeparator}([0-9]+)/
|
162
|
+
re = /([0-9]+)\.([0-9]+)/
|
148
163
|
md = re.match(self.to_s)
|
149
164
|
if md.to_a.empty? then
|
150
|
-
re = /(
|
165
|
+
re = /([0-9]+)#{Decimal::decimalSeparator}\[([0-9]+)\]/
|
166
|
+
re = /([0-9]+)\.\[([0-9]+)\]/
|
151
167
|
md = re.match(self.to_s)
|
152
168
|
if md.to_a.empty? then
|
153
|
-
re = /(
|
169
|
+
re = /([0-9]+)/
|
154
170
|
md = re.match(self.to_s)
|
155
171
|
t0 = 0
|
156
172
|
t1 = '0'
|
@@ -176,6 +192,31 @@ class String
|
|
176
192
|
end
|
177
193
|
Decimal(t3,t2,t1,t0,e)
|
178
194
|
end
|
195
|
+
def to_Frac
|
196
|
+
re = /(^[0-9]+) ([0-9]+)\/([0-9]+)/
|
197
|
+
md = re.match(self.to_s)
|
198
|
+
t = nil
|
199
|
+
if not md.nil? then
|
200
|
+
t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i))
|
201
|
+
else
|
202
|
+
re = /^-1\(([0-9]+) ([0-9]+)\/([0-9]+)\)/
|
203
|
+
md = re.match(self.to_s)
|
204
|
+
if not md.nil? then
|
205
|
+
t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i),-1) unless md.nil?
|
206
|
+
else
|
207
|
+
re = /(\-*[0-9]+)\/([0-9]+)/
|
208
|
+
md = re.match(self.to_s)
|
209
|
+
if not md.nil? then
|
210
|
+
t = Fraction(Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i)))
|
211
|
+
else
|
212
|
+
t=Fraction(Quotient(self.to_i,1))
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
def to_ST
|
218
|
+
ST.new(self)
|
219
|
+
end
|
179
220
|
def is_K?
|
180
221
|
t = true
|
181
222
|
re = /(\d+)#{Kettenbruch::Separator}(\d+)/
|
@@ -192,7 +233,6 @@ class String
|
|
192
233
|
end
|
193
234
|
def append_K(a)
|
194
235
|
a = a.to_Frac
|
195
|
-
# "Fraction(Zahlen(#{a.integer.to_s}),Quotient(Zahlen(#{a.properfraction.numerator.to_s}),Zahlen(#{a.properfraction.denominator.to_s})))"
|
196
236
|
self.gsub!("&&&&","Fraction(Zahlen(#{a.integer.to_s}),Quotient(Zahlen(#{a.properfraction.numerator.to_s}),Zahlen(#{a.properfraction.denominator.to_s})))")
|
197
237
|
end
|
198
238
|
def to_K
|
@@ -205,8 +245,29 @@ class String
|
|
205
245
|
end
|
206
246
|
def to_Sig
|
207
247
|
end
|
208
|
-
|
209
|
-
|
248
|
+
end
|
249
|
+
def Real(a,&block)
|
250
|
+
if a.kind_of?(Real)
|
251
|
+
a
|
252
|
+
elsif a.kind_of?(Array)
|
253
|
+
rez = Real.new!(Quotient(0,1),block)
|
254
|
+
rez.continuedFraction = a.to_s
|
255
|
+
rez.update_eval = proc{|k0,k,ret,irrat| (k0..k).to_a.each{|n| n==k0 ? ret << irrat.call(n): ret << ","+ irrat.call(n)}; ret = "[" + ret + "]";eval(Real::gcontinuedFractionFactory(eval(ret)))}
|
256
|
+
rez.updateApprox{
|
257
|
+
@k0 = 1
|
258
|
+
@k = 12
|
259
|
+
@rat += update_eval.call(@k0,@k,@continuedFraction,@irrat).to_Q
|
260
|
+
}
|
261
|
+
elsif a.kind_of?(Quotient)
|
262
|
+
Real.new!(a,block)
|
263
|
+
elsif a.kind_of?(Natural) or a.kind_of?(Counting) or a.kind_of?(Zahlen) or a.kind_of?(Fraction) or a.kind_of?(Decimal)
|
264
|
+
elsif
|
265
|
+
Real.new!(a.to_Q,block)
|
266
|
+
elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass) or a.kind_of?(NilClass)
|
267
|
+
a unless b
|
268
|
+
new(Quotinet(0,1),block)
|
269
|
+
elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass)
|
270
|
+
a
|
210
271
|
end
|
211
272
|
end
|
212
273
|
class Numeric
|
@@ -437,7 +498,6 @@ class Rational
|
|
437
498
|
end
|
438
499
|
end
|
439
500
|
class ST<Numeric
|
440
|
-
#class SymbolicTerm<Numeric
|
441
501
|
def initialize(a,b=0,c='t') # a*(c) + b
|
442
502
|
if a.kind_of?(String)
|
443
503
|
regex = /(\d+[a-z])*(\+)?(\d+)?/
|
@@ -608,8 +668,6 @@ def Fraction(a,b=Quotient(0,1),c=1)
|
|
608
668
|
else
|
609
669
|
(a+b).to_Frac
|
610
670
|
end
|
611
|
-
# elsif a.kind_of?(Zahlen) && b.kind_of?(Fraction)
|
612
|
-
# Fraction(a,b.to_Q)
|
613
671
|
elsif Integer === a && b.kind_of?(Quotient)
|
614
672
|
if a>0 then
|
615
673
|
Fraction.new!(Zahlen(a),b,c)
|
@@ -678,12 +736,15 @@ def Decimal(a,b=nil,c='0',d=0,e=1)
|
|
678
736
|
end
|
679
737
|
def Kettenbruch(a,b='',c=1,leicht=true)
|
680
738
|
if a.kind_of?(Kettenbruch)
|
681
|
-
a
|
739
|
+
a
|
740
|
+
elsif a.kind_of?(Array)
|
741
|
+
b = a.shift
|
742
|
+
b<0 ? Kettenbruch.new!(-1*b,a) : Kettenbruch.new!(b,a)
|
682
743
|
elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass)
|
683
744
|
a
|
684
745
|
elsif a.kind_of?(String)
|
685
|
-
a.
|
686
|
-
elsif a.kind_of?(Proc)
|
746
|
+
a.to_K
|
747
|
+
elsif a.kind_of?(Proc)
|
687
748
|
a
|
688
749
|
elsif (a.kind_of?(Fixnum) or a.kind_of?(Bignum)) and b.kind_of?(String)
|
689
750
|
if (a>0 and c<0) or (a<0 and c>0) then
|
@@ -691,9 +752,21 @@ def Kettenbruch(a,b='',c=1,leicht=true)
|
|
691
752
|
else
|
692
753
|
Kettenbruch.new!(a,b,1)
|
693
754
|
end
|
755
|
+
elsif a.kind_of?(Quotient) and b==''
|
756
|
+
if a.to_Z == emptySet then
|
757
|
+
(a>0 and c<0) or (a<0 and c>0) ? Kettenbruch.new!(a.abs,b,-1): Kettenbruch.new!(a.abs,b,1)
|
758
|
+
else
|
759
|
+
Kettenbruch(a.to_Z,b,c)
|
760
|
+
end
|
761
|
+
elsif (a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural))and b==''
|
762
|
+
(a>0 and c<0) or (a<0 and c>0) ? Kettenbruch.new!(a.abs,[],-1): Kettenbruch.new!(a.abs,[],1)
|
694
763
|
end
|
695
764
|
end
|
696
|
-
def
|
765
|
+
def Symbolic_Term(a,b)
|
766
|
+
Symbolic_Term.new(a,b)
|
767
|
+
end
|
768
|
+
def Symbolic_Prod(a,b)
|
769
|
+
Symbolic_Prod.new(a,b)
|
697
770
|
end
|
698
771
|
def Matrix(m,n)
|
699
772
|
Matrix.instanciate(m,n)
|
@@ -734,11 +807,8 @@ class Natural < Numeric
|
|
734
807
|
end
|
735
808
|
def - (a)
|
736
809
|
if a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural) or a.kind_of?(Bignum) or a.kind_of?(Fixnum)
|
737
|
-
|
738
|
-
p z
|
739
|
-
p z<=0
|
810
|
+
z = @a.to_i - a.to_i
|
740
811
|
z <= 0 ? emptySet : Natural(z)
|
741
|
-
|
742
812
|
elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass)
|
743
813
|
self
|
744
814
|
elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass)
|
@@ -1711,16 +1781,19 @@ class Quotient < Numeric
|
|
1711
1781
|
def to_K
|
1712
1782
|
Kettenbruch(self.to_Frac)
|
1713
1783
|
end
|
1784
|
+
def to_Z
|
1785
|
+
self.denominator == 1 ? Zahlen(self.numerator) : emptySet
|
1786
|
+
end
|
1714
1787
|
def q2Dec(remainder)
|
1715
1788
|
maxcount =1000
|
1716
1789
|
kmcount = 0
|
1717
1790
|
ret = nil
|
1718
|
-
until (@remainders.member?(remainder) and @remainders.index(remainder)!= 0) or (kmcount > maxcount + 100) do
|
1791
|
+
until (@remainders.member?(remainder) and @remainders.index(remainder)!= 0) or (kmcount > maxcount + 100) do
|
1719
1792
|
break if remainder == 0
|
1720
1793
|
@remainders << remainder
|
1721
1794
|
@reg2 << remainder.div(@denominator.to_i)
|
1722
1795
|
remainder = remainder.remainder(@denominator.to_i)*10
|
1723
|
-
kmcount += 1
|
1796
|
+
kmcount += 1
|
1724
1797
|
end
|
1725
1798
|
@reg2.shift
|
1726
1799
|
if remainder == 0
|
@@ -1730,14 +1803,13 @@ class Quotient < Numeric
|
|
1730
1803
|
ret = "Decimal('-#{@numerator.div(@denominator)}#{Decimal::decimalSeparator}#{@reg2.join}')"
|
1731
1804
|
end
|
1732
1805
|
else
|
1733
|
-
# @reg2.insert(@remainders.find_index(remainder)-1,"[")
|
1734
1806
|
@reg2.insert(@remainders.find_index(remainder)-1,"[") unless (kmcount > maxcount + 100)
|
1735
1807
|
if @abs1 ==1 then
|
1736
1808
|
ret = "Decimal('#{@numerator.div(@denominator)}#{Decimal::decimalSeparator}#{@reg2.join}]')" unless (kmcount > maxcount + 100)
|
1737
|
-
ret = "Decimal('#{@numerator.div(@denominator)}#{Decimal::decimalSeparator}#{@reg2.join}[0]')" if (kmcount > maxcount + 100)
|
1809
|
+
ret = "Decimal('#{@numerator.div(@denominator)}#{Decimal::decimalSeparator}#{@reg2.join}[0]')" if (kmcount > maxcount + 100)
|
1738
1810
|
elsif @abs1 == -1
|
1739
1811
|
ret = "Decimal('-#{@numerator.div(@denominator)}#{Decimal::decimalSeparator}#{@reg2.join}]')" unless (kmcount > maxcount + 100)
|
1740
|
-
ret = "Decimal('#{@numerator.div(@denominator)}#{Decimal::decimalSeparator}#{@reg2.join}[0]')" if (kmcount > maxcount + 100)
|
1812
|
+
ret = "Decimal('#{@numerator.div(@denominator)}#{Decimal::decimalSeparator}#{@reg2.join}[0]')" if (kmcount > maxcount + 100)
|
1741
1813
|
end
|
1742
1814
|
end
|
1743
1815
|
eval(ret)
|
@@ -1918,7 +1990,7 @@ class Decimal < Numeric
|
|
1918
1990
|
end
|
1919
1991
|
ret.to_Dec
|
1920
1992
|
end
|
1921
|
-
def minus(a)
|
1993
|
+
def minus(a)
|
1922
1994
|
ret = nil
|
1923
1995
|
pat = nil
|
1924
1996
|
if a.kind_of?(Decimal)
|
@@ -2042,7 +2114,7 @@ class Decimal < Numeric
|
|
2042
2114
|
) or (self.decimalfraction == other.decimalfraction_1
|
2043
2115
|
)
|
2044
2116
|
)
|
2045
|
-
elsif other.kind_of?(Float) or other.kind_of?(Quotient) or other.kind_of?(Fraction)
|
2117
|
+
elsif other.kind_of?(Float) or other.kind_of?(Quotient) or other.kind_of?(Fraction)
|
2046
2118
|
self == other.to_Dec
|
2047
2119
|
else
|
2048
2120
|
other.to_i == self.to_i
|
@@ -2079,12 +2151,9 @@ class Decimal < Numeric
|
|
2079
2151
|
def d2Frac
|
2080
2152
|
t0 = Quotient(0,1)
|
2081
2153
|
s = @decimalfraction.to_s.length > 0 ? @decimalfraction.to_s.length - 1 : 0
|
2082
|
-
#p "decimal fraction part"
|
2083
2154
|
s == 0 ? t0 = Quotient(@decimalfraction.nil? ? 0 : @decimalfraction,("1" + ("0"*@decimalExponent)).to_i) : t0 = Quotient(@decimalfraction.nil? ? 0 : @decimalfraction,("1" +("0"* (@decimalfraction.to_s.length)) + ("0"*@decimalExponent)).to_i)
|
2084
|
-
#p "repetend part"
|
2085
2155
|
t1 = Quotient(Zahlen(@repetend.call.to_i),Zahlen((("9"*@repetend.call.length)+("0"* s)+("0"*@decimalExponent)).to_i))
|
2086
2156
|
Fraction(Zahlen(@integraldecimal),(t0 + Fraction(Zahlen(0),t1)),@absolute)
|
2087
|
-
#Fraction(Zahlen(@integraldecimal),(t0 + Quotient(Zahlen(0),t1)),@absolute)
|
2088
2157
|
end
|
2089
2158
|
def to_Frac
|
2090
2159
|
@to_Frac ||= d2Frac
|
@@ -2398,9 +2467,8 @@ class Kettenbruch<Numeric
|
|
2398
2467
|
p "raise error" unless a.kind_of?(Array)
|
2399
2468
|
init=true
|
2400
2469
|
b = a.pop(2) if y
|
2401
|
-
# y=="" ? tmp1 = "Fraction(Zahlen(#{b.at(0)}),Quotient(Zahlen(1),#{b.at(1)}))" : tmp1 = "Fraction(Zahlen(\#{y.integer.to_s}),Quotient(Zahlen(#{\y.properfracti#on.numerator.to_s}),Zahlen(#{y.properfraction.denominator.to_s})))"
|
2402
2470
|
y ? tmp1 = "Fraction(Zahlen(#{b.at(0)}),Quotient(Zahlen(1),#{b.at(1)}))" : tmp1 = "&&&&"
|
2403
|
-
tmp0 = ""
|
2471
|
+
tmp0 = ""
|
2404
2472
|
a.reverse.each{|x|
|
2405
2473
|
break if x.nil?
|
2406
2474
|
tmp0 = "Fraction(Zahlen(#{x}),Quotient(Zahlen(1),(#{tmp1})))"
|
@@ -2413,7 +2481,6 @@ tmp0 = ""
|
|
2413
2481
|
p "raise error" unless a.kind_of?(Array)
|
2414
2482
|
init=true
|
2415
2483
|
b = a.pop if y == ''
|
2416
|
-
# y=='' ? tmp1 = "Fraction(Zahlen(#{b.at(0)}),Quotient(Zahlen(0),Zahlen(#{b.at(1)})))" : tmp1 = "Fraction(Zahlen(#{y.integer.to_s}),Quotient(Zahlen(#{y.properfraction.numerator.to_s}),Zahlen(#{y.properfraction.denominator.to_s})))"
|
2417
2484
|
y ? tmp1 = "Fraction(Zahlen(#{b.at(0)}),Quotient(#{b.at(1)},#{b.at(2)}))" : tmp1 = "&&&&"
|
2418
2485
|
tmp0 = ""
|
2419
2486
|
a.reverse.each{|x|
|
@@ -2463,9 +2530,7 @@ tmp0 = ""
|
|
2463
2530
|
c = cfra
|
2464
2531
|
until tmp == 0
|
2465
2532
|
b = Kettenbruch::euclid(c)
|
2466
|
-
# p "#{c.denominator} = #{b.at(0)}.#{c.numerator} + #{b.at(1)}" #=8=
|
2467
2533
|
@fractionalK << b.at(0)
|
2468
|
-
#if @fractionalK.length.is_even? then @fractionalK_ << b.at(0) remove last add last - 1 then + [1]
|
2469
2534
|
tmp = b.at(1)
|
2470
2535
|
c = Quotient(tmp,c.numerator)
|
2471
2536
|
end
|
@@ -2476,7 +2541,6 @@ tmp0 = ""
|
|
2476
2541
|
attr_accessor :integralK, :fractionalK, :continuedFraction, :patt_succ, :absolute, :canonical, :longfracK, :leicht
|
2477
2542
|
private_class_method :new
|
2478
2543
|
def partition(size=9,length=100)
|
2479
|
-
# stop if ref
|
2480
2544
|
e = ""
|
2481
2545
|
e = "-" if @absolute == -1
|
2482
2546
|
rep = @repetend
|
@@ -2497,14 +2561,12 @@ tmp0 = ""
|
|
2497
2561
|
res.gsub!("[, ","[").gsub(",]","]").gsub(",[]","]")
|
2498
2562
|
t = eval(res + "]")
|
2499
2563
|
t.delete_at(t.length - 1)
|
2500
|
-
|
2564
|
+
zz = t.delete_at(t.length - 1)
|
2501
2565
|
zz = Kettenbruch::leichtfactory(zz)
|
2502
2566
|
t.map!{|x|
|
2503
2567
|
Kettenbruch::leichtfactory(x,false)
|
2504
|
-
# leicht? ? ret = Kettenbruch::leichtfactory(n) : ret = Kettenbruch::factory(n)
|
2505
|
-
|
2506
2568
|
}
|
2507
|
-
t << zz
|
2569
|
+
t << zz
|
2508
2570
|
end
|
2509
2571
|
def convergents
|
2510
2572
|
ret = []
|
@@ -2663,21 +2725,14 @@ t << zz
|
|
2663
2725
|
end
|
2664
2726
|
tmp = 0
|
2665
2727
|
self.to_pix(a0,b0,c0,d0,e0,f0,g0,h0)
|
2666
|
-
p "init"
|
2667
2728
|
while tmp <19 #true # size of k_res is less than epsilon
|
2668
2729
|
eggs = true
|
2669
2730
|
if e0 == 0 or f0 == 0 or g0 == 0 or h0 == 0 then
|
2670
2731
|
eggs = false if f0 == 0
|
2671
2732
|
else # all are positive
|
2672
|
-
p "positive"
|
2673
|
-
#p a0.div(e0).at(0)
|
2674
2733
|
eggs = false if a0.divmod(e0).at(0) == c0.divmod(g0).at(0)
|
2675
2734
|
end
|
2676
|
-
|
2677
|
-
#p (f > 0 and e > 0 and g > 0 ) ? (c/g-a/e).abs : f,e,g
|
2678
|
-
p "### #{eggs}"
|
2679
|
-
if eggs then
|
2680
|
-
p "to the right"
|
2735
|
+
if eggs then # "to the right"
|
2681
2736
|
x = sa.shift
|
2682
2737
|
a1 = (a0*x)+c0
|
2683
2738
|
b1 = (b0*x)+d0
|
@@ -2688,8 +2743,7 @@ t << zz
|
|
2688
2743
|
g1 = e0
|
2689
2744
|
h1 = f0
|
2690
2745
|
self.to_pix(a1,b1,c1,d1,e1,f1,g1,h1)
|
2691
|
-
else
|
2692
|
-
p "downwards"
|
2746
|
+
else # "downwards"
|
2693
2747
|
y = oa.shift
|
2694
2748
|
a1 = (a0*y)+b0
|
2695
2749
|
b1 = a0
|
@@ -2707,7 +2761,6 @@ t << zz
|
|
2707
2761
|
test = eucint == b0.divmod(f0).at(0) and eucint == c0.divmod(g0).at(0) and eucint == d0.divmod(h0).at(0) and eucint > 0
|
2708
2762
|
end
|
2709
2763
|
if test then
|
2710
|
-
p "here"
|
2711
2764
|
res_a << eucint
|
2712
2765
|
a0 = e1
|
2713
2766
|
b0 = f1
|
@@ -2868,7 +2921,613 @@ t << zz
|
|
2868
2921
|
end
|
2869
2922
|
end
|
2870
2923
|
end
|
2871
|
-
class Real
|
2924
|
+
class Real< Numeric
|
2925
|
+
include SGML
|
2926
|
+
@@threebareqs = "\u2261"
|
2927
|
+
def to_sgml
|
2928
|
+
"<mn #{sgml_id}class='Real'>#{@a}</mn>"
|
2929
|
+
end
|
2930
|
+
def Real.defines
|
2931
|
+
@@threebareqs.encode('utf-8')
|
2932
|
+
end
|
2933
|
+
def Real.new!(num,a,b)
|
2934
|
+
if a.kind_of?(Real)
|
2935
|
+
a
|
2936
|
+
elsif a.kind_of?(Array)
|
2937
|
+
z = eval(gcontinuedFractionFactory(a))
|
2938
|
+
new(z.to_Q,b)
|
2939
|
+
elsif a.kind_of?(Quotient)
|
2940
|
+
new(a,b)
|
2941
|
+
elsif a.kind_of?(Natural) or a.kind_of?(Counting) or a.kind_of?(Zahlen) or a.kind_of?(Fraction) or a.kind_of?(Decimal)
|
2942
|
+
elsif
|
2943
|
+
new(a.to_Q,b)
|
2944
|
+
elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass) or a.kind_of?(NilClass)
|
2945
|
+
a unless b
|
2946
|
+
new(Quotinet(0,1),b) if b
|
2947
|
+
elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass)
|
2948
|
+
a
|
2949
|
+
end
|
2950
|
+
end
|
2951
|
+
def Real::epsilon(e)
|
2952
|
+
#on epsilon change flag for dirty and recalculate
|
2953
|
+
end
|
2954
|
+
private_class_method :new
|
2955
|
+
def initialize(lbl,definitn,irrat)
|
2956
|
+
@label = lbl
|
2957
|
+
@equality_by_definition_symbols = ["==",Real.defines]
|
2958
|
+
@definitn = definitn
|
2959
|
+
@rat = definitn
|
2960
|
+
@irrat = irrat
|
2961
|
+
@k = 5
|
2962
|
+
@k0 = 0
|
2963
|
+
@update_eval = proc{ ret = Quotient(0,1) ; (@k0..@k).to_a.each{|n| ret += @irrat.call(n)}; ret}
|
2964
|
+
@continuedfraction
|
2965
|
+
end
|
2966
|
+
def updateApprox(&block)
|
2967
|
+
instance_exec(&block)
|
2968
|
+
end
|
2969
|
+
def updateApprox1
|
2970
|
+
@rat += @update_eval.call
|
2971
|
+
# instance_eval(@update_eval.call)
|
2972
|
+
end
|
2973
|
+
private :initialize
|
2974
|
+
attr_accessor :update_eval, :continuedFraction
|
2975
|
+
private_class_method :new
|
2976
|
+
@@epsilon = Quotient(1,100000000000)
|
2977
|
+
@@upsilon = "a very large number ceiling to signal change to scientific format"
|
2978
|
+
def Real::continuedFractionFactory(a)
|
2979
|
+
init=true
|
2980
|
+
b = a.pop(2)
|
2981
|
+
tmp1 = "Fraction(Zahlen(#{b.at(0)}),Quotient(Zahlen(1),#{b.at(1)}))"
|
2982
|
+
tmp0 = ""
|
2983
|
+
a.reverse.each{|x|
|
2984
|
+
break if x.nil?
|
2985
|
+
tmp0 = "Fraction(Zahlen(#{x}),Quotient(Zahlen(1),(#{tmp1})))"
|
2986
|
+
tmp1 = tmp0
|
2987
|
+
tmp0 = ""
|
2988
|
+
}
|
2989
|
+
tmp1
|
2990
|
+
end
|
2991
|
+
def Real::gcontinuedFractionFactory(a,y=true)
|
2992
|
+
Kettenbruch::allseitigfactory(a,y)
|
2993
|
+
end
|
2994
|
+
def to_Ball
|
2995
|
+
rad = @@epsilon / Quotient(2,1)
|
2996
|
+
"(#{@rat - rad} .. #{@rat + rad})"
|
2997
|
+
end
|
2998
|
+
def to_Ball!
|
2999
|
+
rad = @@epsilon / Quotient(2,1)
|
3000
|
+
tmp = @rat - rad
|
3001
|
+
tmp.setdelta
|
3002
|
+
(tmp..(@rat + rad))
|
3003
|
+
end
|
3004
|
+
def to_a
|
3005
|
+
to_Ball!.to_a
|
3006
|
+
end
|
3007
|
+
def to_Frac
|
3008
|
+
@rat.to_Frac
|
3009
|
+
end
|
3010
|
+
def to_Dec
|
3011
|
+
@rat.to_Dec
|
3012
|
+
end
|
3013
|
+
def to_Q
|
3014
|
+
@rat.to_Q
|
3015
|
+
end
|
3016
|
+
def to_Z
|
3017
|
+
@rat.to_Z
|
3018
|
+
end
|
3019
|
+
def to_N0
|
3020
|
+
@rat.to_N0
|
3021
|
+
end
|
3022
|
+
def to_N
|
3023
|
+
@rat.to_N
|
3024
|
+
end
|
3025
|
+
def to_s
|
3026
|
+
"#{@label} #{Real.defines} #{@definitn}"
|
3027
|
+
end
|
3028
|
+
end
|
3029
|
+
class Symbolic_Term#<ST
|
3030
|
+
@@powersym = '\*\*'
|
3031
|
+
def initialize(a,b='',c='t') #a = PI,b = "32PI**4+31PI**3 + 30PI + Natural(29)
|
3032
|
+
@exponents ={}
|
3033
|
+
exponents_add(0,1)
|
3034
|
+
#p @exponents
|
3035
|
+
@symbolic_label = a
|
3036
|
+
@orig_statment = b
|
3037
|
+
@symbolic_expressions = []
|
3038
|
+
if b.kind_of?(String)
|
3039
|
+
b == '' ? add_exponent_accessor(1) : parse(b)
|
3040
|
+
else
|
3041
|
+
end
|
3042
|
+
end
|
3043
|
+
attr_accessor :symbolic_label
|
3044
|
+
# private_class_method :new
|
3045
|
+
def parse(b)
|
3046
|
+
reg0 = /([^\+]+)/
|
3047
|
+
reg1 = /(-?[0-9\(\)]+)(\/?[0-9]*)([a-zA-Z\(\)0-9]+)\*\*(-?[0-9\(\)]+)(\/?[0-9]*)/
|
3048
|
+
# md = b.match(reg0)
|
3049
|
+
md = ""
|
3050
|
+
frstrmneg = false
|
3051
|
+
frstrmneg = true if b.match(/^-/)
|
3052
|
+
if frstrmneg then
|
3053
|
+
b.gsub!(/^-/,'')
|
3054
|
+
b.gsub!('-','+-')
|
3055
|
+
md = b.split('+')
|
3056
|
+
md[0] = '-' + md[0]
|
3057
|
+
else
|
3058
|
+
b.gsub!('-','+-')
|
3059
|
+
md = b.split('+')
|
3060
|
+
end
|
3061
|
+
md.each{|re|
|
3062
|
+
ans = re.match(reg1)
|
3063
|
+
if ans
|
3064
|
+
#p ans[1],ans[2],ans[3],ans[4],ans[5]
|
3065
|
+
# exponents_add(instance_eval(ans[3]),instance_eval(ans[1]))
|
3066
|
+
if ans[2]=='' and ans[5]=='' then
|
3067
|
+
exponents_add(instance_eval(ans[4]),instance_eval(ans[1]))
|
3068
|
+
elsif ans[5]==''
|
3069
|
+
exponents_add(instance_eval(ans[4]),instance_eval("Quotient(#{ans[1]},#{ans[2].gsub('/','')})"))
|
3070
|
+
elsif ans[2]==''
|
3071
|
+
exponents_add(instance_eval("Quotient(#{ans[4]},#{ans[5].gsub('/','')})"),instance_eval("Quotient(#{ans[1]},#{ans[2].gsub('/','')})"))
|
3072
|
+
else
|
3073
|
+
exponents_add(instance_eval("Quotient(#{ans[4]},#{ans[5].gsub('/','')})"),instance_eval("Quotient(#{ans[1]},#{ans[2].gsub('/','')})"))
|
3074
|
+
end
|
3075
|
+
else
|
3076
|
+
ans1 = re.match(/#{@symbolic_label}/)
|
3077
|
+
if ans1 then
|
3078
|
+
#p "#{@symbolic_label}#{@@powersym.gsub('\\','')}1"
|
3079
|
+
re.gsub!(@symbolic_label,'')
|
3080
|
+
# exponents_add('1',instance_eval(re.strip!))
|
3081
|
+
exponents_add('1',re.strip!)
|
3082
|
+
else
|
3083
|
+
#p "constant?"
|
3084
|
+
re.strip!
|
3085
|
+
re.gsub!('-','Zahlen(-1)*')
|
3086
|
+
exponents_add('0',instance_eval(re))
|
3087
|
+
end
|
3088
|
+
end
|
3089
|
+
}
|
3090
|
+
end
|
3091
|
+
def exponent_list
|
3092
|
+
tmp = []
|
3093
|
+
@exponents.sort.map{|a,b| tmp << a}
|
3094
|
+
tmp
|
3095
|
+
end
|
3096
|
+
def exponents_add(a,b)
|
3097
|
+
a = a.to_s
|
3098
|
+
a.gsub!('/','_') if a.match('/')
|
3099
|
+
add_exponent_accessor(a) unless @exponents.has_key?(a)
|
3100
|
+
@exponents[a] = b
|
3101
|
+
end
|
3102
|
+
def add_exponent_accessor(a)
|
3103
|
+
if exponent_list.include?(a)then
|
3104
|
+
else
|
3105
|
+
z = " @exponent_#{a} = 1
|
3106
|
+
def exp_#{a}
|
3107
|
+
@exponents[\"#{a}\"]
|
3108
|
+
end
|
3109
|
+
def coef_at_#{a}
|
3110
|
+
@exponents[\"#{a}\"]
|
3111
|
+
end
|
3112
|
+
"
|
3113
|
+
instance_eval(z)
|
3114
|
+
@exponents[a.to_s] = '1'
|
3115
|
+
end
|
3116
|
+
end
|
3117
|
+
def +(o)
|
3118
|
+
tmp = Symbolic_Term.new(@symbolic_label)
|
3119
|
+
if o.kind_of?(Symbolic_Term) then
|
3120
|
+
exp_list = (exponent_list + o.exponent_list).uniq
|
3121
|
+
if @symbolic_label == o.symbolic_label then
|
3122
|
+
exp_list.each{|a|
|
3123
|
+
if respond_to?("coef_at_#{a}") then
|
3124
|
+
if o.respond_to?("coef_at_#{a}") then
|
3125
|
+
tmp.exponents_add(a,send("coef_at_#{a}") + o.send("coef_at_#{a}"))
|
3126
|
+
else
|
3127
|
+
tmp.exponents_add(a,send("coef_at_#{a}"))
|
3128
|
+
end
|
3129
|
+
else
|
3130
|
+
tmp.exponents_add(a,o.send("coef_at_#{a}")) if o.respond_to?("coef_at_#{a}")
|
3131
|
+
end
|
3132
|
+
}
|
3133
|
+
tmp
|
3134
|
+
else
|
3135
|
+
end
|
3136
|
+
elsif o.kind_of?(Quotient) or o.kind_of?(Zahlen) or o.kind_of?(Counting) or o.kind_of?(Natural)
|
3137
|
+
exponent_list.each{|a|
|
3138
|
+
a == '0' ? tmp.exponents_add(a,(o + coef_at_0 )) : tmp.exponents_add(a,send("coef_at_#{a}"))
|
3139
|
+
|
3140
|
+
}
|
3141
|
+
end
|
3142
|
+
tmp
|
3143
|
+
end
|
3144
|
+
def *(o)
|
3145
|
+
tmp = Symbolic_Term.new(@symbolic_label)
|
3146
|
+
if o.kind_of?(Quotient) or o.kind_of?(Zahlen) or o.kind_of?(Counting) or o.kind_of?(Natural)
|
3147
|
+
exponent_list.each{|a|
|
3148
|
+
tmp.exponents_add(a,(o.to_Q * send("coef_at_#{a}")))
|
3149
|
+
}
|
3150
|
+
elsif o.kind_of?(Symbolic_Term)
|
3151
|
+
if @symbolic_label == o.symbolic_label then
|
3152
|
+
exponent_list.each{|a|
|
3153
|
+
o.exponent_list.each{|b|
|
3154
|
+
tmp.exponents_add((a+b),( send("coef_at_#{a}") * o.send("coef_at_#{b}")))
|
3155
|
+
}
|
3156
|
+
}
|
3157
|
+
else
|
3158
|
+
empty_set
|
3159
|
+
#normally would return a SymbolicExpression, but should be ordered first
|
3160
|
+
end
|
3161
|
+
end
|
3162
|
+
tmp
|
3163
|
+
end
|
3164
|
+
def -(o)
|
3165
|
+
tmp = Symbolic_Term.new(@symbolic_label)
|
3166
|
+
if o.kind_of?(Symbolic_Term) then
|
3167
|
+
exp_list = (exponent_list + o.exponent_list).uniq
|
3168
|
+
if @symbolic_label == o.symbolic_label then
|
3169
|
+
exp_list.each{|a|
|
3170
|
+
if respond_to?("coef_at_#{a}") then
|
3171
|
+
if o.respond_to?("coef_at_#{a}") then
|
3172
|
+
tmp.exponents_add(a,send("coef_at_#{a}") - o.send("coef_at_#{a}"))
|
3173
|
+
else
|
3174
|
+
tmp.exponents_add(a,send("coef_at_#{a}"))
|
3175
|
+
end
|
3176
|
+
else
|
3177
|
+
tmp.exponents_add(a,(-1 * o.send("coef_at_#{a}"))) if o.respond_to?("coef_at_#{a}")
|
3178
|
+
end
|
3179
|
+
}
|
3180
|
+
tmp
|
3181
|
+
else
|
3182
|
+
end
|
3183
|
+
elsif o.kind_of?(Quotient) or o.kind_of?(Zahlen) or o.kind_of?(Counting) or o.kind_of?(Natural)
|
3184
|
+
exponent_list.each{|a|
|
3185
|
+
a == '0' ? tmp.exponents_add(a,(coef_at_0 - o )) : tmp.exponents_add(a,send("coef_at_#{a}"))
|
3186
|
+
|
3187
|
+
}
|
3188
|
+
end
|
3189
|
+
tmp
|
3190
|
+
end
|
3191
|
+
def /(o)
|
3192
|
+
if o.kind_of?(Quotient) or o.kind_of?(Zahlen) or o.kind_of?(Counting) or o.kind_of?(Natural)
|
3193
|
+
exponent_list.each{|a|
|
3194
|
+
tmp.exponents_add(a,(send("coef_at_#{a}")/o.to_Q))
|
3195
|
+
}
|
3196
|
+
end
|
3197
|
+
tmp
|
3198
|
+
end
|
3199
|
+
def to_statement
|
3200
|
+
tmp = ''
|
3201
|
+
first = true
|
3202
|
+
exponent_list.reverse.each{|a|
|
3203
|
+
a0 = instance_eval("coef_at_#{a}")
|
3204
|
+
a0 = instance_eval(a0) if a0.kind_of?(String)
|
3205
|
+
if a0<0 then
|
3206
|
+
first ? tmp += "-" : tmp += " - "
|
3207
|
+
if a == '0' or a=='1' then
|
3208
|
+
a=='1' ? tmp += (Zahlen(-1)*a0).to_s + @symbolic_label.to_s : tmp += (Zahlen(-1)*a0).to_s
|
3209
|
+
else
|
3210
|
+
tmp += (Zahlen(-1)*a0).to_s + @symbolic_label.to_s + @@powersym.to_s.gsub('\\','') + a.to_s
|
3211
|
+
end
|
3212
|
+
else
|
3213
|
+
tmp += " + " unless first
|
3214
|
+
if a == '0' or a=='1' then
|
3215
|
+
a=='1' ? tmp += a0.to_s + @symbolic_label.to_s : tmp += a0.to_s
|
3216
|
+
else
|
3217
|
+
tmp += a0.to_s + @symbolic_label.to_s + @@powersym.to_s.gsub('\\','') + a.to_s
|
3218
|
+
end
|
3219
|
+
end
|
3220
|
+
first = false
|
3221
|
+
}
|
3222
|
+
tmp
|
3223
|
+
end
|
3224
|
+
def coerce(o)
|
3225
|
+
[self, o]
|
3226
|
+
end
|
3227
|
+
def to_s
|
3228
|
+
# @orig_statment == '' ? to_statement : @orig_statment
|
3229
|
+
to_statement
|
3230
|
+
end
|
3231
|
+
def inspect
|
3232
|
+
"Symbolic_Term(#{@symbolic_label}#{@orig_statment})"
|
3233
|
+
end
|
3234
|
+
end
|
3235
|
+
class Symbolic_Prod
|
3236
|
+
@@powersym = '\*\*'
|
3237
|
+
def initialize(a,b='',c='t') #a = ['e','PI'],b = "32e**2PI**4+31e**5PI**3 + 30PI + Natural(29)
|
3238
|
+
@exponents ={}
|
3239
|
+
@symbolic_labels = a
|
3240
|
+
@orig_statement = b
|
3241
|
+
parse(b)
|
3242
|
+
if b.kind_of?(String)
|
3243
|
+
b == '' ? add_exponent_accessor(1) : parse(b)
|
3244
|
+
else
|
3245
|
+
end
|
3246
|
+
end
|
3247
|
+
attr_accessor :symbolic_labels, :orig_statement
|
3248
|
+
attr_accessor :exponents # mk private
|
3249
|
+
# private_class_method :new
|
3250
|
+
def arity
|
3251
|
+
@symbolic_labels.size
|
3252
|
+
end
|
3253
|
+
def parse(b)
|
3254
|
+
#scan + #32(e**2PI**4)+1(e**5.PI**3)+ 30PI
|
3255
|
+
reg0 = /(-?[0-9]+)\(([^\)]*)\)/ #32(e**2PI**4) => m[1] = 3 m[2]= (e**2PI**4)
|
3256
|
+
reg1 = /([a-zA-Z]+)\*\*([0-9]+)/
|
3257
|
+
md = ""
|
3258
|
+
frstrmneg = false
|
3259
|
+
frstrmneg = true if b.match(/^-/)
|
3260
|
+
if frstrmneg then
|
3261
|
+
b.gsub!(/^-/,'')
|
3262
|
+
b.gsub!('-','+-')
|
3263
|
+
md = b.split('+')
|
3264
|
+
md[0] = '-' + md[0]
|
3265
|
+
else
|
3266
|
+
b.gsub!('-','+-')
|
3267
|
+
md = b.split('+')
|
3268
|
+
end
|
3269
|
+
coeffc = ""
|
3270
|
+
labels = []
|
3271
|
+
expnts = []
|
3272
|
+
lbsort = []
|
3273
|
+
md.each{|re|
|
3274
|
+
re.strip!
|
3275
|
+
ans1 = re.split('.')
|
3276
|
+
if ans1.size < @symbolic_labels.size + 1 then # we have missing labels .. so all exponents are 0
|
3277
|
+
ansdup = ans1.dup
|
3278
|
+
missing_lbls = @symbolic_labels.dup
|
3279
|
+
poss_coeff = ansdup.shift
|
3280
|
+
if poss_coeff.match(reg1) then # then is not a number..ie no coeff.. ie implied coeff == one
|
3281
|
+
ans1.unshift("Natural(1)")
|
3282
|
+
ansdup.unshift(poss_coeff) # put back the label!
|
3283
|
+
elsif poss_coeff.match(/[0-9]/) # could be other numbers!
|
3284
|
+
ansdup.map!{|item| item.to_s + "**1"}
|
3285
|
+
ansdup.unshift(poss_coeff) # put back the label!
|
3286
|
+
ans1 = ansdup.dup
|
3287
|
+
ansdup.shift
|
3288
|
+
else
|
3289
|
+
poss_coeff += "**1" if poss_coeff.match(/\*\*/).nil? # no power
|
3290
|
+
end
|
3291
|
+
|
3292
|
+
ansdup.each{|t|
|
3293
|
+
tst2 = t.match(reg1)
|
3294
|
+
missing_lbls.delete(tst2[1]) if @symbolic_labels.include?(tst2[1])
|
3295
|
+
}
|
3296
|
+
missing_lbls.map!{|item| item.to_s + "**0"}
|
3297
|
+
ans1 += missing_lbls
|
3298
|
+
end
|
3299
|
+
ans1.each{|re1| # each labl
|
3300
|
+
re2 = re1.match(reg1)
|
3301
|
+
if re1.match(reg1)
|
3302
|
+
labels << re2[1]
|
3303
|
+
lbsort << re2[1]
|
3304
|
+
expnts << re2[2]
|
3305
|
+
else # "coeffiecient"
|
3306
|
+
coeffc = re1
|
3307
|
+
end
|
3308
|
+
}
|
3309
|
+
if labels.empty? and lbsort.empty? and expnts.empty? # "constant"
|
3310
|
+
labels = @symbolic_labels if labels.size == 0
|
3311
|
+
lbsort = @symbolic_labels if lbsort.size == 0
|
3312
|
+
expnts = Array.new(labels.size,'0') if expnts.size ==0
|
3313
|
+
|
3314
|
+
else # "coeff"
|
3315
|
+
end
|
3316
|
+
tmp = ""
|
3317
|
+
tmp0 = ""
|
3318
|
+
lbsort.sort!
|
3319
|
+
first = true
|
3320
|
+
lbsort.each_index{|i|
|
3321
|
+
first ? tmp += "#{labels.at(labels.index(lbsort.at(i)))}_#{expnts.at(labels.index(lbsort.at(i)))}" : tmp += ".#{labels.at(labels.index(lbsort.at(i)))}_#{expnts.at(labels.index(lbsort.at(i)))}"
|
3322
|
+
first ? tmp0 += "#{expnts.at(labels.index(lbsort.at(i)))}" : tmp0 += "_#{expnts.at(labels.index(lbsort.at(i)))}"
|
3323
|
+
first = false
|
3324
|
+
}
|
3325
|
+
labels = []
|
3326
|
+
expnts = []
|
3327
|
+
lbsort = []
|
3328
|
+
add_exponent_accessor(tmp0) unless @exponents.has_key?(tmp0)
|
3329
|
+
ncoef = instance_eval(coeffc)
|
3330
|
+
ncoef.kind_of?(Numeric) ? @exponents[tmp0] = ncoef.to_Q : @exponents[tmp0] = coeffc
|
3331
|
+
}
|
3332
|
+
end
|
3333
|
+
def exponent_full_sorted_list
|
3334
|
+
test = {}
|
3335
|
+
st1 = ""
|
3336
|
+
st2 = ""
|
3337
|
+
str2 = false
|
3338
|
+
exponent_sorted_list.each{|a|
|
3339
|
+
tmp = a.split('_')
|
3340
|
+
first = true
|
3341
|
+
symbolic_labels.each_index{|i|
|
3342
|
+
if tmp.at(i) == '0' then
|
3343
|
+
str2 = true
|
3344
|
+
first ? st2 += "1" : st2 += ".1"
|
3345
|
+
elsif tmp.at(i) == '1' then
|
3346
|
+
str2 = true
|
3347
|
+
first ? st2 += "#{symbolic_labels.at(i)}" : st2 += ".#{symbolic_labels.at(i)}"
|
3348
|
+
end
|
3349
|
+
first ? st1 += "#{symbolic_labels.at(i)}**#{tmp.at(i)}" : st1 += ".#{symbolic_labels.at(i)}**#{tmp.at(i)}"
|
3350
|
+
first = false
|
3351
|
+
}
|
3352
|
+
test[st1] = a
|
3353
|
+
test[st2] = a ; str2 = false if str2
|
3354
|
+
st1 = ""
|
3355
|
+
}
|
3356
|
+
test
|
3357
|
+
end
|
3358
|
+
def exponent_sorted_list #look like a = la1b3_lb2l34_lb3l45, b=coeff , {'la1b3_lb2l34_lb3l45'=>coeff}
|
3359
|
+
tmp = []
|
3360
|
+
@exponents.sort.map{|a,b| tmp << a}
|
3361
|
+
tmp
|
3362
|
+
end
|
3363
|
+
def exponents_add(a,b)
|
3364
|
+
a = a.to_s
|
3365
|
+
# b = b.to_s
|
3366
|
+
a.gsub!('/','_') if a.match('/')
|
3367
|
+
add_exponent_accessor(a) unless @exponents.has_key?(a)
|
3368
|
+
# @exponents[a] = b
|
3369
|
+
@exponents[a] = b.to_Q
|
3370
|
+
end
|
3371
|
+
def add_exponent_accessor(a)
|
3372
|
+
z = ""
|
3373
|
+
unless @exponents.has_key?(a)then
|
3374
|
+
z = "
|
3375
|
+
def coef_at_#{a}
|
3376
|
+
@exponents[\"#{a}\"]
|
3377
|
+
end
|
3378
|
+
"
|
3379
|
+
end
|
3380
|
+
instance_eval(z)
|
3381
|
+
@exponents[a] = '1'
|
3382
|
+
end
|
3383
|
+
def coef_methods
|
3384
|
+
tmp = []
|
3385
|
+
methods.each{|md|
|
3386
|
+
tmp << md if md.match(/coef_at_/)
|
3387
|
+
}
|
3388
|
+
tmp
|
3389
|
+
end
|
3390
|
+
def +(o)
|
3391
|
+
tmp = Symbolic_Prod.new(@symbolic_label)
|
3392
|
+
coeffs = public_methods.select{|i| i[/coef_at[_\d+]+$/] }
|
3393
|
+
tmp = self.dup
|
3394
|
+
str = ""
|
3395
|
+
tplt = '_0'
|
3396
|
+
first = true
|
3397
|
+
arity.times{
|
3398
|
+
first ? tplt = '1' : tplt = '_0'
|
3399
|
+
str += tplt
|
3400
|
+
first = false if first
|
3401
|
+
}
|
3402
|
+
if o.kind_of?(Symbolic_Prod) then
|
3403
|
+
sym_list = (symbolic_labels + o.symbolic_labels).uniq
|
3404
|
+
elsif o.kind_of?(Symbolic_Term) then
|
3405
|
+
if @symbolic_labels.contain(o.symbolic_label) then
|
3406
|
+
else
|
3407
|
+
end
|
3408
|
+
elsif o.kind_of?(Quotient) or o.kind_of?(Zahlen) or o.kind_of?(Counting) or o.kind_of?(Natural)
|
3409
|
+
p o.to_Q
|
3410
|
+
str = ""
|
3411
|
+
tplt = '_0'
|
3412
|
+
first = true
|
3413
|
+
arity.times{
|
3414
|
+
first ? tplt = '0' : tplt = '_0'
|
3415
|
+
str += tplt
|
3416
|
+
first = false
|
3417
|
+
}
|
3418
|
+
@exponents.has_key?(str) ? @exponents[str].to_Q += o.to_Q : tmp.add_exponent_accessor(str) ; @exponents[str] = o.to_Q
|
3419
|
+
tmp.orig_statement += " + #{@exponents[str]}"
|
3420
|
+
end
|
3421
|
+
tmp
|
3422
|
+
end
|
3423
|
+
def *(o)
|
3424
|
+
|
3425
|
+
end
|
3426
|
+
def -(o)
|
3427
|
+
|
3428
|
+
end
|
3429
|
+
def /(o)
|
3430
|
+
|
3431
|
+
end
|
3432
|
+
def to_statement
|
3433
|
+
tmp = ''
|
3434
|
+
first = true
|
3435
|
+
exponent_sorted_list.reverse.each{|a|
|
3436
|
+
a0 = instance_eval("coef_at_#{a}")
|
3437
|
+
a0 = instance_eval(a0) if a0.kind_of?(String)
|
3438
|
+
if a0<0 then
|
3439
|
+
first ? tmp += "-" : tmp += " - "
|
3440
|
+
if a == '0' or a=='1' then
|
3441
|
+
a=='1' ? tmp += (Quotient(-1,1)*a0).to_s + @symbolic_label.to_s : tmp += (Quotient(-1,1)*a0).to_s
|
3442
|
+
else
|
3443
|
+
tmp += (Quotient(-1,1)*a0).to_s + @symbolic_label.to_s + @@powersym.to_s.gsub('\\','') + a.to_s
|
3444
|
+
end
|
3445
|
+
else
|
3446
|
+
tmp += " + " unless first
|
3447
|
+
if a == '0' or a=='1' then
|
3448
|
+
a=='1' ? tmp += a0.to_s + @symbolic_label.to_s : tmp += a0.to_s
|
3449
|
+
else
|
3450
|
+
tmp += a0.to_s + @symbolic_label.to_s + @@powersym.to_s.gsub('\\','') + a.to_s
|
3451
|
+
end
|
3452
|
+
end
|
3453
|
+
first = false
|
3454
|
+
}
|
3455
|
+
tmp
|
3456
|
+
end
|
3457
|
+
def to_full_statement
|
3458
|
+
tmp = ''
|
3459
|
+
first = true
|
3460
|
+
exponent_sorted_list.reverse.each{|a|
|
3461
|
+
a0 = instance_eval("coef_at_#{a}")
|
3462
|
+
a0 = instance_eval(a0) if a0.kind_of?(String)
|
3463
|
+
if a0<0 then
|
3464
|
+
first ? tmp += "-" : tmp += " - "
|
3465
|
+
if a == '0' or a=='1' then
|
3466
|
+
a=='1' ? tmp += (Quotient(-1,1)*a0).to_s + @symbolic_label.to_s : tmp += (Quotient(-1,1)*a0).to_s
|
3467
|
+
else
|
3468
|
+
tmp += (Quotient(-1,1)*a0).to_s + @symbolic_label.to_s + @@powersym.to_s.gsub('\\','') + a.to_s
|
3469
|
+
end
|
3470
|
+
else
|
3471
|
+
tmp += " + " unless first
|
3472
|
+
if a == '0' or a=='1' then
|
3473
|
+
a=='1' ? tmp += a0.to_s + @symbolic_label.to_s : tmp += a0.to_s
|
3474
|
+
else
|
3475
|
+
tmp += a0.to_s + @symbolic_label.to_s + @@powersym.to_s.gsub('\\','') + a.to_s
|
3476
|
+
end
|
3477
|
+
end
|
3478
|
+
first = false
|
3479
|
+
}
|
3480
|
+
tmp
|
3481
|
+
end
|
3482
|
+
def coerce(o)
|
3483
|
+
[self, o]
|
3484
|
+
end
|
3485
|
+
def to_s
|
3486
|
+
to_full_statement
|
3487
|
+
end
|
3488
|
+
# def inspect
|
3489
|
+
# "Symbolic_Prod(#{@symbolic_labels},#{@orig_statment})"
|
3490
|
+
# end
|
3491
|
+
def cannonical_term_sorted_list
|
3492
|
+
cannonical_terms = {}
|
3493
|
+
complete_terms = {}
|
3494
|
+
st1 = ""
|
3495
|
+
st2 = ""
|
3496
|
+
st3 = ""
|
3497
|
+
str2 = false
|
3498
|
+
exponent_sorted_list.each{|a|
|
3499
|
+
tmp = a.split('_')
|
3500
|
+
first = true
|
3501
|
+
symbolic_labels.each_index{|i|
|
3502
|
+
if tmp.at(i) == '0' then
|
3503
|
+
str2 = true
|
3504
|
+
first ? st2 += "1" : st2 += ".1"
|
3505
|
+
st3 = "1"
|
3506
|
+
elsif tmp.at(i) == '1' then
|
3507
|
+
str2 = true
|
3508
|
+
first ? st2 += "#{symbolic_labels.at(i)}" : st2 += ".#{symbolic_labels.at(i)}"
|
3509
|
+
end
|
3510
|
+
(first ? st2 += "#{symbolic_labels.at(i)}**#{tmp.at(i)}" : st1 += ".#{symbolic_labels.at(i)}**#{tmp.at(i)}") unless str2
|
3511
|
+
str2 = false
|
3512
|
+
first ? st1 += "#{symbolic_labels.at(i)}**#{tmp.at(i)}" : st1 += ".#{symbolic_labels.at(i)}**#{tmp.at(i)}"
|
3513
|
+
first = false
|
3514
|
+
}
|
3515
|
+
cannonical_terms[st1] = a
|
3516
|
+
complete_terms[st2.gsub('.1','')] = a
|
3517
|
+
st1 = ""
|
3518
|
+
st2 = ""
|
3519
|
+
st3 = ""
|
3520
|
+
}
|
3521
|
+
complete_terms.merge!(cannonical_terms)
|
3522
|
+
complete_terms
|
3523
|
+
end
|
3524
|
+
end
|
3525
|
+
class Symbolic_statment
|
3526
|
+
def initialize
|
3527
|
+
@symbolic_product = nil
|
3528
|
+
@symbolic_terms = []
|
3529
|
+
@constants =[]
|
3530
|
+
end
|
2872
3531
|
end
|
2873
3532
|
class Matrix
|
2874
3533
|
include SGML
|
@@ -3009,7 +3668,7 @@ attr_accessor :msize, :nsize
|
|
3009
3668
|
end
|
3010
3669
|
return a
|
3011
3670
|
end
|
3012
|
-
def -(nm)
|
3671
|
+
def -(nm)
|
3013
3672
|
a = ""
|
3014
3673
|
if not(nm.is_tr? or @tr) then
|
3015
3674
|
if nm.msize == @msize and nm.nsize == @nsize then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: M500
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mark ingram
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: M500 contains easy to use classes that model modern mathematical concepts
|
14
14
|
email:
|
15
15
|
- m.ingram@computer.org
|
16
16
|
executables: []
|
@@ -19,7 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- lib/M500_containers.rb
|
21
21
|
- lib/m500.rb
|
22
|
-
homepage:
|
22
|
+
homepage: https://sites.google.com/site/m500numbers/
|
23
23
|
licenses:
|
24
24
|
- Ruby
|
25
25
|
metadata: {}
|