Category Archives: Mathematica

Recent revisions to abstractmath.org

For the last six months or so I have been systematically going through the abstractmath.org files, editing them for consistency, updating them, and in some cases making major revisions.

In the past I have usually posted revised articles here on Gyre&Gimble, but WordPress makes it difficult to simply paste the HTML into the WP editor, because the editor modifies the HTML and does things such as recognizing line breaks and extra spaces which an HTML interpreters is supposed to ignore.

Here are two lists of articles that I have revised, with links.

Major revisions

Other revised articles

Other recent changes

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.

Send to Kindle

Functions: Metaphors, Images and Representations

Please read this post at abstractmath.org. I originally posted the document here but some of the diagrams would not render, and I haven’t been able to figure out why. Sorry for having to redirect.

Send to Kindle

The only axiom of algebra

This is one of a series of posts I am writing to help me develop my thoughts about how particular topics in my book Abstracting Algebra (“AbAl“) should be organized. This post concerns the relation between substitution and evaluation that essentially constitutes the definition of algebra. The Mathematica code for the diagrams is in Subs Eval.nb.

Substitution and evaluation

This post depends heavily on your understanding of the ideas in the post Presenting binary operations as trees.

Notation for evaluation

I have been denoting evaluation of an expression represented as a tree like this:



In standard algebra notation this would be written:\[(6-4)-1=2-1=1\]

Comments

This treatment of evaluation is intended to give you an intuition about evaluation that is divorced from the usual one-dimensional (well, nearly) notation of standard algebra. So it is sloppy. It omits fine points that will have to be included in AbAl.

  • The evaluation goes from bottom up until it reaches a single value.
  • If you reach an expression with an empty box, evaluation stops. Thus $(6-3)-a$ evaluates only to $3-a$.
  • $(6-a)-1$ doesn’t evaluate further at all, although you can use properties peculiar to “minus” to change it to $5-a$.
  • I used the boxed “1” to show that the value is represented as a trivial tree, not a number. That’s so it can be substituted into another tree.

Notation for substitution

I will use a configuration like this

to indicate the data needed to substitute the lower tree into the upper one at the variable (blank box). The result of the substitution is the tree

In standard algebra one would say, “Substitute $3\times 4$ for $a$ in the expression $a+5$.” Note that in doing this you have to name the variable.

Example

“If you substitute $12$ for $a$ in $a+5$ you get $12+5$”:

results in

Example

“If you substitute $3\times 4$ for $a$ in $a+b$ you get $3\times4+b$”:

results in

Comments

Like evaluation, this treatment of substitution omits details that will have to be included in AbAl.

  • You can also substitute on the right side.
  • Substitution in standard algebraic notation often requires sudden syntactic changes because the standard notation is essentially two-dimensional. Example: “If you substitute $3+ 4$ for $a$ in $a\times b$ you get $(3+4)\times b$”.
  • The allowed renaming of free variables except when there is a clash causes students much trouble. This has to be illustrated and contrasted with the “binop is tree” treatment which is context-free. Example: The variable $b$ in the expression $(3\times 4)+b$ by itself could be changed to $a$ or $c$, but in the sentence “If you substitute $3+ 4$ for $a$ in $a\times b$ you get $(3+4)\times b$”, the $b$ is bound. It is going to be difficult to decide how much of this needs explaining.

The axiom

The Axiom for Algebra says that the operations of substitution and evaluation commute: if you apply them in either order, you get the same resulting tree. That says that for the current example, this diagram commutes:

The Only Axiom for Algebra

In standard algebra notation, this becomes:

  • Substitute, then evaluate: If $a=3\times 4$, then $a+5=3\times 4+5=12+5$.
  • Evaluate, then substitute: If $a=3\times 4$, then $a=12$, so $a+5=12+5$.

Well, how underwhelming. In ordinary algebra notation my so-called Only Axiom amounts to a mere rewording. But that’s the point:


The Only Axiom of Algebra is what makes algebraic manipulation work.

Miscellaneous comments

  • In functional notation, the Only Axiom says precisely that $\text{eval}∘\text{subst}=\text{subst}∘(\text{eval},\text{id})$.
  • The Only Axiom has a symmetric form: $\text{eval}∘\text{subst}=\text{subst}∘(\text{id},\text{eval})$ for the right branch.
  • You may expostulate: “What about associativity and commutativity. They are axioms of algebra.” But they are axioms of particular parts of algebra. That’s why I include examples using operations such as subtraction. The Only Axiom is the (ahem) only one that applies to all algebraic expressions.
  • You may further expostulate: Using monads requires the unitary or oneidentity axiom. Here that means that a binary operation $\Delta$ can be applied to one element $a$, and the result is $a$. My post Monads for high school III. shows how it is used for associative operations. The unitary axiom is necessary for representing arbitrary binary operations as a monad, which is a useful way to give a theoretical treatment of algebra. I don’t know if anyone has investigated monads-without-the-unitary-axiom. It sounds icky.
  • The Only Axiom applies to things such as single valued functions, which are unary operations, and ternary and higher operations. They also apply to algebraic expressions involving many different operations of different arities. In that sense, my presentation of the Only Axiom only gives a special case.
  • In the case of unary operations, evaluation is what we usually call evaluation. If you think about sets the way I do (as a special kind of category), evaluation is the same as composition. See “Rethinking Set Theory”, by Tom Leinster, American Mathematical Monthly, May, 2014.
  • Calculus functions such as sine and the exponential are unary operations. But not all of calculus is algebra, because substitution in the differential and integral operators is context-sensitive.

References

Preceding posts in this series

Remarks concerning these posts
  • Each of the posts in this series discusses how I will present a small part of AbAl.
  • The wording of some parts of the posts may look like a first draft, and such wording may indeed appear in the text.
  • In many places I will talk about how I should present the topic, since I am not certain about it.

Other references

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.


Send to Kindle

Presenting binops as trees

Binary operations as trees

This is one of a series of posts I am writing to help me develop my thoughts about how particular topics in my book Abstracting Algebra (“AbAl“) should be organized. In some parts, I present various options that I have not decided between.

This post concerns the presen­ta­tion of binary operations as trees. The Mathematica code for the diagrams is in Substitution in algebra.nb

Binary operations as functions

A binary operation or binop $\Delta$ is a function of two variables whose value at $(a,b)$ is traditionally denoted by $a\Delta b$. Most commonly, the function is restricted to having inputs and outputs in the same set. In other words, a binary operation is a function $\Delta:S\times S\to S$ defined on some set $S$. $S$ is the underlying set of the operation. For now, this will be the definition, although binops may be generalized to multiple sets later in the book.

In AbAl:

  • Binops will be defined as functions in the way just described.
  • Algebraic expressions will be represented
    as trees, which exhibit more clearly the structure of the expressions that is encoded in algebraic notation.
  • They will also be represented using the usual infix expressions such as “$3\times 5$” and “$3-5$”,

Fine points

The definition of a binop as a function has termi­no­logical consequences. The correct point of view concerning a function is that it determines its domain and its codomain. In particular:


A binary operation determines its underlying set.

Thus if we talk about an arbitrary binop $\Delta$, we don’t have to give a name to its underlying set. We can just say “the underlying set of $\Delta$” or “$U(\Delta)$”.

Examples

“$+$” is not one binary operation.

  • $+:\mathbb{Z}\times\mathbb{Z}\to\mathbb{Z}$ is a binary operation.
  • $+:\mathbb{R}\times\mathbb{R}\to\mathbb{R}$ is another binary operation.

Mathematicians commonly refer to these particular binops as “addition on the integers” and “addition on the reals”.

Remark

You almost never see this attitude in textbooks on algebra. It is required by both category theory and type theory, two Waves flooding into math. Category theory is a middle-aged Wave and type theory, in the version of homo­topy type theory, is a brand new baby Wave. Both Waves have changed and will change our under­standing of math in deep ways.

Trees

An arbitrary binop $\Delta$ can be represented as a binary tree in this way:

generic binop

This tree represents the expression that in standard algebraic notation is “$a\Delta b$”.

In more detail, the tree is an ordered rooted binary tree. The “ordered” part means that the leaves (nodes with no descendants) are in a specific left to right order. In AbAl, I will define trees in some detail, with lots of pictures.

The root shows the operation and the two leaves show elements of the underlying set. I follow the custom in computing science to put the root at the top.

Metaphors should not dictate your life by being taken literally.

Remark

The Wikipedia treatment of trees is scat­tered over many articles and they almost always describe things mostly in words, not pictures. Describing math objects in words when you could use pictures is against my religion. Describing is not the same as defining, which usually requires words.

Some concrete examples:



    
    

3trees

These are represen­ta­tions of the expressions “$3+5$”, “$3\times5$”, and “$3-5$”.

Just as “$5+3$” is a different expression from “$3+5$”, the left tree in 3trees above is a different expression from this one:



    

switch

They have the same value, but they are distinct as expressions — otherwise, how could you state the commutative law?

Fine points

I regard an expression as an abstract math object that can have many repre­sentations. For example “$3+5$” and the left tree in 3trees are two different represen­ta­tions of the same (abstract) expression. This deviates from the usual idea that “expression” refers to a typographical construction.

In previous posts, when the operation is not commutative, I have sometimes labeled the legs like this:


I have thought about using this notation consistently in AbAl, but I suspect it would be awkward in places.

Evaluation and substitution


The two basic operations on algebraic expressions
are evaluation and substitution.

They and the Only Axiom of Algebra, which I will discuss in a later post, are all that is needed to express the true nature of algebra.

Evaluation

  • If you evaluate $3+5$ you get $8$.
  • If you evaluate $3\times 5$ you get $15$.
  • If you evaluate $3-5$ you get $-2$.

I will show evaluation on trees like this:




Evaluation with trace

A more elaborate version, valuation with trace, would look like this. This allows you to keep track of where the valuations come from.




You could also keep track of the operation used at each node. An interactive illustration of this is in the post Visible algebra I supplement. That illustration requires CDF Player to be installed on your computer. You can get it free from the Mathematica website.

Variables

In the tree above, the $a$ and $b$ are variables, just as they are in the equivalent expression $a\Delta b$. Algebra beginners have a hard time understanding variables.

  • You can’t evaluate an expression until you substitute numbers for the letters, which produces an instance of expression. (“Instance” is the preferable name for this, but I often refer to such a thing as an “example”.)
  • If a variable is repeated you have to substitute the same value for each occurrence. So $a\Delta b$ is a different expression from $a\Delta a$: $2+3$ is an instance of $a+b$ but it is not an instance of $a+a$. But $a\Delta a$ and $b\Delta b$ are the same expression: any instance of one is an instance of the other.
  • Substitute $a\Delta b$ for $a$ in $a\Delta b$ and you get $(a\Delta b)\Delta b$. You may have committed variable clash. You might have meant $(a\Delta b)\Delta c$. (Somebody please tell me a good link that describes variable clash.)
  • Later, you will deal with multiplication tables for algebraic structures. There the elements are denoted by letters of the alphabet. They can’t be substituted for.

Empty boxes

A straightforward way to denote variables would be to use empty boxes:

The idea is that a number (element of the underlying set) can be inserted in each box. If $3$ (left) and $5$ (right) are placed in the boxes, evaluation would place the value of $3\Delta5$ in the root. Each empty box represents a separate variable.

Empty boxes could also be used in the standard algebraic notation: $\Delta$ or $+$ or $-$.
I have seen that notation in texts explaining variables, but I don’t know a reference. I expect to use this notation with trees in AbAl.

To achieve the effect of one variable in two different places, as in

we can cause it to repeat, as below, where “$\text{id}$” denotes the identity function on the underlying set:

To evaluate at a number (member of the underlying set) you insert a number into the only empty box

which evaluates to

which of course evaluates to $3\Delta3$.

This way of treating repeated variables exhibits the nature of repeated variables explicitly and naturally, putting the values automatically in the correct places. This process, like everything in this section, comes from monad theory. It also reminds me of linear logic in that it shows that if you want to use a value more than once you have to copy it.

Substitution

Given two binary trees



      

you could attach the root of the first one to one of the leaves of the second one, in two different ways, to get these trees:



      


2trees

which in standard algebra notation would be written $(a-b)-c)$ and $a-(b-c)$ respectively. Note that this tree



would be represented in algebra as $(a-b)-b$.

In general, substituting a tree for an input (variable or empty box) consists of replacing the empty box by the whole tree, identifying the root of the new tree with the empty box. In graph theorem, “substitution” may be called “grafting”, which is a good metaphor.

You can evaluate the left tree in 2trees at particular numbers to evaluate it in two stages:



Of course, evaluating the right one at the same values would give you a different answer, since subtraction is not associative. Here is another example:


Binary trees in general

By repeated substitution, you can create general binary trees built up of individual trees of this form:

In AbAl I will give examples of such things and their counterparts in algebraic notation. This will include binary trees involving more than one binop, as well. I showed an example in the previous post, which example I repeat here:

It represents the precise unsimplified expression

\[A=wh+\frac{1}{2}\left(\pi(\frac{1}{2}w)^2\right)\]

Some of the operations in that tree are associative and commutative, which is why the expression can be simplified. The collection of all (finite) binary trees built out of a single binop with no assumption that it satisfies laws (associative, commutative and so on) is the free algebra on that binary operation. It is the mother of all binary operations, so it plays the same role for an arbitrary binop that the set of lists plays for associative operations, as described in Monads for High School III: Algebras. All this will be covered in later chapters of AbAl.

References

Preceding posts in this series

Other references

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.


Send to Kindle

Inverse image demo revisited

This post is an update of the post Demonstrating the inverse image of a function.

To manipulate the demos in this post, you must have Wolfram CDF Player installed on your computer. It is available free from the Wolfram website. CDF Player works on most desktop computers using Firefox, Safari and Internet Explorer, but not Chrome.

The code for the demos, with some explanatory remarks, is in the file InverseImage.nb on my ,Mathematica website. That website also includes some other examples as .cdf files.

If the diagrams don’t appear, or appear but show pink diagrams, or if the formulas in the text are too high or too low, refresh the screen.

  • The vertical red interval has the horizontal green interval(s) as inverse image.
  • You can move the sliders back and forth to move to different points on the curve. The sliders control the vertical red interval. $a$ is the lower point of the vertical red line and $b$ is the upper point.
  • As you move the sliders back and forth you will see the inverse image breaking up into a disjoint union in intervals, merging into a single interval, or disappearing entirely.
  • The arrow at the upper right makes it run automatically.
  • If you are using Mathematica, you can enter values into the boxes, but if you are using CDF Player, you can only change the number using the slider or the plus and minus incrementers.

 

This is the graph of $y=x^2-1$.

The graph of $-.5 + .5 x + .2 x^2 – .19 x^3 – .015 x^4 + .01 x^5 $

The graph of the rational function $0.5 x+\frac{1.5 \left(x^4-1\right)}{x^4+1}$

The graph of a straight line whose slope can be changed. You can design demos of other functions with variable parameters.

The graph of the sine function. The other demos were coded using the Mathematica Reduce function to get the inverse image. This one had to be done in an ad hoc way as explained in the InverseImage.nb file.

 

Send to Kindle

Monads for high school I

 

Notes for viewing

The interactive examples in this post require installing Wolfram CDF player, which is free and works on most desktop computers using Firefox, Safari and Internet Explorer, but not Chrome. The source code is the Mathematica Notebook associative.nb, which is available for free use under a Creative Commons Attribution-ShareAlike 2.5 License. The notebook can be read by CDF Player if you cannot make the embedded versions in this post work.

Monads in Abstracting Algebra

I've been working on first drafts (topic posts) of several sections of my proposed book Abstracting algebra (AbAl), concentrating on the ideas leading up to monads.  This is going slowly because I want the book to be full of illustrations and interactive demos.  I am writing the demos in Mathematica simultaneously with writing the text, and designing demos is very s l o w work. It occurred to me that I should write an outline of the path leading up to monads, using some of the demos I have already produced. This is the first of probably two posts about the thread.

  • AbAl is intended to give people with a solid high school math background a mental picture of or way of thinking about the various levels of abstraction of high school algebra.
  • This outline is not a "Topic post" as described in the AbAl page. In particular, it is not aimed at high school students! It is a guided tour of my current thoughts about a particular thread through the book.
  • The AbAl page has a brief outline of the topics to be covered in the whole book.  Perhaps it should also have a list of threads like this post.

Associativity

AbAl will have sections introducing functions and binary operations using pictures and demos (not outlined in this thread).  The section on binary operations will introduce infix, prefix and postfix notation but will use trees (illustrated below) as the main display method.  Then it will introduce associativity, using demos such as this one: 

Using this computingscienceish tree notation makes it much easier to visualize what is happening (see Visible Algebra II), compared to, for example, \[(ab)(cd)=a(b(cd))=a((bc)d)=((ab)c)d=(a(bc))d\]  In this equation, the abstract structure is hidden.  You have to visualize doing the operation starting with the innermost parentheses and moving out.  With the trees you can see the computation going up the tree.

I will give examples of associative functions that are not commutative using $2\times2$ matrices and endofunctions on finite sets such as the one below, which gives all the functions from a two element set to itself. 


  • Note that each function is shown by a diagram, not by an arbitrary name such as "id" or "sw", which would add a burden to the memory for an example that occurs in one place in the book. (See structural notation in the Handbook.) 
  • The section on composition of functions will also look in some depth at permutations of a three-element set, anticipating a section on groups.

 By introducing a mechanism for transforming trees of associative binary operations, you can demonstrate (as in the demo below) that any associative binary operation is defined on any list of two or more elements of its domain.

For example, applying addition to three numbers $a$, $b$ and $c$ is uniquely defined. This sort of demo gives an understanding of why you get that unique definition but it is not a proof, which requires formal induction. AbAl is not concerned with showing the reader how to prove math statements.

In this section I will also introduce the oneidentity concept: the value of an associative binary operation on a an element $a$ is $a$.  Thus applying addition or multiplication to $a$ gives $a$.  (The reason for this is that you want an associative binary operation to be a unique quotient of the free associative binary operation.  That will come up after we talk about some examples of monads.)  

The oneidentity property also implies that for an associative binary operation with identity element, applying the operation to the empty set gives the identity element.  Now we can say:

An associative binary operation with identity element is uniquely defined on any finite list of elements of its domain.

Thus, in prefix notation,$+(2,3)=5$, $+(2,3,5)=10$, $+(2)=2$ and $+()=0$.  Similarly $\times(2)=2$ and $\times()=1$.

This fact suggests that the natural definition of addition, multiplication, and other associative binary operations is as functions from lists of elements of the domain to elements of the domain.   This fits with our early intuition of addition from grade school, not to mention from Excel:  Addition is something you do to lists.  That feeling (for me) is not so strong for multiplication; for many common business applications you generally multiply two things like price and number sold. That's because multiplication is usually for things of different data types, but you usually add things of the same data type (not apples and oranges?).   

That raises the question: Does every function taking lists to elements come from an associative binary operation?  I will give an example that says no.  But the next thing is to introduce joining lists (concatenation), where we discover that joining lists is an associative binary operation.  So it is really an operation on lists of lists.  This will turn out to give us a systematic way to define all associative binary operations by one mechanism, because it is an example of a monad.  That is for the second installment of this outline.

Send to Kindle

Abstracting algebra

This post has been turned into a page on WordPress, accessible in the upper right corner of the screen.  The page will be referred to by all topic posts for Abstracting Algebra.

 

Send to Kindle

Apportionment 1

The interactive examples in this post require installing Wolfram CDF player, which is free and works on most desktop computers using Firefox, Safari and Internet Explorer, but not Chrome.

Notes on viewing.

Election systems

This post begins a new thread in Gyre&Gimble: Election systems.  In 1968 I created a game called Parlement and ran a few games by mail before being absorbed by family and career.  In it you ran a political party in a parliament in the style of many European countries: The parliament forms a government, votes on bills & budgets, then an election is held where each party runs on its record.

My interest in election systems has continued sporadically since them.  Since the nineties I have been programming in Mathematica and made stabs at implementing various systems for achieving proportionality. Now I expect to devote several posts to Mathematica demos of election and apportionment systems.  

Proportional representation

An elected body is chosen by a list method of proportional representation this way: 

  • The election is by districts, each electing several members.  In most cases the number of seats each district has in the body is fixed ahead of the election. 
  • Each voter votes for a party list.
  • The proportion of the integer number of representatives that party will have out of the total number of seats alloted to the district is chosen to be near to the proportion of votes the party list receives out of the total votes.
  • The method for choosing the number of seats for the party can be any one of many methods proposed in the past 200 or so years.  Only a few methods are actually used in practice.
  • Once the number of members for the party is determined, that many persons on the list are chosen according to some method.  There are quite a few different methods used for this.  I will not write about this aspect at all.

This post looks at the method of equal proportions. This method may also be used to apportion the legislature of countries such as the USA that has states or provinces so that each state has a suitably proportionate number of seats.  For most of the history of the USA, that method has been the method of equal proportions, but in the early days other methods were used.

My impression is that the equal proportion method is the most common method used in legislatures elected by the list system, and is also the most common method used for apportioning legislative seats among states or provinces.  There is much information about these things scattered over many articles in Wikipedia, and a close study may prove me wrong about this. 

Note: The summary above is oversimplified and leaves out many details.  The references list more details than most people would ever want to know.

The equal proportions method

Several sites listed in the references describe the equal proportions method in detail.  The method for calculation used in the demo (there are others) works this way:  

  • Create a list $V$ of weights indexed by the party number.  
  • For proportional representation for parties, each party starts with $0$ seats and  $V_p$ is initially the number of votes party $p$ has for the district.
  • For state representation, each state starts with $1$ seat and the the initial $V_s$ is the number of votes state $s$ receives divided by $\sqrt{2}$.
  • Suppose $S$ seats are to be assigned . 
  • Assign the first one to the party $m$ for which $V_m$ is the maximum of the list $V$.  (In the case of states, this is the first seat after the initial one.)
  • Change the list by setting $V_m:=\frac{V_m}{\sqrt{2}}$ ($V_m:=\frac{V_m}{\sqrt{6}}$ in the case of states).
  • At the $k$th step, if $n$ is the party for which $V_n$ is the max of the list $V$ in its current state, assign the $k+1$st seat to party $n$ and set $V_n:= \frac{V_n}{\sqrt{u(u+1)}}$ (the geometric mean), where $u$ is the number of seats party $n$ had before the new one was assigned. 
  • Stop which $k=S$. 

Interactive demos of the method of equal proportions

To manipulate these demos, click on "Enable Dynamics".  At present the demo has a bug that makes the table pink (Mathematica's way of giving an error message). Move any slider and the pink will disappear forever.  The demos are also available on my website: PartySimple.cdf and PartyComparison.cdf.  If you download them onto a machine with CDF player installed and run them the pink table does not happen.  I can't imagine what could cause an error like that only when run embedded in html. These notebooks are available for free use under a Creative Commons Attribution-ShareAlike 2.5 License..

Both demos have the same controls.

  • Five sliders labeled n1 through n5 control the number of votes they get in the election.  
  • The bottom slider controls the number of seats that district gets to elect.
  • By moving a slider you control the information it represents.
  • By clicking on the plus sign to the right of the slider, you toggle a list of controls below it.  The party vote sliders begin with the controls invisible and the seats slider begins with them visible.

How the EP method works

The demo below assumes that five parties, numbered 1 through 5, are running to get seats in the elected body.  You may change the votes (Column Votes) received by any party, and also the total number of representatives to be chosen (Seats).

Data

  • Total votes is the total number of votes received by all five parties.
  • Seats is the total number of representatives assigned to the elected body. It can be changed using the Seats slider.
  • Quota is Total votes divided by Seats.  Some systems use slight variations on this quota.
  • The Name of the party is given just as a number.  In a suitably fancy demo you might give each party a real name.
  • Votes is the number of votes the party receives in the election, controlled by the relevant slider.
  • SeatsAsgd  is the number of seats the equal proportions method assigns to that party.
  • Weight: This number is $\frac{\text{Votes}}{\sqrt{\text{SeatsAsgd}\times(\text{SeatsAsgd}+1)}}$

Playing with the demo

  • Start with any settings for the sliders, and press the $+$ button underneath the seat slider. This allots one more seat to the representatives.  
  • You will see that the party with the largest weight gets the new seat.  That is how the method works: The algorithm starts with no seats and adds one at a time until the correct number of seats is reached.
  • The weight is a function of the number of seats allotted to the party. 
  • Try changing the Votes for a single party, letting the total number of seats remain the same.  Which parts of the data get changed by doing this?  Do you understand why?
  • Try changing the votes for all the parties, so that one has most of the votes and the others have only a few votes apiece.  Start with Seats at zero and step the seats up one at a time.  Notice what happens in column SeatsAsgd and what happens to Weight.

 

 

 

How close to an accurate apportionment does it get?

  • Quota is Total votes divided by Seats.  Note how it changes when you move any slider.
  • The Name of the party is given just as a number.  In a suitably fancy demo you might give each party a real name.
  • Votes is the number of votes the party receives in the election, controlled by the relevant slider.
  • SeatsAsgd is the number of seats the equal proportions method assigns to that party, given the total number of Seats allotted.
  • SeatsIdeal is the party's Votes divided by Quota.  Note that this is generally close to SeatsAsgd, which is usually but not always either the floor or the ceiling of SeatsIdeal. Try to find a setting where that is not true (hint: Give one party most of the votes.)
  • VotesPerSeat is Votes divided by SeatsAsgd.  Compare it to SeatsIdeal.  They are usually close, but can  be quite far off if only a few Seats are assigned.
  • Deviation is VotesPerSeat divided by Quota.  This is a relative measure of how far away from exactness the representations of the parties are.

Playing with the demo

  • Move Seats down to 2 or 3.  Notice that the deviations are quite bad, even $40\%$ off sometimes. Move Seats  up and see that deviations get much better.  Can you understand why that happens?
  • Note that usually Seats is either the integer just below SeatsIdeal (the floor) or the integer just above it (the ceiling).  This is reasonable and is called "keeping quota".
  • Make one or two parties large and the others small, then move the Seats slider around.  You find examples where Seats busts through the ceiling, "breaking quota".  Sometimes Seats is several units bigger than the ceiling. 
  • Note that if you step Seats up one at a time, the only thing that ever happens is that one party's seats goes up one unit.  Some other common systems cause some other party's seats to go down occasionally when the total seats is incremented.  That obviously never happens with EP.  

 

About demos

These demos were designed for people to learn about a concept by experimenting with them.  Such demo should be fairly simple with only choices and displays relevant to what you are trying to show.  

You can also build elaborate CDF's. Elaborate Riemann Sums Demo.nb contains a command PlotRiemann which allows for many options showing different kinds of Riemann sums with different options, and you could design a single demo of apportionment with many buttons, sliders and other gadgets that allow for all sorts of possibilities (but I have not designed such a monster).  

I do expect to eventually design a command such as PlotRiemann that does for voting systems something like what PlotRiemann does for Riemann Sums, but the way to do that is to create one feature or option at a time.  I will be doing that and they will result in other election systems demos that I will post here from time to time.  (Promises, promises).

References 

 

Notes on Viewing  

This post uses MathJax. If you see mathematical expressions with dollar signs around them, or badly formatted formulas, try refreshing the screen. Sometimes you have to do it two or three times.

To manipulate the demo in this post, you must have Wolfram CDF Player installed on your computer. It is available free from the Wolfram website. The code for the demo is in the Mathematica notebook Equal Proportions.nb.

Send to Kindle

Visible algebra I supplement

The interactive examples in this post require installing Wolfram CDF player, which is free and works on most desktop computers using Firefox, Safari and Internet Explorer, but not Chrome. The source code is the Mathematica Notebook algebra1.nb, which is available for free use under a Creative Commons Attribution-ShareAlike 2.5 License. The notebook can be read by CDF Player if you cannot make the embedded versions in this post work.

Active calculation of area

In my previous post Visible algebra I constructed a computation tree for calculating the area of a window consisting of a rectangle surmounted by a semicircle. The visual algebra system described there constructs a computation by selecting operations and attaching them to a tree, which can then be used to calculate the area of the window. 

I promised to produce a live computation tree later; it is below.

Press the buttons from left to right to simulate the computation that would take place in a genuine algebra system.  Note that if you skip button 2 you get the effect of parallel computation (the only place in the calculation that can be parallelized).

In Visual Algebra I the tree was put together step by step by reasoning out how you would calculate the area of the window: (1) the area is the sum of the areas of the semidisk and the rectangle, (2) the rectangle is width times height, (3) the semidisk has half the area of a disk of radius half the width of the rectangle, and so on.  So the resulting tree is a transparent construction that lets you see the reasoning that created it.  

The resulting tree could obviously be simplified.  But if you were designing a few such windows, why should you simplify it?  You certainly don't need to simplify it to speed up the computation.  On the other hand, if you are going on to solve the problem of finding the maximum area you can get if the perimeter is fixed, you will have to do some algebraic manipulation and so you do want a simplified expression.    

Later, I will write more about simplifying trees, solving the max area problem, and other things concerning this system of doing algebra.

Remark

What I am showing in these posts is a simulation of a possible visible algebra system.  I have not constructed any part of the system; these posts only show something about what the interface will look like.  My practice in the last few years is to throw out ideas, not construct completed documents or programs.  (I am not saying how long I will continue to do this.)  All these posts, Mathematica programs and abstractmath.org are available to reuse under a Creative Commons license.

Send to Kindle

Generating a Collatz tree

I have written a short Mathematica program that generates the function tree of the Collatz function.  The code is in the document collatz.nb on the abmath website.

Examples

Here are some examples.  The first one is generated by the integers between 1 and 26.  (27 is to be avoided because it makes a shoot that is 111 nodes high.)  The primes from 1 to 26 generates the same tree. 

This one is generated by the odd numbers from 1 to 26: 

This is generated by the even numbers from 1 to 50:

 

Remark

This program is not of great import, but it was fun doing it and I learned more Mathematica. In particular, I learned that you cannot assign to a parameter in a function definition. For example, I had to write fv[gl_List, n_Integer] := (nn := n; ggl := {nn}; (Sow[1]; While[! MemberQ[ggl, cf[nn]], (Sow[nn]; Sow[cf[nn]]); nn = cf[nn]]) // Reap) instead of fv[gl_List, n_Integer] := (Sow[1]; While[! MemberQ[gl, cf[n]], (Sow[n]; Sow[cf[n]]); n = cf[n]]) // Reap) (where n:=cf[n] wouldn't have worked either).

Send to Kindle