Understanding Postgres’s similarity algorithm

Could someone explain how Postgres’s similarity algorithm works?

Why do these examples return different results?

select similarity('Foo Bar Baz', 'Foo Bar'); -- 0.8 select similarity('Foo Bar Baz', 'Bar Foo'); -- 0.8 select similarity('Foo Bar Baz', 'Foo Baz'); -- 0.8 select similarity('Foo Bar Baz', 'Baz Foo'); -- 0.8 select similarity('Foo Bar Baz', 'Bar Baz'); -- 0.6 select similarity('Foo Bar Baz', 'Baz Bar'); -- 0.6