Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

HI Folks,

I have an expression such as

   foo := t0 A + t2 B + t13 C;

and I like to easily replace each of the t* scalars with 1. So my target result is

   foo := A + B + C;

Using something like

   substitute (foo, $t? -> 1$)

fails because it replaces all objects with 1, not just the scalars. Is there a simple way to do this properly for any expression like the above, no matter how many terms?

Cheers, Leo

in General questions by (1.6k points)

1 Answer

+1 vote
 
Best answer

Try

foo := t0 A + t2 B + t13 C;
substitute(foo, $t? | \regex{t?}{"t[0-9]*"} -> 1$);

The structure of this replacement rule is described in the reference guide chapter on patterns.

by (76.4k points)
selected by

Hi Kasper,

Many thanks for the quick reply. That page has all the details that I need, many thanks. I have a vague recollection that I've seen this page before but I can't seem to find it by navigating from the cadabra.science web page.

Cheers, Leo

It always was in the old reference guide, and I put it on the web under 'manual' this morning

I just refreshed my browser, now I can see the page. Thanks.

Sorry, help, not manual. That by itself shows that this needs fixing...

...