experience-monks / math-as-code Goto Github PK
View Code? Open in Web Editor NEWa cheat-sheet for mathematical notation in code form
License: MIT License
a cheat-sheet for mathematical notation in code form
License: MIT License
It appears many notations can also be expressed as unicode. Not sure if it's useful, but it might be worth considering. So far these are the pros / cons I could think of:
pro
con
100
∑ i
i=1
100
∑ (2i+1)
i=1
3 6
∑ ∑ (3ij)
i=1 j=4
6
Π i
i=1
â
Thanks!
Where are the integrals?
I thought I was the only one who had a hard time with mathmatical notation. This is exactly what I needed (and what I always thought would be a great idea) to aid my personal CS/game programming studies.
Just thought I'd say thanks! ❤️
May I make a section showing how to calculate gravity in JS through canvas animation?
at the Sigma part:
var sum = 0
for (var i = 1; i <= 100; i++) {
sum += i
}
var n = 100 // upper bound
var sum = (n * (n + 1)) / 2
shouldn't n be i?
Nice project. In my line of work, the "hat" over variables typically means that the variable is an estimate of some unknown quantity. An example is here: http://mathworld.wolfram.com/MaximumLikelihood.html
The maximum likelihood estimate for a parameter mu is denoted mu-hat.
In mathematics, the := =: and = symbols are used for definition.
Are all three equivalent? If not, would you kindly explain the differences? If so, would you mention please that they are exchangeable?
Thank you _very much_ for writing this. I have wanted a document like this forever.
Disclaimer: This is a bot
It looks like your repo is trending. The github_trending_videos Instgram account automatically shows the demo gifs of trending repos in Github.
Your README doesn't seem to have any demo gifs. Add one and the next time the parser runs it will pick it up and post it on its Instagram feed. If you don't want to just close this issue we won't bother you again.
I think that it should be noted that the JS code isn't equivalent, as in math the '=' sign denotes an alias when used as presented.
I saw that you noted that 'x' is just another name, but further clarification would be beneficial in my opinion.
Hope this helps.
PS: Love your effort. I think it will be useful for a lot of people. If I get some free time, expect some pull requests from me. Keep up the good work.
It's probably worth noting that floating point numbers are rational numbers (as well as real and complex).
The number hierarchy is usually ordered by inclusion:
It helps in explaining how each type of number contains the previous numbers.
Great page. Just trying to help. Thanks!
These explanations are really cool, thanks for this. It turns something abstract into something tangible that a developer can play with. To build on this, I would love to see a transpiler that leverages these explanations to turn mathematics into executable javascript, and potentially turn executable javascript into mathematical notation. It would go a long way towards demystifying scientific research for the layprogrammer.
I think it might be more mathematically "correct" to use Sets instead of Arrays for Elements ("In"/"Not In"). Most of the time, mathematicians make the assumption that they are working on sets (uniqueness, abstract ordering) instead of lists. I know it depends on usage, especially with respect to game and graphics dev, but I think the ES6/Harmony API for Set is pretty nifty!
Matrix A dot Matrix B
where the dot is usually a small circle (not sure if there's a unicode character for it)
cross product is also a peculiar x, but is not the same as matrix multiplication or component wise multiplication
GitHub supports executing and rendering Jupyter notebooks which would be much more maintainable and expressive (especially since you can use numpy
to execute all kinds of math operations out of the box).
Another big benefit is that you can have GitHub render math notations for you instead of including lots of images in the repo (+ you get retina support!).
Example on GitHub using Jupyter:
I really love this project, and think it could be a fantastic way for math and physics students in particular to become familiar with a programming language.
Any prospect for a Python language version?
...And other symbols found in http://enigma.media.mit.edu/enigma_full.pdf ?
Would be good to render it white when the background is dark.
Do you have any contributing rules for other languages such as Python and Go?
Branch:
https://github.com/Jam3/math-as-code/tree/feature/derivatives-integrals
Let me know if there's problems. Some of these are pretty challenging to explain in code / developer terms. 😕
Ideally I'd like to find a less "mathy" way of demonstrating this part, to make it a bit more code/newb-friendly. Basically the whole "derivatives" section could do with a clean up.
Some of the SVGs are failing because the site hosting them is 503ing.
Could switch to @blixt's SVG Latex viewer. Or maybe save them (eg gh-readme-scrape) and host them in GitHub since this guide has stabilized for the time being.
sum([k for k in range(100)])
output: 4950
The reference said output: 5050
Which would be
sum([i for i in range(101)])
Note: Real numbers are also finite, as in, not infinite.
I don't think this expresses well what it is trying to express. I'm guessing that it is referring to the check && isFinite(k)
to exclude ∞ (Infinity
) from ℝ, which in itself is correct, as infinity is not a Real number. But, saying that "infinity is not a real number" is different from saying that "real numbers are finite". This second way of saying it may confuse people with the fact that "ℝ is of infinite size", i.e. that "there are infinite real numbers".
What I think may mark the difference is that, in english, "Real numbers" usually refers to all of them as a whole, while "A Real number" refers explicitly to any individual Real number. I think a better way of saying this could be something along the lines of "Note: Infinity
is not a Real number" or maybe "A Real number is also finite, as in, ∞ ∉ ℝ").
I have personally wrote C++ code representations for all the functions and notations referred in the current readme file and also have implemented some extra features, such as 2D point, 2D line class, 3D point, 3D vector class, and all their calculative functions(addition, negation, dot product, scalar product,perpendicular eqn of a line, parallel eqn of a line). Plus for the ease of use of geometry, I have implemented translation, rotation, scaling etc functions for the above classes. If permitted, I would like to add them in a new file dedicated towards C/C++ developers.
I've had a few comments so far that the define/equality section is not really accurate to the language of mathematics.
Hopefully this is more accurate:
https://github.com/Jam3/math-as-code/tree/fix/definition#equals-symbols
the code example goes like this
var b = [nextafter(0, Infinity), 1] // interval closed on the left
var c = [0, nextafter(1, -Infinity)] // interval closed on the right
however, I think the correct version is
var b = [nextafter(0, Infinity), 1] // interval closed on the right
var c = [0, nextafter(1, -Infinity)] // interval closed on the left
{ 0, 1, 2, 3, ... } { 1, 2, 3, 4, ... }The latter is more common in computer science, for example:
function isNaturalNumber (n) { return isInteger(n) && n >= 0 }
the latter one is n > 0, not n>= 0
so which one is more common in computer science?
Add ES6 to some of the content like (Sigma).
Hello, we have indexd this cheat sheet to awesome-cheatsheet
Thank You !!! 🚀 🚀 🚀
primes represent the next value, for example:
A' = A * MVP
can be thought of as
A *= MVP
The single apostrophe is sometimes referred to as prime. "Matrix A prime is the result of matrix A times matrix MVP"
Imagine I was looking for some symbol description.
What if I could come here, ⌘ + f
, and then search for something, that looks like what I'm looking for.
For example <=>
or /=
.
The exclamation mark has many uses in mathematics. We can take a look at these as follows.
Exclamation mark !
in mathematics typically denotes the factorial operation.
This expression means "the product of the integers from 1 to n". For example, 4!
(read four factorial) is 4 × 3 × 2 × 1 = 24
.
In JavaScript:
function factorialize(num) {
if (num < 0)
return -1;
else if (num == 0)
return 1;
else {
return (num * factorialize(num - 1));
}
}
factorialize(5);
The double factorial is an extension onto the normal factorial function. It is denoted with two exclamation points: a!!
.
The double factorial of an integer n
is defined recursively as:
The double factorial is not defined when n
is a negative even integer. Also do not confuse the double factorial for a factorial computed twice.
The double in double factorial represents the increment between the values of the terms when the factorial is expanded into a product. In the case of a regular factorial, each factor is decremented by one, from the number 'a' to 1. In the case of a double factorial, each factor is decremented by two.
The double factorial terminates with the sequence of evens, for example: 4 × 2 × 0!!
or the sequence of odds: eg 5 × 3 × 1!!
where 1!! = 0!! = 1
.
In JavaScript:
function doublefactorial(num) {
if (num < 0)
return -1;
else if (num == 0 || num == 1)
return 1;
return (num * doublefactorial(n - 2));
}
Additionally, exclamation mark can also represent uniqueness in mathematics and logic. The phrase "there is one and only one" is used to indicate that exactly one object with a certain property exists and this sort of quantification is known as uniqueness quantification or unique existential quantification.
Uniqueness quantification is often denoted with the symbols ∃! or ∃=1. For example, the formal statement
may be read aloud as "there is exactly one natural number n
such that n - 2 = 4
".
If exclamation mark used in front of a number, it can represent a subfactorial. The nth subfactorial (also called the derangement number) is the number of permutations of n objects in which no object appears in its natural place (i.e., "derangements").
The first few values of !n for n=1, 2, ... are 0, 1, 2, 9, 44, 265, 1854, 14833, ... For example, the only derangements of {1,2,3} are {2,3,1} and {3,1,2}, so !3=2. Similarly, the derangements of {1,2,3,4} are {2,1,4,3}, {2,3,4,1}, {2,4,1,3}, {3,1,4,2}, {3,4,1,2}, {3,4,2,1}, {4,1,2,3}, {4,3,1,2}, and {4,3,2,1}, so !4=9.
Sums and formulas for !n include:
In linear logic, the exclamation mark denotes one of the modalities that control weakening and contraction.
The exclamation mark is also used in programming, but not the way it's in mathematics. Several computer languages use "!" at the beginning of an expression to denote logical negation: e.g. "!A" means "the logical negation of A", also called "not A" and A != B means "A is not equal to B".
Resources
https://www.wikiwand.com/en/Exclamation_mark
https://www.wikiwand.com/en/Uniqueness_quantification
https://www.wikiwand.com/en/Derangement
http://mathworld.wolfram.com/Subfactorial.html
https://plato.stanford.edu/entries/logic-linear/
https://math.stackexchange.com/questions/67801/what-does-the-exclamation-mark-do
http://math.wikia.com/wiki/Double_factorial
https://medium.freecodecamp.org/how-to-factorialize-a-number-in-javascript-9263c89a4b38
The readme says sqrt(x^2) = x. But this is not true in general (take x=-1). In general it's equal to +/- x.
It probably should say sqrt(x)^2 = x, which is always true, and can be taken as a "definition" of the square root.
Variable name conventions href is incorrectly linked.
The guide is not complete. More planned features:
step()
)And generally:
First of all, I think this repository is a great initiative to help programmers delve into and understand theoretical (computer science) literature. However, it would be great if there were more content about the symbols used in (First Order) Logic. Logic sentences are often comprised of just these symbols, making them very hard to read without an intuitive understanding of them.
Personally, I find it very helpful to think about them programmatically when reading them, though not all symbols are equally simple to mentally model.
http://tug.ctan.org/info/undergradmath/undergradmath.pdf provides a nice summary of symbols
#12 is an example of another person with difficulties in this area.
Like
"Let x be ..." means x will be defined there, either explicit (you can code it directly) or as an element from an not fully known set, which should be explored in the remainder of the theorem.
"... then there exists a y ..." means y must exist, if the preconditions are met, but we do not neccessarly know how to find y.
And metaconcepts like:
In a paper the author can define anything he wants. There are many papers, which define "if CONDITION is met, the element is called admissable", but there is no general concept of admissable.
Authors also can redefine existing concepts like "in the following we assume all vectors are normed" (this means you need to make sure in your code, your vectors are normed). Some will even admit some easy going notation like "with a bit abusive notation we can write ..."
What do you think of me adding a pull request to add the vector variable to calculate vector magnitude? Can be done easily with Pythagorean theorem which most people will understand.
Element 1, 2 & 3 image symbols are missing.
This is a very useful resource thank you.
Could I potentially start a section on basic graph theory?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.