Author Topic: Programming as Mathematics  (Read 7056 times)

0 Members and 1 Guest are viewing this topic.

Nation of One

  • { }
  • { ∅, { ∅ } }
  • Posts: 4756
  • Life teaches me not to want it.
    • What Now?
Re: Programming AND Mathematics: HyperNotes!
« Reply #15 on: March 14, 2016, 10:03:38 pm »
Runge Kutta in C++

This code approximates e to 2.71828 which is close to the value which is close to the value of

e = 2.7182818284590452353602874713527

Interesting ...

This is why I find it so much more relaxing studying at my leisure, since, rather than racing through problems, I can go on a tangent in the midst of one little exercise.

Quote from: amiruddin
Can you solve this equation ?Given the first order differential equations below which is derived from series RLC circuit. Write a program to solve it using Runge-Kutta 4th order method. The output should be in graphical form, i.e. plot of i and q versus t.

Quote from: Bernard Hsu
Hi amiruddin,

you should be able to solve this using the first order differential equation derived from RLC circuit, which was likely covered in your class and lecture. put that equation into

static double dt_dt(double x, double y) { /* your equation here */ }

The output will only give the answer it converges on. If you want graphical output, you can write a method to write to a .csv file and graph from a spreadsheet program.

Cheers!

The output will be numerical and fed into the iteration process.

Anyway, there is a little typo in their code.  I wonder if it is even worth troubling them over.

I fixed it in the attached text file.  Just save as rk4.cpp and complie.

The little error is when they define halfdx = 0.5 * x;

It should be halfdx = 0.5 * dx;

It was a nasty little typo. I kept getting wrong results when I changed the code to handle a different differential.  So I stepped through it with gdb and I noticed halfdx kept coming up as zero when it should have been half of what dx was.

Also, when comparing the results to results I got by hand and with other programs and spreadsheets, the results were different.  I even checked definitions of Runge-Kutta method in textbooks to verify there is a slight error in their algorithm. I made the following three changes:

double rk4(double x, double y, double dx, double(*f)(double, double)) {
   double halfdx = 0.5 * dx;
   double k1 = dx * f(x, y);
   double k2 = dx * f(x + halfdx, y + k1/2.0);// changed from y + k1 * halfdx
   double k3 = dx * f(x + halfdx, y + k2/2.0); // changed from y + k2 * halfdx
   double k4 = dx * f(x + dx, y + k3); // changed from  y + k3 * dx
   return (y + sixth * (k1 + 2 * k2 + 2 * k3 + k4));
}


I also made the code interactive by changing main():

int main(int argc, const char * argv[]) {
  double x, y, dx, target;
 
  std::cout << "\nEnter initial value of dependent variable x: ";
  std::cin >> x;
  std::cout << "Enter inintial value of [dependent] function y: ";
  std::cin >> y;
  std::cout << "Enter the step size dx: ";
  std::cin >> dx;
  std::cout << "Enter the target value y(x): ";
  std::cin >> target;

  Equation eq(x, y, dx, target);
   eq.Run();
   return 0;
}
Other than that, this code is cool since it approximates differentials that might not be solvable by quantitative methods.  What's more, it is short and elegant.  The Runge-Kutta method is surprisingly accurate, even with with ridiculously large step-size.  I appreciate code that does a little task ... as I do not want to become too distracted with libraries such as boost.numeric.odeint ... although, if I live long enough, I would love to learn to use it.  First, I want to concentrate on understanding the mathematical concepts ... so I appreciate Python modules like SymPy as well as Sage which is built upon so much ...

Still, it is more than a little humbling to see that there is certainly no need to reinvent any wheels.  It will take a lifetime to explore, but this gives me even more motivation to continue to devote my energies to mathematical explorations ... god willin' and the crick don't rise ...  :-\

HyperNotes (sleepy time):

Computational Physics Programs C/C++

Polymatheia

Runge-Kutta 4th Order ODE Solver

Shampine and Gordon ODE Solver

odeint in boost?

Holy Fuuck, coders are busy bees out there ... It blows my mind.

Solving ODEs in C++

Peter Gottschling: Odient and MTL4

« Last Edit: November 12, 2019, 06:58:10 pm by _id_Crisis_ »
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?
math code and the will to know ...
« Reply #16 on: March 15, 2016, 10:35:02 am »
Looking through the boost libraries, you may sympathize with why I just like to make my own simple rudimentary code that does what I need it to do so I don't have to deal with the learning curve of compiling code that depends on huge libraries.

Now, I prefer to focus on the mathematics and keep my "mathematical code" as simple as possible.

For the Runge-Kutta method, I found that it was more efficient as far as time and learning curve to use LibreOffice Calc (spreadsheet) using a similar method as A Spreadsheet Solution Using the Fourth-Order Runge-Kutta Method

setting cell A1 as step size, h, I can easily just change that as I wrote each formula using $A$1

For other formulas, using syntax such as $C4 would update the row number (4) but leave column (C) constant.

I could analyse the data in a grid.

Now, I am not saying I am not at all interested in the ODE libraries for C++.  I just have to use self-restraint when it comes to my "Will to Know".

To get sidetracked into troubleshooting compile errors just to use odeint or mtl (boost) libraries would only frustrate me.  I want to stay focused on the textbooks working through problem sets, trying out the projects, and basically using CAS, graphing calculator, spreadsheets, tables, and even some home grown rudimentary C++ code ON THE FLY ---- spontaneously in a calm manner.

This is, after all, the benefit of not having to be subjected to some professor's or supervisor's arbitrary agenda!

I think it is ok to learn by reading other people's code ...

Methods

« Last Edit: March 16, 2016, 12:00:58 am by H »
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: math code ---> euler and runge-kutta
« Reply #17 on: March 16, 2016, 12:00:28 am »
I find it very satisfying to understand just enough about code and math to be able to find source code and alter it to suit my needs.  For instance, when in the start of a problem set in one of the DE texts, the authors suggest one use a computer algebra system, or, alternatively writing a program for solving initial value problems, I am thankful that I at least have the confidence to tweak the code ...

If someone's code is written for working with input and output files, I like to alter it to interact with me at the console.  Also, I don't mind redefining the differential equation for each case right in the source code and recompile it each time.  I just comment out all the equations in case I need one again.  Oh, and lest I pull the kind of thing Sickmind Fraud pulled (not acknowledging Schopenhauer's influence on his theories), I better mention that euler3.cpp was more than a little inspired by code written  Alex Godunov. Last revision - March 2007. I found it here, (Computational Physics Programs C/C++)


Also, at compile time, sometimes it is just something as simple as adding a flag such as -static or -std=c++11 to get it to run ...

When I wake up in the morning, I will be glad I tinkered on some code BEFORE diving into the exercises with pencil and paper.  Often, I like to transcribe the working source code into a notebook in pencil since the code itself basically explains the algorithms.   For years I have always liked to make code look as much like the mathematics as possible, calling functions simply f(x, t) or what have you.

Rather than have 3 separate programs to help me check some problems in a numerical methods section, this code (euler3.cpp) gives a menu:

 Solver for first order Ordinary Differential Equations
 
 x'(t) = f1(x,t)   equation
 x(ti) = xi        initial condition
 
 Methods (select one by a key)
 key = 0; simple Euler
 key = 1; modified Euler (predictor-corrector)
 key = 2; 4-th order Runge-Kutta

to compile with gnu gcc:

g++ -g euler3.cpp -o e3 -static

then, to run: ./e3

I like to slow down long enough to compare results with the "spreadsheet versions."

Actually, I find writing simple C++ code, even if spending a little extra time formatting the output so it's easier to read, ends up being more fun than using the spreadsheet method.  With the code, you just have to define the differential equation and recompile, whereas with a spreadsheet, you have to change the cell for y', and then copy and fill down - rather tedious. 

So, in the version I am using, I formatted the output for the console, even placing an increment counter n on both sides of the values of "independent variable" t and "dependent function" x.

I swear, 20 years ago, when I began studying programming in earnest and returning to college to start over with Calculus and Physics, this really is what I envisioned ... growing older by the day and being able to tinker around with computer programs that helped me analyze* mathematical problems.  This is all I ever wanted, so, even though I may appear to be the classic "loser" who has lived an uneventful life, at least, along the way, I have been able to take just enough interest in what the "eggheads" have been up to so as to ... well .. how else to phrase this? ... to be mentally stimulated.

I could not have asked for more from or for myself.  I think I may actually be content.   :-\

* analyze vs. analyse?

You will notice I use the "American English" as opposed to the "British English".  I'm always doubting myself when the editor puts those squiggly red lines under such words.  I kept thinking I forgot how to spell humor or endeavor when it is just the absence of the British u.

I beg forgiveness of the creators of the freeboards free forum software for my lack of manners.  I'm not confused, just stubborn.   I don't take orders from software.  ;)

One of these days, Holden, you might catch this math-code fever ... then you will surely not want to report to a boss ... since you will become a mathematical madman.   :D
« Last Edit: March 16, 2016, 11:36:47 pm by H »
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 ~

Holden

  • { ∅, { ∅ } }
  • Posts: 5070
  • Hentrichian Philosophical Pessimist
Introversion- Mathematics-Schopenhauer
« Reply #18 on: March 16, 2016, 01:52:38 pm »
I think you like math primarily because you are sick of "people".And so am I.So was Schopenhauer.I literally talk to no one during my off-duty time ,except with you,because I am extremely introverted.With Cioran, I say:
As far as I am concerned, I resign from humanity. I no longer want to be, nor can still be, a man. What should I do? Work for a social and political system, make a girl miserable? Hunt for weaknesses in philosophical systems, fight for moral and esthetic ideals? It’s all too little. I renounce my humanity even though I may find myself alone. But am I not already alone in this world from which I no longer expect anything?

I just wanna do a bit of math & then kick the bucket.That's all.And I think you are also very introverted.That's perhaps your greatest quality.
That's it, I think.Why should I live in history, huh? I don’t want to know anything anymore. Except mathematics.You are right, again.
« Last Edit: March 16, 2016, 01:56:21 pm by Holden »
La Tristesse Durera Toujours                                  (The Sadness Lasts Forever ...)
-van Gogh.

Nation of One

  • { }
  • { ∅, { ∅ } }
  • Posts: 4756
  • Life teaches me not to want it.
    • What Now?
do math then kick bucket
« Reply #19 on: March 17, 2016, 10:06:16 am »
Quote from: Holden
I just wanna do a bit of math & then kick the bucket.That's all.

Perfect. 

Out of nowhere, you have spontaneously suggested a possible solution to my Inquiry into How to Get Through a Life Not Worth Living.

This also puts to rest the question as to whether hypothetical eternal life would even be something desirable.   ::)

While I am trying to fall asleep, there are parts of the mind that do not "shut down." 

Quote from: Cioran
I no longer want to be, nor can still be, a man. What should I do? Work for a social and political system, make a girl miserable? Hunt for weaknesses in philosophical systems, fight for moral and esthetic ideals?

I have found it is easier to view oneself as a chimpanzee-like organism.  There are many creatures whose lives are sustained by the gargantuan artifice of modern technological industrialized mass society.  Not all creatures succumb to the slaughterhouse or zoo. 

I want to spend as much time going through enough of the core subjects so that no matter where I end up, I might be able to convince someone to send me a particular book of problems to work on. 

Maybe this activity gives consciousness enough to keep itself occupied so that it doesn't turn the focus of its laser beam of attention on  the problem of existence itself.  We will continue to think about the problem of existence itself, but as long as we exist, there is definitely some kind of psychological comfort in becoming more comfortable with "a bit of mathematics."

Finding where one is at is a solitary affair.  One has to defend against having one's consciousness assaulted by mass society.  Around 2AM, just before trying to shut my eyes, I was reading that Proust book, Swann's way, and I was struck by a comment about "journalism."   It's gotten far worse with television and what they have transformed some aspects of the Internet into.

I wonder if I can access the passage through "the cloud" ...

There is no "Kindle for PC" that runs on Linux, which is what I am in.

There is only https://read.amazon.com/ ...

Let's see ... Here it is.  I'll have to type this (oh, the agony!  I am being rushed out the door ... I will skip breakfast.

"The fault I find with our journalism is that it forces us to take an interest in some fresh triviality or other every day, whereas only three or four books in a lifetime give us anything that is of real importance."
« Last Edit: March 17, 2016, 11:13:25 am by H »
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: Programming as Mathematics
« Reply #20 on: March 19, 2016, 08:56:55 am »
Quote
I think you like math primarily because you are sick of "people"

Perhaps this is true.  While I am sleeping, my mind scans the feelings of its organism.  It processes subtle observations, such as what a rip-off farce "anger management" is ... the mind sees more than I can ever hope to write about.  I should save this for the thread about the Unconscious.

Anyway, this sense of disgust and disdain, this sickness of "people" ... I try not to write down or focus on any particular individual.  I suppose I dislike quite many, if not most people I have met and have not met.   This is not something that I need to be concerned about.  I don't think I have to like anyone.  I suppose most animals are a-s-s-holes as well.  I probably don't want to be in close quarters with most individual organisms on the planet.  It's horrible to consider, no?

At least here, on this message board (and others like it, I'm sure there are countless other groups of two and three or five), we can transcend all the happy-hippy horseshiit, and articulate an honest appraisal of what it means to exist, not some mumbo-jumbo narrative we like to tell ourselves.

So, yes, I might like to engage in the study of mathematics because I want to have as little as possible to do with other people, including the telephone.

One wakes in the morning and must endure time.  Both mathematics and programming require a considerable amount of concentration.  One can study for years and have nothing to really show for it, whereas a professional athlete can earn a great deal of money in one year.  It is nearly impossible to explain why anyone would be interested in these activities if one does not receive some kind of monetary pay-off. 

The first thing one hears is, "Why don't you go back to school and get another diploma or find some kind of "job".  People don't get it.  Formal education has a way of destroying my interest in a subject. 

As you will see when you receive the flash drive with the H Diaries, I have spent a lifetime writing about the details of getting through a life not worth living.  Now I am filling notebooks with notes on mathematics and programs associated with mathematical operations.  I have written enough about how I feel about life in general.  I don't want to write my life story or some kind of existential novel.  I want to slow down long enough to explain details of solving a problem without feeling under pressure to move along to the next problem.

I want to force myself to concentrate on math problems and try to enjoy implementing some methods with code.  That's all.  That life is not worth living is not really a topic of conversation that is going to attract many participants.  Yes, I am sick of people, it's true.  I would not have the patience to sit through lectures in a university, knowing what I know about the slow nature of the learning process.  One may resist using words as strong as "hate," but I hate the thought of needing transportation to a building where one is supposedly learning when one could get further along cracking open the books in isolation.

I use the word hate because this best describes my sentiments.  I hate Career Days.  I hate "Group Projects" ... I hate exams.  I hate student loans.  I hate the farce of society.  I don't need any stamps of approval or recognition from society.   They only keep track of the police records, anyway.  Never in a court of law has "graduating with honors at the university" ever been acknowledged by a judge.  He only brings up my altercations with the police! 

For me, Holden, the game is over.  My only goal is to remain an honest student of mathematics, programming, and pessimistic antinatalist depressive philosophy.

Fortunately, for me, anyway, approaching the age of 50 insures I don't entertain any ideas about making some kind of career out of mathematics or programming.  Fuuck the world.  They can't lock me out of my own brain.  I realize that none of this leads anywhere.  I get that part.

This is a solitary project, and the satisfaction I get from it is impossible to quantify.  To be blunt, I want to devote a couple of years to 3 specific subjects simultaneously.  This is in total defiance of covering the material in robo-mode in a couple semesters.  Hell, if I devote more than 2 years, so be it ... the slower the better as far as I'm concerned.

Perhaps studying these disciplines is an alternative to suicide, an alternative to "spectator sports and automobile worship", an alternative to "gainful employment and therapy", an alternative to "participating in some kind of political protest". 

Daily I have to convince myself to eat food.

Mathematics gives me something to write about other than the pointlessness of existence in general.  So what if it doesn't lead anywhere.  What does lead anywhere but the to the grave, anyway?

What I like most about our correspondence here on this message board, as opposed to jotting down these daily frustrations in a private notebook, is that I can shed some light on daily aggravations that are most likely common to all but hardly ever articulated in such a shameless manner. 

The drudgery involved in feeding the creature ...

I devote myself to studying as a way to endure time.

I am tinkering my life away ... Thankfully, I don't need anyone's permission to crack open a textbook.  Shall I write about the chains of biological necessity?

If I do not crack a couple eggs, there will be no energy ...

It is best to isolate.  Why do we bother to eat food?  I eat food so I can continue to study math.

 :-\

Most people do not dare to articulate their complaints about everyday existence because of the conspiracy which pressures people to preserve some kind of public image.  Keep your complaints to yourself of be accused of whining.  Thomas Ligotti explains this phenomenon very well in Conspiracy Against the Human Race.  No wonder I found that work so appealing.

May we continue to defiantly express our complaints here.

Hell, if I may be brutally honest here, it is quite often the case that studying mathematics makes me long for death even more intensely, since, after all, I wonder what the point is.   :-\
« Last Edit: March 19, 2016, 11:05:34 pm by H »
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: Programming as Mathematics
« Reply #21 on: August 07, 2019, 08:30:20 am »
A Programmer's Introduction to Mathematics

This looks extremely interesting.

https://pimbook.org/

"Programmers are in a privileged position to engage with mathematics."
« Last Edit: August 07, 2019, 10:44:04 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: Programming as Mathematics
« Reply #22 on: August 26, 2019, 11:31:05 am »
I feel obligated to part of myself to type up some notes from my "exploratory investigations."   Some of these notes are from a 1200 page text book mixed with other sources.    I feel a need to articulate what I find so interesting about "generic programming."


----------------------------------------------------------------------------------------------
First of all, may I suggest From Mathematics to Generic Programming" by Alex Stepanov and Daniel Rose, a book I mentioned in the "Generic Programming" thread:  http://whybother.freeboards.org/math-diary/generic-programming/ (very related to this thread).

-------------------------------------------------------------------------------------------
My apologies for putting on my "technician's hat."   Just remember that the creature who types is still this frustrated, albeit philosophical, animal with forever-growling stomach, rotten teeth, bad breath, and excrement quite nasty!   
----------------------------------------------------------------------------------------

From a 2006 paper by Peter Gottschling, "Fundamental Algebraic Concepts in Concept-Enabled C++":

symbiosis - the relation between two different species, where each gains benefits from the other.

Using generic programming concepts to define algebraic structures is an organic symbiosis between generic programming and abstract algebra.  At first, the idea of concepts was adapted from algebra to generic programming.  Now, algebraic structures are specified with the generic programming concepts. 
-------------------------------------------------------------------------------------------

In Bjarne Stroustrup's textbook, Programming:  Principles and Practice Using C++, early on in chapter 20, he writes, "We look at the STL [Standard Template Library] not just as a useful set of facilities, but also as an example of a library designed for maximal flexibility and performance.  The STL was desgined by Alex Stepanov to provide a framework for general, correct, and efficient algorithms operating on data structures.

The ideal was the simplicity, generality, and elegance of mathematics. 


From page 681, chapter 19:


GENERIC PROGRAMMING

Templates are the basis for generic programming in C++. In fact, the simplest definition of “generic programming” in C++ is “using templates.” That definition is a bit too simpleminded, though. We should not define fundamental programming concepts in terms of programming language features. Programming language features exist to support programming techniques — not the other way around. As with most popular notions, there are many definitions of "generic programming.” We think that the most useful simple definition is

Generic programming: Writing code that works with a variety of types presented as arguments, as long as those argument types meet specific syntactic and semantic requirements.

When what we parameterize is a class, we get a class template, what is often called a parameterized type or a parameterized class. When what we parameterize is a function, we get a function template, what is often called a parameterized function and sometimes also called an algorithm. Thus, generic programming is sometimes referred to as “algorithm-oriented programming”; the focus of the design is more the algorithms than the data types they use.

Since the notion of parameterized types is so central to programming, let’s explore the somewhat bewildering terminology a bit further. That way we have a chance of not getting too confused when we meet such notions in other contexts.  This form of generic programming relying on explicit template parameters is often called parametric polymorphism. In contrast, the polymorphism you get from using class hierarchies and virtual functions is called ad hoc polymorphism and that style of programming is called object-oriented programming.

The reason that both styles of programming are called polymorphism is that each style relies on the programmer to present many versions of a concept by a single interface. Polymorphism is Greek for “many shapes,” referring to the many different types you can manipulate through a common interface. 

There are several differences between object-oriented programming (using class hierarchies and virtual functions) and generic programming (using templates). The most obvious is that the choice of function invoked when you use generic programming is determined by the compiler at compile time, whereas for object-oriented programming, it is not determined until run time.


So — assuming you have had your fill of philosophy for now — what do people actually use templates for?

 For unsurpassed flexibility and performance:
• Use templates where performance is essential (e.g., numerics and hard real time)

• Use templates where flexibility in combining information from several
   types is essential.


C O N C E P T S


As usual, the benefits have corresponding weaknesses. For templates, the main problem is that the flexibility and performance come at the cost of poor separation between the “inside” of a template (its definition) and its interface (its declaration). This manifests itself in poor error diagnostics — often spectacularly poor error messages. Sometimes, these error messages come much later in the compilation process than we would prefer.

When compiling a use of a template, the compiler “looks into” the template and also into the template arguments. It does so to get the information to generate optimal code. To have all that information available, current compilers tend to require that a template must be fully defined wherever it is used. That includes all of its member functions and all template functions called from those. Consequently, template writers tend to place template definitions in header files. This is not actually required by the standard, but until radically improved implementations are widely available, we recommend that you do so for your own templates: place the definition of any template that is to be used in more than one translation unit in a header file.


(This means you don't have a separate .h and .cpp file for declarations and definitions, respectively; but define everything in one .h file.)

C++14 provides a mechanism for vastly improved checking of template interfaces.  For example, in C++11, we write:

template<typename T> // for all types T
class My_Vector {
 // ...
};

We cannot precisely state what is expected of an argument type T.  The standard says what these requirements are, but only in English, rather than in code that the compiler can understand.  We call a set of requirements on a template argument a concept

A template argument must meet the requirements, the concepts, of the template to which it is applied.  For example, a vector requires that its elements can be copied or moved, can have their address taken, and be default constructed (if needed). In other words, an element must meet a set of requirements, which we could call Element.

 In C++14, we can make that explicit:

template<typename T>    // for all types T
requires Element<T>()     // such that T is an Element

class vector {
// . . .
};

This shows that a concept is really a type predicate, that is, a compile-time-evaluated (constexpr) function that returns true if the type argument (here, T) has the properties required by the concept (here, Element) and false if it does not.

This is a bit long-winded, but a shorthand notation brings us to

template<Element T>   // for all types T, such that Element<T>() is true
class vector {
      // . . .
};

The compiler doesn’t understand our names or read our comments, but being
explicit about concepts helps us think about our code, improves our design of
generic code, and helps other programmers understand our code. As we go along,
we will use some common and useful concepts:

• Element<E>(): E can be an element in a container.

• Container<C>(): C can hold Elements and be accessed as a [begin():end())
  sequence.

• Forward_iterator<For>(): For can be used to traverse a sequence [b:e)
  (like a linked list, a vector, or an array).

• Input_iterator<In>(): In can be used to read a sequence [b:e) once only
  (like an input stream).

• Output_iterator<Out>(): A sequence can be output using Out.

• Random_access_iterator<Ran>(): Ran can be used to read and write a
   sequence [b:e) repeatedly and supports subscripting using [ ].

• Allocator<A>(): A can be used to acquire and release memory (like the
  free store).

• Equal_comparable<T>(): We can compare two Ts for equality using == to
  get a Boolean result.

• Equal_comparable<T,U>(): We can compare a T to a U for equality using
   == to get a Boolean result.

• Predicate<P,T>(): We can call P with an argument of type T to get a Boolean result.

• Binary_predicate<P,T>(): We can call P with two arguments of type T to
  get a Boolean result.

• Binary_predicate<P,T,U>(): We can call P with arguments of types T and
  U to get a Boolean result.

• Less_comparable<L,T>(): We can use L to compare two Ts for less than
  using < to get a Boolean result.

• Less_comparable<L,T,U>(): We can use L to compare a T to a U for less
  than using < to get a Boolean result.

• Binary_operation<B,T,U>(): We can use B to do an operation on two Ts.

• Binary_operation<B,T,U>(): We can use B to do an operation on a T and a U.

• Number<N>(): N behaves like a number, supporting +, -, *, and /.

_____________________________________________________________________

This is a more philosophical treatment of a technical subject than is usually available, so I thought it worthy to be stored here on our "old school message board" for posterity (or just to continue to daydream of ways to bring together my interests in abstract algebra and computing ...

When my stomache growls, I catch myself wishing I were dead and no longer needed to eat food and shiit.   Not much interests me in this world ... and I foresee myself spending the remainder of my days on earth sulking and brooding, with some moments of delight upon grasping such abstractions.

I apologize again for such technical posts.   I am still quite philosophical, but the thoughts I have been "entertaining" have been too dark to verbalize.   Perhaps my heart is finally going bad.   I mean, I don't want to feel so much distress and anguish.  I don't want to make this life any harder than it actually is.

I thank each of you for your philosophical and often poetic prose.

Being a human animal, well, as each of you know, has a very tragic element to it.


« Last Edit: September 23, 2019, 05:35:45 pm by Haywire Baboonery »
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: Programming as Mathematics
« Reply #23 on: September 23, 2019, 01:14:44 pm »
I am building another specialized command-line activated, but Menu Driven old-style, calculator, this time, a [GENERIC] templated Polynomial calculator which introduces the concept of a "Field" by allowing polynomial operations over various fields or rings, such as real, rational, and complex.

[as I type these words, this woman who spawned me is nagging me to do something I was planning to do anyway : wash windows of domicile.   I scrubbed mold from tub and cleaned liners with bleach/water spray last night, pulled dead flowers this morning].  I pay heavy rent and food and am also a live-in janitor+geek_squad+SystemAdmin::ROOT ??  ? ]

peace
it's a long project

Thanks for the posts.  I'm an avid reader when not "adding content" - mostly, our board is a kind of international smoke signal, so I am merely being polite reporting my activities. 

I am a living man, with all that this entails.

I want to want to scrub the windows as a "spiritual Kata," and not as a job "the Subject, I" is commanded to perform by a demanding, squirrelly-brained parent [ I := 52, womb := 77].

in Spontaneous-and-Perpetual-Misery,
Haywire HenTric AKA Mudslide Mike

The bottom line is that "Maintenance" is my middle name ...
« Last Edit: September 24, 2019, 09:46:12 pm by Haywire Baboonery »
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: Programming as Mathematics
« Reply #24 on: September 23, 2019, 04:02:23 pm »
NOTES TO ?:
Previous version of polycalc (polymath.cpp) built with Schniederman's (c.2006) templated Polynomial.h, but only implemented with reals (double in C++).  That was written awhile back. 

The current project, this [command-line activated] Generic Polynomial Calculator, originated as an attempt to illustrate some fundamental concepts of algebra with generic-concepts; that is, I wanted to test the robustness of "templated" nature of Schneiderman's Polynomial class.  Moreover, I wanted to test C++ std::complex and my own personal Fraction class, which I have implemented in several other programs/projects to satisfy my lust for displaying the rational form of anything, if possible. 

Likewise, I prefer the algebraic form of complex numbers, z = a + i b, as opposed to the native C++ (STL: #include <complex>), displayed as (a, b), so I was motivated to create various istream >> helper functions for dealing with input of Fractions and std::complex<double>.

I wanted to add to the menu an option to display old school synthetic division process, even though there are built in functions to deal with just that, the Quotient and Remainder (polynomials) after polynomial division.   While +, -, and * are straight-forward to code, / is more complicated.

Long story short, while I have great versions that display fractions and reals, and then even reals and fractions, where the work in the synthetic division process is displayed according to the type (computer programming term) to signify a particular data-structure, whether built into the language, or created from scratch, of the coefficient; that is, according to which Field (a mathematical concept) the coefficients of the polynomial are "over" - I was getting errors while compiling that had to do with difficult things to explain.

I could always use boost library, but I found one particularly basic, well-documented, library created as an assignment at some University called Polynom-Nom has breathed some curiosity into my brain.   I am replacing parts of my code that use my Fraction with its Rational, and parts of my code that use std::complex<double> will be made to use its Complex.


This code hints at the intimate threshold where mathematical phenomena manifests itself, such as mathematical fields and programming data-types, eg:

char choose_Field()  {
   char field = 'R';
   std::cout << "\n-----------------------------------------------------------------------\n";
   std::cout << "Polynomials over which field?"<< std::endl;
   std::cout << "\n-----------------------------------------------------------------------\n";
   std::cout << "   Q (Polynomial over the field of rational numbers x = a/b)\n"
             << "   R (Polynomial over the field of real numbers x = a.)\n"
             << "   C (Polynomial over the field of complex numbers x = a + i b)\n"
             << "\n-----------------------------------------------------------------------\n"
             << "This polynomial is over :  ";

 std::cin >> field;
 std::cout << std::endl;
 return field;
}

______________
So, I investigated other libraries that might better implement the main Polynomial, and I found:

https://github.com/whisperity/polynomnom

There is a slight grammatical error in the first sentence/statement of the README.md, but I am otherwise enjoying incorporating this educational library into my "generic polynomial calculator" code.   It keeps expanding in my mind, and I keep adjusting and changing it according to my needs, borrowing key parts from previous versions, and transforming the interface code after inspecting and studying the STRUCTURE of the "mathematical phenomena."

Oh, the grammatical error is significant as it has to do with multiplicity versus unity, mathematical concepts in their own right. 

_____________________________________________________________
Polynom-Nom Synopsis

Polynom-Nom is a C++ library, based mainly around implementing the concept of polynomials and various discrete mathematical phenomenon. The code was used to deepen my understanding in the field but most importantly to practice implementation in C++.
________________________________________* should be _____________________
                                                          phenomena, as in mathematical phenomena (plural of
phenomenon, which is one thing)

Suddenly I feel like the Henry Fool of Computer Science.

I'll let you know when I get something substantial compiled.   I'm taking it as it goes, all the while incorporating it into documenting a presentation of "The Fundamental Theorem of Algebra," which I plan to use Computer Algebra System, SageMath, to explore factorization of polynomials over Fields:  Real x ---> element of Real Numbers R,
Rational f = a/b ---> element of Rational Numbers Q,
 and Complex z = a + i b ---> element of Complex Numbers C.

There is a function, is_irreducible which will come in handy, and I will want to use Jupyter Notebook as a medium for documenting the exploration.

But, now, back to applying generic=ALGORITHM-based programming to implementing algebraic phenomena.

Hey, Holden, what would you think of an imaginary discipline called "Mathematical Phenomenology" ?   (fixed typo)

It sounds like a symptom of too much LSD.   :-[

Haywire Baboonery

see general theory of polynomials  - an "abstract algebraical approach" ...
« Last Edit: September 24, 2019, 06:32:50 pm by Haywire Baboonery »
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?
Programming as Mathematics: Got Sanity?
« Reply #25 on: October 09, 2019, 05:14:12 am »
Programming-Mathematical-Concepts as a Sanity Check

There is a great deal of Madness in this world.  Codemonkeys slaving away on code they may not even care about for 80+ hours per week.   If they are lucky they might code with pure thought and nobel intentions one day ... if they can ever find or program their way out of that maze.

Got sanity?

Where oh where might a little sanity be hiding in this mad world?

With a lot of luck, you might be able to squeeze a few drops of sanity out of your Lifeworld.

Start with mathematics.  Try tinkering around with arithmetic and textual operations, making custom designed command line "operations" - your own personal arsenal of computer algebra ...

If any Sanity is to be had in this or your Lifeworld, it will be found (or not) directly between the ears and nowhere else.
« Last Edit: October 09, 2019, 05:27:34 am by Haywire Baboonery »
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: Programming as Mathematics
« Reply #26 on: November 02, 2019, 01:35:34 pm »
From Stroustrup's "Programming:  Principles and Practice Using C++", c.2014:

What are types good for?

Types are good for directly representing ideas into code.

________________________________________________________

An aside:   I am not sure if Bjarne Stroustrup realizes how profound this statement is to a man with deep philosophical tendencies.   This statement, that types are good for directly representing ideas into code, could be a mantra, and becomes even deeper when applied to mathematical phenomena.

Consider the user-defined type, the class Fraction.    Developing this type helps me to express the "idea," the Qualita Occulta ?, of rational numbers and how to "operate" with them as "numerical structures" consisting of defined members, specifically, two "Integers," the Numerator and the Denominator, and on and on, et cetera.
« Last Edit: November 02, 2019, 05:18:21 pm by mike »
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: Programming as Mathematics: ELEMENTS OF PROGRAMMING
« Reply #27 on: November 12, 2019, 10:23:06 am »
Briefly, Elements of Programming is condensed, raw computer science explained via solid, concrete mathematics.
_______________________________________________________________________

From http://elementsofprogramming.com/  : 

Decomposing programs into a system of algorithmic components ...

News  (from the preface to the Author's Edition)

After ten years in print, our publisher decided against further printings and has reverted the rights to us. We are publishing Elements of Programming in two forms: a free PDF and paperback.

Elements of Programming
_______________________________________________________________________
Please be advised that this book is terse and DEEEEEEP and may require me 20 years to appreciate.    I am averaging about 1 paragraph per month ... it's just that heavy, the code is that beautiful that it really slows you down, the words, so heavy with philosophical and mathematical meaning, it demands an incredibly slow reading ...

Again, I only post it here hoping someone will at least read section 1.1 of (1) FOUNDATIONS and tell me what goes through your mind after reading it.

___________________________________________________________________________

Starting with a brief taxonomy of ideas, we introduce notions of value, object, type, procedure,  and concept that  represent  different  categories of  ideas in the computer.  A central  notion  of  the  book, regularity,  is  introduced  and  elaborated.   When  applied  to  procedures,  regularity  means that  procedures  return  equal  results  for  equal  arguments.   When  applied to  types,  regularity  means  that  types  possess  the  equality  operator  and equality-preserving copy construction and assignment.  Regularity enables us to apply equational reasoning (substituting equals for equals) to trans-form and optimize programs.



1.1    Categories of Ideas:  Entity, Species, Genus

In order to explain what objects, types, and other foundational computer notions  are,  it  is  useful  to  give  an  overview  of  some  categories  of  ideas that correspond to these notions.  An abstract entity is an individual thing that is eternal and unchangeable, while a concrete entity is an individual thing that comes into and out of existence in space and time. 

An attribute — a correspondence between a concrete entity and an abstract entity — describes some property, measurement, or quality of the concrete entity. Identity, a primitive notion of our perception of reality, determines the sameness of a thing changing over time.  Attributes of a concrete entity can change without affecting its identity.  A snapshot of a concrete entity is a complete collection of its attributes at a particular point in time.  Concrete entities are not only physical entities but also legal,  financial,  or political entities.  Blue and 13 are examples of abstract entities.  Socrates and the United States of America  are  examples  of  concrete  entities.   The  color  of  Socrates’  eyes and the number of U.S. states are examples of attributes.  An abstract species describes common properties of essentially equivalent abstract entities.  Examples of abstract species are natural number and color.  A concrete species describes the set of attributes of essentially equivalent concrete entities.  Examples of concrete species are man and U.S. state.   A function is a rule that associates one or more abstract entities, called arguments, from corresponding species with an abstract entity, called the result, from another species. Examples of functions are the successor function, which associates each natural number with the one that immediately follows it, and the function that associates with two colors the result of blending them.   An abstract genus describes different abstract species that are similar in  some  respect.   Examples  of  abstract  genera  are  number  and  binary operator.  A concrete genus describes different concrete species similar in some respect.  Examples of concrete genera are mammal and biped.   An entity belongs to a single species, which provides the rules for its construction or existence.  An entity can belong to several genera, each of which describes certain properties.   We show later in the chapter that objects and values represent entities, types represent species, and concepts represent genera.
_____________________________________________________________________________

(meanwhile, that some form of the unknown will eat us is a fact of existence - horror highlights the transitory nature of the me [the body, the mind] which is real to the extent it has agency ...)

I want to be one who eventually understands this book, but part of me is grappling with the disquieting question of who this "I" even is, or what it could possibly even mean to "understand" such a book.   If we find the presentation of the ideas elegant, that's one thing, but we still must get on in this world as these miserably needy apes with such delicate psyches, psyches whose flimsiness might be pierced at any moment by the gaping maw of the universe.

That mathematical ideas help us to organize the sequences of on/off [0/1] switches to represent eternal ideas is more than a little sublime, but the possibility for hubris is nil since we are so thirsty for and appreciative of the little we are able to understand in the long run.

What happens to our memories and cognitive functioning as "we" - as meat and bones - are swallowed by the void?

- The Programmer Who Never Was

These notes are simply a message in a bottle to some future "researcher," even it is a future version of my so-called "self," whatever a self is.

RECAP: 

Objects and Values represent ---->  Entities
Types represent  --->  Species
Concepts represent ---> Genera

Let's hope and pray some of us might get this symbiosis by osmosis eventually.

At least Stepanov has gone a long way to show me why I sometimes jokingly view Bjarne Stroustrup as a kind of Immanual Kant.  If you look at Appendix B (written by Stroustrup and Sean Parent) defining a subset of C++ (used in the book) with an extended Backus-Naur form, you will get a sense of why - the strictly rational elegance of mapping invisible thought-stuff-ideas to the structure and syntax of the language.   

I do not claim to understand this text, or to have gotten very far with it, but I have this exciting suspicion that I (we) may be familiar with these ideas already; but have yet to witness them stated and organized with such formal mathematical rigor, with proofs, lemmas, the whole 9 yards.

It's quite an edifice, a great gift to present to someone with a great deal of time on their hands - and a great deal of patience with themselves.
____________________________________________________________________________


footnotes:

1
Elements of Programming (Source code)

This includes a different parser than the one mentioned in footnote 2.


2
 Implementing a Parser for Elements of Programming

Excerpt from parser report :

Alexander Stepanov and Paul McJones recently published a magnificent book on structured generic programming titled Elements of Programming. They show-case programming as a mathematical activity, a wonderful journey in the land of simplicity and generality. Their approach makes essential use of axioms (and more generally properties) and concepts,i.e.collections of syntactic, semantics, and complexity requirements on datatypes and operations.

_________________________________________________________________________

Proofs and exercises from "Elements of Programming" by Stepanov (author of C++ STL) and McJones
« Last Edit: November 12, 2019, 06:33:58 pm by _id_Crisis_ »
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: Programming as Mathematics
« Reply #28 on: March 29, 2020, 04:33:08 pm »
From this thread, page 1, end of December 2015:

Quote from: Holden
Do you think that essentially Sol is a bit like Schopenhauer in that he knows that ultimately human effort is fruitless and that Max is Nietzschean?


I get this feeling often.  Without reading too much into the analogy, I sometimes feel like the Henry Fool to your Simon Grimm.  That is, I sense you might aim to actually make something of your literary, philosophical, and mathematical musings, whereas I very strongly resist putting myself in a position to be poked with a stick by any slob with a pretense to taste or "knowledge".

Definitley no offense meant.  I think you might be the more practical of us.  This is not to say I am ashamed of my reluctance to try to be taken seriously by this Confederacy of Health Nazis Police.  I have mixed feelings, but I am noticing a desire to complete unfinished "projects" which I egotistically presume will be embraced by a future generation of mathematics students struggling to find clear explanations of what they may be inclined or forced to study.

It is humbling.  If the gods (Fate) is with me (or the receivers), then it will be.  If the oceans rise and it all gets buried by Forces Greater than my passions-Will, then so be it.  I have worked on the mathematics and programming in order to motivate myself to continue to abstain from imbibing alcohol while assisting Maman with "enduring her existence" …

I probably have cheated death many times already, and I have prayed for death - yet here I am, a meat puppet who cares about and is cared about by his meat puppet mother.     :D

If I live to be old, I'll most likely have that drink. 
« Last Edit: March 31, 2020, 11:52:44 am by mike »
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: Programming as Mathematics
« Reply #29 on: December 23, 2021, 11:19:09 pm »
A few links to the future, if it even exists: 

(1)  Metamath: A Computer Language for Mathematical Proofs  - the book

(2) http://us.metamath.org/  (the website)

(3) source at github:  https://github.com/metamath/metamath-book
« Last Edit: December 23, 2021, 11:23:21 pm by Half-Crazy Nobody »
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 ~