C ++ Embedding Mathematical Formulas

I like to know best practices for documenting mathematical formulas in C ++ code.

Ideally, this could be ideal to be able to write equations directly in comments, but it does not seem possible to write them in human-readable form.

I looked at LaTex, MathML, and the syntax is complicated when working with many people coming from different horizons (after all, not all are mathematicians). If you have experience in this area, please comment.

For example, Im adds a cross-reference to external HML files in every function that needs to be documented, but is difficult to maintain. I tried the Doxygen formulas, and most of us have found that the syntax is very complex.

\f[ |I_2|=\left| \int_{0}^T \psi(t) \left\{ u(a,t)- \int_{\gamma(t)}^a \frac{d\theta}{k(\theta,t)} \int_{a}^\theta c(\xi)u_t(\xi,t)\,d\xi \right\} dt \right| \f] 
+4
source share
3 answers

You can always use "ASCII" art. If your editors support Unicode (in particular, UTF-8 encoded), all the better. It can be more readable when you really look at the code. Although saving it couldn't be simpler than TeX syntax. For instance.

 // β”‚ ⌠T { } β”‚ // β”‚ | { ⌠a dΞΈ ⌠θ } β”‚ // β”‚ I β”‚ = β”‚ | ψ(t) { u(a,t) - | ------ | c(ΞΎ) u (ΞΎ,t) dΞΎ } dt β”‚ // β”‚ 2 β”‚ β”‚ | { ⌑γ(t) k(ΞΈ,t) ⌑at } β”‚ // β”‚ ⌑0 { } β”‚ 
+4
source

If you have complex mathematical equations that require all kinds of characters, you better write them in your functional documentation, rather than in the code documentation. those. separate document.

+3
source

The LaTeX syntax is not too complicated and much more readable (and accessible to humans!) Than MathML (well, this is an opinion). A little practice helps, but it's not something you won't pick up in a couple of hours. In my experience, writing math text in LaTeX is by far the most convenient option.

Depending on how complex your formulas are, or rather, whether you need fashionable characters, I would say that you can embed formulas in the code and use doxygen or, as already noted, create a separate document.

+1
source

Source: https://habr.com/ru/post/1392894/


All Articles