@@ -133,10 +133,14 @@ function (a::FreeAssociativeAlgebra{T})(b::T) where T
133
133
return FreeAssociativeAlgebraElem {T} (a, T[b], [Int[]], 1 )
134
134
end
135
135
136
- function (a:: FreeAssociativeAlgebra{T} )(b:: Integer ) where T
137
- iszero (b) && return zero (a)
136
+ function (a:: FreeAssociativeAlgebra{T} )(b:: Union{Integer, Rational, AbstractFloat} ) where T
138
137
R = base_ring (a)
139
- return FreeAssociativeAlgebraElem {T} (a, T[R (b)], [Int[]], 1 )
138
+ return a (R (b))
139
+ end
140
+
141
+ function (a:: FreeAssociativeAlgebra{T} )(b:: T ) where {T <: Union{Integer, Rational, AbstractFloat} }
142
+ iszero (b) && return zero (a)
143
+ return FreeAssociativeAlgebraElem {T} (a, T[b], [Int[]], 1 )
140
144
end
141
145
142
146
function (a:: FreeAssociativeAlgebra{T} )(b:: FreeAssociativeAlgebraElem{T} ) where T <: RingElement
633
637
#
634
638
# ##############################################################################
635
639
640
+ function * (a:: FreeAssociativeAlgebraElem , n:: Union{Integer, Rational, AbstractFloat} )
641
+ z = zero (a)
642
+ return mul! (z, a, n)
643
+ end
644
+
645
+ function * (a:: FreeAssociativeAlgebraElem{T} , n:: T ) where {T <: RingElem }
646
+ z = zero (a)
647
+ return mul! (z, a, n)
648
+ end
649
+
650
+ * (n:: Union{Integer, Rational, AbstractFloat} , a:: FreeAssociativeAlgebraElem ) = a* n
651
+
652
+ * (n:: T , a:: FreeAssociativeAlgebraElem{T} ) where {T <: RingElem } = a* n
653
+
636
654
function divexact (
637
655
a:: FreeAssociativeAlgebraElem{T} ,
638
656
b:: Integer ;
@@ -786,6 +804,33 @@ function sub!(z::FreeAssociativeAlgebraElem{T}, a::FreeAssociativeAlgebraElem{T}
786
804
return z
787
805
end
788
806
807
+ function mul! (a:: FreeAssociativeAlgebraElem{T} , n:: Union{Integer, Rational, AbstractFloat, T} ) where T <: RingElement
808
+ for i in 1 : length (a)
809
+ a. coeffs[i] = mul! (a. coeffs[i], n)
810
+ end
811
+ return a
812
+ end
813
+
814
+ function mul! (z:: FreeAssociativeAlgebraElem{T} , a:: FreeAssociativeAlgebraElem{T} , n:: Union{Integer, Rational, AbstractFloat, T} ) where T <: RingElement
815
+ if z === a
816
+ return mul! (a, n)
817
+ end
818
+ fit! (z, length (a))
819
+ j = 1
820
+ for i = 1 : length (a)
821
+ if isassigned (z. coeffs, j)
822
+ z. coeffs[j] = mul! (z. coeffs[j], a. coeffs[i], n)
823
+ else
824
+ z. coeffs[j] = a. coeffs[i] * n
825
+ end
826
+ if ! iszero (z. coeffs[j])
827
+ z. exps[j] = a. exps[i]
828
+ j += 1
829
+ end
830
+ end
831
+ z. length = j - 1
832
+ return z
833
+ end
789
834
790
835
# ###############################################################################
791
836
#
0 commit comments