RosettaCodeData/Task/Sort-numbers-lexicographically/Isabelle/sort-numbers-lexicographically.isabelle
2023-07-01 13:44:08 -04:00

23 lines
673 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

theory LexList
imports
Main
"~~/src/HOL/Library/Char_ord"
"~~/src/HOL/Library/List_Lexorder"
begin
definition ord_ascii_zero :: nat where
"ord_ascii_zero == of_char (CHR ''0'')"
textGet the string representation for a single digit.
definition ascii_of_digit :: "nat ⇒ string" where
"ascii_of_digit n ≡ if n ≥ 10 then undefined else [char_of (n + ord_ascii_zero)]"
fun ascii_of :: "nat ⇒ string" where
"ascii_of n = (if n < 10
then ascii_of_digit n
else ascii_of (n div 10) @ ascii_of_digit (n mod 10))"
lemma ascii_of 123 = ''123'' by code_simp
value sort (map ascii_of (upt 1 13))
end