Torsors

Suppose you're defining a Point class, and you're trying to write the subtraction operator. What type should it return? Another Point? Or should you invent a new class called Vector? Vectors and Points have exactly the same machine representation, so it seems kind of a waste to create two classes. And yet you have this vague feeling that Vectors and Points really are different, and it might be a good idea to maintain different types for different things. Who knows, maybe it'll catch a mistake in your math. On the other hand, maybe you'll end up having to convert between them all the time, and it'll just end up being annoying rather than helpful.

Here's another example that's a bit more clear cut. Suppose you're working with a version control system, and you want to represent both documents and the differences between documents. In theory both of these could be represented by strings (for example the output from the unix diff command is just plain text). It makes sense to subtract two documents to get a diff, and to add a diff to a document to get a new, patched document. But it makes no sense to add two documents, or to subtract a diff and a document. In this example, it's pretty obvious that you want to keep the types separate, even if the physical representation is the same.

If you've ever found yourself designing a program that has these kinds of concepts, you might want to read about torsors. They're a concept from math that generalizes the idea of things as opposed to differences between things. My favorite quote from that article:

An affine space is like a vector space that has forgotten its origin. A torsor is like a group that has forgotten its identity.

To me, the interesting thing about the concept of a torsor is that it makes it clear that there's a mathematical justification for why addition and subtraction (or multiplication and division) might not have the same types. I love stuff like this. It makes me want to write a Torsor type class in haskell, just because it feels right, even though I have no immediate use for it.

Posted on March 30, 2006 11:13 AM
More languages articles

Comments

i hope people aren't going to go away thinking diff is an example of a torsor :I

Posted by: ian at March 31, 2006 06:05 PM

Why, may I ask, is it not?

Posted by: crzwdjk at April 1, 2006 12:39 PM

assuming theres a diff that allows you to add 'hello' to the start of any document, its difficult to see what kind of document when having this diff applied to it would result in the empty document.

Posted by: ian at April 2, 2006 09:17 AM

I think it's supposed to be the other way around, with documents being the torsor, and diffs just being a plain old group (assuming no such thing as rejected diffs). After all, there is an identity diff, and no special document, since the only thing we care about is the difference between two documents. So I think it is still valid.

Posted by: crzwdjk at April 4, 2006 03:36 AM

if it is a torsor then my 'hello' diff should have an inverse. applying this inverse to the empty document will give another document. its this document which will result in the empty document when my 'hello' diff is applied to it.
theres nothing special about the empty document. i just use it as an example of a document.

Posted by: ian at April 4, 2006 04:29 PM

The linked explanation made no mention whatsoever of inverses, and only talked about groups. And a group does not imply having an inverse, for example multiplication in the set of integers, or n by n matrices and multiplication, or string concatenation. As far as I understood it, the whole torsor idea applies to plain old groups, and inverses are not needed.

Posted by: crzwdjk at April 5, 2006 02:53 AM

http://en.wikipedia.org/wiki/Group_(mathematics)#Basic_definitions
;)

Posted by: ian at April 5, 2006 03:45 PM

One could draw an analogy between documents and the notion of temperature as explained in John Baez's article. The empty document would then correspond to absolute zero.

(This would imply that the set that diffs constitute is the same as the group of documents, but I am stepping beyond the limits of my understanding here!)

-K

Posted by: Kaushik at April 10, 2006 02:05 AM

In the case of points and vectors, the distinction goes even deeper. If you transform the space, then points and vectors transform differently.

As an example: Take two points. Now move the origin. The points "move" relative to the origin, but the difference between the two points (which is a vector) does not change at all:

(p1 + o) - (p2 + o) = p1 - p2

Posted by: Pseudonym at May 6, 2006 07:28 PM

... and even deeper ...
in 3D computer graphics we know that tangents transform differently from normals (tangents transform like points), and in mechanics we know that torques transform differently than forces.

The underlying deepness is that you really need to go beyond the degenerate representations using vectors and matrices, to a graded space that keeps all the different kinds of 'vectors' separate: scalars, pseudo-scalars, pseudo-vectors, vectors, directed volumes, etc.
You need a Clifford Algebra.

Mik

Posted by: Mik at November 27, 2007 03:46 AM

Of course, it's true that Baez's example of temperatures as forming a torsor is misleading. Indeed, if there were no absolute 0, then they would form such a torsor; but the presence of absolute zero makes temperatures a copy of R_+, not of R. Remedy: Define torsors for semi-groups and other algebraic structures (as Baez almost does for rings when he talks about dilation and translation at the end of the linked article).

Posted by: JadeNB at August 24, 2008 05:13 PM

Great post, thanks.

Posted by: free online games at October 25, 2009 04:13 PM

Love this man. Great stuff, great prices, free shipping. Email him if you cant find what you are looking for and he will look for you. Good customer service.louis vuittonSomeone who is knowledgeable in louis vuitton.Another guy from hong Kong (Largest louis vuitton second hand city, I believe) he has great stuff at fair prices but his shipping is insane

Posted by: louis vuitton at October 29, 2009 10:08 AM

Eliminating the need for the extra trouble to wear ugg boots uk
ugg boots saleuggs, in the extreme sports, look for happiness in life, with UGG Classic boots and nike sb showed off your tall body, do not worry about being laughed at, dancing new style ugg australia and nike sb dunk . The flavor of life that is colorful, there are Christian Louboutincheap nike dunksUGG cardy boots、and nike sb for sale also used fear to creep away money from your pocket Mody ? Love beauty, you might even love UGG Classic tall bootsUGG Nightfall bootsUGG Classic short bootsnew nike sb。There are an infinite high power drivers of popular front ugg boots saleugg saleuggsnike dunkdiscount ugg bootsnike dunk sb, our website also have UGG Nightfall bootsbutton ugg bootsbailey button uggugg button bootsbailey button bootsnike dunk midnike dunk highChristian Louboutin Boots, pick your favorite, do not hesitate!

Posted by: ugg boots sale at November 12, 2009 04:02 AM

Good day! Thx for your great post and Im thinking about how to introduce my ugg boots to you cos Im not sure if u like this. Many people who live in the cold area like the ugg boots, especially the north-europe. Our uggshare.co.uk supply the cheapest classic cardy ugg boots, class tall ugg boots, classic short ugg boots and other series of uggs, hope my words didn’t trouble u, cy!

Posted by: ugg boots at November 16, 2009 09:43 PM

Uggs on sale now.UGG Classic Cardy Boot makes me different form the other

girls. The UGG Bailey Button Boot is a good choice for female.

Posted by: ugg classic cardy boots at November 17, 2009 12:09 AM

Louis Vuitton , commonly referred to as Gucci and Louis Vuitton, or sometimes shortened to Mont Blanc has become one of the most Swarovski Mirror Agendas luxurybrands Tiffany Co UGG .

Posted by: 1 at November 17, 2009 01:31 AM

UGG Bailey Button bootsis a new style in 2009.The classic cardy uggs boots is another hot boots that worth of buying.And the classic tall ugg boots will make your winter amusing.And now uggs on sale,if you are looking for such a boot,the ugg boots is good choice this year.

Posted by: UGG Bailey Button Boots at November 17, 2009 01:37 AM

I love Women's UGG Classic Cardy Boot 5819 very much. And the new style UGG Mayfaire Boots is aslo a good choice this year.

Posted by: UGG Bailey Button Fancy Boots at November 17, 2009 03:33 AM

www.enjoywholesale.com

china wholesale clothing,china wholesale shoes,china wholesale electronics,china wholesale suppliers,china manufacturers

china wholesale products,light in the box,wholesale lots,wholesale ipod
china direct,china dropship,china trade,made in china

electronics wholesaler,ebay wholesaler,financial wholesaler
fashion wholesaler,clothing wholesaler,wholesaler magazine

computer wholesaler,external wholesaler,dvd wholesaler,wholesaler definition,china wholesaler,mutual fund wholesaler,define wholesaler,insurance wholesaler


discount ugg boots
forture
ugg boots
Discount store

Posted by: wholesaler business website, net shopping site, external wholesaler,dvd wholesaler,wholesaler definition,china wholesaler,mutual fund wholesaler,define wholesaler,insurance wholesaler at November 18, 2009 02:54 AM

lxjuan08ed hardyis a famous ed hardy store which sell directly ed hardy clothing, shoes, boots, swim suit and other cheap ed hardy.

Browse through our catalogue of hundreds of ed hardy clothing,Ed hardy Shirt,Ed hardy ... Buy Ed Hardy today for a gift, for a friend, or for yourself.

ED HARDY Online Shop,Ed Hardy Store by Christian Audigier,coach handbags,rolex watches.We supply cheapest Newest ed hardy discount 2009 Commodity New styles.


ed hardy sale

Posted by: ed hardy at November 18, 2009 08:19 PM

We are the best online sales for the china wholesale . Here you can have a large of choices of kinds Ugg Boots,Converse Shoes,Timberland Boots,puma shoes,Nike Shox Shoes ,Nike Dunk SB Shoes,Nike Air Max,Links Of London,Tiffany Jewelry,Dior Handbags?,jimmy choo handbags ,Cartier Watches, 8GB Mp4 Players,Bluetooth Car DVDs. All our cheap online cheap goods are high quality and original packages, and best service. We offer our customers the best service, 7 days arrive at your door.Enjoy your easy and happy shopping with us.

Posted by: cheap goods sale. at November 19, 2009 09:49 PM

We are the best online sales for the china wholesale . Here you can have a large of choices of kinds Ugg Boots,Converse Shoes,Timberland Boots,puma shoes,Nike Shox Shoes ,Nike Dunk SB Shoes,Nike Air Max,Links Of London,Tiffany Jewelry,Dior Handbags?,jimmy choo handbags ,Cartier Watches, 8GB Mp4 Players,Bluetooth Car DVDs. All our cheap online cheap goods are high quality and original packages, and best service. We offer our customers the best service, 7 days arrive at your door.Enjoy your easy and happy shopping with us.

Posted by: cheap goods sale. at November 20, 2009 12:21 AM

Do you like sports? If you like it,the NIke Air Max TN and Nike Air Max 360 is a good choice for you.And now the there is a good news,CheapNike Air Max running Shoes is waiting for you.I think The New Nike Air MAX 2009 Running Shoes makes you great comfortable.

Posted by: Nike Air Max shoes at November 20, 2009 03:40 AM

Your article is write very well, I like it very much ~
ghd Hair Straightener
ghd Hair Straighteners
ghd straighteners
GHD
hair straighteners
bose in ear headphones
bose on ear headphones
bose headphones
nike sb dunks
nike dunks
I wish you have a wonderful day!Thank you.

Posted by: ghd straighteners at November 22, 2009 08:27 PM

Timeberland boots on sale now! Do you want moreTimeberland boots information?Just move your mouse and press it to our Timberland shoes online store.

Posted by: Timberland uk at November 23, 2009 01:07 AM

a href="http://www.christianlouboutinbuy.net/Christian-Louboutin-Boot/">cheap Christian Louboutin Boot
cheap Christian Louboutin Pump
cheap Christian Louboutin sandal
cheap Jimmy Choo Handbags
cheap Jimmy Choo Shoes
cheap Yves Saint Laurent Shoes

Posted by: cheap Yves Saint Laurent Shoes at November 23, 2009 11:49 AM

m6yj ner nern netj nerj nearh nerh

Posted by: Angle Lina at November 24, 2009 03:05 AM

Laptop Battery Laptop Battery Laptop Batteries
Laptop Batteries discount laptop battery
discount laptop battery
notebook battery notebook battery
computer battery computer battery
replacement laptop battery replacement laptop battery
notebook batteries notebook batteries

Posted by: Laptop Battery at November 25, 2009 12:15 AM

People all over the world know the abercrombie and fitch,but not everyone really knows how fashion the abercrombie is,hollister is the Legend maker. Everybody wears the hollister clothing would be the abercrombie mens and the abercrombie womens, if you want know you can search the Ruehl No.925 or abercrombie outlet in the www.google.com .

Posted by: fitch at November 25, 2009 10:20 PM

Ugg Classic Cardy

Boots

Ugg Classic Tall

Boots

Ugg Classic Short

Boots

Posted by: topuggshoes at November 26, 2009 02:38 AM

chaoying nfl jerseys
Giants Jerseys
Patriots Jerseys

Posted by: jerseysleague at November 29, 2009 04:09 AM

Paul Smith has been collaborating with a few different organizations recently and his latest venture sees him teaming up with Japanese bicycle saddle, Paul Smith bag, on a limited edition leather saddle. The release features Smith’s signature stripes where only 20 will be available at Paul Smith Clothing store in Japan and 8 at the Floral Street store in London. Get on it quick

Posted by: fasfw at November 29, 2009 11:45 AM

Just wanted to say great job with the blog, today is my first visit here and I’ve enjoyed reading your posts so far
ugg bailey button
Wow, my ugg classic mini will not be coming off now! I’ve had them on for 12hrs strait and I do not want to take them off. Thanks for everything, well worth the wait.

Posted by: ugg bailey button boots at November 30, 2009 05:50 AM

It is no doubt that Replica Louis Vuitton Speedy 30 enjoys highest reputation in the world. Louis Vuitton Speedy 30, purses, shoes, watches, clothes, and belts successfully seize loving heart of a majority of people. Speedy 30 is filled with romantic and fantasy, and it is a symbol of noble and high quality of life for gucci ever! Today, let us talk about Tivoli PM.belts have different styles and colors, such as Monogram series belts, Graffiti series belts, both men and women love them crazily. All of them match with various leisure clothes, formal business suits, and beautiful clothes very well. Whenever you wear a Louis Vuitton belt to make your public appearance, you will be naturally concerned and admired by every body. When we talk of high quality, there is no other company to compare with Louis Vuitton Replica Speedy 30. All Louis Vuitton belts adopt top quality cow leather, high quality hard ware, and the color will never be faded. The belts are so durable, and you can wear them to match your clothes for several years. Also, you can clearly see an obvious LV logo as a buckle of each belt.

Posted by: fanqin at December 1, 2009 02:13 AM

ugg boots sale at a time when large heat has set off a winter 08/09 to Ewha.Outlines the

warm wool winter fashion degree to wool crocheted wool ugg boots uk to join after the

body does not stimulate your skin soft, soft comfort UP. Fashion can not without
ugg boots presence in Winter.and ugg boots have many series.such as:
ugg classic
UGG Bailey Button boots
ugg nightfall
ugg kids

Posted by: uggboots at December 2, 2009 08:44 PM
Post a comment









Remember info?




Prove you're human. Type "human":