2020-03-29

Rules

Before anyone has a go about looking for loopholes, please just stay at home. If you have to go out, keep away from people, try not to touch your face, wash your hands (take sanitiser with you even). Stay safe!

However, when the new rules actually came out (here), and I mean for England, as, confusingly, other UK countries are not quite the same, I did wonder how the police were supposed to enforce them at all.

For example, a gathering of more than 2 people is prohibited, unless from same household. How to you prove you are from the same household, or, more importantly in an "innocent until proven guilty culture" how do the police prove you are not? You don't have to carry ID.

But I assumed some sense. E.g. a couple with a child going for a walk are probably OK, but a group of 20 teenagers is probably not.

Sadly the police are not being sensible, even publishing drone footage of a couple walking way apart from anyone else, and suggesting somehow that was not allowed. Worrying times.

But then you get to some of the more complicated rules. In this case I am not so much pointing out loopholes, as highlighting some rather crazy drafting of the law.

Funerals

A gathering for a funeral is allowed. You can leave your home to attend a funeral, but only of a member of your household, a close family member, or a friend. However, you can only go to a fiend's funeral if there is not a member of the same household or close family attending. But it seems like if none of your household or close family attending the friends funeral rather than close family or same household as the friend, which is rather confusing. It looks like if two people in the same family or household know someone as a friend, only one of them can go to the funeral. This is almost the reverse of the gatherings rule where people have to be the same household - at a funeral they can't be the same household, if the deceased is a friend, but can if the decided is their family. Arrrg! How do you police that and why is that the rule? It makes no sense!

It would have been far simpler to say funerals max 25 people or something simple and enforceable, but no, they have created convoluted rules.

But wait, it is not that simple. The convoluted rules only relate to leaving your home. It is the valid excuse to leave if to attend a funeral. If you leave your home to, say, exercise, you can then go to a funeral (an allowed gathering).

So it seems the only safe way to go to a friend's funeral is to wear a jogging outfit.

I can only hope none of us have to attend many funerals though - so please stay home and stay safe.

Need

Of course, these convoluted rules are simply part of the list of things that are a reasonable excuse. You can leave home for any "reasonable excuse" even those not on the list, but you may have to convince a police officer of your reasonable excuse. Even the list has the caveat that you leave your home for a "need" to do something, and arguably nobody "needs" to go to a funeral.

2020-03-24

Business as usual, or is it?

Obviously, to slow the spread of COVID-19 cases and reduce burden on NHS, we need people to stop interacting as much.

TLDR; governments have given five different messages about going to work, from yes you can, to only key workers, shutting down the economy almost entirely, with no clear message. It is causing confusion and will cost businesses and livelihoods.

The message from the government last night seemed clear...

Don't go out, but you can get food, medicine, and importantly you CAN GO TO WORK. Ideally, you work from home if you can, but all that was being shut down is the face to face shops and places where people gather and spread the virus a lot with other random people. Indeed, stopping all contact probably does not help as the spread just comes back as soon as you relax the lockdown - this is all about statistics - reduce contact enough to allow the NHS to cope.

It was, otherwise, for all those offices and factories and businesses that keep the economy going - business as usual (working from home if you can).

Now, assuming this is enough to slow the virus, that is great, well done UK government.

So, yes, please follow advice, stay at home, let's slow this spread enough for the NHS to still work.

My issue, however, is the horrible mixed messages from the government, which is really causing a lot of confusion.

First the message was, you can go to work, but try and work from home where possible.

Then, No10 twitter tweeted (image below) that you can go to work (if you're a key worker).

Now that is a massively different message. That is shutting down the whole UK economy in one go over night with no notice. That is HUGE!

They deleted the tweet, and changed so you can go to work (but work from home if possible) as per the speech. OK, good.

This was however a massive mis-direction and confusion by a tweet that was up for a while last night.

But it gets worse, a document about the lock down (here) says, in bold and underlined: "Non-essential businesses and premises must now shut!" We think this is meant to be a heading, and wording like "Non-essential businesses and premises that must now shut:-" or some such, but that is not what it says.

Again, confusing and mixed messages.

But now they are SMSing everyone with a link to gov.uk/coronavirus which says not to go outside except for "essential work", which is yet another unclear term, and again suggests a complete UK economic shutdown.

So what the hell is the message meant to be - is this business as usual apart from shops, or what?
Why the hell are the government not giving a CLEAR MESSAGE?

P.S. Obviously offices and factories have some duty of care, so things like people being able to keep apart and hand sanitisers and so on are an important step as well.

P.P.S. as per final image below, they have now changed the web site to say "work (where this absolutely cannot be done from home)". This is a total shambles!

P.P.P.S. the BBC have yet another, subtly different wording: Travelling to and from work, but only if it is "absolutely necessary", which is not clear either, is it necessary for you to still be paid, or is it "necessary work", i.e. key worker stuff?

P.P.P.P.S. as of this morning (25th) they have finally changed the PDF guidance document. That is three separate bits of government information that have changed now, having initially given misleading or wrong information.

Here are the messages:-









2020-03-14

Pi day

As it is Pi day (14th March) I thought I would say something obvious, but slightly mind blowing about another irrational number.

When you square a decimal number, you always end up with twice as many significant digits, or one fewer. e.g. 214² = 45796 (3 digits times 2 is 6, but in this case one less, 5), 56² = 3136 (2 digits times 2 is 4). If you think about it, it is obvious. Basically, for the last digit you multiply out not to count as a significant digit, it would have to be 0. You can do that with 2*5, but not by squaring any final significant digit.

But √2 is irrational. It goes on forever. It starts 1.41421356237 (12 significant digits), which squared is be 1.9999999999912458800169 (23 significant digits, i.e. 12*2-1).

Obviously the more digits, the closer... even lots, such as 1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147010955997160597027453459686201472851741864088919860955232923048430871432145083976260362799525140798968725339654633180882964062061525835239505474575028775996172983557522033753185701135437460340849884716038689997069900481503054402779031645424782306849293691862158057846311159666871301301561856898723723528850926486124949771542183342042856860601468247207714358548741556570696776537202264854470158588016207584749226572260020855844665214583988939443709265918003113882464681570826301005948587040031864803421948972782906410450726368813137398552561173220402450912277002269411275736272804957381089675040183698683684507257993647290607629969413804756548237289971803268024744206292691248590521810044598421505911202494413417285314781058036033710773091828693147101711116839165817268894197587165821521282295184884720896946338628915628827659526351405422676532396946175112916024087155101351504 squared, is 1.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999843358064061778389918448031979379487768885015043845659822004916377513166730291211571068952082602447585053372271803775212141335211046806468017544012173246168673653215429898752600809076945040478226149804752092795249913294211896685919489781038912339790863836308797672158570101054709837854108990150947671626758096902141232172374611365869462539815599093474631680641002315522198827855254655681178183773171267162025505081207619119154315015019593781997539423459450924437955866358803983089345879502011206070716091422845617882605404958297112110314310433923158845197889301909351312924983769999151087074570462040601631719823168853951704021687236598419124498942731362178121174457523357788222619729955636686231081657732082989686914502778260949270241394967997279088545806588326980598466346571508275959469245048169832037947129583450529101421217940987273080154757322849492641724996747550397932241142493214043106291202086235967891808498928787226259087932847850782010982642427061227177199617553123685346155963957806300620208169830364794225870383219224922644130340677633853727891782934367363062016

Yes, lots of 9's after that 1. but it just gets more complex.

What must blow your mind is that ultimately, to infinite digits, the answer does actually cancel out and actually end up as exactly 2.

How?!?!


2020-03-09

Backwards compatibility!

Arrrrrrrrg!

As I said, I have made a nice new decimal maths library and am using it in one of my bits of code.

It was a simple update. The original code evaluated a simple sum and provided an answer. It was a tad quick and cheerful (a bit of a bodge) but worked well enough until recently. The new code does the same but using my new library.

What could go wrong - it was a function to evaluate a text decimal sum, simple as that. How hard could it be?

The original function just added and subtracted. It worked out how many decimal places were in play and did integer maths to that precision and printed result to that many places. I said it was a bodge.

This meant, as a fluke of the way it worked, 1.00+2 would be 3.00. I.e. the number of places in the output was dependant on the max number of places of the arguments. This was never a documented feature, but guess what, people were assuming it would work like that. This is in spite of output formatting for money to two places which is what I was using in my stuff.

Then we get the fact the old code allowed blanks for operands and treated as 0. Again, a fluke of the original code and not a documented feature, but once again, they were relying on it.

It is infuriating having to make special cases in code to reproduce old and totally undocumented side effects in some function just to keep users happy! I suspect that even if the manual had said "You cannot assume a specific number of decimal places in the output" and "Behaviour for an input that is not a well formed numeric expression is undefined and cannot be relied on" it would not be any different. Users are like that!

I am waiting for the next thing, but I have a feeling it is a side effect of the total lack of error handling and syntax checking in the earlier bodged code. I might end up refusing to fix what happens when total garbage is thrown at the function and insist they fix their use cases. We'll see how bad it is.

Arrrrrrrrrrrrg!

No comment

It seems blogger have broken something - no matter ho much I clear cookies and so on, I am not able to comment on my own blog!

It used to be that it understood it was me, allowed me to edit posts directly from my blog, and comment, and reply to comments as me.

Sadly, it is not doing that - I have to go in to blogger and from there I can make new posts and edit posts, but even then I am unable to actually comment or reply.

So if you are wondering why I have not replied lately, blame blogger.

Grr.

P.S. Apparently it is not just me! Thanks for confirming, Neil.



P.P.S. looks like using incognito actually asks me for my login, and then oddly the main browser window knows who I am, WTF? So, err, fixed now.

P.P.P.S. and magically, a little later, it forgets who I am again and won't ask me for a login. Grrr

2020-03-08

Big number maths

One of my first C programmes ever, at uni, was a calculator. I had done a lot of code in BASIC, Z80, 6502 and other languages before, but C I learned at uni.

It was a strange exercise for me as I was teamed with someone else, and basically gave up on him. To me a calculator, i.e. something that could parse 1+2*3 and get 7, and understand brackets, was inherently simple. The code was a couple of pages at most and I had added all sorts of extras over and above the basic +, -, *, / binary operators. It handle brackets and operator precedence, and even had a table of operators to allow easy expansion. My "partner" made code that was dozens of pages and every test that involved extra brackets or some unexpected sequence broke it and he had two add extra code for edge cases. Oddly I once encountered a compiler that must have been written in such a way as adding extra brackets, e.g. 1+(2*3), actually broke it and made wrong code. Scary that stuff like exists.

My code has a simple loop to process: prefixes or "("s, operand, postfixes or ")"s, operator, in a loop, ending after last operand. It stacked operands, and operators (after processing the stack for any higher operators before adding), and that was it. It allowed unary pre and post operators, and binary operators. Simple and easy to understand, IMHO.

Of course, it used the normal C code to parse and output numbers, storing internally as floats (I think).

However, having played with mechanical calculators, one of the things I have meant to code one day and had not got around to for over 30 years, is a decimal calculator library... That is until this weekend.

Basically, one tool I have written, and my friends use a lot, includes an "eval" function to evaluate a simple sum for them. It is used in loads of places (as it embeds maths in a back end for a web page). It used integer (long long) types (64 bit) and shifted by number of decimal places it saw, giving it around 18 significant digits. Sadly it broke if you went over that (my bad) and they had some silly case of some numbers plus a fraction which had rather too many decimal places. So they asked me to fix.

A simple fix was limit the size, and then limit size and apply bankers rounding at the limit.

But I decided this may be the time to finally do that decimal maths code. I googled, and there are a few decimal libraries. There are also some arbitrary precision binary libraries. To my surprise the latest GCC has decimal types, where data is stored and processed in decimal. I can only assume we have decimal maths in some processors even, these days. This is good for accounting where the rounding errors you can get are bad (essentially binary does not have a way to represent 0.1 or 0.01 without recurring digits). Sadly GCC may have it, but clib does not yet (scanf and printf), but will some time, and I can see that being useful. Even so, _Decimal128 does have limits on number of digits. There are libraries in other languages, but I wanted something for C.

So I made a C string decimal library, and put it here on GitHub for all to use.

It is a library and command line, and includes functions to add, subtract, multiple, divide, and compare, as well as a simple evaluation function that parses basic sums, just like my uni project calculator.

The key thing is that it works on C text strings for numbers. A simple sum (I learned at school, and now out of date) was 366.2564*86164.091=31558149.7789324. It was numbers from an encyclopaedia in the library. I remember because I had to do the maths manually as no calculator I had would do it to full precision. Even google calculator truncates it a bit. That was my first test, and it worked. Yes, I also learned π to 50 places (and now only remember 25).

So, for add, subtract, and multiple, it is simple to ensure you have as many digits as needed. Sadly division can go on for ever, so I had to include a limit of decimal places, and a rounding rule, and remainder option.

I included rounding on limit on division, and also a separate simple rounding function - obviously actually applied at whatever digit you set. Default is banker's rounding :-

  • Round towards 0 (i.e. -3.9 rounds to -3)
  • Round away from 0 (i.e. -3.9 rounds to -4)
  • Round towards -ve (i.e. -3.9 rounds to -4, 4.2 rounds to 4)
  • Round towards +ve (i.e -3.9 rounds to -3, 4.2 rounds to 5)
  • Simple rounding (i.e 2.4 rounds to 2, 2.5 rounds to 3)
  • Banker's rounding (i.e. 2.4 rounds to 2, 2.5 rounds to 2, 2.6 rounds to 3, 3.5 rounds to 4)
I went further though, and made the calculator work on rational numbers, that means all of the maths is done with numerator and denominator, and only finally at the end does the division get done and rounding applied. This means that 1000/7*7 is 1000, unlike bc which makes it 994. minor optimisations for adding/subtracting with same denominator, and anything with denominator of 1 or a power of 10, making it simpler. For anything without division the maths does not even need a final divide.

I had a few silly bugs, one that fooled me is that zero is a special case, which I store as a magnitude of 0 and no digits, which is fine, but comparing numbers I started by comparing magnitude before comparing digits, so 0 looked like a bigger number than 0.1 as 0 was 0*10^0 and 0.1 was 1^10-1 and magnitude 0 is greater than magnitude -1. I had to add checks for comparison with 0.

However, overall, I am quite chuffed. Heck, I even asked it to work out 1e1000000000+1 and it just worked, that is a billion significant digits!

This is pure coding fun though. But may be useful - feel free to use it.

P.S. Someone asked about Banker's rounding, and I was sure I had blogged once, but cannot find it. Unlike that which I was taught at school, and every Casio (and other) calculator I had, rounding is not as simple as you think. I used to assume that a residual of exactly 0.5, or above, rounded up, and below 0.5 was down. That is what my calculator did. However, this creates a bias. Ideally you want to round an exact 0.5 residual down half the time and up half the time to remove bias. This could be random, but that is bad as you get results which are not reproducible. One simple way, bankers rounding, is to round 0.5 residual to nearest even number. Hence 0.5 rounds to 0, 1.5 rounds to 2, 2.5 rounds to 2, 3.5 rounds to 4, and so on.

FB9000

I know techies follow this, so I thought it was worth posting and explaining... The FB9000 is the latest FireBrick. It is the "ISP...