As of May 31, 2023, we have updated our Code of Conduct.

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.

227 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
10 votes
0 answers
264 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 ...
user13892's user avatar
  • 8,779
10 votes
0 answers
229 views

Does Compilation option "InlineExternalDefinitions"/"InlineCompiledFunctions" lead to unnecessarily complicated nesting?

Question: When an external (possibly complicated) definition f is used inside a compiled function with ...
QuantumDot's user avatar
  • 19.3k
9 votes
0 answers
63 views

Does ArgumentsOptions do anything we couldn't do without it?

ArgumentsOptions was new in version 12.2. I looked at the application on that page, and it makes code very difficult to understand. What if anything does ArgumentsOptions do for us that we couldn't do ...
Ted Ersek's user avatar
  • 6,924
9 votes
0 answers
124 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 ...
sebhofer's user avatar
  • 2,701
8 votes
0 answers
149 views

Defining a SparseArray functions in Mathematica 13

I am defining a sparse array as a function of argument x, i.e. f[x_] = SparseArray[{1->x}, {3}] In Mathematica 12 this works perfectly, I can pass arguments and ...
Alik's user avatar
  • 81
8 votes
0 answers
163 views

KeyValuePattern specificity in DownValues

Bug introduced in 10.4.0 and persisting through 11.3.0 CASE:3824590 [...] Developers are discussing this behavior. [...] I will let you know when I have definite information on this. [...] ...
Kuba's user avatar
  • 135k
7 votes
0 answers
69 views

Why does Longest not work on OptionsPattern?

When having a function with optional arguments and options, I frequently find myself writing something like this: ...
Lukas Lang's user avatar
  • 32.1k
6 votes
0 answers
254 views

Finding periodic cycles of a function

Given a function f[{x,y}] it is rather simple to use, for example, NSolve to find periodic points of period $n$. We simply take ...
math's user avatar
  • 713
4 votes
0 answers
35 views

Efficiently threading with a default value for missing parts / defining custom behavior for addition of expressions with a given head

In short, I would like to be able to "add" expressions with a particular head (call it h for our purposes) which will always appear with a sequence of (...
max's user avatar
  • 61
4 votes
1 answer
473 views

Return unevaluated expression from function

Is there any way (except using upvalues) to make a function that returns it's input Unevaluated? What I mean by that: Take the following example: ...
Lukas Lang's user avatar
  • 32.1k
4 votes
0 answers
975 views

Wick Contractions; help with a piece of code

An alternative title to this thread could be, understanding another person's code. A few years back there was a workshop on Mathematica and applications to theoretical physics; if you want I can ...
a_User_with_No_namE's user avatar
4 votes
0 answers
339 views

Strange behaviour of MMA in derivatives of some standard functions

There are some peculiar things to be discovered in derivatives of some standard functions in MMA: Strange behaviour Example 1: Abs We have ...
Dr. Wolfgang Hintze's user avatar
3 votes
0 answers
52 views

How can one automatically arrange the connections of a circuit with as few crossings as possible, given a set of edges?

Here are two functions to create symbols of dc voltage source and a resistor. ...
hana's user avatar
  • 2,832
3 votes
0 answers
76 views

What are some ways to overload Min in order for it to work with user defined expressions?

I have defined size to work with discrete size labels: ...
yosimitsu kodanuri's user avatar
3 votes
0 answers
116 views

Prime Matrix with determinant of powers $2^x$

Mathematica has commands for finding prime matrices, for example, here is a matrix with randoms in the range $<100$: RandomPrime[100, {3, 3}] This $2 \times 2$ ...
Moo's user avatar
  • 2,702
3 votes
0 answers
60 views

Differences between u[x,y,t] vs. u[x,y][t] vs. u[x][y][t]

Is there any difference between defining a variable by u[x,y,t] or u[x,y][t] or u[x][y][t] ? ...
Nitra's user avatar
  • 157
3 votes
0 answers
158 views

Fast way to check if an expression matches any of the rules in a list?

I have a function defined roughly like so. This is a minimum recreation. foo[expr_, rules: {__Rule}] := "some fancy result" /; AnyRuleMatchesQ[expr, rules]; What ...
Mosaic Blounder's user avatar
3 votes
0 answers
383 views

How to achieve with Mathematica the effect a closure has in other languages?

Motivation I want to write an auxiliary function (brief auxf) for testing the output of another function that evaluates its body repeatedly using ...
user42582's user avatar
  • 4,115
3 votes
0 answers
78 views

What's the role of the lines order in defining a function?

I'm totally surprised by the finding I had never noticed before. This code works as obviously intended ...
mitochondrial's user avatar
3 votes
0 answers
168 views

How to reduce computation time for a large symbolic matrix

I have a 6x6 matrix (A) that is a function of k and H with complex symbolic entries that contain functions. I want to reduce the computational time since I will be evaluating the matrix many times for ...
S. Balaji's user avatar
3 votes
0 answers
442 views

Generating a list of random numbers that follows a pattern

I'm a beginner to Mathematica. I'm writing a code to design a 4-bar linkage mechanism that traces a path in 2D space. I got the modelling done right, now I'm writing my own implementation of a genetic ...
Mahmoud Mousa's user avatar
3 votes
0 answers
125 views

How to get this terrible summation/product to run in Mathematica?

I've come across this formula and have no idea where to even start. (My assumption here is that $m,n$ are known and input into the expression to arrive at an answer.) $$f(m,n) = \sum_{\substack{0 \...
SAWblade's user avatar
  • 143
3 votes
0 answers
627 views

Lyapunov Exponent as a function of parameter

I am working at Rossler system and I would like to ask you for some help. This system is described by equations: \begin{array}{ll} \dot{x} = -y - z \\ \dot{y} = x + 0.2y \\ \label{eq:UkladRosSP} \dot{...
MarcinK's user avatar
  • 59
3 votes
0 answers
143 views

How to make a new analytic function work seamlessly with Mathematica's analysis functions?

I am defining a new analytic function of six variables. I have algorithms to evaluate it numerically, and have amassed a large catalog of analytic properties. It is easy for me to program the ...
QuantumDot's user avatar
  • 19.3k
2 votes
0 answers
89 views

How to write 2D finite volume solver in a functional approach?

I'm solving 2D poisson problem of a finite volume problem using TDMA. The solution of the problem is given: \[Phi][x_, y_] := x^2 y + x y^2 + 1 The definitions are ...
kpaz's user avatar
  • 41
2 votes
0 answers
66 views

Argument value loss using Listable C-Compiled Function

In my recent studies, I have come across a very strange anomaly with C compiled functions. When I call a function that has the 'Listable' attribute while global variables are accessed through ...
Michael Haring's user avatar
2 votes
0 answers
54 views

How to separate coefficient and argument of the function?

I'm trying to make a list with coefficient and argument of the function f as below. myList is my input and ...
hana's user avatar
  • 2,832
2 votes
0 answers
96 views

How does Mathematica choose which function definition to use?

I was wondering what the process of matching function arguments arguments against different function definitions actually looks like for Mathematica. (Just to be clear, I'm not simply looking for an ...
thorimur's user avatar
  • 8,825
2 votes
0 answers
40 views

Rules of operation

I am trying to implement the following. But the first four lines are not implementing in my rules!!! ...
Jasmine's user avatar
  • 1,225
2 votes
0 answers
1k views

General:: Exp[-717.401] is too small to represent as a normalized machine number; precision may be lost

I am solving pde. For the post processing bvp, there is solution given in output which is the solution from mathematica version 10.0.1. Output from above in mathematica 10.0.1 is, But when the similar ...
user75507's user avatar
2 votes
1 answer
155 views

Why do some variables get substituted and others don't?

I was running into some trouble with my math and I whittled it down to this nugget: ...
Scott's user avatar
  • 31
2 votes
0 answers
265 views

How to define tensors similar to Riemann tensor in xAct xTensor xTras

I'm working on a project where we deal with objects very similar to Riemann tensor. In fact they are Christoffel symbols for higher spins. I'm using xTras for modeling problems in wolfram mathematica. ...
Melik Karapetyan's user avatar
2 votes
0 answers
115 views

How to override a built-in Mathematica function using its old version?

How can we override a Mathematica built-in function using itself in the definition? For example, the DiracDelta function is not defined for complex numbers like: <...
GarouDan's user avatar
  • 1,536
2 votes
0 answers
118 views

How to handle Units when Integrating?

I have some functions defined, which are to use units. Now another function is used to integrate over those, with the integration variable also quantified and the input to said function. I better just ...
JustAGuy's user avatar
2 votes
0 answers
125 views

Speeding up the process of NDSolve[] when a user-defined function is involved?

I am trying to tackle a (1+4 dimensional PDE) model at which the solution of the first PDE (with some interpolations and changing the domain) would be used in the second PDE. In fact, I must choose ...
Fazlollah's user avatar
  • 1,795
2 votes
0 answers
190 views

Lambda calculus reduction in Mathematica

Are there any built-in functions for reducing lambda terms in Mathematica? If not, how might one do it? I've heard of Function, which is good for $\beta$-reduction, ...
koro's user avatar
  • 21
2 votes
0 answers
157 views

How to simplify Log expressions using rules

I have the following expression, ...
Jaswin's user avatar
  • 183
2 votes
0 answers
115 views

Why does the evaluation of "Catch[Break[],\$Failed]" not return "\$Failed"?

Under normal conditions, evaluating something that emits a Message eg the evaluation of 1/0 that produces a ...
user42582's user avatar
  • 4,115
2 votes
0 answers
40 views

Keyed eigensystem for nested Association

Suppose a matrix is given where both rows and columns are keyed, for example this correlation matrix: ...
alancalvitti's user avatar
2 votes
0 answers
51 views

Scoping of OptionValue for inner functions in closures

Assume a function f is a closure over an inner function g. Both f and ...
Sascha's user avatar
  • 8,369
2 votes
0 answers
183 views

Defining a function by coordinates of points and degree of a polynomial

I'm studying about solid of revolution. In these studies, I learned that to get the volume of such a solid, I need to know $f(x)$ to describe the contour of the profile. This concept I understood. $...
Luciano's user avatar
  • 253
2 votes
0 answers
75 views

3 parameter definition for solid modeling

...
Narasimham's user avatar
  • 2,972
2 votes
0 answers
88 views

Obtaining the interpolation function of a surface

Some sample data ...
Vaggelis_Z's user avatar
  • 8,530
2 votes
0 answers
95 views

Built-in functions for Homotopy group

Does Mathematica have built-in functions for Homotopy group, for example for computing $$\pi_n(S^m)=?$$ or more generally $n$-th homotopy group, $$\pi_n(X)=?$$ for some $X$. (I search, but I could ...
wonderich's user avatar
  • 843
2 votes
0 answers
86 views

Is there an efficient way to monitor the progress of a task remotely?

Recently, I've been running Mathematica packages on a remote cluster using SSH (using, e.g. the command ...
Nikhil Anand's user avatar
2 votes
0 answers
131 views

Obtaining a Previously Constructed Function as Desired Output

I was playing around with some Generalized Trigonometric Functions defined as follows; ...
Eleven-Eleven's user avatar
2 votes
0 answers
74 views

First position of incremental series

I am still a beginner and maybe I want to do something too complicate! After 29 cycles I obtained the following events list: ...
Three Shell's user avatar
2 votes
0 answers
67 views

Rescale large numerical factors in rational functions

Given a rational function $$ f(x_1,x_2) = \dfrac{r_1 x_1^2 + r_2 x_2}{r_3 x_1 + r_4 x_2}, $$ with $r_i$ arbitrary real or complex numbers, is there a built-in function to get Mathemtica to rewrite as $...
jjstankowicz's user avatar
2 votes
0 answers
584 views

Defining a function with a subscripted head

How can I define a function with subscript? Forexample: f_alpha[x] = 2*x
bluehills's user avatar
2 votes
0 answers
360 views

How to Implement a "Function Object" suitable for NDSolve and Finite Element Method?

I have a bunch of methods that shoud return an expression that behave like a function, i.e. an expression that, when supplied with suitable arguments, evaluate to something. A simple ...
unlikely's user avatar
  • 7,033

1
2 3 4 5