# Questions tagged [function-construction]

For questions on writing functions (pure or using Set/SetDelayed) for any purpose, including the features that may be incorporated in those functions, such as options, patterns and conditions.

1,870 questions
Filter by
Sorted by
Tagged with
407 views

### Two identical functions give different answers

I am new to mathematica and I hope this is a simple problem. I have two identical functions that only differ by the variable names: ...
204 views

### What is the best and most efficient way to curry?

Suppose I have a function with a signature like g[expr, _?(f), {1}, Heads -> False] and I want to access it as an operator by giving the first argument last. I ...
113 views

### Fast Destructuring

This might be a XY problem. I first post my immediate question and some background below. Question: What's the fastest way to pass arguments matching ...
2k views

### Generating list of alphabet letters

I want to create a list of length n with the letters of the alphabet. For example, if n = 3, by list would be ...
5k views

### Find function inverse

I'm trying to find the inverse of a function: (30*x^2 (1 - x)^2) (* where 0<x<1 *) I tried all the following options: 1. ...
9k views

### Creating custom functions with multiple arguments

I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow. I want to define a custom function (more complicated than the usual ...
295 views

### Generating date ranges

How can I, in one line, generate all the dates with a constant day difference from one date to another? For example, if I'm interested in dates in the interval staring from 24.4.2012 till 2015 and a ...
328 views

### How to inject unevaluated list of Unique into a RuleDelayed?

I am writing a function that constructs a rule which has Unique[] in the RHS. Here is a simplified segment of code ...
481 views

### How can I create currying functions using pure function syntax?

For example how can I write In: pureFunctionSyntax[myF] /@ {7, 3} Out: {myF[7, Log[7]], myF[3, Log[3]]}
3k views

### Define a function with a function for an input

I want to create the functions $even[f]$ and $odd[f]$ which will apply the formula $even[f(x)] = \frac{f(x)+f(-x)}{2}$ and $odd[f(x)]=\frac{f(x)-f(-x)}{2}$ for an arbitrary $f$. I tried using <...
3k views

### Force function to make assumptions about its input variables in Mathematica

I'm trying to force a Mathematica function to make an assumption about its input variables. In my case, I'm trying to define a function to return the pdf of a Gaussian. But let's use a simple toy case:...
604 views

### return {} when the function is given {}

I have a function taking an array as argument and giving an output. However, sometimes my argument is {} (the empty array), then how can I get an output {} when my argument is {}? Actually, I want the ...
1k views

### Composition of functions

I have a number of rotations computed by rot = RotationTransform[theta, point], and I would like to compose them to produce one function that is the composition of ...
228 views

175 views

### How to find the position in original list ranked first by SortBy

SortBy is a wonder and convenient way to sort a list using a list of functions with which ties can be broken. ...
326 views

### How to create a version of FixedPointList for asymptotically periodic functions?

I need to efficiently generate a bunch of bifurcation diagrams. A simple familiar example illustrates the efficiency problems I'm running into: ...
194 views

### Possible to scope an anonymous function within Module?

This is my first question. I'm fairly new to Mathematica and completely new to SE, so I apologize if this question is trivial. I'm working on a problem that requires a function to be redefined ...
173 views

### Automatic Piecewise Approximation

I would like to create the following function: It should approximate a function func[x] by piecewise polynomial interpolations, splitting the approximate function ...
311 views

### FullDefinition and Module local variable

I have a question about FullDefinition and how it interacts with the local variables of Module. I've created a few functions (...
184 views

### How does a construct like i : func[arg_] := i = an expression using arg work? [duplicate]

Occasionally I run into a Pattern that looks like i:func[arg_]:=i= an expression using arg I have two questions on this: Can ...
162 views

### Defining a custom Plus for a specific class of arguments

I'm trying to develop an domain-specific language with Mathematica. I want to define a customized behavior for the Plus function when applied to my data. For ...
170 views

### Is it possible to write a function immune to symbol redefinitions in any Block surrounding its invocation?

Normally, semantics of symbols used in a function definition can be changed by their redefinitions in Blocks surrounding the function invocation: ...
126 views

### Maximum number of literal values for SetDelayed?

Under what circumstances should I expect Mathematica to turn a delayed assignment into an immediate assignment? I have put together a minimal example (available here) which demonstrates this behavior. ...
189 views

### Position-based Inline syntax for Curry

I would like to update an existing pseudo-curry function: ā¢ /: h_[pre___, ā¢, post___] := Function[expr, h[pre, expr, post]]; that I use inline like this - the ...