```
capabilities, which sounds super cool!
The code in this section was tested on `sympy==1.8` and
``` 3.9.5.
Let's start with some basics. :
``
from sympy import *
sympify(2)/3 + sympify(1)/2
``
outputs:
``
7/6
``
Note that this is an exact value, it does not get converted to where precision could be lost!
We can also do everything with symbols:
``
from sympy import *
x, y = symbols('x y')
expr = x/3 + y/2
print(expr)
``
outputs:
``
x/3 + y/2
``
We can now evaluate that expression object at any time:
``
expr.subs({x: 1, y: 2})
``
outputs:
``
4/3
``
How about a square root?
``
x = sqrt(2)
print(x)
``
outputs:
``
sqrt(2)
``
so we understand that the value was kept without simplification. And of course:
``
sqrt(2)**2
``
outputs `2`. Also:
``
sqrt(-1)
``
outputs:
``
I
``
`I` is the . We can use that symbol directly as well, e.g.:
``
I*I
``
gives:
``
-1
``
Let's do some trigonometry:
``
cos(pi)
``
gives:
``
-1
``
and:
``
cos(pi/4)
``
gives:
``
sqrt(2)/2
``
The exponential also works:
``
exp(I*pi)
``
gives;
``
-1
``
Now for some . To find the of the :
``
from sympy import *
x = symbols('x')
diff(ln(x), x)
``
outputs:
``
1/x
``
Just read that. One over x. Beauty.
Let's do some more. Let's solve a simple :
``
y''(t) - 2y'(t) + y(t) = sin(t)
``
Doing:
``
from sympy import *
x = symbols('x')
f, g = symbols('f g', cls=Function)
diffeq = Eq(f(x).diff(x, x) - 2*f(x).diff(x) + f(x), sin(x)**4)
print(dsolve(diffeq, f(x)))
``
outputs:
``
Eq(f(x), (C1 + C2*x)*exp(x) + cos(x)/2)
``
which means:
$$
f(x) = C_1 + C_2x e^x + cos(x)/2
$$
To be fair though, it can't do anything crazy, it likely just goes over known patterns that it has solvers for, e.g. if we change it to:
``
diffeq = Eq(f(x).diff(x, x)**2 + f(x), 0)
``
it just blows up:
``
NotImplementedError: solve: Cannot solve f(x) + Derivative(f(x), (x, 2))**2
``
Sad.
Let's try some :
``
from sympy import *
x, a, b, c = symbols('x a b c d e f')
eq = Eq(a*x**2 + b*x + c, 0)
sol = solveset(eq, x)
print(sol)
``
which outputs:
``
FiniteSet(-b/(2*a) - sqrt(-4*a*c + b**2)/(2*a), -b/(2*a) + sqrt(-4*a*c + b**2)/(2*a))
``
which is a not amazingly nice version of the . Let's evaluate with some specific constants after the fact:
``
sol.subs({a: 1, b: 2, c: 3})
``
which outputs
``
FiniteSet(-1 + sqrt(2)*I, -1 - sqrt(2)*I)
``
Let's see if it handles the :
``
x, a, b, c, d, e, f = symbols('x a b c d e f')
eq = Eq(e*x**4 + d*x**3 + c*x**2 + b*x + a, 0)
solveset(eq, x)
``
Something comes out. It takes up the entire terminal. Naughty. And now let's try to [mess with it]:
``
x, a, b, c, d, e, f = symbols('x a b c d e f')
eq = Eq(f*x**5 + e*x**4 + d*x**3 + c*x**2 + b*x + a, 0)
solveset(eq, x)
``
and this time it spits out something more magic:
``
ConditionSet(x, Eq(a + b*x + c*x**2 + d*x**3 + e*x**4 + f*x**5, 0), Complexes)
``
Oh well.
Let's try some .
``
m = Matrix([[1, 2], [3, 4]])
``
Let's invert it:
``
m**-1
``
outputs:
``
Matrix([
[ -2, 1],
[3/2, -1/2]])
``
= SymPy special function
{c}
{parent=SymPy}
= python/sympy_cheat/logarithm_integral.py
{file}
{parent=SymPy special function}
{title2=`li`}
= Scientific visualization
{parent=Scientific software}
= Chart
{parent=Scientific visualization}
{wiki}
= Chart type
{parent=Chart}
= Histogram
{parent=Chart type}
{wiki}
= Scientific visualization software
{parent=Scientific visualization}
https://en.wikipedia.org/wiki/Scientific_visualization
[Ciro's] large dataset survey: {full}.
= Open source scientific computing consultancies
{parent=Scientific visualization software}
Huge respect to this companies.
= Enthought
{c}
{parent=Open source scientific computing consultancies}
{wiki}
= Kitware
{c}
{parent=Open source scientific computing consultancies}
{wiki}
= Plotting software
{parent=Scientific visualization software}
= Real time live plot from streaming data
{parent=Plotting software}
E.g. showing live data from a scientific instrument! TODO:
* https://superuser.com/questions/825588/what-is-the-easiest-way-of-visualizing-data-from-stdout-as-a-graph
* https://unix.stackexchange.com/questions/190337/how-can-i-make-a-graphical-plot-of-a-sequence-of-numbers-from-the-standard-input
* https://stackoverflow.com/questions/44470965/how-can-you-watch-gnuplot-realtime-data-plots-as-a-live-graph-with-automatic-up
* https://stackoverflow.com/questions/14074790/plotting-a-string-of-csv-data-in-realtime-using-linux
* https://stackoverflow.com/questions/11874767/how-do-i-plot-in-real-time-in-a-while-loop-using-matplotlib
= Survey of open source interactive plotting software with a 10 million point scatter plot benchmark by Ciro Santilli
{c}
{parent=Plotting software}
https://stackoverflow.com/questions/5854515/large-plot-20-million-samples-gigabytes-of-data/55967461#55967461
By .
\Image[https://raw.githubusercontent.com/cirosantilli/media/master/VisIt_zoom_in_10_million_straight_line_plot_with_some_marked_points.png]
{source=https://stackoverflow.com/questions/5854515/large-plot-20-million-samples-gigabytes-of-data/55967461#55967461}
= Matplotlib
{c}
{parent=Plotting software}
{tag=Python library}
{wiki}
It does a huge percentage of what you want easily, and from [the language that you want to use].
Tends to be [Ciro]'s pick if can't handle the use case, or if the project is really really serious.
Couldn't handle exploration of large datasets though:
Examples:
* \a[matplotlib/hello.py]
* \a[matplotlib/educational2d.py]
* \a[matplotlib/axis.py]
* \a[matplotlib/label.py]
* Line style
* \a[matplotlib/line_points.py]
* \a[matplotlib/tick.py]
* \a[matplotlib/prop_cycle.py]
* Subplots
* \a[matplotlib/subplots.py]
* \a[matplotlib/subplots_add.py]
* \a[matplotlib/two_lines.py]
* \a[matplotlib/plot_matrix.py]
* \a[matplotlib/plot_matrix_x.py]
* \a[matplotlib/legend_outside.py]
* Data from files
* \a[matplotlib/plotfile.py]
* Specialized
* \a[matplotlib/bloch_sphere_walk.py]
* \a[matplotlib/bloch_sphere.py]
Tested on Python 3.10.4, .
= gnuplot
{c}
{parent=Plotting software}
{wiki=Gnuplot}
Tends to be 's first attempt for quick and dirty graphing: https://github.com/cirosantilli/gnuplot-cheat[].
. When it get the jobs done, it is in 3 lines and it feels great.
When it doesn't, you Google for an hours, and then you give up in frustration, and fall back to .
Couldn't handle exploration of large datasets though:
= gnuplot command line hello world
{c}
{parent=gnuplot}
https://askubuntu.com/questions/277363/gnuplot-not-showing-the-graph-window/683073#683073
CLI hello world:
``
gnuplot -p -e 'p sin(x)'
``
= Software bug
{parent=Software}
{wiki}
= Formal verification
{parent=Software bug}
{wiki}
= Formally verified
{synonym}
= Glitch
{parent=Software bug}
{wiki}
A glitch is more precisely a that is hard to reproduce. But it has also been used to mean a software bug that is not very serious.
= Debugging
{parent=Software bug}
{wiki}
Debugging sucks. But there's also nothing quite that "oh fuck, that's why it doesn't work" moment, which happens after you have examined and placed everything that is relevant to the problem into your brain. You just can't see it coming. It just happens. You just learn what you generally have to look at so it happens faster.
Related:
* {child}
= Ciro's call hierarchy notation
{c}
{parent=Debugging}
This is a simple hierarchical plaintext notation created to explain programs to himself.
It is usuall created by doing searches in an , and then manually selecting the information of interest.
It attempts to capture intuitive information not only of the call graph itself, including callbacks, but of when things get called or not, by the addition of some context code.
For example, consider the following :
``
f1() {
}
f2(i) {
if (i > 5) {
f1()
}
}
f3() {
f1()
f2_2()
}
f2_2() {
for (i = 0; i < 10; i++) {
f2(i)
}
}
main() {
f2_2()
f3()
}
``
Supose that we are interested in determining what calls `f1`.
Then a reasonable call hierarchy for `f1` would be:
``
f2(i)
if (i > 5) {
f1()
f2_2()
for (i = 0; i < 10; i++) {
f2(i)
main
f3
f3()
main()
``
Some general principles:
* start with a regular call tree
* to include context:
* remove any blank lines from the snippet of interest
* add it indented below the function
* and then follow it up with a blank line
* and then finally add any callers at the same indentation level
= Bisection
{disambiguate=software engineering}
{parent=Debugging}
One of the Holiest age old debugging techniques!
has some helpers to help you achieve bisection Nirvana: https://stackoverflow.com/questions/4713088/how-to-use-git-bisect/22592593#22592593
Obviously not restricted to software engineering alone, and used in all areas of engineering, e.g.