Thursday, June 30, 2022

C_Day

 Had a spot of trouble working with matplotlib on Pycharm. The

YouTube video below saved the situation. As well, Pycharm

refuses  matplotlib.use('Agg'). (This uses a newer  ersion of matplotlib.)





                                                           *     *     *

HAPPY CANADA DAY TO ALL!


Wednesday, June 29, 2022

Tuesday, June 28, 2022

D_Humour

 Dark, very dark!!



source: Facebook

Monday, June 27, 2022

ASCII

 Python can convert from binary to letters and back:



source: StackOverflow


Sunday, June 26, 2022

Surprises

 

from: W3Schools



Python Operators - GeeksforGeeks

                                                  *     *     *

Using logical operators to do bitwise operations can

have surprising outcomes. 

10             0000 1010

4               0000 0100

Thus, 10 and 4 have no aligned 1s, and the return on 10 & 4 is 0.

Had I asked for 10 & -4, two's complement would have kicked in:

-4             1111 1011    for the flip to complement

                 1111 1100   to two's complement

                 0000 1000   which is a return of 8


                                           *     *     *

The example with the NOT operstor is a bit more complicated. Here's thedeal:



                                                                     
             https://www.programiz.com/c-programming/bitwise-operators                                              


   source: Python reference                         
                                                   

                                                         *     *     *

OR        a | b     One is the result if either bit of the same rank is a 1.

10     0000 1010
4       0000 0100
______________
        0000 1110                       which is 14.

                                                        *     *     *

NOT     ~a

10    0000 1010
_____________
       0000 1011                  
       0000 1110
       1000 1110                       which is -11. The procedure is the same whether the
                                               value is posistive or negative: -(x +), that is, add 1 and 
                                               flip the sign.

                                                                       


                                                      *     *     *

XOR      a ^b

A repeat of  which had no double 1s.... 14.

       

Saturday, June 25, 2022

To Binary

 I have long heard that computers subtract by addition.

It's actually rather clever. The most significant bit (in a signed number), on

the left, is the sign of the number: 0 iindicates a positive number,

1 a negative. So if the second (negative) number in our operation

 is greater than the first (positive) one, the 0 flips to 1 and one has

a negative value.


So why do we say that it is subtraction through addition: because one is

adding a positive number and a negative one, rather then subtracting

a positive from a positive. This magic works as we flip the second number,

transforming a small positive number into a lage negative one. ie

a simple 8-bit binary number represents numbers of 0 to 255, while a flipped

number goes from 0 to 127 in the positive and 0 to -127 for the negative.

Problem here, 0 and -0 have different representations. Adding 1 to the

flip solves the problem. One then subtracts by addition with no problem.




Two's complement is standard for most computers. Below, (4 - 1).

0000 0100

1111 1111

________

0000 0011

So essentially, the machine just adds 0s and 1s, which we can emulate

using the normal rules of addition ie with a carry-over!!


Binary Subtraction - Rules, How to do Binary Subtraction, Binary Subtraction using 1's complement, Examples. (cuemath.com)

Interesting site:

Binary and Decimal Numbers - AndyBargh.com


Friday, June 24, 2022

Bitwise









                                                          






                                                                         


Thursday, June 23, 2022

FN22



Of course

 Of course, the two pear images are of the same color.


source: The Sun, UK

                                                         *     *     *


A  photo Lyse recently took, from Banff:


Wednesday, June 22, 2022

Blabber

 The May to May inflation numbers are coming out this morning, and

it's going to be bad: I've seen, 7.4% suggested because transportation

costs are going up. Taking a bit of perspective, I compute, below, inflation

going back three years, giving a yearly average of...3.3%:








Fine, I'm blabbering...Let's wait!

                                                                   *     *     *

7.7% for Canada, 7.5% for Quebec.


                                                                  *     *     *

This is how income programs for Seniors are indexed. The 'Rentes du Quebec'

follows the same calculations as the CPP, from November Year 1 to October Year 2.

With changes applied from January. OAS/GIS gets adjusted on a quarterly basis,

with the annual re-set in July. (Benefit levels vary with amounts received from

private income, including CPP).


https://lop.parl.ca/sites/PublicWebsite/default/en_CA/ResearchPublications/201174E#:~:text=After%20the%20initial%20benefit%20is,the%20following%20year%20is%20announced.

Tuesday, June 21, 2022

Getting User_Input

 


It is recommended to use int for currency:

                                                                            

For entering cents:



Wondering

 First day of astronomical summer, and longest day of the year, with -

at this latitude - 15 hours and 40 seconds of daylight!



We will have lost 3 seconds by next Wednesday.

Mexico City will be seeing a mere13 hours and 18 seconds of daylight!!

                                                                             

Wondering what the math behind all these projections looks like...

AND, still looking for this year's summer song!?

                                                                    *     *     *

Nairobi, Kenya:

                                                                       


Brisbane, Australia:

                                                                              


                                                              *     *     *




Monday, June 20, 2022

Making Visuals

 Mathplotlib forPython is really easy to use, and can create quite

awesome little visuals. Below, 6 months of inflationdata from the

Bank of Canada:




Working from W3Schools Mathplotlib interface...

Blasé

 I say it's a good thing: France's Macron government is short

39 votes out of 577 to govern with a majority, and thus needs

to ally itself with another parliamentary group to pass anything.

Many will opine that it is democracy in action, forcing hard work

and compromise. Have your say! What I like about it is that the

shortfall is so slim that the government can do pretty much anything

and the votes are there for it. It can leave the EU with the Rassemblement

 National, curb immigration with Les Républicains, ban anything that belches

from the roads with the Nupes. And spend on things military with any 

number of partners. Things look daunting this morning, but in these

troubled times, it makes the government adaptable.


A particularity of recent French elections is the low participation rate. Young people

in particular shun elections with a blasé 'what difference can it make'. This

is not apathy; these same young poeple, who will only vote if the vote is 'crucial',

think nothing of going to the streets, shutting down schools and other direct action.

Indeed, the 2017 election saw the appearance of J-L Mélenchon's  'La France

Insoumise' - ('Disobedient France') - was a clear appeal to this population. 

Followed by the creation of Macron's 'En Marche' - (Advancing together) - which has

governed since then. And in a show of great consideration, Mélenchon himself 

(71 years old) did not seek a seat for himself, while still leading his coalition to substantive 

gains!!


So in my usual vein, as someone watching foreign elections from afar, Congratulations

to All on this election!!

source: Le Figaro


Saturday, June 18, 2022

Python Basics

 A little Python reminder: the print command has to be used for

a result to be shown on the screen as such. The return statement

merely stores something in memory. One needs to create a variable

whose name goes in the print command...



The import 'math statement'  at the beginning gives access to the math library

of pre-defined functions.



                                                               *     *     *


I remember this from high school physics: all metals expand in the heat, as

a functio of length ofobject and degree of heat:






If one wishes to crete a new variable to store the answer to a previous function,

on must declare a tyoe ie tell the computer whether to expect decimals with a float

or not:

                                                       



Friday, June 17, 2022

Not Funny!!

 Had occasion to look up 'Baltic cocktail', and eneded up

on the urban dictionary. Hey, it's the week-end...







Wednesday, June 15, 2022

Warren_Buffet

 







*     *     *

                                        

                                                                           *     *     *

As an example, I invest in a 10 year bond which pays 3% per year cumulatively.

At the same time, I project inflation to be running at 2% annually. Waht is the

discounted return of my investment:


                                                                                 


                                                                                




I am actually beating inflation, but only making 1.18% per year cumulatively, and my money

is all tied up for ten years. It's all in what one wants...


                                                            *     *     *

Below, discounting GDP figures. Real GDP - as opposed to nominal - takes inflation

into account.

                                                    


                


Real GDP averaged 2% per year in those years. (There is also Net DP which discounts

depreciated assets!?)


                                                                      *     *     *

Working with Python on the Idle interface, one can output yearly numbers

from a formula:                         

                                              


This is enigmatic: Python and my Windows calculator start showing different numbers

after a while. Both my Mac and  an Android tablet wisely stopped short of giving

that many decimals: