Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to be able to define functions (at least simple ones that Mathematica can otherwise understand) using TraditionalForm; but this seems to require the use of an underscore.

For example, I'd like to be able to have something like

$$f(x) = x^2$$

correspond to

f[x_]:=x^2

but Mathematica seems to require

$$f(x\text{_}) = x^2$$

which goes a long way towards defeating the whole purpose.

Is there, perhaps, a way to define some formatting that's less obtrusive, and more "conventionally notational" than the underscore that could correspond to the TraditionalForm underscore (and thus resolve any ambiguities)?

share|improve this question
2  
Even if it is possible, it's probably not a very good idea to indulge in code gymnastics just to be able to make your code look like a latex document. At some point it will break and you'll be left wondering what went wrong. I'd strongly urge keeping code in StandardForm and use TraditionalForm only for output formatting or in labels/text, etc. Besides, how will you differentiate the $f(x)$ in f[x_] = 2 and f[x] = 2? Both are valid definitions, but your usage above makes it ambiguous. (note, I didn't down vote). –  rm -rf Nov 12 '12 at 1:01
1  
@rm-rf: If that were in fact my goal, I'd be using a different tool. The goal is simply to not have to repeat simple equations that are more readable as TraditionalForm in the cases, like the one above, where the intent is clear. –  raxacoricofallapatorius Nov 12 '12 at 1:05
    
No, the intent is not clear — see the example in my above comment (I was editing it when you posted yours). –  rm -rf Nov 12 '12 at 1:07
1  
There is another ambiguity: How to distinguish between "set f(x) = x^2" and "is f(x) = x^2 ?". To overcome these ambiguities, some good heuristics would be needed (just like when trying to read traditional math notation). And they would be wrong sometimes. –  Andrew Moylan Nov 12 '12 at 1:26
1  
@raxacoricofallapatorius what I do is I typeset in normal form my input and when needed I select the input cell and Convert to Traditionnal Form from the Cell Menu –  chris Nov 12 '12 at 7:28
show 2 more comments

1 Answer

up vote 1 down vote accepted

All the comments notwithstanding, I think there may be an acceptable compromise between notational simplicity and formal accuracy. It involves defining functions really as Function, not by patterns.

Here is an example of how that looks in TraditionalForm. It's the replacement for the standard definition a[x_]:= Sin[x], now written in a notation that you'll find in almost that same form in math texts:

a = {x} \[Function] sin(x)

(* ==> Function[{x}, Sin[x]] *)

Here, I've entered the symbol as EscfnEsc and it's displayed above as \[Function]. I'm assuming this is entered in TraditionalForm. So what you actually see in the notebook is

a = {x} ↦ sin(x) 

which (depending on your background) might be a familiar way of writing a function definition. At least you don't have to worry about how to hide or modify the underscore that would be required in the pattern based type of function definition.

The function is of course invoked the same way you always do it. In TraditionalForm again, that would be

a(π/2)

(* ==> 1 *)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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