This note is about some math concepts that can be converted into that you can easily write, they'll define some useful things in maths, which are generally not in the modules, but are needed at times.
So, these programs can really help you reduce calculations, they can do the calculations for you...
New addition here
This is a program to print prime numbers till a range. (This is not written by me, but i felt like sharing because it's way useful)
Input and it prints a list of all primes till the number .
img
If you want it to get simple, just add the line and then wanted changes in .
This function is defined for coprime integers and , that is inverse of modulo if
It is used when you want to perform actions like division in modulo, and also, it is used in the application of CRT (The Chinese Remainder Theorem).
The Python program that prints the Inverse of a number is as follows, after you type this program and input , it will return the inverse of modulo .
img
is the number of ways of choosing objects from a set of identical objects.
It is defined as (where is factorial notation)
It is useful in many (almost all) Combinatorics Problems and some Number Theory problems can be designed on them.
The Python program that prints value is as follows
mg
So when you input after typing this program, you'll obtain the output as
It is defined as the number of congruences of powers of , after which the remainder starts repeating.
For example,
See that the congruence will repeat again after , that means the remainder is repeating after multiplying by , so order of modulo is
>>> Note that order can be mentioned as the least positive integer for which (This can be treated as the definition for ).
It's easy to see that if , then we'll have,
For example, if , say for numbers and ,
So order of 8 modulo 14 is . (Though
This is an extremely important thing in modular arithmetic and tedious calculations of remainder are reduced to simpler ones.
However, it's not that easy to find order of larger integers modulo some other large integers. So here is the python code that prints Order of modulo ( if ), when you input
img
Note+Exercise:- Try to extend this program to numbers with (A simple manipulation will do)
This note might perhaps seem obvious to expert people, so note that it is for beginners and learners.
When I think of some new program related to Maths, I will be adding to this note.
If you all have any suggestions (additions), i would like to learn the new techniques of converting maths to Programming. Please comment and I will make sure it's included in the note.
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
Superb note! Also congrats on being selected as Moderator!!
Of course this is a good idea, but as someone who has written Python code for a living I feel compelled to suggest a few improvements:
1) Finding modular inverse using brute force is exponential in the size of the input. We can easily make it polynomial by adapting Euclid's algorithm for GCD a bit:
2) Finding factorials is expensive. We can do much better by using a tuple as a representation of a fraction and using the fact that nCk = (n/k) x (n-1)C(k-1):
Alternatively, if you are okay with multiplying large numbers but don't like taking gcds each time,
3) For the gcd = 1 case we don't even need to keep the list:
For the gcd != 1 case we do need something but a dict is probably the better solution. Something like this:
Congratulations Aditya on being selected as moderator
Log in to reply
Thanks friend ! I'll give all efforts possible to make Brilliant free of problematic problems and spam comments...
Thank you. I know C , But not python. I will learn it. I love programming a lot.
Awesome....Have you heard about pygame module of python @Aditya Raut ?If yes,have you created any game using it?
Log in to reply
Not heard, I am still a learner and I learn Python from self study... So I don't know what pygame is, will search !
Log in to reply
Congrats for being selected as a moderator.
You guys may also want to look into IPython, Numpy, SciPy and Sage.
Log in to reply
IPython and Sage both use Numpy, SciPy and and other libraries to make programming easier. In particular Sage focuses on math. In fact in Sage:
And for binomial coefficients:
Don't know about mod order, but there may be something like it in sage. Examples taken from the docs. This doesn't even scratch the surface of what you can do with Sage.
Sir, How to create a program that inputs 2 numbers then get the GCF of it? in C language please.
Log in to reply
@Jep Iglesia , I'm your age, 1 year younger as per what your account shows, So don't call me sir... I'm not knowing C that much, I learn Python..... but I've got a friend who can help you... I'll ask him to post that
@Aamir Faisal Ansari
Log in to reply
Sir Thank you sir. You know I'm used to call Sir/Ma'am in Internet. Its a kind of showing respect.
Use Euclid Algorithm: see http://stackoverflow.com/questions/19738919/gcd-function-for-c
Sympy module in python is amazing.