2

How do I get powers of a trig function in Math.net?

Expr x = Expr.Variable("x");
Expr g = (2 * x).Sinh().Pow(2);

g.ToString() gives the output: (sinh(2*x))^2

What I want is sinh^2(2*x)

How do I do that?

Edit:

As per Christoph's comment below this can be done in v0.21.0 which implements Expr.ToCustomString(true)

Paul Matthews
  • 2,164
  • 5
  • 20
  • 29

1 Answers1

2

It does not currently support this notation. However, I see three options:

  1. We define powers of trigonometric functions as new functions, or make them parametric.
    This is something I do not wish to do.
  2. We introduce un-applied functions as first class concept, which can be manipulated in such ways.
    This is something we likely want to explore at some point, but this is a larger topic, and likely overkill for what you need.
  3. Extend our visual expressions to support positive integer powers of functions.
    This is something which we could implement.

Option 3 would save one set of parentheses in such expressions, which would lead to a more compact rendering, especially also for the LaTeX formatter where the result would be more readable. When building a visual expression from an expression, it would automatically pull positive integer powers to the applied function.

To my understanding your concern is only about how it is printed, so it seems to me this would solve your problem as well?

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34
  • I thought maybe an additional method overload like 'public Expr Sinh(uint Power)' might be the way but it might be too similar to your Option 1 maybe? – Paul Matthews Apr 28 '20 at 23:47
  • Option 3 seems the most logical but would that behavior be provided as an option or would it be hardcoded straight into the 'ToString()' method? – Paul Matthews Apr 28 '20 at 23:51
  • FYI, I've just published v0.21.0 which implements option 3 and returns the more compact notation e.g. when using `Expr.ToCustomString(true)`. – Christoph Rüegg May 02 '20 at 14:34