Questions tagged [programming]

Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.

150 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
9 votes
0 answers
62 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 ...
  • 6,914
8 votes
0 answers
320 views

Convert logical relational expression to / from disjunctive and conjunctive forms?

I would like to convert logical relational expressions in disjunctive form, e.g., $$(x \lt -1) \lor (-1 \lt x \lt +1) \lor (x \gt +1)$$ into conjunctive form, e.g., $$(x \ne -1) \land (x \ne +1)$$ ...
7 votes
0 answers
170 views

Mimicking Console and Output Matlab/Rstudio-Style Environment in Mathematica?

I am trying to crudely approximate the RStudio or Matlab Workspace environment in Mathematica by having a specific notebook function as the "console notebook" where I execute commands and another ...
  • 907
7 votes
0 answers
863 views

How to create protected single-file stand-alone CDF applications

After hours of work trying to understand how much protection I can get when creating stand-alone CDF applications I have come to the decision that the best protection to my work is provided by ...
6 votes
0 answers
1k views

How to find the a minimum cost perfect matching

Crossposted on Wolfram Community A a minimum cost perfect matching is very useful tool.This three links about this demand just related me,let alone all MMA.SE. How to get some pairing with smallest ...
  • 25.3k
6 votes
0 answers
94 views

How to trigger an "ErrorBox behavior"?

Here's an example of what I mean by an "ErrorBox behavior". In the front end, if one evaluates the expression ...
  • 11.5k
6 votes
0 answers
859 views

Code formatting

This question is a follow up from Formatting notebook files In Programmatic formatting for Mathematica code - possible? masterxilo proposed to use ...
  • 11.5k
6 votes
0 answers
118 views

How is CellContext->CellGroup supposed to work?

After reading the documentation on the subject, I still cannot get CellContext->CellGroup to work. Here's a simple example. (Unfortunately, I cannot easily ...
  • 11.5k
5 votes
0 answers
291 views

How to Write Stand-alone Mathematica Projects/Programs

I wish to write several stand-alone projects/programs using Mathematica because of its easy-to-use graphics. I could use Python for this, but Mathematica has built-in graphics that would be better ...
5 votes
0 answers
243 views

Use Mathematica with Go Language

I would like to know if I can use Go and Wolfram Language? Example C ...
5 votes
0 answers
107 views

Techniques in debugging with preview of possibly large expressions + garbage collection issues

First of all, all appreciate all suggestions how to rephrase the title to make it more friendly. Here's the background: Let's say your top level procedure flow is complicated, involves url calls, ...
  • 135k
5 votes
0 answers
258 views

Is Mathematica a good choice for a scientific project with Machine Learning?

I'm a chemist with some rudimentary programming skills and in the middle of the year I'll be starting a project concerning machine learning, so, I'm sorry if I'm going to ask two questions in this ...
  • 193
5 votes
0 answers
265 views

Can I define an axiomatic (Boolean algebra) system and prove theorems using Mathematica?

The general question is Can I define an axiomatic system and prove theorems using Mathematica? The more concrete one is about Boolean algebra. I consider this axiomatic Boolean algebra system (wiki)....
  • 818
5 votes
0 answers
1k views

A* algorithm for finding shortest path in a graph

FindShortestPath finds the shortest path between two vertices in an edge-weighted graph, allowing a choice between the Dijkstra and Bellman-Ford algorithms. In my (limited) understanding, both of ...
  • 1,395
4 votes
0 answers
141 views

What is the best coding style for performance?

The problem of Mathematica is there are too many ways to perform one task. That leads to confusion for new users because the performances of these methods are so different. I'm learning the best ...
  • 1,721
4 votes
0 answers
45 views

What built-in functions have bad time/space complexity and their alternatives?

It's surprising that Join is $\mathcal{O}(n)$ (due to copy) while I've been using it as a convenient way to join lists together. It also reminds me of suggestions ...
  • 2,010
4 votes
0 answers
111 views

Neural network for a simple game?

I'm taking a class that is based on the Mathematica coding language, and we must do a 6-week final project. I am considering coding a neural network for a simple game like 2048, pacman, snake, etc. ...
4 votes
0 answers
819 views

Code Review: ECDSA for Mathematica

The code below contains functions related to ECDSA (Elliptic Curve Digital Signature Algorithm) with standard parameters secp256k1. The implementation is based on ...
4 votes
0 answers
303 views

How to convert a URLFetch to a URLRead or URLExecute?

Consider the following function: ...
4 votes
0 answers
268 views

Finding all Minimal Cut Sets for Site Percolation?

Bug introduced in 9.0 and persisting through 11.3.0 FindVertexCut and FindMinimumCut are new in 9.0. I want to disconnect the ...
  • 2,513
4 votes
0 answers
262 views

What am I missing in this highly oscillatory integral?

I want to numerically integrate this equation (in python without calling Mathematica): $\int_0^\infty {\rm d}k f(k) J_v(r k) J_n(s k)$ where $f(k)$ is a non-smooth function, $J_v$ are the Bessel ...
  • 141
4 votes
0 answers
967 views

Expectation Maximization Algorithm

I would like to use the expectation maximization algorithm within Mathematica. The issue is that I am very basic user and progress slowly with understanding functional programming.. I have found this ...
4 votes
0 answers
103 views

Can BreadthFirstScan be modified?

I would like to obtain a "slick" implementation of A*-search algorithm on Graph objects, using the built-in BreadthFirstScan (if that is possible at all). I noticed that BreadthFirstScan is static in ...
4 votes
0 answers
369 views

Using NVIDIA 3D Shutter Glasses with Mathematica

Mathematica has great capabilities to display 3D Graphics rendered to the 2D screen. This should make it perfectly suited to use the Graphics3D system together with an NVIDIA Graphics card, a 3D ...
  • 2,781
4 votes
0 answers
500 views

Call Haskell from Mathematica and return the results inside Mathematica

I would like to learn Haskell using Mathematica's environment. I know there is the RLink protocol. Is there a similar protocol for Haskell?
  • 61
4 votes
0 answers
167 views

Is there a way to check whether two notebooks share the same variables?

When I code in Mathematica, I often re-use code from old notebooks which fulfilled a specific purpose; for example, one testing for soft matches in strings, or one that identifies outliers on a graph ...
4 votes
0 answers
95 views

How to insert expression matching the format?

I would like programmatically to insert/write an expression at the current insertion point, but matching the current format, such as font size and style, so that it looks like the user typed it. ...
  • 1,463
3 votes
0 answers
82 views

Module inside With, With inside Module, or Just Module?

In general, if one wants to define local variables and local constants, which of the following is the best programming practice in terms of performance and code "safety"? (Assume ...
3 votes
0 answers
197 views

Calling custom function from C++

I'm programming a project where I use multivariate symbolic polynomials. At some point I need to perform a PolynomialMod over a prime modulus, but the library GiNaC which I use works only over the ...
  • 203
3 votes
0 answers
509 views

Epsilon algorithm to accelerate sum's convergence in a functional approach

I am trying to learn to use Mathematica in an efficient way. Thus, I decided to spend some time on functional programming. I would like to implement the so-called epsilon algorithm, that is used to ...
3 votes
0 answers
148 views

How to set up Switch with variable number of conditionals?

I would like to use a Switch command with IntegerPartitions[n] of terms with n ranging from 3 to 12 and n chosen at run time. I have: ...
  • 31
3 votes
0 answers
76 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 ...
3 votes
0 answers
370 views

Help to finish a Sperner lemma application

This is the code for the celebrated Sperner's Lemma in two dimensions --- which is equivalent to Brouwer Fixed Point theorem. Incidentally, it's my first program without any help --- until I ask this ...
3 votes
0 answers
140 views

What is recommended way to define my function option

In Mathematica 5.x days many packages used the following standard mechanism to read option values ...
  • 3,104
3 votes
0 answers
496 views

How to compute the Lovász number for the given graph in Mathematica?

Here is a graph whose adjacency matrix is ...
  • 1,115
3 votes
0 answers
1k views

Lazy evaluation/loading of parts of an expression

Is it possible to have an expression x such that its elements are only evaluated when they are individually accessed, for example when evaluating statements like <...
3 votes
0 answers
295 views

Malliavin Derivative with Mathematica is it possible?

Is it possible to define a Malliavin calculus with Mathematica 9? Consider a random variables on the Wiener-space $\Omega=\mathcal{C}([0,1])$ of the form $$F=F(\omega)=\displaystyle\int_{0}^{T}h_{t}...
  • 391
3 votes
1 answer
646 views

Forecasting future Stock Prices II

I intend to do the following: I want to forecast future stock price under the following assumptions: The stock price is governed by the stochastic differential equation: dS = μSdt + σSdWt whereas ...
3 votes
0 answers
242 views

I am missing a function like HoldPattern

Temporary message: I am planning to edit this question, making the examples less confusing and by moving the things that are confusing to a separate question For any confusion about expressions that ...
2 votes
0 answers
90 views

The fastest and most scalable way to write a nested loop

The problem is to find the weights {w1,w2,w3,w4} that satisfy the condition. Which is the fastest and most scalable way (e.g. for 10000 weights) to write this ...
2 votes
0 answers
50 views

Does the Wolfram Cloud permit real-time Collaboration?

I am curious if anyone has found a workaround or directly built-in method to work collaboratively with colleagues? Something analogous to the google productivity apps like google docs where different ...
  • 1,147
2 votes
0 answers
68 views

family photo album,how to optimize its realization?

I am Beezy, the eldest daughter of the couple. I have a lot of photos on paper and I want to make a photo album for my parents, but the task is titanic. First I use a scanner, to scan the photos that ...
  • 480
2 votes
1 answer
166 views

In NMinimize, how to incorporate constraints on positive semidefiniteness of a matrix which is not the matrix variable being optimised?

The problem I want to solve the following problem for symmetric matrix $X$: $$ \begin{aligned} \min_{X\succ 0} \; & -\log(\det(X)) & \\ \text{subject to} \; & \begin{pmatrix} X &...
  • 215
2 votes
0 answers
34 views

How to abort evaluation when clicking CancelButton in program with Dialog boxes?

If you run the following code you will notice when Cancelbutton is clicked, the output is an $Abort, but it continues running the following cells, I tried different things but no one works. I want to ...
2 votes
0 answers
87 views

How can I make this "Pick" inside a "Table" run faster?

I am working on becoming more and more familiar with MMA and on a scale from one to ten, I would rate myself as a four or a five. I understand vectorization and that loops-are-very-bad. I have ...
2 votes
0 answers
113 views

Problem with PopupMenu: Its values don't update dynamically

I have a problem with PopupMenu inside DynamicModule, its values don't update dynamically as they supposed to. The example below ...
  • 77
2 votes
0 answers
90 views

Fold/ NestList/ etc in MCMC loop for optimisation

I am trying to simplify and optimise an old loop code I wrote. Since Fold and NestWhile use the results of the last iteration in the new iteration, I would like to use them in order to get rid of Do ...
  • 1,268
2 votes
0 answers
198 views

Extracting the curl-free component of a vector field

I am trying to extract the curl-free component of a discrete vector field. My plan is to take the Fourier transform of the vector field and then extract the radial component in Fourier space. The ...
2 votes
0 answers
119 views

Package for static Mathematica code analysis to produce a Cayley tree?

I am looking for a package which can display a static dependency tree of code from a single Mathematica notebook or from a list of Mma notebooks. (Of course, to prevent such a tool from producing tons ...
2 votes
0 answers
115 views

How to implement a regular grammar in Mathematica 10.0 onwards?

I would like to see a new answer to this question: How to implement a regular grammar? considering the introduction of GrammarRules in 10.0 ( 2014 ). ( I don't know if this question satisfies the ...