> Your idea is good, but it's complicated for Vector because it doesn't have
> fixed length, for DirectProduct, it's simple because it's fixed length,
> a simple local variable will do.

I suggested the type List % for allocatedVectors, because of concurrent
execution of subtractIfCaan that would run on the same local variable.
OK, that's a non-issue currently, since Fricas does not allow such
parallel execution. (Or am I wrong?)

> And in the Groebner basis computation,
> it uses DirectProduct.
> 
>          tmp := 0$%

Ooops. No. If you intend to use tmp later, you shouldn't use 0, but
initialize it to a copy of 0.

I had a similar error in one of my earlier Aldor programming where
suddenly I saw that the *constant* 0 of the domain had a value that was
different from 0.

In fact, the above assignment just makes tmp pointing to the memory
location of 0$%.

>          subtractIfCan(u:%, v:%):Union(%,"failed") ==
>           for i in 1..dim repeat
>             (c := subtractIfCan(qelt(u, i)$Rep, qelt(v,i)$Rep)) case "failed" 
> =>
>                     return "failed"

Yes, that's the way it would be done with only the current
"subtractIfCan" available. But in case of failure in the last component
of the vector, one would have created a lot of Union(R, "failed")
objects where only the R part would be used in the following qsetelt!

>             qsetelt!(tmp, i, c::R)$Rep

That sounds like needless memory allocation.

I would suggest to introduce two new function canSubtract? and subtract.
(The names are, of course, open for discussion.)

CancellationAbelianMonoid() : Category == AbelianMonoid with
  --operations
  canSubtract?: (%, %) -> Boolean
    ++ canSubtract?(x, y) retruns true if that is an element z such
    ++ that \spad{z+y=x} and false otherwise.
  subtract: (%, %) -> %
    ++ subtract(x, y) retruns an element z such that \spad{z+y=x} if
    ++ such an element exists, i.e., if canSubtract?(x, y) is true.
    ++ The behaviour of that function is unspecified if no such element
    ++ exists, i.e., if canSubtract?(x, y) is false.
  subtractIfCan : (%,%) -> Union(%,"failed")
    ++ subtractIfCan(x, y) returns an element z such that \spad{z+y=x}
    ++ or "failed" if no such element exists.

In DirectProduct we could have something like

  QE(x, i) ==> qelt(x, i)$Rep
  canSubtract?(u: %, v: %): Boolean ==
    for in in 1 .. dim repeat
      if not canSubtract(QE(u, i), QE(v, i)) then return false
    true
  subtractIfCan(u: %, v: %): Union(%, "failed") ==
    canSubtract?(u, v) => subtract(u, v)::Union(%, "failed")
    "failed"
  -- Note the the following requires canSubtract(u, v) to be true.
  subtract(u: %, v: %): % ==
    w: % :=  new(dim, 0)$Vector(R)
    for in in 1 .. dim repeat
      qsetelt!(w, i, subtract(QE(u, i), QE(v,i)))$Rep
    return w

> One might expect that 'subtract' never fails. I think we should choose
> between 'subtractIf' or 'subtractCan'.

Well, I still opt for "subtract" in connection with "canSubtract?" and
"subtractIfCan".

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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to