cadabra2 icon indicating copy to clipboard operation
cadabra2 copied to clipboard

Sum of single element substitution rules looks wrong to me

Open leo-brewin opened this issue 5 years ago • 4 comments

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.

leo-brewin avatar Sep 14 '19 12:09 leo-brewin

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.

kpeeters avatar Sep 23 '19 21:09 kpeeters

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).

leo-brewin avatar Sep 24 '19 10:09 leo-brewin

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

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

or

foo1:= \comma{A}

kpeeters avatar Jun 27 '20 22:06 kpeeters

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 [email protected] 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.

leo-brewin avatar Jul 03 '20 09:07 leo-brewin