ongoing work on numerals

This commit is contained in:
Herbert Lange
2019-06-12 15:03:27 +02:00
parent 8dde0246c4
commit f725562f79
5 changed files with 133 additions and 80 deletions
+75 -32
View File
@@ -1,6 +1,6 @@
concrete NumeralLat of Numeral = CatLat ** open ResLat,ParadigmsLat in {
concrete NumeralLat of Numeral = CatLat ** open ResLat,ParadigmsLat,Prelude in {
lincat
Digit = Numeral ;
Digit = TDigit ;
Sub10 = Numeral ;
Sub100 = Numeral ;
Sub1000 = Numeral ;
@@ -8,38 +8,81 @@ concrete NumeralLat of Numeral = CatLat ** open ResLat,ParadigmsLat in {
lin
num x = x ;
n2 = lin Numeral ( mkNum "duo" "secundus" ) ;
n3 = lin Numeral ( mkNum "tres" "tertius" ) ;
n4 = lin Numeral ( mkNum "quattuor" "quartus" ) ;
n5 = lin Numeral ( mkNum "quinque" "quintus" ) ;
n6 = lin Numeral ( mkNum "sex" "sextus" ) ;
n7 = lin Numeral ( mkNum "septem" "septimus" ) ;
n8 = lin Numeral ( mkNum "octo" "ocatvus" ) ;
n9 = lin Numeral ( mkNum "novem" "nonus" ) ;
-- n2 = lin Digit ( mkDigit "duo" "viginti" "ducenti" "secundus" ) ;
-- n3 = lin Numeral ( mkNum "tres" "triginta" "trecenti" "tertius" ) ;
-- n4 = lin Numeral ( mkNum "quattuor" "quadraginta" "quadringenti" "quartus" ) ;
-- n5 = lin Numeral ( mkNum "quinque" "quinquaginta" "quingenti" "quintus" ) ;
-- n6 = lin Numeral ( mkNum "sex" "sexaginta" "sescenti" "sextus" ) ;
-- n7 = lin Numeral ( mkNum "septem" "septuaginta" "septingenti" "septimus" ) ;
-- n8 = lin Numeral ( mkNum "octo" "octoginta" "octingenti" "ocatvus" ) ;
-- n9 = lin Numeral ( mkNum "novem" "nonaginta" "nongenti" "nonus") ;
lin pot01 = lin Numeral ( mkNum "unus" "primus" ) ;
lin pot0 d = d ;
--lin pot110 = regCardOrd "ten" ** {n = Pl} ;
--lin pot111 = regCardOrd "eleven" ** {n = Pl} ;
--lin pot1to19 d = {s = d.s ! teen} ** {n = Pl} ;
lin pot0as1 n = n ;
--lin pot1 d = {s = d.s ! ten} ** {n = Pl} ;
--lin pot1plus d e = {
-- s = \\c => d.s ! ten ! NCard ++ "-" ++ e.s ! unit ! c ; n = Pl} ;
pot1as2 n = n ;
--lin pot2 d = {s = \\c => d.s ! unit ! NCard ++ mkCard c "hundred"} ** {n = Pl} ;
--lin pot2plus d e = {
-- s = \\c => d.s ! unit ! NCard ++ "hundred" ++ "and" ++ e.s ! c ; n = Pl} ;
pot2as3 n = n ;
--lin pot3 n = {
-- s = \\c => n.s ! NCard ++ mkCard c "thousand" ; n = Pl} ;
--lin pot3plus n m = {
-- s = \\c => n.s ! NCard ++ "thousand" ++ m.s ! c ; n = Pl} ;
--
-- -- 1
-- pot01 =
-- -- d * 1
-- pot0 d = d ;
-- -- 10
-- pot110 = pot01 ;
-- -- 11
-- -- pot111 = pot1to19 pot01 ;
-- -- 10 + d
-- -- pot1to19 d = mkNum "" "" "" "" ; -- {s = d.s ! teen} ** {n = Pl} ;
-- -- coercion of 1..9
-- pot0as1 n = n ;
-- -- d * 10
-- --lin pot1 d = {s = d.s ! ten} ** {n = Pl} ;
-- -- d * 10 + n
-- --lin pot1plus d e = {
-- -- s = \\c => d.s ! ten ! NCard ++ "-" ++ e.s ! unit ! c ; n = Pl} ;
-- -- coercion of 1..99
-- pot1as2 n = n ;
-- -- m * 100
-- --lin pot2 d = {s = \\c => d.s ! unit ! NCard ++ mkCard c "hundred"} ** {n = Pl} ;
-- -- m * 100 + n
-- --lin pot2plus d e = {
-- -- s = \\c => d.s ! unit ! NCard ++ "hundred" ++ "and" ++ e.s ! c ; n = Pl} ;
-- -- coercion of 1..999
-- pot2as3 n = n ;
-- -- m * 1000
-- --lin pot3 n = {
-- -- s = \\c => n.s ! NCard ++ mkCard c "thousand" ; n = Pl} ;
-- -- m * 1000 + n
-- --lin pot3plus n m = {
-- -- s = \\c => n.s ! NCard ++ "thousand" ++ m.s ! c ; n = Pl} ;
oper
n1 : Digit = lin Digit ( fullDigit "unus" "decem" "primus" "decimus" "centesimus" "millesimus" ) ;
mkDigit : (ones, tens, hundreds, ord : Str) -> TDigit =
\ones, tens, hundreds, ord ->
case <tens,hundreds> of {
-- <"decem",_> => fullDigit ones tens hundreds ord "decimus" "centesimus" ;
-- <"viginta",_> => fullDigit ones tens hundreds ord "vicesimus" "ducentesimus" ;
-- <"triginta",_> => fullDigit ones tens hundreds ord "tricesimus" "trecentesimus" ;
<quadra + "ginta",quadringent + "i"> => fullDigit ones tens hundreds ord (quadra + "gesimus") (quadringent + "esimus")
} ;
fullDigit : (ones, tens, hundreds, ord1,ord10,ord100 : Str) -> TDigit =
\ones, tens, hundreds, ord1,ord10,ord100 ->
{ s = table { one => cardFlex ones ;
ten => cardFlex tens ;
hundred => cardFlex hundreds ;
thousand => \\_,_ => nonExist ;
ten_thousand => \\_,_ => nonExist ;
hundred_thousand => \\_,_ => nonExist }
-- n = case ones of { "unus" => Sg ; _ => Pl } ;
-- ord =
-- \\_,_ => [] ;
-- -- table { one => (mkA ord1).s ! Posit;
-- -- ten => (mkA ord10).s ! Posit ;
-- -- hundred => (mkA ord100).s ! Posit ;
-- -- thousand => \\_,_ => nonExist ;
-- -- ten_thousand => \\_ => nonExist ;
-- -- hundred_thousand => \\_ => nonExist } ;
} ;
-- numerals as sequences of digits
lincat
Dig = TDigit ;
Dig = TDig ;
lin
IDig d = {s = d.s ! one; unit = ten} ;
@@ -61,11 +104,11 @@ concrete NumeralLat of Numeral = CatLat ** open ResLat,ParadigmsLat in {
D_9 = mkDig "IX" "XC" "CM" "(IX)" "(XC)" "(CM)" ;
oper
TDigit = {
TDig = {
s : Unit => Str
} ;
mkDig : Str -> Str -> Str -> Str -> Str -> Str -> TDigit =
mkDig : Str -> Str -> Str -> Str -> Str -> Str -> TDig =
\one,ten,hundred,thousand,ten_thousand,hundred_thousand -> {
s = table Unit [one;ten;hundred;thousand;ten_thousand;hundred_thousand]
} ;