Archive for the ‘maths’ Category

Credit card designed for internet shopping

Friday, July 23rd, 2010

It seems like it would be possible to make a great deal of money by creating a payment system better than credit cards. Paypal has come closest to doing this, but has a lot of problems.

How could one make credit cards better? It would be very difficult to get your payment system into as many retailers as Visa and Mastercard, so perhaps aiming for a niche would be a good idea. One such niche might be internet purchases. Develop a payment system/credit card designed specifically for internet purchases and it could be very popular.

One major difference between a payment system designed for the internet and one predating it is that one could authenticate the transaction, not the identity. Whenever you buy something online, you put in your card number as usual but then (unlike with normal credit cards) there is an extra step – you log into the payment system’s website and approve the requested transaction. Until you have done that, the merchant doesn’t get any money (and won’t deliver the goods). This cuts out all “stolen card” type fraud, since the thief would also need to steal your payment system password (which never goes anywhere near the merchant). This would allow this payment system to undercut the existing credit card issuers and become competitive. Fraud caused by loss of the payment system password would be treated the same as fraud caused by the loss of any other online banking password (which I think varies from place to place).

This system would still need a “chargeback” mechanism to combat fraud from merchants (and mechanisms to combat fraudulent chargebacks) but my impression is that the costs of these are small compared to the “stolen card” costs.

With suitable cellphone applications for authorization, the system could even be used for brick-and-mortar stores as well.

Unlike Paypal, this system would actually be able to lend money like a credit card, it wouldn’t need to be linked to a bank account or credit card.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Time derivative accounting

Wednesday, July 21st, 2010

Sometimes I think it would make things simpler if, when I logged onto my bank’s website, there were two sorts of transactions listed. One would the normal sort: “x dollars paid to y on date z”. The other sort would be “x dollars per month paid to y since date z”. For example, my monthly mortgage payment would be listed as a single transaction, not a separate one each month.

Certain calculations are much easier when done with time derivative values. For example, interest on my mortgage accumulates daily but the payments are monthly, so to figure out what is actually owed at any time requires a lengthy spreadsheet or complicated program. If the interest accumulated continuously, and the payment also happened continuously, the calculations would be much simpler.

Normally, interest is specified as a percentage by which a debt grows. But to know what that really means, you have to specify how long it takes to grow by that much – this can lead to confusion (deliberate or accidental). It would be much better if interest was specified as a growth constant f (with standard units of Hz, bizarrely enough), such that if you have a debt x0 at time 0 and changes only because of interest (no payments or fees) then after time t the debt will have grown to x etf. If you are also making payments at the rate of r per unit time, then the debt x is given by the differential equation dx/dt = xf – r which has the solution

x = r/f + (x0 – r/f)*eft for r != x0f
x = x0 for r = x0f

Hence one can easily solve for the time it takes to repay the loan:

t = log(-r/(x0f – r))/f

Or you can solve for the repayment rate if you want to repay the loan in a specific amount of time:

r = x0feft / (eft – 1)

Similarly, one can do calculations around retirement savings. Suppose you have x0 in retirement savings today and the inflation growth constant is i. If you are saving at a rate of r eit and investing in something with a growth rate of f, and you want to retire when you can maintain an income of y eit.

The amount you need in savings at retirement is x in:

dx/dt = xf – y eit = xi

Plugging this into the equation for the savings rate while working:

dx/dt = xf + r eit

Gives:

y = r+(x0*(f-i)-r)*e(f-i)t

Solving for retirement time:

t = log(-r/(x0*(f-i)-r))/(f-i)

Or savings rate:

r = eft*x0*(f-i)/(-eit+eft)

Of course, all that assumes you can get a fixed rate of return and that inflation stays constant. In reality, these variables are constantly changing. There’s also the matter of risk to consider – trading off means for variances, but you get the idea.

The inflation rate current inflation rate is about 300 picoHertz. The highest recorded hyperinflation is about 6000000 picoHertz (6 microHertz).

How should payment rates be specified in user interfaces? “Dollars per month” is probably the most meaningful multiplier – to make it consistent we should use a standard average month length of 2629746 seconds. Current balance would be updated continuously supposing that the paying of salary and recurring bills could also be paid continuously. One would want to take care to set limits on the payment rate for bills (just as one does with direct debits) so that a mistake at the gas company doesn’t instantly wipe out your savings.

Further derivatives could be taken into account so that one could pay exponentially increasing bills like the retirement savings above without making any adjustments. The ultimate outcome of this would be to link everything to inflation and display/specify amounts in “year 2000 dollars” (for example) – in other words, the Inflation-linked currency I’ve written about before.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Liquid democracy

Monday, July 19th, 2010

Another political idea I really like is that of electronic liquid democracy. The idea is this – instead of trying to choose which of a very small number of representatives will best represent your interests, you can instead vote directly on every measure that your representative would vote on.

Most of the time, you might not care or might not have enough background knowledge to know what’s best, so you appoint a proxy to choose your vote on your behalf. You can even choose different proxies for different areas – one for health-related legislation, another for trade-related and so on. You can choose multiple ranked proxies so that if one proxy fails to vote on one issue, the vote will go to your second choice and so on. Proxies can also delegate to other proxies. All this is done electronically (with appropriate security safeguards to avoid elections getting hacked) so you can change your proxies and votes whenever you like.

It’s somewhat surprising to me that this hasn’t taken off already, given how often voters seem to be dissatisfied with the decisions of their elected representatives. It seems like it would be relatively easy to get going – somebody just needs to run on a platform of no policy except voting in accordance with the result of the system. Such a representative could get votes from both sides of the political spectrum and grants voters much more power and control – it seems to be the best of all worlds. Unfortunately when it was tried in Australia, the Senator On-Line failed miserably to get elected. There are several reasons why this might have happened:

  • People avoiding voting for a candidate they feel is unlikely to win in order to avoid the wrong mainstream candidate getting elected.
  • People not trusting this newfangled internet stuff.

The second problem should go away as the generations that haven’t grown up in the internet age die out. The first problem is ever present for third parties in first-past-the-post systems. Given that politicians won’t generally reform the systems that elected them, it seems like the only chances are for the third parties to sneak in at times when a majority of people have an unpopular view of both mainstream parties (which may happen more often as internet-savvy voters get better informed about what their representatives are actually doing).

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Seasteading

Sunday, July 18th, 2010

I find the idea of Seasteading fascinating – it could certainly be a great thing for humanity if it accelerates the evolution of government systems and gets them to solve the Hotelling’s law problem and the irrational voter problem . However, I have serious doubts that a seastead would be a good place to live in the long term. Assuming it gets off the ground, here is how I think the experiment would play out.

The first problem is that seastead “land” is extremely expensive – hundreds of dollars per square foot, on par with living space in a major US city but (initially) without the network effects that make US cities valuable places to live/work/do stuff. The “land” also has ongoing maintainance costs much greater than old-fashioned land – making sure it stays afloat, de-barnacling, ensuring a supply of fresh water and food, removing waste and so on.

This means that (at least initially) a seastead is going to be importing much more than it exports. In order to be practical, it’s going to have to ramp up to being a net exporter as quickly as possible to pay back the initial costs, keep itself running and generate net wealth. But there are far fewer options for a seastead to make money than for a landstead. Farming is going to be particularly difficult as it requires a lot of space. So the seasteads will have to concentrate on producing wealth in ways that don’t require a lot of space, and trade with land states for food.

The things which seasteads will be able to do cheaper than landsteads are things which are made more expensive by government interference, such as manufacturing (no government to impose a minimum wage or environmentally friendly disposal practices) software and other IP-intensive activities (no copyrights or patents to worry about) and scientific research (particularly biological – no ethics laws to get in the way). Drugs, prostitution and gambling will be common as sin taxes can be avoided. Seasteads which don’t do these things just won’t be able to compete with the land states, so by a simple survival-of-the-fittest process, this is what the successful seasteads will end up doing – a classic race to the bottom.

By design, it’s supposed to be very easy to leave a seastead and join another if you disagree with how your current seastead is being run – you just pack up your house onto a ship and go to another seastead. But this very mobility will introduce its own set of problems. Crime, for example – if someone commits a serious crime aboard a seastead, there’s little stopping them from leaving before the police start breathing down their necks. To avoid having a serious crime problem, the seasteads are going to have to sacrifice freedom for security in one of a number of ways:

  • Make it more difficult to move (you’ll need a check to make sure you aren’t under suspicion of a crime before you’ll be allowed to get on the boat).
  • Have a justice system and uniform baseline of laws covering a large union of seasteads – allow free travel between these seasteads but you’ll still be under the same criminal jurisdiction – similar to how US states operate. By agreeing to be a part of the union, your seastead gets some additional security but you have to play by the union’s rules to keep your police protection.

Another problem is that it’s going to be difficult to institute any form of social welfare – if you tax the rich to feed the poor, those who are getting a net tax will just leave for a seastead which doesn’t do that. So there is likely to be a great poverty problem – a big divide between wealthy seastates and poor ones. The poor ones will just die out and their “land” will be taken over by other seasteads, accelerating the Darwinism to the delight of libertarians and the dismay of humanitarians.

If lots of people end up on seasteads, I forsee large environmental problems since it’s going to be very difficult for seasteads to enact (let alone enforce) anti-pollution laws. Seasteads which take pains to avoid dumping their toxic waste in the ocean just won’t be able to compete with those that don’t.

There are certain economies of scale in many of the wealth-generating activities that seasteads will perform, so it seems likely that reasonably successful seasteads will merge into larger conglomerates the way corporations do in the western world (particularly in the US). These corporate sea-states will be the ones which are nicest to live on – since they are major producers of wealth they’ll be able to afford the best living conditions and attract the brightest and hardest-working people. They won’t be the most free seasteads though – only those who can (or have) contributed to the seastead’s economy will be allowed to live there – customers, employees and their families, retired employees, employees of partner corporations and so on. As an employee, you’ll have to play by the company rules and not engage in any activities which might be deleterious to the company’s profit margin – don’t expect to be able to take recreational drugs, for example – they might affect your job performance and add costs to the company healthcare plan.

Some seasteads might have constitutions which prevent this sort of thing. They might not be as big, as pleasant to live on or quite as good at making money, but their small size and consequent agility might allow them to survive and become viable in certain niche areas of the seasteading economy. They may have to make some compromises to stay viable, but as different seasteads will make different compromises, there will be plenty of choice.

The outcome of the seasteading experiment is really important because when humankind inevitably starts colonizing space, similar economic forces will be at work.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Arbitrary precision Mandelbrot sets

Tuesday, July 6th, 2010

I added arbitrary precision arithmetic to my Mandelbrot zoomer. Surprisingly, the difficult part wasn’t the arbitrary precision arithmetic itself, it was deciding when and how to switch from double-precision to arbitrary precision arithmetic. Because my program reuses data computed at one zoom level to speed up the computation of more deeply zoomed images, some images contained pixels computed using both methods. The trouble is, the two methods don’t give the same results. In fact, after some experimentation I discovered that the problem was even worse than that: even using just the double-precision code, you get different results depending on the number of digits you use. So the point that was represented in my program by 0xffa615ce + 0x00000002i (using 10.22 bit fixed point) escaped after 548 iterations but the point 0xffa615ce00000000 + 0x0000000200000000i (using 10.54 bit fixed point) escaped after 384 iterations. The problem is that after every multiplication we shift the result right by the number of fractional bits, which performs a rounding operation. The images generated look reasonable but are actually only approximations to the true images that would be calculated if infinite precision were employed.

Having determined this, I realized it would be necessary to throw away all the points computed with lower precision once we started using a higher precision. This isn’t as bad as it sounds, since (when zooming in by a factor of 2) the recycled points only account for 1/4 of the computed points but if we just threw them all out at once it would result in a visible artifact when passing through the precision boundary – the entire window would go black and we’d restart calculation from scratch. I wanted to avoid this if possible, so I started thinking about convoluted schemes involving restarting a point if its 3 sibling points were of higher precision. Then I realized that I could just recycle the points but keep their colours when splitting blocks to a new precision boundary, avoiding the glitch. There are still some artifacts while the image is being computed, but they are less jarring.

Finally there was the problem of interfacing with double-precision floating-point numbers. The Mandelbrot set is contained entirely within the circle |c|<2 and in this range a double has 52 bits of fractional precision. But if we replace the 10.22 and 10.54 bit fixed point numbers with doubles, we'll have a region of blockiness where we need 53 or 54 bits but only have 52. Rather than having two sorts of 64-bit precision numbers, I decided to simplify things and have 12 integer bits in my fixed point numbers.

The program is very slow when it switches into arbitrary precision mode - it's barely optimized at all. The 96-bit precision code is currently has a theoretical maximum speed of about 92 times slower than the SSE double-precision code (190 million iterations per second vs 2 million). It could be significantly faster with some hand assembler tuning, though - I have a 96-bit squaring routine that should speed it up by an order of magnitude or so. All of the multiplications in the Mandelbrot inner loop can be replaced with squarings, since 2xy = (x+y)2 – x2 – y2. Squaring is a bit faster than multiplication for arbitrary precision integers, since you only need to do n(n+1)/2 digit multiplications instead of n2. Given that we are calculating x2 and y2 anyway and the subtractions are very fast, this should be a win overall.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Improved GPU usage for fractal plotter

Sunday, November 1st, 2009

I’ve been tinkering with my fractal plotter again. One thing that annoyed me about it was the pauses when you zoomed in or out past a power of 2. I thought this was due to matrix operations until I did some profiling and discovered that it was actually dilation (both doubling and halving) of the “tiles” of graphical data to which squares are plotted and which themselves are painted to the screen.

This is work that can quite easily be done on the GPU, without even having to resort to pixel shaders, by using the ability to render to a texture. Here is the result and here is the source. In order to do this I moved all the tiles to video memory (default pool instead of managed pool) and used ColorFill() to actually plot blocks instead of locking and writing directly to textures. All this adds up to much more CPU time available for fractal iterations.

Another change is that instead of an array of grids of tiles, I’ve switched to using a grid of “towers” each of which is itself a tile and can point to 4 other towers. This simplifies the code somewhat.

There is still some glitchiness when zooming but it is much less noticable now.

This reminds me of something I meant to write about here. When I originally converted my fractal program to use Direct3D, I figured that locking and unlocking textures was probably an expensive operation so rather than locking and unlocking every time I needed to plot a square, I kept them all locked most of the time and just unlocked them to paint. However, it turns out that this “optimization” was actually a terrible pessimization – now all the tiles were dirtied each frame and had to be copied from system memory to video memory for each paint, and because of the locking nothing else could happen during that time. I was able to get a big speed up by locking and unlocking around each plot operation – that caused only the parts of tiles that were actually plotted on to be dirtied. It just goes to show that when optimizing you do have to be careful to actually measure performance and see where the slow bits really are.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Rotating fractal

Thursday, October 29th, 2009

Last year, I wrote about a way to make rotating fractals. I implemented this and here is the result:

The equation used was z <- z1.8 + c, and the branch cut varies from 0 to ~10π.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

A trip around the cardioid

Tuesday, October 27th, 2009

Take a point that moves around the edge of the main cardioid of the Mandelbrot set, and plot orbits with values of c close to that point. You end up with this:

It can be thought of as a sequence of cross-sections of the Buddhabrot.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Why should healthcare be a right anyway?

Tuesday, October 20th, 2009

Ron Paul says healthcare isn’t a right. He’s correct, technically – the US constitution guarantees no such right. However, unlike Dr Paul, I think healthcare should be a right – at least, some basic level of healthcare.

There are several reasons for this. One is a basic moral imperitive – enshrining such a right would save tens of thousands of lives each year.

Another is that healthcare doesn’t work like other goods. I have a choice about whether to buy a new car or a new computer. If I am in need of life-saving healthcare – if my “choice” is to get the healthcare I need, or to die – that isn’t really a choice at all. Faced with such a need, my only rational response would be to obtain the healthcare I needed by any means necessary, even if that means using all my savings and selling everything I own. No-one “shops around” for the cheapest cancer treatments – people go to the doctor, get fixed, and then worry about the cost afterwards. Until the bill comes, they probably have no idea how much it’s going to cost.

Food and shelter are also essential goods, but they don’t bankrupt people like medical bills do (at least in the US) because they are very predictable costs – one isn’t going to suddenly find oneself faced with a food bill of hundreds of thousands of dollars due to circumstances beyond one’s control. A “basic minimum for survival” level of food is also very cheap (we spend so much on food because we like it to be tasty and interesting as well as nutritious) but healthcare is very expensive because doctors are very highly trained professionals.

Yet another reason is that universal healthcare benefits everyone, even the healthy. Preventitive medicine and quick treatment of disease (as opposed to people avoiding going to the doctor because they can’t afford it) means a healthier population overall, less disease, fewer sick days and greater productivity.

One other reason that doesn’t seem to be mentioned anywhere is peace of mind. Unless you work for a very large corporation, health insurance isn’t reliable. Even if you have insurance, you might still be bankrupted by deductibles, copays and coinsurance. If you have an individual insurance plan, your insurance company will look for any excuse to drop you as a customer if you develop a particularly expensive condition – woe betide you if you left an i undotted or a t uncrossed on your application form! If you work for a small company, the insurance company may pressure your employer to fire you (with threat of cripplingly higher rates) if you get too sick. All these add up to worries (and stress) that those who are guaranteed healthcare by their governments simply don’t have.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark

Plan for welfare

Wednesday, October 14th, 2009

I think social welfare is generally a positive thing for society – nobody should have to starve, become homeless or sacrifice their retirement savings due to circumstances beyond their control (such as losing their job). However, it is also important to not destroy the incentive to work – we should balance the aim of having everyone contribute usefully to society with the safety net. It seems the UK isn’t doing a very good job with this at the moment as there are people on welfare who could work and would like to except that it would mean having less money for greater effort (a minimum wage job pays less than welfare, and if you have the job you stop getting the welfare). There are also many teenage girls who become pregnant just so that they will get a council house. [EDIT: This is an unsubstantiated and almost certainly false claim - I heard it on the Jeremy Vine show and failed to research it before repeating it here.]

If we were designing the system from scratch, one question might be to ask “what do we do with someone who is just Terminally Lazy (TL)?” I.e. what do we do with somebody who simply refuses to work or contribute to society at all? What sort of lifestyle should they have? For humanitarian reasons, I don’t think we should let them freeze to death in the streets, so I think they should have some sort of Basic Minimum Standard Of Living (BMSOL). We would also like to avoid the possibility of them committing crimes simply so they get sent to prison and have a place to sleep (on the general principle that encouraging crimes is a bad idea). I also don’t think we should treat TL-ness as a crime itself – if a TL person wakes up one day and decides to go and get a job and become a productive member of society, that should be encouraged – they should not lose the ability to do that.

I think that the concept of “prison” is the right idea here, though – apart from the “freedom to leave” thing, there is no reason to provide any better BMSOL to a TL person than to a convicted criminal. In both cases, we only provide that BMSOL for humanitarian reasons. Let anyone who wants to have a bed for the night in conditions that are roughly the same as those in prison: shelter, a bed, basic hygiene facilities, up to three square meals per day and a basic level of medical care. No sex, booze, drugs or TV.

Paying for the BMSOL for the TL whilst making the non-TL pay for those things isn’t exactly fair, though, so let’s have a guaranteed minimum income (equal to the cost of the BMSOL) for everyone, and give people the choice of receiving it in the form of cash or BMSOL (or some of each).

If you want more than the BMSOL you have to do some work. With the BMSOL system in place, the minimum wage could be scrapped which would mean there would be plenty of work to go around (the problem with unemployment isn’t that there’s a lack of stuff to do, it’s that because of the minimum wage there’s a lack of money to pay people to do it).

How to pay for all this? I tend to favour an income tax since it’s cheaper to collect and more progressive than a sales tax. I think inheritance tax is one of the most fair taxes, as I’ve mentioned here before. Seignorage (if carefully controlled) is probably also a good idea. It would be nice if the government had a national surplus rather than a national debt, so that it could make some money from investments rather than having to pay interest. Sin taxes (on booze, tobacco, recreational drugs, pollution and gambling) should be levied exactly as much as necessary to undo the harm that they cause (so smokers should pay the costs of treatment of smoking related diseases, etc) – any less leads to the abstinent paying for the sins of the partakers, and any more could lead to encouragement of the sins.

Income tax should be calculated as a function yielding y (the take home pay) from x (the salary) such that:

  • There is always an incentive to earn more (i.e. an increase in your salary always corresponds to an increase in your take-home pay) – dy/dx > 0.
  • The tax is progressive (i.e. the more you earn the less of your salary you take home): (d/dx)(y/x) < 0.
  • There’s no tax on the first penny (i.e. dy/dx = 0 at x = 0).
  • A minimum income is guaranteed (i.e. y >= m) rather than a minimum wage (x >= n).

Because the minimum income is part of the income tax system, the tax bill x-y is negative for people making less than a certain amount (not necessarily the same as the minimum income).

It would be interesting to write a program to simulate the economics of a society and see what effect various tax and welfare schemes have.

  • Reddit
  • Digg
  • Facebook
  • StumbleUpon
  • Twitter
  • Delicious
  • Share/Bookmark