 Welcome to Emerging Languages Camp 2010. Frank by Alan Eliason. Okay, we're going to get started here. My name is Alan Eliason and I will be talking about a few features of my programming language called Frank. I'm just going to be able to cover a few features, some of the distinguishing features of Frank. One of those is that it tracks units of measure through all calculations. This gives you the ability for doing physical calculations easily and making sure that they make sense. It has a large library of standard data. One of the design goals for Frank is that I try and do the right thing with numerics. And it also has a few other features I'll talk about such as interval arithmetic, symbolic algebra and some other graphical features that I have. Very short history of Frank. The precursor language to Frank was developed at the University of Colorado. And I built a system for tracking units of measure in a special purpose language that's used to in environmental simulations. And that eliminated a large category of errors with people mixing units that were having expecting units in one unit of measure or another. But that was a special purpose language and I couldn't use it anywhere else. So a couple years after that, I got one of those always forwarded emails of interesting trivia that said, if you fart continuously for six years and nine months, you'll have enough gas to create the equivalent of an atomic bomb. And I said, well, that's pretty gross. And then I said, but that doesn't sound right. So I need to calculate that. So I tried fiddling around with the units program on Unix and I was trying to take square roots and it couldn't do square roots. And I couldn't have more than one division per calculation. So I said, well, it's about time I build my own programming language. So let's take this as a little example here. This is the Frank interactive interface. What I'm going to be showing you is a lot of one line calculations here. So if we have a unit of time here, I'm going to put in six years and nine months and that gives us the output in seconds. You can also convert that to different units, but then I'm going to go up here and I'm going to say, okay, an average size or a small size atomic bomb may have a yield of about 12.5 kilotons of TNT. And Frank has these units of measure built into its standard data file. So I can say 12.5 kilotons of TNT divided by six years and nine months. And what that gives me is a, what that gives me is a, so these may be a little bit off. It's being annoying here. So that gives me a set of units of measure and it tells you that it has units of power. You can see that those are in the base units of the international system of units, but usually you want to get those results in some sort of units that you're familiar with. So I'm going to convert this to watts and let me just see if this helps anything. So that is a 245,000 watt fart. That's probably a lot of power. You can also convert it to different types of units that you may be more familiar with such as horsepower. So a 329 watt fart is pretty powerful. So if you want to turn that into something that you can actually see if that's even feasible in any sort of way, you can see how many calories per day you'd have to eat to be able to sustain that sort of power. And you should note that Frink is case sensitive. This calories is with a capital C is what is a food calorie. It's what a physicist would call a kilocalorie. So you would actually have to eat 5 million calories a day in order to maintain that sort of an energy. So it doesn't really sound too feasible. Frink takes numerics very seriously. You can do simple calculations there. It does maintain proper order of mathematical order of operations. Numbers can be arbitrarily large. So I'm taking 17 to the hundredth power. You can use named numbers like billion and has a lot of other built in mathematical functions and operations like factorial. So a hundred factorial. Frink also has rational numbers as a data type. These are automatically reduced to their lowest terms and demoted back to integers when necessary. And parts of rational numbers can also be arbitrarily large. So you can say one over a Google or something like that. Anything with a decimal point in it is an uncertain floating point number. So if I say 1.0, that's a floating point number. And if I divide it by three, it will give me the results. So Frink does do arbitrarily precision for floating point numbers as well. So I just set the precision for internal calculations to be 40 digits. And it will give me all the digits there. Also, if I have something like 7.0 to the thousandth power, floating point numbers can be almost arbitrarily large. This is something that would overflow normal IEEE 754 math. So floating point numbers can be very large. Frink also knows about complex numbers. If you take the square root of negative one, it gives you one I. And all of Frink's functions are complex aware. So if you take the arc sign of a number, it will give you a complex result. So all those different numeric types are managed automatically by the programming language. You don't have to do that manually. All quantities can also have units of measure. So if I say 100 yards, I can also get those results in inches. So this is using the arrow operator, which is the conversion operator. And that formats results into something you may be interested in. So you can also put that in quotes. And it will append the units of measure to your output there. You can convert it to meters. And when you see an exact conversion like this, this is giving us a rational number as a result. That's to make sure that these calculations are reversible. And it knows that there is an exact conversion between feet or yards and meters. And you can also break this up into its constituent parts. Like if I wanted to see it in meters and centimeters, you can break it up into 91 meters and 44 centimeters. Frink will also prevent you from making many types of errors. And you can mix units of measures somewhat transparently. So if I say 100 yards plus 3 meters, it will automatically do the right thing with those. So you can mix units of measure throughout your calculations and Frink will automatically make sure that the result is correct. If you do something that doesn't make sense, like a thousand yards plus one day, it will give you an error saying those units of measure do not have the same dimensions. But you can also do things like you can multiply that 100 yards times 160 feet, which you might recognize as being the dimensions of a football field. And you can also convert those to other units saying us how many acres that is. And it gives you an exact rational number for how many acres would be covered by a football field. It's just football fields just over one acre. So you can also do a lot of physical calculations like a common one has said, if everyone in China jumped off a chair at the same time, it would throw the earth off its axis. Well, we can calculate that. So we say, oh, there's a 1.2 billion people in China. They average about 120 pounds and they jump off a chair that's two feet tall. And we want to get those results in joules, which is a unit of energy. Now, Frink helps you right here when I tried to do that calculation. It says, OK, the left side of your calculation has these units, but you're trying to get an energy. So it gives a suggestion. It says multiply the left side by an acceleration. And for help, you can type units acceleration and Frink will list the units of acceleration that it knows about. And you say, oh, yeah, I forgot to tell you that they're jumping off in the earth's gravitational field. So multiply that by gravity, which is the standard acceleration of gravity. And it gives you an answer in joules. Well, that number is still not very meaningful. So you can convert that into something like, how many tons of TNT would that be equivalent to? And it's only equivalent to about 93 tons of TNT, not that huge of a thing. Or you can say, oh, how many gallons of gasoline? Oops. And it's only about equal to the combustion of about 2,700 gallons of gasoline. Or you can convert it into something like, oh, would that be on the Richter scale? And it's only about a 4.8 on the Richter scale. So we can debunk that rather easily. So if you don't know what Frink calls a unit of measure, let's say, right, what's a qubit? And a few people got that. So you can precede part of the unit name with a question mark. So you put question mark qubit and it tells you about all the different types of qubits that have been defined through history. If you do two question marks, it will give you more verbose information about each one and its size. You can also use a single question mark and you say, I want to convert that to inches. So it'll give each one of those to you in inches. It also knows a lot of things about planets, fundamental particles, things like that. So if I do a question mark moon, it'll tell me what it knows about the moon. If I do two question marks, it will tell me the values of the things that it knows about the moon. And you can also do the same things for, say, the proton or Saturn. So it has a large database of built-in standard values that you don't have to go and look up. And that makes a lot of calculations a lot simpler. So for example, it knows a lot of fundamental constants so you can cut and paste physical equations without a lot of modifications. So if you put in C for the speed of light, it knows that. It knows the gravitational constant. It knows Planck's constant. It knows things like pi and E. So all those things, you don't have to go out and look up and say, okay, how do I convert that with the units of measure that I have? So it makes some of those types of calculations much easier. It also has other sources of data that can be loaded dynamically such as inflation calculations. So let's say you bought a house for $35,000 in 1970 and you want to know how much that's worth now. It will go out and fetch consumer price index data to convert that for inflation. So that's worth about $186,000 right now. And it also does that for the British pound. So if you're reading some Charles Dickens and you have six shillings in the year 1830, I'm not sure what I'm doing wrong there. I'll have to try that one later. It also does currency conversions. So you can say convert the dollar to Euro and it gets live currencies. Now if you want to see, for example, what the different units of something are, you can say unit and then what Frank calls it. So units of currency and it's thinking. Not sure what it's thinking about. It should not be fetching the values, but maybe it actually is. So that would be a bad thing. There we go. So it even knows it actually fetched historical conversions too. So let's say I also have a, it's not taking input anymore. Frank can also do different types of calculations like you can say and translate it to a different language. Either I dropped my network connection. So some of these examples won't work. Anyway, Frank knows also about different units of time. These are integrated. So if we wanted to meet again in a billion seconds from now, I could say now plus one billion seconds. And it'll tell me that's the end of the year 2042 and it's on a Saturday. Or if you wanted to know what that was, say in France, you can convert it to that time zone. Frank also has other systems of time like Julian days and Julian day of femoris, terrestrial atomic time, dynamical time and things like that. I'm going to define a function here. So I'm going to say this function is 3x squared. Then you can just call the function that way. So it gives the value of 12. Sorry about the scrolling here. It can also do symbolic calculations. So if I have undefined variables like f5y, it's going to tell me that it's going to turn it into 75y squared. And there's a little bit of warning there. What I'm going to do is turn on symbolic mode and then it suppresses some of those undefined symbol warnings. Okay, I'm going to go back to some of my design goals were to preserve normal mathematical notation as you've seen. Anti-goals is I do not want to try and parse English sentences that they are ambiguous. And I want it to be portable. So Frank will run on your Android device. If you have one, you can get it in the Android market. You can write little programs that are portable. So portability is an important thing. Mathematical notation forces the way that the language looks a little bit. One of the things to remember is that multiplication is the same precedence as division. So on that bottom sample there, you do want to put the parentheses around the two hours. Units are converted into the base units of the international system of units, plus two that I've added for information and currency. So it just tracks the, in terms of these base units. But the user can also make their own data file. Skip that. There are, you can add prefixes to these things, kilometer. And you can also use single or plural of defined units like meter or meters. There are some special operators like conforms to see if a certain variable has the same units as another unit of measure. Frank also does symbolic calculations. And I'm going to just show this to you pretty quickly. This is a relatively new feature. A lot of the time you have equations that you need to solve for a variable. For example, this is an equation for the power radiated by a black hole. And it gives it in terms of p, which is the power. But I wanted to resolve that for the mass. So this is a little sample of Frank's server page. This Frank also runs web-based applications like this. So you can solve it. You can tell it to show its work. I don't have a network connection, so I guess it worked. Showing its work and transforms one expression to another. So this is a library that's going into Frank that's going to be pretty powerful. I'll demonstrate another solver here. This is a system of equations. These here are the equations of an ellipse, these three lines here. And Frank can automatically solve that system of equations in all the different ways it can be solved for all the different variables. So that saves the program a lot of work in rearranging equations and what this is eventually going to be targeted for is to solve systems of equations and have sort of a magical dispatching class where you enter your knowns and unknowns and Frank will calculate all the rest for you. So it does have a pretty general-purpose mathematical library that's built into it now. I haven't really announced that too officially because it's still changing a little bit. You do the mathematical transformations by writing transformation rules that look like this. This first rule would only match a literal ax plus bx and then transform it into a plus b times x. So anything, any variable name that begins with an underscore is a pattern, which means match anything, not just the literal variable a, but we will match something and we'll call it that pattern a. And when you're doing these pattern matches, there may be the case that you have default values like this a is 1 if that doesn't appear in the equation because you don't usually write 1x, you write just x, and so this will also recognize different types of patterns. And there's also ways of making conditionals here with your transformations. And then after you've defined your transformation rules, you can transform them using the transform expression function and that will apply all the transformation rules you have defined. Here's a really simple sample here. This is one to do all the derivatives that you learned in your first semester calculus. This is the whole thing for solving pretty much those arbitrarily complicated derivatives as you can imagine. So you can write rules for doing math quite concisely here. Okay, I'm out of time. I will talk about, if anybody's interested, I will talk about the interval arithmetic and some of the other advanced features of Frank and its numerics if you catch me any time in the next couple of days. Thanks. Okay, go ahead. I'll get with you. The difference is between survey feet and modern feet, which was a definition changed in 1959. Too much to get into right now. It's the right answer. You can ask a surveyor and they'll explain that whole thing to you. It's really nasty. Any more questions right now over here? It's a pound mass. That's another thing, a defined change. The pound is defined as a unit of mass by standards bureaus and has been since 1893. You can use pound force or LBF to indicate the pound force. It goes out and fetches the live consumer price index data from a couple of different web sources. So I don't do depreciation by, say, wage of a worker. That's another way you can do depreciation calculations. Okay. Okay. Yeah, I don't do that. Do one more. This is a full featured language. And I only got to show you a little bit of anything. It has regular expressions, classes, object oriented programming. It is a full language and it runs things like Frank server pages. So it is a fully capable system. I don't want anybody to get the idea that this is just for, you know, this is a calculator. I didn't even get to show you good, cool programs. But it has lots of big sample libraries for doing high accuracy astronomical calculations, atmospheric kinds of things. So you can really write real programs that do real stuff. Okay. Thanks.