Coming up on DTNS, talking to your smart speaker by Laser, plus computer parts are getting cheap. Are they cheap enough? And Patrick Norton's Tales of Life with only mobile internet. A little late for Halloween, but it's still scary. This is The Daily Tech News Show. This is The Daily Tech News for Tuesday, the 5th of November, 2019, that we remember. In Los Angeles, I'm Tom Merritt. And from Studio Redwood, I'm Sarah Lane. And I'm the show's producer, Roger Chang. As just mentioned, host of AVXL in this week in computer hardware, Patrick Norton with us today. Good to have you back, man. Greetings from the Silver Twinkie. And don't mind that husky. It's not congenital. No, it's not contagious. It's not congenital either, though, I assume.   The Silver Twinkie is where you live now. Silver Twinkie, yeah. So we are packed up. We are in the Airstream. We are mobile and heading north shortly. Although we may have to head to Reno to pick up the winter clothing because it's getting colder as we head north as Sarah will attest. We have got a show for you. We were just talking about V for Vendetta and Red Dwarf and all kinds of good stuff on Good Day Internet. If you want that wider show and our wider conversations about things, become a member at patreon.com slash DTNS. Let's start with a few tech things you should know. Uber reported its Q3 earnings that beat analysts' expectations on revenue at $3.81 billion and a lost per share of 68 cents versus 81 cents, which was expected. Uber reported a net loss of $1.16 billion for the quarter, which included 401 million in stock-based compensation. During the same quarter last year, Uber lost $986 million. So the losses are going up, but CEO, Dara Khazver Shah, he says that the company expects to reach profitability in 2021. Federal Trade Commission announced Tuesday that AT&T will pay $60 million U.S. dollars to settle a case alleging the company lied to customers about unlimited data plans, which throttled data over a certain threshold. AT&T now must deposit $60 million into a fund, providing partial refunds to customers who signed up for unlimited data plans before 2011. AT&T also must disclose any restrictions its unlimited plans have going forward. Yes, that would be nice if it did that. When new users sign up for Disney Plus and ESPN Plus, they'll now see a box promoting signups for the Starz streaming service. The deal was made by Disney in order to get back streaming rights for some movies that had been licensed to Starz. Like Starz Wars, for instance. Google Incubator Area 120 launched an app called Pigeon last year in New York City that crowdsources transit information. So kind of like Waze, but letting you know if there's a delay in your bus or your train, that kind of thing. Pigeon is now launching in Boston, Chicago, Los Angeles, San Francisco, and home of the World Champion Nationals Washington DC. Pigeon is available for iOS with an Android version on the way. Malaysia will allow motorcycle hailing firms like Gojek to start limited operations beginning in January. Gojek says it will work with Malaysian regulators to determine how best to enter the market. A six-month pilot project will be limited to the Klang Valley, Malaysia's, where the capital Kuala Lumpur is located. Gojek will compete with local company DegoRide and Car Hailing Service, Grab. And Google, ETH Zurich, GND Mobile Security, Nuvoton Technology, and Western Digital have partnered to create Open Titan, an open source secure chip design project. Open source hardware. The idea is to build some secure chips for things like data centers, storage, computer peripherals that can be easily inspected for back doors and be, therefore, very secure. Open Titan will build off Google's own Titan chip design. They use that in their Android phones as well as in the multi-factor security keys. Open Titan will be run by a nonprofit called the Low Risk Community. That's RISC, Low Risk Community. All right, let's talk a little about Google's new loyalty program. Yeah, Google is launching something called Google Play Points in the US. So you can earn points for things that you do within Google Play, like downloading apps or subscribing to services, buying movies, books, TV shows, the like. Points can be redeemed for other things that you would otherwise do in Google Play, like in-app purchases for Pokemon Go, renting a movie, buying an audiobook. Google Play Points first launched in Japan in September of 2018, came to South Korea in April of this year, and the US program has four levels of its own. Bronze through platinum, and points are worth more, the higher level that you reach, obviously. Points can be used on a few dozen apps as well, some charitable causes. Google funds the points, so developers don't lose any money by participating. Yeah, so if you get up to that platinum level, I don't know exactly, but it's something like each point is no longer worth a dollar, it's worth $1.40, something, you know, stuff like that. Great way to keep people in the system. It's going to make people open Google Play more often, which will make them probably spend more money in Google Play, and it will keep people a little more loyal to Android if they build up a lot of points. They won't want to switch to another platform. I'm not totally sure how successful this will be, but it is very genius to gamify the method of buying apps and just sort of being in Google Play in general, and just like, I don't know, it's why I always fly United, because I have miles on United. Is it the best airline? Well, yeah, it's arguably not, but you get into a system and you end up, you do build loyalty with customers by doing stuff like this. Patrick? I am trying to decide if I am horrified, disgusted, or just irrified. I find the gaming of buying stuff to be kind of loathsome. I also had to buy a game for my boys, and I had to explain to them that they may get killed every time they open up the game, because about a year ago, the game developers decided to make a whole lot of money selling staggering amounts of accessories or upgrades to a tiny percentage. Hey, look, if they build up points, they won't have to spend your money to get those things. Yeah. I don't know. I mean, one, it's always nice to get something back, because you're going to spend the money on these apps anyway. I always get a little uptight about the gamification of spending. Yeah, I'm starting to get loyalty program weariness. Everybody's got one. Uber's got one. I can't keep track, because they only work if they end up having their customers spend more money. So you always have to look for the loopholes that are going to trick you into spending more money than you would otherwise, which is exhausting. Well, it's also, I mean, a lot of them mostly exist because they want to capture your information and track your information. In order to set something up recently, I had to get an ID from this website, which is the brand on the thing.  And then it kicked me back to the original application to log in with my new ID. And I just may be weary of just all of the privacy tracking. I don't know. I have complicated fields that will not fit in the context of this very short news show. Researchers from Tokyo's University of Electrocommunications and the University of Michigan have demonstrated how lasers could activate voice assistants. Microphones in mobile devices and smart speakers use MEMS, micro-electromechanical systems to detect vibration in the air. They're very sensitive at that. That's why those microphones can be so small and so good. They convert the vibrations of a diaphragm in the microphone into electrical signals. It's just how microphones work. But the diaphragm used in MEMS to detect sound happens to also react to variations in laser light. They're that sensitive. So a nice focused laser beam, stream of photons, can push that diaphragm a little. And therefore a laser pointed at a MEMS microphone and modulated properly will be read as a voice by the mic, but you won't be able to hear it unless you can hear a laser light and your ears in the way because it's also a line of sight. To pull this off, an attacker would need a laser source like a laser pointer. That's cheap enough. But you also need a laser driver and an audio amplifier. And the laser driver is intended for lab use. So you're going to need someone with some experience with laser equipment to assemble this properly. Not everybody's going to be able to do it just by going down to their hardware store. Researchers tested Apple, Amazon, Google and Facebook devices found that almost all the smart speakers registered the commands from at least 164 feet away. They tested up to 300 feet and then they just didn't test any farther than that. iPhones were only vulnerable from a range of around 33 feet and Android phones were only able to be controlled within 16 feet for some reason. But you do have to have clear line of sight. They were able to make it work through a window with a telephoto lens that refocused the beam. But you do have to target that very small microphone exactly accurate as well. Well, we know that if somebody wants to hack a voice assistant, a voice enabled device, and they have the wherewithal to figure something like this out, someone will do it. So this is definitely a security risk. And it's something that people should understand is possible. It does sound complicated, yes. But I guess my initial question is, okay, well, if that's the case, pretty genius hack really, then how do the microphones in these devices have to change so this doesn't happen? I don't know that that is necessarily the solution, right? When I say I don't know, I don't know. It may just be like, these are fundamentally insecure. Don't use them for things that are important like your door locks. Yeah. Or just turn them so the microphones aren't facing any open window. Yeah. So it would be hard to get a laser pointed at it.  But you might not be paying attention. The bigger risk is probably when you're not there. Right. To break in. I think there's also a positive here, you know, at night, when you want to be super quiet, you don't even want to whisper, just point your laser at the thing. I guess you could just use a remote control. The laser know what you wanted to say. Yeah. Well, you have to build it yourself. You have to program the laser ahead of time. You have to build one of these with the driver and everything. Yeah. Yeah. I guess that's not really convenient. No. No. No, you're right. How to mitigate this is an interesting conundrum and probably just moving the bike away from line of sight is one of your best defenses. Send us your favorite defense feedback at DailyTechNewShow.com. Facebook has announced a corporate rebranding with an all-caps version of the word Facebook in gray or whatever color fits some of its sub-brands, like Instagram or WhatsApp. For example, if you're in WhatsApp, it'll be green. Instagram will be kind of that rainbow Instagram band of colors. Those brands will have a new logo in the form of from Facebook, Facebook all in caps at the bottom of pages. The idea is to distinguish the Facebook company from the Facebook social networks. Two different things, guys, to be clear, the social network not changing its logo. It's still that lowercase blue Facebook. Okay. So the social network where I go and get very angry at my relatives is called Facebook. That's right. But the parent company is called Facebook. Yes. Yeah. And that should make it very good. I mean, this is, it's funny. I told the guys before the show that I asked a designer friend of mine who does a lot of corporate identity brand logo stuff. I said, is this like, what's your take? Right? Because I'm not much of an artist.  And that's it. That's all he had to say. Technical design language there. Yeah. Yeah.   It's just, this is just going to further confuse people. I mean, you don't want to have different versions of the Facebook logo all over the place, because people don't understand the difference between Facebook, the company and Facebook, the social network. I mean, we do, our listeners do, but in general, it does sort of dilute the logo in general. Facebook made a decision that they didn't want to change the name of the parent company like Alphabet did. And so when they did that, they then decided, well, but we also want to remind people that Instagram and WhatsApp are part of us, because we think that'll help keep folks from wanting to break us up if they think of us less as a conglomerate that owns a bunch of things and more as like a family. So they wanted to brand those things. I'm not sure this is going to achieve what they want when most people think Facebook is too big and putting the Facebook name on more things makes it look bigger. Yeah. I mean, it's, it's just what Sarah was saying was, if you look at Ford went to do a new logo, I don't know, maybe in the late 60s, early 70s.  And also it's like, so we have Facebook, the 300 pound gorilla, you know, a small chicken, and you know, this sort of Svelte's nice house caddy kind of thing that also weighs two or 300 pounds. And it's the whole idea of like branding is Facebook is going to dilute people's fear of Facebook and the horrible things they do on such a regular basis with their information is just, I mean, that's incredible wishful thinking for a company that big and that smart. I think there's a little bit of effect, right?  And I've heard people say this, why can't Facebook be more like that? If they look and see, oh wait, Facebook makes this, sure it will have that effect in those cases. I'm with you, Patrick. I don't think that effect outweighs the other effect that I also have. You know what I'm saying? It's just going to make more people, when they are angry at other things, think of Facebook that way. I think of CNET. When CNET started buying other properties like download.com, like GameSpot, they changed the parent company name to CNET Networks because they like Facebook wanted to keep the branding in the parent company name. They didn't want to go as extreme as Alphabet did with Google. But CNET Networks implied, oh, this is different. It's not just CNET. It's the other networks that are involved with CNET. Facebook just branding themselves as we're Facebook, but also Facebook, I don't know that it achieves that either. Well, it's also funny because it's such a sophisticated piece of typography compared to the Facebook local. It's like, I'm fun, I'm cheerful. You want to have me as your first college roommate. And then you get to Facebook, like, oh, we're big fans of the Lincoln Mark V typography. So we just copied that in gray. Every once in a while, I have to sort of take a step back and be like, the company is called Facebook. I mean, it's sort of silly.  But Facebook is, it's a rather silly company name considering what the company has become. Well, that's good news for Peacock then. I think this is a decent name. Freedom House has issued its internet freedom rankings, which it does regularly, and has found a worldwide decline in freedom on the internet. Freedom has been around for a long time. They evaluate things like freedom of the press and end of late freedom on the internet. Iceland and Estonia, T2T2, you can raise that flag. High Iceland and Estonia remained at the top of the charts. China and Iran are at the bottom of the internet freedom charts. While censorship is one of the factors it measures, it's found this report that disinformation and propaganda have seen significant increases. And those are also negatives for internet freedom. Freedom House President Mike Abramowitz said, quote, many governments are finding that on social media propaganda works better than censorship.  Surveillance, which also has a chilling effect on speech when you think people are watching, you're less likely to do certain things, also on the rise. In fact, the United States and China have both expanded monitoring of social media significantly. If you're like, wait a minute, who are these Freedom House guys? They were started in 1941 by Republican presidential candidate Wendell Wilkie and the wife and first lady Eleanor Roosevelt, currently 86% wife of President Roosevelt and first lady Eleanor Roosevelt. And it's currently 86% funded by US government grants. Considering the world we live in, it doesn't surprise me that suppressing information is possible sometimes. But as we all know, it's getting harder and harder to do. Being able to spread propaganda to mitigate what might be information that you don't want out there, or that's incorrect, or you're incorrect, and you're trying to confuse people further, it contributes to a lot of noise. And so it's not necessarily the right direction I think we should be going in, but it does make sense that that's kind of the way it works right now. And it does seem to be something that you see being used, not just by governments, but by activist organizations as well. So it's a good warning, just something to keep in mind. All right, let's talk numbers. Falling numbers, in fact. Microns revenue dropped 23%. Seagate revenue dropped 25%. Samsung reported a 52% fall in profit. Not good news for investors, but very good news if you're building a PC because it's going to be cheaper than it was before. PC parts in general have been getting cheaper all year. A 16 gigabyte DDR4 kit that might have cost you upwards of $150 or more in recent memory now sells for around $75. And with Singles Day coming in China, that's November 11th, and Black Friday to follow in the US at the end of this month, deals on already cheap parts rather are going to be very attractive if you like to build or modify your desktop. And we just so happen to have Patrick Norton with us today. So Patrick, what is the good news here? Oh my goodness. I had a conversation with a friend of mine, one of my neighbors, and he was like, what a new PC, but everything's expensive. And I'm like, what's the last time you checked prices? And he was like, what? And we were looking at, we're talking about this before, when you look at the Amazon price history, I love camel, camel, camel.com, right? It is an incredible tool to figure out whether or not, for example, something you're shopping for for Black Friday, is it actually a Black Friday deal? And you want to get the information early, because if you are thinking about buying something at Black Friday, sometimes popular items have an entire new Amazon entry created. So all of the price history for the product, if it's been around for a while, magically disappear sometimes temporarily just for Black Friday and Cyber Monday, which I find really loathsome. It doesn't happen a lot, but it happens occasionally. But when you look at, for example, memory prices, of course, of engines, 16 gigabyte DDR4 RAM, one of the most popular memory products on there, peaked out at like $220, I want to say January 2018, February 2018. And it's back down to the $65, $75 range for 16 gigabytes of RAM. That's as low as it's been since mid-2016, which is awesome.  It is great if you're thinking about building a new PC. Same thing for SSD drives. SSD prices have been dropping off of a cliff. It's easy to get a decent not a VME drive and a standard SSD drive. I think Samsung's 860 EVO, the 500 gigabyte version. If you look at the history, back in early 2018, that was selling for like $150. They're down to like $70 now. One terabyte drives, by the way, under $150 from most of the major manufacturers of SSDs. Not NVME. Those are a little more expensive, but it has been amazing to watch the prices drop down. We had something we effectively referred to as Trout's Law on this week in computer hardware. Ryan Trout now, of course, works for Intel doing internal benchmarking, but his thing was like, he's not going to be happy until SSDs are actually down to 10 cents a gigabyte. And we've actually been seeing those prices being hit on non-sale prices, depending on the part when you're looking at it. Yeah. So if you don't have an SSD, it's time. And that camelcamelcamel.com is a great resource, especially like you say, on sale days. If you're like, is this really cheap? Because it looks cheap. That's an excellent resource. Hey, folks, if you want to get all the tech headlines each day in about five minutes, be sure to subscribe to dailytechheadlines.com. Patrick, as we mentioned earlier in the show, is sort of taken off on the road a little bit these days, which means you're relying entirely, am I right, on mobile internet? Pretty much entirely. Unless we stop in at a hotel or unless we're, say, at an empty RV park, like a KOA, we are pretty much actually, for all intents and purposes, when you look at a lot of places like campgrounds of America, it's a popular place to park RVs. Most of them actually have that we've stayed at, actually throttle internet so you can kind of download webpages and answer email, but you're not going to stream anything off of their internet. And so we kind of moved out and I was waiting for a decent, to find like a better plan in terms of the amount of data we would get. And my family blew through the, I have an old 50 gigabytes a month guaranteed without throttling plan on AT&T. And they blew through that in like 15 days. And I was like, uh-oh. And what's interesting is when you talk about mobile data, when you talk about wireless data, nobody really wants to sell data in bulk, period. Several years ago, it got to the point where, you know, I used to have a plan where I would get like 25, 30 gigabytes and then I could buy additional blocks of data. And then of course everything went to unlimited, which I'll make fun of and talk smack about in a moment. But, and then it went from you could buy additional blocks of data to, oh, no, we're going to shut you down to 128K. And in my case, you know, I had, I had, I was at CES one year and the internet we were provided with was Trash. And, you know, I was able to, you know, I went through like 25 gigabytes of data and then bought like another 25 gigabytes of data, which was expensive for what it was, but compared to the monthly fee, but was manageable and allowed us to actually, you know, do the uploading we needed to do to be in our production deadlines.  And after that they throttle you. So in case you didn't know, and I'm sure everybody listening to Daily Tech News shows knows this, unlimited basically means you get X number of gigabytes, then they have their choice of throttling you at that point, or they automatically throttle you. And if they say they throttle you to 128K, but you get all the 128K data you want until the next billing cycle, it turns out a lot of websites won't actually load at 128K. They have large graphics, active server pages. So just as a surprise. So at that point I was like, oh, well now I got to go, you know, now I got to go pull the ripcord and buy a whole bunch of internet. And one of the only companies that is offering a plan with more than like 20, 25 gigabytes of data is Sprint.  I did a MiFi 8000. But you get 100 gigabytes of data for 60 gigs a month. Speed's not spectacular. For 60 bucks a month. Yeah, 100 gigabytes for 60 bucks a month, which is incredibly low for wireless data. And then I found out about there's a website called RVMobileInternet.com. And I had a note about these guys for a while. And I went back to them when Sasha Sagan, who does all the editing, who's basically that runs the mobile group over at PCMag.com, he's like, oh, you need to go. I was like, I know about them. They're awesome. And RVMobileInternet.com, one of the things they do is they track all of the deals on large amounts of wireless data because they tend to sort of pop up.  For example, Verizon had a fast dating, unlimited prepaid data plan, which is a huge deal because Verizon has the best coverage, especially west of the Mississippi for the United States. And they have an excellent, incredibly fast network. So they for a brief like for several minutes, it was actually several weeks, you could actually get an actual genuine unlimited data Verizon plan. I spent like three weeks trying to find one to buy with zero success. So, you know, what I ended up doing was buying, there's a company called Togo who's from an RV manufacturer called Thor. And they have a branded version of this wine guard device. It looks like a giant salad bowl or Tupperware bowl. And it's about eight inches high and about 16 inches wide. It's got a mediocre, but acceptable router and a 4G LTE, you know, radio with a couple of antennas. And it's designed to perch on top of your be bolted to the top of your, in my case, airstream, your RV. And it comes with for an extra $360 a year and unlimited data plan. Wow. Yeah. Who do they use as the carrier for that? AT&T. And that's the only thing it'll run with getting it to run in a way. This is actually, I'm very excited because this is my first actual attempt with this where I've successfully been able to run an actual Skype conversation. So that is the connection you're using right now. Right now. And have been using for the past, you know, the entire show. So that's yeah, I was, I was kind of waiting for that because I know everybody listening was like, but what is he using now?  You know, you seem up and running for, you know, considering the limitations that you're dealing with. It's been interesting. The performance. It's funny because I'm in the middle of what I will effectively call a conversation and learning process with tech support for the company that built the box, you know, because I started asking lots of questions. And, you know, I had some questions about the performance, which originally was not so good. And I got this boilerplate back, this cut and paste boilerplate back that was like AT&T reserves, they're right. I'm like, no, that's not the plan I have. That's not the boilerplate I signed for. Doesn't really matter because AT&T can basically do whatever they want at any time based on their boilerplate, their, excuse me, their licensing agreement. But it's been fun because at this point it's gone from being sort of unusable to like, hey, this is actually, I can stream video on this. Yeah, it's also amazing how little bandwidth Skype actually needs. For it's like 720B streaming, you do, you should be able to do pretty well with megabytes up. But yeah, I would, I would, you know, poke around on the app and see exactly what my bandwidth is right now. But I'm afraid if I do that, I'll probably kill this conversation. Don't bring everything down. We'll try it after DTNS has done it. Let's see what happens. Yeah. I know there's somebody out there going like, what about Google Fi? And the problem with Google Fi is it's $10 per gigabyte after 15 gigabytes.  But yeah, it's going to add up really fast. Well, I think that RVMobileInternet.com is definitely a great resource for a lot of people out there. Oh, give us the name of the mushroom, the salad bowl again. The Togo C2 Roadlink or the Togo Roadlink C2. Togo Roadlink, like to go. Togo Roadlink. I guess it's probably what I'm supposed to be saying is to go Roadlink C2. I like Togo. That's much better. Yeah. And it makes me think of Jim Belushi and terrible things in Animal House. Right. It definitely made me think of Togas for sure. Yeah. Yeah. Togo Roadlink C2. Yeah. Excuse me. To go Roadlink C2. Thank you, Patrick. Appreciate that. We'll have links to all this stuff in the show notes as well. Thanks, everybody who participates in our subreddits. You guys, you know, guys and gals submit lots of stuff related to the conversation that we just had. Keep it coming. Submit stories and vote on them at dailytechnewshow.reddit.com. Also, join in on that conversation on our Discord where you can link to at patreon.com slash DTNS. Let's check out the mailbag. Let's do it. Dave in Madison, Wisconsin wrote in with a couple really good points. And this was in response to yesterday's show, Monday's show. Dave says, regarding the AirPods Pro and their new noise canceling feature, I had the opportunity to attend some live music over the weekend. I forgot my earplugs. I did have the new AirPods Pros in my pocket though. Since I was wearing my Apple Watch, I knew that the ambient sound levels were around 110 decibels sustained. However, popping in the AirPods and turning on the noise reduction prevented me getting any tinnitus the next day. So while that probably isn't advertised use of them, it worked out great in my case and I'm thankful for having had them. Then Dave goes on to say regarding the data storage on Glass Story, I work for a very large research university's library as a programmer and we have very large data sets that don't change once they're established. Something like the Glass type of data storage would be perfect for our needs. I'm especially curious how it could be used for things like our digital collections, for example, the Darefield work recordings. Currently, we use a few options, even tape backups, one of which is a service like Amazon Glacier, which is super cheap to store, and keep, but costs a little bit more to restore. Having another medium like the Glass Story mentioned would be really valuable to us. Oh, that's great. And very resourceful using the AirPods Pro for a little noise reduction. That's a great tip. Thank you, Dave. And thank you everyone who emails us feedback at dailytechnewshow.com. Also shout out to our patrons at our master and grandmaster levels, including DeGrasia, A. Daniels, Tim Deputy, and Kevin S. Morgan. And also thanks to Patrick Norton for being with us today. Patrick, you're on the move. We're so glad to have you and can't wait to have you back wherever you may be next. Let folks know where they can keep up with your life. You're going on. Twitter.tv slash Twitch. This week in computer hardware. Just search for it on your favorite podcaster or avxcel.com. Robert and I finally got avxcel up and running again and did our first episode quite a long time earlier this weekend. And it's up for our patrons and about to go out to everybody who subscribes to the podcast. We have new Patreon rewards right here. Daily Tech News show. Get a peek at our show rundown as we develop it behind the scenes chats. Join in our discord, like we said. Sign up right now. And you actually, if you sign up by November 25th, you'll get included on our holiday greeting card, lend Peralta hard at work on a new design. We'll send you a holiday card if you sign up right now. Patreon.com slash D T N S. Would you like to send us an electronic email, electronic mail, rather turn it? Man, I messed that up. Our email address is feedback at dailytechnewshow.com. We're live Monday through Friday at 4 30 p.m. Eastern. That's 21 30 UTC and you can find out more at dailytechnewshow.com slash live back tomorrow with Scott Johnson. Talk to you then. This show is part of the frog pants network. Get more at frogpants.com.


On October 13th, 1775, a new champion arrived on the world stage. Today we will add one more victory. We will not falter or fail. We will not give up the ship.


So, uh, welcome to another talk. Uh, Sophia Davis is going to be talking about picking into Python's C API. So we're all here because we like Python the programming language. Today, I'm going to talk a little about Python the C program underlying that programming language by walking through how I learned the basics of making the C, a C library callable from Python code and vice versa. So here's a screenshot of the first time I sign-faulted the Python repel. I'm Sophia. I'm an American software developer and I'm right now in Amsterdam. In the summer of 2014, I attended the recurse center, which is kind of like a writer's workshop for programmers in New York City. And this talk comes out of a very down the rabbit hole kind of project that I worked on while I was there. Um, code and soon a link to the slides will be on my GitHub. So, uh, let's get started. This is the story of how I shaved a yak. Because probably if you find yourself breaking out the Python C API docs, you started out with a different problem. Um, one that you thought you could solve using tools provided by an existing C code base. Um, so for me, this code base was a hash table implementation. So this is probably review for most of you, but just in brief, a hash table is a very powerful data structure for storing key value pairs. Um, for associating keys with values such that every key maps to one value. Where Python people, we tend to call them dictionaries. Um, they're so powerful because they're very efficient. No matter how many key value pairs you have in a hash table, the average time complexity of adding a key value pair, looking up the value associated with the key, or removing a key value pair is constant. Uh, so they go one. How does it achieve this amazing performance? Well, under the hood, a hash table is just an array. And we're going to call each index in this array a bucket. Every key value pair gets put into one of these buckets. And how do we know which pair goes in which bucket? Well, that's where the hash of hash table comes in. A hash function is just a mapping of any arbitrary input to a fixed set of values, like the set of all positive integers. When we want to put a key and a value in our hash table, we pass the key through a hash function to convert it to an integer. And then we use that number modulo the size of the array to determine which bucket the key value pair should go in. Um, work similarly for lookup and remove. We calculate the hash of the key, go to the bucket associated with that hash, and either lookup the value or remove the key value pair. Um, so here's a picture thanks Wikipedia of a phone book stored as a hash table. Um, so we calculate the hash value of each person's name and use that number to determine the bucket in the array to put the phone number entry. Um, but what happens if the hash values of two keys result in them being put in the same bucket? Well, that's called the collision. And there are a couple ways of dealing with it, but one way is just to store a linked list at every bucket in the array. Um, so every item that gets assigned to that bucket just gets tacked on to the linked list. Um, again, at the Wikipedia example here, we're using a hash function that results in, uh, John Smith and Sandra D. Um, both being assigned to the same index, 152. So we've just started a list containing both entries. Um, but if lots of items end up in the same buckets, then our hash table starts to look like just a bunch of linked lists. And the performance of linked lists is not nearly as good as those of a hash table, especially when looking up or removing items. A lookup or removal on a linked list, um, in the average case involves traversing the list, which is a big O of N operation. And as we add more and more items to our hash table, it's inevitable that more and more entries will end up in the same bins, the same buckets. Consider a hash table with an underlying array of length one. No matter what hash function you use, all items are going to be stored in that one and only bucket, and that's rapidly going to be a long-linked list. So in order to keep our average performance constant, um, we'll occasionally increase the size of the underlying array and redistribute our keys. Uh, then provided that we're using a decent hash function, the number of collisions should decrease because we're spreading out the same number of keys as before among more buckets. And how do we know when to resize? Well, if we keep track of the number of items currently in the hash table compared to the length of the underlying array, then we should resize when the proportion of items to length reaches a certain threshold. We'll call this the maximum load proportion. Um, so we've talked about three variable properties of hash tables. We've got the size of the underlying array, the hash function, and the maximum load proportion. And all three can affect the performance of your hash table. Um, for example, initial size helps determine how often you might need to resize, and that's going to be a costly operation. Uh, the hash function impacts how many collisions you might have, and more complicated hash functions will take longer to evaluate. Um, the maximum load proportion will play a role in how long those linked lists might get before you resize, et cetera. So in order to explore how these affect performance, I wrote my own hash table implementation. And it enabled the user to choose the maximum load proportion and the initial size of the underlying array. Um, my library provided functions to initialize a table with the given properties, to add, look up, and remove key value pairs, um, of integer float and string type, and finally to free the memory malloc to store the data structure, so the array, the linked lists, all your strings, data, whatever. Um, and I also wanted to explore how different hash functions would affect performance. So this is the signature of the add function in my C implementation. It accepts a hash argument, uh, because my idea was that the user should do their own hashing of the keys, and then they'd just pass that hash value in when adding, looking up, or removing an entry. And my library would find the appropriate bucket for that key value pair based on the past in hash. If the user chose not to pass in a hash with their key, then I, my library just used this hand rolled hand function, hash function, excuse me. So, um, if it's an integer, use the integer. If it's a float, round it down and use that integer. If it's a string, just use the length of the string. Um, that was inspired by the hash function that no joke, an early version of PHP used to store function names in the symbol table. Good times. Um, so it's, it's basically an awful hash function. And, uh, next I set off to do some hardcore bit shifting and string manipulation in C to experiment with writing my own hash functions. Just joking. If I were going to experiment, I'd rather do it in Python. Wouldn't it be nice if I could write cool hash functions in Python and then just call them from my C hash table code? After all, Python is so nice and easy to write, and I'm a lot faster writing Python than I am at writing C. But, you know, under the hood, Python is actually just a really big complicated C program that processes those strings of whitespace sensitive code that we write. And, thankfully, there's a well-documented API for bridging the gap between Python the programming language and Python the C program. Um, it's as easy to use this API as including a simple line in your C file. And then the magic begins. So, um, my goal is to call a hash function that's written in pure Python from inside my C hash table library. Um, little disclaimer, the C API did change substantially-ish between Python 2 and Python 3, and all the code in my talk is Python 2. Um, so, I started by wrapping everything I needed to use a hash table inside my hash table library inside of a struct. So, I've got a pointer to the actual data structure and some of those other properties associated with hash tables like the current load, the initial size. Um, I also have this py object pointer to hashfunk. Um, so, at this point, I had the data that I wanted in my Python type, but I needed to implement that API telling Python how to manage objects of this type. Um, it starts with this py object head thing, which is a macro imported with the Python header. Um, it expands to the bare minimum that you need to create a Python object, which is a reference count. Um, I chose to ignore that at the time. And a pointer to, um, this py type object, which is just a struct of function pointers defining how Python should manage objects of the hash table type. So, that's things like the class name, um, how to print and make a string representation of your object, um, how to initialize, delete and free the memory allocated to hold objects. I'll come back to these a little later. And there are a lot more that I left out. Um, so, at this point, I had my basic type defined, but I needed some way to use this type from within Python code. Um, so I created a module to contain the hash table type. Um, in order to initialize a module, you need to write a pymod init function that has the name init, your module name, so mine's init hash table. Um, when a Python program imports a module for the first time, this is the function that's run. Again, I've left some stuff out, but of note are, um, this line, which initializes the type, and it fills in more of that, uh, py type object, which, I think some compiler specific functions. Uh, here we initialize the module. And this line adds my new type to the module dictionary so we can actually instantiate new objects via the class name. Um, packaging, there are a couple different ways to package Python modules, but one simple way is just to write a setup.py file, um, telling Python the name of your module and what C files your module needs. Uh, so this is the entire contents of my setup.py file. When you run, uh, Python setup.py build, um, it creates a build sub directory and puts, uh, a, um, compile file containing your extension that can be dynamically loaded into a Python program. So on Unix, this is a shared object file. I work on a Mac, so my module was named hashtable.so. On Windows, this would be a DLL with a .pyd extension. So if you start up a Python interpreter or run a Python, uh, program in the same directory as that .so file, then you can type import hash table and do hash table stuff from Python. So that was cool, except my program kept segfaulting. And I was forced to look at a section of the API docs that I had kind of been ignoring, which was the section on reference counting. Um, one reason why Python is so nice is that it it's a pretty high level language, and it handles a lot of things for the programmer, for example, memory management. Um, when you use data in a Python program, Python takes care of dealing with the OS to ensure that that data is stored in memory. However, if Python only added to your program's memory, eventually the program would run out of memory, so it needs to know when it can remove data once that data isn't being used anymore. Python the C program uses a method called reference counting to know when it can safely free objects. So that means it keeps track of the number of other things referring to a given object, and when that reference count drops to zero, Python cleans up the unneeded object by calling the deallocation function that's defined for its type. So here are two tools that can help us understand reference counts a little bit. From the sys module, we have the get ref count function, and from the GC garbage collection module, there's get refers, which returns a list of all things that currently own references to an object. So here I've written a function, show ref counts, and all it does is find the objects that own references to the argument named an object. It prints out how many there are, and optionally it can call itself a lot of times, and it can actually print out extra details about exactly which objects own references to an object. So let's look at how this works. So in a Python shell, we're gonna start by importing the module, the tools that we need, which are the sys and GC modules, and also that function I just showed you, which I saved in a file called ref counts. So we'll start by instantiating a new object, and we'll see what the reference count is on that object. Two, all right, and if we assign another variable name to that object, then we'll look at the reference count again, and it's three, cool. So what exactly is referring to this object? We'll use that get refers function. So we've got this dict here with the two variable names that we just made, and they're both referring to object, object at memory location thing. So what exactly is that? Well, it's the local namespace. So there it is again, cool. So what happens to the reference count on an object if we pass it as an argument to a function? Well, we'll use that function that I just showed you. So first we'll call it, we're gonna pass in our object, and we'll have it not, we'll just call it once. And we will show the details about the refers this time. So we've still got that local namespace, but there's something new, this frame object in there that now also owns a reference to our object.  So we see that each time we call the function, the reference count increases by one, and if we were to look at the details of the refers, we'd see another frame object being added to the refers with each call. Cool. So if you're going to write a C extension and work with Python objects, then first you need to signal to Python when your program starts working with a certain object. By triggering Python to increase the reference count on that object by one, thereby keeping it in memory while you represented by that one need it. Otherwise, if the reference count drops to zero, then Python will free the object. And when your program tries to access that object, which is now in a piece of memory that has been released back to the OS, I guess, your program will crash, hopefully, or just like weird shit will happen. You also need to take care of telling Python when you're done working with a certain object, by decrementing its reference count by one. If you don't do your part in decrementing that reference count, its reference count can never decrease to zero, and it will never be cleaned from memory, so that's a memory leak. The Python API provides two macros to communicate when you're starting to work with an object and when you're finished working with an object. Calling PyAncref on an object increases the reference count by one, and calling PyDecref decreases a reference count by one. Also, if the reference count has reached zero, it triggers a call to the deallocation function for the type. So what happens when you forget to PyAncref an object that you need to work on? Remember that PyType object structure is a function pointer that defined the Python API for my type? This is what I had defined as the deallocation function for Python to call when the reference count of a hash table object reaches zero. It does two important things. The first one is some printf debugging, so we can see when it's being called, and it also calls the free function that I defined for my object via the PyType object struct. And so that free function also has some nice printfs, and then calls the free table function provided by my initial C program to free the memory mallet for that hash table. Initially, the set method on hash table objects returned the hash table object itself. See here, that turns self. Now, there are a lot of rules and exceptions about in which situations the caller versus the callee is responsible for PyAncrefing arguments, and I barely scratched the surface. However, I think I caused a problem here, because if a C function returns a reference to an object, like self, then that reference must be owned by the function, i.e., the object must have been PyAncrefed inside the function. But I had left that out. So let's see how this affects my program. First, we'll use that setup.py script to build our module. Okay, compiler output, great. I've got another window open here to the build sub directory, so there's our .so file. And if we start up the Python repel, then we can import hash table in my module, and we can instantiate a new hash table object, and we'll start setting some values. So not very creative, but rounded down. So remember that the set method right now returns the hash table object itself. So this is the string representation, the wrapper whatever being returned to the Python repel. Each bracket square represents one of our buckets, and each star represents an item in the linked list at that bucket. So let's set some more values, two maps, four. All right, so, uh-oh, those are the printfs that I put inside my cleanup functions. We didn't tell Python to increase the reference count on that object, on that hash table object, but all the other referrers must have released their references to that object, and its reference count has dropped to zero, and the cleanup functions have been called. So if we try to do anything else with our hash table object, like set another key value pair, then Python's like false. So, um, let's add that pie ink graph back in there, and look at the demo again. Um, I just ran the build step, and so we'll import the new version of my module, and instantiate a new object, and start setting some values. So we'll start with pie again, and there, a star representing pie, great. Two stars, looking good. No seg faults so far. Um, we'll keep going with this squares thing. It resized, that's great. We've still got three items, four items. Um, we'll try another, a string, uh, because strings are evil, um, and it resized again, so looking good, no seg faults. I think that solved that problem, at least. But, um, the other type of mistake you can make is forgetting to call pie dec graph when you're done with an object, and I also ran into that issue. So, uh, remember that my Python hash table type struct here, it contains a pointer to another Python object, namely the hash function, um, used to hash keys. So, here's a snippet from the initialization function for, of, of hash tables. Um, we do some other stuff, but I set the object's hash funk attribute, either to, um, the hash function passed in by the user when the object was initialized, or to the Python's built-in hash function, just as a default. Um, I also increased the reference count on this hash function object, because I need to tell Python, like, hey, I'm going to be working with this function object for a while, please don't clean it up. So, we say that each hash table object owns a reference to the hash function object. Um, conversely, in the deallocation function for my hash table type, I tell Python to dec, decrement the reference count on that hash function object. Um, so here's a simple demo. We're going to look at the reference count on Python's built-in hash function. Um, so I have this function here, do hash table stuff, and all it does is initialize a hash table using, uh, the built-in hash function as the hash function. So, our hash table object will own a reference to the built-in hash function object, hash. Um, it prints out the reference count on that function object, and then this program will just call do hash table stuff a couple of times. Uh, so let's look at how that reference count on the built-in hash function changes. Um, I've run the build step, and we're going to run the program. So, initially, we start out with just three reference count, uh, references to the built-in hash function object. Each time we enter do hash table stuff, and instantiate a new hash table that owns a reference to the built-in hash function, the reference count on that function object increases by one, uh, to four. Um, each time do hash table stuff completes, uh, the hash table that was initialized inside of it goes out of scope, so the reference count on the hash table drops to zero, which triggers the de-allocation function for hash tables, um, this function, which triggers a pie-deck ref on the built-in hash function object. So, uh, after calling do hash table stuff a couple of times, we still just have a reference count of three on that built-in hash function object. But, let's just say that we had forgotten to decrease that reference count, and we'll run that demo again. I just ran the build step. Um, so, this is without that pie-deck ref. Um, initially the reference count is still three up there, and each time we enter do hash table stuff, we instantiate a new hash table, which owns a reference to the built-in hash function object. The reference count on that function object increases by four, by one, to four, to five, to six, because each time do hash table stuff completes, the hash, its hash table goes out of scope, reference count on hash table drops to zero, and it's the allocation functions it's called, but nowhere did we release that reference that we own to the built-in hash function. So, after calling do hash table stuff a couple of times, um, the reference count on the built-in hash function object has increased from three to six, even though the object that, the objects that owned those last three references have themselves been freed. Um, so this is a memory leak. Uh, those three extra references were owned by objects that Python has now cleaned up. They no longer exist. We've lost our opportunity to signals to Python that those references aren't needed anymore. The reference count can never drop to zero, so Python will never remove that function object from memory. Now, we're talking about the built-in hash function here, so it's not like we really want it removed from memory, but imagine a more memory intensive object and a longer running program that created tons of these objects that could never be cleaned up. Eventually, this type of area will cause a problem. Um, so I went back and added that PyDec ref line and I rebuilt my program, and after all that, I finally had a module that worked like well enough. So, I wrote my very own Python hash function. Um, if the item to hash is an integer or a float, then we'll do this one thing I found on Stack Overflow. And, otherwise, we're clearly hashing a string, so I did this other thing I found on Stack Overflow. And, um, so I've also included a print statement so we can see when this function is called, it's prefixed by the word Python, because this is Python code. And I also went back and added more print statements to my C wrapper module and the original C library. And those are also prefixed by their origin. Um, so now let's look at how the program works. Um, so I've started an IPython repl here with that awesome hash function loaded. And, uh, we can import the module. And, um, so we can see some print statements that are, that I put inside that init hash table, uh, function. Um, so I can instantiate a new hash table object. And, um, as a hash function, we're going to use that awesome Python hash function that I just wrote. Um, so, via the C, the wrapper module, we see that it's the, the underlying C library that's actually doing the heavy hitting of like, malaking space for my data structure and getting everything set up. Um, so we can look at that new object. It's empty. Great. So we'll set some values. Um, I was on a, on a roll with squares here. So we see the, the C module, um, the set function there is, is executing the Python code that I wrote in that rep, in the repel. Uh, it's calling the Python. That's so cool. And then it's also further, you know, dealing with the underlying C library, which actually does the hard work of like adding that item into the right linked list and things. Um, so we'll set some more values. Cool. Still works. Uh, strings always break everything. So, hey, look, so the underlying C library knew that it needed to resize. So that was, that was done. And it's bigger. Great. Also, bonus, it works as a hash table. We can look up values. Um, we can remove the value, the key value pair associated with pi. Um, and now if we try to look up the value again, then, uh, the library, the underlying library looks for the key value pair. Can't find it. And the, the module takes care of returning none to the repel. Um, when I finally quit the repel, uh, then again we see the, the, the deallocation function is called from the C module, but it's the underlying library that's actually doing the heavy hitting of like walking through all my data structures and freeing stuff. Um, so I've got the Python repel, uh, calling the functions from that I wrote in my C module and that C code executing the hash function that I wrote in Python in the repel and it's just all working together and I thought it was pretty cool. Um, but, uh, if there are any questions. Are there any questions? Well, first, thanks for sharing. It looks great. Could you clarify, um, is this a typo? I don't think so. At some point you had some PyDecref, uh, macros and in other code I think I saw py underscore x decref. Is that a typo or are those different types of references? They're, they're two different types. The PyX the x decref one, um, don't throw an error if the pointer is none. Whereas the other one, if, if you can't, you can't de, yeah, if you actually have a pointer there, then it won't, it won't work. Will it be hard to make, uh, syntax like in, uh, native, uh, Python dictionary, you can initiate values with brackets and so on? Um, I'm not, I'm not sure, but I know that like all the double under methods are like related to C functions, so probably that would work. You just add it to that py typed object struct function of function pointers, but I'm not sure. Anybody else? Thanks for the talk. Well, very well structured. I enjoyed that. The answer to this question is probably no, but did you get a chance to experiment with any other ways to do this? Let me go back to my yak slide. No, I just shaved it. I thought, I thought, I thought no, because I've been exploring this. Oh, really? And there's like five or six different ways to do it. Okay. And this is one of the ways that's why I was interested in the talk, but this is a very good example. So I do, I do actually, I do like this as well. So maybe you have time for one more. Okay, nobody's home. Thank you very much again.


Ancient Mesopotamia, around 3000 BCE, no greenbacks, no plastic, just straight up barter. You want some of my barley? Trade me your silver. But as societies got more complex, barter didn't cut it anymore. Enter commodity money, goods with intrinsic value. Fast forward to the 7th century BCE, the Lydians, went all in with the first metal coins. A mix of gold and silver called electrum. Now we had a currency everyone could recognize. Meanwhile, over in China, calorie shells were the big bucks. Different places, different dough, salt, shells, large stones, you name it. This evolution from barter to commodity cash, then to paper money, didn't happen overnight. It took centuries, and it varied across civilizations, but it's what got our economies humming. So next time you spend a buck, remember its roots. Don't forget to subscribe.


Now, let us discuss minimization of errors, so if you want to consider how errors can be minimized we should know how they are estimated, now here is one example shown on the slide. Suppose our goal was to measure the resistance of a particular resistance, we have taken 8 readings, so 8 different trials of the experiment were done and then the measurements are reported here. So, 4.615 ohms, 4.638 ohms, 4.597 ohms, incidentally you can see how the table is written on that in the first row you have r divided by ohms, so this helps you to avoid writing ohms against each number in the table, another way this could have been done is you could have put ohms in brackets, the symbol ohm in brackets you write r and against that you put the ohms in brackets. So, now you take all these readings and now you know that when you want to report you will report the average value, so average of all these readings is 4.625 ohms, now some other parameters associated with this set of readings, the standard deviation, standard deviation s is equal to 0.017 ohm, you know how the standard deviation is calculated, you take the mean and each measurement is subtracted from the mean and then the difference is squared, you know sum all these up and then divide by the total number of readings. Now, another parameter associated with this set of readings is the range which is the difference between the maximum value and the minimum value, so in this case it is 4.659 minus 4.597 which is equal to 0.062 ohms, now let us see how the standard deviation and the range these can be used to specify the error in the average value, error in the average value, so when you report your result after doing this 8 experiments you are going to report the result as 4.625 ohms plus or minus an error, now what we are going to discuss is what is that error, what is 4.625 plus or minus, what is that plus or minus quantity that depends on the standard deviation but it is not exactly equal to the standard deviation, please understand this, now this is the point that we are going to discuss and this is what we will explain or help you understand how averaging reduces the error, if you average more number of readings your error is reduced, otherwise there is no point in taking more readings and averaging, this is a very crucial thing that students miss, I am not going to discuss the theory behind this, I am going to give you the result, the theory behind this is related to the distribution of the errors, for example here on this slide you show you see a histogram there, this histogram shows the number of readings in the interval delta r equal to 0.02 ohms, so on the x axis is a reading r on the y axis it is a number of readings which lie within an interval 0.02 ohms, now there is nothing very special about choosing delta r as 0.02 ohms, you can choose any other interval if you want, you can choose a smaller interval, if you choose too large interval then you will not get a histogram with variation obviously, so now you start from the 4.6 minus 0.01 to 4.6 plus 0.01 that is one range, see how many readings are there which lie in that range, now that is what is the height here, so if you take that range 4.6 minus 0.01 it is 4.59 is a lower value, now 4.59 and 4.61, so 4.597 this is one value which is more than 4.59 and 4.61 all other values seem to be more than that, so if I take the interval 4.59 to 4.61 I will get the number as 1, there is only one reading in this range, however what is shown here is 2, 2 readings there, pardon 4.613 it is more than 4.61, so it may be that the interval starts from 4.595 it is possible in which case it will go to 4.615, it depends on how you draw the histogram, so it may be it is starting from 4.595 in which case the upper value is 4.615, then 4.613 will be included you will get 2, then the next you consider 4.615 plus 0.02 which is 4.615 to 4.635, so let us see that 4.615 to 4.635, so now so that number there is 4, 4 readings, is it 4 is correct? 4.615 is 1, 3, 623, 4, so this is correct, so I think that is the way this histogram is organized, so that is how this histogram is prepared, now the theory that is developed assumes an ideal condition, if you take every large number of such readings and you were to draw a histogram by reducing this interval delta R, so you will get a shape that will be very close to a Gaussian, so that is how your readings will be distributed, now it is under this assumption that the theory for errors is developed, so we are not going to discuss the theory, these are the elements of the theory, now what does the theory say, so the theory says that error in a mean of observations is less than the error in a single observation, and the relation between the two is given as follows for the limiting case of very large number, the error in the mean sigma m, sigma shows the error, sigma is a symbol used to indicate the error, sigma m is given by error in a single variable or error in a single observation of the variable sigma divided by square root of the number of readings, now what are the estimates for sigma, the estimates one estimate for sigma is, sigma is equal to standard deviation s into square root of n by n minus 1, where n is the number of readings, so note that sigma is the error in a single observation, you are trying to estimate the error in a single observation from the standard deviation calculated for a number of readings, that is what is interesting here, another estimate for sigma because the calculation of standard deviation is little bit involved, the calculation of the sigma from this formula s into square root of n by n minus 1 is little bit involved, so one can use an approximation for this, this approximation there is a theory behind this also, it states that the estimate of the error in a single observation sigma is approximately equal to the range r, which is the difference between the maximum and the minimum reading divided by the square root of the number of readings, this formula is fairly accurate for n lying between 2 and 12, so 2 to 12 readings and in fact in practice the theory shows that since the error in the mean of observations goes down as 1 by square root n and not 1 by n, therefore there is not much point in increasing the number of readings too much, so they say you take about 9 to 12 readings, that is sufficient if you want to reduce the random error using averaging, let us do some calculations and see how this formula apply in our case, so in our case we have 8 readings and the standard deviation was 0.017 ohm of the 8 readings, so your error in a single observation estimate of the error in a single observation sigma is square root of 8 by 7 into 0.01 n by n minus 1 square root into s that was the formula that is 0.019 ohms, this means for example in our table for one reading is 4.615 ohm, if you want to show this reading including the error then it should be shown as 4.615 plus or minus 0.019 ohm, that is this is the error in a single observation, however now after averaging we obtain the value of 4.625 this is the mean, now it is important to note what is the error in this mean, it will not be 0.019 ohm, now that is the crucial thing that is what is the advantage you are getting by taking the average that will be given by sigma m the formula for which was sigma divided by square root of n, so that is how the number of readings is reducing your error in the mean, so 0.019 by square root of 8 it gives you 0.007, so if you had to take only one reading then you should report your reading as 4.615 plus or minus 0.019 that is what would have been your error plus or minus 0.019, but after averaging 8 readings the result is 4.625 plus or minus 0.007, so this quantity is less than that quantity, that is the advantage you have gained by averaging, this is how averaging reduces the random error. Now instead of calculating this quantity from the standard deviation which is an involved calculation one could have done a very rough calculation using the range, so in our readings the range was 0.062 ohms, difference between the maximum and the minimum readings, so if I were to use that then I could have estimated sigma as range which is 0.062 ohms that is r divided by square root n, so square root 8 that is your sigma and this value if you estimate it comes to 0.022, so instead of 0.019 you would have got 0.022, so that is the kind of deviation that occurs because of using a simpler method which is more approximate, and then you carry through this 0.022 instead of 0.019 you put 0.022 and then you can estimate sigma m and that is how you report here, so this is how random errors are minimized by averaging a number of readings. Finally your experiment involved calculating a quantity which is a function of several variables each of which are measured independently. For example what you want to determine is some parameter z which is a function of a, b, c and so on.  Now how will you obtain the error in z because of all these errors? Now here is the formula for obtaining the error in a function of several variables, so formula is very straightforward if z is a parameter you want and f is a function then delta z is given by dou z by dou a evaluated at a particular value we will see what is that into delta a plus dou z by dou b into delta b and so on. Now the suffix 0 here indicates the value at the mean point, so dou z by dou a should be evaluated at z obtained by replacing a, b, c and so on by their mean values. So a is replaced by average a, b is replaced by average b and so on. So you evaluate dou z by dou a and you substitute a equal to its average value, b equal to the average value and so on. So here are some examples which you can take it as an assignment because I am not going to work out for all these cases. Some straightforward cases we can see if z is equal to a plus b then when you apply the formula what you find is delta z equal to dou z by dou a is 1 so it will be delta a and dou z by dou b is again 1 so second term will be delta b. So delta z is equal to simply delta a plus delta b. If z is equal to a into b you will get b into delta b as the first term dou z by dou a into delta a. I am sorry dou z by dou a into delta a will be z equal to b into delta a, b into delta a plus a into delta b and so many times you will find the formula written as since delta z if z is equal to a plus a into b delta z is equal to b delta a plus a delta b.  So when you have product then relative errors can be estimated easily delta z by z is percentage error or relative error. So percentage error is sum total of the percentage error in each whereas if z is equal to a plus b then delta z the absolute error is sum total of the absolute errors. This is the difference between a b and a plus b. So one can work out similarly for a by b and more complicated functions shown on this slide. Now we have discussed reduction of random errors by repeating the readings and averaging. How do you reduce systematic errors? This is a much more involved topic because it all depends on what is the kind of error which is present. Yeah there is a question here. Regarding the number of readings we said that n can lie between 2 and 12 the number of readings that we take. Yes. So suppose with that the percentage error comes out to be say even 0.01% but what if the case when even 0.01% can be say millions of rupees like in finance or stock market. So there we cannot rely on few number of readings where the error of 0.1% can be millions of rupees or dollars. Let me clarify one thing. We do not say we have not said that n should be between 2 and 12. All that we have said is if you use the formula R by root delta n to estimate the error sigma in a single observation then this formula can be used between 2 and 12. That is all what we have said. All that we are saying is if you want to use the formula sigma equal to R by square root n which is a simple way of estimating sigma. Sigma is the error in a single observation. If you use that formula then this formula will be reasonably accurate if n is between 2 and 12. That is all what it means. This is not the reason why we are saying that you restrict your number of readings to 9 or 12 or something like that. That follows from this formula here. Sigma m is sigma by root n. It is from this that we are saying. This has just to do with using the simplified formula for estimating sigma. So if you see sigma by root n you can see supposing I take 9 readings. My error in the mean is sigma by 3. Even if I take 16 readings it is sigma by 4 where I have changed from 9 to 16. So it has only reduced from sigma by 3 to sigma by 4. If I go to 25 readings it will go to sigma by 5. 36 readings sigma by 6. So you see as you increase your number of readings initially you get a rapid improvement but thereafter the improvement tapers off. That is all what we are saying. It is from this point of view we said that you know you take about 9 readings or 9 to 12 something like that. So now let us come back to reduction of systematic error. So here the methods used are not so general. So method for reducing random error is very general. In all cases random error can be reduced by simply repeating the measurement and taking the average and using that formula you can report the error. But reduction of systematic error is specific to the experiments. Still some guidelines can be given you know by considering some examples. So we will consider two methods which are important and which will work in several instances. So the first method here is choice of sequence of measurements. Now when you are taking a number of readings one should consider how your result will be affected by the sequence in which you make the readings. Let us consider an example. Let us take the experiment of terminal velocity as a function of the diameter. We want to measure the terminal velocity of the ball as a function of diameter. Supposing I choose four different balls of four different diameters. Now I want to reduce the random error. So which means that I will take ball of say the biggest diameter A and supposing I choose to make nine trials of the experiments. Nine readings I will take of the terminal velocity. I will drop the ball A first time then I will use my approach of stop clock and the distance and then I will distance by time is terminal velocity. I will make one measurement one reading. I will drop the same ball again ok. I will take one more reading like this I will take nine readings. Again nothing special about just the number nine you can take twelve readings if you want right. So nine readings I take and then I average. So this way I obtain the terminal velocity for a ball of diameter A the particular ball A. Now I will do the same thing with ball B same thing with ball C and D and then I will see I will make a table ball A what is the terminal velocity B what is the terminal velocity. So then I will try to see whether as a function of diameter there is any change in the terminal velocity this is the experiment. So how many readings I should take if I follow this approach nine trials for each diameter total of four diameters. So nine into four thirty six readings I have to take. Now these thirty six readings when I take I may take about an hour or even more to do the experiment. For several reasons the temperature of the viscous medium can increase supposing I am starting the experiment at about ten thirty in the morning. Now that is the time when temperature goes on rising fast temperature of the environment I do not have an AC and so on imagine a situation. So because the environment is heating up that is one reason why the glycerin is heating up and it is heating up also because of friction. So because of these reason the temperature is increasing. Now as we have pointed out earlier this variation in temperature is the systematic error one source of systematic error in this particular experiment. Now how do I remove this effect of temperature variation. So one way would be to use a temperature controlled bath however there is an inexpensive way of removing the effect of temperature and this is where we are considering the sequence in which you take the measurements. So our impulse would be to take the measurement as follows. So I will first take so our tendency would be first I use the ball A I take all the nine readings for ball A then I take the ball B I take all the nine readings then D then C and then D. Now what is going to happen here the ball with the largest diameter is being measured at the lowest temperature and the ball with the smallest diameter is being measured at the highest temperature. So as a result when you change the diameter in one fashion the temperature is changing in a particular fashion. Instead of that what I should do is supposing I take the sequence of readings as follows. I do the first experiment with A then I do the first experiment with B then I do the first experiment with C and then D. Then I do the second experiment with D first then second experiment with C then B then A then now I change again now I start with the third experiment with D then C then D A. Now I will average the nine readings that I obtain in after I have taken the done the experiments in this sequence. Now one can show that approximately the readings will average of the readings will correspond to the same temperature for all the cases. Why because you see supposing temperature is T1 for A and T2 for D here. Now since you are following up with D immediately it is likely that both these two readings for D are at T2. Now the temperature corresponding to this reading here A would be T3. Now average of T1 and T3 will be very close to T2. So like this you are cancelling out the effect of drift of T temperature. So choice of the sequence of in which you do the readings take the readings this is very crucial is one important point in all measurements. So by proper choice of the sequence you can reduce the systematic error. Let us take one more example of reducing systematic error one more method supposing you are measuring the pole conductivity of a sample. So how do you measure thermal conductivity let us say this is your sample and you see to it that one end of the sample is maintained at a particular temperature another end is maintained at another temperature and you are measuring the temperatures at these two ends using two thermometers. So I put one thermometer here or maybe I should show it the other way around. This is the sample this is one thermometer and this is another thermometer. So this thermometer measures T1 this measures T2. Now you know the thermal conductance of the sample is obtained by if I use the term sigma to represent conductance then it is equal to heat flux divided by T1 minus T2 temperature difference. So you will measure the heat flux how much heat flux is there and you will measure the temperatures T1 and T2 and then you will put it in this formula and calculate the conductivity. Now here what you should do is a systematic error can be maybe this thermometer 2 has a tendency to measure a slightly provide a slightly higher reading than it actually is. It can be a error in the thermometer 2 that it always tends to give you a slightly higher reading than the actual temperature. Now how can you cancel the effect of such a systematic error? So what you should do you should interchange the thermometers. So you measure T1 temperature using second thermometer. So in this approach therefore you will have one reading for T1 and T2. You interchange the thermometers and then you take the readings again maybe you will get different readings T1 dash and T2 dash. Now you take your delta T as T2 minus T1 plus T2 dash minus T1 dash divided by 2. Now when you use this approach then if there is any tendency on the part of any thermometer to show a reading that is higher than the actual temperature or lower than the actual temperature this effect can be cancelled out. So this approach can be termed as use of symmetry in the apparatus. There is some sort of a symmetry in the apparatus which you are using. So you are interchanging some elements over there and then using this to cancel the effect. Another example of this use of symmetry in the apparatus supposing you are measuring the resistance and unknown resistance using this potential balance approach. So you have a standard resistance and you have the unknown resistance and you have a wire uniform wire which you are going to tap and a moving pointer a moving tap and then you have a galvanometer. This is the approach which is used to measure resistances precisely. Now when the resistance of this part to this part ratio of this becomes equal to this resistance by this resistance your galvanometer will show zero reading. This is so called potential balance approach of measuring the resistance. So how can you measure the resistance from this? Since this is uniform wire the resistance of the wire is proportional to its length. Suppose total length is L and you have a scale here which allows you to measure let us say distance from this end of the pointer suppose this distance is x. So then you write rx by rs is equal to x by L minus x that is how you get rx. So you know rs, you know x, you know L. Now what one must do is because it is alright to write the formula like this. In practice there are contacts here and there will be some resistances associated with these contacts which also need to be taken into account. Now how can you cancel the effects of these? So what you should do is you should interchange you put the standard resistance on this side and put the unknown resistance on this side. Now if this so called end effects that is effects of these contacts are really absent then your new potential balance point would be this point will move to another point which is exactly distance x from this end. But in practice you will find that will not be true. So moment you find that that is not true then you realize that you are having something like end effects which are systematic errors. So now you can take the two readings and from there you can cancel out the effect of the systematic error. Now how can you do it in detail that I will not go into I am just pointing out methods. This is all common technique that is using symmetry in the apparatus and interchanging components to cancel out the effect of the systematic errors. So now let me come to the end of this discussion of experimental skills fitting a straight line because this is very very important and done very often. There are several ways in which you can fit straight lines very commonly used method is the method of least squares. So here you have made several measurements. So you want to know the behavior between one dependent variable and an independent variable and you want to approximate this behavior by a straight line. So you have taken several readings y i y is one variable several readings for y x is another variable. So you have taken equal number of readings for x which you call as x i. Now what is the best straight line which describes the behavior between y and x. So that straight line if you use the method of least squares we will just explain what is the method of least squares. First let us look at the formula. The slope m of such a line is given by sigma x i y i minus sigma of x i into sigma of y i product of this divided by n divided by sigma of x i square minus sigma of x i whole square divided by n and the constant c is given by sigma y i divided by n minus m into sigma of x i divided by n. Let us understand this method of least squares and fitting straight line by this method. If you look at this particular paper slide now this is a graphical representation of what we are doing there. Again you will appreciate how graphical representations explain things very nicely. So for example I have taken reading y i x i. So this is y i and this is x i. Like that this is x 2 y 2 x 3 y 3 x 4 y 4 and so on. So I have taken 1 2 3 4 5 6 7 8 8 readings for y and 8 readings for x and then I have plotted them on this graph. Now I want to know the best straight line that passes through all the points. Now it all depends on what is your criterion of the best straight line. The method of least square says that it minimizes this particular sum here shown here. Sigma of y i minus m x i minus c whole square. Again if I want to show this graphically what it means what is y i minus m x i minus c it is the distance of the reading from the straight line. So this is y i and then m x i minus c it is this. So this difference is this. So what you are doing is your straight line is such that if you take these differences this length this length this length this length this length and this length and you square each of them and sum all of them up you will find that the formula that we have suggested if you use that formula some of these squares of these lengths would be minimum. You take any other line some of these squares will be more that is the method of least squares. So with this we come to the end of the experimental skills.


Crosse! Hey everybody, Dr. O here. In this video we're going to cover the body planes. But first let's chat about why it matters. So the key is that humans are three-dimensional objects. So we need the multiple planes, the X, Y and Z axis, to actually orientate ourselves. So the two key places where you're going to see body planes being important will be with medical imaging, like your CT scans, MRIs, those types of things that are recording you in three dimensions as well as in kinesiology. So when a body is moving we're not robotic, right, when we move in all different directions. So kinesiology, so the study of the movement of the human body and medical imaging will be when these are important. All right, let's go ahead and go through them. Let's start with the sagittal plane. So the sagittal plane will separate any structure, like this woman here, into a left and right half. So or another term you can use, these terms aren't used very much anymore, but you still do occasionally see them, would be sinister and dexter. Just kind of interesting, sinister means left, dexter means right. So take that for whatever you will, I'm left-handed, so I don't like the fact that left is sinister. But the sagittal plane separates between left and right halves. If you separate it right in the middle, like this green line here, then this is a mid-sagittal section or mid-sagittal plane. If it's off to one side or the other, so the two halves are uneven, it would be called parasagittal. All right, so that's the sagittal plane. Next we have the frontal or coronal plane. So corona means crown. So the frontal plane will separate any structure into an anterior and posterior half or a front and back half. So pretty straightforward there. So that's the frontal plane. Then lastly we have the transverse plane. Another term you're going to see with this quite often would be a cross section. So separating something into a superior and inferior half or a top and bottom half. All right, so those are your three main body planes. So just like I was mentioning before about how human movement is messy, these planes are often messy too. Of course there are oblique planes, there's going to be transverse planes that aren't right in the middle, but these are the three main body planes. All right, you have a wonderful day. Be blessed.