All Questions

Filter by
Sorted by
Tagged with
2
votes
1answer
36 views

Construction of symmetric function / matching function argument patterns

[Edited for clarification after comment] Suppose that the function f is defined as the linear combination of several translated/reflected functions starting from the primitive f0[x,y,z] ...
0
votes
1answer
32 views

Constructing sequence of function with elements depending on the previous one / recursion

Starting from a function $\theta0[x\_ , y\_ , z\_ ]$, the terms $\varphi[x\_ , y\_ , z\_ ]$ constitutes a sequence of functions that is constructed as follows: Order 1 (one function and its ...
3
votes
2answers
104 views

Append a function of an expression as operator form using Curry?

I fielded this q to tech support but didn't get a conclusive answer yet: Is it possible to use Curry specifically to modify ...
3
votes
1answer
52 views

Is using Length more efficient than using === as stopping criterion?

I am using NestWhileList[ f[#, elems]&, pairs, Length[#1]<Length[#2]&, 2, Infinity, -1 ] to generate all suitable subsets from ...
4
votes
2answers
67 views

How to make FoldListIndexed ie FoldList with an index or iterator?

Is there a functional or inbuilt way to add an index to FoldList? i.e.: FoldListIndex[f,x,{a,b,...}] gives ...
18
votes
4answers
2k views

Cleanest way to take a[b[c]] to a[b][c]

As indicated in the title I'm looking for the fastest way to transform a[b[c]] into a[b][c], and the natural generalization to ...
1
vote
2answers
55 views

Switch applying tests to forms

Is it correct that the Select equivalent of Cases is missing for Switch? I mean a function <...
2
votes
1answer
76 views

Creating a bound method (partial function application)

I want to bind arguments to methods (e.g. for use in OOP creating a bound method--what Java just calls a method). I realized this is basically just a partial function application. Now I want to make ...
1
vote
1answer
58 views

How to write conditional loop structure in a function based on input passed through that function

I know the question is rather vague so, here is what I am trying to do: Lets say we have the following function: `color[data_,variableInputs_]. Now what I want this function to do is loop over the ...
4
votes
5answers
295 views

How to build these functions without nested For loops?

I am trying to solve the 8-puzzle using two heuristics, which are: Pieces out of place and Distance Manhattan. After consulting several websites for example see and some books, I'm with some doubts, ...
0
votes
1answer
80 views

Defining a random potential on the unit square

I'm trying to define a random potential on the 2D unit square. For some fixed j, I want to decompose the unit square into $2^{2j}$ smaller squares with sides length $2^{-j}$. On each of the smaller ...
2
votes
1answer
85 views

How to program MapList? [closed]

I would like to know if there is a nice functional way to code up a MapList which applies f to each element of ...
1
vote
0answers
46 views

Multiple Square Bracketed Function definition

I am familiar with the typical way of defining a function--such as f[x_,y_]:=x+y but I have not found a discussion of definitions such as ...
6
votes
2answers
104 views

Efficient way to partition list of expressions based on its contents

I have a list of polynomials polys linear in a set of variables vars. How do I partition the list based on successive dependence ...
8
votes
1answer
174 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 ...
1
vote
1answer
105 views

A function which performs multiple steps

I'm trying to figure out how I can define a function which takes an input, performs an operation on it, then produces a table from the result. For example, I have a function ...
2
votes
0answers
30 views

Scoping of OptionValue for inner functions in closures

Assume a function f is a closure over an inner function g. Both f and ...
1
vote
1answer
65 views

Compute and evaluate function of a function and keep the result a function

Let's assume I have a various functions for signal amplitudes, e.g. pulse[t_] = Sech[t]^2 and pulse2[t_]L = Exp[-2t^2]. What I'...
5
votes
2answers
94 views

Problems folding - resorting to hacks with `StringReplace`

I would like to FoldList a simple function, with desired output: ...
2
votes
0answers
48 views

Folow-up on combining pure functions [duplicate]

This is a follow-up to this question. Consider: f = #^2& g = #^3& Compose[f, g] (#1^3 &)^2 Am I the only one to think this is a bug?
11
votes
2answers
457 views

Combining pure functions

Is there an easy way to combine pure functions into a single pure function? For example, say I have f = #1^2 &; g = #1 - 2 &; and I want to define a new ...
11
votes
2answers
430 views

How to build private function with built-in function's option

Since this code work well: ...
11
votes
2answers
236 views

Simplifying a reverse Fold for a Query

Is there a simpler way to parametrize this tail-recursive expression to be applied as a Query (for processing a nested ...
2
votes
2answers
128 views

Conditional definition (/;) [duplicate]

I defined the following functions ...
2
votes
2answers
77 views

Inserting an integer into a list while maintaining descending order

Define a function g with two arguments, w and n, where w ...
4
votes
2answers
190 views

Making a list-function acting one-to one in a list of elements

Consider a pair of functions f1 and f2, and a vector {x,y}. I can get easily ...
2
votes
2answers
91 views

Pick complexes out from a list

Consider the assumptions $Assumptions = {Element[a,Reals], Element[z,Complexes]} I'm looking for a test, to be applied on a ...
0
votes
1answer
123 views

Define new symbols and “inverse” function

I have an expression that involve variables and conjugate of the variables eg ...
0
votes
1answer
55 views

How to fold a function whose output parameter is two

Supposing I have such function: fun[num_] := If[num < 24, num, {24, num - 24}] Usage: fun[79] {24, 55} I want split ...
8
votes
4answers
180 views

Elegant Replace Hold combination?

I would like to define an distributive function like this: com[x__Plus, y_] := c @@@ Distribute[c[x, y]]; which is Ok. I know that it's possible to define it ...
2
votes
1answer
74 views

Mapping multiple functions to one general rule/pattern

I am writing my own Mathematica code for simplifying tensor index manipulations with a metric. Here is what I wrote: ...
4
votes
1answer
155 views

How to make a custom function as inbuilt

I have a custom function like following: ...
11
votes
1answer
885 views

How to construct the RHS of Wick's theorem

I've been trying this for a few days now, but I just can't seem to find an efficient (speed-wise) functional way to code the following task. Context: I would like to construct an expressions that is ...
1
vote
2answers
240 views

Partial Function Evaluation [closed]

How can I evaluate only part of a stack of function calls? In particular, given f[x_,y_,z_]=x+y+z;, say, I'd like to define a function ...
4
votes
1answer
282 views

How to use currying to write a tail recursive function for summing factorials given a certain bound

I am very confused about how can i use currying to write a tail recursive function for summing factorials within a certain bound or summing the bounds i.e. given [1,5] i should be getting 1!+2!+3!+4!+...
4
votes
1answer
268 views

The basic primitive recursive functions

How can the basic primitive recursive functions be expressed in the Wolfram Language? Apparently here's an example for primitive recursion: ...
7
votes
3answers
422 views

How to organize expression by symbols (like Collect), but apply different functions to each coefficient

I want to mimic the functionality of Collect[expr, {vars}, func], but with the following modification: The function f that is ...
2
votes
2answers
60 views

Deciding whether the return value of a function is defined based on its input [duplicate]

I have been met with the following problem: I have defined the following: myFunc[e_Integer]; That means, if I call: ...
10
votes
3answers
255 views

List of functions to list of parameters

I am working in a Dataset and I need to create a function for a ChartStyle option of a ...
2
votes
2answers
515 views

Multiply pure function with scalar

Somtimes I still get lost in the Hold, HoldAll etc. functions of Mathematica. I want to scale a simple PDF function with a previously calculated variable e.g. ...
1
vote
1answer
93 views

Mapping Linear Model Fit Over An Arbitrary Number of sets

I have multiple sets of data, and I want to apply Linear Model Fit sequentially to each set of data. For example, below tstlst contains 3 data sets. Right now I ...
3
votes
3answers
114 views

How to force evaluation on the right of an @ operator?

Is there a way to force evaluation on the right before the Prefix operator (@) without using parentheses? I came across this question when I was working with the ...
0
votes
1answer
132 views

How to define the following bracket?

My quetion is about the definition of the so-called Courant Bracket. Given two generalised vector field, defined as a formal sum of a vector and a one-form, i.e. $X = x + \lambda,\ Y = y + \omega$, ...
0
votes
2answers
90 views

Supply a function as an argument to another, and find its minimum

I would like to minimize a function, which is supplied as an argument to another function, and report back the estimates of the values of the variables that result in its minimum. In specific, I would ...
2
votes
1answer
273 views

General function taking general number of arguments

The following is an edit of this post, for which a working solution was provided by John McGee. I have a different function and am not sure how to adapt the solution for it: I want to construct a ...
1
vote
1answer
132 views

The problem (time) caused by ?NumericQ

In here, I asked a related (similar) question. Using ?NumericQ seems have slowed down the entire calculation. But I now have a more serious problem: ...
1
vote
0answers
97 views

What are the differences between these functions when used for NMaximize?

In short, the question is how to construct the function you want to optimize? ...
2
votes
1answer
64 views

Searching for symbol except within subexpressions with a particular Head

I would like to write a searcher like FreeQ that looks for a Symbol (or Head) in an ...
2
votes
1answer
663 views

How can I call the R-programming packages in my Mathematica?

I am trying to call the R-programming package called highfrequency in my Mathematica so that I can use its function rCov. I ...
3
votes
1answer
45 views

Mapping also for one element (or telling it how to do so if head got changed)

Some code generates a polynomial, and has the form: expr = Plus[a[i],b[i],c[i],d[i]] I need to apply f to each term. To do ...