@@ -503,7 +503,7 @@ function show_call(io, f, args)
503503 if binary
504504 for (i, t) in enumerate (args)
505505 i != 1 && print (io, " $fname " )
506- print_arg (io, t)
506+ print_arg (io, t, paren = true )
507507 end
508508 else
509509 if f isa Sym
@@ -513,7 +513,7 @@ function show_call(io, f, args)
513513 end
514514 print (io, " (" )
515515 for i= 1 : length (args)
516- print (IOContext (io, :paren => false ) , args[i])
516+ print (io , args[i])
517517 i != length (args) && print (io, " , " )
518518 end
519519 print (io, " )" )
@@ -775,9 +775,21 @@ mul_t(a) = promote_symtype(*, symtype(a))
775775 a. coeff * b. coeff,
776776 _merge (+ , a. dict, b. dict, filter= _iszero))
777777
778- * (a:: Number , b:: SN ) = iszero (a) ? a : isone (a) ? b : Mul (mul_t (a, b), makemul (a, b)... )
778+ function * (a:: Number , b:: SN )
779+ if iszero (a)
780+ a
781+ elseif isone (a)
782+ b
783+ elseif b isa Add
784+ # 2(a+b) -> 2a + 2b
785+ T = promote_symtype (+ , typeof (a), symtype (b))
786+ Add (T, b. coeff * a, Dict (k=> v* a for (k, v) in b. dict))
787+ else
788+ Mul (mul_t (a, b), makemul (a, b)... )
789+ end
790+ end
779791
780- * (b :: SN , a :: Number ) = iszero (a) ? a : isone (a) ? b : Mul ( mul_t (a, b), makemul (a, b) ... )
792+ * (a :: SN , b :: Number ) = b * a
781793
782794/ (a:: Union{SN,Number} , b:: SN ) = a * b^ (- 1 )
783795
853865
854866* (a:: Pow , b:: Mul ) = b * a
855867
856- _merge (f, d, others... ; filter= x-> false ) = _merge! (f, copy (d), others... ; filter= filter)
868+ function copy_similar (d, others)
869+ K = promote_type (keytype (d), keytype .(others)... )
870+ V = promote_type (valtype (d), valtype .(others)... )
871+ Dict {K, V} (d)
872+ end
873+
874+ _merge (f, d, others... ; filter= x-> false ) = _merge! (f, copy_similar (d, others), others... ; filter= filter)
857875function _merge! (f, d, others... ; filter= x-> false )
858876 acc = d
859877 for other in others
0 commit comments