Writing mathematical expression in a file

I am trying to write a mathematical expression as variable = expression in the output file.

The current method that I am doing is through WriteString as

expr = -((a*b*y^2*(-1 + z)*z*(1 + a*b + z))/(1 + a*b)^2) +         (z*(1 + a*b - a*b*z + (z + a*b*z)^2))/(1 + a*b)^2 -         (y*z*((-1 + z)^2 + a*b*(2 - 3*z + z^2) + a^2*b^2*(1 - z + z^2)))/(1 + a*b)^2 expression = CForm[expr] /. {Power->pow}; (*expression = CForm[HornerForm[expr]] /. {Power->pow};*) str=OpenWrite["output.hh"]; WriteString[str," double variable = ", expression,";"]; (*WriteString[str," double variable = ", ExportString[expression,"Text"]];*) Close[str]; 

The output is

 cat output.hh  double variable = -(a*b*(-1 + z)*z*(1 + a*b + z)*pow(1 + a*b,-2)*pow(y,2)) - y*z*pow(1 + a*b,-2)*(pow(-1 + z,2) + a*b*(2 - 3*z + pow(z,2)) + pow(a,2)*pow(b,2)*(1 - z + pow(z,2))) + z*pow(1 + a*b,-2)*(1 + a*b - a*b*z + pow(z + a*b*z,2)); 

I want to break the line as the original expr (or after some user-specified column say 80) i.e.

 double variable = -(a*b*(-1 + z)*z*(1 + a*b + z)*pow(1 + a*b,-2)*pow(y,2)) -                    y*z*pow(1 + a*b,-2)*(pow(-1 + z,2) + a*b*(2 - 3*z + pow(z,2)) + pow(a,2)*pow(b,2)*(1 - z + pow(z,2))) +                     z*pow(1 + a*b,-2)*(1 + a*b - a*b*z + pow(z + a*b*z,2)); 

Although this might not lead to optimized expression for numerical evaluation, however it is wanted as beautification. Also how should one optimize expression for further processing to other languages. Any suggestion? Experimental`OptimizeExpression and HornerForm are some options. Any other recommendation? MathCode is much costly 😀

finding FWHM of a dataset with unknown mathematical equation

I have a dataset. I have plotted using "Listloglinearplot". Now I need to find the FWHM (full width half maxima) of the same, However I dont know which mathematical eqution describes best to fit my dataset to find out FWHM. I have the following data and plot:

dataset={{0., 0.0518175}, {1., 0.0306299}, {1.9, 0.610295}, {2.,    1.32653}, {2.2, 4.01183}, {2.5, 6.37931}, {3., 6.50091}, {5.,    6.54052}, {6., 6.57276}, {8.2, 6.59119}, {15., 6.56125}, {20.,    6.5267}, {30., 6.4484}, {45., 6.2987}, {60., 6.11953}, {75.,    5.84962}, {90., 5.43738}, {100., 4.96757}, {105., 4.54382}, {120.,    3.42917}, {135., 2.23092}, {150., 1.55222}, {165., 0.679385}, {180.,    0.444479}} dataplot =   ListLogLinearPlot[dataset,    PlotStyle -> {Dashing[{.0071, 0.005, 0.005}], Blue},    PlotMarkers -> {\[FilledCircle], 15}, Frame -> True,    FrameStyle -> Directive[Black, Thickness[0.002]],    FrameLabel -> {Style["x", Black, FontFamily -> "Times New Roman",       FontSize -> 26],      Style["y", Black, FontFamily -> "Times", FontSize -> 26]},    PlotRange -> {{0, 190}, {1, 7.2}}, FrameTicks -> Automatic,    ImageSize -> 650,    BaseStyle -> {FontFamily -> "Times", FontSize -> 10}] 

Can anyone please help me with the mathematical equation?

Thank you.

Defining an mathematical operator in Mathematica

I’m trying to learn mathematica to use in my thesis. I have basic problems with definitions, calculations etc. Let me ask a question.

I want to define anti derivative operator and derivative operator, then a new operator with composition of these operators. Compositions must be identity, so if I give a function into new operator it will turn out the function what I gave it.

To explain better, I will try to write these in mathematical sense;

Here $ D^m$ denotes standard derivative operator $ m$ times and anti-derivative operator $ I_m$ defined with

\begin{cases}  f(x), & m=0 \ \int_0^{x} \dfrac{(x-y)^{m-1}}{(m-1)!}f(u)du, &  m\geq 1 \end{cases} 

which seems

Editor gives an error so I use code option and screenshot to code

Now, if we composite these functions, $ [D^m\circ I_m](f)(x)$ these will give us directly $ f(x)$ . I want to define these operators in Mathematica and see composition of operators.

Actually these problem is not my main problem but the answers will shows me what I need, then I will try to learn myself again.

Thanks for your helps, if I wrote incomprehensible or wrong forgive me.

Why are mathematical proofs so hard?

i am an electrical engineer and trying to make a transition into machine learning. I read in multiple articles that i have to learn data structures and algorithms, before this i have to learn about mathematical proofs. I started studying it on my own using the material available on mit’s ocw, while i did grasp the concepts of induction and well ordering etc.. I’ve been struggling with the exercises for a very long time and it’s really frustrating. I can easily deal with any type of proofs that i saw before ( eg. once i saw the proof of a recurrence question i became pretty good at prooving them). My problems start when i face an unusual question. I feel like i am memorizing the proofs rather than learn how to prove. is there any way ( or any resources) that can improve my proving skills ? in a way that whenever i see an unusual question ( like the checkers tiles and chess tiles type of questions) i dont have to stare at them for 2 hours before giving up

Mathematical limits on lossless data compression

Let’s say Bob wants to send a particular binary sequence to Alice. Imagine that Bob and Alice both have powerful machines but slow Internet connections. Bob could just send the sequence directly but the upload and the download would take a lot of time. Instead Bob could send a program that outputs the sequence. Assume Bob and Alice have agreed on the programming language they will use beforehand (be it C++ or Iota).

Two natural questions are what is the smallest possible size of the source file and how to find a program attaining the lower bound for a given sequence (e.g. can it be done algorithmically for any sequence or at least for some sequences). Have these questions been studied?

Essence of the cost benifit obtained by using “markings” in Fibonacci Heaps (by using a mathematical approach)

The following excerpts are from the section Fibonacci Heap from the text Introduction to Algorithms by Cormen et. al


The authors deal with a notion of marking the nodes of Fibonacci Heaps with the background that they are used to bound the amortized running time of the $ \text{Decrease-Key}$ or $ \text{Delete}$ algorithm, but not much intuition is given behind their use of it.

What things shall go bad if we do not use markings ? (or) use $ \text{Cacading-Cut}$ when the number of children lost from a node is not just $ 2$ but possibly more ?

The excerpt corresponding to this is as follows:

We use the mark fields to obtain the desired time bounds. They record a little piece of the history of each node. Suppose that the following events have happened to node $ x$ :

  1. at some time, $ x$ was a root,
  2. then $ x$ was linked to another node,
  3. then two children of $ x$ were removed by cuts.

As soon as the second child has been lost, we cut $ x$ from its parent, making it a new root. The field $ mark[x]$ is true if steps $ 1$ and $ 2$ have occurred and one child of $ x$ has been cut. The Cut procedure, therefore, clears $ mark[x]$ in line $ 4$ , since it performs step $ 1$ . (We can now see why line $ 3$ of $ \text{Fib-Heap-Link}$ clears $ mark[y]$ : node $ у$ is being linked to another node, and so step $ 2$ is being performed. The next time a child of $ у$ is cut, $ mark[y]$ will be set to $ \text{TRUE}$ .)


[The intuition of why to use the marking in the way stated in italics portion of the block above was made clear to me by the lucid answer here, but I still do not get the cost benefit which we get using markings what shall possibly go wrong if we do not use markings, the answer here talks about the benefit but no mathematics is used for the counter example given]


The entire corresponding portion of the text can be found here for quick reference.

A pretrained model for mathematical equations characters detection

I am working on a project to convert equations to LaTeX code. After segmenting out the characters, I got stuck on the detection part and was looking for some pre-trained model that could detect characters of the equation for later conversion to LaTeX. Is there any such pre-trained model available on the internet that could be used in Python to identify characters. If not then can somebody share some source to find a dataset to train such kind of model in Keras? I was able to find one on GitHub but It doesn’t detect symbols accurately.

Complicated problem involving mathematical induction


We are collecting donations to buy a new chair. We receive $ m$ donations in total $ d_1, d_2, …, d_m \in \mathbb{N}$ ($ m \geq 1$ and every donation $ d_i$ is whole-numbered, i.e $ \in \mathbb{N}$ ). A chair costs $ c$ dollars, where $ c \in [m].$ (Notation: $ [m]$ $ :=$ $ \{1, 2, …, m\}$ ).

Prove using mathematical induction over $ m$ , that there exists two numbers $ k, l$ with $ k \leq l$ such that the sum of the amount of donations $ \sum _{s=k} ^l {d_s}$ is exactly sufficient to purchase $ x$ chairs ($ x \in \mathbb{N}$ ) without any money being left.

I’m unable to find the correct approach to solve this. I’m sure the Pigeonhole Principle will be useful here, but I don’t know how to correctly apply it within the induction proof. Can someone point me in the right direction?

Intersection algorithim for finding the intersection points of two arbitrary mathematical curves

I’m looking for an intersection algorithm for finding the intersection points of two arbitrary mathematical curves. Websites like Desmos, GeoGebra, and WolframAlpha allow you to graph and/or input two(Or more but I’m only interested in two) curves to find their intersection points. I know all of the services I’ve listed have some form of API, my problems with those APIs are the technical and practical restrictions. Therefore, I’d like to just use the algorithms they use under the hood. Problem comes when I don’t even know the names of those algorithms or even whether they’re public domain. I’ve done some searching around but I can’t seem to find what I’m looking for. So I guess what I’m asking for are some basic design descriptions/requirements for these algorithms so I can implement one of them. I figured this problem wasn’t really a question for the mathematics StackExchange or StackOverflow So I decided to place it here. Let me know if that’s a problem.