Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,62 @@
|
|||
define: #Polynomial &parents: {Comparable} &slots: {#coefficients -> ExtensibleArray new}.
|
||||
|
||||
p@(Polynomial traits) new &capacity: n
|
||||
[
|
||||
p cloneSettingSlots: #(coefficients) to: {p coefficients new &capacity: n}
|
||||
].
|
||||
|
||||
p@(Polynomial traits) newFrom: seq@(Sequence traits)
|
||||
[
|
||||
p clone `>> [coefficients: (seq as: p coefficients). normalize. ]
|
||||
].
|
||||
|
||||
p@(Polynomial traits) copy
|
||||
[
|
||||
p cloneSettingSlots: #(coefficients) to: {p coefficients copy}
|
||||
].
|
||||
|
||||
p1@(Polynomial traits) >= p2@(Polynomial traits)
|
||||
[p1 degree >= p2 degree].
|
||||
|
||||
p@(Polynomial traits) degree
|
||||
[p coefficients indexOfLastSatisfying: [| :n | n isZero not]].
|
||||
|
||||
p@(Polynomial traits) normalize
|
||||
[
|
||||
[p degree isPositive /\ [p coefficients last isZero]]
|
||||
whileTrue: [p coefficients removeLast]
|
||||
].
|
||||
|
||||
p@(Polynomial traits) * n@(Number traits)
|
||||
[
|
||||
p newFrom: (p coefficients collect: [| :x | x * n])
|
||||
].
|
||||
|
||||
p@(Polynomial traits) / n@(Number traits)
|
||||
[
|
||||
p newFrom: (p coefficients collect: [| :x | x / n])
|
||||
].
|
||||
|
||||
p1@(Polynomial traits) minusCoefficients: p2@(Polynomial traits)
|
||||
[
|
||||
p1 newFrom: (p1 coefficients with: p2 coefficients collect: #- `er)
|
||||
].
|
||||
|
||||
p@(Polynomial traits) / denom@(Polynomial traits)
|
||||
[
|
||||
p >= denom
|
||||
ifTrue:
|
||||
[| n q |
|
||||
n: p copy.
|
||||
q: p new.
|
||||
[n >= denom]
|
||||
whileTrue:
|
||||
[| piv |
|
||||
piv: p coefficients last / denom coefficients last.
|
||||
q coefficients add: piv.
|
||||
n: (n minusCoefficients: denom * piv).
|
||||
n normalize].
|
||||
n coefficients isEmpty ifTrue: [n coefficients add: 0].
|
||||
{q. n}]
|
||||
ifFalse: [{p newFrom: #(0). p copy}]
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue