Live CEOing Ep 755: Language Design in the Wolfram Language [DigitSum, SphericalAngle and More]

Stephen Wolfram discusses designing new functions for the Wolfram Language, including DigitSum and SphericalAngle. The conversation covers naming choices, message handling, and the practical decisions behind adding features to a programming language.
Chapters
Okay. Hello everyone. Welcome to another Wolfram language design review. Getting Ready for version 14, part of our incremental language development series. All right, the first function here. Okay, we get the ZF page. This was a suggested by the AI function, as I recall, correct?
Yeah, it was one of the ones that came in through our LLM tools. And Danny and Ian put together the function and ref page and we just wanted to get a final once over.
Oh, wait a minute. What the heck's happening here? This is not letting me type here, see if this works. That worked. So this goes along with digit count.
Right? And digits.
Yeah, I think this is just fine.
Mm.
Yeah, we included it, for example, supports mixed radix forms. So basically the sum of the.
Yep, looks fine to me. Okay, onward.
Sounds quick and easy. Second one will probably take a little more time and that's spherical angle, which Brad has an example here. And there's also a ref page to see.
What the heck is that thing?
Well, it's a graph of vertices on a sphere that has some special angle properties. Actually those are great circles if you turn them into arc arcs instead of lines. Maybe we should look at the documentation first though, because this is kind of like a neat example that the documentation has more simple things in it.
So we looked at spherical distance last for the last version, right? We have.
Yes. And what we did for spherical distance is that we pretty much implemented hyperspherical distance and that was basically set. The pattern for what we're doing here is that if you input, if you input coordinates, that or high dimensional, it'll actually tell you in an angle between two great circles on a, you know, in sphere, similar to the spherical distance tells. You can tell you a distance on an N sphere, but.
So the input to this is a specification of great circles specified with two points. Is that right?
Three points? Yeah. And that the specification for this is based on planar angle. It's very similar to planar angle.
I need to remember how planar angle works. Oh, I see. Yeah, I haven't used planarangle very much and I'm surprised. It seemed like a function one should be using all the time.
Yeah, actually I didn't know it existed, but now that I know about it, I think it is a pretty good one to use. And there's only one thing that we found a little bit surprising about this specification, which is that if you see the first and second usage there, they. One of them returns a signed angle and the other does not return a signed angle. And in spherical angle we just made A decision of returning the signed angle as often as possible.
But what do you mean it doesn't return sign? I mean, doesn't it.
You'll have to look at.
You'll have to look at the open details.
Yeah, because there's something in details. It splits cases or something.
Yeah.
The signed angles are the counterclockwise and clockwise. And the intent is that you use the rule form. The other ones are triangle angles, which we introduced for synthetic geometry. And those are not signed, although you can use either syntax. But the intent is the list of three points is for triangles and the rule is for angles between lines.
That seems sensible. I mean, so are you proposing something different for the spherical case?
Well, yeah, the way that it is now, if we can return an angle with a sine, we return an angle with a sine. But there's another caveat here, which is that, you know, the ability to get a sine for the angle depends on having the correct dimensional constraint for the cross product. So if you go up into higher end sphere cases, then you don't have a functional cross product anymore and the situation is non orientable. So we just return an angle without a sine in that case.
I don't understand. Why is there not. I'm very confused. Lines are always definable in any number of dimensions.
Yeah. For the N sphere we can all Because. Well, actually, what happens with the N sphere is you might not. You have two great circles, they might not even intersect. But when you specify the thing as being one point from one great circle, one point from the other great circle, and then the point where the two great circles intersect, we've already sort of circumvented that problem.
So hold on a second, hold on a second. You're saying that on A five sphere or something, great circles do not necessarily intersect.
No, they don't.
Huh.
Because I, and I think you can like understand this even with the A3 sphere or A4 sphere that, you know, you have different copies. You could, once the space is big enough, you have different copies of S2 in there. And if the circles are on those different copies, they don't intersect.
Okay.
In four dimensions, for example, you can have a plane fully perpendicular to another plane.
Okay, I don't understand this. First note that says that it's using the same conventions as coordinate chart data. Right. Because coordinate chart data is giving you. So, I mean, the spherical or hyperspherical coordinates of coordinate chart data are extrinsic coordinates on the sphere. And you are. And Right. This is supposed to be Something intrinsic. So I have no idea what that note is even attempting to say.
The note is exactly the same as the one for spherical distance.
So what you said is true. It says we are removing the radius and by that that's the only projection we do to the sphere. So our coordinates are like those of coordinate chart data without the radius. The radius is always one.
Oh, this is the. I see. So. So this is for the input.
Yes.
These are the coordinates for inputting the points. Not for the answer.
Exactly. Yep.
Okay, so. All right.
So. So this is the general case of three points in GEO direction. For example, one of the three points is always the north pole. That's why geodirection only needs two points.
By the way, this should say it's in radians. Doesn't even mention that.
Okay, thanks.
Yeah, it should.
But yeah, so maybe following Jose's comment, I think under, under the comparisons or something, there probably is a geo. GEO example there that would be helpful to look at. Okay. Right, right here.
Why is this in applications? This should be in properties and relations. It's not an application of spherical angle.
Why is it not? You're computing the angle on the sphere.
I know, but I mean this is really comparing it with. Well, I don't know what it is.
No, it's saying that is an area. So it's saying that you can use this function spherical angle to compute the area of a region.
I know, but. But you're not supposed to. We've got geofunctions to do that. This is really the comparison between this function and the geofunctions.
Okay, well we can move it. That's fine.
I think it should be in properties and relations. Like it's a good thing to have that. But I just don't think it's an application of this function because you know, if you're trying to do geo, we.
Have lots of applications for things that you can and then compare with the built in function. I mean that's. This is not exceptional in that case.
Well, it's the wrong thing. The application is supposed to be things you would use this function for and not other functions. If it's the relations to other functions, put it in properties and relations. That's what that was for. By the way. Cube shouldn't be capitalized here.
Okay.
I don't know exactly what this is. Looks interesting, but don't know what it is.
Oh yeah, here's something good. The convention turned out to be different because the, the mathematical people use counterclockwise for in the. In in geo, it's clockwise.
So.
Yep.
Yeah, okay. That's an unfortunate historical thing.
And then this is the Pentagramma mirificum is some old thing that I guess probably Gauss had worked on, where you draw like five great circles on the sphere. And it's possible that, you see, you get a pentagon outlined and the pentagon has star points on it. Those star points that are on the pentagon to turn out to have right angles. It's a four join vertex and all those four, those four angles are 90 degrees.
Okay, right.
Yep. That's the definition of this pentagram is, is all such geometries that have that 90 degree condition.
See also here. Well, you'll put them in.
Yeah, well, we'll put in the planar angle. Spherical distance.
Yeah.
And the GEO stuff in the G looks good to me. I mean, anything more we should discuss with this?
I. Well, I want to talk more about the, the signed, not signed. I mean, there's a utility for, you know, the unsigned thing, which is why planar angle does that. Right. And if you want to be talking about, you know, sums of angle, you know, sums of angles of triangles being greater than PI and things like that, I mean, do we really want to have this difference with planar angle?
Well, you know, it's just a matter of adding mod2pi.
All angles are defined mod2pi. Right.
Well, if we say spherical angle here, let me just understand this. If I. What the heck? Why isn't this working? This is the prototype build. No, it's not. Where is the prototype build? Okay, so if I say, If I say spherical angle of. Let me pick some random point on the sphere.
Let's say you need to have it in spherical coordinates.
Yeah, okay, that's fine. I'm saying two, one here. And that's my points you got to spend. You got to specify how these points are specified. You're not saying that.
Yes, yes, that's the first note that we discussed.
Okay. But you should show that it's explicitly theta phi. So I'm assuming that if I do this, if I say I've got this triangle and I've got it going from 2, 1 to. Let's say, you know, 2.1, 2.1, 1.2, you know, 1.91, 1.3, let's say. Oh, wow.
Now, now try to do reverse of that.
Okay, but now, now what I want to do.
So take that first input. Sorry, that first input is inconsistent with planar angle because that syntax for planar angle would be the interior angle of a triangle.
Okay, so hold on, let's just get the sum of the angles of the triangle. Okay, so this is presumably, if I'm not mistaken, it's rotate left of this thing. Table of. Rotate left of that thing, comma, N. Am I right?
Yep. And there's a threaded usage, so you can get all the angles just by putting that whole thing in spherical angle.
Okay, so 0 to 2 here. Right? Like this.
Yep.
Okay, so now let's say spherical angle of that. Okay. And now let's say total of that. Oh, splafferoo. Why the heck isn't it. Oh, I see. Because it's the sum of the triangle. Yeah. Okay, so if we take these things.
That should be the area. Right. That or. Or even though it's got a sign on it.
Yeah, but I don't know what that sign is doing. And I'd like to see the following thing. So I'm going to take. I'm going to do this. I'm going to say here, Now, Grind, grind, grind.
Right.
I mean, that's not going to have a simple expression.
No, I. I'm not sure what we're trying to accomplish here.
Well, here, let me. Let me do what I'm trying to do. Let's say plot percent 8d from 0 to PI, let's say. So that's the sum of the angles of a triangle, which will always be greater than PI.
So this contains information about the orientation as you follow the three points.
Yes.
Yeah.
Right.
It's different.
Right.
Which was. Right. Not what the case would be for this syntax in planar angle, where it always gives you the interior angle.
Yes, we fully accept this is different from planar angle. Now the question is, what is more useful?
But it is always giving the interior angle.
Well, the interior angle can't be negative.
No, it can be negative if you read it backwards.
Not in planar angle.
It's not planar angle.
Yeah.
Yes, Inconsistent with planar angle.
And that is. Exactly.
It's got an orientation associated with it.
Right. Like geodirection, for example. Your direction always keeps the sign.
Okay, so.
And yeah, I'll. I'll just say I, I don't. I don't have too much of a preference about this, about the consistency thing. I asked Jose about it. I think Jose kind of made the decision of keeping the sign. But, you know, if.
Okay, so hold on, let's talk about it. What do people think about this? I don't know enough to know what the right thing to do is here.
So my view on this is that if we always report the signed angle. There is a way to remove the sign, but if we don't report the sine angle, there is no way to remove. To add the sign. So that, that's, that's my main.
Why don't we say right here gives the signed angle between the great circles, blah blah blah.
Because there's no way to give a signed angle for the higher dimensional cases.
Right. It's only for the 2 to T. We could do what you said at the beginning. Have a first line that instead of P is theta phi.
Yeah.
And that specifies the case of the two dimensional case. And there we put sine tan mode. Yeah.
Say gives the higher dimensional. And then it's, you know, theta phi, theta one, theta two, dot dot dot phi. Higher order, you know, higher dimension.
Yep. So you're still get rid of all the pqr.
No, no, no. We just added a first line with a two dimensional case and there we put signed.
Okay.
Yeah.
And the rest of the cases are.
It looks good to me. I mean, when do we get all the rest of the spherical trigonometry functions for them? This one looks to me like, I mean a lot of effort has been spent on this one. It seems like it's just great.
But no, it's actually, it wasn't. I don't think it was too much effort. Main thing that's been the effort was the. An exploration of spherical clipping that we did.
What does that mean?
Well, like, you know how we have the. We have big geocountry polygons.
Yes.
Whenever we create a map projection of the Earth.
Yep, yep.
We, we need to chop the boundaries.
Yep.
And we, we want, I mean ultimately in the long term, I think we want to have the mathematical version of that algorithm.
I see. For what purpose? Go ahead.
For applications to the geo. I mean it would be really great if we had the spherical version of that. Then we could. The mathematical version. We could use the mathematical version to.
Do as opposed to the version that just works with coordinates.
Well, I think that there are two parts here. So this project has the computational part, all these functions to compute things like distances, angles, areas, et cetera. And then the graphical part, we need sphere graphics and polygons, et cetera. And so the graphical part will be shared with geo, but the mathematical part here, it's more complicated because we want exact results, et cetera. So it goes beyond what GEO needs or does.
Yeah. Okay.
And so that's the part that Brad is focusing right now. We are developing at the same Time this framework for graphical spherical graphics. And that will be shared and that's where we are working on all these algorithms. And then of course Brad wants also some of those algorithms to work. Exactly. And it will be done for this spherical part.
Okay.
The mathematical spherical part. But that's under development.
All right, should we move on?
One last question. Do we envision spherical angle getting a second argument like planar angle has.
What is planar angle? Second argument?
Well, you can specify usually the. There's an orientation inferred by the order of the points. But you can just override that and ask for the different orientation. Or in the case of triangles, interior exterior for. Or full exterior.
Seems two dimensional case.
Jose and I talked about it and decided to leave it out so far.
Okay, fine. I don't think it's terrible to leave it out for now. All right.
One. One final comment. So as we proceed with all the sphere functions, should it be all spherical or sphere? Because I find myself using sphere graphics and sphere polygon rather than spherical graphics. Sounds a bit strange. So before we move on with more spherical functions, we need to make that decision.
I think it should be spherical. I think sphere. That's a bit odd. I always thought they were going to be called spherical X.
Sort of like the difference between plane angle and planar angle. You have to make a choice.
Yeah. I mean it's the adjectival form. It's a spherical angle. I agree that sphere graphics is a. Well, gosh, I mean that would require. What is the family of functions.
Well, I think here we will need the graphics itself plus the primitives polygon, point line and then we will have more. The computational part I was referring to before sounds nice. With spherical distance angle.
Yeah, absolutely. Spherical triangle is what you always call it. You don't call a sphere triangle, which I don't know what the heck that would be.
Right. But spherical graphics. I don't know. It sounds like it's. You are not referring to. It's the graphics that is spherical. Not. Not a graphics or honest.
Yeah, no, I understand, I understand. But I think, I think it's going to be. Have to be the spherical family. See, presumably we're one day going to have hyperbolic graphics too or something. And those are adjectival forms. It's not hyperbole graphics.
Okay.
I mean we cheated with geo and astronomy by using the word roots right?
Exactly.
But I don't, I don't think we can do that here. I really do think spherical graphics can be a worthwhile, very nice function And I mean, shouldn't be that difficult to do, Right, based on geographics technology.
Correct?
Yes, yes. But fundamentally it's all vector or vector has to work well, and that's the part where current geographics is weak, and that's what we are improving.
Yeah. Okay. But there's no base map for spherical graphics, presumably.
Yes, it will be just white as graphics itself.
Yeah. Okay. All right. Comap. Oh, my gosh. Yep.
COMAP and COMAP Apply have been least provisionally approved as experimental functions for version 14. I think the main sticking point still is if we want a different name. But we wanted to review that.
We've been through this name for five years. I mean, you know, this, this is the. I don't know whether I'll ever remember how this works, but, you know, I don't know.
It's.
It's one of these things. Where will it reach above the. The level of, you know.
Will it use like map or will it get used like through where it.
Yeah.
Have to check the ref page every time you want to use it.
Right. I think its name is as good as we're going to get.
Satisfies some kind of misery minimax condition.
Yeah.
So the, the main question is, are we satisfied with leaving it as experimental or do we? Yes. Okay.
Yep, that's what we should do, because it might change its name if it really isn't comprehensible. People are like, what the heck is this?
Okay.
Okay. Message redirection.
So this is a bit of a spinoff from the general topic of error handling. We talked last time about the general error handling packlet, and one specific utility that, at least within the IL group we use a lot is message redirection. Because a lot of times we're writing a function that either has similar argument handling to an existing function or is built on top of an existing function. And we don't want calls into COMAP to start issuing map messages. So we have utilities like this level queue function that basically just calls map on an argument to see if it's actually a level spec. And if it does, then it has to issue the same message over again. And if it doesn't, then it carries on its merry way. And so Rick has this nice function in the function repository that lets us do message replacement, at least for existing messages, just by applying a rule to the message head or the function head.
Which I'm sure breaks in all sorts of lovely ways.
Yes, there are various caveats, like if the message doesn't exist, you know, it's only defined for a specific set of heads and you issue with another head, then you're going to get a missing message. Message.
Does the most general case work where you're replacing every message from, you know, emanating from inside with the head that you provide it?
I believe I made that work, but it's been a while since I looked at it.
So that might be the most important single case.
Sorry, say that again.
Where, where you want to replace everything that shows up as a message with a particular head. Like I am comap and anything that I call under the hood that issues a message, I want it to be comap associated with Comap with. If that case works.
Where you want, you want the messages branded with your brand.
Yes. What I'm maintaining is that that is the single most important case and if that works well, that's useful. I mean, even if it's only an internal utility, we need it often in ILD work.
I did make that work actually, and I put it in chat as an example.
I'm kind of confused about the name of this function and I, I. You're saying that within a block, any message issued within a block that was a power message will now be a myfunction message, Is that correct? Inside this expo here?
Yep.
Any power function, any message.
Any message generated by power will instead.
And how does the off stuff work? Does the off stuff work correctly?
I doubt this works correctly in the general case.
I mean, does off work, does off work with my function? You know, I believe it would if.
You did off of my function with like the infi tag or something like that. But it wouldn't respect off of power messages.
No, I understand, it shouldn't. I mean, that would be correct. I'm just surprised that that can work.
I actually, yeah, I don't actually remember. I'd have to dig into it again.
And there are caveats like the, the message, the power messages are not actually getting issued. So if you have an outer function that is checking for power to issue that message, it's not going to catch it because it's not actually getting issued.
Right.
I, I think this function needs more thought.
Yeah, I think it requires quite a bit more thought. But I mean I'm.
The functionality is very useful to be able to do this would be super useful.
At the very least it's something we should have in a non system context.
Yeah.
In fact language context would be, I think, the right place.
You could certainly, you know, make a small project of having, you know, I can work with Rick or we can kind of take A modification of this and have it as an internal utility and bang on it a bit and see, you know, where the edge cases that our big problems are and where it can be refined. And even if it's only used internally for some general cases, it at least.
Gives us the name. Totally confuses me.
Yeah, I think it needs head, perhaps replace message head.
Well, it's not necessarily message head. You can replace anything in the message expression. So, like the parameters as well. Like that last example there, it's replacing the integer parameters with some text.
I mean, it's really like reissue message or something.
Yeah, that. That seems like a potentially better name.
I see.
I was originally calling it Message Redirect and I just figured that's because you can just give it arbitrary replacement rules.
Yeah, redirection makes people think streams or something.
Yeah.
Okay. I'm not sure we're going to get this solved today. And I think this should be combined with the error handling discussion because this is a whole.
Yes, I.
That's definitely part of it.
Yep.
Well, I. Yeah, I don't know why this one piece was split off before here.
Well, but no, it's right. I mean, maybe it's not discussion, but we need this internally.
Fine, but there, there's a time and a place and I don't think this is it.
Fair enough.
We were originally going to cover it during the error handling discussion and that discussion got cut a little short. We also didn't get to talk about fail safe, but Christopher wasn't immediately available and we weren't sure how long the prior points were. So I at least wanted to be able to touch on them a little bit, even if it's just to say this is interesting, needs more thought. We need a bigger group to discuss it more thoroughly or say I think this idea is terrible and move on.
All right. I mean, look, message gymnastics is definitely a topic and understanding kind of. You know, the message mechanism is a very old mechanism that's, you know, done well over the years, but I suspect, you know, formalizing some aspects of it. Like, you know, the whole message inheritance from one symbol to another is kind of. It's very old. I don't know. You know, I don't know whether it's all right anymore and whether we can be more sophisticated about that. And this is a very specific way of doing that in a block of code. You know, reissue the messages from a different symbol. Right. I would have thought message modify was better than message replace because I understand that they are replacement rules, but it's still a complicated concept of what's happening. Anyway, just, you know, one small point. All right, let's wrap it up.
Okay.
Nothing else here?
Nope. That should take care of us for 14.
Great. Okay, thanks a lot. All right, see you all soon. Bye. Bye.
Bye.
Bye.
More from Guy

Cheryl Strauss Einhorn | The Human Edge: Smarter Decisions in the Age of AI | Talks at Google

Rachel Glennerster | Innovation and the Center for Global Development | Talks at Google

Rebecca Winthrop | Rethinking the Purpose of Education in the Age of AI | Talks at Google

Dr. Robert Wachter | A Giant Leap: How AI Is Transforming Healthcare... | Talks at Google






