0
$\begingroup$

My objective is to define an opeartor op such that for every rational function $f(c)$ of a fixed symbol c, $op(f(c) x)=f(c) op(x)$. What is a good way to implement this?

$\endgroup$
1
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Commented Jul 25 at 15:27

1 Answer 1

0
$\begingroup$

An alternative solution using UpValues, and defining the operator as linear:

ClearAll[op, x] 
SetAttributes[op, HoldAll] 
(* Define the linearity property using UpValues *) 
op /: op[a_ + b_] := op[a] +op[b] 
(* Define the commuting property using UpValues *) 
op /: op[f_*expx_] /; FreeQ[expx, c] := f*op[expx]

Test:

op[(c^2 + 3)/(c + 1)*x^2]
(*output*)
((3+c^2)*op[x^2])/(1+c)

and for linearity:

op[(c^2 + 3)/(c + 1)*x^2+ c x] 
(* output *)
c*op[x]+((3+c^2)*op[x^2])/(1+c)
$\endgroup$
2
  • $\begingroup$ Thank you for your answer. It appears that x is declared as a special variable instead of c. Is it possible to go the other way around? $\endgroup$
    – user475525
    Commented Jul 28 at 18:51
  • $\begingroup$ Sure!, I edited the code op /: op[f_*expx_] /; FreeQ[expx, c] := f*op[expx], so that the special variable declared is c. $\endgroup$
    – Ferca
    Commented Jul 28 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.