Thursday, October 10, 2024

Inversion

Inversion is a process of working backwards, or inverting operations to solve a problem. Example of inverse operations are addition and subtraction. They are each an inverse of the other. Multiplication and division are inverses. Just as you can work backwards to check a solution to a problem you can work through inversion to find many ways to solve problems from the mundane to the extremely complex.



We can use inversion to add two numbers without adding. In, fact we can use it to add through the use of subtraction.  For example: we can add 3 + 5 by subtraction. First we will subtract 3 from 10 to get 7 then from 7 we well subtract the next number 5 to get 2. We can then subtract 2 from 10 again to get 8.



Now this seems an incredibly long way to add two numbers together. Yet, the importance is not in the specific inversion itself. It is in the way of thinking that it promotes. The ability to conceive of a new way of approaching a problem can often lead to a more profound discovery. It could lead you into finding a way to solve entire groups of problems.



It is a simple concept, work backwards. Look at the data and work backwards to determine the source.
An example can be found in inverse scattering problems. These problems look at the scattering to determine the source, or likely causal factors. Such as in sonar technologies. You look at the variations in the sound wave echos to locate objects.



The inverse scattering problem solving technique is also used in medicine. The Positron emission tomography (PET) scan uses the detection of photon bursts from the beta decay of radioisotopes.
Then working to generate an image of the targeted tissue from the scattered data.



It it is based on the category of problems called inverse problems. In these problems the likely source is the unknown, and only through inversion can you find trace back to the source. It is probably the most important class of problems, with this most important process of solving them.

Kindergarten Math worksheets

I know that I haven't posted in a while, I have been very busy getting my daughter ready to start kindergarten. In doing this, I found that worksheets have been extremely helpful. So I created a few math worksheets of my own to help out. I decided I would share them with you so you may download and print the the worksheets below.  You may need to open them on a new page to get them zoomed to the right size for printing.


Forms and Algebra



                When studying mathematics at any level, one might find themselves asking where did this stuff come from? , or why is this useful?.  The answer to these questions can be summed up in one word , Algebra.    Why algebra? Why is it so important?  Well, let’s look at what algebra actually means.  Algebra, throughout history, has developed many rules, relations, and symbols to answer some of the everyday problems we encounter.  The history of algebra and how it was formed, in my opinion, has little to do with what it actually means. I will instead explain algebra by use of philosophy. We can call it the philosophical theory of algebraic reasoning.

The Theory of forms and Algebra

      The theory of Forms is basically that real-world objects have forms. For example, when you look at your table, how do you know it’s a table?  In fact, your table could be extremely different from all other tables, but you know it’s a table because it has the form of a table. The form of a table is that it has a flat surface at the top, and a support structure at the bottom.  The Form of the table can be restated as the abstraction of a table.  By having the abstract model or form of a table, we can then manipulate or customize our table to look how we want so long as it stays within the basic bounds of the form.  We can also now take our base form and use it to define specific types of tables.
    Algebra works in the same way as the theory of forms. In algebra we use letters to symbolize or initialize the form of a number. We call the letters variables because they can change their value. Let’s look at the statement 1+1=2. Even though we have numbers and not variables this is still an abstraction. This is a perfect abstraction for general purposes it gives us a specific form unity. The 1 is the form or abstraction of a real world object. It can be any object as long as it is a single object. So to translate this statement we would say that a single object and a single object together has the form of two objects.  For most the meaning of this statement is obvious, however; the statement a + a = b is not as obvious. Also, this statement does not mean the same as 1+1=2.   Table + Table = 2 tables this statement is equivalent to 1+1=2 only because we are assuming the Knowledge of what the symbols 1, 2, + , =, represent. So we build our philosophical theory of algebra off of the assumption that we don’t need to define the symbols for numbers and what they mean.
     The symbols 1 and 2 have a very specific meaning, but their properties, and interactions have a more complicated philosophical meaning. So we have a gap in our ability to abstract numbers and their properties, which is why we use the letters or variables.  The variables are in fact a form of a form. Sounds redundant, but it is necessary to provide abstraction from something that is already an abstraction. This concept is where it gets a little tricky.  We can say a variable is the form of a number but not all numbers only numbers that have the specific properties we provide with the rest of the statement. Take our a + a = b statement. This statement gives us a relationship between any two numbers that can be represented in this form a + a = b which has many numerical equivalences.                            It can mean 1+1 =2, 2+2 = 4, 3+3 =6, 4+4 = 8…etc. In fact this statement provides an abstract definition of even numbers.  Statements like this should then be called definitions of forms.  We shall go back to our table example again. The basic form of a table is flat surface at the top and support structure at the bottom. What if we said table + wood? We are giving an abstract definition of tables that are made out of wood. So table + wood is the same as a + a =b they are both abstract definitions of forms.   The only difference is abstract definitions of numerical forms take a little more interpretation. However both assume an understanding of something else. The table + wood example assumes an understanding of the form of wood and the form of table. The a+a=b example assumes an understanding that 2,4,6,8,10…etc are called even numbers. a+a=b just gives us a definition of even numbers without trying to list all of the even numbers up to infinity. So abstraction is actually necessary to define specific numbers and number relationships, because we cannot realistically list every even number to infinity.

Why is algebra the heart of mathematics?


                The abstraction of algebra gives us strong foundation by which to build many more complex definitions with a wide range of uses in everyday life. A lot of these concepts we use every day without even realizing it. In fact nearly every branch of mathematics would not exist without the foundation laid down by algebra. For example statistics, uses many definitions that would not exist without the framework of algebra. We even use algebraic concepts in many other subjects. For example in composition classes we use abstraction as a tool to write papers we start with an outline, which is simply an abstraction. Our outline gives us a simple abstract definition of our paper which makes writing our paper much easier.  Language itself is an abstract definition of our thoughts and feelings.   

Multiplication with positional notation and the distributive property

In this post we will be learning how to use positional notation to perform multiplication.
If you need a review on positional notation please refer to my previous post on this subject.
Positional Notation

To refresh on what positional notation looks like we will write the number 235 with positional notation.





With a smaller example we can see if this allows us to learn something new about multiplication.
So to multiply 32 and 24 we will first write these two numbers into positional notation.







Does this look familiar? If we replace the 10 with x and since 100 = 1 we will
 replace it to and then we have:.







To put into a more familiar form:

(3x + 2)(2x + 4)

With our number in this form we can now use basic algebra.

From distributive property.
a(b+c)
=
(ab)
+
(ac)

We can now multiply this out using what is sometimes referred to as the foil method *(First Outer Inner Last)
















Now if we substitute the 10 back in for x











To see how this works scaled up we will multiply 3259 and 1564





And again we can put this into the familiar form:Now again to replace the 10 with x and since 1(x) is just x we remove the 1 in the second number:




Now we gather like terms:

If we put the 10 back in for x then multiply we will get




And here is our answer using positional notation and distributive property to multiply two numbers. 
5,097,076

5th Iteration Minecraft Mighty Menger Sponge!!!!!!!!!!!!!!!




In an earlier post I created a 4th iteration 160,00 block Menger Cube in minecraft. After I discovered the newly added structure block I was able to construct the 5th iteration 3,200,000 block version.




After I cleared out a large enough area all the way down to bedrock I began construction.


Here is the bottom section with 5, 4th iteration menger cubes


















The 32x32x32 limit of the structure block meant that I had to use 3rd iteration 8,000 block menger cubes Menger cubes to construct this because the 4th iteration was more than the 32 cubed or 32,768 limit.

An fun side note is that I constructed this with x = 0, z  =  0 at the very center.















With the bottom section of 8, 4th iteration Menger cubes finished I it was time to do the second row of 4,




And the beginning of the top row of 8, 4th iterations menger cubes




From the above picture you can see the outline of the structure block for the 3rd iteration Menger cube. It takes 20 of the 3rd iteration to make a 4th iteration so for each of the 20, 4th iteration cubes I had place the structure block 20 times. That is still a huge drop from having to place each of the 3.2 million cubes.


If you can't make out the y coordinates below this structure goes from y = 0 to just under the minecraft build height limit. What this means is that the 6th generation is not gonna happen in minecraft unless that limit is changed.




Another side note a quick way to clear an area using the structure block is to save a 32x32x32 area of just air then use the structure blocks in the area you need to clear. You could also use the /fill command to fill an area with air but I like the structure block approach.


Here is a few shots of the finished product a megalith of 3.2 million blocks!!!!!!














And here is a few shots of me starting to decorate the inside.




5th iteration menger



Tuesday, October 8, 2024

Does poverty hurt academic success?

          While reading through the various new articles about test scores, I have seen a common argument about poverty affecting test scores.  Is this true or is it just an excuse?

I will start out with a personal note. I was a very impoverished teen in high school. I had to work two jobs while going to school. My parents were so poor I eventually had to live with my grandparents, who although were not much better off than my parents, they at least provided a steady home.

However they were unable to afford all of the things that I needed for school. My school required special clear backpacks which my family could not afford. I had to buy those and  I was responsible for all of my clothing, car payment and insurance.
School supplies was another expense I had to work for.

While most students were sitting at home doing homework or out with friends, I was at work. I became an emancipated teen so I could work the late hours I needed just to survive financially.  Unlike the students who would go out with friends I was unable to stay up late doing homework, or do it in the morning before class. I worked so late that I was already only getting a few hours of sleep.  I did however pay attention in class, and read while on my lunch breaks at work.

Luckily most of my teachers, would focus on teaching an understanding of material rather that just rote memorization. My teachers also spoke to me on their level like I was a colleague in some situations, or they would at least speak to me like an adult rather than like a third grader. Not all of them were like this, I did have some bad teachers. However, most of it was due to the student to teacher ratio being so unbalanced that inexperienced teachers had to sometimes ":fill in" the gaps.  No matter how old you are , most teachers treat their students like small children.

 I believe it was the way some of my teachers would treat me that helped me not only understand the material, but also have the desire and ability to learn on my own.
Due to school policies homework was 2/3 of the grade and I did very poorly in my classes. However all of my final exams were A's and B's, which is the only reason I was allowed to graduate.  ( thanks to an amazing teacher Mrs Janice Miller who rallied the rest of my teachers to get the school to allow me graduation and a diploma) I also was ale to achieve a 35 on the ACT test which shows that I was still able to learn despite my financial situation.

I have gotten a little off topic here, but I believe it is important to see that the way we treat students can go a long way in helping them learn. So if you have a student who is on a free lunch program or their parents can not afford all of the things they need for school, treat them like an adult who is at the same economic status that you are. They will respect you so much more for it , and will be more apt to get a lot more out of your lessons.

I will leave off with a question. Does how much money you have determine intelligence? Does a student whose parents can buy them a a brand new laptop, have an advantage over the student whose parents can barely afford  pencils and paper? Should we change how we teach students of different economic backgrounds?

The answer to all of these is no. If a course in high school is designed to require a laptop the school should provide one, or not require it. If a school is in a lower income district it should still get the same amount of funding that a school in a high income district gets.
















Wednesday, April 13, 2016

Minecraft 4th iteration Menger Sponge

Minecraft Menger sponge (Menger Universal Curve) :

The Menger sponge is a 3 dimensional cube that models the Sierpinski carpet. The Sierpinski carpet is a fractal generalization of the Cantor set.

The Sierpinski carpet is a 2 dimensional figure starting with a square and then subdividing into 9 sections. You then remove the center section.
  


The next step is to take the remaining 8 sections and repeat the process for each one.




After that you are left with an image where the middle section is missing from each of the 8 subsections of the original figure. You then take each of those subsections and repeat the process again. This will leave you with this figure:


You can then repeat the process again....













An amazing property of the Sierpinski carpet is that as the number of iterations of this process approaches infinity the area will approach 0
When this process is moved up into 3 dimensions you construct a Sierpinski sponge. The Menger cube is slight alteration of the Sierpinski sponge.

The Menger sponge has a similar amazing property that as the iterations approach infinity the Surface area approaches infinity and the Volume approaches 0..  



I created a 4 iteration Menger sponge in Minecraft, starting with a 3X3X3cube.



Then I removed the center block from each of the 6 faces.




I Then cloned this cube using the Minecraft /clone command to get to 20 cubes arranged to show the next iteration of the Menger sponge.






I then cloned that cube to make 20 more copies to construct the next iteration.




At this point I will note that for the Menger sponge the number of cubes (or in this case blocks) is given by the formula (Number of blocks) N = 20ⁿ where n is the number of iterations and the above cube is iteration 3. which is N = 20³ = 8000 blocks.

For the final project I decided to move over into my realms server and construct a 4 iteration Menger cube with N = 20⁴ = 160,000 blocks...!!!!





Saturday, April 9, 2016

The controversy with common core:

The controversy with common core:



     Math has become a new phobia among youth and current parents. It has many wearing math illiteracy as a badge of honor. The problem began with adults experiencing negativity at a young age toward the subject. It was often taught in very rigid and mechanical tone. The rigidity is where the problem we face today finds its roots. Math was drilled into our heads with the idea that there is only one way to do things, and anything else leads to lower grades. Many teachers were strictly against alternative methods, and led to an ingrained aversion to the subject for their students.


     Other issues include the teaching methods themselves, as well as the lack of guidance for students who may take longer to grasp the subject. In the interest of time, and testing, the teachers are encouraged to cover large amounts of material in a short amount of time. These factors in combination are what has resulted in the attitude toward math that parents possess today. This attitude is also being passed on to their children, by encouraging an avoidance of mathematics. The parents own aversion and lack of proper education in mathematics makes it difficult to understand the material their children are bringing home. The new common core standards and teaching tools are incredibly different from what many of these parents are familiar with.
      

      Currently students are being introduced new concepts for learning math with the development of common core. Altering how things are done, can be beneficial to finding better teaching options. Sure many of these methods are breaking from tradition, but as with all things we are learning. Which forces us to integrate new information and approaches to teaching. Parents and educators all need to stay aware of this. As we learn and grow intellectually, knowledge must force us to change. However, this change conflicts with the fact that the parents of these children are unable to help them to better their skills in these areas. Here we see the roots of the problem. The parents were not taught by common core standards, and therefore cannot aid their children until first learning the methods themselves.


     If parents or teachers see common core standards as a problem maybe schools could host a week long open seminar on what is actually going to be taught and how it is implemented. The schools could have qualified instructors in the common core standards come and talk with parents and teachers. They could even teach some of the new math strategies to the parents so they can be better informed on how to help their children adapt to the new material.


     Given the chance to come to understand the common core math standards could help change the way some respond to them. I understand the problems many people have with common core math. Seeing a drop in test scores with new standards being put into place is a shock, but when you look into it you see it is not the problem with the tests, it is us. We are failing our children. The common core math standards are well informed and vetted by leaders in the stem fields. And these are the things our children need to learn to remain competitive with their peers around the globe.




Friday, March 18, 2016

The largest prime

The largest prime number ever seen by humankind was found on January 7, 2016.  It weighs in at  22,338,618 digits in length. It is what is known as a Mersenne prime (274,207,281-1).  Mersenne primes are a group of prime numbers of the form 2n -1 where n is  is assumed to be prime. This is a fascinating find. Prime numbers are the "building blocks" of all other numbers.  Their unique nature has led many number theorists and math enthusiasts to study them in great detail. Although they are used heavily in cryptography, the latest find is far too large to be used in any encryption schemes to date. But as computation theory evolves and computer architectures become more sophisticated these extremely large primes may find their place.

Tuesday, September 22, 2015

The "common core check guy"

In the news recently, we see the story of Doug Herrmann. Doug is a father from Ohio who out of frustration with his child's math homework, wrote a check using common core methods. He was frustrated because he was unable to understand what the school was teaching his son, and therefore was unable to help his son with his math homework.

The ten card system that his “viral” check picture was intended to highlight is not a terrible method of mental math. One exception is that for some it abstracts the idea so far that it seems to become separate from the actual “math”. Utilizing grouping techniques is in no way a “bad” technique to understand mental math. However, it becomes a problem if too much emphasis is placed on a single rigid method.

Using the ten card system is one of many useful techniques for understanding grouping. We only run into problems when the standardized testing systems force children to “believe” there is only one right way. The testing should only test for the ability to solve problems and not for the strict adherence to a single “correct” way of getting there. The practice tests I have looked at appear as though they are actually structured that way. The second grade tests do emphasize place value, but do not seem to indicate a single method. Now as far as the rigidity of the teachers, I have not seen how this comes into play. I do know that in many instances students fall behind due to teachers being too strict in the techniques that you use.

Please understand that I am well aware that there has been a rising trend in math illiteracy. I am not completely blasting common core. I , along with other parents, have some questions about the implementation and flexibility of these standards.
Some questions I have include:
  • How flexible are the methods used ?
    • Are students being taught that the ten card system is the “only correct” method ?
    • Will students be penalized for utilizing other techniques to arrive at their answers ?
  • How are conflicts between common core, and how the parents teach their children handled ?
    • Do teachers penalize their students for the way their parents teach them to solve problems ?
  • Is there an awareness of the different ways people understand concepts ?
    • Is there an accommodation in place for students who understand place value through other means than just grouping visualizations? ( e.g. positional notation instead of ten cards.)
These questions go beyond just common core. The rigid adherence to single techniques has long been the culprit behind the fall in mathematics education.

On a personal note, I have been a victim to the rigidity of teachers. When I was in high school(many years before common core) I failed a math class simply due to my teacher not approving of my mental math techniques. To be fair, I would like to emphasize the math teacher was not actually a math teacher, she was a soccer coach moonlighting as a math teacher due to a poor student teacher ratio.
The conflict arose when I was forced to show my work(and by show my work I mean that my teacher wanted to see the remedial addition, subtraction, multiplication, and division) This was an algebra class, where showing your work meant to show the steps taken to simplify the expressions. However, this instructor insisted we not just show that we had to multiply she wanted to see the actual steps we took to multiply. I thought this was odd in an algebra class, because learning to multiply was second grade. However, I did comply and attempted to be verbose with “showing my work”. However, my method of “long hand” multiplication was different from what she was taught. Most people are taught the “only” way to multiply is to start in the one column and carry and borrow and all these other concepts. I used a more “short hand” method which lends itself well to mental math. I would start with the highest power of ten column and work left to right instead of right to left. For example if I were to multiply two digit numbers I would start in the tens column and multiply no need for carrying and borrowing. You are just simply adding up zeros. This method isn't understood by all, but it was how I understood numbers and place value. Unfortunately, my math teacher was strict and rigid in how she wanted it done and failed me on all of my quizzes. I understood the algebra part and understood the basic calculations part, and arrived at the correct answer. I just applied a different method for the basic calculations.

Now my story is sadly similar to many other students. For most, these situations reinforce their frustrations with mathematics. It can quickly lead students to make snap judgments about the efficacy of learning and understanding math. They soon start to see math as a foolish endeavor with rigid methodologies not worth their time. Or they could simply just give up believing they will never understand and struggle to merely pass.



 I don't exclusively place the blame on teachers for the problem of rigidity. The parents also hold a share of the blame. As with the “common core check guy” Doug Hermann and some of the comments on his posting, they also find themselves rigid in their understanding. Simply not understanding a technique of solving a problem does not condemn it. Rather, it simply means you should probably learn more about it before condemnation.  

Wednesday, July 1, 2015

Propositional calculus: an introduction

Propositional calculus is the branch of mathematics that deals with the rules of logic and evaluation of statements or propositions. It is sometimes referred to as sentential calculus for its use of the sentential conjunctions. It is primarily concerned generating laws for evaluating conjugated statements. Propositional calculus is part of a broader science of logic and proof.


Some of the symbols used in propositional calculus:

Symbol
Meaning
¬
Not or negation
^
and
v
or
implies
If and only if
P
Sentential Statement
Q
Sentential
Statement
T
True
F
False

In propositional calculus the above symbols are used in constructing truth tables for evaluating compound or conjugated sentences. The truth tables provide a short hand tool for deriving new laws from the simple compound sentential statements. Truth tables like the one below shows some of the simple rules and the new rules derived from those.


P
Q
PQ
P^Q
PvQ
(P^Q)P
P ↔ Q
T
T
T
T
T
T
T
F
T
T
F
T
T
F
T
F
F
F
T
T
F
F
F
T
F
F
T
T



This is just a simple introduction to propositional calculus, it is part of a much broader branch of propositional logic . It is useful in the formulation of logic rules, and methods of proof.

Saturday, June 20, 2015

The "Reality" of math and logic

Logic has been used as a methodology even before its formalization. In order to survive, our progenitors had to be able to deduce whether a particular place or event was dangerous. These more earlier versions of ourselves, needed to determine what was safe to eat and where food was located. In this sense they were using logic intuitively.

As societies evolved, we became aware of a need for a system of accounting. We developed symbols to serve as abstract models for real world objects. Empirically , we can demonstrate the need for a modeling system. We can also demonstrate that these models of real world objects work. The models functionality means they can be used for future discoveries, and aids in civilization building.

Enumeration permeates our entire civilization and history on multiple levels. It observably exists separate from language. From the simplest counting systems, patterns began to emerge. The laws of mathematics became more complex, and a method of proof was needed that was empirically verifiable. The earliest proofs were purely empirical as used by the Pythagoreans and Thales of Miletus. Over time, mathematical proofs slowly became less heuristic and a formalized system of logic was becoming more prominent. Logic was largely an emergent aspect of these methods of empirical verification. The methods of logical proof slowly grew over the next two and half centuries from Thales around 550 BCE to Euclid around 300 BCE. Euclid is credited with formulation of the axiomatic method of proof.

The Euclidean style of proof through axioms, appears assumptive, or only justifiable a priori.
The axioms served as descriptions or definitions of geometric objects. The definitions could be demonstrated empirically in general, but they did rely on assumptions. For example, take the statement 2 points determine a line. This is a postulate proposed as self-evident, and deduced from it is many other theorems. If you were to take this as meaning all statements derived rely on a non-empirical premise you would be incorrect. The statement can be demonstrated as empirically true. You would simply have to draw a line through only one point. The line drawn, would be a point and not a line. To construct a line you would have no choice but to have it pass through multiple points. So, we can see the statement is both self-evident and empirically demonstrable.

The evolution of mathematical systems of proof allowed for a more formalized system of logic. All of which finds its origins in our innate pattern recognition. The ability to recognize patterns and natural desire to seek them out led to the mathematical modeling of real world objects. The modeling techniques made a complete system of logic and mathematics more easily constructed and shared. We formulated logical and mathematically complete laws and theorems from some of the simplest models.
We see that these models are intuitive,empirical, and justified in their use.



Tuesday, June 2, 2015

Positional Notation

Positional Notation



Our number system is base ten, as many learned in elementary school. Which means that there is only ten symbols to represent numbers. 0,1,2,3,4,5,6,7,8,9 . To represent ten we use 1 and 0 (10). Which when we learned place value, we recognized this as 1 in the tens place and 0 in the ones place. What this means is that the position of the symbol will determine the value of the number. For example when we see the symbol 34 we recognize it as 3 tens and 4 ones. We would often see something like:
Tens ones
3 4



 We are mostly taught this and just accept it as is and move on. To dig a little deeper into to place value I will introduce a new way of looking at this (Positional Notation) . To rewrite our example ,34, into positional notation we get this:



3 x 10¹ + 4 x 10º



The reason I write it this way is that is represents a number as powers of the base it is in. In this case it is base 10. Positional notation gives us a way of looking at numbers relevant to their base. The reason this is useful to learn, is that it gives us a quick way to convert numbers from other bases to base ten. For example, if you need to convert the number 101 in binary to base 10 you can rewrite 101 in positional notation and convert it easily. Since 101 is in binary we will use powers of 2 instead of 10 and we get



1 x 2² + 0 x 2¹ + 1 x  2º
1 x 4 + 0 x 2 + 1 x 1
4 + 0 + 1
5


As you can see from the table above just by rewriting the number into positional notation relevant to the base it is in you add it all up and you get the number in base 10. So when we convert 101 from binary to base ten we get 5.


 This is just a neat little trick I use to quickly convert numbers from other bases to base 10. With a little practice, you can convert numbers from most bases back to base ten almost effortlessly. There is other ways of converting number to other bases, I just really like this one.    

Tuesday, July 30, 2013

Python and Prime number Lists

Prime numbers, although simple in definition, provide several complexities in the field of mathematics, as well as in computer science. For reference, prime numbers are natural numbers which are only divisible by one and themselves. On the surface, this definition seems straightforward and not an important area for research. However, there are a great many applications of prime numbers.  Prime numbers are essentially the building blocks of all other numbers.  For centuries, this unique set of numbers has mesmerized and even baffled some of the greatest mathematicians.  The distribution of prime numbers is another big area of mathematics research. It would be great if we could find a formula for the nth prime. Yet, it seems as though it would be impossible. We can however use computers to do this for us up to the limits of the processing power available.  No real efficient algorithms exist to find primes other than methods of iterating through every number up to the square root of a given number to determine if it is prime.  Finding the patterns with some high level mathematics, is being used but no solid proofs exist yet to revolutionize this area of research.  With this in mind I would like to continue with discussing python in mathematics. 

I previously showed a fairly simple program for Slope-intercept using python. The program served to output a formula in slope-intercept form given two points.   In another post on computer programming in mathematics, I included some Java code for testing if a number is prime. Below I have a Python code to ask for 2 numbers to serve as the starting point and ending point for  listing primes within that range.  I have not included any error checking or input checking,  so it is important to ensure this code works you must enter an integer greater than 1. If you do not do this you will not get a meaningful output or you will get errors.   This was written and tested in Idle 3.2 so it may not work as expected in other versions.  This code also utilizes the standard sieving algorithm to perform its prime checking so it is by no means efficient for larger inputs and can be very processor intensive
.   CAUTION!!!  only use this code to list primes in small ranges CAUTION!!!   The caution is here because I have locked up my computer trying to list primes from 2 – 10,000,000 I would recommend running it on ranges in the 100's It was originally written for educational and research purposes only.   I generally use it to write primes to text files to print out as educational resource materials.


#primecheck(x) checks if x is prime returns boolean#
def primecheck(x):
    i=2
    for i in range(2,x):
        if x%i == 0:
            return False
    return True
#primelist(start,stop) lists all prime numbers between start and stop#
def primelist():
    start = int(input('Enter starting point must be an integer greater than 1:  '))   
    stop = int(input('Enter ending point must be an integer greater than 1:   '))  
    i=2
    primeList = []
    for i in range(start,stop):
        if primecheck(i) == True:
            primeList.append(i)
    return primeList


print (primelist())

Sunday, July 28, 2013

Python Slope-Intercept

Python  is a wonderful programming language for quickly coding solutions to many problems. You can download python by going to python.org/download and selecting the version that’s best for your operating system.  Python can run from command line or though Idle that comes with most python downloads.   I have been working with python for almost a year now and it has become my “go to “for  
a lot of work in mathematics. It is not necessarily the “best” language for processor intensive mathematical algorithms, but it can offer efficient and quick solutions that can be easily applied to larger projects.  Recently, I have been doing some review of linear algebra and slope-intercept formulas. This is a fairly simple subject in mathematics but I thought it might be interesting to use python to solve some of these problems.   My solution might not be elegant but it is fairly simple.  I designed the program to take in two points (x1, y1), (x2, y2)  and output an equation of the line in slope-intercept form.   For those who may not be familiar slope-intercept form it is  y = mx + b where m is the slope and b is the y- intercept. The slope is calculated from the two given points by the formula (y1-y2)/(x1-x2) and the y -intercept can be found by 
b = y – mx.


Slope-intercept is useful in linear depreciation models.  For example:  if you bought a car at $81,292 and after 10 years it is only worth $33,121 to find out how much it will be worth after 13 years you can use slope-intercept to get a depreciation formula. The two points are at 0 years it is 81,292 (0, 81,292) and at 10 years it is 33,121 (10 , 33,121) substituting these numbers into our formulas you first find the slope which will represent the rate of depreciation.  You use the slope formula (y1-y2)/(x1-x2) 
(33,121 – 81,292) / (10-0) = -48,171 / 10 = -4817.1   and the y intercept is b = y – mx. 81292- 0(4817.1) = b= 81292 and putting it together you get y = (-4817.1) x + 81292 using this formula we can then determine the value of the car at 13 years by substituting 13 in for x
y = (-4817.1)13 + 81292 and we get 18,669.70 so after 13 years our car is worth $18,669.70
The Python code to find our linear depreciation formula is fairly straight forward


def slope():

    result = ''
    x = float(input("enter x one"))
    y = float(input("enter y one"))
    a = float(input("enter x two"))
    b = float(input("enter y two"))
    slope = (y-b)/(x-a)
    yint = y - (slope*x)
    if yint < 0:
        sign='-'
    else:
        sign='+'
    result = str("y="),str(slope),str("x"),sign,str(yint)
    return result
print(slope())


I use the input() method to take in the two points (x,y), (a,b)
then create a variable named “slope” and then immediately assign it to the formula to find the slope given 2 points (y-b)/(x-a). I then create a variable yint and assign it to the formula for the y-intercept. The if-else statement I use to aid with formatting because generally the + (plus sign) isn't displayed when you get a positive. The final line print(slope()) is there only for when you are running the code in console or idle if you were to convert this to a python module it won't be needed.  
I am sure there are more elegant and efficient ways of doing this as well as built-in python methods to make it display much better but that’s the beauty of python it’s easy to modify and play around with to get desired output style.