kpeeters / cadabra2

A field-theory motivated approach to computer algebra.
https://cadabra.science/
GNU General Public License v3.0
215 stars 37 forks source link

Sum of single element substitution rules looks wrong to me #163

Open leo-brewin opened 4 years ago

leo-brewin commented 4 years ago

Here is a short Cadabra fragment

foo1 := {A->B}.
foo2 := {A->B,B->C}.

bah1 := {D->E}.
bah2 := {D->E,E->F}.

print(foo1+bah1)
print(foo1+bah2)
print(foo2+bah1)
print(foo2+bah2)

print(foo1 + Ex(",,") + bah1)

This produces the following output

A -> B + D -> E
{A -> B, D -> E, E -> F}
{A -> B, B -> C, D -> E}
{A -> B, B -> C, D -> E, E -> F}
{A -> B, D -> E}

The first line (a sum of two single element rule) looks wrong. I think it should look the same as the final line of output.

kpeeters commented 4 years ago

That's because, for historical reasons, it is not the curly brackets that lead to the creation of a list, but the comma. So bah1 is not a list, it is a single expression.

I could probably change this now, but it may trigger weird other problems. I'll keep the issue open.

leo-brewin commented 4 years ago

Hi Kasper, Thanks for the explanation. I think I'll avoid this problem by rewriting that section of the tutorial to not involve adding single element rules. I'll change the example to be a sum of four rules (which I can split into the sum of two lists).

kpeeters commented 4 years ago

For reference: you can generate a single-item list with

foo1 := {A->B, {}}

or

foo1:= \comma{A}
leo-brewin commented 4 years ago

HI Kasper,

My apologies for not replying sooner (I got distracted with other stuff).

Thanks for the update. Your solution is similar to what I’ve been using which was to include a trivial rule such as foo1 := {A->B, x->x} Cheers, Leo

On 24 Sep 2019, at 7:22 am, Kasper Peeters notifications@github.com wrote:

That's because, for historical reasons, it is not the curly brackets that lead to the creation of a list, but the comma. So bah1 is not a list, it is a single expression.

I could probably change this now, but it may trigger weird other problems. I'll keep the issue open.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kpeeters/cadabra2/issues/163?email_source=notifications&email_token=AA6E7NITMXLBI4UNRR32YX3QLEXPZA5CNFSM4IWW5JQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7MJ7YA#issuecomment-534290400, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6E7NKU26TRXLLKQFB3HLTQLEXPZANCNFSM4IWW5JQQ.