I have defined two variables a and b:

SetAttributes[a, Constant];
SetAtributes[b, Constant];

I have defined a function c as follows:

c = a*b;

But this does not inherit the attribute of being constant:

Out: {}

How can I make Mathematica understands that c is a new constant and inherits the attributes of a and b ?

  • $\begingroup$ I want to define a new constant. @infinitezero $\endgroup$
    – Alex97
    Nov 28 '21 at 13:29
  • $\begingroup$ The question is, should attributes on symbols be combined/merged when one adds them or multiply or subtract them from each others? How about c=Exp[a]*b or infinity number of other combinations. It is not clear what happens. Help does not say that attributes get inherited or migrated after some operation. And which attributes should be inherited? All? some? This can get complicated very quickly. I think the semantics is not clear here. May be there is a way to force this by adding special code. $\endgroup$
    – Nasser
    Nov 28 '21 at 13:29
  • 1
    $\begingroup$ I mean in your function you defined, you can add special code to obtain the Attributes of the symbols, check if both have Constant and then use the SetAttribute to force Constant attribute on the new symbol you want. I mean do it case by case basis. Something along these lines since it is not done automatically it looks like it. Notice that Constant in Mathematica does not mean you can't change the value of the variable. (as constant means in other languages), It just means the derivative w.r.t to anything is zero. I never use it myself. I never find a use for it. $\endgroup$
    – Nasser
    Nov 28 '21 at 13:42
  • 1
    $\begingroup$ @Nasser Indeed, Constant is only meaningful for symbols that don't have numeric values. $\endgroup$
    – John Doty
    Nov 28 '21 at 14:28
  • 3
    $\begingroup$ c evaluates to a*b, and c disappears from an expression. The attributes of c seem unimportant. Can you give a use-case in which the attributes are important to what you are doing? For instance Dt[Exp[c*x]] first becomes Dt[Exp[a*b*x]] and then Dt is evaluated (after c has disappeared from the expression). $\endgroup$
    – Michael E2
    Nov 28 '21 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.