In English, plurals usually follow the rule of simply appending an s to the word, but there are many irregular words that do not. This .sw3 file encodes that knowledge, along with the inverse mapping. Our code starts by defining a general rule for the plural operator, followed by the general inverse of removing the s suffix. To handle the irregular cases, we make use of the language feature that specific rules have higher precedence than general rules. So if we ask the system the plural of mouse, it will return mice, not mouses. The final line of code generates the specific inverse rules. The find-inverse[op] operator scans through the known learn rules with operator op, and then generates the inverse-op learn rules. This is because our learn rules correspond to a directed graph, the inverse-op learn rules then point in the reverse direction.
Here is the code:
plural |*> #=> |_self> _ |s> inverse-plural |*> #=> remove-suffix["s"] |_self> plural |mouse> => |mice> plural |tooth> => |teeth> plural |foot> => |feet> plural |radius> => |radii> plural |matrix> => |matrices> plural |elf> => |elves> plural |calf> => |calves> plural |knife> => |knives> plural |loaf> => |loaves> plural |shelf> => |shelves> plural |wolf> => |wolves> plural |man> => |men> plural |person> => |people> plural |child> => |children> plural |goose> => |geese> plural |louse> => |lice> plural |cactus> => |cacti> plural |appendix> => |appendices> plural |ox> => |oxen> plural |fish> => |fish> plural |addendum> => |addenda> plural |analysis> => |analyses> plural |antithesis> => |antitheses> plural |apex> => |apexes> plural |appendix> => |appendices> plural |axis> => |axes> plural |bacillus> => |bacilli> plural |bacterium> => |bacteria> plural |basis> => |bases> plural |codex> => |codices> plural |corpus> => |corpora> plural |criterion> => |criteria> plural |curriculum> => |curricula> plural |datum> => |data> plural |diagnosis> => |diagnoses> plural |die> => |dice> plural |dwarf> => |dwarves> plural |ellipsis> => |ellipses> plural |erratum> => |errata> plural |formula> => |formulae> plural |fungus> => |fungi> plural |genus> => |genera> plural |half> => |halves> plural |hoof> => |hooves> plural |hypothesis> => |hypotheses> plural |index> => |indices> plural |locus> => |loci> plural |medium> => |media> plural |memorandum> => |memoranda> plural |nucleus> => |nuclei> plural |oasis> => |oases> plural |opus> => |opera> plural |ovum> => |ova> plural |parenthesis> => |parentheses> plural |phenomenon> => |phenomina> plural |phylum> => |phyla> plural |prognosis> => |prognoses> plural |quiz> => |quizzes> plural |referendum> => |referenda> plural |scarf> => |scarves> plural |self> => |selves> plural |sheep> => |sheep> plural |series> => |series> plural |shrimp> => |shrimp> plural |species> => |species> plural |stimulus> => |stimuli> plural |stratum> => |strata> plural |swine> => |swine> plural |syllabus> => |syllabi> plural |symposium> => |symposia> plural |synopsis> => |synopses> plural |tableau> => |tableaux> plural |thief> => |thieves> plural |trout> => |trout> plural |tuna> => |tuna> plural |vertebra> => |vertebrae> plural |vertex> => |vertices> plural |vita> => |vitae> plural |vortex> => |vortices> plural |wharf> => |wharves> plural |wife> => |wives> plural |woman> => |women> find-inverse[plural]
Some quick examples in the SDB shell:
sa: plural |mouse> |mice> sa: plural |apple> |apples> sa: plural |orange> |oranges> sa: inverse-plural |carrots> |carrot> sa: inverse-plural |vertices> |vertex>
As an aside, given the above data, we can find the set of plurals that equal themselves. To do this we make use of the filter() operator and the rel-kets operator:
sa: equal-plural |*> #=> filter(|op: plural>, |_self>) |_self> sa: equal-plural rel-kets[*] |fish> + |sheep> + |series> + |shrimp> + |species> + |swine> + |trout> + |tuna>
where we define an equal-plural operator that returns the ket it is applied to if its plural equals itself, otherwise the operator returns the empty ket. rel-kets[*] returns the list of all known kets that have a defined learn rule. In contrast, rel-kets[op] only returns the list of kets that have a learn rule with respect to the op operator. We then use operator chaining to apply the equal-plural operator to the output of rel-kets[*]. Since the empty ket is the identity element for superpositions, the output of rel-kets is compressed by equal-plural down to our desired list.
Raw file here.