Implementing functions that include name and symbol

55 Views Asked by At

I need to define in Sage some functions with attributes that define

  • the name of the function
  • its mathematical/physical symbol
  • the definition of the function
  • (and those in combination)

and methods that return

  • those attributes in LaTeX format

both symbolic and with parameters input and then also

  • the result of the function on those parameters

An example is something like

>>> somefunction.name
\text{some function}
>>> somefunction.symbol
\mathrm{SF}
>>> somefunction.definition
\mathrm{SF} = 3x + y
>>> somefunction(4, 5)
17
>>> somefunction(4, 5).symbol
\mathrm{SF}\left(4, 5\right)
>>> anotherfunction.name
\text{another function}
>>> anotherfunction.symbol
\mathrm{AF}
>>> anotherfunction.definition
\mathrm{AF} = 2z
>>> anotherfunction('SF')
2(3x + y)

I suppose the way of implementing it is by defining a new class that inherits from the function Class. And perhaps the method names should have _latex appended.

Any ideas?

Thanks in advance,

Chris

1

There are 1 best solutions below

1
On

You definitely don't want to just use function if you are planning something more interesting. See if the tips for implementing new symbolic functions fits your needs (though this may be overkill). Yes, you definitely want something with a latex attribute/method.