Biringa.cat -v /dev/urandom | grep -i biringa
Math: The min and max functions, using only basic arithmetic operationsPosted by Etienne Perot (admin (at) biringa (dot) com) on Saturday, February 28, 2009.

First non-introductory post! I wanted to mark my geekiness, truth to be told.
LaTeX markup is available for all equations on this page; click on an equation to get its code if you're not viewing this in an RSS reader. LaTeX rendering courtesy of Texify, graphing thanks to this utility.

The idea came up as a challenge for me — most students in my classroom now know about my "DNA" function, which looks like this:
\Huge dna(x)=\max(\Large -|\sin x|\Huge ,\Large \min(\large |\sin x|\Large ,\large 9001.\cos(\frac{5x}{2}+\frac{\pi}{2})\Large )\Huge )
Which is basically the function:
f(x)=9001.\cos(\frac{5x}{2}+\frac{\pi}{3})
But limited by these two functions:

  • g(x)=\sin(x)
  • h(x)=-\sin(x)
Coupled with those two functions, it yields a curve like this:
DNA graph

Fair enough, that's DNA, alright. The thing is that it uses the function min() and max() to constrain the function into a reserved space. The max() function returns the largest number out of two given numbers, and min() does the opposite. These are what I unscientifically call conditional functions: they return a certain value in one case, another value in another case. It reminded me of the abs() function, which returns the positive value of a given number. abs(x) can be replaced by simple arithmetic operations:
|x|=\sqrt{x^2}
Simple as that, really. This way, I could rewrite my DNA function using only basic math.

But then I thought about min() and max(). What about them? Could they be written in such a manner? Using only these three operations:

  • Addition/substraction (+, -)
  • Multiplication/division (×, ÷)
  • Exponents (ab)

And I managed to do it, albeit with some limitations (more on that later). Here's the logic I used:

The max() function

max(a,b) is a when a > b, or b when b > a. It's also a×1 + b×0 when a > b, or a×0 + b×1 when b > a. In other words, max(a,b) is a(a > b) + b(b > a), with (a > b) and (b > a) being booleans (1 when true, 0 when false).

All good up to now, but using boolean is also "conditional". So my next worry was: how to write (a > b) or (b > a) using simple arithmetic operations?
In order to compare two numbers, a and b, you can compare their difference, a - b, and look at its sign, given using the signum (sgn) function. In other words:
\text{sgn}(a-b) is either 1 if a > b, either -1 if b > a.

That's great, we got 1 or -1. How do we convert that to a boolean (0 or 1)? Why, all that's needed is to add one and to divide by 2:
\frac{\text{sgn}(a-b)+1}{2}
Indeed, (1+1)÷2 = 1 (if a > b), and (-1+1)÷2 = 0 (if b > a).

This way, the max() function can be rewritten like so:
\max(a,b)=a.\frac{(\text{sgn}(a-b)+1)}{2}+b.\frac{(\text{sgn}(b-a)+1)}{2}
\max(a,b)=\frac{a.(\text{sgn}(a-b)+1)+b.(\text{sgn}(b-a)+1)}{2}

That's some progress. But there's still the sgn function here which troubles the whole thing. How exactly do you get the sign of a number?
Well, here's a pretty obvious way to do it:
\text{sgn}(x)=\frac{|x|}{x}
Which uses the abs() function, which can be replaced as described earlier in this post:
\text{sgn}(x)=\frac{\sqrt{x^2}}{x}

Awesome! Here's the final result:
\max(a,b)=\frac{a.(\frac{\sqrt{(a-b)^2}}{a-b}+1)+b.(\frac{\sqrt{(b-a)^2}}{b-a}+1)}{2}
Which gives the following curve for a(x)=2cos(x) and b(x)=sin(2x):
(2cos(x)(sqrt((2cos(x)-sin(2x))^2)/(2cos(x)-sin(2x))+1)+sin(2x)(sqrt((sin(2x)-2cos(x))^2)/(sin(2x)-2cos(x))+1))/2

The min() function

You can apply the same reasoning here as well. You only have to switch around the a and b coefficient. Here's the result:
\min(a,b)=\frac{b.(\frac{\sqrt{(a-b)^2}}{a-b}+1)+a.(\frac{\sqrt{(b-a)^2}}{b-a}+1)}{2}
And the curve, with the same a and b:
(sin(2x)(sqrt((2cos(x)-sin(2x))^2)/(2cos(x)-sin(2x))+1)+2cos(x)(sqrt((sin(2x)-2cos(x))^2)/(sin(2x)-2cos(x))+1))/2

The DNA function - rewritten

It had to be done. Sorry guys. Here's the mighty DNA function again, in "simple arithmetic" form! (Hover to fancy-ly enlarge! If you're not viewing this in an RSS reader, that is)

The ultimate DNA function

LaTeX code:

\text{dna}(x)=\frac{-\sqrt{\sin^2(x)}.(\frac{\sqrt{(-\sqrt{\sin^2(x)}-\frac{9001.\cos(\frac{5x}{2}+\frac{\pi}{2}).(\frac{\sqrt{(\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2}))^2}}{\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2})}+1)+\sqrt{\sin^2 x}.(\frac{\sqrt{(9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x})^2}}{9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x}}+1)}{2})^2}}{-\sqrt{\sin^2(x)}-\frac{9001.\cos(\frac{5x}{2}+\frac{\pi}{2}).(\frac{\sqrt{(\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2}))^2}}{\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2})}+1)+\sqrt{\sin^2 x}.(\frac{\sqrt{(9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x})^2}}{9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x}}+1)}{2}}+1)+\frac{9001.\cos(\frac{5x}{2}+\frac{\pi}{2}).(\frac{\sqrt{(\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2}))^2}}{\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2})}+1)+\sqrt{\sin^2 x}.(\frac{\sqrt{(9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x})^2}}{9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x}}+1)}{2}.(\frac{\sqrt{(\frac{9001.\cos(\frac{5x}{2}+\frac{\pi}{2}).(\frac{\sqrt{(\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2}))^2}}{\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2})}+1)+\sqrt{\sin^2 x}.(\frac{\sqrt{(9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x})^2}}{9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x}}+1)}{2}+\sqrt{\sin^2(x)})^2}}{\frac{9001.\cos(\frac{5x}{2}+\frac{\pi}{2}).(\frac{\sqrt{(\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2}))^2}}{\sqrt{\sin^2 x}-9001.\cos(\frac{5x}{2}+\frac{\pi}{2})}+1)+\sqrt{\sin^2 x}.(\frac{\sqrt{(9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x})^2}}{9001.\cos(\frac{5x}{2}+\frac{\pi}{2})-\sqrt{\sin^2 x}}+1)}{2}+\sqrt{\sin^2(x)}}+1)}{2}

Limitations

Evidently, the formula takes a lot longer to process and calculate on a standard graphing calculator. But the main limitation of such a formula probably seem evident to most of you guys that have been reading until this point: The function fails if a = b. Yes, and it's pretty obvious (division by (a - b)). If anyone has a suggestion on how to fix this, feel free to share!


#1: Posted by Anonymous on Saturday, March 26, 2011.
This is pretty awesome.
Reply
#2: Posted by Benjamoose on Thursday, March 31, 2011.
I'll say it again;

"Your average person blogs about their Cat. In Wind's spare time, he decodes the universe..."
Reply
#3: Posted by Anonymous on Tuesday, October 25, 2011.
Xrumer - Hey you ever even heard of Xrumer ? If you have well then you definitely know the strength of its Back Links. For them that do not know, its the most overall comprehensive link builder out there. But heres the best part these guys have taken xrumer to a next level. There Xrumer mods allows link building to over 60 different platforms and growing monthly. Which is equivalant to access over 9,000,000 different sites or more. Here check it out. Xrumer


These professional Xrumer isnt a joke but the real deal. Go ahead contact them and they will show you proof. Many SEO companies employ there Xrumer backlinks, plus many link sellers out there.
Watch your site go straight to the top of the SERPS with this Xrumer.


Like I said before just check it out. Xrumer SEO
I know it was the best decision I ever made!! Now I set on the first page of the top three search engines with all my websites.
Reply
#4: Posted by Anonymous on Friday, October 28, 2011.
<img>http://img3.imageshack.us/img3/2262/logoaij.jpg</img>
Scotland is a destination with varied faces. May it be people looking in behalf of harmoniousness and inactive, or a fun sect feeling, there is something convenient quest of everyone. Scotland has beautiful scenery with a nice stand which gives people ‚lite to lay defeat and relax. On the other help, people of Scotland from been known in behalf of their joy loving ways and partying culture.
For the benefit of people looking to find their own measure out, there are a lot of destinations and living accommodations to elect from. There are small cottages to mighty castles and villas, whatever the tourist’s requirement may be. For those looking in place of a self-catering accommodation, look no yet than self-catering Perthshire accommodations.
Perthshire is a county located in dominant Scotland. With unequalled agricultural landscape all finished the countryside to the pulchritudinous mountain ranges to its south, Perthshire is a stir fetching place. If these are not sufficiently to plagiarize your be firm off things, have a hunch self-governing to indulge in the several bars and restraints in Perth, which is the capital of the county.
Another object which thinks fitting surely pull people to it is that there are various self catering Perthshire cottages present which are part of the harmed approachable holidays in Scotland. The numerous <a href=http://www.hfbscotland.co.uk><b>self catering Perthshire</b>



accommodations are at one's fingertips in distinct rate ranges, with something from the poorest to the richest of travellers.
There are beautiful properties located in monastic and restful locations which recompense self catering in Perthshire. These self catering Perthshire accommodations which are available as a factor of lame sisterly Scotland vigour by means of the people, permit against more than two people to comfortably stay. To be scuppered brotherly, the self catering Perthshire accommodations are required to convene the guidelines which sire been scheduled up by a directory as a replacement for this mere purpose.
Therefore, it can be confident than lame holidays in Scotland force assuredly please non-functioning people because of the surplus concentration and watch over taken in setting up these self-catering accommodations all closed Scotland.
If
Reply
#5: Posted by Anonymous on Wednesday, November 2, 2011.
<a href=http://www.ppiclaimcompany.co.uk>ppi claims</a>
Reply
#6: Posted by Anonymous on Saturday, November 26, 2011.
Scotland is a exact uncharitable country. However, it is blessed with song of the most outstanding gifts for the future, sources of stick-to-it-iveness like hear tell of take fright, hydro, waves and tidal in abundance. As per the latest estimate, Scotland has a cyclopean 37 GW of wind power origination wit, along with 7.5 GW of tidal power. A very inimitable and newly developing well-spring of renewable energy in Scotland which is being is white horse energy. The guess suited for this start of energy is pegged at yon 14 GW. There figures absolutely distinctly highlight Scotland’s energy generation capacity in <a href=http://www.ecodyn.com><b>C&F Wind Turbines</b></a>.
The European Harmoniousness is undivided of the biggest consumers of liveliness globally. Due to increasing demands instead of dash, it has had to look toward renewable sources to happen on its power requirements. Abundance of renewable vivacity in Scotland has emerged as entire of the reasons Scotland is gaining power clique over. Right to its huge and luxuriant availability, and shrewd that terribly diminutive has been exploited so far-away, there is a possibility of much more.
Inoperative of the estimated 35 GW of braggadocio power start attainable, however 2.5 GW is being actively harnessed at the moment. This is because until the turn of the 21st century, there was no carbon emission and verve deficiency fears on the scale it is present today. Reductions of carbon emissions and global warming have become paramount issues beyond the biography decades. There is also realisation that present resources intention not pattern forever and with phenomenon in third world countries also becoming rapid, there is an the same serious want of development of renewable sources of verve in Scotland especially.
Harnessing the vigour of the wind has grace a particular of the big moves towards renewable vigour in Scotland. The control is encouraging large-scale development of wind farms across the country. No matter how, measures can be enchanted on a smaller graduation also. <a href=http://www.ecodyn.com><b>Small wind turbines</b>


are a technology which has discover into the twin to fulfil this requirement. The trivial wind turbines generally speaking can sphere from 7 feet to 25 feet, with power begetting of 3-10 kW. These slight gust turbines are popular in the US because of the sponsoring provided by the government. However they can expense a misplaced initially, small destroy someone's advantage turbines accommodate savings greater than the want period and mainly write out up their charge exceeding 5-10 years.
Renewable energy age group in Scotland is accordingly still in its nascent stages and domination should minister to enough incentives to the sedulousness to capacitate them to harness the accessible intelligence and on the other mete should provided people incentives to opt recompense pint-sized turbine generators.
Reply

:Math: The min and max functions, using only basic arithmetic operations
:Please select an authentication method.

:: :

:
HTML tags allowed: <a href="stuff" title="stuff">, <strong title="stuff">, <em title="stuff">, <blockquote>, <br>, <hr>.