[fricas-devel] [PATCH] cleanup "*" in MRING

2019-07-23 Thread oldk1331
The local function "sortAndAdd" is almost the same as
"construct", but less efficient: it creates new "Term"
instead of using existing ones.

Also, the usage of "+" in "*" can also be omitted:
we can use the newly added "concat!" and pass the whole
list to "construct!".

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAGBJN92wyNrqgAzZbPkR4qPzs8L5dgTHXPZWJtG0DQ34Nxysbw%40mail.gmail.com.
diff --git a/src/algebra/mring.spad b/src/algebra/mring.spad
index 930f7321..4092362c 100644
--- a/src/algebra/mring.spad
+++ b/src/algebra/mring.spad
@@ -229,8 +229,8 @@ MonoidRing(R : Ring, M : Monoid) : MonoidRingCategory(R, M) == MRdefinition wher
 
 termless(t1:Term, t2:Term):Boolean == smaller?(t1.k, t2.k)
 
-construct(x : List Term) : % ==
-xs : List Term := sort(termless, x)
+construct!(x : List Term) : % ==
+xs : List Term := sort!(termless, x)
 res : List Term := empty()
 -- find duplicates
 while not empty? xs repeat
@@ -246,6 +246,8 @@ MonoidRing(R : Ring, M : Monoid) : MonoidRingCategory(R, M) == MRdefinition wher
 res := cons (t1, res)
 res
 
+construct(x : List Term) : % == construct! copy x
+
 if R has CommutativeRing then
 f : M -> R
 x : %
@@ -302,42 +304,16 @@ MonoidRing(R : Ring, M : Monoid) : MonoidRingCategory(R, M) == MRdefinition wher
   for ta in reverse a]
 else -- M hasn't OrderedMonoid
 
--- we cannot assume that mutiplying an ordered list of
+-- we cannot assume that multiplying an ordered list of
 -- monoid elements by a single element respects the ordering:
--- we have to order and to collect equal terms
-  ge : (Term, Term) -> Boolean
-  ge(s, t) == not smaller? (s.Mn, t.Mn)
-
-  sortAndAdd : List Term -> List Term
-  sortAndAdd(liTe) ==  -- assume liTe not empty
-liTe := sort(ge, liTe)
-m : M :=  (first liTe).Mn
-cf : R := (first liTe).Cf
-res : List Term := []
-for te in rest liTe repeat
-  if m = te.Mn then
-cf := cf + te.Cf
-  else
-if not zero? cf then res := cons([m, cf]$Term, res)
-m := te.Mn
-cf := te.Cf
-if not zero? cf then res := cons([m, cf]$Term, res)
-reverse res
-
+-- we have to order and to collect equal terms using 'construct',
+-- and it can also handle the ZeroDivisors case.
 
-  if R has noZeroDivisors then
 a : % * b : % ==
   zero? a => a
-  zero? b => b  -- avoid calling sortAndAdd with []
-  +/[sortAndAdd [[ta.Mn*tb.Mn, ta.Cf*tb.Cf]$Term
-for tb in b ] for ta in reverse a]
-  else
-a : % * b : % ==
-  zero? a => a
-  zero? b => b  -- avoid calling sortAndAdd with []
-  +/[sortAndAdd [[ta.Mn*tb.Mn, r]$Term
-for tb in b | not zero?(r := ta.Cf*tb.Cf)]
-  for ta in reverse a]
+  zero? b => b
+  construct! concat! [[[ta.Mn*tb.Mn, ta.Cf*tb.Cf]$Term
+for tb in b] for ta in a]
 
 
 else -- M hasn't OrderedSet


[fricas-devel] [PATCH] add 'concat! : List % -> %' in URAGG

2019-07-23 Thread oldk1331
We already have 'concat : List % -> %', and it's equally
useful to have its destructive counterpart, for long lists,
this version can save many many copies.

Although 'concat : List % -> %' is exported in LNAGG,
I believe that the proper place for
'concat/concat! : List % -> %' should be in URAGG.

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAGBJN93_s5Czp2q4htm45FuawwDxZLrWRtVJb6k--xJ0%2BRCX9g%40mail.gmail.com.
diff --git a/src/algebra/aggcat.spad b/src/algebra/aggcat.spad
index 23a785db..73678bf7 100644
--- a/src/algebra/aggcat.spad
+++ b/src/algebra/aggcat.spad
@@ -1381,6 +1381,12 @@ UnaryRecursiveAggregate(S : Type) : Category == Join(RecursiveAggregate S,
   concat! : (%, S) -> %
 ++ concat!(u, x) destructively adds element x to the end of u.
 ++ Note: \spad{concat!(a, x) = concat!(a, [x])}.
+  concat! : List % -> %
+++ concat!(lu), where \spad{lu} is a list of aggregates
+++ \spad{[a, b, ..., c]}, returns a single aggregate consisting
+++ of the elements of \spad{a} followed by those of \spad{b}
+++ followed ... by the elements of \spad{c}.  This function may
+++ destructively modify the aggregates in \spad{lu}.
   cycleSplit! : % -> %
 ++ cycleSplit!(u) splits the aggregate by dropping off the cycle.
 ++ The value returned is the cycle entry, or empty() if none exists.
@@ -1635,6 +1641,15 @@ UnaryRecursiveAggregate(S : Type) : Category == Join(RecursiveAggregate S,
   setelt!(x,  "rest", a) == setrest!(x, a)
   concat(x : %, y : %) == concat!(copy x, y)
 
+  concat!(lu : List %) ==
+  empty? lu => empty()
+  res := first lu
+  t := tail res
+  for u in rest lu repeat
+  setrest!(t, u)
+  t := tail t
+  res
+
   -- The qxxx variants are for speed.  If we do not care about
   -- speed the regular ones will do.
 


[fricas-devel] [PATCH] optimize "+" in MRING when Comparable

2019-07-23 Thread oldk1331
Clearly, the usage of using "concat!" to add an element to
the end of a list is extremely inefficient.

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAGBJN91TUUrLy52msTZXCAhzB71p5godbow49hwogTyx1xK2RQ%40mail.gmail.com.
diff --git a/src/algebra/mring.spad b/src/algebra/mring.spad
index 4092362c..8d76157e 100644
--- a/src/algebra/mring.spad
+++ b/src/algebra/mring.spad
@@ -273,13 +273,13 @@ MonoidRing(R : Ring, M : Monoid) : MonoidRingCategory(R, M) == MRdefinition wher
   ta:Term := first repa; tb:Term := first repb
   ra:Rep := rest repa;  rb:Rep := rest repb
   res :=
-smaller?(tb.Mn, ta.Mn)  => (repa := ra; concat!(res, ta))
-smaller?(ta.Mn, tb.Mn) => (repb := rb; concat!(res, tb))
+smaller?(tb.Mn, ta.Mn) => (repa := ra; concat(ta, res))
+smaller?(ta.Mn, tb.Mn) => (repb := rb; concat(tb, res))
 repa := ra; repb := rb
 not zero?(r := ta.Cf + tb.Cf) =>
-concat!(res, [ta.Mn, r])
+concat([ta.Mn, r], res)
 res
-per concat!(res, concat(repa, repb))
+per concat!(reverse! res, if empty? repa then repb else repa)
 
 coefficient(a, m) ==
 for t in a repeat


Re: [fricas-devel] Wayland and no X

2019-07-23 Thread oldk1331
HyperDoc can not work in pure Wayland.

I just tried with "weston", when launching fricas, it shows

(HyperDoc) Cannot connect to the X11 server!

Because the "DISPLAY" environment variable is not defined;
of course the command line part of fricas works as usual.

On 7/23/19 1:31 PM, Ralf Hemmecke wrote:
> Does someone know whether Wayland without an X server is problematic for
> FriCAS?
> 
> Ralf
> 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/886de96c-92e9-d9ae-4de9-6a27375760eb%40gmail.com.