Questions tagged [pure-function]

Questions about implementing or applying functions which: (1) always yield the same result for the same input, (2) are independent of outside information, and (3) produce no side effects.

28 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
0 answers
279 views

Performance of pure function - Best way to define a function?

In general, to define a function, we often use f[x_]. Another way is to use pure function (full form and shorthand). I want to test the performance of these ...
Nam Nguyen's user avatar
  • 1,761
7 votes
0 answers
201 views

Can Wolfram Language enforce pure functions?

Is there a feature in Wolfram Language that supports or enforces pure functions? WL has something that it calls "pure functions" in its documentation, but these are most emphatically not pure ...
orome's user avatar
  • 12.8k
5 votes
0 answers
153 views

Third syntax version of LogitModelFit: unexpected result of "BestFit"

The third listed syntax version of LogitModelFit allows one to specify input in a simple way: Only a design matrix (with a row of values of the explanatory input ...
Sjoerd C. de Vries's user avatar
4 votes
0 answers
46 views

`Function` does something bizarre with formal parameters

I think this may overlap with existing questions, including one I asked years ago, but I'm not sure how, because the behavior I'm seeing is confusing enough I can't even really describe it except to ...
Pillsy's user avatar
  • 18.5k
4 votes
0 answers
53 views

Bug with LinearRecurrence and Slot/SlotSequence?

The code below runs without any error: LinearRecurrence[{##}, {1}, 5] Each term is the previous term squared, times the index of the previous term. If the ...
JungHwan Min's user avatar
  • 4,674
4 votes
0 answers
77 views

Wrong autogenerated package from notebook containing #key and Part as subscript

Bug introduced in 10.0.0 and persisting through 10.1.0 or later Mathematica v10.1.0, under Windows 8.1 x64 Mathematica v10.0.2, under Windows 1) Define a function in an initialization cell: ...
unlikely's user avatar
  • 7,103
3 votes
0 answers
263 views

How to overload and compile pure functions operating on associations

I am writing a small package for myself for operating on zonotopes. I am storing the generator matrix and the center of the zonotope in an association. I decided to write a small constructor: ...
Mario E. Villanueva.'s user avatar
2 votes
0 answers
75 views

Memory leak with pure function and in the listable option of compiled function?

I'm using 13.0.0 for Microsoft Windows (64-bit) (December 3, 2021) When I repeatedly run the command ...
dzsoga's user avatar
  • 341
1 vote
1 answer
106 views

A way to generalize my code for this non linear ODE problem

I am trying to solve the differential equation $y''(x) = y(x)+\sin[y'(x)]$ using "Fixed Point Iteration" over the interval $[0,1].$ Now using central difference method I arrived at the ...
Learner's user avatar
  • 219
1 vote
0 answers
72 views

Mapping two pure functions over different lists

Say if I have two lists of vectors of the same length, for example: u = {{1,0,0},{0,1,0},{0,0,1}} v = {{1,0,1},{1,1,0},{1,1,1}} I want to add (modulo 2) ...
am567's user avatar
  • 501
1 vote
0 answers
71 views

Shorten Pure Function

My task is to write a pure function with 5 characters or less that can be called with a single number a or a list {a,b,c} and returns 1/a^3 or {1/a^3,1/b^3, 1/c^3,...}, depending on the input. I am ...
noob3000's user avatar
1 vote
0 answers
49 views

Why are nested anonymous pure functions shielded from evaluation?

I tried the following code (ignoring the warning messages): ...
Terence Li's user avatar
1 vote
0 answers
106 views

Is there a good reason why `Slot[]` is not an atomic expression?

Here's a good reason why I think it should be, Map[ If[AtomQ@#, #->"is an atom", #->"not an atom"]& , {"hello",Range@3, # &} , {-1} ] ...
Fortsaint's user avatar
  • 2,060
1 vote
0 answers
45 views

Issues with Manipulate (or variable assignment)

I am working to take a large manipulator I have built and generalize it, but I keep running into some variable assignment issue. I made a short example of my issues below: Set up: ...
user60143's user avatar
1 vote
0 answers
65 views

Mapping over array/matrix the efficient(compact) way

Update In short, I have myCAans[[1 ;; 5]] like this: {{0, 0, 0, True, 0, 0, 0, 0, True, 0, "T0", 39}, {0, 0, 0, True, 0, 0, 0, 1, True, 1, "B", 101500}, {...
Chen Stats Yu's user avatar
1 vote
0 answers
94 views

Time-stepping an equation in Mathematica

I have an iterative integral equation of the form $$n(k,t+dt)=n(k,0)+dt\int_{0}^{\infty}dp\int_{0}^{\pi}d\alpha\int_{0}^{2\pi}d\beta\int_{0}^{\pi}da\,p^{2}q^{2}\sin(\alpha)\sin(a)\frac{(n(p,t)+1)}{\...
user35305's user avatar
  • 291
1 vote
0 answers
136 views

Using Solve without introducing extra variables

First post here. I've tried searching for an answer for this for a few days now, but it seems the search terms (solve, slot, etc) are too generic to be helpful. I'm struggling with understanding how ...
cjdrover's user avatar
  • 341
1 vote
0 answers
115 views

How to Fold (FoldList) this in a more compact (efficient) way?

Example code: x = Table[something[i], {i, 5}] Table[Fold[f1[#1, f2[#2, a], a] &, x[[i]], {c1, c2, c3}], {i, Length[x]}] This above is just an example. I ...
Chen Stats Yu's user avatar
1 vote
0 answers
240 views

Defining an operator

Let s be a positive integer and let DifferenceDelta be this function with step = 1. Define <...
Kimist's user avatar
  • 116
0 votes
0 answers
47 views

Why does this function only work with exact numbers?

First, I tried calculating A^k with this and got an error. ...
emnha's user avatar
  • 2,111
0 votes
0 answers
166 views

Numerical errors in compiled function involving real and complex numbers as output

I am trying to use the Compile command in Mathematica to reduce the computation time because of its fast execution within Mathematica and ability to use the ...
Rohan's user avatar
  • 13
0 votes
0 answers
35 views

Behavior of ## changes inside Position function?

I don't understand the behavior of this following simple(?) example: ##&/@ {{0,1},{1,2}} Position[%,{1,2}] gives {{2}} ...
majmun's user avatar
  • 207
0 votes
0 answers
76 views

List of function - basis

I would like to define list of function (make polynomial basis as a set of the functions), and then evaluate value of first/ second function in the set. I have made set of the fuctions that I have ...
Waney's user avatar
  • 101
0 votes
0 answers
687 views

Commutator of differential operators

Let $P_x = \frac{\hbar}{i}\frac{d}{dx}$, after specifying the commutator relation symbolically $[X, P_x] = i\hbar$, I can ask Mathematica to calculate commutator algebra. My question: is there a way ...
Histoscienology's user avatar
0 votes
0 answers
65 views

How to protect pure functions

I have some pattern functions and pure function in my package. If i set attributes Protected and ReadProtected. My pattern ...
user13892's user avatar
  • 9,395
0 votes
0 answers
55 views

Max and Mean command produce the same result

I tried to find a point that is nearest to two other points, using both "Max" and "Mean". I wonder why both produce the same value. I tried changing the input, but the results by using "Max" and "Mean"...
C_S's user avatar
  • 139
0 votes
0 answers
68 views

Error in storing the output of a module (subroutine) into an array

For a physics application, I have to compute components of a rank-4 tensor, the Riemann tensor. I do this using a module (subroutine) which looks like this ...
leastaction's user avatar
0 votes
0 answers
67 views

What makes items with head `Function` different?

I apologize beforehand for the muddleheadedness of this question. It reflects the fact that I'm trying to interpret outward "behaviors" of Mathematica expressions without having any understanding of ...
kjo's user avatar
  • 11.7k