Author Topic: Arithmetic is Drudgery  (Read 3966 times)

0 Members and 2 Guests are viewing this topic.

Nation of One

  • { }
  • { ∅, { ∅ } }
  • Posts: 4756
  • Life teaches me not to want it.
    • What Now?
Re: Arithmetic is Drudgery: Linear Programming
« Reply #45 on: March 02, 2018, 03:41:03 pm »
This site has automated how to use the simplex method [by hand algorithm] for solving a linear programming problem.  It solves for minimization as well as maximization and shows ALL the steps.

Pretty remarkable, I think.

SIMPLEX

min z = 5x1 + 6x2 + 4x3
subject to
10x1 + 12x2 + 6x3 >= 750
5x1 + 2x2 + 7x3 >= 600
3x1 + 11x2 + 2x3 >= 280
x1 + x2 + x3 = 100
and x1,x2,x3 >= 0


I chose Minimize and Fraction MODE.

This shows all the steps, which is what I happen to be practicing BY HAND at the moment.

For the record, sage is able top solve this as well, but none of the work is shown.

I typed this up at cocalc.com, but I suspect I can't make it public since i refuse to pay $7 per month just to show a couple people this kind of thing.  I guess they don't really care about amateurs and hobbyists and are aiming at an audience of graduate students and professional mathematicians.   ::)

You can cut and paste this into a sage cell:


p = MixedIntegerLinearProgram(maximization=False, solver = "GLPK")
x, y, z = p['x'], p['y'], p['z']
p.set_integer(x)
p.set_integer(y)
p.set_integer(z)
p.set_objective(5*x + 6*y + 4*z)
p.add_constraint(x + y + z == 100)
p.add_constraint(10*x + 12*y + 6*z >= 750)
p.add_constraint(5*x + 2*y + 7*z >= 600)
p.add_constraint(3*x + 11*y + 2*z >= 280)
p.solve(), p.get_values(x), p.get_values(y), p.get_values(z)

But, by all means, check out aToZmath.

I'll attach the output I got. 

Solving graphically becomes problematic with three variables and impossible with more than 3, so I've been practicing the Simplex Method by hand even though sage handles the work fine (better than me). 

I don't care how slowly I have to work through the arithmetic at each step.  I just want to know how tedious it all is by hand ...
« Last Edit: March 02, 2018, 04:29:20 pm by Non Serviam »
Things They Will Never Tell YouArthur Schopenhauer has been the most radical and defiant of all troublemakers.

Gorticide @ Nothing that is so, is so DOT edu

~ Tabak und Kaffee Süchtigen ~

Nation of One

  • { }
  • { ∅, { ∅ } }
  • Posts: 4756
  • Life teaches me not to want it.
    • What Now?
While attempting to solve some algebra word problems outside in the cold while smoking the first cigarette of the day, while using the simple idea of direct proportion to solve the problems was a "breeze," when it came to calculating the numerical result, while I had a feel for the size of the result, as well as the exact numbers to multiply and divide, I found the effort involved in reckoning to be drudgery, just as Arthur Schopenhauer claims it to be.  So, after doing the arithmetic in pencil, I figured that, rather than waste a heap of scrap paper on work "below the dignity of a sentient life-form," I figured I might go through the "drill" type exercises with the assistance of a computer algebra system.  The important thing, I figure, is to know how to apply certain knowledge to solve a problem, to set up the mathematical model.    The arithmetic involved in computation, while tedious, can be handled by a machine once I have the equations set up properly.

When I returned indoors, I fired up the computer, opened a web browser, and did a search for "why arithmetic is so difficult even for mathematicians".

I hit upon an essay, which was not even remotely related to what i was looking for, called When Even Mathematicians Don't Understand the Math

''Our brains evolved so that we could survive out there in the jungle,'' he said. ''Why in the world should a brain develop for the purpose of being at all good at grasping the true underlying nature of reality?''

The essay was more about the writings one finds in "popular math and science books" that attempt to explain theories to the "layperson".  It astounds me that those who claim to be interested in such theories would find basic algebra problems somewhat challenging.

But this is not the kind of difficulty I wish to explore.  I am simply curious about a certain inherent laziness of the mind which confronts us on a subjective level when we must perform the operations of multiplication and especially division. 

Even Karl Gauss recognized that of the four arithmetic operations, division was the most troublesome, so he sought a method of converting division into multiplication where possible.   This work led him to the publication of his masterpiece, Disquisitiones Arithmeticae [Latin for Arithmetical Investigations] in 1801, when he was 24.  I suppose Schopenhauer would have been a young teenager at that time, maybe studying algebra and Latin/Greek?

An aside, it is not necessary to memorize the year 1788.  Simply associate age 30 with 1818.  I had always heard as a child that "Jesus of Nazareth" quit carpentry at age 30 and from then on wandered around talking to people in the streets and drinking wine, getting into trouble with the local thought police.  So, it makes sense for me to be impressed with Schopenhauer getting his opus published at the tail end of 1818, maybe even the start of 1819, when he still would be age 30.

When I saw 1801, I just subtracted 1801 from 1818 [= 17], then subtracted 17 from 30, hence, Arthur S being 13 at the time.   Of course, 1788 + 13 = 1801, but one has to wonder, why is Herr Hentrich so obsessed with Schopenhauer that he would interrupt a totally unrelated topic by mentioning how old he would have been when Karl Gauss published Arithmetical Investigations in 1801?

Well, you see, my lonely reader, it is Arthur Schopenhauer, after all, who was one of the rarest of men of intellect to be so kind-hearted as to give positive affirmation as to the "difficulties inherent in arithmetic, in calculating and reckoning," the tedium of it, the MECHANICAL NATURE of the operations which tax our limited short term memory capacity, where we are prone to make errors - not LOGIC errors, but basic computational arithmetical errors.

In "Arithmetical Investigations," Gauss defines two integers a,b to be congruent modulo n if (and only if) a - b is divisible by n.  Thus, integers can be grouped into distinct residue classes modulo n.  Why is this useful? you might wonder.

Well, it is not my intention to go on a tangent about congruence and modular arithmetic.  I only wished to confess that, especially in the early mornings, if i have to solve problems which involve repeated divisions, I see no harm whatsoever in using calculators and computers.

Although, it is still cool to learn about different tips and tricks for reckoning without instruments.  I suppose it must depend on one's mood at any given moment, and the situation.   If outdoors, without access to any instruments, well, it is a good feeling to be able to find the square root using the Old School Square Root Algorithm which I taught myself while spending the entire month of February birthing a program which might one day serve as evidence of a manic, somewhat insane, but focused logician dwelling somewhere in this skinny lazy bag of bones that only faintly resembles his ape-like ancestors.

People get a kick out of a gorilla strutting about on two legs while carrying an apple so as not to get his hands dirty (a neat freak gorilla) - so fascinated are we by this that it is put on the evening news broadcast.

Well, I and the rest of us "useless eaters" are also primates, but the little feats we pull off with our fingers, thumbs, and computers are considered just goofing off.  Many gorts would be no more impressed with that console program, were they to have witness me in the throes of debugging and testing, than they would be with watching someone play Black Jack on the computer.   They would not see the math going on in my ape head.

But alas, I rattle on and on, perhaps as a way to avoid another long day filled with the drudgery of arithmetic and the somewhat less tedious and almost pleasurable application of algebraic manipulations, which still must bow down to the fundamental operations of arithmetic and how these operations' behavior is defined over the given set of numbers.

Is there a way to make such activities less tedious?  Is there a way to become genuinely interested in the problems at hand? 

The reason I have been devoted to exploring these old high school textbooks is because I have discovered many treasures within them as far as the exercises and learning experiences go.  I am free to LEARN without having to adapt myself to any community college type "title" or have the government declaring me a "student".

I am a god damned student!  I don't need to pay any institution in order to explore subjects I find worth revisiting.   The educators test you and tell you that you have all the prerequisites and back ground knowledge to pursue a degree in nuclear fuucking physics.   I want to study some fundamentals without the ape politics of gathering in rooms which promote pissing contests.

I'm sorry.  Was I raving?

There are times I do enjoy doing most if not all the work by hand, including (nearly all) the arithmetic, but its nice to have a "computer assistant". 


These skills are a kind of intellectual technology which our ancestors have fought hard to create and to pass on to us, skills which are not part of our natural environment and which come to us only after hard work and study.
  ~ Sam Nelson (Why Math?)


The question remains, Why is arithmetic such drudgery, even for "trained" mathematicians?

Well, arithmetic is not considered mathematics, not proof based mathematics; and yet Edmund Husserl and many other minds from that time period were examining the Foundations of Arithmetic.

Sure, arithmetic is not like set theory, but the two basic operations of addition and multiplication are everywhere, multiplication being defined via addition.   The electrical engineers and all who design hardware cannot escape the arithmetical nature of the contraptions they design.

That is too mind boggling for me to reflect on.  I have my plate full with some regular old word problems.   The trick is to find whatever it is you are going over INTERESTING. 

Without that, it is just dead matter with patterns of ink on pages or electronic monitors.

The magic happens between the ears and nowhere else.  It's more of a psychological issue.  Maybe before the appearance of "psychology", the ancients might have considered this a "spiritual" issue.    Can one muster enough "grace" and "humility" to devote one's limited attention to the matter at hand?

Math is in our heads even when it is scribbled on paper or coded into a computer algebra system.

What makes something "interesting" is a matter of taste.

A simple example:

A salesperson makes a commission of $756 on sales of $5400.  At the same rate, what commission would she make on sales of $6500.

Since the problem involves money which could be used to purchase groceries or pay bills, the problem would be of practical concern.

The key to the solution is recognizing this as a problem of direct variation where y1/x1 = y2/x2

We have the solution immediately upon seeing 756/x = 5400/6500

So x = 756 * (6500/5400)

Does this have meaning?  Definitely.  It is the solution to the problem.

Do we want to leave it at that or simplify it into something more meaningful in terms of dollars or pesos or whatever?

If so, do we need an electronic brain to assist us?  Do we need to use long division?

My personal approach to arithmetic involving fractions is to simplify in steps, a kind of divide and conquer into steps my old brain can handle in a calm manner.

I first simplify 6500/5400 to 65/54 then note that both 756 and 54 are divisible by 9, that is, they have the common factor 9.

So, the first two steps look something like this (on paper. mind you - not in my head):

 x = 756 * (65/54) = 84 * (65/6)

From there, even though 6 divides 84, I add a step by dividing 84 and 6 by 2:

x = 42 * (65/3) = 14 * 65

I am posting all these details so as to humbly lay bare the ape computer made of meat in my head, and the way it functions.  It's nothing to be ashamed of.  This is our shared mental apparatus.

For me, it is easier to multiply 7 * 130 than 14 * 65, so, even though this is arithmetic, using the distributive, associative, commutative axioms and the substitution properties of algebra, I can manipulate the integers in a way that suits my taste.

x = 14/2 * 65*2 = 7 * 130

By multiplying one factor by 1/2 and the other by 2, I have in effect multiplied entire the expression by 2/2 = 1., thereby writing an equivalent "name" for the same value.

x = 7 * 130 = 7*100 + 7*30 = 700 + 210 = 910

She makes $910

Is the name $910, or even just 910, more meaningful than 756 * (6500/5400) ?

Of course it is.

Even in this age of calculators and computer algebra systems, it is worthwhile to KNOW OURSELVES, and part of our "selves" if that ape-like intelligence which reckons, that creature who may have been born into a society which values mathematics enough to mandate the youth be instructed in it somewhat.  No matter how far one advances in their exploration of the edifice of "Mathematics" as a discipline, one never transcends the limitations of our mental apparatus when it comes to the arithmetic operations.

Of course, it is a personal decision as to when to "play around" with reckoning without instruments, and when to depend on a computer algebra system or a basic calculator.

When dealing with money, if it is large amounts, it's a good idea to use a calculator since one or two digits can make a huge difference.

Two decimal places error turns $5000 into $500000 or $10 into $0.10 (10 cents).

One might get to the end of a complicated problem in integral calculus and make one tiny arithmetic error on the last line.  Then the bridge collapses and you go to jail.

It's quite possible that I only write down word problems (in my math notebooks) for posterity once i have solved the problem on scrap paper first.  I don't want to feel embarrassed while the ape (me) is reckoning, sometimes with brute force.  I only document the more elegant form of the solution.

The above problem would never be documented since I find it too trivial; but I still like to look at such problems just to note where and when I am inclined to reach for a pencil, whether I use scrap paper or whether I wish to document it for some future reference.  At what point do I resort to SymPy or Sage or one of my homegrown math programs?   There's no shame in any of this.   I simply make observations of my own behavior as though I were viewing a documentary on national Geographic.

It's really all just a journey of exploration in following the advice that the dark-skinned Oracle gave way back when to the Greeks:  "Know Thyself."

Revisiting old "Algebra 2 & Trigonometry" texts, with their wide assortment of exercises and problems, presents a tremendous arsenal of opportunities for me to become more deeply acquainted with this elusive notion of a self, a phenomenon which does not seem to be a static entity, but is more of a state or processes forever transforming and destined to evaporate into thin air.     :-\
« Last Edit: July 25, 2019, 10:10:52 am by gorticide »
Things They Will Never Tell YouArthur Schopenhauer has been the most radical and defiant of all troublemakers.

Gorticide @ Nothing that is so, is so DOT edu

~ Tabak und Kaffee Süchtigen ~

Nation of One

  • { }
  • { ∅, { ∅ } }
  • Posts: 4756
  • Life teaches me not to want it.
    • What Now?
Re: Arithmetic is Drudgery - LPs in SageMath
« Reply #47 on: May 19, 2018, 08:14:12 am »
There is a concise explanation under the heading "How can I solve a linear program using Sage ?" on this page.

From the note at the very top of the page, it would appear that Nathann Cohen, the author of the page, has great resentment over the idea of any individual corporatizing SageMath and "making lots of money" off the work put in by the many contributors of the Open Source code upon which Sage is built.

I know such a statement is difficult to ignore, and I am not suggesting that such a statement be ignored.  I just want to point out that it was not the motivation for me providing the link to the page.   The motivation for the link is the following:

----------------------------------------------------------------------------------------------
Nathann Cohen :

Sage can solve Linear Programs or Mixed Integer Linear Programs through the class 'MixedIntegerLinearProgram' defined in 'sage.numerical.mip'. To illustrate how it can be used, we will try to solve one easy problem



First, we define our MixedIntegerLinearProgram object as a maximization problem:

  sage: p=MixedIntegerLinearProgram( maximization=True )


We then define the objective using p[1] and p[2] as variables. Not that we could have picked `p["x1"]` and `p["x2"]`, or even `p[("x",1)]` and `p[("x",2)]` : any hashable Sage object is a valid key, as it would be in an usual Python dictionary !


  sage: p.set_objective( 2*p[1]+p[2] )


The two constraints :

  sage: p.add_constraint( 3*p[1]+4*p[2], max = 2.5 )
  sage: p.add_constraint( 1.5*p[1]+0.5*p[2], min = 0.5, max = 4 )


Our problem is now defined, and we can now ask Sage to solve it.
( be assured that you have installed the Sage package for Coin-OR CBC or GLPK. If you do not, see the Solvers section at the bottom of this page )

  sage: p.solve()
  1.6666666666666665

The value returned by the ``solve`` method is the optimal value of the objective functions. In order to obtain the optimal values, you have to use the ``get_value``

  sage: print "The optimal values are x_1="+ str(p.get_values(p[1])) + "x_2= "str(p.get_values(p[2]))

All in all, here is how to solve this system

  sage: p=MixedIntegerLinearProgram( maximization=True )
  sage: p.set_objective( 2*p[1]+p[2] )
  sage: p.add_constraint( 3*p[1]+4*p[2], max=2.5 )
  sage: p.add_constraint( 1.5*p[1]+0.5*p[2], max=4,min=0.5 )
  sage: p.solve()
  1.6666666666666665

  sage: print "The optimal values are x_1 = "+str(p.get_values(p[1]))+", x_2 = "+str(p.get_values(p[2]))
  The optimal values are x_1 = 0.833333333333, x_2 = 0.0





Dictionaries of variables in ``MixedIntegerLinearProgram``



For more complex Linear Programs, it is sometimes useful to associate many parameters to the same object. Instead of using just one dictionary, it is possible to create many of them using the method ``new_variable`` : if several objects `B1, B2, ...` all have both a "value" and a "cost", the two being variables of the same linear program, you can define two dictionaries to store them

  sage: value = p.new_variable()
  sage: cost = p.new_variable()

It is now possible to define constraints mixing the two different kinds of variables
  sage: p.add_constraint( cost[ B1 ] +  3*value[ B2 ], max = 9)
« Last Edit: May 19, 2018, 08:17:32 am by Non Serviam »
Things They Will Never Tell YouArthur Schopenhauer has been the most radical and defiant of all troublemakers.

Gorticide @ Nothing that is so, is so DOT edu

~ Tabak und Kaffee Süchtigen ~

Nation of One

  • { }
  • { ∅, { ∅ } }
  • Posts: 4756
  • Life teaches me not to want it.
    • What Now?
Re: Arithmetic is Drudgery
« Reply #48 on: October 22, 2018, 11:28:35 pm »
In a poetic mood I think, "It is not mathematics which is difficult, but living as a biological creature which makes it so."

It's as though one must detach from the living breathing worrying anxious animal body in order to compute, calculate, rationalize ...

For life is an irrational force, and we are irrational creatures.

Life does not compute.  Life does not make any sense.  This life is painful to witness and experience.

There is something lacking in mathematics that makes it incapable of describing our world in human terms. 
« Last Edit: July 25, 2019, 04:46:21 pm by gorticide »
Things They Will Never Tell YouArthur Schopenhauer has been the most radical and defiant of all troublemakers.

Gorticide @ Nothing that is so, is so DOT edu

~ Tabak und Kaffee Süchtigen ~

Nation of One

  • { }
  • { ∅, { ∅ } }
  • Posts: 4756
  • Life teaches me not to want it.
    • What Now?
Re: Arithmetic is Drudgery
« Reply #49 on: July 25, 2019, 12:03:31 pm »
OK, so, I've been forcing myself to do away with this idea that "arithmetic operations are beneath the dignity of a sentient life-form," and have a more relaxed attitude when confronted with "arithmetic operations which require effort and care."

For instance, suppose you come across the "fraction,"  0.015625/8.5

You have choices as to how you will proceed.   Long division?   You can either do it first and deal with shifting decimal places, or, and this is my preference, do your "work" with rational numbers and save the long division for last.   You can't get around it.  Most of us are brainwashed to believe we "have more important or more interesting things" we could be doing, and that doing arithmetic by hand is irresponsible and even reckless, knowing how easy it is to miscalculate (just once is all it takes).   

What I have tried:

Suppose you have to square 4.125
Using the long-form multiplication we've used since childhood, that is four rows of numbers (four multiplications added), producing 17.015625

The other way comes from (a + b)^2 = a^2 + 2*a*b + b^2, where a = 4 and b = 1/8

(4 + 1/8)^2 = 4^2 + 2*4*(1/8) + (1/8)^2 = 16 + 1 + 1/64 = 17 + 1/64

Since 1/64 = 0.015625, 17 + 1/64 = 17.015625

This is what I ran into approximating the square root of 17 with f(x) = x^2 - 17 = 0

Hence, f(4.125) = -17 + 17.015625 = 0.015625
For the derivative, the old-school table is more trouble than it's worth, and I compute f'(4.125) = 2*4.125 = 8.25 (direct substitution).

So, the next x, say x3 = x2 - f(x2)/f'(x2) = 4.125 - f(4.125)/f'(4.125)

= 4.125 - 0.015625/8.25

Again, without a computer program (app on so-called "smart phone") or at the very least, a 10 dollar solar powered calculator, fractions such as "0.015625/8.25" require setting up the long division problem 15625/8250000.

Again, for whatever reasons, I am "repelled" by the thought of proceeding in such a manner.   If my life depended on another person reckoning correctly, and I mean EXACTLY with care, I would be in trouble.   Most people really don't want to be bothered with this kind of "work."   

So, my idea was to see if I might explore alternative ways of dealing with such "numbers.'

We know 0.015625 = 1/64 and that 8.25 = 33/4

I feel a little relief upon jotting down 0.015625/8.25 = [1/64] / [33/4] = [1/64]*[4/33]
 = 1 / (16*33) = [1 / 528]

Now, let's be honest, I think I have a better "feel" for the nature of 0.015625/8.25 when it is written in its rational form, 1/528.  Will this help?  Let's see … since 4.125 = 4 + 1/8 = 33/8,

4.125 - 0.015625/8.25 = 33/8 - 1/528 = 4 + 1/8 - 1/528 = 4 + (66 - 1)/528

= 4 + 65/528

Now I just do this smaller "long division" to get the result 0.123106, hence x3 = 4.123106.

I choose 4.123

If I want to prove to myself that this is correct to 4 figures, I have to apply the Newton-Raphson iteration one more time.    This is the phase where the numbers can get just wild enough to discourage you from proceeding.     I suspect that in this phase, my proclivity for the rational form will be seriously challenged.  That is, I will have to be flexible and proceed in a calm manner.

And remember, I'm 52 years old and I'm no dummy.  I have to drive my mom to yet another doctor in about 20 minutes, so must throw down some eggs.

I don't have time to walk through the next step, but my sage/python code will give a hint of what I'll be pecking at while waiting 2 hours.

I run rsd then rsd_Rational for x = 4.123, first with 4 figures, then with 6:


sage: rsd(P, 2, 4.123,4)


 x = 4.123 |         | f(4.123)
---------------------------------------------------
        |  1    4.123   -0.0009
        |  1.0  8.246 =  f'(4.123)

 f(4.123) = -0.0009
 and f'(4.123) = 8.246

        nextX = 4.123 - [f(4.123)/f'(4.123)]

        = 4.123 - [-0.0009/8.246] = 4.123  + 0.0001

         = 4.123105626970652 ~=~ 4.1231


sage: rsd_Rational(P, 2, 4.123,4)


 x = 4123/1000 |             | f(4123/1000)
---------------------------------------------------
        |  1    4123/1000       -9/10000
        |  1    4123/500 =  f'(4.123)

 f(4.123) = -0.0009
 and f'(4.123) = 8.246

        nextX = 4.123 - ( [f(4.123)] / [f'(4.123)] )

             = 4.123 - ( [-0.0009] / [8.246] )
             = 4123/1000  - ( [-9/10000] / [4123/500] )

           = 4123/1000  + [34107446034441/312500000000000000]
           = 4.123  + [0.0001]

         = 4.12310914382731 ~=~ 4.1231


Changing the last number (number of significant figures):

sage: rsd(P, 2, 4.123,6)


 x = 4.123 |         | f(4.123)
---------------------------------------------------
        |  1    4.123   -0.000871
        |  1.0  8.246 =  f'(4.123)

 f(4.123) = -0.000871
 and f'(4.123) = 8.246

        nextX = 4.123 - [f(4.123)/f'(4.123)]

        = 4.123 - [-0.000871/8.246] = 4.123  + 0.000106

         = 4.123105626970652 ~=~ 4.123106


sage: rsd_Rational(P, 2, 4.123,6)

 x = 4123/1000 |             | f(4123/1000)
---------------------------------------------------
        |  1    4123/1000       -871/1000000
        |  1    4123/500 =  f'(4.123)

 f(4.123) = -0.000871
 and f'(4.123) = 8.246

        nextX = 4.123 - ( [f(4.123)] / [f'(4.123)] )

             = 4.123 - ( [-0.000871] / [8.246] )
             = 4123/1000  - ( [-871/1000000] / [4123/500] )

           = 4123/1000  + [3300842832888679/31250000000000000000]
           = 4.123  + [0.000106]

         = 4.123105626970653 ~=~ 4.123106


Gotta eat … need fuel … must help the Mother.

« Last Edit: July 27, 2019, 04:51:09 pm by gorticide »
Things They Will Never Tell YouArthur Schopenhauer has been the most radical and defiant of all troublemakers.

Gorticide @ Nothing that is so, is so DOT edu

~ Tabak und Kaffee Süchtigen ~