What does f[a] mean in mathematica?

  • Context: Mathematica 
  • Thread starter Thread starter tgt
  • Start date Start date
  • Tags Tags
    Mathematica Mean
Click For Summary

Discussion Overview

The discussion revolves around the interpretation of function notation in Mathematica, specifically the meaning of expressions like f[a][b] and how to index functions. Participants explore various ways to define and apply functions, as well as how to create indexed functions.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Some participants explain that f[a][b] means applying a to the function f, and then applying b to the resulting function.
  • Examples are provided to illustrate how f[a] can produce a function that can then be applied to another argument, such as f[3][2] yielding 5.
  • There is a question about whether f[a][b] is equivalent to f[a, b], indicating a potential misunderstanding of function application.
  • Participants discuss the concept of indexing functions, with one suggesting the use of subscripts to create indexed functions like Subscript[g, 1][x], Subscript[g, 2][x], and Subscript[g, 3][x].
  • Another participant questions the choice of the letter 'g' for the subscripted function, leading to a discussion about naming conventions in function definitions.
  • There is mention of using Control + hyphen to create subscripted functions, which may not be universally known.

Areas of Agreement / Disagreement

Participants express differing views on the equivalence of f[a][b] and f[a, b]. The discussion on indexing functions also reveals varying approaches and preferences, with no consensus reached on the best method.

Contextual Notes

Some participants' definitions and examples depend on specific interpretations of function application and indexing, which may not be universally applicable. The discussion does not resolve the ambiguity surrounding the notation.

Who May Find This Useful

This discussion may be useful for Mathematica users seeking to understand function application and indexing, as well as those interested in naming conventions for functions in programming contexts.

tgt
Messages
519
Reaction score
2
What does f[a] mean in mathematica?

What does f[a] mean in mathematica?
 
Physics news on Phys.org


It applies a to the function f, and then b to the resulting function.
For example, you could do something like
f[a_] := (a + #)&
then
f[3] would give the function (3 + #)& and applying that to 2 would produce 5.

In more extended notation,
f[a_] := Function[y, a + y]
f[3] => Function[y, 3 + y]
f[3][2] = Function[y, 3 + y][2] = 3 + 2 = 5

Or, equivalently
f[a_, b_] := a + b
f[3, 2]
 


So F[a]=F[a,b]?

What happens if I'd like F[x] to be indexed by i=1,2,3,...

how to do that?
 


No, F[a] is F[a] applied to b, which is (f applied to a) applied to b.
It depends on what F is.

How do you mean "indexed" by i = 1, 2, 3? You would like three functions F[x], G[x], H[x] but call them Fi[x] (i = 1, 2, 3) instead? Or ...
 


CompuChip said:
How do you mean "indexed" by i = 1, 2, 3? You would like three functions F[x], G[x], H[x] but call them Fi[x] (i = 1, 2, 3) instead?


That's right. How to do it?
 
Last edited:


So the simplest form is
Code:
Subscript[g, 1][x_] := x
Subscript[g, 2][x_] := x^2
Subscript[g, 3][x_] := Sin[x]

Plot[{Subscript[g, 1][x], Subscript[g, 2][x], 
  Subscript[g, 3][x]}, {x, -1, 1}]
where you can type g2 using Control + hyphen (-).

An alternative would be
Code:
Subscript[f, i_?(Function[IntegerQ[#] && 1 <= # <= 3])][x_] := 
 Which[i == 1, F[x], i == 2, G[x], i == 3, H[x], True, "This should not occur!"]
Then you can call fi[x] (type with Control + - (hyphen)) for i = 1, 2, 3 and it will call F[x], G[x] or H[x], respectively. The complicated-looking pattern matching is to have it return just fi[x] if i is not 1, 2 or 3.
 


CompuChip said:
So the simplest form is
Code:
Subscript[g, 1][x_] := x
Subscript[g, 2][x_] := x^2
Subscript[g, 3][x_] := Sin[x]

[/QUOTE]

why g?
 


Why not?
I had already used f in the other example. You can call it f if you want, or Apples, or GqoFKdsJF or LoremIpsumDolorem. Just don't use any reserved names (E, N, Sin, ...) or - preferably - things you already defined.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
8
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K